:root {
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --line: #E2E8F0;
  --line-soft: #EEF2F6;
  --ink: #0F172A;
  --ink-2: #475569;
  --ink-3: #64748B;
  --accent: #0B6B57;
  --accent-hover: #08493B;
  --accent-soft: #E6F2EF;
  --accent-ink: #0B5345;
  --side: #0E2A24;
  --side-ink: #E7F0EE;
  --side-ink-2: #A7C4BC;
  --side-active: #17423A;
  --warn-bg: #FEF3C7; --warn-ink: #92400E;
  --bad-bg: #FEE4E2;  --bad-ink: #B42318;
  --info-bg: #E0EAFF; --info-ink: #1D4ED8;
  --mute-bg: #EEF2F6; --mute-ink: #334155;
  --pos: #067647; --neg: #B42318;
  --radius: 12px;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); } .neg { color: var(--neg); }

/* layout */
.layout { display: flex; min-height: 100vh; }
.side { width: 232px; flex: none; background: var(--side); color: var(--side-ink); padding: 22px 14px;
        display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { padding: 4px 10px 22px; display: flex; flex-direction: column; gap: 2px; }
.brand img { display: block; width: 168px; height: auto; }
.brand span { font-size: 12px; color: var(--side-ink-2); }
.nav { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 12px; border-radius: 8px;
       color: var(--side-ink); text-decoration: none; font-weight: 500; }
.nav:hover { background: var(--side-active); color: #fff; }
.nav.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #5FD3B3; }
.nav .count { margin-left: auto; background: #F59E0B; color: #1F1300; font-size: 11px; font-weight: 700;
              border-radius: 999px; padding: 1px 7px; }
.side-foot { margin-top: auto; padding: 18px 10px 4px; font-size: 12px; color: var(--side-ink-2);
             display: flex; flex-direction: column; gap: 6px; }
.side-foot b { color: #fff; font-weight: 600; }
.side-foot button { align-self: flex-start; background: none; border: 1px solid #2F5A51; color: var(--side-ink);
                    border-radius: 6px; padding: 6px 10px; font: inherit; cursor: pointer; }
.main { flex: 1; min-width: 0; padding: 24px 32px 56px; }
.page { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head .sub { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.cols { display: flex; flex-wrap: wrap; gap: 18px; }
.cols > * { flex: 1 1 360px; min-width: 0; }

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.kpi .label { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .02em; }
.kpi b { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--ink-2); }
.empty { padding: 28px; text-align: center; color: var(--ink-2); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--info-bg); color: var(--info-ink); font-size: 13px; }

/* tables */
.tblwrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 10px 14px;
          border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th.num, .tbl td.num { text-align: right; }
.tbl tr.voided td, .tbl tr.rejected td { color: var(--ink-3); text-decoration: line-through; }
.tbl tr.voided td.keep, .tbl tr.rejected td.keep { text-decoration: none; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #F6FAF9; }
.tbl tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--line); }

/* controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px;
       border-radius: 8px; border: 1px solid #CBD5E1; background: var(--surface); color: var(--ink);
       font: 500 13px Inter, system-ui, sans-serif; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: #F1F5F9; color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--bad-ink); border-color: #F4B7B0; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 12px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--accent-soft); color: var(--accent-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill.bad { background: var(--bad-bg); color: var(--bad-ink); }
.pill.info { background: var(--info-bg); color: var(--info-ink); }
.pill.mute { background: var(--mute-bg); color: var(--mute-ink); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; background: none; font: 500 13px Inter, system-ui, sans-serif; color: var(--ink-2);
       cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; text-decoration: none; }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }
select.inline { height: 34px; border: 1px solid #CBD5E1; border-radius: 8px; padding: 0 8px; font: inherit; background: #fff; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.form fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin: 0;
                 display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.form legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.field .help { font-size: 11px; color: var(--ink-3); }
.field input, .field select, .field textarea { height: 38px; border: 1px solid #CBD5E1; border-radius: 8px; padding: 0 10px;
       font: 14px Inter, system-ui, sans-serif; color: var(--ink); background: #fff; width: 100%; }
.field textarea { height: 64px; padding: 8px 10px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #9AD9C7; border-color: var(--accent); }
.form .error { background: var(--bad-bg); color: var(--bad-ink); padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.form .actions { display: flex; justify-content: flex-end; gap: 8px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
         box-shadow: 0 20px 60px rgba(15, 23, 42, .25); }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dlg-head { padding: 18px 20px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dlg-body { padding: 16px 20px 20px; }
.x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-2); min-width: 36px; min-height: 36px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); padding: 11px 16px; border-radius: 10px;
         background: var(--ink); color: #fff; font-size: 13px; box-shadow: 0 10px 30px rgba(15,23,42,.25); z-index: 50; max-width: calc(100vw - 32px); }
.toast.bad { background: var(--bad-ink); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
         background: linear-gradient(180deg, var(--side) 0 38%, var(--bg) 38%); }
.login .card { width: min(400px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 16px; }

/* phone-only pieces are hidden on desktop */
.mhead, .tabbar, .only-mobile { display: none; }

/* holdings / client cards (phone) */
.mcards { display: flex; flex-direction: column; gap: 8px; }
.mcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
         display: flex; flex-direction: column; gap: 6px; text-align: left; font: inherit; color: inherit; width: 100%; }
button.mcard { cursor: pointer; }
.mcard .l1, .mcard .l2, .mcard .l3 { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.mcard .l1 b { font-size: 15px; }
.mcard .l1 .v { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mcard .l2, .mcard .l3 { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* compact stat strip and sortable headers (Live client window) */
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .label { font-size: 11px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .02em; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--ink-2); }
.sortbtn { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; white-space: nowrap; }
.sortbtn:hover { color: var(--accent-ink); }
.sortbtn.on { color: var(--accent-ink); }
.ibtn { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1px solid #CBD5E1;
        background: #fff; color: var(--ink-2); font: 600 12px Georgia, serif; cursor: pointer; margin-left: 6px; vertical-align: middle; }
.ibtn:hover { border-color: var(--accent); color: var(--accent); }
details.card > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 6px; }
.kvgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 24px; }

/* phone layout — keep LAST so it overrides the rules above */
@media (max-width: 860px) {
  body { font-size: 14px; -webkit-text-size-adjust: 100%; }
  .layout { flex-direction: column; }
  .side { display: none; }
  .mhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: 0; z-index: 30;
           background: var(--side); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
  .mhead img { display: block; height: 26px; width: auto; }
  .mhead span { font-size: 12px; color: var(--side-ink-2); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--surface);
            border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
            min-height: 56px; font: 500 11px Inter, system-ui, sans-serif; color: var(--ink-3); text-decoration: none;
            background: none; border: 0; position: relative; }
  .tabbar .active { color: var(--accent); }
  .tabbar .dot { position: absolute; top: 7px; left: calc(50% + 6px); background: #F59E0B; color: #1F1300; font-size: 10px;
                 font-weight: 700; border-radius: 999px; padding: 0 5px; line-height: 15px; }
  .main { padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }
  .page { gap: 14px; }
  h1 { font-size: 20px; }
  .page-head { align-items: flex-start; }
  .page-head .row { width: 100%; }
  .only-mobile { display: block; }
  .only-desktop { display: none !important; }

  /* two compact tiles per row */
  .strip, .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat, .kpi { padding: 9px 11px; }
  .stat b, .kpi b { font-size: 15.5px; }
  .stat .hint, .kpi .hint { font-size: 11px; }
  .cols > * { flex-basis: 100%; }

  /* tables marked .stack become one card per row; labels come from the header */
  .tbl.stack thead { display: none; }
  .tbl.stack, .tbl.stack tbody, .tbl.stack tfoot, .tbl.stack tr, .tbl.stack td { display: block; width: 100%; }
  .tbl.stack tr { border-bottom: 1px solid var(--line); padding: 8px 12px; }
  .tbl.stack td { border: 0; padding: 3px 0; white-space: normal; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .tbl.stack td:first-child { font-size: 15px; text-align: left; }
  .tbl.stack td:first-child::before { display: none; }
  .tbl.stack td[data-label]::before { content: attr(data-label); color: var(--ink-3); font-size: 12px; text-align: left; flex: none; }
  .tbl.stack td:empty { display: none; }
  .tblwrap { border-radius: 10px; }

  /* dialogs fill the screen */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; margin: 0; }
  .dlg-head { padding-top: calc(14px + env(safe-area-inset-top)); position: sticky; top: 0; background: var(--surface); z-index: 1; padding-bottom: 8px; }
  .dlg-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .login { background: var(--side); }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

