:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --surface-3: #f3f3f1;
  --border: #e2e2dd;
  --border-strong: #cfcfc8;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #86857f;
  --accent: #2a78d6;
  --accent-deep: #184f95;
  --accent-wash: #eaf2fd;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --s100: #cde2fb; --s200: #9ec5f4; --s300: #6da7ec; --s400: #3987e5;
  --s450: #2a78d6; --s500: #256abf; --s550: #1c5cab; --s600: #184f95;
  --s650: #104281; --s700: #0d366b;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(11,11,11,.06), 0 4px 12px rgba(11,11,11,.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--surface-3);
  color: var(--text-primary);
  font-family: "Segoe UI", "Assistant", "Rubik", system-ui, -apple-system, Arial, sans-serif;
  font-size: 14px;
}

/* ── shell ───────────────────────────────────────────── */
header.topbar {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex; align-items: center; gap: 22px;
  position: sticky; top: 0; z-index: 40;
  height: 56px;
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--text-muted); }

nav.tabs { display: flex; gap: 2px; height: 100%; }
nav.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 0 15px; height: 100%; cursor: pointer;
  font: inherit; font-weight: 500; color: var(--text-secondary);
}
nav.tabs button:hover { color: var(--text-primary); background: var(--surface-3); }
nav.tabs button.active { color: var(--accent-deep); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ── cards & bars ────────────────────────────────────── */
.card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px;
}
.card > h2 {
  margin: 0; padding: 13px 16px; font-size: 14px; font-weight: 650;
  border-bottom: 1px solid var(--border); display: flex;
  align-items: center; gap: 10px; flex-wrap: wrap;
}
.card > h2 .sub { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.card .body { padding: 14px 16px; }

.filters {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end;
  padding: 13px 16px; background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 11px; color: var(--text-muted); font-weight: 600; }
select, input, textarea {
  font: inherit; padding: 6px 9px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: var(--surface-2); color: var(--text-primary);
  min-height: 32px;
}
select:focus, input:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
input[type=number] { width: 84px; }

button.btn {
  font: inherit; font-weight: 550; padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text-primary); cursor: pointer; min-height: 32px;
}
button.btn:hover { background: var(--surface-3); }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn.primary:hover { background: var(--accent-deep); }
button.btn.ghost { border-color: transparent; color: var(--text-secondary); padding: 5px 8px; }
button.btn.ghost:hover { background: var(--surface-3); color: var(--critical); }
button.btn.sm { padding: 3px 9px; min-height: 26px; font-size: 12px; }

/* ── stat tiles ──────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px; box-shadow: var(--shadow);
}
.tile .label { font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 5px; }
.tile .value { font-size: 21px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .value.warn { color: var(--critical); }
.tile .value.ok { color: var(--good); }
.tile .note { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ── tables ──────────────────────────────────────────── */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
thead th {
  background: var(--surface-1); font-weight: 650; font-size: 11.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}

/* choosing a unit: a box you type into, and one list for the whole page */
.upick { display: inline-flex; width: 100%; position: relative; }
.upick .upick-text { width: 100%; }
#upick-list { position: fixed; display: none; z-index: 80; max-height: 320px; overflow: auto;
  background: var(--surface-1, #fff); border: 1px solid var(--border-strong); border-radius: 8px;
  box-shadow: 0 12px 34px rgba(0,0,0,.22); font-size: 13px; padding: 4px 0; }
#upick-list [data-uid] { padding: 5px 10px; cursor: pointer; white-space: normal; line-height: 1.3; }
#upick-list .upick-unit { display: inline-block; min-width: 34px; padding: 0 5px; margin-right: 4px; border-radius: 4px; background: var(--surface-2); text-align: center; }
#upick-list [data-uid]:hover, #upick-list [data-uid].on { background: var(--surface-2); }
#upick-list .upick-co { padding: 6px 10px 2px; font-size: 11px; font-weight: 650; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em; position: sticky; top: 0; background: var(--surface-1, #fff); }
#upick-list .upick-none { padding: 10px; color: var(--text-secondary); }

/* the grip at the right edge of every column heading */
.colgrip { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 3; border-radius: 2px; }
.colgrip:hover, .colgrip.on { background: color-mix(in srgb, var(--accent, #2563eb) 45%, transparent); }

/* kept as a no-op so markup stays stable */
.ltr { unicode-bidi: isolate; }
.nowrap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
tbody tr:hover { background: var(--accent-wash); }
td.num, th.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
td.strong { font-weight: 650; }
tfoot td { font-weight: 700; background: var(--surface-1); border-top: 2px solid var(--border-strong); border-bottom: none; }
.muted { color: var(--text-muted); }
.warnrow td { background: #fdf0f0; }
tbody tr.warnrow:hover td { background: #fbe4e4; }

td input, td select { padding: 3px 6px; min-height: 26px; font-size: 12.5px; }
td input.amt { width: 92px; text-align: right; }
td input.wk { width: 74px; text-align: right; }

/* magnitude bar inside a table cell (single series, one hue) */
.bar { height: 6px; border-radius: 4px; background: var(--accent); min-width: 2px; }
.barcell { width: 116px; }
.bartrack { background: var(--surface-3); border-radius: 4px; height: 6px; width: 100%; }

/* ── chips ───────────────────────────────────────────── */
.chip {
  display: inline-block; padding: 1px 7px; border-radius: 10px;
  font-size: 11px; font-weight: 650; border: 1px solid var(--border-strong);
  background: var(--surface-3); color: var(--text-secondary);
}
.chip.lv { color: #fff; border: none; min-width: 21px; text-align: center; margin-inline-end: 3px; }
.chip.sold { color: var(--text-muted); }
.chip.bad { background: #fbe4e4; border-color: #f0c4c4; color: #8f2020; }
.chip.good { background: #e6f6e6; border-color: #bfe6bf; color: #076707; }

.statusdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-inline-end: 6px; }

/* ── misc ────────────────────────────────────────────── */
.rowactions { display: flex; gap: 4px; justify-content: flex-start; }
.empty { padding: 34px; text-align: center; color: var(--text-muted); }
.hint { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; }
.toast {
  position: fixed; bottom: 20px; inset-inline-start: 20px; z-index: 100;
  background: #0b0b0b; color: #fff; padding: 10px 16px; border-radius: 7px;
  font-size: 13px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px);
  transition: opacity .18s, transform .18s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 7px; overflow: hidden; }
.seg button {
  font: inherit; font-weight: 550; border: none; background: var(--surface-2);
  padding: 6px 15px; cursor: pointer; color: var(--text-secondary); min-height: 32px;
}
.seg button + button { border-inline-start: 1px solid var(--border-strong); }
.seg button.active { background: var(--accent); color: #fff; }

.invoice-total {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--accent-deep); color: #fff; padding: 13px 18px;
  border-radius: var(--radius); font-size: 17px; font-weight: 700; margin-top: 14px;
}
details.subtable { margin: 0; }
details.subtable > summary {
  cursor: pointer; padding: 9px 16px; font-weight: 620; font-size: 13px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.lvlegend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); }
.lvlegend i { width: 15px; height: 9px; border-radius: 2px; display: inline-block; }

@media print {
  header.topbar, .filters, nav.tabs, .noprint { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  main { padding: 0; max-width: none; }
  thead th { position: static; }
}


/* ── invoices & import ───────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 30px; text-align: center; color: var(--text-secondary);
  background: var(--surface-1); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-wash); }
.dropzone b { color: var(--accent-deep); }

.statusbadge { display: inline-flex; align-items: center; gap: 5px; font-weight: 620; font-size: 12px; }
.statusbadge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.st-matched { color: var(--good); }
.st-review { color: #b07600; }
.st-unmatched { color: var(--text-muted); }
.st-unreadable { color: var(--critical); }

.candrow { background: var(--surface-1); }
.candrow td { padding: 0; }
.candbox { padding: 10px 14px 14px; }
.candbox h4 { margin: 0 0 8px; font-size: 12px; color: var(--text-secondary); font-weight: 650; }
.cand {
  display: flex; align-items: center; gap: 12px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); margin-bottom: 6px;
}
.cand .why { color: var(--text-muted); font-size: 12px; flex: 1; }
.cand .sc {
  font-weight: 700; font-variant-numeric: tabular-nums; min-width: 34px; text-align: center;
  padding: 1px 6px; border-radius: 5px; background: var(--accent-wash); color: var(--accent-deep);
}
.mapgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
code.path {
  background: var(--surface-3); padding: 2px 6px; border-radius: 4px;
  font-size: 12px; word-break: break-all;
}

select.miss { border-color: #e8a0a0; background: #fdf5f5; }
.candbox .tablewrap { max-height: 460px; overflow-y: auto; }
.candbox table thead th { position: sticky; top: 0; z-index: 2; }

/* a statement went out and the numbers behind it have since moved */
.warnbanner {
  margin-top: 12px; padding: 10px 14px; border-radius: var(--radius);
  background: #fdf3e7; border: 1px solid #f0d2a8; color: #7a4b12; font-size: 13px;
}
.warnbanner b { color: #5d3809; }

.whoami { margin-left: auto; display: flex; align-items: center; gap: 8px; }
/* what the last pull brought in, under the button that pulls */
#pull-panel { position: absolute; right: 0; top: 36px; width: 420px; max-height: 70vh; overflow: auto; z-index: 70;
  background: var(--surface-1, #fff); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2); padding: 12px 14px; font-size: 13px; text-align: left; }
#pull-panel h4 { margin: 0 0 6px; }
#pull-panel ul { margin: 4px 0 10px 18px; padding: 0; }
#pull-panel li { margin: 2px 0; }

/* A disabled button looked exactly like a working one, so "Scan Drive now"
   read as broken rather than as waiting for its credentials. */
.btn:disabled, .btn:disabled:hover {
  opacity: .45;
  cursor: not-allowed;
  filter: saturate(.4);
}


/* A folded card keeps its heading and nothing else, so a long screen can be
   read without scrolling past three hundred rows to reach the next section. */
.card > h2 .caret {
  display: inline-block;
  width: 14px;
  margin-right: 2px;
  color: var(--text-muted);
  font-size: 11px;
  user-select: none;
}
.card.collapsed > h2 { border-bottom: none; margin-bottom: 0; }
.card > h2[data-collapsible]:hover .caret { color: var(--text); }


/* The three levels of the portfolio table. Indentation alone is not enough to
   read at a glance which row is a company, which a building and which a unit,
   so each level gets its own weight and ground. */
#tbl-tree tr.lvl-co > td { background: var(--surface-2); font-size: 13px; }
#tbl-tree tr.lvl-co > td:first-child { font-weight: 650; }
#tbl-tree tr.lvl-pr > td { background: var(--surface-1, transparent); }
#tbl-tree tr.lvl-pr > td:first-child { font-weight: 500; }
#tbl-tree tr.lvl-u > td { color: var(--text); }
#tbl-tree tr[data-toggle] { cursor: pointer; }
#tbl-tree .tw { display: inline-block; width: 14px; color: var(--text-muted); font-size: 11px; }
#tbl-tree tr.lvl-co:hover > td, #tbl-tree tr.lvl-pr:hover > td { filter: brightness(0.98); }

/* Our portfolio and other people's property are two different questions, so
   they get two headings rather than one continuous list. */
#tbl-tree tr.lvl-sec > td {
  background: var(--text, #1a1a1a);
  color: #fff;
  font-weight: 650;
  font-size: 12px;
  letter-spacing: .02em;
  padding-top: 9px;
  padding-bottom: 9px;
}
#tbl-tree tr.lvl-sec .muted { color: rgba(255,255,255,.62); font-weight: 400; }

/* ── projects: two halves side by side ───────────────── */
/* the owner asked for the two halves one under the other, not side by side */
.split { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }

/* how much of a budget has gone, read at a glance before reading the number */
.bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent, #3987e5); }
.bar.over > i { background: #c0392b; }

/* a charge whose invoice is linked is settled: read, not edited */
tr.settled td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
input[data-bank][readonly] { border-color: transparent; background: transparent; cursor: default; }

/* one block per card on the invoices screen; the months sit inside it */
tr.lvl-card td { background: var(--surface-2); font-weight: 600; font-size: 14px; padding: 12px 12px 8px; border-top: 2px solid var(--border-strong); }

/* the invoice, shown while the mouse rests on its name */
#inv-preview { position: fixed; top: 70px; width: min(560px, 45vw); height: min(760px, 85vh);
  background: var(--surface-1, #fff); border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25); z-index: 60; overflow: hidden; display: none; }
#inv-preview iframe, #inv-preview img { width: 100%; height: 100%; border: 0; object-fit: contain; background: #fff; }

/* a property as a whole: one segment per unit, each in its own readiness colour */
.rrstack { display: inline-flex; gap: 1px; width: 140px; height: 12px; border-radius: 3px; overflow: hidden; vertical-align: middle; }
.rrstack i { flex: 1; display: block; min-width: 3px; }

/* where a unit stands today: ten cells, filled to its level */
.bar10 { display: inline-flex; gap: 2px; vertical-align: middle; }
.bar10 i { display: inline-block; width: 9px; height: 12px; border-radius: 2px; }
