:root {
  --bg: #0b0d14;
  --panel: #12151f;
  --panel-2: #171b27;
  --border: #232838;
  --text: #e7e9f3;
  --muted: #8b91a7;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --err: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1a1740 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.5 "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  min-height: 100vh;
}
a { color: var(--accent-2); text-decoration: none; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0; }
button { font: inherit; cursor: pointer; }
input, select {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; outline: none;
}
input:focus { border-color: var(--accent); }

/* ---- layout ---- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: rgba(18, 21, 31, 0.7); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 700; font-size: 16px; }
.brand .mark {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.navlink {
  display: block; padding: 9px 12px; border-radius: 10px; color: var(--muted);
  background: none; border: none; text-align: left; width: 100%;
}
.navlink:hover { color: var(--text); background: var(--panel-2); }
.navlink.active { color: #fff; background: linear-gradient(135deg, rgba(124,92,255,.28), rgba(34,211,238,.16)); }
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: 10px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.main { padding: 24px 28px 60px; max-width: 1180px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; gap: 12px; }
.balance-pill { background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px; }
.balance-pill b { color: var(--ok); }

/* ---- cards ---- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.kpi-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 26px; font-weight: 700; margin: 6px 0 2px; }
.kpi-sub { color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 16px; margin-top: 16px; }

.chip {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 6px 12px; margin-left: 6px;
}
.chip.active { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }

.btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #0b0d14;
  border: none; border-radius: 10px; padding: 9px 14px; font-weight: 600;
}
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); font-weight: 500; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- tables ---- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid rgba(35,40,56,.55); }
.tbl tr:last-child td { border-bottom: none; }
.pill { font-size: 11px; padding: 3px 8px; border-radius: 999px; }
.pill.ok { background: rgba(52,211,153,.15); color: var(--ok); }
.pill.err { background: rgba(248,113,113,.15); color: var(--err); }

.row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid rgba(35,40,56,.55); }
.row:last-child { border-bottom: none; }

/* ---- chart ---- */
.chart { width: 100%; }
.barsvg { width: 100%; height: 180px; display: block; }
.chart-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; }

/* ---- auth ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 380px; max-width: 100%; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.field input { width: 100%; }
.notice { border-radius: 10px; padding: 11px 13px; font-size: 13px; margin-bottom: 14px; }
.notice.ok { background: rgba(52,211,153,.12); color: var(--ok); border: 1px solid rgba(52,211,153,.3); }
.notice.warn { background: rgba(250,204,21,.1); color: #facc15; border: 1px solid rgba(250,204,21,.28); }
.notice.err { background: rgba(248,113,113,.12); color: var(--err); border: 1px solid rgba(248,113,113,.3); }
.loading { color: var(--muted); padding: 40px 0; }
.keybox { display: flex; gap: 8px; align-items: center; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.keybox code { flex: 1; overflow: auto; white-space: nowrap; }
.pack { cursor: pointer; }
.pack.sel { border-color: var(--accent); }
.muted-small { color: var(--muted); font-size: 12px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar .spacer, .sidebar .who { display: none; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---- dashboard additions ---- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.neg { color: #fb7185; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: 1fr 1fr; } }
label.fl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ta { width: 100%; font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; resize: vertical; }
a.btn { text-decoration: none; display: inline-block; }
.btn.danger { background: #be123c; border-color: #be123c; color: #fff; }
.chatlog { max-height: 420px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bubble { border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; background: var(--panel-2); }
.bubble.user { align-self: flex-end; max-width: 85%; }
.bubble.assistant { align-self: flex-start; max-width: 92%; }
.bubble.err { border-color: #be123c; }
.bubble .who { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.bubble .txt { white-space: pre-wrap; word-break: break-word; }
.bubble .think { white-space: pre-wrap; font-size: 12px; color: var(--muted); border-left: 2px solid var(--border); padding-left: 10px; margin-bottom: 8px; max-height: 120px; overflow: auto; }
.card { overflow-x: auto; }
.main { min-width: 0; }
.cards.small { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .cards.small { grid-template-columns: repeat(2, 1fr); } }
.kpi-value.sm { font-size: 20px; }
.kpi-sm { padding: 14px 16px; }
.tblwrap { overflow-x: auto; }
.btn.tiny { padding: 2px 8px; font-size: 11px; margin-left: 6px; }
.row.col { display: block; padding: 8px 0; }
.meter { height: 5px; border-radius: 3px; background: var(--panel-2); margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, #7c5cff, #22d3ee); }
.pill.warn { background: rgba(245, 158, 11, .15); color: #f59e0b; }
.pill.muted { background: rgba(139, 145, 167, .15); color: var(--muted); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--muted); margin: 4px 0 14px; }
.check input { width: auto; margin-top: 3px; }
.check a, .notice a { color: var(--accent, #7c5cff); }
