/* Trafford Park Management System
   Clean light theme · navy brand · Inter · balanced density */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/inter-latin-wght-normal.woff2") format("woff2-variations"), url("/static/fonts/inter-latin-wght-normal.woff2") format("woff2");
}

:root {
  /* Surfaces */
  --bg: #f4f6f9;
  --card: #ffffff;
  --card-2: #f8fafc;
  --line: #e3e8ef;
  --line-strong: #cbd5e1;
  /* Text */
  --ink: #0f172a;
  --ink-2: #1e293b;
  --muted: #475569;
  --faint: #64748b;
  /* Brand (navy) */
  --brand: #1e3a5f;
  --brand-hover: #27497a;
  --brand-press: #172f4d;
  --brand-soft: #eaf0f7;
  --brand-line: #c9d6e6;
  --link: #1d4ed8;
  --ring: rgba(37, 99, 235, .35);
  /* Sidebar */
  --side: #0e1c30;
  --side-ink: #b8c4d6;
  --side-hover: #16294a;
  --side-active: #1d3459;
  --side-accent: #60a5fa;
  /* Status */
  --ok: #047857; --ok-soft: #ecfdf5; --ok-line: #a7f3d0;
  --warn: #b45309; --warn-soft: #fffbeb; --warn-line: #fde68a;
  --bad: #b91c1c; --bad-soft: #fef2f2; --bad-line: #fecaca;
  --wa: #128c4a; --wa-hover: #0f7a40;
  /* Shape */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* hidden must win over display styles like .btn */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/1.55 var(--font); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: #1e40af; }
h1 { font-size: 1.5rem; font-weight: 650; line-height: 1.25; margin: 0; letter-spacing: -.015em; color: var(--ink); }
h2 { font-size: 1.03rem; font-weight: 650; line-height: 1.35; margin: 0 0 14px; letter-spacing: -.005em; color: var(--ink); }
h3 { font-size: .95rem; font-weight: 650; margin: 20px 0 10px; color: var(--ink); }
p { margin: 0 0 10px; }
strong { font-weight: 600; }
code { font: 500 .82em/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--ink-2); }
.lead { color: var(--muted); margin: 6px 0 0; font-size: .94rem; max-width: 72ch; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
::selection { background: #dbe7f6; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 6px; }

/* ================= Shell ================= */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto; padding: 18px 14px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; color: #fff; text-decoration: none; padding: 4px 8px 22px; font-weight: 650; font-size: .98rem; line-height: 1.2; letter-spacing: -.005em; }
.brand:hover { color: #fff; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; display: grid; place-items: center;
  background: linear-gradient(145deg, #3b6aa8, #1e3a5f); color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .04em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.brand-sub { display: block; font-size: .72rem; font-weight: 500; color: #8193ad; margin-top: 3px; letter-spacing: .01em; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side a.nav {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 12px;
  color: var(--side-ink); text-decoration: none; border-radius: 9px; font-size: .925rem; font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.side a.nav svg { width: 19px; height: 19px; opacity: .85; }
.side a.nav:hover { background: var(--side-hover); color: #fff; }
.side a.nav.active { background: var(--side-active); color: #fff; font-weight: 600; }
.side a.nav.active::before { content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--side-accent); }
.side a.nav.active svg { opacity: 1; color: var(--side-accent); }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 11px; padding: 14px 8px 4px; border-top: 1px solid #1d2f4a; color: #fff; font-size: .86rem; line-height: 1.3; }
.side-foot .avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: #24406a; color: #dbe7f6; font-size: .78rem; font-weight: 650; flex-shrink: 0; }
.side-foot span { display: block; color: #8193ad; font-size: .76rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.scrim { display: none; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 32px; min-height: 64px;
  background: rgba(255, 255, 255, .92); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 15;
}
.topbar-title { font-weight: 650; font-size: 1.05rem; color: var(--ink); letter-spacing: -.01em; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { display: flex; align-items: center; gap: 14px; font-size: .86rem; color: var(--muted); }
.who form { margin: 0; }
.mode-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); font-size: .76rem; font-weight: 600; white-space: nowrap; }
.mode-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.menu-btn { display: none; background: none; border: 0; padding: 8px; margin-left: -8px; color: var(--ink); cursor: pointer; border-radius: 8px; }
.menu-btn svg { width: 24px; height: 24px; }
.testbar { display: none; }

/* Section tabs */
.subnav { display: flex; gap: 4px; padding: 0 26px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; position: sticky; top: 64px; z-index: 14; }
.subnav::-webkit-scrollbar { display: none; }
.subnav a {
  position: relative; padding: 14px 12px 13px; text-decoration: none; color: var(--faint); font-weight: 550; font-size: .9rem;
  white-space: nowrap; transition: color .15s var(--ease);
}
.subnav a:hover { color: var(--ink); }
.subnav a.active { color: var(--brand); }
.subnav a.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px; background: var(--brand); }

.content { padding: 30px 32px 80px; width: 100%; max-width: 1280px; }

/* ================= Page structure ================= */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px 20px; margin-bottom: 24px; }
.page-head > div:first-child { min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px 28px; margin-bottom: 20px; box-shadow: var(--shadow-sm); }
.card.flush { padding: 0; }
/* Safety net: a table too wide for the screen scrolls inside its card (cards with drop-down panels stay unclipped) */
.card.flush:not(:has(details.manage)) { overflow-x: auto; }
/* Rounded corners without clipping, so drop-down panels can float over the card */
.card.flush > :first-child, .card.flush > table:first-child thead tr:first-child th:first-child { border-top-left-radius: calc(var(--radius) - 1px); }
.card.flush > :first-child, .card.flush > table:first-child thead tr:first-child th:last-child { border-top-right-radius: calc(var(--radius) - 1px); }
.card.flush > table:last-child tbody:last-child tr:last-child td:first-child,
.card.flush > table:last-child tfoot tr:last-child td:first-child { border-bottom-left-radius: calc(var(--radius) - 1px); }
.card.flush > table:last-child tbody:last-child tr:last-child td:last-child,
.card.flush > table:last-child tfoot tr:last-child td:last-child { border-bottom-right-radius: calc(var(--radius) - 1px); }
.card.flush > h2 { padding: 22px 28px 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 16px; }
.card.flush .card-head { padding: 20px 28px; margin: 0; border-bottom: 1px solid var(--line); min-height: 76px; }
.card-head h2 { margin: 0; }
.card-foot { padding: 18px 28px; line-height: 1.6; border-top: 1px solid var(--line); background: var(--card-2); }
.card-band { padding: 20px 28px 4px; border-bottom: 1px solid var(--line); background: var(--card-2); }
@media (max-width: 900px) { .card-band { padding: 18px 18px 2px; } }
.card.flush > .card-foot:last-child { border-radius: 0 0 var(--radius) var(--radius); }

.grid { display: grid; gap: 16px; }
.grid.k4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.k3 { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.grid.k2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }

/* KPI tiles */
.stat {
  position: relative; display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease), transform .15s var(--ease);
}
a.stat:hover { color: inherit; border-color: var(--brand-line); box-shadow: var(--shadow); }
a.stat:active { transform: translateY(1px); }
.stat .k { font-size: .8rem; color: var(--faint); font-weight: 550; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.stat .v { font-size: 1.5rem; font-weight: 650; margin-top: 8px; line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -.02em; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { font-size: .82rem; color: var(--muted); margin-top: 6px; }
/* Tiles that need attention: amber edge + dot */
.stat.alert { box-shadow: inset 3px 0 0 #f59e0b, var(--shadow-sm); }
.stat.alert .k::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; flex-shrink: 0; }

.section-title { font-size: .74rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); margin: 32px 0 12px; }
.section-title:first-child { margin-top: 0; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 0; font-size: .92rem; }
.dl dt { color: var(--faint); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; color: var(--ink-2); }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); font-size: .93rem; }
.empty::before {
  content: ""; display: block; width: 40px; height: 40px; margin: 0 auto 12px; border-radius: 12px; background: var(--brand-soft)
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231e3a5f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 7h16M4 12h10M4 17h7'/%3E%3C/svg%3E") center / 20px no-repeat;
}

/* ================= Tables ================= */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; line-height: 1.5; }
th, td { padding: 20px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th {
  font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--faint);
  background: var(--card-2); white-space: nowrap; padding-top: 14px; padding-bottom: 14px;
}
td { color: var(--ink-2); }
td strong { color: var(--ink); }
tbody tr { transition: background .12s var(--ease); }
tbody tr:hover td { background: #fafbfd; }
tbody tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { padding-left: 28px; }
th:last-child, td:last-child { padding-right: 28px; }
tr.group td, tbody tr.group:hover td { background: #eef3f9; color: var(--brand); font-size: .74rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; padding-top: 11px; padding-bottom: 11px; border-bottom-color: var(--brand-line); }
tfoot td { padding-top: 18px; padding-bottom: 18px; font-weight: 650; background: var(--card-2); border-top: 1px solid var(--line-strong); border-bottom: 0; color: var(--ink); }
tr.is-off td { color: #94a3b8; }
tr.is-off td strong { color: #94a3b8; }
td.tick, th.tick { text-align: center; }
td.primary { min-width: 190px; }
td.primary strong { white-space: nowrap; }
th.right:last-child, td.right:last-child { width: 1%; white-space: nowrap; }
.row-link { color: inherit; text-decoration: none; }
.row-link:hover, .row-link:hover strong { color: var(--link); text-decoration: underline; text-underline-offset: 3px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: .84rem; letter-spacing: 0; color: var(--ink-2); }
.unit-row { display: flex; align-items: center; gap: 16px; }
.unit-chip { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 28px; padding: 0 8px; border-radius: 6px; background: var(--brand-soft); border: 1px solid var(--brand-line); color: var(--brand); font-size: .8rem; font-weight: 650; flex-shrink: 0; }
td.emails div { max-width: 210px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.7; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
/* Compact tables for long lists (e.g. payments) */
table.dense td { padding-top: 12px; padding-bottom: 12px; }
td .part { white-space: nowrap; line-height: 1.6; }
td .part a { text-decoration: none; }
/* Payments list: long cells wrap only when space runs out, so the table fits its card */
table.paylist td.primary { min-width: 0; }
table.paylist td.primary strong { white-space: normal; }
table.paylist td .part { white-space: normal; }
table.paylist td.c-ref .mono { word-break: break-all; }
td .part a:hover { text-decoration: underline; }
/* Yearly billing report grid */
.report-key { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; margin: 0 0 14px; font-size: .86rem; color: var(--ink-2); }
.report-key span { display: inline-flex; align-items: center; gap: 7px; }
.rk { display: inline-block; width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--line-strong); background: #fff; }
.rk-paid { background: #dcfce7; border-color: #86efac; }
.rk-part { background: #fef3c7; border-color: #fcd34d; }
.rk-tick { color: var(--brand); font-weight: 800; margin-right: 3px; }
table.report-grid { font-size: .78rem; }
table.report-grid th, table.report-grid td { padding: 9px 2px; }
table.report-grid th { text-align: right; font-size: .66rem; letter-spacing: .04em; padding-right: 6px; }
table.report-grid th:first-child, table.report-grid td:first-child { padding-left: 16px; }
table.report-grid th:last-child, table.report-grid td:last-child { padding-right: 16px; }
table.report-grid .rg-tenant { position: sticky; left: 0; z-index: 1; background: var(--card); width: 1%; text-align: left; box-shadow: 1px 0 0 var(--line); padding-right: 10px; }
table.report-grid thead .rg-tenant, table.report-grid tfoot .rg-tenant { background: var(--card-2); }
table.report-grid .rg-tenant strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 118px; font-size: .84rem; }
table.report-grid .rg-tenant .unit-row { gap: 8px; }
table.report-grid .rg-tenant .unit-chip { min-width: 34px; height: 22px; padding: 0 5px; font-size: .68rem; }
table.report-grid .rg-total { background: var(--card-2); padding-left: 8px; }
table.report-grid tfoot td { font-size: .76rem; }
.rc { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rc a { position: relative; display: block; margin: -5px 0; padding: 5px 5px 5px 13px; border-radius: 6px; color: var(--ink-2); text-decoration: none; }
.rc a .rk-tick { position: absolute; left: 3px; top: 50%; transform: translateY(-50%); margin: 0; font-size: .7rem; }
.rc a:hover { box-shadow: inset 0 0 0 1px var(--brand-line); color: var(--ink); }
.rc-paid a { background: #dcfce7; color: #166534; }
.rc-part a { background: #fef3c7; color: #92400e; }
.rc-none { color: #cbd5e1; text-align: center; }
.rc-covered { color: #a8b3c2; font-size: .68rem; font-style: italic; text-align: center; }
tbody tr:hover td.rg-tenant { background: #fafbfd; }

/* Withholding tax: in the payment pop-up and the statement */
.pay-wht { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; margin: -2px 0 2px; padding: 9px 12px; border-radius: 8px; background: #f5f8fc; border: 1px dashed var(--brand-line); font-size: .86rem; color: var(--ink-2); }
.pay-wht .check { font-weight: 500; gap: 8px; }
.pay-wht .check input { width: 16px; height: 16px; }
.pay-wht .wht-note { color: var(--faint); font-size: .8rem; }
.pay-withheld { display: block; font-weight: 500; font-size: .8rem; color: var(--muted); }
table.statement tr.st-open td { background: var(--card-2); }
table.statement tr.st-wht td { color: var(--muted); }
/* LPO items */
.lpo-lines { padding: 8px 28px 4px; }
.lpo-line { display: grid; grid-template-columns: minmax(0, 1fr) 90px 140px 150px 120px 40px; gap: 10px; align-items: center; padding: 6px 0; }
.lpo-head { font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding-bottom: 2px; }
.lpo-head .num, .lpo-amount { text-align: right; }
.lpo-line input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.lpo-amount { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.lpo-foot { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.lpo-totals { display: grid; grid-template-columns: auto 140px; gap: 6px 18px; margin: 0; font-variant-numeric: tabular-nums; }
.lpo-totals dt { color: var(--muted); text-align: right; }
.lpo-totals dd { margin: 0; text-align: right; color: var(--ink); }
.lpo-totals dt:last-of-type, .lpo-totals dd:last-of-type { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
@media (max-width: 900px) {
  .lpo-lines { padding: 8px 18px 4px; }
  .lpo-head { display: none; }
  .lpo-line { grid-template-columns: 1fr 1fr; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .lpo-line > input:first-child { grid-column: 1 / -1; }
  .lpo-amount { text-align: left; }
}

/* Letter previews (pop-ups): formatted like the email */
.letter-preview { white-space: normal; line-height: 1.6; }
.letter-preview ul { margin: 0; padding-left: 22px; }

/* Two-step sign-in code page */
.code-input { font-size: 1.6rem; letter-spacing: .4em; text-align: center; font-variant-numeric: tabular-nums; }
.code-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }

/* Cleaning materials */
.cleaning-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin-bottom: 20px; }
.cleaning-tile { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 2px; }
.cleaning-tile:hover { box-shadow: var(--shadow); }
.cleaning-tile .pill { align-self: flex-start; margin-top: 8px; }
.cleaning-unit { font-size: .95rem; font-weight: 500; color: var(--muted); }
.cleaning-usage-form { grid-template-columns: repeat(auto-fit, minmax(180px, 220px)); align-items: end; }
.cleaning-cols { align-items: start; }
.cleaning-counts { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.order-lines { margin: 8px 0 4px; }
.order-line { display: grid; grid-template-columns: minmax(0, 1.4fr) 120px 180px 130px 40px; gap: 10px; align-items: center; padding: 6px 0; }
.order-head { font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.order-line input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
.order-amount { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.order-head .num { text-align: right; }
.order-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.order-total { font-size: 1.05rem; color: var(--muted); }
.order-total strong { color: var(--ink); margin-left: 10px; font-variant-numeric: tabular-nums; }
.cancel-order summary { list-style: none; }
.cancel-order summary::-webkit-details-marker { display: none; }
.cancel-order form { display: flex; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.cancel-order input { width: 150px; min-height: 34px; padding: 4px 8px; }
@media (max-width: 900px) {
  .order-head { display: none; }
  .order-line { grid-template-columns: 1fr 1fr; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .order-line > select { grid-column: 1 / -1; }
}

/* Cheques */
.cheques-table td { vertical-align: middle; }
.cheques-table tr.is-voided td { text-decoration: line-through; }
.cheques-table tr.is-voided td a, .cheques-table tr.is-voided td .pill { text-decoration: none; }
.cheque-inline { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cheque-inline input[type=date] { width: auto; min-height: 36px; padding: 4px 8px; }
.cheque-inline input[name=collected_by] { width: 150px; min-height: 36px; padding: 4px 10px; }
.inline-undo { display: inline; margin-left: 8px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--link); font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.cheque-invoices { margin-top: 4px; }
.cheque-invoice-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 16px; }
.cheque-invoice { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.cheque-invoice .num { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
@media (max-width: 900px) {
  .cheque-inline { justify-content: flex-end; }
  .cheque-inline input[name=collected_by] { width: 100%; }
}

/* Purchases (grouped by supplier, like the purchases record) */
.purchases-table tr.supplier-row td { background: var(--bg, #f6f8fa); padding-top: 10px; padding-bottom: 10px; }
.purchases-table tr.is-voided td { text-decoration: line-through; }
.purchases-table tr.is-voided td .btn, .purchases-table tr.is-voided td a { text-decoration: none; }
.purchases-table .cu-no { font-variant-numeric: tabular-nums; font-size: .86rem; }
.purchases-table th { white-space: normal; vertical-align: bottom; }
.purchases-table tr.supplier-row .pin { display: inline-block; min-width: 118px; margin-right: 14px; font-variant-numeric: tabular-nums; }
.purchases-table td.purchase-what { padding-left: 20px; max-width: 200px; }
.purchases-table td.purchase-what .sub { margin-top: 0; }
.purchases-table .purchase-edit { display: inline-block; margin-top: 4px; font-size: .82rem; font-weight: 600; }
@media (max-width: 900px) {
  .purchases-table tr.supplier-row { padding: 12px 18px; background: var(--bg, #f6f8fa); }
  .purchases-table tr.supplier-row td { padding: 0 !important; background: none; }
  .purchases-table td.purchase-what { padding-left: 0; max-width: none; }
}

/* Meter reading records */
.records-table td { white-space: nowrap; }
.records-table th { white-space: normal; vertical-align: bottom; }
.records-table td .sub { white-space: normal; }
.records-table td.primary { white-space: normal; min-width: 170px; }
.records-table td.records-pay .sub { white-space: normal; max-width: 170px; margin-left: auto; }
.records-table td.primary strong { white-space: normal; }
.records-table .sub .pill { margin-top: 2px; }
.records-table tfoot .sub { font-weight: 500; }

/* Backups */
.restore-help summary { cursor: pointer; }
.restore-help ol { margin: 12px 0 0; padding-left: 20px; line-height: 1.7; color: var(--muted); }
.restore-help code { font-size: .85em; background: var(--line); padding: 1px 5px; border-radius: 4px; }

/* Email outbox */
.outbox-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; margin-bottom: 20px; }
.outbox-table td { white-space: normal; }
.outbox-table td.nowrap { white-space: nowrap; }
.outbox-table td.primary { min-width: 220px; }
.outbox-table td.primary strong { white-space: normal; }
.outbox-table .outbox-to { max-width: 210px; }
.outbox-table .outbox-to .addr { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.outbox-table .outbox-to .addr + .addr { color: var(--muted); }
.outbox-pages { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.mail-head { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 20px; margin: 0; padding: 22px 28px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.mail-head dt { color: var(--faint); font-weight: 550; }
.mail-head dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }
.mail-files { display: flex; flex-wrap: wrap; gap: 8px; }
.mail-file { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg, #f6f8fa); font-size: .84rem; }
.mail-file svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; color: var(--muted); }
.mail-body { padding: 26px 28px 30px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .95rem; line-height: 1.7; color: var(--ink); max-width: 78ch; }
.mail-frame { display: block; width: 100%; height: 520px; border: 0; background: #fff; }
.mail-plain { border-top: 1px solid var(--line); padding: 14px 28px; }
.mail-plain summary { cursor: pointer; font-size: .86rem; color: var(--muted); font-weight: 550; }
.mail-plain .mail-body { padding: 14px 0 6px; }
.mail-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.mail-foot .muted { margin-left: auto; }
@media (max-width: 900px) {
  .mail-head { padding: 18px; grid-template-columns: 1fr; gap: 2px; }
  .mail-head dd { margin-bottom: 10px; }
  .mail-body { padding: 18px; }
  .outbox-bar .toolbar, .outbox-bar input[type=search] { width: 100% !important; }
  .outbox-table .outbox-to { max-width: none; }
  .outbox-table .outbox-to .cv { min-width: 0; text-align: right; }
}

/* Letterhead preview (Settings) */
.letterhead-field { margin-top: 4px; }
.letterhead-preview { display: block; width: 100%; max-width: 720px; height: auto; margin: 4px 0 12px; padding: 12px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }

/* Load existing data */
.import-steps { margin-bottom: 20px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.import-steps .step { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.import-steps .step p { margin: 0 0 12px; }
.import-sheets { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: .84rem; }
.import-sheets strong { display: block; color: var(--ink); font-weight: 600; }
.import-sheets span { color: var(--muted); line-height: 1.45; }
.import-upload { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; width: 100%; }
.import-upload input[type=file] { flex: 1 1 220px; min-width: 0; }
.import-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px 32px; }
.import-facts .k { font-size: .8rem; color: var(--faint); font-weight: 550; }
.import-facts .v { font-size: 1.25rem; font-weight: 650; color: var(--ink); margin-top: 4px; }
.import-facts p { margin: 8px 0 0; }
.import-stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 20px; }
.import-stats a.stat { text-decoration: none; color: inherit; }
.import-stats a.stat:hover { box-shadow: var(--shadow); }
.import-problem { padding: 16px 28px 0; }
.import-table .import-rowno { width: 64px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }
.import-table tr.is-error td { background: var(--bad-soft); }
.import-table .bad-text { color: var(--bad); font-weight: 500; }
.import-table .warn-text { color: var(--warn); font-weight: 500; }
.import-table td .pill + .sub { margin-left: 0; }
.import-table td.primary { min-width: 0; width: 1%; white-space: nowrap; }
.import-table td.nowrap { white-space: nowrap; }
.import-table td.nowrap .sub { white-space: normal; }
.import-table td.num { white-space: normal; }
.import-table td.num strong, .import-table td.num { font-variant-numeric: tabular-nums; }
.import-table td.num .sub { white-space: normal; max-width: 240px; margin-left: auto; }
.import-table .import-status { white-space: nowrap; }
.import-table tr.is-error:has(+ tr.import-msgs) td { border-bottom: 0; }
.import-table tr.import-msgs td { padding-top: 0; }
.import-table tr.import-msgs ul { margin: 0; padding: 10px 14px 10px 30px; border-radius: 8px; background: var(--card); border: 1px solid var(--bad-line); color: var(--bad); font-size: .86rem; font-weight: 500; line-height: 1.55; }
.import-table tr.import-msgs:not(.is-error) ul { border-color: var(--brand-line); color: var(--brand); }
.import-table .cv { display: block; min-width: 0; }
@media (max-width: 900px) {
  .import-table tr.import-msgs td.import-rowno { display: none; }
  .import-table td .cv { text-align: right; }
  .import-table tr.is-error { background: var(--bad-soft); }
  .import-table tr.is-error td { background: transparent; }
  .import-table tr.import-msgs td { display: block; text-align: left; }
  .import-table tr:has(+ tr.import-msgs) { border-bottom: 0; padding-bottom: 6px; }
  .import-table .import-rowno { width: 100%; }
  .import-table td.primary .cv { text-align: left; }
  .import-table td.num .sub { max-width: none; }
  .import-table tr.import-msgs { padding-top: 0; }
  .import-table td.nowrap { white-space: normal; }
}
.import-bar { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px;
  margin: 8px 0 0; padding: 14px 20px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -4px 18px rgba(15, 23, 42, .08); }
.import-bar .import-upload { width: auto; }

/* Profit page */
.period-card { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 16px 20px; }
.period-card .period-range { margin-left: auto; }
.profit-tile.is-profit { box-shadow: inset 3px 0 0 #10b981, var(--shadow-sm); }
.profit-tile.is-profit .v { color: #047857; }
.profit-tile.is-loss { box-shadow: inset 3px 0 0 #ef4444, var(--shadow-sm); }
.profit-tile.is-loss .v { color: #b91c1c; }
td.neg, td.neg strong { color: #b91c1c; }
table.wrap-names td.primary { min-width: 0; }
table.wrap-names td.primary strong { white-space: normal; }
@media (max-width: 900px) { .period-card .period-range { margin-left: 0; } }

/* Hover cards ([data-tip] with a hidden .tip-src inside) */
.tip {
  position: fixed; z-index: 1100; max-width: 300px; padding: 12px 14px; border-radius: 10px; pointer-events: none;
  background: #0f1d33; color: #e2e8f0; font-size: .82rem; line-height: 1.45; box-shadow: 0 12px 32px rgba(15, 23, 42, .28);
  animation: dd-in .1s var(--ease);
}
.tip::after { content: ""; position: absolute; left: var(--tip-x, 50%); width: 10px; height: 10px; background: #0f1d33; transform: translateX(-50%) rotate(45deg); }
.tip.below::after { top: -5px; }
.tip:not(.below)::after { bottom: -5px; }
.tip > span { display: block; }
.tip .tip-title { font-weight: 650; color: #fff; font-size: .88rem; }
.tip .tip-sub { color: #94a3b8; font-size: .78rem; margin-top: 1px; }
.tip .tip-amount { font-size: 1.05rem; font-weight: 700; color: #fff; margin: 8px 0 6px; font-variant-numeric: tabular-nums; }
.tip .tip-row { display: flex; align-items: baseline; gap: 8px; margin-top: 3px; }
.tip .tip-dot { width: 7px; height: 7px; border-radius: 50%; background: #64748b; flex-shrink: 0; transform: translateY(-1px); }
.tip .tip-dot.ok { background: #34d399; }
.tip .tip-dot.warn { background: #fbbf24; }
.tip .tip-dot.bad { background: #f87171; }
.tip .tip-foot { margin-top: 9px; padding-top: 8px; border-top: 1px solid rgba(148, 163, 184, .25); color: #94a3b8; font-size: .74rem; }

/* Number inputs inside table rows */
td.input-cell input, .cell-input { display: block; width: 100%; max-width: 168px; margin-left: auto; min-height: 38px; text-align: right; font-variant-numeric: tabular-nums; }
td.input-cell input::placeholder { text-align: right; }
.sub { display: block; color: var(--faint); font-size: .8rem; font-weight: 400; margin-top: 5px; line-height: 1.45; }
.card.flush > table, .card.flush > .table-wrap { margin: 0; }

/* ================= Status pills ================= */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600;
  line-height: 1.5; white-space: nowrap; background: #f1f5f9; color: var(--muted); border: 1px solid #e2e8f0;
}
.pill.ok, .pill.Paid, .pill.warn, .pill.Part-paid, .pill.flagged, .pill.bad, .pill.Unpaid, .pill.info { border-width: 1px; }
.pill.ok::before, .pill.Paid::before, .pill.warn::before, .pill.Part-paid::before, .pill.flagged::before, .pill.bad::before, .pill.Unpaid::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.pill.ok, .pill.Paid { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.pill.warn, .pill.Part-paid, .pill.flagged { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.pill.bad, .pill.Unpaid { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.pill.info { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-line); }
.pill.Replaced, .pill.Cancelled { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }
/* Inside tables a status reads as a coloured dot + plain text: calmer than filled badges in long lists */
td .pill { background: none !important; border-color: transparent !important; text-decoration: none; padding: 0; gap: 8px; font-size: .86rem; font-weight: 550; color: var(--muted); }
td .pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; }
td .pill.ok, td .pill.Paid { color: #047857; }
td .pill.ok::before, td .pill.Paid::before { background: #10b981; }
td .pill.warn, td .pill.Part-paid, td .pill.flagged { color: #b45309; }
td .pill.warn::before, td .pill.Part-paid::before, td .pill.flagged::before { background: #f59e0b; }
td .pill.bad, td .pill.Unpaid { color: #b91c1c; }
td .pill.bad::before, td .pill.Unpaid::before { background: #ef4444; }
td .pill.info { color: var(--brand); }
td .pill.info::before { background: #3b82f6; }
td .pill.Replaced, td .pill.Cancelled { color: #94a3b8; text-decoration: line-through; }
td .pill + .sub { margin-left: 16px; }
td.primary .pill + .sub { margin-left: 0; }
/* Labels (not statuses): small neutral chip */
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; background: #f1f5f9; border: 1px solid var(--line); color: var(--ink-2); font-size: .75rem; font-weight: 600; line-height: 1.5; white-space: nowrap; vertical-align: 1px; }
.yes { color: var(--ok); font-weight: 700; }
.no { color: #cbd5e1; }

/* ================= Forms ================= */
label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
input, select, textarea {
  width: 100%; font: inherit; font-size: .94rem; padding: 9px 12px; min-height: 42px; color: var(--ink);
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder, textarea::placeholder { color: #94a3b8; text-transform: none; }
input:hover, select:hover, textarea:hover { border-color: #94a3b8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 3px var(--ring); }
select { appearance: none; padding-right: 36px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right 12px center / 16px no-repeat; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; padding: 0; accent-color: var(--brand); cursor: pointer; }
input[type=file] { padding: 7px; cursor: pointer; background: var(--card-2); }
input[type=file]::file-selector-button { font: inherit; font-size: .84rem; font-weight: 600; margin-right: 12px; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink-2); cursor: pointer; }
input[disabled], select[disabled], textarea[disabled] { background: #f1f5f9; color: var(--faint); cursor: not-allowed; }
textarea { min-height: 88px; resize: vertical; }
input.calc, .readonly-value { background: var(--card-2); color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.readonly-value { padding: 10px 12px; border-radius: var(--radius-sm); min-height: 42px; font-weight: 500; border: 1px solid var(--line); }
.field { margin-bottom: 16px; min-width: 0; }
.field-end { align-self: end; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 18px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 6px; }
.hint { font-size: .8rem; color: var(--faint); margin-top: 6px; line-height: 1.45; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 0; cursor: pointer; color: var(--ink-2); }

/* Styled dropdowns (desktop): the native select stays underneath for keyboard, forms and validation */
.dd { position: relative; display: block; width: 100%; }
.dd.dd-auto { display: inline-block; width: auto; vertical-align: middle; }
.dd > select.dd-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; }
.dd-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px; padding: 8px 38px 8px 12px; margin: 0;
  font: inherit; font-size: .94rem; line-height: 1.3; text-align: left; color: var(--ink); cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right 12px center / 16px no-repeat;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.dd-btn:hover { border-color: #94a3b8; }
.dd:focus-within .dd-btn, .dd.open .dd-btn { border-color: #3b82f6; box-shadow: 0 0 0 3px var(--ring); outline: none; }
.dd.open .dd-btn { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231d4ed8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 15 6-6 6 6'/%3E%3C/svg%3E"); }
.dd.invalid .dd-btn { border-color: var(--bad); }
.dd-btn .dd-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-btn.is-placeholder .dd-title { color: #94a3b8; }
.dd-btn[disabled] { background-color: #f1f5f9; color: var(--faint); cursor: not-allowed; }
.dd-right { margin-left: auto; color: var(--muted); font-size: .85rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dd-chip { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; height: 22px; padding: 0 6px; border-radius: 5px; background: var(--brand-soft); border: 1px solid var(--brand-line); color: var(--brand); font-size: .72rem; font-weight: 650; flex-shrink: 0; }
.dd-badge { font-size: .7rem; font-weight: 650; color: #b91c1c; background: var(--bad-soft); border: 1px solid var(--bad-line); border-radius: 999px; padding: 1px 8px; white-space: nowrap; flex-shrink: 0; }
.dd-pop {
  position: fixed; z-index: 1000; display: flex; flex-direction: column; padding: 6px; background: #fff;
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(15, 23, 42, .18), 0 2px 6px rgba(15, 23, 42, .06);
  animation: dd-in .12s var(--ease);
}
@keyframes dd-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dd-search { min-height: 38px; margin: 2px 2px 6px; font-size: .9rem; }
.dd-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; }
.dd-opt { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--ink-2); font-size: .92rem; }
.dd-opt .dd-main { flex: 1; min-width: 0; }
.dd-opt .dd-title { display: block; font-weight: 550; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-opt .dd-sub { display: block; margin-top: 1px; font-size: .8rem; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dd-opt.active { background: var(--card-2); }
.dd-opt[aria-selected="true"] { background: var(--brand-soft); }
.dd-opt[aria-selected="true"] .dd-title { color: var(--brand); }
.dd-opt[aria-selected="true"]::after { content: ""; width: 16px; height: 16px; flex-shrink: 0; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231e3a5f' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 12 5 5 9-10'/%3E%3C/svg%3E") center / 16px no-repeat; }
.dd-opt[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }
.dd-opt[aria-disabled="true"] .dd-sub::after { content: " · already chosen"; }
.dd-empty { padding: 12px 10px; color: var(--muted); font-size: .9rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  font: inherit; font-size: .9rem; font-weight: 600; line-height: 1; white-space: nowrap; text-decoration: none; cursor: pointer;
  color: #fff; background: var(--brand); border: 1px solid var(--brand); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
  transition: background .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), transform .08s var(--ease);
}
.btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn:active { background: var(--brand-press); transform: translateY(1px); }
.btn.secondary { background: #fff; color: var(--ink-2); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--card-2); border-color: #94a3b8; color: var(--ink); }
.btn.danger { background: #fff; color: var(--bad); border-color: var(--bad-line); }
.btn.danger:hover { background: var(--bad-soft); border-color: #f87171; }
.btn.wa { background: var(--wa); border-color: var(--wa); }
.btn.wa:hover { background: var(--wa-hover); border-color: var(--wa-hover); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .84rem; }
/* One button per row, same width down the column */
.row-btn { min-width: 132px; min-height: 38px; }
.btn.secondary.act { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-line); }
.btn.secondary.act:hover { background: #dce6f2; border-color: #9fb3cc; color: var(--brand); }
.btn svg { width: 17px; height: 17px; }
.btn[disabled], .btn.is-disabled { opacity: .45; cursor: not-allowed; pointer-events: none; box-shadow: none; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form .field { margin: 0; }

/* Disclosure */
details summary { cursor: pointer; color: var(--link); font-weight: 600; font-size: .88rem; }
details summary:hover { color: #1e40af; }
details.card > summary { color: var(--ink-2); list-style: none; display: flex; align-items: center; gap: 8px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: ""; width: 16px; height: 16px; transition: transform .15s var(--ease);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 6 6 6-6 6'/%3E%3C/svg%3E") center / 16px no-repeat; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.manage { display: inline-block; text-align: left; position: relative; }
details.manage > summary {
  list-style: none; display: inline-flex; align-items: center; min-height: 34px; padding: 0 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); color: var(--ink-2); background: #fff; font-size: .84rem; font-weight: 600; transition: background .15s var(--ease);
}
details.manage > summary:hover { background: var(--card-2); border-color: #94a3b8; color: var(--ink); }
details.manage > summary::-webkit-details-marker { display: none; }
details.manage[open] > summary { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand); }
details.manage > summary::after { content: ""; width: 14px; height: 14px; margin-left: 6px; margin-right: -2px; transition: transform .15s var(--ease);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") center / 14px no-repeat; }
details.manage[open] > summary::after { transform: rotate(180deg); }
.manage-panel { margin-top: 10px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); box-shadow: var(--shadow-lg); min-width: 300px; text-align: left; white-space: normal; font-size: .9rem; }
.manage-panel form + form, .manage-panel .mp-section + .mp-section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.manage-panel .field { margin-bottom: 12px; }
.manage-panel .form-grid { grid-template-columns: 1fr 1fr; gap: 0 12px; }
.manage-panel .form-grid.one-col { grid-template-columns: 1fr; }
.manage-panel .inline-form .field { flex: 1 1 0; }
.manage-panel .inline-form .btn { min-height: 42px; }
.mp-title { font-size: .95rem; font-weight: 650; color: var(--ink); margin: -2px 0 12px; }
.mp-label { font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin-bottom: 8px; }
/* Desktop: the panel floats over the table like a drop-down instead of stretching the row */
@media (min-width: 901px) {
  details.manage > .manage-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 25; width: 420px; margin: 0; animation: mp-in .14s var(--ease); }
  td:not(.right) > details.manage > .manage-panel { right: auto; left: 0; }
  @keyframes mp-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
}

/* ================= Messages ================= */
.flash { position: relative; display: block; padding: 12px 16px 12px 44px; border-radius: 10px; margin-bottom: 16px; font-size: .92rem; line-height: 1.5; border: 1px solid; }
.flash a { color: inherit; font-weight: 600; }
.flash::before { content: ""; position: absolute; left: 16px; top: 14px; width: 18px; height: 18px; background: currentColor;
  -webkit-mask: var(--flash-icon) center / contain no-repeat; mask: var(--flash-icon) center / contain no-repeat; }
.flash.ok { background: var(--ok-soft); color: #065f46; border-color: var(--ok-line);
  --flash-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='m8 12 3 3 5-6'/%3E%3C/svg%3E"); }
.flash.error { background: var(--bad-soft); color: #991b1b; border-color: var(--bad-line);
  --flash-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 7v6M12 16.5v.5'/%3E%3C/svg%3E"); }
.flash.info { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-line);
  --flash-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M12 11v6M12 7.5v.5'/%3E%3C/svg%3E"); }
.flash.small { font-size: .86rem; }

/* ================= Bill workflow steps ================= */
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.step { position: relative; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: var(--card); }
.step.done { border-color: var(--ok-line); background: linear-gradient(180deg, #f3fdf8, #fff 70%); }
.step .n, .n { font-size: .7rem; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
.step.done .n { color: var(--ok); }
.step.done .n::after { content: " · Done"; }
.step h4 { margin: 4px 0 10px; font-size: .98rem; }

/* ================= Duty lists ================= */
.roster { list-style: none; margin: 0; padding: 0; }
.roster li { display: flex; align-items: center; gap: 14px; padding: 12px 24px; border-bottom: 1px solid var(--line); transition: background .12s var(--ease); }
.roster li:hover { background: #fafbfd; }
.roster li:last-child { border-bottom: 0; }
.roster label.person { display: flex; align-items: center; gap: 14px; flex: 1; margin: 0; cursor: pointer; font-weight: 500; min-height: 40px; }
.roster .pname { font-weight: 600; color: var(--ink); }
.bigcheck { width: 22px !important; height: 22px !important; }
.roster .group-head { background: var(--card-2); font-size: .72rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); padding: 10px 24px; }
.roster .group-head:hover { background: var(--card-2); }
.wa-list { display: flex; flex-wrap: wrap; gap: 10px; }
.msg-preview { white-space: pre-wrap; font: .86rem/1.55 var(--font); background: #f3f8f5; border: 1px solid #d6eadf; border-radius: 10px; padding: 14px 16px; margin: 12px 0 0; max-width: 540px; color: var(--ink-2); }

/* Labour day chips */
/* Jump links land below the sticky header */
[id] { scroll-margin-top: 132px; }
/* Pop-up dialog (e.g. send the bowser notice) */
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; max-height: 320px; overflow: auto; }
.plain-list li { display: flex; align-items: center; gap: 14px; }
dialog.modal { width: min(600px, calc(100% - 32px)); max-height: calc(100% - 48px); padding: 0; border: 0; border-radius: 14px; background: var(--card); color: var(--ink-2); box-shadow: 0 24px 64px rgba(15, 23, 42, .28); overflow: auto; }
dialog.modal::backdrop { background: rgba(15, 23, 42, .5); }
dialog.modal[open] { animation: modal-in .16s var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
dialog.modal.wide { width: min(980px, calc(100% - 32px)); }
dialog.modal { overflow-x: hidden; }
/* Pop-ups sit in the centre of the screen, both across and down */
dialog.modal { position: fixed; inset: 0; margin: auto; height: fit-content; }
.pay-details { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* Record a payment: one row per bill (dropdown + amount) */
.pay-lines-head { display: grid; grid-template-columns: minmax(0, 1fr) 170px 40px; gap: 10px; font-size: .72rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 6px 0 6px; }
.pay-lines { display: grid; gap: 10px; margin-bottom: 12px; }
.pay-line { display: grid; grid-template-columns: minmax(0, 1fr) 170px 40px; gap: 10px; align-items: center; }
.pay-line input { text-align: right; font-variant-numeric: tabular-nums; }
.icon-btn { width: 40px; min-height: 42px; padding: 0; font-size: 1.2rem; }
.pay-total { font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
@media (max-width: 900px) {
  .pay-lines-head { display: none; }
  .pay-details { grid-template-columns: 1fr 1fr; gap: 0 10px; }
  .pay-line { grid-template-columns: minmax(0, 1fr) 44px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
  .pay-line select { grid-column: 1 / -1; }
  .icon-btn { width: 44px; min-height: 44px; }
}
.modal-body table { margin: 4px 0 8px; border: 1px solid var(--line); border-radius: 10px; border-collapse: separate; border-spacing: 0; overflow: hidden; }
.modal-body table th:first-child, .modal-body table td:first-child { padding-left: 16px; }
.modal-body td.input-cell input { max-width: 180px; }
.modal-body table th:last-child, .modal-body table td:last-child { padding-right: 16px; }
.modal-head { padding: 24px 28px 4px; }
.modal-head h2 { margin: 0 0 6px; font-size: 1.15rem; }
.modal-head p { margin: 0; }
.modal-body { padding: 18px 28px 6px; }
.modal-body .msg-preview { max-width: none; }
.modal-foot { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 10px; padding: 18px 28px 22px; background: var(--card); }
@media (max-width: 900px) {
  .modal-head, .modal-body { padding-left: 18px; padding-right: 18px; }
  .modal-foot { padding: 16px 18px 18px; }
  .modal-foot .btn { flex: 1; min-height: 46px; }
}
/* Short pop-up messages (after saving a single row) */
.toasts { position: fixed; top: 128px; right: 24px; z-index: 60; width: min(400px, calc(100% - 32px)); display: grid; gap: 8px; pointer-events: none; }
@media (max-width: 900px) { .toasts { top: 112px; right: 16px; } }
.toasts .flash { margin: 0; box-shadow: var(--shadow-lg); animation: mp-in .16s var(--ease); }
/* Segmented filter (floors) */
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; margin-bottom: 20px; background: #e8edf4; border-radius: 10px; }
.seg a { display: inline-flex; align-items: center; min-height: 36px; padding: 0 16px; border-radius: 7px; font-size: .88rem; font-weight: 600; color: var(--muted); text-decoration: none; white-space: nowrap; transition: background .15s var(--ease), color .15s var(--ease); }
.seg a:hover { color: var(--ink); background: rgba(255,255,255,.55); }
.seg-x { white-space: pre; }
.seg a[aria-current] { background: #fff; color: var(--brand); box-shadow: var(--shadow-sm); }
.chips { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.chips a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border: 1px solid var(--line); border-radius: 10px;
  text-decoration: none; color: var(--ink-2); font-size: .86rem; background: #fff; transition: border-color .15s var(--ease), background .15s var(--ease);
}
.chips a:hover { border-color: var(--brand-line); background: var(--card-2); color: var(--ink); }
.chips a span { font-size: .72rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.chips a.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.line-input { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); margin: 0; font-weight: 500; }
.line-input:last-child { border-bottom: 0; }
.line-input input[type=number] { width: 112px; text-align: right; }
.check-line { cursor: pointer; }

/* ================= Login ================= */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #24467a 0%, transparent 60%), linear-gradient(160deg, #0e1c30, #1e3a5f); }
.login { width: 100%; max-width: 400px; background: #fff; border-radius: 16px; padding: 34px 30px 30px; box-shadow: 0 24px 60px rgba(2, 6, 23, .35); }
.login .brand { color: var(--ink); padding: 0 0 24px; }
.login .btn { min-height: 44px; }

/* ================= Phone ================= */
.show-sm { display: none; }
@media (max-width: 900px) {
  body { font-size: 15px; }
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 30; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform .22s var(--ease); box-shadow: var(--shadow-lg); }
  body.nav-open .side { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 20; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 14px; min-height: 56px; }
  .topbar-title { flex: 1; font-size: 1rem; }
  .who { gap: 8px; }
  .who .who-name { display: none; }
  .mode-chip { padding: 3px 8px; font-size: .7rem; }
  .subnav { padding: 0 8px; top: 56px; }
  .subnav a { padding: 13px 10px 12px; }
  .content { padding: 20px 14px 80px; }
  h1 { font-size: 1.32rem; }
  .page-head { margin-bottom: 18px; }
  .card { padding: 22px 18px; border-radius: 12px; }
  .card.flush > h2, .card.flush .card-head { padding-left: 18px; padding-right: 18px; }
  .card-foot { padding: 16px 18px; }
  th:first-child, td:first-child { padding-left: 18px; }
  th:last-child, td:last-child { padding-right: 18px; }
  .roster li, .roster .group-head { padding-left: 16px; padding-right: 16px; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline; }
  input, select, textarea { font-size: 16px; min-height: 44px; } /* no zoom on iPhone */
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; }
  .stat .v { font-size: 1.4rem; }
  .grid.k2 { grid-template-columns: 1fr; }
  /* Tables marked .stack become one card per row */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 20px 18px; border-bottom: 1px solid var(--line); }
  table.stack tbody tr:last-child { border-bottom: 0; }
  table.stack tbody tr:hover td { background: transparent; }
  table.stack td { border: 0; padding: 7px 0 !important; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--faint); font-size: .82rem; text-align: left; flex-shrink: 0; }
  table.stack td[data-label=""]::before, table.stack td:not([data-label])::before { content: none; }
  table.stack td.primary { display: block; text-align: left; font-size: 1rem; padding-bottom: 12px !important; }
  table.stack td.primary::before { content: none; }
  table.stack td.right, table.stack td:last-child:not([data-label]) { justify-content: flex-start; padding-top: 14px !important; }
  table.stack td.right:last-child { width: 100%; }
  table.stack td:empty { display: none; }
  /* Summary tiles side by side on phone instead of one per screen */
  .grid.stats-compact { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 10px; }
  .stats-compact .stat { padding: 14px 16px; }
  .stats-compact .stat .v { font-size: 1.15rem; margin-top: 4px; }
  .stats-compact .stat .s { margin-top: 2px; font-size: .78rem; }
  /* Payments list on phone: compact card (tenant + amount / date + reference / what it paid) */
  table.paylist tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 14px 18px; }
  table.paylist td { padding: 0 !important; display: block; text-align: left; width: auto; }
  table.paylist td::before { content: none !important; }
  table.paylist td.c-tenant { grid-column: 1; grid-row: 1; font-size: .95rem; }
  table.paylist td.c-amount { grid-column: 2; grid-row: 1; text-align: right; align-self: center; }
  table.paylist td.c-date { grid-column: 1 / -1; grid-row: 2; color: var(--muted); font-size: .85rem; }
  table.paylist td.c-parts { grid-column: 1; grid-row: 3; align-self: center; }
  table.paylist td.c-act { grid-column: 2; grid-row: 3; text-align: right; }
  table.paylist td.c-act:has(details[open]) { grid-column: 1 / -1; grid-row: 4; text-align: left; }
  table.paylist td.c-act summary { min-height: 32px; padding: 0 10px; }
  table.paylist td.c-act:empty { display: none; }
  table.paylist .unit-chip { min-width: 38px; height: 24px; font-size: .74rem; }
  table.paylist .unit-row { gap: 10px; }
  td .part { white-space: normal; }
  .modal-body table { border: 0; }
  .seg { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .seg a { flex: 1 1 0; justify-content: center; min-height: 44px; padding: 0 6px; }
  .seg-x { display: none; }
  .seg.seg-scroll a { flex: 0 0 auto; padding: 0 14px; }
  .page-head form.toolbar { width: 100%; }
  .page-head form.toolbar > select, .page-head form.toolbar > input[type=month] { flex: 1 1 140px; width: auto !important; }
  table.stack tr.group { padding: 10px 18px; background: #eef3f9; border-bottom: 1px solid var(--brand-line); }
  table.stack tr.group td { padding: 0 !important; background: none; justify-content: flex-start; text-align: left; }
  table.stack td .row-btn { flex: 1; min-height: 44px; }
  table.stack td:has(> .pill + .sub)::before { margin-right: auto; }
  table.stack td:has(> .pill + .sub) { justify-content: flex-end; gap: 8px; }
  table.stack td > .pill + .sub { margin: 0; }
  table.stack td > .pill + .sub::before { content: "· "; }
  .unit-row { gap: 10px; }
  table.stack td.input-cell:has(input) { display: block; text-align: left; padding-top: 6px !important; }
  table.stack td.input-cell:has(input)::before { display: block; margin-bottom: 6px; }
  table.stack td.input-cell input { width: 100%; max-width: none; text-align: left !important; }
  table.stack td.input-cell input::placeholder { text-align: left; }
  td.primary { min-width: 0; }
  td.primary strong { white-space: normal; }
  td .pill + .sub { margin-left: 0; }
  .row-btn { min-width: 0; }
  .manage-panel .form-grid { grid-template-columns: 1fr; }
  table.stack tfoot { display: block; }
  table.stack tfoot tr { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 14px; background: var(--card-2); }
  table.stack tfoot td { width: auto; padding: 4px 0 !important; }
  .manage-panel { min-width: 0; box-shadow: none; }
  details.manage { display: block; }
  .chips { gap: 5px; }
  .chips a { padding: 8px 2px; font-size: .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media print {
  .side, .topbar, .subnav, .testbar, .no-print, .flash, .actions, .toolbar, details.card { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; box-shadow: none; }
  body { background: #fff; }
}
