:root {
  --bg: #12151c;
  --bg-elev: #1b202b;
  --bg-soft: #232a38;
  --line: #323b4d;
  --text: #e8edf6;
  --muted: #9aa6bb;
  --accent: #e2a23a;
  --accent-2: #7eb6ff;
  --good: #63c08a;
  --warn: #e2a23a;
  --bad: #e06b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --mono: "IBM Plex Mono", "Source Code Pro", ui-monospace, monospace;
  --sans: "IBM Plex Sans", "Source Sans 3", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(226, 162, 58, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(126, 182, 255, 0.08), transparent 45%),
    var(--bg);
  color: var(--text);
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: #0e1218;
  border-right: 1px solid var(--line);
  padding: 1.2rem 0.9rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-weight: 700; letter-spacing: 0.04em; margin: 0 0.4rem 0.2rem; }
.brand-sub { color: var(--muted); font-size: 0.78rem; margin: 0 0.4rem 1.2rem; }
.nav a {
  display: flex;
  justify-content: space-between;
  color: var(--text);
  padding: 0.48rem 0.7rem;
  border-radius: 10px;
  margin-bottom: 0.15rem;
}
.nav a:hover, .nav a.is-active { background: var(--bg-soft); text-decoration: none; }
.badge {
  background: var(--accent);
  color: #1a1408;
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
}
.main { padding: 1.4rem 1.8rem 3rem; }
.topbar { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1.2rem; }
.demo-pill, .status-pill, .muted { color: var(--muted); font-size: 0.85rem; }
h1 { font-size: 1.55rem; margin: 0 0 0.35rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 0.6rem; }
.grid { display: grid; gap: 0.9rem; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.cards { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card, .table-wrap, form.panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi .value { font-size: 1.35rem; font-family: var(--mono); margin-top: 0.25rem; }
.deal-card { border-left: 4px solid var(--accent); }
.deal-card.low { border-left-color: var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
th a.sort { color: var(--muted); text-transform: uppercase; }
th a.sort:hover, th a.sort.is-sorted { color: var(--text); text-decoration: none; }
th .sort-ind { font-size: 0.7rem; }
.tag {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.08rem 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.tag.good { color: var(--good); border-color: #2f6a48; }
.tag.warn { color: var(--warn); border-color: #7a5a1d; }
.tag.bad { color: var(--bad); border-color: #7a3232; }
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
button, .btn, input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
}
button, .btn { cursor: pointer; background: #31405a; }
button.primary, .btn.primary { background: var(--accent); color: #1a1408; border-color: transparent; font-weight: 700; }
.messages { list-style: none; padding: 0; }
.messages li { background: #2a3344; border-radius: 10px; padding: 0.55rem 0.8rem; margin-bottom: 0.5rem; }
.login-wrap { max-width: 420px; margin: 12vh auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem 1rem; }
.form-grid label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid .checkbox { flex-direction: row; align-items: center; gap: 0.45rem; }
.form-grid .errorlist { color: var(--bad); list-style: none; padding: 0; margin: 0; font-size: 0.8rem; }
.inline-form { display: inline; }
.ai-panel { margin-bottom: 0.4rem; }
.ai-picker { display: grid; grid-template-columns: minmax(220px, 0.7fr) 1fr; gap: 1.2rem; align-items: start; }
.ai-picker-form { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: end; }
.ai-picker-form label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--muted); font-size: 0.85rem; min-width: 220px; }
.ai-picker-form label.ai-endpoint-field { min-width: 10rem; }
.ai-picker-form label.ai-endpoint-field.ai-model-field { min-width: 16rem; }
.ai-picker-form label.ai-endpoint-field.ai-level-field { min-width: 8.5rem; }
.ai-picker-form label.ai-endpoint-field[hidden] { display: none; }
.ai-picker-form input[type="number"] { width: 5.2rem; }
.ai-picker-form input[type="text"] { width: 12.5rem; }
.ai-picker-form select { min-width: 12rem; max-width: 28rem; }
.ai-endpoint-hint[hidden] { display: none; }
.ai-model-status { min-height: 1.1em; }
.ai-model-status[hidden] { display: none; }
.ai-model-status.is-error { color: var(--bad); }
#ai-model-hint[hidden] { display: none; }
#ai-level-hint[hidden] { display: none; }
.ai-runtime .label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.ai-runtime p { margin: 0.35rem 0; }
.usage-table-wrap { overflow-x: auto; }
.usage-table { min-width: 880px; }
.usage-table th.num, .usage-table td.num { text-align: right; white-space: normal; min-width: 7.2rem; }
.usage-table .scope { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.usage-table tr.scope-combined td:first-child strong { font-size: 1rem; }
.usage-table .token-total { font-family: var(--mono); font-size: 1.02rem; }
.usage-table .cell-sub { font-size: 0.72rem; line-height: 1.35; }
.usage-chart-card { margin: 0 0 0.9rem; }
.usage-chart-head { display: flex; justify-content: space-between; gap: 1rem; align-items: end; margin-bottom: 0.8rem; }
.usage-window-form label { display: flex; flex-direction: column; gap: 0.3rem; color: var(--muted); font-size: 0.85rem; min-width: 160px; }
.usage-chart-kpis { margin-bottom: 0.6rem; }
.usage-chart { width: 100%; height: auto; display: block; }
.usage-chart .grid { stroke: var(--line); stroke-width: 1; }
.usage-chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.usage-chart .area { fill-opacity: 0.38; }
.usage-chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.usage-chart .hover { fill: transparent; }
.usage-chart .hover:hover { fill: rgba(126, 182, 255, 0.08); }
.usage-legend { display: flex; flex-wrap: wrap; gap: 0.7rem 1.1rem; list-style: none; padding: 0.7rem 0 0; margin: 0; font-size: 0.82rem; }
.usage-legend .swatch { width: 0.7rem; height: 0.7rem; border-radius: 999px; display: inline-block; margin-right: 0.35rem; vertical-align: -0.05rem; }
.job-research { margin-bottom: 0.9rem; }
.job-research-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; flex-wrap: wrap; }
.research-io {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.4rem;
  align-items: end;
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}
.research-io form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
}
.research-io label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.research-io .checkbox { flex-direction: row; align-items: center; gap: 0.4rem; }
.research-io input[type="number"] { width: 5.2rem; }
.research-io input[type="file"] { max-width: 16rem; }
.research-io textarea { min-width: 18rem; min-height: 4.2rem; }
.jobs-desk { margin: 1.2rem 0; }
.jobs-table button { white-space: nowrap; }
.countdown { font-family: var(--mono); }
.countdown.is-due { color: var(--warn); }
.delta-up { color: var(--warn); }
.delta-down { color: var(--good); }
.ai-calls-card { margin: 0 0 0.9rem; }
.ai-calls-table { width: 100%; }
.ai-calls-table td { vertical-align: top; }
.ai-calls-table tr.is-running { background: rgba(226, 162, 58, 0.08); }
.ai-calls-table tr.is-waiting { background: rgba(126, 182, 255, 0.06); }
.ai-calls-table tr.is-stale { background: rgba(224, 107, 107, 0.08); }
.ai-calls-table .elapsed { font-family: var(--mono); }
.ai-calls-table button { white-space: nowrap; }
@media (max-width: 960px) {
  .ai-picker { grid-template-columns: 1fr; }
}
.breakdown { font-size: 0.88rem; }
.archive-extract {
  white-space: pre-wrap;
  max-height: 28rem;
  overflow: auto;
  font-size: 0.85rem;
  line-height: 1.45;
}
.capture-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.6rem;
}
.capture-url { overflow-wrap: anywhere; flex: 1 1 16rem; }
.capture-note { color: var(--warn); margin: 0 0 0.6rem; }
.capture-frame-wrap {
  height: 24rem;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}
.capture-frame-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}
.capture-upload { margin-top: 1rem; }
.capture-upload summary { cursor: pointer; color: var(--muted); }
.capture-embed { margin-top: 1.2rem; }
.capture-embed summary { cursor: pointer; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.8rem 0 1rem; }
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 1rem 0 0;
}
.split { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 1rem; }
@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .split { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
