:root {
  --bg: #fafaf8;
  --panel: #ffffff;
  --ink: #1a1d21;
  --muted: #8a8f98;
  --line: #e7e6e1;
  --accent: #0f6b4f;
  --accent-soft: #e8f3ee;
  --pos: #0f8a5f;
  --neg: #c34a3d;
  --cand: #b98a1e;
}
* { box-sizing: border-box; margin: 0; }
body {
  font-family: -apple-system, "SF Pro Text", Inter, Segoe UI, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 14.5px; line-height: 1.55;
}
header {
  display: flex; justify-content: space-between; align-items: center; gap: 24px;
  padding: 18px 32px; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-wrap: wrap;
}
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; }
.tagline { color: var(--muted); font-size: 12.5px; }
.brand { display: flex; align-items: baseline; gap: 12px; }

.account-bar { display: flex; gap: 8px; align-items: center; }
input, select, textarea, button {
  font: inherit; color: inherit;
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 12px; background: var(--panel); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
#account-url { width: 300px; }
button { cursor: pointer; transition: background .15s; }
button:hover { background: var(--accent-soft); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { opacity: .92; }

main { display: grid; grid-template-columns: 1fr 300px; gap: 24px; padding: 24px 32px; max-width: 1360px; margin: 0 auto; }
.left { min-width: 0; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tab { border: none; background: none; padding: 8px 14px; color: var(--muted); border-radius: 8px 8px 0 0; }
.tab.active { color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 10px; }
.muted { color: var(--muted); font-weight: 400; }

.cards { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px;
}
.card .content { white-space: pre-wrap; margin: 10px 0; }
.card .meta { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.card .pred { font-weight: 650; font-size: 15px; }
.pred.pos, td.pos { color: var(--pos); }
.pred.neg, td.neg { color: var(--neg); }
.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.badge.gray { background: #f0efeb; color: var(--muted); }
.drivers { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.driver { font-size: 11px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line); }
.driver.pos { border-color: #cfe7dc; background: #f2faf6; }
.driver.neg { border-color: #eed4d0; background: #fbf3f2; }
.card .actions { display: flex; gap: 8px; margin-top: 12px; }
.image-prompt { font-size: 12.5px; color: var(--muted); border-left: 3px solid var(--line); padding-left: 10px; margin-top: 8px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
td.text-cell { max-width: 480px; }
td.text-cell .clamp { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
tr.thread-child td { background: #fafaf8; }
tr.thread-child td.text-cell { padding-left: 28px; }
.stat-line { font-size: 12px; color: var(--muted); margin-top: 3px; }
.thread { margin-top: 4px; border-left: 2px solid var(--line); padding-left: 10px; }
.thread-part { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; }
.thread-part .badge { margin-top: 2px; }

.right { display: flex; flex-direction: column; gap: 20px; }
.side-block { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.stats { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.stats b { font-size: 18px; font-weight: 650; }
.zeit-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.zeit-cols h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.zeit-cols ol { padding-left: 16px; font-size: 12.5px; display: flex;
  flex-direction: column; gap: 7px; margin: 0; }
.zeit-cols .src { color: var(--muted); font-size: 10.5px; }

#tree-viz { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; overflow: auto; }
#tree-viz svg { display: block; }
.legend { font-size: 12px; color: var(--muted); display: flex; gap: 12px; align-items: center; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }
.dot.pos { background: var(--pos); } .dot.neg { background: var(--neg); } .dot.cand { background: var(--cand); }

.node text { font-size: 11.5px; fill: var(--ink); }
.node .weight-label { fill: var(--muted); font-size: 10px; }
.link { fill: none; stroke: var(--line); stroke-width: 1.2; }

#model-health .metric-row { display: flex; gap: 24px; margin-bottom: 16px; flex-wrap: wrap; }
.metric { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 20px; min-width: 130px; }
.metric b { font-size: 22px; font-weight: 650; display: block; }
.metric span { font-size: 12px; color: var(--muted); }

textarea { width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.row { display: flex; gap: 10px; margin-top: 10px; align-items: center; }
.alloc-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.alloc-row input[type="range"] { flex: 1; accent-color: var(--accent); }
.alloc-pct { min-width: 3.2em; font-weight: 650; font-variant-numeric: tabular-nums; }

button.turbo { border-color: #e8c268; background: #fdf6e3; font-weight: 600; }
button.turbo:hover { background: #faedc8; }

.modal {
  position: fixed; inset: 0; background: rgba(20, 22, 25, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel); border-radius: 14px; padding: 26px 30px;
  max-width: 640px; width: 92%; max-height: 86vh; overflow: auto;
  box-shadow: 0 18px 60px rgba(0,0,0,.18);
}
.modal-box h2 { margin-bottom: 10px; }
.modal-box h3 { margin: 16px 0 6px; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--ink); }
.modal-box ol { padding-left: 20px; display: flex; flex-direction: column; gap: 4px; margin: 4px 0; }
.modal-box code { background: #f0efeb; padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.modal-head { display: flex; justify-content: space-between; align-items: start; }
.modal-head button { border: none; background: none; font-size: 16px; }
.dropzone {
  margin: 14px 0 8px; border: 1.5px dashed var(--line); border-radius: 12px;
  padding: 22px; text-align: center; color: var(--muted); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone.drag, .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { display: none; }

.badge.warn { background: #fdf3dd; color: #8a6d1a; }

button.mini { font-size: 11px; padding: 3px 10px; border-radius: 6px; }
.image-prompt button.mini { margin-left: 8px; font-weight: 600; letter-spacing: .03em; }
.caliber { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.caliber textarea { width: 100%; font-size: 12.5px; resize: vertical; }
.caliber button.mini { align-self: flex-end; }
.stale-warn { color: #8a6d1a; background: #fdf3dd; border-radius: 8px; padding: 4px 10px; font-size: 12px; margin-top: 4px; }

/* loading feedback */
.spinner {
  display: inline-block; width: 13px; height: 13px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.spinner.big { width: 26px; height: 26px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-box {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 42px 20px; background: var(--panel); border: 1px dashed var(--line);
  border-radius: 12px; text-align: center;
}
button:disabled { opacity: .6; cursor: default; }

/* account weight comparison */
.cmp-table { margin-top: 12px; }
.cmp-table td { font-size: 12.5px; }
.cmp-bar-wrap { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.cmp-bar { height: 8px; border-radius: 4px; min-width: 2px; }
.cmp-bar.pos { background: var(--pos); }
.cmp-bar.neg { background: var(--neg); }
.cmp-val { font-size: 11px; color: var(--muted); white-space: nowrap; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .25s;
}
#toast.show { opacity: 1; }

@media (max-width: 980px) { main { grid-template-columns: 1fr; } }
