:root {
  --page: #f6f6f4; --surface: #ffffff; --ink: #191919; --ink-2: #5f5f5f; --ink-3: #8a8a8a;
  --line: #e7e7e7; --line-2: #d6d6d6; --axis: #c2c2c2;
  --blue: #257de0; --blue-ink: #1757ac; --blue-wash: #eaf2fd;
  --orange: #f47230; --orange-ink: #a8480f; --orange-wash: #fdeee5;
  --good: #006c10; --good-wash: #e6f4e8; --warn: #8a5a00; --warn-wash: #fdf3dc; --bad: #b42324; --bad-wash: #fbe9e9;
  --radius: 8px; --gap: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--page);
  font-size: 14px; line-height: 1.45;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--blue-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.muted { color: var(--ink-2); } .small { font-size: 12px; } .num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: 208px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { padding: 0 10px 14px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.brand b { display: block; font-size: 15px; }
.brand span { font-size: 12px; color: var(--ink-2); }
.nav a { display: block; padding: 8px 10px; border-radius: 6px; text-decoration: none; color: var(--ink); }
.nav a:hover { background: var(--page); }
.nav a.on { background: var(--blue-wash); color: var(--blue-ink); font-weight: 600; }
.side .foot { margin-top: auto; font-size: 12px; color: var(--ink-3); padding: 0 10px; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.topbar .title { flex: 1; min-width: 200px; }
.topbar .title .sub { font-size: 12px; color: var(--ink-2); }
.asof { display: flex; align-items: center; gap: 6px; }
.asof label { font-size: 12px; color: var(--ink-2); }
.presets { display: flex; gap: 4px; }
.content { padding: 20px 24px 60px; display: flex; flex-direction: column; gap: var(--gap); max-width: 1320px; }

/* controls */
.btn { border: 1px solid var(--line-2); background: var(--surface); padding: 6px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #333; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--page); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 8px; background: var(--surface); min-width: 0;
}
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card > header p { margin: 2px 0 0; color: var(--ink-2); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid3 { display: grid; grid-template-columns: 2fr 1fr; gap: var(--gap); }
@media (max-width: 1000px) { .grid2, .grid3 { grid-template-columns: 1fr; } .app { grid-template-columns: 1fr; } .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; } .side .foot { display: none; } }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .k { font-size: 12px; color: var(--ink-2); }
.tile .v { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -0.02em; }
.tile .v small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.tile .d { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
.meter { height: 6px; background: var(--line); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--blue); border-radius: 3px; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.scale { background: var(--good-wash); color: var(--good); }
.badge.change { background: var(--warn-wash); color: var(--warn); }
.badge.stop { background: var(--bad-wash); color: var(--bad); }
.badge.watch, .badge.neutral { background: #eeeeee; color: var(--ink-2); }
.badge.warm { background: var(--blue-wash); color: var(--blue-ink); }
.badge.cold { background: var(--orange-wash); color: var(--orange-ink); }
.badge.sim { background: #f1ecfb; color: #4a33a8; }
.badge.paid { background: var(--good-wash); color: var(--good); }
.badge.overdue { background: var(--bad-wash); color: var(--bad); }
.badge.open { background: #eeeeee; color: var(--ink-2); }
.badge.cancelled { background: #eeeeee; color: var(--ink-3); text-decoration: line-through; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
td:first-child { min-width: 170px; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #fafafa; }
.cell-sub { font-size: 12px; color: var(--ink-2); }

/* lists */
.attn { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.attn li { display: grid; grid-template-columns: 18px 1fr; gap: 8px; }
.attn .ic { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; margin-top: 1px; }
.attn .ic.bad { background: var(--bad); } .attn .ic.warn { background: #c98a00; } .attn .ic.good { background: var(--good); } .attn .ic.info { background: var(--ink-3); }

/* charts */
.chart { width: 100%; display: block; }
.chart text { font-size: 11px; fill: var(--ink-2); }
.chart .lbl { fill: var(--ink); font-size: 12px; }
.chart .val { fill: var(--ink); font-size: 12px; font-weight: 600; }
.chart .grid { stroke: var(--line); }
.chart .axis { stroke: var(--axis); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; display: inline-block; background: var(--blue); border-radius: 2px; }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--ink-3) 0 4px, transparent 4px 7px); }
.tip { position: fixed; pointer-events: none; background: var(--ink); color: #fff; padding: 6px 8px; border-radius: 6px; font-size: 12px; z-index: 50; max-width: 260px; }

/* board */
.board { display: grid; grid-template-columns: repeat(var(--cols, 4), minmax(170px, 1fr)); gap: 10px; overflow-x: auto; }
.col .list { max-height: 70vh; overflow-y: auto; }
.col { background: #efefec; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col > h3 { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; margin: 2px 2px 10px; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin-bottom: 8px; cursor: pointer; }
.kcard:hover { border-color: var(--ink-3); }
.kcard .t { font-weight: 600; }
.kcard .m { font-size: 12px; color: var(--ink-2); margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* drawers & modals */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.06); z-index: 20; display: flex; flex-direction: column; }
.drawer > header { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.drawer .body { padding: 16px 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.form .full { grid-column: 1 / -1; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }
.form .actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; }
.note { background: var(--warn-wash); color: #5c3d00; padding: 8px 10px; border-radius: 6px; font-size: 12px; }
.note.info { background: var(--blue-wash); color: var(--blue-ink); }
.note.sim { background: #f1ecfb; color: #3b2a85; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.timeline li { padding: 0 0 10px 12px; position: relative; font-size: 13px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--axis); }
.timeline li.future { opacity: .45; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; font-size: 13px; }
.toast.err { background: var(--bad); }

/* chat */
.chat { width: min(560px, 100vw); }
.msgs { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 12px 12px 2px 12px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--page); padding: 10px 12px; border-radius: 12px 12px 12px 2px; }
.msg.bot p { margin: 0 0 8px; } .msg.bot p:last-child { margin: 0; }
.msg.bot ul, .msg.bot ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.bot table { font-size: 12px; margin: 6px 0; background: var(--surface); }
.msg.bot th, .msg.bot td { padding: 4px 6px; }
.msg.bot code { background: #ececec; padding: 0 3px; border-radius: 3px; font-size: 12px; }
.msg .meta { font-size: 11px; color: var(--ink-3); margin-top: 6px; }
details.trace { font-size: 12px; margin-top: 6px; color: var(--ink-2); }
details.trace summary { cursor: pointer; }
details.trace pre { white-space: pre-wrap; word-break: break-word; background: var(--surface); border: 1px solid var(--line); padding: 6px; border-radius: 4px; max-height: 160px; overflow: auto; font-size: 11px; }
.proposal { border: 1px solid var(--blue); background: var(--blue-wash); border-radius: 8px; padding: 10px; margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.proposal .row { display: flex; gap: 6px; flex-wrap: wrap; }
.proposal input { flex: 1; min-width: 120px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-2); background: var(--surface); border-radius: 14px; padding: 4px 10px; font-size: 12px; cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--blue); color: var(--blue-ink); }
.composer { border-top: 1px solid var(--line); padding: 12px 18px; display: flex; gap: 8px; }
.composer textarea { min-height: 42px; max-height: 140px; }
.thinking { color: var(--ink-2); font-size: 12px; }
.fab { position: fixed; right: 20px; bottom: 20px; z-index: 15; box-shadow: 0 4px 14px rgba(0,0,0,.15); padding: 10px 16px; border-radius: 22px; }
.kcard .badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
