/* ============================================================
   style.css — Image Plotter UI
   ============================================================ */

/* ── Google Fonts ─────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ────────────────────────────────────────── */
:root {
  --bg:           #0d0f14;
  --bg-card:      #141720;
  --bg-input:     #1a1e2b;
  --bg-hover:     #1f2435;
  --border:       #252b3b;
  --border-focus: #4f7cff;
  --accent:       #4f7cff;
  --accent-light: #7ba3ff;
  --accent-2:     #00e5c3;
  --accent-glow:  rgba(79,124,255,0.25);
  --success:      #00c896;
  --warning:      #ffb347;
  --error:        #ff5c6a;
  --text-primary: #e8ecf4;
  --text-muted:   #7a86a1;
  --text-dim:     #4a5470;
  --radius-sm:    8px;
  --radius-md:    14px;
  --radius-lg:    22px;
  --shadow-card:  0 4px 32px rgba(0,0,0,0.45);
  --transition:   0.2s cubic-bezier(0.4,0,0.2,1);

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Layout ───────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 40px;
  border-bottom: 1px solid var(--border);
  background: rgba(13,15,20,0.85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent-light), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.logo-sub {
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--text-muted);
  -webkit-text-fill-color: var(--text-muted);
}

.header-badge {
  font-size: 0.7rem;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Main content ─────────────────────────────────────────── */
main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 36px 24px 60px;
  display: grid;
  grid-template-columns: 420px 1fr;
  grid-template-rows: auto 1fr;
  gap: 24px;
  align-items: start;
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-card);
}

.card-title {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* ── Upload zone ──────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-input);
  position: relative;
  overflow: hidden;
}
.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(79,124,255,0.06);
  transform: scale(1.01);
}
.upload-zone.drag-over { box-shadow: 0 0 0 4px var(--accent-glow); }

.upload-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.65;
  transition: transform var(--transition);
}
.upload-zone:hover .upload-icon { transform: translateY(-4px); }

.upload-zone p { color: var(--text-muted); font-size: 0.88rem; }
.upload-zone span { color: var(--accent-light); font-weight: 600; }
.upload-hint { font-size: 0.75rem !important; margin-top: 6px; opacity: 0.6; }

#file-input { display: none; }

/* ── OR divider ───────────────────────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Form elements ────────────────────────────────────────── */
.input-group { margin-bottom: 14px; }
.input-group label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="url"],
select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder { color: var(--text-dim); }

/* ── Settings grid ────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ── Range sliders ────────────────────────────────────────── */
.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.range-row input[type="range"] {
  flex: 1;
  padding: 0;
  height: 4px;
  -webkit-appearance: none;
  background: var(--border);
  border-radius: 2px;
  border: none;
  box-shadow: none;
}
.range-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  transition: transform 0.15s;
}
.range-row input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}
.range-val {
  min-width: 36px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent-light);
}

/* ── Collapsible section ──────────────────────────────────── */
.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
.collapsible-header:hover .collapse-arrow { color: var(--accent); }
.collapse-arrow {
  font-size: 0.65rem;
  color: var(--text-dim);
  transition: transform 0.2s, color var(--transition);
}
.collapsible-header.open .collapse-arrow { transform: rotate(180deg); }
.collapsible-body { overflow: hidden; transition: max-height 0.3s ease; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  width: 100%;
  margin-top: 18px;
  font-size: 0.95rem;
  padding: 14px;
  letter-spacing: 0.02em;
  box-shadow: 0 4px 20px rgba(79,124,255,0.35);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(79,124,255,0.5);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent-light); }

.btn-success {
  background: linear-gradient(135deg, #00c896,#00e5c3);
  color: #0d1a16;
  font-weight: 700;
}
.btn-success:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,200,150,0.4);
}

/* ── Preview panel ────────────────────────────────────────── */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* ── Preview tabs ─────────────────────────────────────────── */
.preview-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 5px;
}
.tab-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-sans);
}
.tab-btn.active {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.tab-btn:hover:not(.active) { color: var(--text-primary); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Image previews ───────────────────────────────────────── */
.preview-image-wrap {
  width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #111318;
  border: 1px solid var(--border);
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-image-wrap img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  max-height: 480px;
}
.preview-empty {
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
  padding: 40px;
}
.preview-empty-icon { font-size: 2.5rem; margin-bottom: 10px; opacity: 0.4; }

/* ── Canvas preview ───────────────────────────────────────── */
#toolpath-canvas {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #f0f4ff;
  max-height: 480px;
  object-fit: contain;
  display: block;
}

/* ── Stats bar ────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.stat-chip strong { color: var(--accent-light); font-family: var(--font-mono); }

/* ── G-code preview ───────────────────────────────────────── */
.gcode-preview {
  background: #0a0c10;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: #9eb8ff;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre;
  line-height: 1.7;
}
.gcode-preview .gc-comment { color: var(--text-dim); }
.gcode-preview .gc-move   { color: #7bd4a2; }
.gcode-preview .gc-pen    { color: #ffb347; }

/* ── Download row ─────────────────────────────────────────── */
.download-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.download-name {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-muted);
  flex: 1;
}

/* ── Loader ───────────────────────────────────────────────── */
.loader-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(13,15,20,0.8);
  backdrop-filter: blur(6px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
}
.loader-overlay.active { display: flex; }

.loader-spinner {
  width: 52px;
  height: 52px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.9s cubic-bezier(0.4,0,0.2,1) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loader-text {
  color: var(--text-muted);
  font-size: 0.88rem;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50%       { opacity: 1;   }
}
.loader-steps {
  display: flex;
  gap: 8px;
}
.loader-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 0.8s ease-in-out infinite;
}
.loader-dot:nth-child(2) { animation-delay: 0.15s; background: var(--accent-2); }
.loader-dot:nth-child(3) { animation-delay: 0.3s;  background: var(--success);  }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1.2); opacity: 1;   }
}

/* ── Toast notifications ──────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: slideIn 0.3s ease;
  max-width: 340px;
}
.toast.success { background: #0d2218; border: 1px solid var(--success); color: #50e8b0; }
.toast.error   { background: #20090c; border: 1px solid var(--error);   color: #ff8a95; }
.toast.info    { background: #0d1428; border: 1px solid var(--accent);  color: var(--accent-light); }
@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes fadeOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(60px); }
}

/* ── Thumbnail strip ──────────────────────────────────────── */
.thumbnail-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.thumb {
  width: 70px;
  height: 70px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition);
}
.thumb:hover, .thumb.active { border-color: var(--accent); transform: scale(1.06); }

/* ── Footer ───────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.75rem;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    padding: 20px 16px 48px;
  }
  header { padding: 14px 20px; }
}
@media (max-width: 480px) {
  .settings-grid { grid-template-columns: 1fr; }
  .download-row { flex-direction: column; }
}

/* ── Animations on mount ──────────────────────────────────── */
.card { animation: fadeUp 0.4s ease backwards; }
.card:nth-child(2) { animation-delay: 0.08s; }
.card:nth-child(3) { animation-delay: 0.14s; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Highlighted result state ─────────────────────────────── */
.result-ready .card-title::before { background: var(--success); }

/* ── Watermark grid background ────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(79,124,255,0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(79,124,255,0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}
.app-wrapper { position: relative; z-index: 1; }

/* ── Pipeline progress bar ────────────────────────────────── */
.pipeline-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 12px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  overflow-x: auto;
}
.pipe-stage {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  white-space: nowrap;
  transition: all 0.35s ease;
  letter-spacing: 0.03em;
}
.pipe-stage.active {
  background: rgba(79,124,255,0.14);
  border-color: var(--accent);
  color: var(--accent-light);
  box-shadow: 0 0 12px var(--accent-glow);
  transform: scale(1.06);
}
.pipe-stage.done {
  background: rgba(0,200,150,0.12);
  border-color: var(--success);
  color: var(--success);
}
.pipe-arrow {
  font-size: 1rem;
  color: var(--text-dim);
  padding: 0 4px;
  user-select: none;
}

/* ── Download grid ────────────────────────────────────────── */
.download-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.dl-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.dl-item.ready { border-color: rgba(0,200,150,0.35); box-shadow: 0 0 16px rgba(0,200,150,0.08); }
.dl-info { display: flex; align-items: center; gap: 12px; }
.dl-icon { font-size: 1.6rem; width: 36px; text-align: center; }
.dl-name { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.dl-meta { font-size: 0.72rem; color: var(--text-dim); font-family: var(--font-mono); margin-top: 2px; }

/* ── Loader sub-text ──────────────────────────────────────── */
.loader-sub {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  min-height: 1.4em;
  letter-spacing: 0.04em;
}

/* ── FDM G-code extra colours ─────────────────────────────── */
.gcode-preview .gc-extruder { color: #c792ea; }
.gcode-preview .gc-temp     { color: #f78c6c; }
