/* Layout: fixed left rail of sections, one sticky filter bar, white cards on a cool grey
   page. Light theme by design; colour comes from the section icons, grades and P&L. */
:root {
  --page: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --ink: #12142b;
  --ink-2: #4d5068;
  --muted: #8588a0;
  --line: #e6e7f0;
  --line-2: #d5d7e4;
  --accent: #5b4bd6;
  --accent-ink: #4336b3;
  --accent-soft: #eeecfc;
  /* categorical */
  --c-blue: #2a78d6;  --c-blue-soft: #e6f0fc;
  --c-orange: #eb6834; --c-orange-soft: #fdeee7;
  --c-aqua: #1baf7a;  --c-aqua-soft: #e3f6ee;
  --c-yellow: #eda100; --c-yellow-soft: #fdf3da;
  --c-magenta: #d55181; --c-magenta-soft: #fbe9f0;
  --c-violet: #6250d6; --c-violet-soft: #eeecfc;
  /* profit / loss (always paired with a sign and an arrow) */
  --profit: #0a7a2f;  --profit-fill: #1baf7a; --profit-soft: #e4f6ec;
  --loss: #c22f2c;    --loss-fill: #e34948;   --loss-soft: #fdecec;
  --warn: #9a5b00;    --warn-soft: #fff3da;
  --display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 12px;
  --side-w: 232px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.5 var(--body); }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.num, td.r, th.r { font-variant-numeric: tabular-nums; }

/* ---------- side rail ---------- */
.side { position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--surface);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 14px; gap: 18px; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand strong { display: block; font-family: var(--display); font-size: 15px; }
.brand small { color: var(--muted); font-size: 11.5px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); display: flex;
  align-items: flex-end; justify-content: center; gap: 3px; padding: 8px 7px; }
.brand-mark i { width: 5px; border-radius: 2px; background: #fff; }
.brand-mark i:nth-child(1) { height: 8px; opacity: .7; } .brand-mark i:nth-child(2) { height: 16px; }
.brand-mark i:nth-child(3) { height: 11px; opacity: .85; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; text-decoration: none;
  color: var(--ink-2); font-weight: 500; }
nav a:hover { background: var(--surface-2); color: var(--ink); }
nav a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
nav a .ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex: none; }
nav a .ico svg { width: 15px; height: 15px; }
nav a .count { margin-left: auto; font-size: 11px; background: var(--loss-soft); color: var(--loss); border-radius: 20px; padding: 1px 7px; font-weight: 600; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.side-status { font-size: 12px; color: var(--muted); line-height: 1.45; padding: 0 4px; }
.side-status b { color: var(--ink-2); font-weight: 600; }

/* ---------- main ---------- */
.main { margin-left: var(--side-w); min-height: 100%; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 4; background: rgba(244, 245, 251, .92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); padding: 14px 28px; display: flex; gap: 16px 24px; align-items: center; flex-wrap: wrap; }
.top-title { min-width: 0; margin-right: auto; }
.top-title p { color: var(--muted); font-size: 12.5px; }
.filters { display: flex; gap: 8px 10px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 7px; cursor: pointer; color: var(--ink-2); font-size: 12.5px; font-weight: 500; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--accent); color: #fff; }
.date-in { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
input[type=date], input[type=text], input[type=search], input[type=number], select, textarea {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 9px; }
textarea { width: 100%; resize: vertical; line-height: 1.5; }
#view { padding: 22px 28px 60px; display: flex; flex-direction: column; gap: 18px; outline: none; }
#banners { padding: 0 28px; display: flex; flex-direction: column; gap: 8px; }
#banners:not(:empty) { padding-top: 16px; }

/* ---------- pieces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.card > header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card > header .sub { color: var(--muted); font-size: 12px; }
.card > header .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.grid { display: grid; gap: 18px; }
.g-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-21 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-12 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
@media (max-width: 1250px) { .g-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) { .g-21, .g-12, .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); } .g-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .side { position: static; width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  nav { flex-direction: row; flex-wrap: wrap; } .side-foot { margin: 0; flex-direction: row; align-items: center; }
  .main { margin-left: 0; } .top, #view, #banners { padding-left: 16px; padding-right: 16px; } .g-5 { grid-template-columns: minmax(0, 1fr); }
}

.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .lab { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 12px; font-weight: 500; }
.kpi .dot { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; }
.kpi .dot svg { width: 13px; height: 13px; }
.kpi .val { font-family: var(--display); font-size: 27px; font-weight: 600; line-height: 1.15; letter-spacing: -0.02em; }
.kpi .foot { color: var(--muted); font-size: 12px; }
.pos { color: var(--profit); } .neg { color: var(--loss); } .mut { color: var(--muted); }

.btn { border: 1px solid var(--line-2); background: var(--surface); border-radius: 9px; padding: 7px 12px; cursor: pointer; font-weight: 500; font-size: 13px; }
.btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-ink); color: #fff; }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.wide { width: 100%; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.chip.buy { background: var(--c-blue-soft); color: #1c5cab; } .chip.sell { background: var(--c-orange-soft); color: #b0441a; }
.chip.gA { background: var(--profit-soft); color: var(--profit); } .chip.gB { background: var(--c-blue-soft); color: #1c5cab; }
.chip.gC { background: var(--warn-soft); color: var(--warn); } .chip.gD { background: var(--loss-soft); color: var(--loss); }
.chip.rule { background: var(--loss-soft); color: var(--loss); } .chip.ok { background: var(--profit-soft); color: var(--profit); }
.chip.info { background: var(--accent-soft); color: var(--accent-ink); } .chip.grey { background: #eef0f6; color: var(--ink-2); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }

.banner { border-radius: 10px; padding: 10px 14px; display: flex; gap: 10px; align-items: baseline; font-size: 13px; border: 1px solid; }
.banner b { font-weight: 600; }
.banner.info { background: var(--accent-soft); border-color: #d9d4f7; color: #2f2780; }
.banner.warn { background: var(--warn-soft); border-color: #f2dba6; color: #6b4200; }
.banner .right { margin-left: auto; white-space: nowrap; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
td.r, th.r { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--surface-2); }
.tbl-wrap { overflow-x: auto; max-height: 640px; overflow-y: auto; }
.remark-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.empty { color: var(--muted); padding: 22px 8px; text-align: center; font-size: 13px; line-height: 1.6; }
.empty b { color: var(--ink-2); }

/* charts */
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz text { font-family: var(--body); fill: var(--muted); font-size: 11px; }
.viz .val-label { fill: var(--ink-2); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.viz .axis { stroke: var(--line-2); } .viz .gridline { stroke: var(--line); }
.viz .hit { fill: transparent; cursor: default; }
.viz .hit:hover + .mark, .viz .mark.hov { filter: brightness(.9); }
.chart-empty { color: var(--muted); padding: 40px 0; text-align: center; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--ink); color: #fff; border-radius: 8px; padding: 7px 10px; font-size: 12px; line-height: 1.45; max-width: 280px; box-shadow: 0 6px 20px rgba(18, 20, 43, .22); }
.tip b { font-weight: 600; } .tip .t-mut { color: #b9bbd0; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.cal .dow { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: center; padding-bottom: 2px; }
.cal .cell { border-radius: 8px; min-height: 52px; padding: 5px 7px; background: var(--surface-2); display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; border: 1px solid transparent; }
.cal .cell.has { cursor: pointer; } .cal .cell.has:hover { border-color: var(--ink-2); }
.cal .cell .d { color: var(--ink-2); font-weight: 600; } .cal .cell .p { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.cal .cell.out { background: none; }
.cal-nav { display: flex; align-items: center; gap: 8px; }

/* findings and review */
.finding { border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; display: flex; flex-direction: column; gap: 4px; }
.finding .head { display: flex; gap: 8px; align-items: baseline; }
.finding .head h3 { flex: 1; min-width: 0; }
.finding p { color: var(--ink-2); font-size: 12.5px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.review h3 { margin: 12px 0 5px; color: var(--ink-2); text-transform: uppercase; font-size: 11px; letter-spacing: .05em; font-family: var(--body); }
.review ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.review .headline { font-family: var(--display); font-size: 16px; font-weight: 600; }
.review .meta { color: var(--muted); font-size: 11.5px; margin-top: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checks li { display: flex; gap: 8px; align-items: baseline; font-size: 13px; }
.checks .mk { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.checks .y .mk { background: var(--profit-soft); color: var(--profit); } .checks .n .mk { background: var(--loss-soft); color: var(--loss); }
.checks .q .mk { background: #eef0f6; color: var(--muted); }

/* day list */
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.day { scroll-margin-top: 150px; }
.day > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: grid; grid-template-columns: 118px 74px 110px 96px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.day > summary::-webkit-details-marker { display: none; }
.day > summary:hover { background: var(--surface-2); border-radius: var(--radius); }
.day .date { font-weight: 600; } .day .date small { color: var(--muted); font-weight: 500; margin-left: 4px; }
.day .hl { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-body { border-top: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 900px) { .day > summary { grid-template-columns: 1fr 1fr; } }

/* drawer */
.drawer-back { position: fixed; inset: 0; background: rgba(18, 20, 43, .28); z-index: 20; }
.drawer { position: fixed; inset: 0 0 0 auto; width: min(760px, 96vw); background: var(--page); z-index: 21; overflow-y: auto; padding: 18px 20px 40px; display: flex; flex-direction: column; gap: 14px; box-shadow: -12px 0 40px rgba(18, 20, 43, .16); }
.drawer-head { display: flex; align-items: center; gap: 10px; }
.drawer-head h2 { font-size: 18px; flex: 1; }

/* chat and memory */
.chat { display: flex; flex-direction: column; gap: 10px; height: 560px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; white-space: pre-wrap; line-height: 1.5; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-in { display: flex; gap: 8px; } .chat-in textarea { flex: 1; min-height: 44px; }
.memory-ta { min-height: 420px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 13px; max-width: 80vw; }
.toast.err { background: var(--loss); }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.steps li { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 8px; }
.steps .detail { color: var(--ink-2); }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; font-size: 12px; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -1px; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* ---------- login (server version) ---------- */
.auth-page { display: grid; place-items: center; min-height: 100%; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px; display: flex; flex-direction: column; gap: 20px;
  box-shadow: 0 10px 30px rgba(18, 20, 43, .06); }
.auth-step { display: flex; flex-direction: column; gap: 14px; }
.auth-step h1 { font-size: 20px; }
.auth-step label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; color: var(--ink-2); font-size: 13px; }
.auth-step input { border: 1px solid var(--line-2); border-radius: 9px; padding: 10px 12px; background: var(--surface); font-size: 15px; }
.auth-step input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-step .mut { color: var(--muted); font-size: 13px; }
.auth-step .qr { display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.auth-step .qr img { width: 190px; height: 190px; }
.auth-step details { font-size: 12.5px; color: var(--ink-2); }
.auth-step code { display: block; margin-top: 6px; word-break: break-all; background: var(--surface-2); padding: 8px; border-radius: 8px; }
.auth-msg { min-height: 1.4em; color: var(--loss); font-size: 13px; }
.auth-msg.ok { color: var(--profit); }
.side-user { font-size: 12px; color: var(--muted); padding: 0 4px; display: flex; gap: 8px; align-items: center; }
.side-user a { margin-left: auto; cursor: pointer; }
