/* ── Design Tokens ── */
:root,
[data-theme="light"] {
  /* Core backgrounds */
  --color-bg: #f3f5fb;
  --color-surface: #ffffff;
  --color-surface-2: #eef2fb;
  --color-surface-dynamic: #dbe4f6;

  /* Borders & dividers */
  --color-divider: #d4dced;
  --color-border: #c4d0e6;

  /* Typography */
  --color-text: #171a2b;
  --color-text-muted: #5f6985;
  --color-text-faint: #97a2bb;

  /* Primary brand */
  --color-primary: #5b8dee;
  --color-primary-hover: #4a7fe7;
  --color-primary-active: #3d6fe0;
  --color-primary-highlight: #dce7ff;

  /* Semantic */
  --color-success: #4f9b73;
  --color-success-highlight: #d9eee3;
  --color-error: #c14d6d;
  --color-error-highlight: #f5dce3;
  --color-warning: #c17a33;
  --color-warning-highlight: #f5e6d4;

  /* Radius */
  --radius-sm: .375rem;
  --radius-md: .5rem;
  --radius-lg: .75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgb(15 23 42 / .06);
  --shadow-md: 0 6px 16px rgb(30 41 59 / .08);
  --shadow-lg: 0 16px 40px rgb(15 23 42 / .12);

  /* Motion */
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Fonts */
  --font-body: 'Inter', 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Typography scale */
  --text-xs: clamp(.75rem, .7rem + .25vw, .875rem);
  --text-sm: clamp(.875rem, .8rem + .35vw, 1rem);
  --text-base: clamp(1rem, .95rem + .25vw, 1.125rem);

  /* Spacing */
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
}

[data-theme="dark"] {
  --color-bg: #0d0d1a;
  --color-surface: #141625;
  --color-surface-2: #1a1a2e;
  --color-surface-dynamic: #2a2a40;
  --color-divider: #23253a;
  --color-border: #353851;
  --color-text: #edf2ff;
  --color-text-muted: #9ca7c2;
  --color-text-faint: #66708b;
  --color-primary: #5b8dee;
  --color-primary-hover: #6b9af1;
  --color-primary-active: #3d6fe0;
  --color-primary-highlight: #1d2f57;
  --color-success: #68b98c;
  --color-success-highlight: #1f352b;
  --color-error: #dc6b8f;
  --color-error-highlight: #3d2230;
  --color-warning: #d59652;
  --color-warning-highlight: #433322;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / .24);
  --shadow-md: 0 6px 18px rgb(0 0 0 / .32);
  --shadow-lg: 0 18px 48px rgb(0 0 0 / .45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #0d0d1a;
    --color-surface: #141625;
    --color-surface-2: #1a1a2e;
    --color-surface-dynamic: #2a2a40;
    --color-divider: #23253a;
    --color-border: #353851;
    --color-text: #edf2ff;
    --color-text-muted: #9ca7c2;
    --color-text-faint: #66708b;
    --color-primary: #5b8dee;
    --color-primary-hover: #6b9af1;
    --color-primary-active: #3d6fe0;
    --color-primary-highlight: #1d2f57;
    --color-success: #68b98c;
    --color-success-highlight: #1f352b;
    --color-error: #dc6b8f;
    --color-error-highlight: #3d2230;
    --color-warning: #d59652;
    --color-warning-highlight: #433322;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / .24);
    --shadow-md: 0 6px 18px rgb(0 0 0 / .32);
    --shadow-lg: 0 18px 48px rgb(0 0 0 / .45);
  }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  overflow: hidden;
}
img, svg { display: block; }
input, button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; border-radius: var(--radius-sm); }

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  z-index: 100;
}
.logo { display: flex; align-items: center; gap: var(--space-2); }
.logo-mark {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-name { font-size: var(--text-sm); font-weight: 700; letter-spacing: -.02em; color: var(--color-text); }
.logo-name span { color: var(--color-primary); }
.topbar-spacer { flex: 1; }
.btn-icon {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--color-surface-dynamic); color: var(--color-text); }

/* ── Hero Banner ── */
.hero {
  padding: var(--space-5) var(--space-6);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-divider);
  display: flex; align-items: center; gap: var(--space-6);
}
.hero-text h1 { font-size: clamp(1rem, 1.1rem + .2vw, 1.2rem); font-weight: 700; letter-spacing: -.02em; margin-bottom: 4px; }
.hero-text p { font-size: var(--text-xs); color: var(--color-text-muted); max-width: 56ch; line-height: 1.5; }
.hero-badges { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-3); }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: .7rem; font-weight: 600; letter-spacing: .02em; border: 1px solid;
}
.badge-green { background: var(--color-success-highlight); color: var(--color-success); border-color: color-mix(in oklch, var(--color-success) 30%, transparent); }
.badge-blue  { background: var(--color-primary-highlight); color: var(--color-primary); border-color: color-mix(in oklch, var(--color-primary) 30%, transparent); }
.badge-warn  { background: var(--color-warning-highlight); color: var(--color-warning); border-color: color-mix(in oklch, var(--color-warning) 30%, transparent); }
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

/* ── Workspace ── */
.workspace { display: grid; grid-template-columns: 1fr 340px; overflow: hidden; height: 100%; }
.panel-main { padding: var(--space-6); overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-5); }
.panel-side {
  background: var(--color-surface);
  border-left: 1px solid var(--color-divider);
  padding: var(--space-5);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--space-4);
}

/* ── Section Labels ── */
.section-label {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--color-text-muted); margin-bottom: var(--space-3);
}

/* ── Dropzone ── */
.dropzone {
  border: 1.5px dashed var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-6);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-3); cursor: pointer; text-align: center;
  transition: background var(--transition), border-color var(--transition);
  min-height: 160px;
}
.dropzone:hover, .dropzone.dragover { background: var(--color-primary-highlight); border-color: var(--color-primary); }
.dropzone-icon { color: var(--color-text-faint); transition: color var(--transition); }
.dropzone:hover .dropzone-icon, .dropzone.dragover .dropzone-icon { color: var(--color-primary); }
.dropzone-text { font-size: var(--text-sm); font-weight: 500; }
.dropzone-sub  { font-size: var(--text-xs); color: var(--color-text-muted); }

/* ── File List ── */
.file-list { display: flex; flex-direction: column; gap: var(--space-2); }
.file-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  animation: slideIn .18s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.file-icon { color: var(--color-primary); flex-shrink: 0; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: var(--text-sm); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: var(--text-xs); color: var(--color-text-muted); margin-top: 1px; }
.file-path {
  font-family: var(--font-mono); font-size: .68rem;
  color: var(--color-text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 32ch;
}
.file-remove {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--color-text-faint); flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.file-remove:hover { background: var(--color-error-highlight); color: var(--color-error); }

/* ── Buttons ── */
.btn-row { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.btn-sm {
  padding: var(--space-2) var(--space-3); font-size: var(--text-xs); font-weight: 500;
  border-radius: var(--radius-md); border: 1px solid var(--color-border);
  background: var(--color-surface-2); color: var(--color-text); white-space: nowrap;
  transition: background var(--transition), border-color var(--transition);
}
.btn-sm:hover { background: var(--color-surface-dynamic); }
.btn-primary {
  padding: var(--space-3) var(--space-6); font-size: var(--text-sm); font-weight: 600;
  border-radius: var(--radius-lg); background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center; gap: var(--space-2); border: none;
  transition: background var(--transition), transform var(--transition);
}
.btn-primary:hover   { background: var(--color-primary-hover); }
.btn-primary:active  { background: var(--color-primary-active); transform: scale(.99); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ── Forms ── */
.form-group { display: flex; flex-direction: column; gap: var(--space-1); }
.form-label { font-size: var(--text-xs); font-weight: 500; color: var(--color-text-muted); }
.form-control {
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-2); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); font-size: var(--text-sm); color: var(--color-text); width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:hover { border-color: var(--color-text-faint); }
.form-control:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--color-primary) 18%, transparent);
}
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23797876' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 2rem;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }

/* ── Tabs ── */
.tabs { display: flex; gap: 2px; background: var(--color-surface-dynamic); border-radius: var(--radius-lg); padding: 3px; }
.tab-btn {
  flex: 1; padding: 5px var(--space-3); border-radius: calc(var(--radius-lg) - 3px);
  font-size: var(--text-xs); font-weight: 500; color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}
.tab-btn.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }
.tab-panel { display: none; }
.tab-panel.active { display: flex; flex-direction: column; gap: var(--space-3); }

/* ── Presets ── */
.preset-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
.preset-chip {
  padding: var(--space-2) var(--space-3); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); font-size: var(--text-xs); font-weight: 500;
  color: var(--color-text-muted); text-align: left; background: var(--color-surface-2);
  line-height: 1.3; transition: all var(--transition);
}
.preset-chip:hover,
.preset-chip.active { border-color: var(--color-primary); color: var(--color-primary); background: var(--color-primary-highlight); }
.preset-chip-name  { display: block; font-weight: 700; }
.preset-chip-hint  { display: block; opacity: .65; font-size: .68rem; margin-top: 1px; }

/* ── Divider ── */
.divider { height: 1px; background: var(--color-divider); margin: var(--space-1) 0; }

/* ── Command Output ── */
.cmd-section { display: flex; flex-direction: column; gap: var(--space-3); }
.cmd-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm);
  animation: slideIn .2s ease;
}
.cmd-header {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-divider);
  background: var(--color-surface-2);
}
.cmd-filename { flex: 1; font-size: var(--text-xs); font-weight: 600; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmd-filesize  { font-size: var(--text-xs); color: var(--color-text-faint); font-family: var(--font-mono); flex-shrink: 0; }
.cmd-body    { padding: var(--space-4); }
.cmd-code {
  font-family: var(--font-mono); font-size: .72rem; line-height: 1.75;
  color: var(--color-text); white-space: pre-wrap; word-break: break-all;
  background: var(--color-bg); border: 1px solid var(--color-divider);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3); user-select: all;
}
/* Syntax highlighting */
.tok-cmd  { color: var(--color-primary); font-weight: 600; }
.tok-flag { color: var(--color-warning); }
.tok-val  { color: var(--color-text); }
.tok-file { color: var(--color-success); }
.cmd-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.btn-copy {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px;
  font-size: var(--text-xs); font-weight: 500; border-radius: var(--radius-md);
  border: 1px solid var(--color-border); background: var(--color-surface-2); color: var(--color-text);
  transition: all var(--transition);
}
.btn-copy:hover { background: var(--color-surface-dynamic); }
.btn-copy.copied { background: var(--color-success-highlight); color: var(--color-success); border-color: transparent; }
.btn-copy-all { background: var(--color-primary-highlight); color: var(--color-primary); border-color: transparent; }
.btn-copy-all:hover { filter: brightness(1.08); }

/* ── Empty state for commands ── */
.cmd-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-3); padding: var(--space-8); text-align: center;
  border: 1.5px dashed var(--color-border); border-radius: var(--radius-xl);
  color: var(--color-text-faint);
}
.cmd-empty svg { opacity: .4; }
.cmd-empty p   { font-size: var(--text-xs); line-height: 1.5; max-width: 32ch; }

/* ── Actions bar ── */
.actions-bar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4) 0 0; border-top: 1px solid var(--color-divider); margin-top: auto;
}

/* ── Status Bar ── */
.statusbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-2) var(--space-6);
  background: var(--color-surface); border-top: 1px solid var(--color-divider);
  font-size: var(--text-xs); color: var(--color-text-muted);
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--color-success); }

/* ── Toast ── */
.toast-container {
  position: fixed; bottom: var(--space-6); right: var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-2);
  z-index: 9999; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  font-size: var(--text-sm); pointer-events: auto; min-width: 220px;
  animation: toastIn .22s ease; transition: opacity .28s ease, transform .28s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.toast.out { opacity: 0; transform: translateY(6px); }
.toast-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.toast.success .toast-dot { background: var(--color-success); }
.toast.error   .toast-dot { background: var(--color-error); }
.toast.info    .toast-dot { background: var(--color-primary); }
.toast-msg { flex: 1; color: var(--color-text); }

/* ── Output Path hybrid ── */
.outpath-row { display: flex; gap: var(--space-2); align-items: stretch; }
.outpath-input-wrap { flex: 1; position: relative; display: flex; align-items: center; }
.outpath-icon { position: absolute; left: 10px; color: var(--color-text-faint); flex-shrink: 0; pointer-events: none; }
.outpath-input { padding-left: 2.1rem !important; padding-right: 2rem !important; }
.outpath-clear {
  position: absolute; right: 8px; width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--color-text-faint);
  transition: background var(--transition), color var(--transition);
}
.outpath-clear:hover { background: var(--color-error-highlight); color: var(--color-error); }
.outpath-browse { display: inline-flex; align-items: center; gap: 6px; flex-shrink: 0; align-self: stretch; height: auto; }
.outpath-hint  { font-size: var(--text-xs); color: var(--color-text-faint); margin-top: var(--space-2); line-height: 1.5; }
.outpath-hint.partial { color: var(--color-warning); font-style: italic; }
.outpath-hint.set     { color: var(--color-success); }

/* ── Batch card ── */
.batch-card { border-color: var(--color-primary); }
.batch-header { background: var(--color-primary-highlight); }
.batch-badge {
  font-size: .6rem; font-weight: 700; letter-spacing: .08em;
  padding: 2px 7px; border-radius: var(--radius-full);
  background: var(--color-primary); color: #fff; flex-shrink: 0;
}
.batch-tab-bar {
  display: flex; gap: 2px;
  background: var(--color-surface-dynamic); border-radius: var(--radius-md);
  padding: 3px; margin-bottom: var(--space-3); width: fit-content;
}
.batch-tab {
  padding: 4px var(--space-3); border-radius: calc(var(--radius-md) - 2px);
  font-size: var(--text-xs); font-weight: 500; color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}
.batch-tab.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }
.batch-code { max-height: 260px; overflow-y: auto; margin-bottom: var(--space-3); }
.tok-comment { color: var(--color-text-faint); font-style: italic; }
.btn-download {
  background: var(--color-success-highlight);
  color: var(--color-success);
  border-color: color-mix(in oklch, var(--color-success) 25%, transparent);
}
.btn-download:hover { filter: brightness(1.08); }

/* ── Scrollbar ── */
::-webkit-scrollbar          { width: 4px; height: 4px; }
::-webkit-scrollbar-track    { background: transparent; }
::-webkit-scrollbar-thumb    { background: var(--color-border); border-radius: var(--radius-full); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .workspace  { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .panel-side { border-left: none; border-top: 1px solid var(--color-divider); }
  .hero       { padding: var(--space-4) var(--space-4); }
  .hero-badges { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
