:root {
  --bg: #0b0d14;
  --bg-2: #121624;
  --panel: #161b2c;
  --line: #232a45;
  --text: #eef1fb;
  --muted: #8891b4;
  --accent: #f4c770;
  --accent-2: #7eb0ff;
  --danger: #ef6f6c;
  --radius: 14px;
  --max: 780px;
}
* { box-sizing: border-box; }
html, body { margin:0; padding:0; background: var(--bg); color: var(--text);
  font: 16px/1.5 "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent-2); text-decoration: none; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---- Topbar ---- */
.topbar {
  display:flex; align-items:center; justify-content:space-between;
  padding: env(safe-area-inset-top, 0) 16px 0 16px;
  height: calc(56px + env(safe-area-inset-top, 0));
  padding-top: env(safe-area-inset-top, 0);
  background: linear-gradient(180deg, rgba(11,13,20,.96), rgba(11,13,20,.72));
  backdrop-filter: blur(8px);
  position: sticky; top:0; z-index: 10;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; display:flex; align-items:center; gap:8px; }
.dot { width:8px; height:8px; border-radius:50%; background: var(--accent);
  box-shadow: 0 0 12px var(--accent); }
.dash-btn {
  padding: 8px 14px; border:1px solid var(--line); border-radius: 999px;
  color: var(--text); background: var(--panel); font-size:14px;
}
.dash-btn:active { transform: scale(.97); }

/* ---- Chat page ---- */
.chat-page { min-height: 100vh; min-height: 100dvh; display:flex; flex-direction:column; }
.chat { flex: 1; display:flex; flex-direction:column; padding: 16px; max-width: var(--max); margin: 0 auto; width:100%; }
.onboard { padding: 16px 4px 120px; }
.onboard h1 { font-size: clamp(28px, 7vw, 40px); line-height: 1.1; margin: 16px 0 20px; }
.onboard .lead { color: #dde3fb; font-size: 17px; max-width: 34ch; }
.field { display:block; margin-top: 28px; }
.field span { display:block; color: var(--muted); font-size: 13px; margin-bottom:6px; }
.field input {
  width: 100%; padding: 14px 16px; border-radius: 12px; border:1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-size: 16px;
}
.cta {
  margin-top: 20px; width:100%;
  padding: 14px 18px; border-radius: 12px; border: 0;
  background: var(--accent); color: #2a1e05; font-weight: 700; font-size: 16px;
}
.cta:active { transform: scale(.98); }
.onboard .note { margin-top: 20px; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---- Thread ---- */
.thread { list-style:none; padding: 8px 0 120px; margin: 0; display:flex; flex-direction:column; gap:10px; }
.msg { max-width: 90%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color:#2a1e05; border-bottom-right-radius: 4px; }
.msg.ai   { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.err  { align-self: center; background: rgba(239,111,108,.12); color: var(--danger); border:1px solid rgba(239,111,108,.3); }
.msg.typing { align-self: flex-start; color: var(--muted); font-style: italic; }

/* ---- Composer ---- */
.composer {
  position: sticky; bottom: 0;
  display:flex; gap:8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom,0));
  background: linear-gradient(0deg, var(--bg) 60%, transparent);
  max-width: var(--max); margin: 0 auto; width:100%;
}
.composer textarea {
  flex: 1; resize: none; padding: 12px 14px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  font: inherit; max-height: 40vh;
}
.composer button {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--accent); color:#2a1e05; display:flex; align-items:center; justify-content:center;
  align-self: flex-end;
}
.composer button:disabled { opacity:.5; }

/* ---- Dashboard ---- */
.dash-page { padding: 0; }
.dash-wrap { padding: 16px; max-width: 1400px; margin: 0 auto; }
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(12, 1fr);
  grid-auto-rows: 240px;
}
.panel {
  grid-column: span 6; grid-row: span 2;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; position: relative; overflow: hidden;
  display:flex; flex-direction:column;
}
.panel h3 { margin: 0 0 6px; font-size: 14px; color: var(--accent); letter-spacing: .04em; text-transform: uppercase; }
.panel .sub { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.panel .body { flex:1; min-height:0; overflow:auto; }
.panel .dock {
  position:absolute; top:10px; right:10px;
  display:flex; gap:6px; opacity:.5; transition: opacity .2s;
}
.panel:hover .dock { opacity:1; }
.panel .dock button {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line);
  width: 26px; height: 26px; border-radius: 6px; font-size: 12px;
}
.kpi-strip {
  display:grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px;
}
.kpi { background: var(--panel); border:1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi b { display:block; font-size: 22px; margin-bottom: 2px; }
.kpi span { color: var(--muted); font-size: 12px; }

/* Cards */
.cards { display:grid; gap:8px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.card { background: var(--bg-2); border:1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.card .cat { font-size: 11px; color: var(--accent); text-transform:uppercase; letter-spacing:.06em; margin-bottom:4px; }
.card .txt { font-size: 13px; }
.card .meta { margin-top:6px; font-size: 11px; color: var(--muted);
  display:flex; align-items:center; justify-content:space-between; gap: 6px; }
.card .upvote {
  background: transparent; color: var(--accent-2); border: 1px solid var(--accent-2)55;
  padding: 3px 8px; border-radius: 999px; font-size: 11px; cursor: pointer;
}
.card .upvote:hover { background: var(--accent-2)22; }
.card .upvote.on { color: var(--accent); border-color: var(--accent)66; cursor: default; }

/* Blobs */
.blobs { width:100%; height:100%; }
.blob { transition: r .6s ease, cx .6s ease, cy .6s ease; }

/* Heatmap */
.heat-row { display:flex; align-items:center; gap:6px; margin: 3px 0; font-size: 12px; }
.heat-row .lbl { width: 110px; color: var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.heat-row .cell { height: 14px; flex:1; border-radius: 3px; }

/* Radar */
.radar-pick { margin-bottom: 6px; }
.radar-pick select { background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }

@media (max-width: 820px) {
  .panel { grid-column: span 12; grid-row: span 2; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
}

/* Admin */
.admin-page { padding: 20px; max-width: 1000px; margin: 0 auto; }
.admin-page table { width:100%; border-collapse: collapse; }
.admin-page th, .admin-page td { padding: 8px; border-bottom: 1px solid var(--line); font-size: 13px; text-align:left; }
.admin-page tr:hover { background: rgba(255,255,255,.02); cursor:pointer; }
.transcript { background: var(--panel); padding: 14px; border-radius: 12px; margin-top: 20px; max-height: 50vh; overflow:auto; }
.transcript .m { padding: 6px 0; font-size: 14px; }
.transcript .m b { color: var(--accent); margin-right:6px; }
