/* ============================================================
   Design tokens — precision instrument
============================================================ */
:root {
  /* Depth stack — blue-black, not neutral-black */
  --depth-0:  #060912;   /* deepest: sidebar */
  --depth-1:  #090e1a;   /* base bg */
  --depth-2:  #0f1626;   /* surface: panels, cards */
  --depth-3:  #172033;   /* elevated: inputs, tags */
  --depth-4:  #1e2b42;   /* floating: dropdowns, tooltips */

  /* Borders — blue-tinted, not grey */
  --border:       #243050;
  --border-muted: #172033;
  --border-dim:   #1a2540;

  /* Text */
  --text:    #eef2ff;   /* slightly blue-white — intentional */
  --text-2:  #c4cce8;
  --muted:   #7585a8;
  --muted-2: #3f4f70;

  /* Accent — custom teal, derived scale */
  --accent:       #2dd4bf;
  --accent-dim:   #1fb8a5;
  --accent-deep:  #14917f;
  --accent-faint: rgba(45, 212, 191, 0.07);
  --accent-glow:  rgba(45, 212, 191, 0.20);
  --accent-ring:  rgba(45, 212, 191, 0.28);

  /* Status */
  --ok:  #34d399;
  --err: #f87171;

  /* Typography */
  --font-display: 'Syne', system-ui, sans-serif;
  --font-body:    'Plus Jakarta Sans', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', 'SFMono-Regular', monospace;

  /* Layered shadows — blue-tinted, not grey */
  --shadow-sm:
    0 1px 2px rgba(6, 9, 18, 0.5),
    0 2px 6px rgba(6, 9, 18, 0.3);
  --shadow-md:
    0 2px 4px rgba(6, 9, 18, 0.5),
    0 8px 24px rgba(6, 9, 18, 0.4),
    0 1px 2px rgba(6, 9, 18, 0.3);
  --shadow-accent:
    0 0 0 1px var(--accent-ring),
    0 4px 20px var(--accent-glow);

  /* Spacing scale */
  --sp-1: 4px;   --sp-2: 8px;   --sp-3: 12px;
  --sp-4: 16px;  --sp-5: 20px;  --sp-6: 24px;

  /* Radius */
  --r-xs: 4px;
  --r-sm: 6px;
  --r:    8px;
  --r-lg: 12px;

  /* Spring easing */
  --spring: cubic-bezier(0.16, 1, 0.3, 1);
  --ease:   cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

/* Grain texture overlay */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.032;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='256' height='256' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 256px 256px;
  mix-blend-mode: screen;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  margin: 0;
  background: var(--depth-1);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Subtle top glow on main bg */
  background-image:
    radial-gradient(ellipse 70% 40% at 65% 0%,
      rgba(45, 212, 191, 0.04) 0%, transparent 60%);
}

/* ============================================================
   App shell
============================================================ */
.app-shell {
  display: grid;
  grid-template-columns: 228px 1fr;
  min-height: 100vh;
}

/* ============================================================
   Sidebar
============================================================ */
.sidebar {
  background: var(--depth-0);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  padding: var(--sp-4) var(--sp-2) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.sidebar::-webkit-scrollbar { display: none; }

/* Atmospheric glow — accent-tinted radial at top */
.sidebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 220px;
  background: radial-gradient(ellipse 140% 60% at 50% -10%,
    rgba(45, 212, 191, 0.09) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.sidebar > * { position: relative; z-index: 1; }

/* Brand — Syne, tight tracking */
.brand {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.03em;
  padding: var(--sp-2) var(--sp-2) var(--sp-4);
  border-bottom: 1px solid var(--border-muted);
  margin-bottom: var(--sp-2);
  line-height: 1.2;
}

.brand span {
  display: block;
  font-size: 9.5px;
  font-family: var(--font-mono);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-top: 3px;
  opacity: 0.9;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: var(--sp-2);
}

.section-title,
.sidebar-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted-2);
  padding: var(--sp-2) var(--sp-2) var(--sp-1);
  font-weight: 500;
}

.env-select {
  width: 100%;
  padding: 7px 26px 7px var(--sp-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background-color: var(--depth-3);
  color: var(--text-2);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%233f4f70' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 9px;
  transition: border-color 180ms var(--ease), background-color 180ms var(--ease);
  margin: 2px 0;
}

.env-select:focus,
.env-select:hover {
  border-color: var(--accent);
  background-color: var(--depth-4);
  outline: none;
  color: var(--text);
}

.env-select option {
  background: var(--depth-3);
  color: var(--text);
}

.mode-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* Nav items — slide-in hover, glow on active */
.mode-item,
.nav-item {
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  border-left: 2px solid transparent;
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.01em;
  box-shadow: none;
  transform: translateX(0);
  transition:
    color 160ms var(--ease),
    background-color 160ms var(--ease),
    border-left-color 160ms var(--ease),
    transform 200ms var(--spring);
}

.mode-item:hover,
.nav-item:hover {
  background: var(--depth-2);
  color: var(--text-2);
  transform: translateX(2px);
}

.mode-item.active,
.nav-item.active {
  background: linear-gradient(to right,
    rgba(45, 212, 191, 0.13) 0%,
    rgba(45, 212, 191, 0.03) 100%);
  border-left-color: var(--accent);
  color: var(--text);
  box-shadow:
    inset 2px 0 12px rgba(45, 212, 191, 0.04);
  transform: translateX(0);
}

.mode-item:focus-visible,
.nav-item:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: -2px;
}

.mode-item-sub {
  padding-left: 22px;
  font-size: 12px;
  opacity: 0.9;
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--sp-3) 0 0;
  border-top: 1px solid var(--border-muted);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--sp-2);
}

.sidebar-footer button.secondary {
  width: auto;
  flex-shrink: 0;
}

.sidebar-footer button.secondary {
  background: transparent;
  border: 1px solid var(--border-dim);
  color: var(--muted-2);
  font-size: 12px;
  padding: 6px 12px;
  font-family: var(--font-body);
  font-weight: 500;
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: none;
  letter-spacing: -0.01em;
  transition:
    border-color 160ms var(--ease),
    color 160ms var(--ease),
    background-color 160ms var(--ease);
}

.sidebar-footer button.secondary:hover {
  border-color: var(--muted);
  color: var(--text-2);
  background-color: var(--depth-2);
}

.sidebar-footer button.secondary:active {
  transform: translateY(1px);
}

/* ============================================================
   Main area
============================================================ */
.main {
  padding: var(--sp-6) 40px 80px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  align-items: center;
  min-height: 100vh;
}

/* Page header — accent left border, subtle shadow */
.page-header {
  width: 80%;
  max-width: 960px;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 10px var(--sp-4) 10px 14px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--r-lg);
  background: var(--depth-2);
  box-shadow: var(--shadow-sm);
}

.page-header-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.page-header-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}

/* ============================================================
   Panels
============================================================ */
.panel {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--depth-2);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.panel.is-hidden,
.main-section.is-hidden { display: none; }

.config-panel { width: 80%; max-width: 960px; }
.main-section  { width: 80%; max-width: 960px; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border-muted);
}

.panel-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.03em;
}

.config-body { display: grid; gap: 14px; }

.field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 6px;
  font-weight: 500;
}

/* ============================================================
   Layout grids
============================================================ */
.row3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-4);
}

.row3 select { width: 100%; }

.row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
}

.row-project-actions {
  align-items: end;
  grid-template-columns: 1fr auto;
  margin-top: var(--sp-2);
}

.row-project-actions .muted { align-self: end; }
.row-project-actions button { justify-self: end; }

/* ============================================================
   Form controls — consistent depth-3 bg
============================================================ */
input,
select,
textarea,
button {
  font-family: var(--font-body);
  font-size: 13px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  padding: 7px 10px;
  background: var(--depth-3);
  color: var(--text);
  transition:
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease),
    background-color 160ms var(--ease);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--depth-4);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

input:disabled,
select:disabled,
textarea:disabled {
  background: var(--depth-2);
  color: var(--muted-2);
  cursor: not-allowed;
  opacity: 0.6;
}

/* ============================================================
   Buttons — full interactive states
============================================================ */
button {
  cursor: pointer;
  font-weight: 600;
  font-size: 12.5px;
  letter-spacing: -0.01em;
  border-radius: var(--r-sm);
  padding: 7px 14px;
  line-height: 20px;
  transition:
    background-color 160ms var(--ease),
    border-color 160ms var(--ease),
    box-shadow 200ms var(--ease),
    transform 120ms var(--spring),
    color 160ms var(--ease);
}

/* Primary — solid teal, dark text, glow on hover */
button.primary {
  background: var(--accent);
  border: 1px solid var(--accent-dim);
  color: #060912;
  font-weight: 700;
  box-shadow:
    0 1px 3px rgba(45, 212, 191, 0.20),
    0 0 0 0 transparent;
}

button.primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-deep);
  box-shadow:
    0 2px 8px rgba(45, 212, 191, 0.30),
    0 0 20px rgba(45, 212, 191, 0.15);
}

button.primary:active {
  transform: translateY(1px) scale(0.99);
  box-shadow: 0 1px 4px rgba(45, 212, 191, 0.15);
}

button.primary:disabled {
  background: var(--depth-3);
  border-color: var(--border);
  color: var(--muted-2);
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button.primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Secondary — depth-3 bg, visible border */
button.secondary {
  background: var(--depth-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
}

button.secondary:hover {
  background: var(--depth-4);
  border-color: var(--muted);
  color: var(--text);
}

button.secondary:active {
  transform: translateY(1px) scale(0.99);
  box-shadow: none;
}

button.secondary:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

/* ============================================================
   Query input card — glow on focus
============================================================ */
.input-card {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--depth-2);
  padding: var(--sp-4);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition:
    border-color 200ms var(--ease),
    box-shadow 200ms var(--ease);
}

/* Activated when textarea inside is focused — via JS fallback: .input-card:focus-within */
.input-card:focus-within {
  border-color: var(--accent-deep);
  box-shadow:
    var(--shadow-sm),
    0 0 0 1px var(--accent-faint),
    0 0 32px rgba(45, 212, 191, 0.06);
}

.input-card label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 6px;
  font-weight: 500;
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: none;
  line-height: 1.65;
  border: 1px solid var(--border-muted);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  background: var(--depth-3);
  font-size: 13.5px;
  color: var(--text);
  font-family: var(--font-body);
}

textarea:focus {
  outline: none;
  border-color: var(--border-dim);
  box-shadow: none;
}

textarea::placeholder { color: var(--muted-2); }

/* ============================================================
   Controls bar
============================================================ */
.controls {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
  flex-wrap: wrap;
}

.controls.is-hidden { display: none; }

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  cursor: pointer;
  user-select: none;
  transition: color 160ms var(--ease);
}

.checkbox:hover { color: var(--text-2); }

.checkbox input {
  width: 14px;
  height: 14px;
  margin: 0;
  border-radius: 3px;
  accent-color: var(--accent);
  cursor: pointer;
  padding: 0;
  box-shadow: none;
  border: 1px solid var(--border);
  background: var(--depth-3);
}

.status {
  margin-top: var(--sp-2);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.status.ok  { color: var(--ok); }
.status.err { color: var(--err); }

/* ============================================================
   Results — spring-eased entrance, teal accent reveal
============================================================ */
.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.result-connector {
  height: 0;
  width: 0;
  margin: 4px auto -4px;
  border-left: 1px dashed var(--border);
  opacity: 0;
}

.result-connector.is-animating {
  animation: connectorIn 300ms var(--spring) forwards;
}

@keyframes connectorIn {
  from { height: 0; opacity: 0; }
  to   { height: 32px; opacity: 1; }
}

.result-card {
  border: 1px solid var(--border);
  border-top: 2px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--depth-2);
  padding: var(--sp-4);
  opacity: 0;
  transform: translateY(8px);
  box-shadow: var(--shadow-sm);
}

.result-card.is-animating {
  animation: cardReveal 360ms var(--spring) forwards;
}

@keyframes cardReveal {
  from {
    border-top-color: var(--border);
    box-shadow: var(--shadow-sm);
  }
  to {
    border-top-color: var(--accent);
    box-shadow:
      var(--shadow-md),
      0 0 0 0 transparent,
      0 -1px 24px rgba(45, 212, 191, 0.07);
  }
}

.result-card.is-visible {
  animation: resultIn 320ms var(--spring) forwards;
}

@keyframes resultIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: var(--sp-3);
  padding-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border-muted);
}

.result-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  letter-spacing: -0.02em;
}

.copy-btn {
  border: 1px solid var(--border-dim);
  background: var(--depth-3);
  color: var(--muted);
  padding: 3px 10px;
  border-radius: var(--r-sm);
  font-size: 10.5px;
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: 0.03em;
  transition:
    color 160ms var(--ease),
    border-color 160ms var(--ease),
    background-color 160ms var(--ease);
}

.copy-btn:hover {
  color: var(--accent);
  border-color: var(--accent-deep);
  background: var(--accent-faint);
}

/* Markdown content */
.result-body h1,
.result-body h2,
.result-body h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  margin: 16px 0 6px;
  color: var(--text);
  letter-spacing: -0.02em;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-muted);
}

.result-body p {
  margin: 8px 0;
  line-height: 1.7;
  color: var(--text-2);
}

.result-body ul,
.result-body ol { margin: 8px 0 8px 20px; padding: 0; }

.result-body li {
  margin: 4px 0;
  color: var(--text-2);
  line-height: 1.65;
}

.result-body code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--depth-3);
  padding: 1px 5px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-dim);
  color: var(--accent);
}

.result-body pre {
  background: var(--depth-3);
  padding: 12px 14px;
  border-radius: var(--r);
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: pre-wrap;
  margin: 10px 0;
  box-shadow: inset 0 1px 8px rgba(6, 9, 18, 0.3);
}

.result-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text-2);
}

/* ============================================================
   Sources
============================================================ */
.sources {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border-muted);
}

.sources-title {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 10px;
  font-weight: 500;
}

.source-item {
  padding: 9px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-muted);
  background: var(--depth-3);
  margin-bottom: 6px;
  transition: border-color 160ms var(--ease);
}

.source-item:hover { border-color: var(--border); }
.source-item:last-child { margin-bottom: 0; }

.source-item .source-label {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 3px;
  color: var(--text);
}

.source-excerpt,
.source-meta {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-2);
  background: var(--depth-1);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-sm);
  padding: 6px 9px;
  white-space: pre-wrap;
  word-break: break-word;
}

.source-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
}

/* ============================================================
   Utility
============================================================ */
.muted {
  color: var(--muted);
  font-size: 12px;
}

.is-hidden { display: none !important; }

.visually-hidden {
  position: absolute !important;
  height: 1px; width: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  white-space: nowrap;
}

/* ============================================================
   History
============================================================ */
.history-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  border: 1px solid var(--border-muted);
  border-radius: var(--r);
  padding: 10px 12px;
  background: var(--depth-3);
  transition:
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease);
  cursor: default;
}

.history-item:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.history-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.history-item-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted-2);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  letter-spacing: 0.02em;
}

.history-item-question {
  font-weight: 500;
  font-size: 12.5px;
  color: var(--text-2);
  margin-bottom: 5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}

.history-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.history-detail {
  border: 1px solid var(--border-muted);
  border-radius: var(--r);
  padding: 14px;
  background: var(--depth-3);
  min-height: 240px;
}

.history-detail h3 {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 500;
  margin: 14px 0 6px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.10em;
}

.history-detail h3:first-child { margin-top: 0; }

.history-detail pre {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--depth-1);
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-muted);
  margin: 0 0 8px;
  color: var(--text-2);
}

.history-empty {
  color: var(--muted-2);
  font-size: 13px;
  font-style: italic;
  font-family: var(--font-body);
}

.history-hint {
  margin-top: 10px;
  padding: 9px 12px;
  border-radius: var(--r);
  border: 1px solid rgba(45, 212, 191, 0.22);
  background: var(--accent-faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--accent);
}

.history-hint.is-hidden { display: none; }

.history-hint button.secondary {
  font-size: 11.5px;
  padding: 4px 10px;
  border-color: rgba(45, 212, 191, 0.25);
  background: rgba(45, 212, 191, 0.06);
  color: var(--accent);
}

.history-hint button.secondary:hover {
  background: rgba(45, 212, 191, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================================
   Batch panel
============================================================ */
.batch-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.bsm-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-2);
  user-select: none;
  transition: color 250ms var(--ease);
}
.bsm-label-inactive { color: var(--muted-2); }

/* ============================================================
   Mode hero
============================================================ */
.mode-hero {
  text-align: center;
  padding: var(--sp-5) var(--sp-4) var(--sp-3);
  pointer-events: none;
  user-select: none;
}
.mode-hero-title {
  font-size: clamp(20px, 2.6vw, 28px);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.025em;
  margin: 0 0 10px;
  line-height: 1.2;
}
.mode-hero-title em {
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
}
.mode-hero-desc {
  font-size: 13.5px;
  color: var(--muted);
  margin: 0 auto;
  max-width: 460px;
  line-height: 1.6;
}

/* ============================================================
   Evidence panel
============================================================ */
.ev-card { margin-bottom: 12px; }
.ev-sm-btn { padding:5px 12px; font-size:13px; width:auto; }
/* Drop zone */
.ev-dropzone {
  display:flex; align-items:center; gap:12px;
  margin-top:8px; padding:12px 16px;
  border:1.5px dashed var(--border);
  border-radius:8px;
  background:var(--depth-3);
  cursor:pointer;
  transition:border-color 150ms, background 150ms;
}
.ev-dropzone:hover, .ev-dropzone.drag-over {
  border-color:var(--accent);
  background:rgba(45,212,191,.06);
}
.ev-dropzone-icon {
  color:var(--accent);
  flex-shrink:0;
  opacity:.8;
}
.ev-dropzone-text {
  display:flex; align-items:center; gap:8px;
  font-size:13px; color:var(--muted);
}
.ev-dropzone-label { white-space:nowrap; }
.ev-choose-btn {
  padding:3px 11px; font-size:12px; font-weight:600;
  background:var(--depth-4); color:var(--text-2);
  border:1px solid var(--border); border-radius:5px;
  cursor:pointer; transition:border-color 120ms, color 120ms;
}
.ev-choose-btn:hover { border-color:var(--accent); color:var(--accent); }
/* Selected file row */
.ev-upload-actions {
  display:flex; align-items:center; gap:8px; margin-top:8px;
}
.ev-selected-name {
  flex:1; font-size:13px; color:var(--text-2);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
  padding:4px 8px; background:var(--depth-3);
  border:1px solid var(--border); border-radius:6px;
}
.ev-clear-btn {
  background:none; border:none; color:var(--muted); font-size:14px;
  cursor:pointer; padding:4px 6px; line-height:1; border-radius:4px;
  flex-shrink:0;
}
.ev-clear-btn:hover { color:var(--err); }
.ev-table { width:100%; border-collapse:collapse; font-size:13px; }
.ev-table th { text-align:left; font-size:11px; color:var(--muted); text-transform:uppercase; letter-spacing:.04em; padding:6px 8px; border-bottom:1px solid var(--border); white-space:nowrap; }
.ev-table td { padding:7px 8px; border-bottom:1px solid var(--border); vertical-align:middle; }
.ev-table tr:last-child td { border-bottom:none; }
.ev-table td input[type=text] { padding:4px 7px; font-size:12px; }
.ev-status-ready      { color:var(--ok); font-weight:600; }
.ev-status-processing { color:var(--accent); }
.ev-status-removed,
.ev-status-stored     { color:var(--muted); }
.ev-status-unsupported,
.ev-status-unknown    { color:var(--err); }
.ev-subtab-bar { display:flex; gap:4px; margin-bottom:14px; padding-bottom:8px; border-bottom:1px solid var(--border); }
.ev-subtab { background:none; border:none; border-bottom:2px solid transparent; padding:5px 12px; font-size:13px; font-weight:600; color:var(--muted); cursor:pointer; border-radius:4px 4px 0 0; transition:color 120ms; }
.ev-subtab.active { color:var(--accent); border-bottom-color:var(--accent); }
.ev-subtab:hover:not(.active) { color:var(--text); }
.ev-sync-bar { padding:8px 12px; border-radius:6px; font-size:13px; margin-bottom:14px; background:var(--depth-3); border:1px solid var(--border); color:var(--text); }
.ev-sync-badge { display:inline-block; padding:1px 7px; border-radius:10px; font-size:11px; font-weight:700; }
.ev-sync-ok    { background:rgba(52,211,153,.18); color:#6ee7b7; }
.ev-sync-miss  { background:rgba(251,191,36,.15); color:#fcd34d; }
.ev-sync-stale { background:rgba(251,146,60,.15); color:#fdba74; }
.ev-sync-orphan{ background:rgba(248,113,113,.15); color:#fca5a5; }
/* Filter bar */
.ev-filter-bar { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-bottom:12px; padding:10px 0 0; }
.ev-filter-bar input[type=text] { flex:1; min-width:140px; padding:5px 9px; font-size:13px; }
.ev-filter-bar select { padding:5px 9px; font-size:13px; }
/* Pagination controls */
.ev-pagination { display:flex; gap:8px; align-items:center; margin-top:10px; }
.ev-page-info { color:var(--muted); font-size:13px; }
/* Sortable column headers */
.ev-table th.ev-sortable { cursor:pointer; user-select:none; white-space:nowrap; }
.ev-table th.ev-sortable:hover { color:var(--text); }
.ev-table th.ev-sort-asc::after  { content:" ▲"; font-size:9px; }
.ev-table th.ev-sort-desc::after { content:" ▼"; font-size:9px; }
/* Metadata modal */
.ev-modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:9999; display:flex; align-items:center; justify-content:center; }
.ev-modal { background:var(--depth-2); color:var(--text); border:1px solid var(--border); border-radius:8px; padding:24px; min-width:320px; max-width:560px; width:90%; max-height:80vh; overflow-y:auto; position:relative; box-shadow:0 8px 32px rgba(0,0,0,.45); }
.ev-modal-close { position:absolute; top:10px; right:12px; background:none; border:none; font-size:18px; cursor:pointer; color:var(--muted); line-height:1; padding:4px; }
.ev-modal h3 { margin:0 32px 16px 0; font-size:15px; }
.ev-meta-row { display:flex; gap:12px; padding:5px 0; border-bottom:1px solid var(--border); font-size:13px; }
.ev-meta-row:last-child { border-bottom:none; }
.ev-meta-key { color:var(--muted); min-width:150px; flex-shrink:0; font-size:12px; }
.ev-meta-val { min-width:0; word-break:break-all; }

/* ============================================================
   Light theme — override tokens on [data-theme="light"]
============================================================ */
[data-theme="light"] {
  --depth-0:  #e8edf7;   /* sidebar */
  --depth-1:  #f0f3fb;   /* base bg */
  --depth-2:  #ffffff;   /* surface: panels, cards */
  --depth-3:  #f0f3fa;   /* elevated: inputs, tags */
  --depth-4:  #e5e9f5;   /* floating: dropdowns, tooltips */

  --border:       #cdd5e8;
  --border-muted: #dde2f0;
  --border-dim:   #d5dcee;

  --text:    #111827;
  --text-2:  #374266;
  --muted:   #6b7a99;
  --muted-2: #9aa3bc;

  --accent-faint: rgba(45, 212, 191, 0.10);
  --accent-glow:  rgba(45, 212, 191, 0.22);
  --accent-ring:  rgba(45, 212, 191, 0.32);

  --ok:  #059669;
  --err: #dc2626;

  --shadow-sm:
    0 1px 2px rgba(0, 20, 80, 0.06),
    0 2px 6px rgba(0, 20, 80, 0.04);
  --shadow-md:
    0 2px 4px rgba(0, 20, 80, 0.06),
    0 8px 24px rgba(0, 20, 80, 0.08),
    0 1px 2px rgba(0, 20, 80, 0.04);
  --shadow-accent:
    0 0 0 1px var(--accent-ring),
    0 4px 20px var(--accent-glow);
}

[data-theme="light"] .ev-sync-ok    { background:#d1fae5; color:#065f46; }
[data-theme="light"] .ev-sync-miss  { background:#fef3c7; color:#92400e; }
[data-theme="light"] .ev-sync-stale { background:#ffedd5; color:#9a3412; }
[data-theme="light"] .ev-sync-orphan{ background:#fee2e2; color:#991b1b; }
[data-theme="light"] .ev-modal      { box-shadow:0 8px 32px rgba(0,0,0,.12); }

[data-theme="light"] body {
  background-image:
    radial-gradient(ellipse 70% 40% at 65% 0%,
      rgba(45, 212, 191, 0.07) 0%, transparent 60%);
}

[data-theme="light"] body::after {
  mix-blend-mode: multiply;
  opacity: 0.02;
}

[data-theme="light"] .sidebar::before {
  background: radial-gradient(ellipse 140% 60% at 50% -10%,
    rgba(45, 212, 191, 0.06) 0%, transparent 70%);
}

/* ============================================================
   Theme toggle — pill-style sun/moon switch
============================================================ */
.theme-toggle {
  display: flex;
  width: 64px;
  height: 32px;
  padding: 4px;
  border-radius: 16px;
  cursor: pointer;
  position: relative;
  align-items: center;
  background: #09101a;
  border: 1px solid #27272a;
  transition:
    background 300ms var(--ease),
    border-color 300ms var(--ease);
  outline: none;
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}

.tt-thumb {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #27272a;
  color: #ffffff;
  flex-shrink: 0;
  transition:
    transform 300ms var(--ease),
    background 300ms var(--ease),
    color 300ms var(--ease);
  transform: translateX(0);
  z-index: 1;
  position: relative;
}

.tt-track-icon {
  position: absolute;
  right: 8px;
  display: flex;
  align-items: center;
  color: #6b7280;
  transition:
    color 300ms var(--ease),
    right 300ms var(--ease),
    left 300ms var(--ease);
}

/* Dark mode: thumb shows moon, track shows sun */
.tt-thumb .tt-sun  { display: none; }
.tt-thumb .tt-moon { display: block; }
.tt-track-icon .tt-sun  { display: block; }
.tt-track-icon .tt-moon { display: none; }

/* Light mode: thumb shows sun on right, track shows moon on left */
.theme-toggle.is-light {
  background: #ffffff;
  border-color: #e4e4e7;
}

.theme-toggle.is-light .tt-thumb {
  transform: translateX(32px);
  background: #e5e7eb;
  color: #374151;
}

.theme-toggle.is-light .tt-track-icon {
  right: auto;
  left: 8px;
  color: #000000;
}

.theme-toggle.is-light .tt-thumb .tt-sun  { display: block; }
.theme-toggle.is-light .tt-thumb .tt-moon { display: none; }
.theme-toggle.is-light .tt-track-icon .tt-sun  { display: none; }
.theme-toggle.is-light .tt-track-icon .tt-moon { display: block; }

/* ============================================================
   History toggle — keep-history pill switch
============================================================ */
.ht-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-left: auto;
}
.hist-toggle {
  display: flex;
  width: 52px;
  height: 28px;
  padding: 3px;
  border-radius: 14px;
  cursor: pointer;
  position: relative;
  align-items: center;
  background: var(--depth-3);
  border: 1px solid var(--border);
  transition: background 250ms var(--ease), border-color 250ms var(--ease);
  outline: none;
  flex-shrink: 0;
}
.hist-toggle:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 2px; }
.ht-thumb {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--depth-4);
  color: var(--muted);
  flex-shrink: 0;
  transition: transform 250ms var(--ease), background 250ms var(--ease), color 250ms var(--ease);
  transform: translateX(0);
  z-index: 1;
  position: relative;
}
.ht-track-icon {
  position: absolute;
  right: 7px;
  display: flex;
  align-items: center;
  color: var(--muted-2);
  transition: color 250ms var(--ease), right 250ms var(--ease), left 250ms var(--ease);
}
/* OFF: thumb left shows slash, track right shows clock */
.ht-thumb   .ht-icon-on  { display: none; }
.ht-thumb   .ht-icon-off { display: block; }
.ht-track-icon .ht-icon-on  { display: block; }
.ht-track-icon .ht-icon-off { display: none; }
/* ON */
.hist-toggle.is-on { background: rgba(45,212,191,.14); border-color: var(--accent); }
.hist-toggle.is-on .ht-thumb {
  transform: translateX(24px);
  background: var(--accent);
  color: #032a27;
}
.hist-toggle.is-on .ht-track-icon { right: auto; left: 7px; color: var(--muted); }
.hist-toggle.is-on .ht-thumb   .ht-icon-on  { display: block; }
.hist-toggle.is-on .ht-thumb   .ht-icon-off { display: none; }
.hist-toggle.is-on .ht-track-icon .ht-icon-on  { display: none; }
.hist-toggle.is-on .ht-track-icon .ht-icon-off { display: block; }
.ht-label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  user-select: none;
}

/* ============================================================
   Responsive
============================================================ */
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar::before { display: none; }
  .history-grid { grid-template-columns: 1fr; }
  .row3, .row { grid-template-columns: 1fr; }
  .checkbox { margin-left: 0; }
  .main-section, .config-panel, .page-header { width: 100%; }
  .main { padding: var(--sp-4) var(--sp-4) 60px; }
}
