:root {
  --bg:               #f8fafc;
  --surface:          #ffffff;
  --sidebar-bg:       #eef2ff;
  --sidebar-border:   #c7d2fe;
  --text:             #0f172a;
  --text-secondary:   #64748b;
  --text-muted:       #94a3b8;
  --accent:           #1e40af;
  --accent-hover:     #1d3a9e;
  --accent-tint:      #eef2ff;
  --border:           #e2e8f0;
  --success:          #16a34a;
  --error:            #dc2626;
  --synthesis-bg:     #eff6ff;
  --synthesis-border: #bfdbfe;
  --radius:           8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.main { flex: 1; padding: 32px; max-width: 860px; }

/* Sidebar */
.sidebar-logo { color: var(--accent); font-weight: 700; font-size: 15px; margin-bottom: 16px; display: block; }
.sidebar-section { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 5px; }
.sidebar-link { display: block; padding: 6px 8px; border-radius: 6px; color: var(--text-secondary); font-size: 13px; }
.sidebar-link:hover { background: var(--border); text-decoration: none; }
.sidebar-link.active { background: var(--accent-tint); color: var(--accent); font-weight: 500; }

/* Buttons */
.btn { display: inline-block; padding: 8px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 600; cursor: pointer; border: none; text-align: center; font-family: var(--font); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-full { width: 100%; display: block; }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-input { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-family: var(--font); font-size: 14px; }
.form-input:focus { outline: none; border-color: var(--accent); }
textarea.form-input { resize: vertical; min-height: 80px; }
select.form-input { cursor: pointer; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { padding: 4px 12px; border-radius: 20px; font-size: 12px; border: 1.5px solid var(--border); background: var(--surface); color: var(--text-secondary); cursor: pointer; user-select: none; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.chip.model-on { background: var(--accent-tint); color: var(--accent); border-color: var(--accent); }
.chip.model-off { background: #f1f5f9; color: var(--text-muted); border-color: #cbd5e1; text-decoration: line-through; }
.chip.add-model { border-style: dashed; color: var(--text-muted); }

/* Synthesis */
.synthesis-panel { background: var(--synthesis-bg); border: 1.5px solid var(--synthesis-border); border-radius: var(--radius); padding: 20px; margin-bottom: 24px; }
.synthesis-panel .panel-label { font-size: 11px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }

/* Tabs */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; gap: 0; }
.tab { padding: 8px 14px; font-size: 13px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Progress list */
.progress-list { display: flex; flex-direction: column; gap: 8px; max-width: 440px; }
.progress-item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.progress-icon { font-size: 14px; width: 18px; text-align: center; color: var(--text-muted); }
.progress-model { flex: 1; font-size: 13px; color: var(--text); font-family: monospace; }
.progress-elapsed { font-size: 12px; color: var(--text-muted); }

/* History job cards */
.job-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 8px; display: flex; align-items: center; gap: 12px; color: var(--text); }
.job-card:hover { border-color: var(--accent); }
.job-card-question { flex: 1; font-size: 14px; font-weight: 500; color: var(--text); }
.job-card-question:hover { color: var(--accent); text-decoration: none; }
.job-card-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.job-card-actions { display: flex; align-items: center; gap: 6px; }
.move-select { padding: 4px 8px; font-size: 12px; border: 1.5px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text-secondary); cursor: pointer; transition: border-color .2s; }
.move-select:focus { outline: none; border-color: var(--accent); }
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 15px; line-height: 1; }
.btn-danger-icon { color: var(--text-muted); }
.btn-danger-icon:hover { background: #fee2e2; color: var(--error); }
.btn-danger { background: #fef2f2; color: var(--error); border: 1px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }

/* Results action bar */
.job-action-bar { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 20px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

/* Alerts */
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: var(--error); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }

/* Collapsible */
.collapsible-toggle { cursor: pointer; color: var(--text-muted); font-size: 13px; user-select: none; }
.collapsible-toggle:hover { color: var(--accent); }
.collapsible-body { display: none; margin-top: 8px; }
.collapsible-body.open { display: block; }

/* Model search dropdown */
.model-search-wrapper { position: relative; }
.model-dropdown { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,.08); max-height: 220px; overflow-y: auto; z-index: 100; display: none; }
.model-dropdown.open { display: block; }
.model-option { padding: 8px 12px; font-size: 13px; cursor: pointer; color: var(--text); }
.model-option:hover { background: var(--accent-tint); }
.model-option:hover .model-option-name { color: var(--accent); }
.model-option-name { font-weight: 500; margin-bottom: 2px; }
.model-option-sub { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }
.model-id-text { font-family: monospace; }
.model-price { margin-left: auto; }
.model-or-link { color: var(--accent); text-decoration: none; opacity: 0.7; }
.model-or-link:hover { opacity: 1; }

/* Misc */
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 24px; }
.badge { padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: #dcfce7; color: var(--success); }
.badge-error { background: #fee2e2; color: var(--error); }
.badge-pending { background: #f1f5f9; color: var(--text-muted); }
.meta-row { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; flex-wrap: wrap; }

/* ── Mobile nav bar (hidden on desktop) ─────────────────────────── */
.mobile-nav {
  display: none;
  position: sticky; top: 0; z-index: 200;
  background: var(--sidebar-bg); border-bottom: 1px solid var(--sidebar-border);
  padding: 12px 16px;
  align-items: center; gap: 12px;
}
.mobile-nav-logo { color: var(--accent); font-weight: 700; font-size: 15px; flex: 1; }
.mobile-nav-logo:hover { text-decoration: none; }
.hamburger {
  background: none; border: none; cursor: pointer;
  padding: 4px 6px; display: flex; flex-direction: column;
  gap: 5px; align-items: center; justify-content: center;
}
.hamburger span {
  display: block; width: 22px; height: 2px;
  background: var(--text); border-radius: 2px;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.35); z-index: 299;
}

/* ── Form row (replaces inline display:flex for 2-col inputs) ────── */
.form-row { display: flex; gap: 12px; margin-bottom: 22px; }
.form-row > div { flex: 1; }

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Show mobile nav */
  .mobile-nav { display: flex; }

  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed;
    left: -270px; top: 0; bottom: 0;
    width: 260px; z-index: 300;
    transition: left 0.25s ease;
    height: 100dvh;
    box-shadow: none;
  }
  .sidebar.open { left: 0; box-shadow: 4px 0 16px rgba(0,0,0,0.12); }
  .sidebar-backdrop.open { display: block; }

  /* Layout */
  .layout { flex-direction: column; }
  .main { padding: 16px; }

  /* Page titles */
  .page-title { font-size: 18px; }

  /* Job cards in history: wrap so question takes full row */
  .job-card { flex-wrap: wrap; gap: 6px; }
  .job-card-question { width: 100%; min-width: 0; }
  .job-card-meta { flex: 1; order: 2; }
  .job-card-actions { order: 3; width: 100%; justify-content: flex-start; }
  .job-card-actions .move-select { flex: 1; }

  /* Results page action bar: stack vertically */
  .job-action-bar { flex-direction: column; align-items: stretch; }
  .job-action-bar select { width: 100%; }
  .job-action-bar .btn { width: 100%; }

  /* Form row: stack on mobile */
  .form-row { flex-direction: column; gap: 0; margin-bottom: 0; }
  .form-row > div { margin-bottom: 18px; }

  /* Model search: full width, remove max-width cap */
  .model-search-row { max-width: 100% !important; }
  .model-search-wrapper { flex: 1; min-width: 0; }

  /* Progress list: full width */
  .progress-list { max-width: 100%; }

  /* Chips: wrap nicely */
  .chips { flex-wrap: wrap; }

  /* Settings form: full width on mobile */
  .card select,
  .card input[type="text"],
  .card input[type="number"],
  .card input[type="password"] { max-width: 100% !important; }
}

@media (max-width: 480px) {
  /* Extra small: tighten padding further */
  .main { padding: 12px; }
  .card { padding: 14px; }
  .synthesis-panel { padding: 14px; }
}
