:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-2: #172033;
  --border: #334155;
  --text: #f8fafc;
  --text-2: #e2e8f0;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --low: #10b981;
  --mod: #f59e0b;
  --high: #ef4444;
  --ins: rgba(16, 185, 129, 0.22);
  --del: rgba(239, 68, 68, 0.22);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.5;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 14px;
  display: flex; flex-direction: column; min-height: 100vh;
}
h1 { font-size: 1.15rem; margin: 0; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; }
h3:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.7rem; letter-spacing: 0.06em; }
.mono { font-family: var(--mono); }
.badge { font-size: 0.72rem; background: #064e3b; color: #6ee7b7; padding: 0.2rem 0.6rem; border-radius: 999px; border: 1px solid #059669; white-space: nowrap; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--card-2);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 0.75rem; align-items: center; }
.top-actions, .top-metrics { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.gauge { display: flex; gap: 0.5rem; align-items: center; }
.gauge-ring {
  --p: 0; --c: var(--border);
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--border) 0);
  position: relative; font-weight: 700; font-size: 0.8rem;
}
.gauge-ring::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--card-2); }
.gauge-ring span { position: relative; }
.gauge-level { font-weight: 700; font-size: 0.85rem; }

/* Buttons and inputs */
button, .btn {
  font: inherit; border: none; border-radius: 6px; padding: 0.5rem 1rem; cursor: pointer; font-weight: 600;
  background: #334155; color: var(--text); display: inline-flex; align-items: center; gap: 0.4rem;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border: 1px dashed var(--border); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }
.btn-danger { background: #7f1d1d; color: #fecaca; }
.btn-ok { background: #065f46; color: #d1fae5; }
.input, textarea, select {
  font: inherit; background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.45rem 0.65rem; width: 100%;
}
textarea { resize: vertical; }
.input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
label.field { display: block; margin: 0.5rem 0; }
label.field > span { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.2rem; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

.pill { border-radius: 999px; padding: 0.3rem 0.75rem; font-size: 0.75rem; border: 1px solid var(--border); background: var(--card); }
.pill-ready { border-color: #059669; color: #6ee7b7; background: #064e3b; }
.pill-loading { border-color: #b45309; color: #fde68a; background: #451a03; }
.pill-unavailable, .pill-error { border-color: #991b1b; color: #fecaca; background: #450a0a; }

/* Alerts */
.alerts { padding: 0 1.25rem; }
.alerts:empty { display: none; }
.alert-box {
  background: rgba(239, 68, 68, 0.15); border: 1px solid var(--high); color: #fca5a5;
  padding: 0.6rem 0.9rem; border-radius: 6px; margin-top: 0.6rem; font-size: 0.85rem;
}
.alert-warn { background: rgba(245, 158, 11, 0.12); border-color: var(--mod); color: #fde68a; }
.alert-info { background: var(--accent-soft); border-color: var(--accent); color: #bfdbfe; }

/* Studio layout */
.studio {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 1rem;
  padding: 1rem 1.25rem; min-height: 0;
}
@media (max-width: 1100px) { .studio { grid-template-columns: 1fr; } }
.pane { background: var(--card-2); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; min-width: 0; display: flex; flex-direction: column; }
.pane-left { gap: 0.75rem; }
.pane-head { display: flex; gap: 0.75rem; align-items: center; }
.editor { min-height: 220px; height: 32vh; font-size: 0.92rem; line-height: 1.55; }
.scan-meta:empty { display: none; }
.scan-meta { font-size: 0.8rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.4rem; }

/* Heatmap */
.chunk-list { display: flex; flex-direction: column; gap: 0.75rem; overflow-y: auto; max-height: 60vh; padding-right: 0.25rem; }
.chunk-item { background: var(--card); border-left: 5px solid var(--border); border-radius: 6px; padding: 0.8rem 1rem; }
.chunk-item.selected { outline: 2px solid var(--accent); }
.chunk-low { border-left-color: var(--low); }
.chunk-mod { border-left-color: var(--mod); box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.25); }
.chunk-high { border-left-color: var(--high); box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.3); }
.chunk-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.4rem; font-family: var(--mono); }
.chunk-text { font-size: 0.88rem; color: var(--text-2); max-height: 7.5em; overflow: hidden; position: relative; }
.chunk-text.expanded { max-height: none; }
.chunk-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.score-low { color: var(--low); } .score-mod { color: var(--mod); } .score-high { color: var(--high); }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 0.75rem; }
.tab { background: transparent; color: var(--muted); border-radius: 6px 6px 0 0; padding: 0.45rem 0.7rem; font-size: 0.82rem; }
.tab.active { color: var(--text); background: var(--card); box-shadow: inset 0 -2px 0 var(--accent); }
.tab-panel { display: none; overflow-y: auto; max-height: calc(100vh - 180px); }
.tab-panel.active { display: block; }

/* Panels */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 0.8rem 1rem; margin-bottom: 0.75rem; }
.box { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.6rem 0.8rem; white-space: pre-wrap; font-size: 0.86rem; color: var(--text-2); }
.box.scroll { max-height: 260px; overflow-y: auto; }
.stat-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.5rem 0; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.3rem 0.6rem; font-size: 0.78rem; font-family: var(--mono); }
.stat.good { border-color: #059669; color: #6ee7b7; }
.stat.bad { border-color: #991b1b; color: #fca5a5; }
.stat.warn { border-color: #b45309; color: #fde68a; }
.diff ins { background: var(--ins); text-decoration: none; border-radius: 3px; }
.diff del { background: var(--del); color: #fca5a5; border-radius: 3px; }
.issue { padding: 0.45rem 0.6rem; border-radius: 6px; background: var(--bg); border: 1px solid var(--border); margin-bottom: 0.4rem; font-size: 0.84rem; cursor: pointer; }
.issue:hover { border-color: var(--accent); }
.issue .ctx { color: var(--muted); font-size: 0.78rem; }
.ok-box { background: rgba(16, 185, 129, 0.12); border: 1px solid var(--low); color: #6ee7b7; padding: 0.5rem 0.8rem; border-radius: 6px; font-size: 0.85rem; }
table.simple { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.simple th, table.simple td { text-align: left; padding: 0.3rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.simple th { color: var(--muted); font-weight: 600; }

/* Claim tree */
.tree, .tree ul { list-style: none; margin: 0; padding-left: 1.1rem; border-left: 1px dashed var(--border); }
.tree { border-left: none; padding-left: 0; }
.tree li { margin: 0.35rem 0; }
.claim-node { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem 0.6rem; font-size: 0.82rem; }
.claim-node.indep { border-color: var(--accent); }
.claim-node .tag { font-size: 0.68rem; padding: 0.05rem 0.35rem; border-radius: 4px; margin-left: 0.35rem; background: #334155; }
.claim-node .tag.multi { background: #7f1d1d; color: #fecaca; }

/* Prior art */
.hit { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.6rem 0.8rem; margin-bottom: 0.5rem; }
.hit-title { font-weight: 600; font-size: 0.88rem; }
.hit-meta { font-size: 0.75rem; color: var(--muted); font-family: var(--mono); }

/* Progress */
.progress { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }

/* Toast */
.toast {
  position: fixed; right: 1.25rem; bottom: 1.25rem; max-width: 460px; padding: 0.75rem 1rem; border-radius: 8px;
  background: var(--card); border: 1px solid var(--border); color: var(--text); font-size: 0.88rem;
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 20;
}
.toast.show { opacity: 1; transform: none; pointer-events: auto; }
.toast-ok { border-color: var(--low); }
.toast-warn { border-color: var(--mod); }
.toast-error { border-color: var(--high); color: #fecaca; }
