/* KRS Analyzer — design tokens & shared component CSS
 * Aesthetic: "Polish enterprise but make it nice"
 * Light only for now. Bootstrap-friendly classnames where reasonable.
 */

:root {
  /* Brand */
  --brand-900: #0a1f38;
  --brand-800: #0f2c4d;        /* primary brand navy */
  --brand-700: #163b66;
  --brand-600: #1f4e85;
  --brand-100: #e6ecf3;
  --brand-50:  #f2f5f9;

  /* Neutrals — defaults are warm; theme classes override these. */
  --ink:         #0f172a;
  --ink-2:       #1f2937;
  --muted:       #475569;
  --muted-2:     #64748b;
  --faint:       #94a3b8;
  --line:        #e5e7eb;
  --line-2:      #eef0f3;
  --surface:     #ffffff;
  --surface-2:   #fafaf7;       /* card alt / panel */
  --bg:          #f5f4ef;       /* warm off-white app bg */
  --bg-2:        #ecebe5;

  /* Status / semantics */
  --cost-bg:    #fdf3e3;        /* amber 50 warm */
  --cost-fg:    #92400e;        /* amber 800 */
  --cost-bd:    #f3d9a8;
  --warn-bg:    #fff7ed;
  --warn-fg:    #9a3412;
  --new-bg:     #eaf0fb;        /* light brand */
  --new-fg:     var(--brand-700);
  --ok-bg:      #e8f3ec;
  --ok-fg:      #166534;
  --danger-bg:  #fdecec;
  --danger-fg:  #991b1b;

  /* Sizes */
  --radius: 6px;
  --radius-lg: 10px;
  --row-h: 52px;
  --shadow-1: 0 1px 0 rgba(15,44,77,.04), 0 1px 2px rgba(15,44,77,.06);
  --shadow-2: 0 1px 0 rgba(15,44,77,.04), 0 4px 12px rgba(15,44,77,.06);

  /* Type */
  --ff-sans: "IBM Plex Sans", "Helvetica Neue", Arial, sans-serif;
  --ff-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
}

/* ── Theme: warm (default, current) ─────────────────────── */
.app.theme-warm {
  --bg: #f5f4ef;
  --bg-2: #ecebe5;
  --surface: #ffffff;
  --surface-2: #fafaf7;
  --line: #e5e7eb;
  --line-2: #eef0f3;
}
.app.theme-warm .tbl tbody tr:hover { background: #fafaf6; }
.app.theme-warm .tbl tbody tr.attn { background: #fcfaf3; }
.app.theme-warm .tbl tbody tr.attn:hover { background: #f8f3e3; }

/* ── Theme: cool (slate, financial / clinical) ──────────── */
.app.theme-cool {
  --bg: #eef1f6;
  --bg-2: #e2e7ef;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --line: #dde3ec;
  --line-2: #e9eef5;
  --muted-2: #5d6b80;
  --faint: #8a96aa;
}
.app.theme-cool .tbl tbody tr:hover { background: #f7f9fc; }
.app.theme-cool .tbl tbody tr.attn { background: #f4f7fc; }
.app.theme-cool .tbl tbody tr.attn:hover { background: #ecf1f9; }
.app.theme-cool .firm-name .avatar { background: #e2eaf5; }

/* ── Theme: bright (white-on-white, Stripe-ish) ─────────── */
.app.theme-bright {
  --bg: #ffffff;
  --bg-2: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --line: #e6e8eb;
  --line-2: #eef0f3;
}
.app.theme-bright .card {
  box-shadow: var(--shadow-1);
}
.app.theme-bright .toolbar { background: #fafafa; }
.app.theme-bright .tbl tbody tr:hover { background: #fafafa; }
.app.theme-bright .tbl tbody tr.attn { background: #fbfbfc; }
.app.theme-bright .tbl tbody tr.attn:hover { background: #f4f5f8; }
.app.theme-bright .tbl tbody tr.attn td:first-child {
  box-shadow: inset 2px 0 0 var(--brand-700);
}

/* Reset / base inside artboards */
.app, .app * { box-sizing: border-box; }
.app {
  font-family: var(--ff-sans);
  color: var(--ink);
  background: var(--bg);
  width: 100%;
  height: 100%;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.app .mono { font-family: var(--ff-mono); font-feature-settings: "tnum" 1; }
.app a { color: var(--brand-700); text-decoration: none; }
.app a:hover { text-decoration: underline; }

/* ── Top bar ───────────────────────────────────────────── */
.topbar {
  background: var(--brand-800);
  color: #fff;
  height: 56px;
  border-bottom: 1px solid var(--brand-900);
}
.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 40px;
  gap: 32px;
}
.topbar .brand {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.topbar .brand .logo {
  width: 22px; height: 22px;
  background: #fff;
  color: var(--brand-800);
  border-radius: 5px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 12px;
  font-family: var(--ff-mono);
}
.topbar nav {
  display: flex; gap: 4px; align-items: center;
  flex: 1;
}
.topbar nav a {
  color: rgba(255,255,255,.78);
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 13.5px;
  font-weight: 500;
  display: flex; align-items: center; gap: 6px;
}
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.topbar nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.topbar nav a .pill {
  background: #e0b352; color: #3a2606;
  font-size: 11px; font-family: var(--ff-mono);
  padding: 1px 5px; border-radius: 999px; min-width: 18px;
  text-align: center; font-weight: 600;
  line-height: 1.4;
}
.topbar .right {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px; color: rgba(255,255,255,.72);
}
.topbar .right .spend {
  font-family: var(--ff-mono);
  background: rgba(255,255,255,.08);
  padding: 5px 10px;
  border-radius: 5px;
  color: rgba(255,255,255,.92);
  font-size: 12px;
  display: flex; align-items: center; gap: 6px;
}
.topbar .right .user {
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,.16);
  color: #fff; display: grid; place-items: center;
  font-weight: 600; font-size: 12px;
}

/* ── Page header / toolbars ────────────────────────────── */
.page {
  padding: 28px 40px 48px;
  max-width: 1440px;
  margin: 0 auto;
}
.page-head {
  display: flex; align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 20px;
}
.page-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}
.page-head .sub {
  color: var(--muted); font-size: 13px; margin-top: 4px;
}
.page-head .crumb {
  color: var(--muted-2); font-size: 12px;
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 6px;
}

.toolbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 16px;
}
.toolbar .grow { flex: 1; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

/* ── Inputs / buttons ──────────────────────────────────── */
.input {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13.5px;
  color: var(--ink);
  min-width: 240px;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus-within {
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px rgba(31,78,133,.12);
}
.input input {
  border: 0; outline: 0; background: transparent;
  font: inherit; color: inherit; width: 100%;
}
.input input::placeholder { color: var(--faint); }

.select {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13.5px; color: var(--ink);
  cursor: pointer;
}
.select .caret { color: var(--muted-2); margin-left: 2px; }
.select:hover { border-color: #d4d6db; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: inherit;
  font-size: 13px; font-weight: 500;
  padding: 8px 13px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--bg); }
.btn-secondary { border-color: var(--line); }
.btn-secondary:hover { border-color: #cfd2d8; background: var(--surface-2); }
.btn-primary {
  background: var(--brand-800); color: #fff; border-color: var(--brand-800);
}
.btn-primary:hover { background: var(--brand-700); border-color: var(--brand-700); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg-2); color: var(--ink); }
.btn-icon { padding: 7px; }
.btn-sm { padding: 5px 9px; font-size: 12.5px; }

/* Cost-bearing action: cost shown as adjoining mono badge */
.cost-action {
  display: inline-flex; align-items: stretch;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
}
.cost-action .btn {
  border: 0; border-radius: 0; background: var(--surface);
}
.cost-action .cost-badge {
  display: inline-flex; align-items: center;
  padding: 0 10px;
  background: var(--cost-bg);
  color: var(--cost-fg);
  font-family: var(--ff-mono);
  font-size: 12px;
  font-weight: 500;
  border-left: 1px solid var(--cost-bd);
  letter-spacing: -0.01em;
}
.cost-action:hover { border-color: #cfd2d8; }
.cost-action:hover .btn { background: var(--surface-2); }

/* Standalone cost badge */
.cost-badge-pill {
  display: inline-flex; align-items: center;
  font-family: var(--ff-mono);
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--cost-bg);
  color: var(--cost-fg);
  border: 1px solid var(--cost-bd);
}

/* ── Badges ────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.new { background: var(--new-bg); color: var(--new-fg); border-color: #cdd9ec; font-weight: 600; }
.badge.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: #f5d0a4; }
.badge.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: #bfdcc5; }
.badge.group { background: transparent; color: var(--muted); border-color: var(--line); }
.badge.dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .85;
}

/* ── Card / panel ──────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.card-head h2 {
  font-size: 14px; font-weight: 600; margin: 0;
  display: flex; align-items: center; gap: 9px;
  color: var(--ink);
}
.card-head h2 .count {
  font-family: var(--ff-mono);
  font-size: 12px; font-weight: 500;
  color: var(--muted-2);
  background: var(--bg);
  padding: 2px 7px;
  border-radius: 4px;
}
.card-head .meta { font-size: 12.5px; color: var(--muted); }

/* ── Table ─────────────────────────────────────────────── */
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  color: var(--muted-2);
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
.tbl thead th.sortable {
  cursor: pointer;
}
.tbl thead th .sort {
  margin-left: 4px; opacity: .55;
}
.tbl tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
  color: var(--ink);
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover { background: #fafaf6; }
.tbl tbody tr.attn { background: #fcfaf3; }
.tbl tbody tr.attn:hover { background: #f8f3e3; }

.firm-name { display: flex; align-items: center; gap: 11px; }
.firm-name .avatar {
  width: 30px; height: 30px;
  flex: 0 0 30px;
  border-radius: 6px;
  background: var(--brand-100);
  color: var(--brand-700);
  display: grid; place-items: center;
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
}
.firm-name .nm { font-weight: 500; color: var(--ink); line-height: 1.25; }
.firm-name .krs {
  font-family: var(--ff-mono);
  font-size: 11.5px;
  color: var(--muted-2);
  margin-top: 1px;
}

.whats-new { display: flex; flex-direction: column; gap: 3px; }
.whats-new .line {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--ink);
}
.whats-new .line .ic { color: var(--brand-700); }
.whats-new .none {
  color: var(--faint); font-size: 12.5px; font-style: italic;
}

.lastcheck { display: flex; flex-direction: column; line-height: 1.25; }
.lastcheck .rel { color: var(--ink); font-size: 13px; }
.lastcheck .abs {
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--muted-2);
}

.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Empty / hint ──────────────────────────────────────── */
.hint {
  display: flex; gap: 8px; align-items: center;
  color: var(--muted); font-size: 12.5px;
  padding: 12px 16px;
}

/* ── Variant B: attention card row ─────────────────────── */
.attn-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-2);
  align-items: center;
}
.attn-row:last-child { border-bottom: 0; }
.attn-row:hover { background: #fcfaf3; }
.attn-row .firm-block { display: flex; align-items: center; gap: 14px; min-width: 0; }
.attn-row .firm-block .avatar {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 8px;
  background: var(--brand-100); color: var(--brand-700);
  font-family: var(--ff-mono); font-size: 12px; font-weight: 600;
  display: grid; place-items: center;
}
.attn-row .docs {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 6px;
}
.attn-row .docs .doc {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--new-bg);
  color: var(--new-fg);
  border: 1px solid #cdd9ec;
  font-weight: 500;
}
.attn-row .docs .doc .dt {
  font-family: var(--ff-mono);
  color: var(--muted-2);
  font-weight: 400;
  font-size: 11px;
  margin-left: 2px;
}
.attn-row .right-actions {
  display: flex; align-items: center; gap: 10px;
}

/* ── Variant C: group section ──────────────────────────── */
.group-section { margin-bottom: 14px; }
.group-section .ghead {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-bottom: 0;
}
.group-section .ghead .chev { color: var(--muted-2); }
.group-section .ghead h3 {
  font-size: 13.5px; font-weight: 600; margin: 0;
  color: var(--ink);
}
.group-section .ghead .meta {
  color: var(--muted); font-size: 12.5px;
  margin-left: auto;
  display: flex; align-items: center; gap: 12px;
}
.group-section .ghead .meta .mono {
  font-family: var(--ff-mono); font-size: 11.5px; color: var(--muted-2);
}
.group-section .gbody {
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow: hidden;
}
.group-section .gbody .tbl thead th {
  background: var(--surface);
}

/* ── Subtle bits ───────────────────────────────────────── */
.kbd {
  display: inline-block;
  font-family: var(--ff-mono);
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface);
}
.divider {
  height: 1px; background: var(--line); margin: 24px 0;
}

/* ── Breadcrumb ────────────────────────────────────────── */
.crumbs {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  color: var(--muted-2);
  margin-bottom: 14px;
}
.crumbs a { color: var(--muted-2); }
.crumbs a:hover { color: var(--ink); text-decoration: none; }
.crumbs .sep { color: var(--faint); }
.crumbs .here { color: var(--ink); font-weight: 500; }

/* ── Firm hero ─────────────────────────────────────────── */
.firm-hero {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  margin-bottom: 20px;
}
.firm-hero .left { display: flex; gap: 16px; align-items: flex-start; min-width: 0; }
.firm-hero .left .avatar {
  width: 48px; height: 48px;
  border-radius: 10px;
  background: var(--brand-100);
  color: var(--brand-700);
  display: grid; place-items: center;
  font-family: var(--ff-mono);
  font-size: 15px;
  font-weight: 600;
  flex: 0 0 48px;
}
.firm-hero h1 {
  font-size: 19px;
  font-weight: 600;
  margin: 0 0 6px;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.firm-hero .meta-line {
  display: flex; gap: 14px; align-items: center;
  font-size: 12.5px;
  color: var(--muted);
  flex-wrap: wrap;
}
.firm-hero .meta-line .mono { color: var(--muted-2); }
.firm-hero .meta-line .sep { color: var(--line); }
.firm-hero .actions { display: flex; gap: 8px; align-items: center; }

/* ── Section header (inside firm/document pages) ───────── */
.sec-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin: 24px 0 12px;
}
.sec-head h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.sec-head h2 .count {
  font-family: var(--ff-mono); font-size: 12px; font-weight: 500;
  color: var(--muted-2);
  background: var(--bg-2);
  padding: 2px 7px;
  border-radius: 4px;
}
.sec-head .right { display: flex; gap: 8px; align-items: center; }

/* ── AI report card ────────────────────────────────────── */
.ai-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  align-items: center;
}
.ai-card .left h3 {
  font-size: 14px; font-weight: 600; margin: 0 0 4px;
  display: flex; align-items: center; gap: 8px;
}
.ai-card .left p { margin: 0; color: var(--muted); font-size: 13px; }
.ai-card .left .stat {
  display: inline-flex; align-items: center; gap: 5px;
  margin-top: 8px;
  font-family: var(--ff-mono);
  font-size: 11.5px;
  color: var(--muted-2);
}
.ai-card .right { display: flex; gap: 8px; align-items: center; }

/* ── Filter chips ──────────────────────────────────────── */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { background: var(--surface-2); color: var(--ink); }
.chip.on {
  background: var(--brand-800);
  border-color: var(--brand-800);
  color: #fff;
}
.chip .num {
  font-family: var(--ff-mono);
  font-size: 11px;
  background: rgba(255,255,255,.15);
  padding: 1px 5px;
  border-radius: 3px;
}
.chip:not(.on) .num { background: var(--bg-2); color: var(--muted-2); }

/* ── Document tables ───────────────────────────────────── */
.doc-icon {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  border-radius: 5px;
  display: grid; place-items: center;
  background: var(--brand-50);
  color: var(--brand-700);
}
.doc-meta { display: flex; gap: 10px; align-items: center; }
.doc-meta .nm {
  font-weight: 500;
  color: var(--ink);
  line-height: 1.25;
}
.doc-meta .sub {
  font-size: 11.5px; color: var(--muted-2);
  font-family: var(--ff-mono);
  margin-top: 1px;
}

.dl-state {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.dl-state .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-2);
}
.dl-state.cached .dot { background: var(--ok-fg); }
.dl-state.loading .dot {
  background: var(--brand-700);
  animation: pulse 1.4s ease-in-out infinite;
}
.dl-state.notdl .dot { background: var(--faint); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ── Chat layout ──────────────────────────────────────── */
.chat-wrap {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  height: calc(100vh - 56px);
  padding: 20px;
}
.chat-side {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.chat-side .ctx-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.chat-side .ctx-head h3 {
  font-size: 13px; font-weight: 600; margin: 0;
  display: flex; align-items: center; justify-content: space-between;
}
.chat-side .ctx-head .summary {
  margin-top: 6px;
  font-size: 11.5px; color: var(--muted-2);
  font-family: var(--ff-mono);
}
.chat-side .tree {
  flex: 1;
  overflow: auto;
  padding: 6px 0;
}
.tree-firm {
  padding: 6px 14px 4px;
}
.tree-firm > .firm-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  padding: 4px 0;
  cursor: pointer;
  flex-wrap: nowrap;
  min-width: 0;
}
.tree-firm > .firm-row > span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.tree-firm > .firm-row .chev { color: var(--muted-2); flex-shrink: 0; }
.tree-firm > .firm-row .cnt {
  margin-left: auto;
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--muted-2);
  flex-shrink: 0;
}
.tree-doc {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 8px 4px 28px;
  border-radius: 4px;
  cursor: pointer;
}
.tree-doc:hover { background: var(--bg-2); color: var(--ink); }
.tree-doc input[type="checkbox"] { accent-color: var(--brand-700); }
.tree-doc .dt {
  margin-left: auto;
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--faint);
}

.chat-side .model-picker {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  background: var(--surface-2);
}
.chat-side .model-picker .lbl {
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin-bottom: 6px;
}
.model-radios { display: flex; flex-direction: column; gap: 4px; }
.model-radio {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
}
.model-radio:hover { background: var(--surface); }
.model-radio.on {
  background: var(--surface);
  border-color: var(--brand-100);
  box-shadow: 0 0 0 1px var(--brand-700) inset;
}
.model-radio .dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  flex: 0 0 14px;
  position: relative;
}
.model-radio.on .dot {
  border-color: var(--brand-700);
}
.model-radio.on .dot::after {
  content: ""; position: absolute;
  inset: 3px; border-radius: 50%;
  background: var(--brand-700);
}
.model-radio .name { font-weight: 500; flex: 1; }
.model-radio .cost {
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--cost-fg);
  background: var(--cost-bg);
  border: 1px solid var(--cost-bd);
  padding: 1px 6px;
  border-radius: 3px;
}

.chat-main {
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  position: relative;
}
.chat-main .chat-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.chat-main .chat-head h2 {
  font-size: 14px; font-weight: 600; margin: 0;
  color: var(--ink);
}
.chat-main .chat-head .ctx-pill {
  font-size: 12px;
  color: var(--muted-2);
  font-family: var(--ff-mono);
}
.chat-body {
  flex: 1;
  overflow: auto;
  padding: 24px 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.msg { display: flex; gap: 14px; align-items: flex-start; }
.msg .ava {
  width: 30px; height: 30px;
  border-radius: 6px;
  flex: 0 0 30px;
  display: grid; place-items: center;
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
}
.msg.user .ava { background: var(--bg-2); color: var(--ink); }
.msg.ai .ava { background: var(--brand-800); color: #fff; }
.msg .body { flex: 1; min-width: 0; }
.msg .body .who {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
  display: flex; gap: 10px; align-items: center;
}
.msg .body .who .when {
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--muted-2);
  font-weight: 400;
}
.msg .body .who .badge {
  margin-left: auto;
}
.msg .body .content {
  font-size: 14px;
  color: var(--ink-2);
  line-height: 1.55;
  min-height: 0;
  padding-top: 0;
}
.msg .body .content p { margin: 0 0 8px; }
.msg .body .content p:last-child { margin: 0; }
.msg .body .content ul,
.msg .body .content ol { margin: 6px 0 8px; padding-left: 20px; color: var(--ink-2); }
.msg .body .content li { margin-bottom: 4px; }
.msg .body .content h1,
.msg .body .content h2,
.msg .body .content h3,
.msg .body .content h4,
.msg .body .content h5,
.msg .body .content h6 {
  font-size: 14px; font-weight: 600;
  margin: 10px 0 4px; line-height: 1.35; color: var(--ink);
}
.msg .body .content h1:first-child,
.msg .body .content h2:first-child,
.msg .body .content h3:first-child { margin-top: 0; }
.msg .body .content blockquote { margin: 6px 0; padding-left: 10px; border-left: 2px solid var(--line); color: var(--muted-2); }
.msg .body .content pre {
  margin: 6px 0; padding: 10px 12px;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 6px; overflow-x: auto;
  font-family: var(--ff-mono); font-size: 12.5px; line-height: 1.45;
}
.msg .body .content code {
  font-family: var(--ff-mono); font-size: 12.5px;
  background: var(--bg-2); padding: 1px 5px; border-radius: 4px;
}
.msg .body .content pre code { background: none; padding: 0; }
.msg .body .content table {
  width: 100%;
  margin: 8px 0;
  border-collapse: collapse;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}
.msg .body .content table thead th {
  background: var(--bg-2);
  font-weight: 600;
  text-align: left;
}
.msg .body .content table th,
.msg .body .content table td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  vertical-align: top;
}
.msg .body .content table tbody tr:nth-child(even) td { background: rgba(15,23,42,0.02); }
.msg .body .content hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.msg .body .content > *:last-child { margin-bottom: 0; }

.chat-composer {
  border-top: 1px solid var(--line);
  padding: 14px 20px 16px;
  background: var(--surface);
}
.chat-composer .box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px 14px;
  transition: border-color .12s, box-shadow .12s;
}
.chat-composer .box:focus-within {
  border-color: var(--brand-600);
  box-shadow: 0 0 0 3px rgba(31,78,133,.1);
}
.chat-composer textarea {
  width: 100%;
  border: 0; outline: 0;
  background: transparent;
  resize: none;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  min-height: 56px;
  line-height: 1.5;
}
.chat-composer .footer-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px;
}
.chat-composer .hints {
  display: flex; gap: 12px; align-items: center;
  font-size: 11.5px; color: var(--muted-2);
}
.chat-composer .report-done {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  border: 1px solid var(--brand-200, var(--line));
  background: var(--brand-50, var(--bg-2));
  border-radius: 8px;
  padding: 12px 14px;
}
.chat-composer .report-done .left {
  display: flex; align-items: flex-start; gap: 10px; min-width: 0;
  color: var(--ink);
}
.chat-composer .report-done .left > svg,
.chat-composer .report-done .left > .ic {
  color: var(--brand-700); flex: 0 0 auto; margin-top: 2px;
}
.chat-composer .report-done .title {
  font-size: 13.5px; font-weight: 600; color: var(--ink); margin-bottom: 2px;
}
.chat-composer .report-done .desc {
  font-size: 12px; color: var(--muted-2); line-height: 1.4;
}

/* ── Modal: "Sprawdzamy zakres pytania" ─────────────────── */
.modal-overlay {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.32);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: 100;
}
.modal-overlay > .modal {
  display: block;
  position: static;
  width: 520px;
  height: auto;
  max-width: 520px;
  max-height: none;
  margin: 0;
  pointer-events: auto;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 24px 64px rgba(15,23,42,.24), 0 0 0 1px rgba(15,23,42,.06);
  overflow: hidden;
}
.modal-head {
  padding: 18px 22px 14px;
  display: flex; gap: 12px; align-items: flex-start;
}
.modal-head .ic {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  border-radius: 8px;
  background: var(--brand-100);
  color: var(--brand-700);
  display: grid; place-items: center;
}
.modal-head h3 { margin: 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.modal-head p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.modal-body { padding: 0 22px 16px; }
.modal-step {
  display: flex; gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line-2);
}
.modal-step:first-child { border-top: 0; }
.modal-step .num {
  width: 22px; height: 22px;
  flex: 0 0 22px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-2);
  color: var(--muted);
}
.modal-step.done .num { background: var(--ok-bg); color: var(--ok-fg); }
.modal-step.active .num { background: var(--brand-800); color: #fff; }
.modal-step .step-body { flex: 1; }
.modal-step .step-body .step-title {
  font-size: 13px; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.modal-step .step-body .step-desc { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.modal-step .step-body .verdict {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink-2);
}
.modal-foot {
  padding: 14px 22px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-foot .est {
  font-family: var(--ff-mono);
  font-size: 12px;
  color: var(--muted);
}
.modal-foot .est strong { color: var(--cost-fg); }

/* ── AI / reports mini-list ────────────────────────────── */
.reports-mini {
  display: flex; flex-direction: column;
  margin-top: 8px;
  gap: 2px;
}
.reports-mini .rep-row {
  display: grid;
  grid-template-columns: 14px 1fr auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--line-2);
}
.reports-mini .rep-row:last-child { border-bottom: 0; }
.reports-mini .rep-row:hover .rep-title { color: var(--brand-700); }
.reports-mini .rep-title {
  color: var(--ink); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reports-mini .rep-meta {
  font-size: 11.5px;
  color: var(--muted-2);
  font-family: var(--ff-mono);
}
.reports-mini .rep-when {
  font-size: 11.5px;
  color: var(--muted-2);
}
.reports-mini .rep-open {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border-radius: 4px;
  color: var(--muted-2);
}
.reports-mini .rep-open:hover { background: var(--bg-2); color: var(--brand-700); }

/* ── Modal verdict colors ──────────────────────────────── */
.modal-step.partial .num { background: var(--warn-bg); color: var(--warn-fg); }
.modal-step.fail .num { background: var(--danger-bg); color: var(--danger-fg); }
.modal-step .verdict.partial {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-fg);
  color: var(--warn-fg);
}
.modal-step .verdict.fail {
  background: var(--danger-bg);
  border-left: 3px solid var(--danger-fg);
  color: var(--danger-fg);
}
.modal-step .verdict ul {
  margin: 6px 0 0; padding-left: 18px;
}
.modal-step .verdict li { margin-bottom: 2px; }
.modal-step .verdict .label-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 4px; font-weight: 600;
}

/* ── /nowe-dokumenty — inbox ────────────────────────────── */
.inbox-day {
  margin-bottom: 24px;
}
.inbox-day-head {
  display: flex; align-items: center; gap: 12px;
  font-size: 12px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  margin: 0 4px 10px;
}
.inbox-day-head .line {
  flex: 1; height: 1px; background: var(--line);
}
.inbox-day-head .cnt {
  font-family: var(--ff-mono);
  text-transform: none;
  letter-spacing: 0;
  color: var(--muted-2);
  font-weight: 500;
}
.inbox-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.inbox-row {
  display: grid;
  grid-template-columns: 28px 1fr 240px 130px 240px;
  gap: 16px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-2);
}
.inbox-row:last-child { border-bottom: 0; }
.inbox-row:hover { background: #fafafa; }
.inbox-row .ic {
  width: 28px; height: 28px;
  border-radius: 5px;
  background: var(--brand-50);
  color: var(--brand-700);
  display: grid; place-items: center;
}
.inbox-row .doc-and-firm .doc-nm {
  font-weight: 500; color: var(--ink); font-size: 14px;
  display: flex; align-items: center; gap: 8px;
}
.inbox-row .doc-and-firm .firm-nm {
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.inbox-row .doc-and-firm .firm-nm .krs {
  font-family: var(--ff-mono); font-size: 11px; color: var(--muted-2);
}
.inbox-row .meta-col {
  font-size: 12.5px;
  color: var(--muted);
  display: flex; flex-direction: column; gap: 3px;
}
.inbox-row .meta-col .mono {
  font-family: var(--ff-mono); font-size: 11.5px; color: var(--muted-2);
}
.inbox-row .actions-col {
  display: flex; gap: 6px; justify-content: flex-end;
}

/* ── Stats strip on inbox top ──────────────────────────── */
.inbox-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.inbox-stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 14px 16px;
}
.inbox-stat .lbl {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted-2);
  font-weight: 600;
  margin-bottom: 6px;
}
.inbox-stat .val {
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  display: flex; align-items: baseline; gap: 8px;
}
.inbox-stat .val .unit {
  font-size: 13px; color: var(--muted-2); font-weight: 400;
}
.inbox-stat .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.fin-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  margin-bottom: 16px;
}
.fin-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface);
}
.fin-head h2 {
  font-size: 14px; font-weight: 600; margin: 0;
  display: flex; align-items: center; gap: 9px;
}
.fin-head .totals {
  display: flex; gap: 18px;
  font-size: 12px;
  color: var(--muted);
}
.fin-head .totals .label { color: var(--muted-2); }
.fin-head .totals .v { font-family: var(--ff-mono); color: var(--ink); margin-left: 4px; font-weight: 500; }

.fin-tree { padding: 6px 0; }
.fin-row {
  display: grid;
  grid-template-columns: 1fr 140px 140px;
  align-items: baseline;
  padding: 7px 18px;
  border-bottom: 1px solid var(--line-2);
  font-size: 13.5px;
}
.fin-row:last-child { border-bottom: 0; }
.fin-row:hover { background: var(--surface-2); }
.fin-row .label {
  color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.fin-row .chev { color: var(--faint); }
.fin-row .label .code {
  font-family: var(--ff-mono);
  font-size: 11px;
  color: var(--muted-2);
  margin-right: 4px;
}
.fin-row .v {
  font-family: var(--ff-mono);
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.fin-row .v.muted { color: var(--muted-2); }
.fin-row .v-head {
  font-size: 11px;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: right;
}
.fin-row.head {
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-weight: 500;
}
.fin-row.level-0 { font-weight: 600; background: var(--surface-2); }
.fin-row.level-0 .label { color: var(--ink); }
.fin-row.level-1 .label { padding-left: 22px; font-weight: 500; }
.fin-row.level-2 .label { padding-left: 44px; color: var(--ink-2); }
.fin-row.level-3 .label { padding-left: 66px; color: var(--muted); font-size: 13px; }
.fin-row.sum {
  background: #f8fafc;
  font-weight: 600;
}
.fin-row.sum .v { color: var(--brand-800); }

