/* ── Design tokens (Linear / Vercel inspired) ── */
:root,
[data-theme="dark"] {
  --bg: #09090b;
  --bg-elevated: #0f0f12;
  --surface: #18181b;
  --surface-hover: #1f1f23;
  --surface-active: #27272a;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-tertiary: #71717a;
  --accent: #fafafa;
  --accent-fg: #09090b;
  --accent-muted: rgba(250, 250, 250, 0.08);
  --brand: #6366f1;
  --brand-soft: rgba(99, 102, 241, 0.12);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 44, 68, 0.12);
  --warning: #f59e0b;
  --code-bg: #0c0c0e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.35);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --sidebar-w: 260px;
  --header-h: 52px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-hover: #f4f4f5;
  --surface-active: #e4e4e7;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.12);
  --text: #09090b;
  --text-secondary: #52525b;
  --text-tertiary: #a1a1aa;
  --accent: #18181b;
  --accent-fg: #fafafa;
  --accent-muted: rgba(0, 0, 0, 0.05);
  --brand-soft: rgba(99, 102, 241, 0.1);
  --code-bg: #f4f4f5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.08);
}

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

html { -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* subtle mesh background */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(99, 102, 241, 0.08), transparent),
    var(--bg);
}

[data-theme="light"] .app-shell {
  background:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(99, 102, 241, 0.06), transparent),
    var(--bg);
}

/* ── Header ── */
.topbar {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: linear-gradient(145deg, #6366f1 0%, #8b5cf6 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1) inset;
}

.logo svg { width: 16px; height: 16px; color: #fff; }

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.topbar-title span {
  color: var(--text-secondary);
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--accent-muted);
  border: 1px solid var(--border);
}

.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.input-sm {
  width: 180px;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-sm:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.input-sm::placeholder { color: var(--text-tertiary); }

/* ── Layout ── */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 0 8px 8px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--brand-soft);
  color: var(--text);
}

.nav-item.active svg { opacity: 1; color: var(--brand); }

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-footer p {
  font-size: 11px;
  color: var(--text-tertiary);
  line-height: 1.45;
}

.sidebar-footer strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ── Main content ── */
.content {
  overflow-y: auto;
  padding: 32px 40px 48px;
}

.panel { display: none; max-width: 1080px; animation: fadeIn 0.2s ease; }
.panel.active { display: block; }

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

.page-header {
  margin-bottom: 28px;
}

.page-eyebrow {
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 8px;
}

.page-header p {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 560px;
  line-height: 1.6;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-head h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-head p {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.card-body { padding: 20px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ── Form ── */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input, textarea, select {
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

textarea {
  min-height: 128px;
  resize: vertical;
  line-height: 1.55;
}

textarea.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition), background var(--transition);
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover:not(:disabled) { opacity: 0.9; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid transparent;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-sm { padding: 5px 10px; font-size: 12px; }

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* ── Code / result blocks ── */
.code-block {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 16px;
}

.code-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.code-block pre,
.result-box {
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--code-bg);
  color: var(--text-secondary);
  max-height: 280px;
  overflow-y: auto;
  margin: 0;
}

.result-box.empty-state {
  color: var(--text-tertiary);
  font-style: italic;
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-muted {
  background: var(--accent-muted);
  color: var(--text-tertiary);
}

.badge-brand {
  background: var(--brand-soft);
  color: #818cf8;
}

/* ── List items ── */
.item-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }

.list-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color var(--transition);
}

.list-item:hover { border-color: var(--border-strong); }

.list-item-content { flex: 1; min-width: 0; }

.list-item-content pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.list-item-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
  font-weight: 500;
}

.source-score {
  font-variant-numeric: tabular-nums;
  color: var(--brand);
}

.col-list { display: flex; flex-direction: column; gap: 4px; }

.col-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition), border-color var(--transition);
}

.col-chip:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.col-chip.active {
  background: var(--brand-soft);
  border-color: rgba(99, 102, 241, 0.25);
  color: var(--text);
}

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
  font-size: 13px;
}

.empty-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  opacity: 0.35;
}

/* ── Toast ── */
.toast-host {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  animation: slideUp 0.25s ease;
  max-width: 320px;
}

.toast.error { border-color: rgba(239, 68, 68, 0.3); color: var(--danger); }
.toast.success { border-color: rgba(34, 197, 94, 0.3); }

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

/* ── Spinner ── */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Welcome / Home ── */
.welcome-hero h1 {
  font-size: 28px;
  max-width: 640px;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.welcome-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.welcome-card:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  transform: translateY(-2px);
}

.welcome-icon { font-size: 24px; margin-bottom: 10px; }
.welcome-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.welcome-card p { color: var(--text-secondary); font-size: 13px; line-height: 1.5; }
.welcome-cta { display: inline-block; margin-top: 12px; font-size: 12px; color: var(--brand); font-weight: 500; }

.welcome-principles .principle-row {
  display: flex;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.welcome-principles .principle-row:last-child { border-bottom: none; }
.welcome-principles strong { min-width: 140px; color: var(--text); }
.welcome-principles span { color: var(--text-secondary); }

@media (max-width: 900px) {
  .welcome-grid { grid-template-columns: 1fr; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: 20px 16px 32px; }
  .page-header h1 { font-size: 22px; }
  .row { grid-template-columns: 1fr; }
  .input-sm { width: 120px; }
}
