:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e3e6ec;
  --brand: #2c5be0;
  --brand-soft: #eaf0ff;
  --ok: #1f8a4c;
  --ok-soft: #e6f5ec;
  --bad: #c23a3a;
  --bad-soft: #fbeaea;
  --warn: #a86a00;
  --warn-soft: #fff4dd;
  --radius: 12px;
  font-family: 'Heebo', 'Assistant', 'Rubik', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }

/* layout */
.app { display: flex; min-height: 100vh; }
.side { width: 220px; background: #151b2b; color: #cfd6e6; display: flex; flex-direction: column; padding: 16px 10px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.login-card .brand { color: var(--ink); padding: 0 0 12px; }
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; opacity: .7; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav button { display: flex; align-items: center; gap: 10px; background: none; border: 0; color: inherit; padding: 9px 10px; border-radius: 8px; cursor: pointer; text-align: right; }
.nav button:hover { background: rgba(255,255,255,.06); }
.nav button.active { background: var(--brand); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { border-top: 1px solid rgba(255,255,255,.1); padding: 10px 8px 0; font-size: 12px; }
.side-foot button { margin-top: 8px; width: 100%; }
main { flex: 1; padding: 22px 26px 60px; min-width: 0; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 22px 0 10px; }

/* pieces */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; direction: ltr; text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.btn:hover { border-color: #c5cad6; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
textarea { width: 100%; min-height: 90px; resize: vertical; line-height: 1.5; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label input, label select, label textarea { color: var(--ink); font-size: 14px; }
.check { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); font-size: 13px; }
.ltr { direction: ltr; text-align: left; unicode-bidi: plaintext; }
.muted { color: var(--muted); }
.pill { display: inline-block; border-radius: 99px; padding: 1px 9px; font-size: 12px; background: #eef0f4; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

table.t { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
table.t th { background: #fafbfc; font-weight: 500; color: var(--muted); font-size: 12px; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f8f9fc; }
.num { direction: ltr; text-align: left !important; white-space: nowrap; }
.scroll { overflow-x: auto; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding-top: 8px; }
.bar { flex: 1; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bar span { position: absolute; bottom: -18px; left: 50%; transform: translateX(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }

pre { background: #0f1422; color: #d6deee; padding: 10px; border-radius: 8px; overflow: auto; max-height: 320px; font-size: 12px; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-word; }

/* drawer */
.drawer { position: fixed; inset: 0; background: rgba(15,20,34,.35); display: flex; justify-content: flex-start; z-index: 50; }
.drawer .panel { width: min(760px, 100%); height: 100%; background: var(--bg); overflow: auto; padding: 18px 20px 40px; box-shadow: 0 0 30px rgba(0,0,0,.2); }
.tool { margin: 10px 0; }
.tool summary { cursor: pointer; display: flex; gap: 8px; align-items: center; }

/* chat */
.chat { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.bubble { max-width: 860px; padding: 10px 14px; border-radius: 12px; line-height: 1.6; }
.bubble.user { background: var(--brand-soft); align-self: flex-start; }
.bubble.ai { background: var(--card); border: 1px solid var(--line); }
.bubble .meta { margin-top: 8px; font-size: 11.5px; color: var(--muted); }
.md h3, .md h4 { margin: 10px 0 4px; font-size: 14.5px; }
.md ul, .md ol { margin: 4px 0; padding-inline-start: 20px; }
.md p { margin: 4px 0; }
.md table { border-collapse: collapse; margin: 6px 0; font-size: 13px; }
.md td, .md th { border: 1px solid var(--line); padding: 4px 8px; }
.md code { background: #eef0f4; padding: 0 4px; border-radius: 4px; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 26px; width: 340px; display: flex; flex-direction: column; gap: 12px; }
.err { color: var(--bad); min-height: 18px; font-size: 13px; }
.toast { position: fixed; bottom: 18px; left: 18px; background: #151b2b; color: #fff; padding: 9px 14px; border-radius: 8px; z-index: 60; }

@media (max-width: 820px) {
  .app { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  main { padding: 14px; }
}
