:root {
  --bg: #0b0f14;
  --surface: #131a23;
  --surface-2: #1a232e;
  --border: #24303d;
  --text: #e8eef5;
  --muted: #8b9bb0;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --out: #f87171;
  --in: #4ade80;
  --warn: #fbbf24;
  --urgent: #f87171;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }

/* ---------------------------------------------------------------- layout */
#app { display: flex; min-height: 100vh; }
aside {
  width: 232px; flex: none; background: var(--surface);
  border-right: 1px solid var(--border); padding: 20px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 19px; padding: 4px 10px 18px;
  letter-spacing: -.02em;
}
.brand span:first-child { font-size: 24px; }
nav button {
  display: flex; align-items: center; gap: 11px; width: 100%;
  background: none; border: 0; color: var(--muted);
  padding: 10px 12px; border-radius: 10px; text-align: left;
  transition: background .15s, color .15s;
}
nav button:hover { background: var(--surface-2); color: var(--text); }
nav button.active { background: var(--surface-2); color: var(--accent); font-weight: 600; }
nav button .ic { width: 20px; text-align: center; }

main { flex: 1; padding: 28px 34px 60px; max-width: 1180px; }
h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 30px 0 12px; letter-spacing: -.01em; }
.sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font-size: 27px; font-weight: 700; margin-top: 5px; letter-spacing: -.02em; }
.stat .value.sm { font-size: 21px; }
.pos { color: var(--in); } .neg { color: var(--out); }
.mono { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- insights */
.insight {
  border-left: 3px solid var(--muted); background: var(--surface);
  border-radius: 10px; padding: 13px 15px; margin-bottom: 10px;
  border: 1px solid var(--border); border-left-width: 3px;
}
.insight.warn { border-left-color: var(--warn); }
.insight.urgent { border-left-color: var(--urgent); }
.insight.info { border-left-color: var(--accent); }
.insight .t { font-weight: 600; display: flex; justify-content: space-between; gap: 12px; }
.insight .b { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.impact { color: var(--accent); font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ---------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: .05em;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
td { padding: 10px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); font-size: 12px;
  border: 1px solid var(--border);
}
.pill.ok { color: var(--accent); border-color: rgba(74,222,128,.3); }
.pill.warn { color: var(--warn); border-color: rgba(251,191,36,.3); }

/* --------------------------------------------------------------- controls */
input, select, textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 9px; font: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; }
.btn {
  background: var(--accent); color: #04120a; border: 0; font-weight: 600;
  padding: 9px 16px; border-radius: 9px;
}
.btn:hover { background: var(--accent-dim); }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--border); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }

/* ------------------------------------------------------------------ chat */
.chat-log { display: flex; flex-direction: column; gap: 13px; margin-bottom: 18px; }
.msg { max-width: 76%; padding: 11px 15px; border-radius: 14px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--accent); color: #04120a; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.think { color: var(--muted); font-style: italic; }
details.ground { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
details.ground pre { white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; }

/* ------------------------------------------------------------------ misc */
.bar { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar > i.over { background: var(--out); }
.empty { color: var(--muted); text-align: center; padding: 44px 20px; }
.spinner {
  width: 15px; height: 15px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; bottom: 22px; right: 22px; background: var(--surface-2);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  padding: 13px 17px; border-radius: 10px; box-shadow: var(--shadow); z-index: 50;
  max-width: 380px;
}
.toast.err { border-left-color: var(--out); }

.login-wrap { display: grid; place-items: center; min-height: 100vh; width: 100%; }
.login { width: 370px; }

@media (max-width: 820px) {
  #app { flex-direction: column; }
  aside { width: 100%; height: auto; position: static; flex-direction: row;
          overflow-x: auto; padding: 10px; }
  .brand { display: none; }
  nav { display: flex; gap: 4px; }
  nav button { white-space: nowrap; }
  main { padding: 18px 16px 50px; }
}
