:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8f9fb; --line: #e6e9ef; --text: #0f1b2d; --muted: #6b778a;
  --navy: #0f1b2d; --navy-2: #1f3864; --accent: #2b5cd6;
  --in: #1e8a4c; --in-soft: #e8f5ee; --out: #c8463a; --out-soft: #fbeceb; --bal: #fff4d6;
  --shadow: 0 1px 2px rgba(15,27,45,.04), 0 6px 24px rgba(15,27,45,.06);
  --r: 16px; --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b111b; --surface: #121a27; --surface-2: #172131; --line: #223047; --text: #e8edf5; --muted: #8a97ab;
    --navy: #e8edf5; --navy-2: #2a4a85; --accent: #6d95ff; --in: #46c47f; --in-soft: #12291d; --out: #ff7a6e;
    --out-soft: #2f1716; --bal: #3a3216; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b111b; --surface: #121a27; --surface-2: #172131; --line: #223047; --text: #e8edf5; --muted: #8a97ab;
  --navy: #e8edf5; --navy-2: #2a4a85; --accent: #6d95ff; --in: #46c47f; --in-soft: #12291d; --out: #ff7a6e;
  --out-soft: #2f1716; --bal: #3a3216; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.25); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 24px 14px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 10px 22px; letter-spacing: -.01em; }
.brand .logo { width: 32px; height: 32px; border-radius: 10px; background: var(--navy-2); color: #fff; display: grid; place-items: center; font-weight: 800; }
.nav { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; color: var(--muted); text-decoration: none; font-weight: 500; transition: background .2s, color .2s; }
.nav:hover { background: var(--surface-2); color: var(--text); }
.nav.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.nav.on svg { color: var(--accent); }
main { padding: 32px clamp(16px, 4vw, 48px) 120px; max-width: 1180px; width: 100%; }
.view { animation: rise .35s cubic-bezier(.2,.8,.2,1); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
h1 { font-size: 26px; letter-spacing: -.02em; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
.pad { padding: 20px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.stat { padding: 22px; }
.stat .lbl { color: var(--muted); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat .val { font-size: clamp(26px, 3.4vw, 36px); font-weight: 700; letter-spacing: -.02em; margin-top: 10px; font-variant-numeric: tabular-nums; }
.stat .meta { color: var(--muted); font-size: 13px; margin-top: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.in { color: var(--in); } .out { color: var(--out); }
.bg-in { background: var(--in); } .bg-out { background: var(--out); }
.section { margin-top: 28px; }
.section-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-h h2 { font-size: 16px; margin: 0; }
.link { color: var(--accent); text-decoration: none; font-size: 14px; font-weight: 500; cursor: pointer; background: none; border: 0; padding: 0; }

.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--line); cursor: default; }
.rows .row:first-child { border-top: 0; }
.row.click { cursor: pointer; transition: background .15s; }
.row.click:hover { background: var(--surface-2); }
.row.new { animation: flash 1.2s ease; }
@keyframes flash { from { background: var(--in-soft); } to { background: transparent; } }
.av { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; background: var(--surface-2); color: var(--navy-2); border: 1px solid var(--line); }
.av.in { background: var(--in-soft); color: var(--in); border-color: transparent; }
.av.out { background: var(--out-soft); color: var(--out); border-color: transparent; }
.grow { flex: 1; min-width: 0; }
.t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t2 { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; transition: transform .12s, background .15s; text-decoration: none; }
.chip:hover { background: var(--surface-2); } .chip:active { transform: scale(.97); }
.chip.on { background: var(--navy-2); color: #fff; border-color: var(--navy-2); }

.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 12px; cursor: pointer; font-weight: 500; transition: transform .12s, background .15s; text-decoration: none; }
.btn:hover { background: var(--surface-2); } .btn:active { transform: scale(.97); }
.btn.primary { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 10px; }
.btn.danger { color: var(--out); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.input { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 14px; outline: none; min-width: 0; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.search { position: relative; flex: 1; min-width: 200px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search .input { width: 100%; padding-left: 40px; }

/* Excel-style counterparty report */
.report { overflow: hidden; }
.report-title { background: var(--navy-2); color: #fff; text-align: center; font-weight: 700; padding: 14px; letter-spacing: .02em; }
.report-date { text-align: right; color: var(--muted); font-style: italic; padding: 8px 16px; font-size: 13px; }
table.x { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.x th { background: var(--navy-2); color: #fff; font-weight: 600; padding: 10px 12px; font-size: 13px; border: 1px solid color-mix(in srgb, var(--navy-2) 70%, #fff); }
table.x td { padding: 10px 12px; border: 1px solid var(--line); font-size: 14px; }
table.x td.n { text-align: right; white-space: nowrap; }
table.x td.c { text-align: center; white-space: nowrap; }
table.x tr.tot td { background: color-mix(in srgb, var(--navy-2) 10%, var(--surface)); font-weight: 700; }
table.x tr.bal td { background: var(--bal); font-weight: 800; }
table.x tr.rev td { color: var(--muted); text-decoration: line-through; }
.table-wrap { overflow-x: auto; }

/* assistant */
.chat { display: flex; flex-direction: column; height: calc(100vh - 160px); min-height: 460px; }
.msgs { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: min(78%, 560px); padding: 11px 14px; border-radius: 16px; white-space: pre-wrap; line-height: 1.45; animation: rise .25s ease; font-size: 15px; }
.bubble.user { align-self: flex-end; background: var(--navy-2); color: #fff; border-bottom-right-radius: 6px; }
.bubble.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.ok { border-color: color-mix(in srgb, var(--in) 40%, var(--line)); }
.composer { display: flex; gap: 10px; align-items: center; padding: 14px; border-top: 1px solid var(--line); }
.composer .input { flex: 1; }
.mic { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--navy-2); color: #fff; display: grid; place-items: center; cursor: pointer; position: relative; flex: none; transition: transform .15s; }
.mic:active { transform: scale(.94); }
.mic.rec { background: var(--out); }
.mic.rec::before, .mic.rec::after { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--out); animation: pulse 1.6s ease-out infinite; }
.mic.rec::after { animation-delay: .8s; }
@keyframes pulse { from { transform: scale(1); opacity: .7; } to { transform: scale(1.8); opacity: 0; } }
.interim { color: var(--muted); font-style: italic; padding: 0 20px 8px; min-height: 22px; font-size: 14px; }
.fab { position: fixed; right: 28px; bottom: 28px; width: 64px; height: 64px; box-shadow: 0 10px 30px rgba(31,56,100,.35); z-index: 5; }
.fab svg { width: 26px; height: 26px; }
.typing span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 10px; height: 16px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.kv { display: flex; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); gap: 12px; }
.kv:first-child { border-top: 0; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--in); background: var(--in-soft); border-color: transparent; }
.badge.warn { color: var(--out); background: var(--out-soft); border-color: transparent; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--navy-2); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 20; animation: rise .25s ease; max-width: 90vw; }
.modal-bg { position: fixed; inset: 0; background: rgba(8,14,24,.45); display: grid; place-items: center; z-index: 30; animation: fade .2s; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(440px, 100%); animation: rise .25s cubic-bezier(.2,.8,.2,1); }
.modal h3 { margin: 0 0 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field .input { color: var(--text); font-size: 15px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 32px; }
.err { color: var(--out); font-size: 14px; min-height: 20px; margin-top: 8px; }

.bottom { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 20px 16px 110px; }
  .bottom { display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 10; }
  .bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); text-decoration: none; padding: 6px 0; }
  .bottom a.on { color: var(--accent); font-weight: 600; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  .grid3 .stat:last-child { grid-column: span 2; }
  .grid2 { grid-template-columns: 1fr; }
  .fab { bottom: 84px; right: 18px; }
  .chat { height: calc(100vh - 190px); }
  .hide-m { display: none; }
}
