/* =============================================================================
   app.css — BLVD WORLD Rent Manager
   Light / dark via CSS custom properties on :root[data-theme].
   RTL-aware: everything is written with logical properties so switching
   direction never needs a second stylesheet.
   ========================================================================== */

/* --------------------------------------------------------------- tokens */
:root {
  --bg:          #f4f6f9;
  --bg-2:        #eaeef4;
  --surface:     #ffffff;
  --surface-2:   #f8fafc;
  --line:        #dde3ec;
  --line-soft:   #eaeef4;
  --text:        #16202e;
  --text-2:      #5b6879;
  --text-3:      #8794a6;
  --accent:      #0e5c8a;
  --accent-2:    #14809f;
  --accent-soft: #e3f0f7;
  --ok:          #1a7f4b;
  --ok-soft:     #e2f4ea;
  --warn:        #b26a00;
  --warn-soft:   #fdf0dc;
  --bad:         #c0392b;
  --bad-soft:    #fbe6e3;
  --muted-soft:  #eef1f6;
  --shadow:      0 1px 2px rgba(16, 32, 54, .06), 0 6px 18px rgba(16, 32, 54, .06);
  --shadow-lg:   0 10px 40px rgba(16, 32, 54, .18);
  --radius:      10px;
  --radius-sm:   6px;
  --mono:        "Cairo", "Segoe UI", system-ui, -apple-system, sans-serif;
  --sidebar-w:   236px;
  --head-h:      56px;
}

:root[data-theme="dark"] {
  --bg:          #10151c;
  --bg-2:        #161d26;
  --surface:     #1a222c;
  --surface-2:   #212b37;
  --line:        #2c3846;
  --line-soft:   #242e3a;
  --text:        #e7edf5;
  --text-2:      #9fb0c3;
  --text-3:      #6f8096;
  --accent:      #4db3e8;
  --accent-2:    #6fc7ee;
  --accent-soft: #16303f;
  --ok:          #4cc38a;
  --ok-soft:     #14312a;
  --warn:        #e0a44a;
  --warn-soft:   #33280f;
  --bad:         #f0776a;
  --bad-soft:    #351d1b;
  --muted-soft:  #232d39;
  --shadow:      0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  --shadow-lg:   0 12px 48px rgba(0, 0, 0, .55);
}

/* ------------------------------------------------------------- baseline */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open { overflow: hidden; }

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
p  { margin: 0 0 8px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

::selection { background: var(--accent); color: #fff; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Scrollbars that do not fight the theme */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
*::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------------- layout */
#app { min-height: 100%; }

/* The grid needs no RTL variant: CSS grid mirrors its own track order under
   `dir="rtl"`, so the first (236px) track — brand + nav — lands on the right
   in Arabic and on the left in English, from the same rules. */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--head-h) 1fr;
  grid-template-areas: "brand topbar" "nav main";
  min-height: 100vh;
}

/* brand ------------------------------------------------------------------ */
.brand {
  grid-area: brand;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  border-block-end: 1px solid var(--line);
  min-width: 0;
}
.brand-mark {
  width: 30px; height: 30px; flex: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800; font-size: 13px;
  display: grid; place-items: center;
}
.brand-text { min-width: 0; }
.brand-text b { display: block; font-size: 12.5px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { display: block; font-size: 10.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* topbar ----------------------------------------------------------------- */
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-block-end: 1px solid var(--line);
  min-width: 0;
}
.topbar .spacer { flex: 1; }
#global-search { max-width: 340px; width: 100%; }

.unsaved-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--warn-soft); color: var(--warn); border: 1px solid transparent;
}
.unsaved-badge.clean { background: var(--ok-soft); color: var(--ok); }
.unsaved-badge::before { content: "●"; font-size: 10px; }

/* nav -------------------------------------------------------------------- */
.nav {
  grid-area: nav;
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  padding: 10px 8px 24px;
  overflow-y: auto;
}
.nav-group-title {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em;
  color: var(--text-3); text-transform: uppercase;
  padding: 12px 10px 5px;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 1px;
  border-radius: var(--radius-sm);
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  text-decoration: none;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.nav a .ico { width: 20px; text-align: center; flex: none; font-size: 14px; }
.nav a .txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav a .n { margin-inline-start: auto; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav a.has-alert .ico { color: var(--bad); }
.nav a .nav-alert {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px;
  background: var(--bad); color: var(--surface);
  font-size: 10.5px; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--surface);
  animation: nav-alert-pulse 2.4s ease-in-out infinite;
}
@keyframes nav-alert-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--surface); }
  50% { box-shadow: 0 0 0 4px var(--bad-soft); }
}
@media (prefers-reduced-motion: reduce) {
  .nav a .nav-alert { animation: none; }
}

/* main ------------------------------------------------------------------- */
.main {
  grid-area: main;
  padding: 18px;
  min-width: 0;
  overflow-x: hidden;
}
#view { max-width: 1600px; margin: 0 auto; }

/* ------------------------------------------------------------------ page */
.page-head {
  display: flex; align-items: flex-start; gap: 14px;
  margin-block-end: 16px; flex-wrap: wrap;
}
.page-title { min-width: 0; }
.page-title .sub { color: var(--text-2); font-size: 13px; margin: 2px 0 0; }
.page-title .badge {
  display: inline-block; margin-block-start: 6px;
  font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  background: var(--muted-soft); color: var(--text-2);
}
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-inline-start: auto; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 14px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-2-1, .grid-1-2, .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 640px)  { .grid-3 { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------------ card */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-block-end: 14px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px;
  border-block-end: 1px solid var(--line-soft);
  background: var(--surface-2);
}
.card-head h3 { flex: 1; min-width: 0; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.card-body { padding: 14px; }
.card-body.tight { padding: 0; }

/* ------------------------------------------------------------------- kpi */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-block-end: 14px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border-inline-start: 3px solid var(--accent);
}
.kpi.ok     { border-inline-start-color: var(--ok); }
.kpi.warn   { border-inline-start-color: var(--warn); }
.kpi.bad    { border-inline-start-color: var(--bad); }
.kpi-label  { font-size: 11.5px; color: var(--text-2); font-weight: 600; }
.kpi-value  { font-size: 21px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; margin-block-start: 2px; }
.kpi-sub    { font-size: 11.5px; color: var(--text-3); }

/* ---------------------------------------------------- collection analysis */
/* The insight cards carry a pavilion name, not a money figure, so the value
   line is smaller and allowed to wrap; a long Arabic name would otherwise
   push the card out of its column. */
.collection-insights { margin-block-end: 12px; }
.collection-insights .kpi-value { font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
/* UI.kpi writes .kpi-ok / .kpi-warn / .kpi-bad on the card, so the collection
   insight cards get the same left-edge tone as the dashboard cards. */
.kpi-ok   { border-inline-start-color: var(--ok); }
.kpi-warn { border-inline-start-color: var(--warn); }
.kpi-bad  { border-inline-start-color: var(--bad); }
.collection-period-hint { margin-block-end: 10px; }
.collection-note { font-size: 11.5px; color: var(--text-3); margin-block-start: 8px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* A one-line statement of which slice of data the summary above it covers.
   Without it a pavilion total reads like a season total. */
.summary-scope {
  font-size: 12px; color: var(--text-2);
  padding: 0 2px 9px; margin-block-end: 10px;
  border-block-end: 1px dashed var(--line);
  font-variant-numeric: tabular-nums;
}

/* A KPI that doubles as a filter shortcut. The pressed state has to be
   obvious, otherwise it just reads as a card that happens to be clickable. */
.kpi-clickable { cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s; }
.kpi-clickable:hover { border-color: var(--accent); background: var(--surface-2); }
.kpi-clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kpi-clickable[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset, var(--shadow);
}
.kpi-clickable[aria-pressed="true"] .kpi-label { color: var(--accent); }

/* ------------------------------------------------------------------- bar */
.bar { height: 5px; background: var(--muted-soft); border-radius: 999px; overflow: hidden; margin-block-start: 7px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.bar-fill.bar-ok { background: var(--ok); }
.bar-fill.bar-warn { background: var(--warn); }
.bar-fill.bar-bad { background: var(--bad); }

/* ---------------------------------------------------------------- button */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn.mini { padding: 4px 9px; font-size: 12px; }
.btn .bi { font-size: 13px; }

.icon-btn {
  width: 30px; height: 30px; flex: none;
  display: inline-grid; place-items: center;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-2); cursor: pointer; font-size: 13px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--line); }

/* ------------------------------------------------------------------ form */
.input {
  padding: 7px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 100%;
  min-width: 0;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 68px; resize: vertical; line-height: 1.5; }
select.select { cursor: pointer; padding-inline-end: 26px; }
.select.mini { width: auto; padding: 3px 8px; font-size: 12px; }

/* Multi-select checkbox dropdown (native <details>). The panel stays in normal
   flow, so it pushes the chart down instead of being clipped by .card. */
.multi-select { min-width: 190px; }
.multi-select > summary {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; list-style: none;
}
.multi-select > summary::-webkit-details-marker { display: none; }
.multi-select > summary::after {
  content: "▾"; margin-inline-start: auto;
  color: var(--text-3); font-size: 10px; line-height: 1;
}
.multi-select[open] > summary {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.multi-select-panel {
  margin-block-start: 5px; padding: 4px;
  max-height: 250px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.multi-select-actions {
  display: flex; gap: 6px; padding: 2px 2px 6px;
  border-block-end: 1px solid var(--line-soft); margin-block-end: 4px;
}
.multi-select-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 7px; border-radius: 4px;
  cursor: pointer; font-size: 12.5px; color: var(--text-2);
}
.multi-select-row:hover { background: var(--surface-2); color: var(--text); }
.multi-select-row input { accent-color: var(--accent); margin: 0; }

.filters {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-block-end: 1px solid var(--line-soft);
}
.filter { display: flex; flex-direction: column; gap: 3px; min-width: 130px; }
.filter.grow { flex: 1 1 240px; }
/* min-height reserves the line even for an unlabelled control, and nowrap
   stops a narrow filter from wrapping its label to two lines. */
.flabel {
  font-size: 10.5px; font-weight: 700; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .04em;
  min-height: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.field { margin-block-end: 12px; }
.field > label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-block-end: 4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { font-size: 11.5px; color: var(--text-3); margin-block-start: 4px; }
.dash-filter-hint { margin: 0 0 12px; }
/* Inline validation message under a form field. */
.field-hint.err { color: var(--bad); font-weight: 600; min-height: 15px; }
.field-hint.err:empty { min-height: 0; margin-block-start: 0; }
.req { color: var(--bad); }

/* A read-only caption next to its control, e.g. "Season" before a dropdown. */
.static-field {
  padding: 7px 0 7px 2px;
  font-size: 13px; color: var(--text-2); font-weight: 600;
}

/* Filters that must stay on one line: flexible items shrink rather than wrap. */
.filters.one-row { flex-wrap: nowrap; overflow-x: auto; align-items: flex-start; }
.filters.one-row .filter { flex: 0 1 auto; min-width: 0; }
/* Grow the .filter box, never the control inside it — a `.filter` is a column
 * flex box, so `flex-basis` on the input would become a HEIGHT. */
.filters.one-row .filter:has(input.search) { flex: 1 1 220px; }
.filters.one-row .input { min-width: 92px; }
@media (max-width: 900px) {
  /* Below this width, six controls on one line would be unusable — wrapping
     is the better failure. */
  .filters.one-row { flex-wrap: wrap; overflow-x: visible; align-items: stretch; }
  .filters.one-row .filter { flex: 1 1 130px; }
}

/* ----------------------------------------------------------------- table */
.table-wrap { display: flex; flex-direction: column; min-width: 0; }
.table-scroll { overflow: auto; max-height: calc(100vh - 250px); }
.compact .table-scroll { max-height: calc(100vh - 300px); }

table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data th, table.data td {
  padding: 7px 10px;
  text-align: start;
  border-block-end: 1px solid var(--line-soft);
  white-space: nowrap;
  vertical-align: middle;
}
table.data th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  font-size: 11.5px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .03em;
  border-block-end: 1px solid var(--line);
  user-select: none;
}
table.data th.sortable { cursor: pointer; }
table.data th.sortable:hover { color: var(--accent); }
table.data th.sorted { color: var(--accent); }
.sort-ind { font-size: 9px; margin-inline-start: 5px; opacity: .55; }
table.data th.sorted .sort-ind { opacity: 1; }
table.data td.ta-end { text-align: end; font-variant-numeric: tabular-nums; }
table.data td.ta-center { text-align: center; }
table.data td.wrap { white-space: normal; min-width: 200px; }
table.data td.num { font-variant-numeric: tabular-nums; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.neg td { color: var(--bad); }
table.data tbody tr.warn-row td { background: var(--warn-soft); }
table.data tfoot td {
  position: sticky; bottom: 0;
  background: var(--surface-2);
  font-weight: 700; font-size: 12.5px;
  border-block-start: 1px solid var(--line);
  white-space: nowrap;
}
table.data td.empty, table.data th { padding: 0; }
table.data td.empty { white-space: normal; }

/* The installment plan's per-date schedule: a native <details> keeps the table
   compact until a reader asks to see every due date. */
.plan-details > summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  list-style: none;
}
.plan-details > summary::-webkit-details-marker { display: none; }
.plan-details > summary::after {
  content: " ▾";
  color: var(--text-3);
  font-size: 10px;
}
.plan-details[open] > summary::after { content: " ▴"; }
.plan-list {
  display: grid;
  gap: 3px;
  margin-block-start: 6px;
  min-width: 180px;
}
.plan-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}
.plan-amount { font-weight: 700; color: var(--text); }

.empty-box { padding: 40px 16px; text-align: center; color: var(--text-3); }
.empty-icon { font-size: 26px; margin-block-end: 8px; opacity: .6; }

.table-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border-block-start: 1px solid var(--line-soft);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.table-bar .spacer { flex: 1; }
.counter { font-size: 12px; color: var(--text-2); }
.counter b { color: var(--text); }

/* ------------------------------------------------------------------ pill */
.pill {
  display: inline-block; padding: 1px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  white-space: nowrap;
}
.pill-ok    { background: var(--ok-soft);   color: var(--ok); }
.pill-warn  { background: var(--warn-soft); color: var(--warn); }
.pill-bad   { background: var(--bad-soft);  color: var(--bad); }
.pill-muted { background: var(--muted-soft);color: var(--text-2); }
.pill-accent{ background: var(--accent-soft);color: var(--accent); }

.tag {
  display: inline-block; padding: 1px 7px; margin: 1px 2px 1px 0;
  border-radius: 4px; font-size: 11px;
  background: var(--muted-soft); color: var(--text-2);
  border: 1px solid var(--line-soft);
}
html[dir="rtl"] .tag { margin: 1px 0 1px 2px; }

/* ---------------------------------------------------------------- notice */
.notice {
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
  padding: 9px 12px; margin-block-end: 12px;
  border-radius: var(--radius-sm); font-size: 12.5px;
  border-inline-start: 3px solid;
}
.notice-info  { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.notice-warn  { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn); }
.notice-error { background: var(--bad-soft);    color: var(--bad);    border-color: var(--bad); }
.notice-ok    { background: var(--ok-soft);     color: var(--ok);     border-color: var(--ok); }
.notice-fatal {
  background: var(--bad-soft); color: var(--bad); border-color: var(--bad);
  display: block; white-space: pre-wrap; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px; line-height: 1.5;
}
.notice strong { font-weight: 700; }

/* ------------------------------------------------------------- stat list */
.statlist { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.stat {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line-soft);
}
.stat .k { font-size: 11.5px; color: var(--text-2); }
.stat .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .d { font-size: 11.5px; font-variant-numeric: tabular-nums; }
.stat .d.up { color: var(--ok); } .stat .d.down { color: var(--bad); }

/* --------------------------------------------------------------- chart */
/* Clips, and is opaque.
 *
 * Both are needed and neither is enough alone: a canvas is transparent, and a
 * .chart-box with no background let a chart that overflowed its frame be drawn
 * over the page with the content showing through the middle of it — a payments
 * table visible through the ring of a pie. Clipping stops the overflow; the
 * background stops the see-through. A chart can no longer render over content
 * that is not part of it.
 *
 * Height is a minimum, not a fixed value, so a legend appended under the drawing
 * can grow the box instead of being clipped off. */
/* ---------------- the company logo ------------------------------------ */
/* Deliberately NO display:none here.
 *
 * The loader hides the logo inline until it has loaded, and reveals it by setting
 * a real display value. A stylesheet rule of display:none would win again the
 * moment the inline value was cleared, and the logo would sit there loaded at full
 * size and invisible — which reads as a missing file and sends you looking in the
 * wrong place. The loader owns this state on its own. */
.brand-logo { vertical-align: middle; }

/* In the top bar: fixed height so the bar does not jump when the image arrives,
 * which matters because it arrives after first paint. */
.app-logo {
  block-size: 32px;
  inline-size: auto;
  max-inline-size: 200px;
  object-fit: contain;
  object-position: left center;
  margin-inline-end: 12px;
  flex: 0 0 auto;
}

/* On paper: larger, above the company name, left-aligned in the letterhead so it
 * cannot push the document reference off the page. */
.print-logo {
  max-inline-size: 160px;
  max-block-size: 56px;
  object-fit: contain;
  object-position: left center;
  margin-block-end: 4px;
}

.chart-box {
  position: relative;
  block-size: auto;
  min-block-size: 200px;
  overflow: hidden;
  background: var(--surface, var(--bg-1, #fff));
}
.chart-box.tall { min-block-size: 260px; }
.chart-box.short { min-block-size: 170px; }

/* The drawing's definite frame. */
.chart-canvas { position: relative; inline-size: 100%; }

/* ----------------------------------------------------------------- tabs */
.tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  border-block-end: 1px solid var(--line);
  margin-block-end: 14px;
}
.tab {
  padding: 8px 14px; border: 0; background: transparent;
  color: var(--text-2); font-size: 13px; font-weight: 600;
  cursor: pointer; border-block-end: 2px solid transparent;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { color: var(--accent); border-block-end-color: var(--accent); background: var(--accent-soft); }
.tab .n { font-size: 11px; color: var(--text-3); margin-inline-start: 4px; }

/* A segmented control, for a choice of two inside a dialog (which season is
   this receipt for?). Unlike .tabs it is a closed set, so it reads as a pair
   of buttons rather than a row of links. */
.seg {
  display: flex; gap: 0; margin-block-end: 4px;
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: var(--surface-2);
}
.seg-btn {
  flex: 1 1 0; padding: 9px 12px; border: 0; background: transparent;
  color: var(--text-2); font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  border-inline-end: 1px solid var(--line);
}
.seg-btn:last-child { border-inline-end: 0; }
.seg-btn:hover { background: var(--surface); color: var(--text); }
.seg-btn.active { background: var(--accent); color: #fff; }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* A control that is waiting on an earlier answer. Dimming plus the disabled
   cursor says "not yet" without hiding it — the user can see the shop box
   exists and knows what will unlock it. */
.input:disabled, .select:disabled {
  opacity: .5; cursor: not-allowed; background: var(--muted-soft);
}
.hint { font-size: 11.5px; color: var(--text-3); margin-block-start: 4px; }

/* A figure that leads somewhere. It must not LOOK like a plain value or nobody
   will try it, and it must not look like a link either or people will expect a
   page change rather than a filtered list. */
.linkbtn {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: inherit; font: inherit; text-align: inherit;
  display: inline-flex; align-items: baseline; gap: 6px;
  border-block-end: 1px dashed var(--accent);
}
.linkbtn:hover .linkbtn-go { text-decoration: underline; }
.linkbtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.linkbtn-go { font-size: 10.5px; font-weight: 700; color: var(--accent); white-space: nowrap; }

/* ---------------------------------------------------------------- modal */
#modals {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; pointer-events: none;
}
#toasts {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  gap: 8px; padding: 16px; pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--text); color: var(--surface);
  padding: 9px 16px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease;
}
.toast-error { background: var(--bad); color: #fff; }
.toast-warn  { background: var(--warn); color: #fff; }
.toast-ok    { background: var(--ok);  color: #fff; }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.modal {
  pointer-events: auto;
  /* Centred by the flex container above rather than by left:50% + a
     translateX whose sign has to flip with the writing direction. */
  position: relative;
  width: min(680px, 100%);
  max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: modal-in .16s ease;
}
.modal.wide { width: min(1100px, 100%); }
.modal.closing { opacity: 0; transition: opacity .12s; }
@keyframes modal-in { from { opacity: 0; transform: scale(.985) translateY(6px); } }

.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-block-end: 1px solid var(--line-soft);
}
.modal-head h2 { flex: 1; min-width: 0; }
.modal-head .back-btn {
  inline-size: 28px; block-size: 28px; flex: 0 0 auto;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 17px; cursor: pointer;
}
.modal-head .back-btn:hover { color: var(--text); border-color: var(--line-strong); }
.modal-body { padding: 16px; overflow: auto; flex: 1; min-height: 0; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 16px; border-block-start: 1px solid var(--line-soft);
  background: var(--surface-2);
}

/* ----------------------------------------------------------------- lock */
.lock {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: var(--bg);
}
.lock-box {
  width: min(360px, calc(100vw - 32px));
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.lock-box .mark {
  width: 48px; height: 48px; margin: 0 auto 12px;
  border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 20px; font-weight: 800;
}
.lock-box p { color: var(--text-2); font-size: 13px; }
.pin-dots { letter-spacing: 10px; font-size: 22px; color: var(--text-3); height: 28px; }
.lock.shake .pin-dots { animation: shake .3s; color: var(--bad); }
@keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }

/* --------------------------------------------------------------- loader */
.loader {
  display: grid; place-items: center; min-height: 60vh;
  color: var(--text-2); gap: 12px;
}
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- misc */
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.mono  { font-variant-numeric: tabular-nums; }
.right { text-align: end; }
.nowrap { white-space: nowrap; }
.mt { margin-block-start: 12px; }
.mb0 { margin-block-end: 0; }
hr.sep { border: 0; border-block-start: 1px solid var(--line-soft); margin: 14px 0; }

.rem-pos  { color: var(--bad); font-weight: 600; }
.rem-zero { color: var(--ok); }
.pc-ok    { color: var(--ok); font-weight: 600; }
.pc-low   { color: var(--warn); font-weight: 600; }
.neg-amt  { color: var(--bad); }

.row-acts { display: inline-flex; gap: 2px; }

/* Excel's receipt numbers are mixed ("1652 R", "THAI 1705"), so they are kept
   together and never wrapped mid-number. */
.receipt-cell { display: inline-flex; align-items: center; gap: 5px; }
.receipt-cell > b { font-weight: 650; white-space: nowrap; }

.minibar { display: flex; align-items: center; gap: 7px; min-width: 110px; }
.minibar .bar { flex: 1; margin: 0; }
.minibar-txt { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; min-width: 40px; text-align: end; }

.attn {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-block-end: 7px;
  border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  color: var(--text); text-decoration: none;
}
.attn:hover { background: var(--accent-soft); border-color: var(--accent); text-decoration: none; }
.attn-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.attn-body b { font-size: 13px; font-weight: 600; }
.attn-body span { font-size: 11.5px; color: var(--text-2); }
.attn-arrow { color: var(--text-3); }

.setting-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 11px 0; border-block-end: 1px solid var(--line-soft);
}
.setting-row:last-child { border-block-end: 0; padding-block-end: 0; }
.setting-label { flex: 1; min-width: 160px; display: flex; flex-direction: column; }
.setting-label b { font-size: 13px; }
.setting-label span { font-size: 11.5px; color: var(--text-3); }
.setting-control { flex: none; display: flex; align-items: center; gap: 8px; }
.setting-control .select { min-width: 150px; }

.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--muted-soft); border: 1px solid var(--line);
  border-radius: 999px; transition: background .16s, border-color .16s;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--text-2); transition: transform .16s, background .16s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); background: #fff; }
html[dir="rtl"] .switch input:checked + .track::after { transform: translateX(-18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------- global search */
.search-box { position: relative; flex: 1; max-width: 340px; }
.search-out {
  display: none;
  position: absolute; inset-block-start: calc(100% + 6px); inset-inline: 0;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 60vh; overflow: auto; z-index: 60; padding: 4px;
}
.search-box.open .search-out { display: block; }
.sr-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border: 0; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; text-align: start;
}
.sr-item:hover { background: var(--accent-soft); }
.sr-kind {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); background: var(--accent-soft);
  padding: 1px 6px; border-radius: 4px; flex: none;
}
.sr-label { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-sub { font-size: 11.5px; color: var(--text-3); flex: none; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- PIN pad */
/* The edit-PIN prompt lives inside a dialog, so it is a compact version of the
   full-screen lock: a number field for fast typing plus the same keypad. */
.pin-dots.sm { letter-spacing: 6px; font-size: 18px; height: 22px; }
.pin-field {
  text-align: center; letter-spacing: .3em; font-size: 16px;
  font-variant-numeric: tabular-nums; margin-block-end: 4px;
}
.pad.compact { max-width: 220px; margin-inline: auto; }
.pad.compact .pad-btn { padding: 7px 0; font-size: 15px; }

.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-block-start: 14px; }
.pad-btn {
  padding: 13px 0; font-size: 19px; font-weight: 600;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer;
}
.pad-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

.lock { display: none; }
.lock.open { display: grid; }

/* ----------------------------------------------------------- sign in */
body.auth-locked { overflow: hidden; }

/* A calm, branded backdrop: two soft colour fields, a light wash, and one
   centred card. Nothing here is decorative enough to compete with the form. */
.login-screen {
  overflow: hidden;
  background:
    radial-gradient(760px 520px at 10% 8%, rgba(20, 128, 159, .20), transparent 62%),
    radial-gradient(820px 600px at 92% 92%, rgba(14, 92, 138, .18), transparent 64%),
    linear-gradient(155deg, var(--bg) 0%, var(--bg-2) 100%);
}
.login-screen::before,
.login-screen::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
}
.login-screen::before {
  width: 360px; height: 360px;
  inset-block-start: -150px; inset-inline-start: -120px;
  background: radial-gradient(circle at 35% 35%, rgba(20, 128, 159, .28), rgba(20, 128, 159, 0) 68%);
}
.login-screen::after {
  width: 460px; height: 460px;
  inset-block-end: -210px; inset-inline-end: -150px;
  background: radial-gradient(circle at 60% 40%, rgba(14, 92, 138, .24), rgba(14, 92, 138, 0) 68%);
}
:root[data-theme="dark"] .login-screen {
  background:
    radial-gradient(760px 520px at 10% 8%, rgba(20, 128, 159, .24), transparent 62%),
    radial-gradient(820px 600px at 92% 92%, rgba(14, 92, 138, .28), transparent 64%),
    linear-gradient(155deg, #0b1420 0%, #111d2b 100%);
}

.login-box {
  width: min(470px, calc(100vw - 32px));
  padding: 36px 30px 26px;
  text-align: start;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    radial-gradient(300px 200px at 108% -8%, var(--accent-soft), transparent 70%),
    var(--surface);
  box-shadow: 0 30px 70px rgba(16, 32, 54, .18), 0 1px 0 rgba(255, 255, 255, .6) inset;
}
/* A slim tri-colour rule along the top and a soft corner glow inside the card. */
.login-box::before {
  content: ""; position: absolute; z-index: 2;
  inset-block-start: 0; inset-inline: 0; height: 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2) 55%, #7a4fbf);
}
.login-box::after {
  content: ""; position: absolute; z-index: 0; pointer-events: none;
  width: 230px; height: 230px;
  inset-block-end: -150px; inset-inline-end: -110px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 70%);
}
.login-box > * { position: relative; z-index: 1; }
:root[data-theme="dark"] .login-box {
  box-shadow: 0 30px 70px rgba(0, 0, 0, .48), 0 1px 0 rgba(255, 255, 255, .04) inset;
}

.login-box .mark {
  position: relative;
  width: 58px; height: 58px;
  margin: 2px auto 14px;
  border-radius: 18px;
  font-size: 22px; letter-spacing: .5px;
  box-shadow: 0 12px 26px rgba(14, 92, 138, .28);
}
.login-box .mark::after {
  content: ""; position: absolute; inset: -5px;
  border: 1px solid var(--accent-soft); border-radius: 23px;
}
.login-box h2 {
  text-align: center; margin: 0 0 4px;
  font-size: 22px; letter-spacing: -.02em;
}
.login-sub {
  text-align: center; color: var(--text-2); font-size: 12.5px;
  line-height: 1.5; margin: 0 auto 16px; max-width: 340px;
}

/* Motivational phrase: a soft accent panel that changes every few seconds. */
.login-quote {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  min-height: 64px; margin: 0 0 20px; padding: 12px 18px;
  border: 1px solid var(--accent-soft); border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-2));
  overflow: hidden;
}
.login-quote::before,
.login-quote::after {
  position: absolute; font-family: Georgia, "Times New Roman", serif;
  font-size: 30px; line-height: 1; color: var(--accent-2); opacity: .5;
}
.login-quote::before { content: "\201C"; inset-block-start: 4px; inset-inline-start: 10px; }
.login-quote::after  { content: "\201D"; inset-block-end: 0; inset-inline-end: 10px; }
.login-quote-text {
  position: relative; z-index: 1; max-width: 340px;
  color: var(--text); font-size: 12.5px; font-weight: 600;
  line-height: 1.55; text-align: center;
  transition: opacity .22s ease, transform .22s ease;
}
.login-quote-text.swap { opacity: 0; transform: translateY(4px); }

.login-box .field { margin-block-end: 15px; }
.login-box .field > label {
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-3); margin-block-end: 6px;
}
.login-box .input {
  padding: 11px 12px; font-size: 13.5px;
  border-radius: 10px; background: var(--surface-2);
}
.login-box .input:focus { background: var(--surface); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-inline-end: 42px; }
.pw-toggle {
  position: absolute; inset-block-start: 50%; inset-inline-end: 6px;
  transform: translateY(-50%);
  padding: 5px 8px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-3);
  font-size: 15px; line-height: 1; cursor: pointer;
}
.pw-toggle:hover { background: var(--surface); color: var(--accent); }
.login-err {
  min-height: 18px; margin-block-end: 8px;
  color: var(--bad); font-size: 12.5px;
}
.login-submit {
  width: 100%; justify-content: center; padding: 11px 14px;
  border: 0; border-radius: 10px; font-weight: 700; letter-spacing: .01em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px rgba(14, 92, 138, .24);
}
.login-submit:hover {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  filter: brightness(1.03); transform: translateY(-1px);
}
.login-submit:active { transform: translateY(0); }
.login-foot {
  margin-block-start: 16px; padding-block-start: 13px;
  border-block-start: 1px solid var(--line-soft);
  text-align: center; color: var(--text-3);
  font-size: 11px; letter-spacing: .02em;
}

@media (max-width: 520px) {
  .login-box { padding: 30px 20px 22px; border-radius: 18px; }
  .login-box h2 { font-size: 20px; }
  .login-quote { min-height: 70px; padding-inline: 16px; }
}
@media (max-height: 660px) {
  .login-box { padding: 26px 26px 20px; }
  .login-box .mark {
    width: 48px; height: 48px; margin-block-end: 10px; border-radius: 15px;
  }
  .login-box .mark::after { border-radius: 20px; }
  .login-sub { margin-block-end: 12px; }
  .login-quote { min-height: 54px; margin-block-end: 14px; padding-block: 9px; }
  .login-box .field { margin-block-end: 11px; }
  .login-foot { margin-block-start: 12px; padding-block-start: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .login-quote-text, .login-submit { transition: none; }
  .login-submit:hover { transform: none; }
}

/* --------------------------------------------------------------- mobile */
@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas: "brand" "topbar" "nav" "main";
    grid-template-rows: var(--head-h) var(--head-h) auto 1fr;
  }
  .nav {
    position: sticky; top: 0; z-index: 20;
    display: none;
    border-inline-end: 0; border-block-end: 1px solid var(--line);
    padding: 8px;
  }
  .nav.open { display: block; }
  .nav a { padding: 9px 10px; }
  .main { padding: 12px; }
  .table-scroll { max-height: none; }
  .page-actions { width: 100%; margin-inline-start: 0; }
  #global-search { display: none; }
  .search-box { max-width: none; }
  .unsaved-badge span:not(:first-child) { display: none; }
}

#print-meta { display: none; }

/* ------------------------------------------------- hide balances */
.exit-btn { color: var(--bad); }
.exit-btn:hover { background: var(--bad-soft); border-color: var(--bad); }

.balance-btn.on {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: var(--warn);
}
.balance-bar {
  position: fixed; inset-block-end: 0; inset-inline: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 7px 14px;
  background: var(--warn-soft); color: var(--warn);
  border-block-start: 1px solid var(--warn);
  font-size: 12.5px; font-weight: 600;
}
.balance-bar .bi { font-size: 14px; }
body.balances-hidden .main { padding-block-end: 44px; }

.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;
}

/* --------------------------------------------------------------- print */
@page { size: A4 landscape; margin: 12mm 10mm; }

/* Group band. It is a row in the body, not a header, so it does not repeat and
   it scrolls with its group — which is the point: the band and its rows stay
   together. The facts beside the name are the group's own figures, so a value
   is stated once in the band instead of being repeated down the column.
   ON SCREEN: a coloured strip with the name, a count chip and one chip per
   figure. Deliberately NOT sticky here — it would slide under the sticky table
   header and hide the row being read. The print-only sticky variant is inside
   the @media print block below. */
table.data tr.grouprow td {
  background: var(--accent-soft);
  border-block-start: 1px solid var(--accent);
  padding-block: 6px;
}
.grouprow-in { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
table.data tr.grouprow .grouplabel { font-weight: 800; font-size: 13px; color: var(--accent); }
table.data tr.grouprow .groupcount {
  font-size: 11.5px; font-weight: 700; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 1px 8px;
  font-variant-numeric: tabular-nums;
}
table.data tr.grouprow .groupbit {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-size: 11.5px; white-space: nowrap;
}
table.data tr.grouprow .groupbit-k { color: var(--text-3); }
table.data tr.grouprow .groupbit-v {
  font-weight: 700; color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Danger zone.
   Marked as a distinct region on purpose: a destructive action that sits in the
   same list as a theme toggle gets pressed by the same muscle memory. The red
   border and the heading say "this one is different" before anything is read. */
.card.danger { border-color: var(--bad); }
.card.danger > .card-head { background: var(--bad-soft) !important; color: var(--bad); }
.danger-zone .notice { margin-block-end: 10px; }
.danger-list {
  border: 1px dashed var(--bad);
  border-radius: var(--r, 8px);
  padding: 8px 10px;
  margin-block-end: 10px;
  background: var(--bad-soft);
}
.danger-list .stat { border-block-end: 1px solid var(--line); }
.danger-list .stat:last-child { border-block-end: 0; }
/* A value that is shown rather than typed.
   Kept looking like a field so the row does not reflow when one control becomes
   read-only, but visibly not an input — a read-only box that accepts clicks is
   worse than a figure that plainly is not editable. */
.field-static {
  padding: 9px 11px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--surface-2, var(--surface));
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-height: 18px;
}

/* The printed name above the signature rule.
   Italic and quiet: it identifies who prepared the report without pretending to
   BE a signature. A typed name is not a signature, and a report should not imply
   otherwise — the rule below it is what an actual signature goes on. */
.pr-sign-name {
  font-size: 12.5px;
  font-weight: 700;
  font-style: italic;
  color: var(--text);
  margin-block-end: 3px;
}

.danger-zone .row-acts { margin-block-start: 4px; }

/* The figures under a chart, in words as well as colour. A chart cannot be read
 * aloud, quoted in a message, or checked against a total, so the numbers are
 * written out beside it. */
.chart-legend { margin-block-start: 10px; display: grid; gap: 4px; }
.chart-legend .legend-row {
  display: flex; gap: 6px; align-items: baseline; font-size: 12px;
  color: var(--text-2); flex-wrap: wrap;
}
.chart-legend .legend-row b { color: var(--text); font-variant-numeric: tabular-nums; }

/* Where there is genuinely nothing to draw, said rather than left as an empty
 * frame — an empty ring reads as a broken chart, not as "no payments yet". */
.chart-empty {
  display: grid; place-items: center; min-height: 140px;
  color: var(--muted); font-size: 13px; text-align: center;
}

/* How many accounts the statement chooser is showing. */
.count-line { font-size: 12px; color: var(--muted); padding: 6px 2px 8px; }

/* The date range a filtered list is actually showing, stated in full. */
.range-stamp {
  margin: 0 0 10px;
  padding: 7px 10px;
  background: var(--panel-2, var(--bg-2));
  border-inline-start: 3px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  color: var(--text-2);
}
/* ---------------- when the figures were read --------------------------- */
/* Provenance, not a headline: it is small and muted because it is rarely the
 * thing you came for. */
.read-stamp {
  margin-block: -4px 10px;
  font-size: 11px;
  color: var(--text-2);
  letter-spacing: .2px;
}

@media print {
  html, body { background: #fff !important; color: #000 !important; font-size: 10.5px; }
  .nav, .topbar, .page-actions, .filters, .table-bar, .icon-btn,
  #modals, #toasts, .tabs, .no-print, .card-actions { display: none !important; }

  .shell { display: block; }
  .main { padding: 0; overflow: visible; }
  #view { max-width: none; }

  #print-meta {
    display: block;
    margin-block-end: 8px; padding-block-end: 6px;
    border-block-end: 1.5px solid #000;
    font-size: 11px; font-weight: 700;
  }

  .card {
    border: 1px solid #999; box-shadow: none;
    break-inside: auto; margin-block-end: 10px;
  }
  .card-head { background: #f0f0f0 !important; padding: 5px 8px; }
  .card-body { padding: 8px; }
  .kpis { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .kpi { border: 1px solid #999; padding: 6px 8px; break-inside: avoid; }
  .kpi-value { font-size: 14px; }

  .table-scroll { max-height: none !important; overflow: visible !important; }
  table.data { font-size: 9.5px; width: 100%; }
  table.data th, table.data td { padding: 2.5px 5px; white-space: normal; }
  table.data th { position: static; background: #eee !important; color: #000 !important; }
  table.data tfoot td { position: static; background: #eee !important; }
  table.data .grouprow-in { font-variant-numeric: tabular-nums; }

  /* Printed group band: sticky, so a band that starts near the foot of a page
     travels to the next one instead of stranding its rows under a stranger. */
  table.data tr.grouprow td { position: sticky; inset-block-start: 0; z-index: 2; }

  /* A row that is one of several for the same merchant, because the merchant
     holds shops in more than one pavilion. Marked so the repeat is legible as
     "same person, another pavilion" rather than looking like a duplicate. */
  table.data tbody tr.in-multi td:first-child { border-inline-start: 3px solid var(--line); }
  table.data tbody tr { break-inside: avoid; }
  table.data thead { display: table-header-group; }
  table.data tfoot { display: table-footer-group; }

  .pill, .tag, .bar { border: 1px solid #999 !important; background: none !important; color: #000 !important; }
  .bar-fill { background: #999 !important; }
  .chart-box { height: 200px; break-inside: avoid; }
  .notice { border: 1px solid #999; background: none !important; color: #000 !important; }

  /* hide the paginated tail: printing shows every row of the current filter */
  .no-print { display: none !important; }
  a[href]::after { content: ""; }
}

/* =========================================================================
 * Two-part sign-in
 *
 * The earlier single centred card is kept above as the base look; these rules
 * turn it into a branded introduction beside a focused sign-in form. The
 * `.login-shell .login-box` selectors intentionally outrank the older card
 * rules, including their narrow-screen and short-screen overrides.
 * ========================================================================= */
.login-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(370px, .95fr);
  width: min(1080px, calc(100vw - 32px));
  max-block-size: calc(100dvh - 32px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--surface);
  box-shadow: 0 38px 90px rgba(16, 32, 54, .22), 0 1px 0 rgba(255, 255, 255, .5) inset;
  isolation: isolate;
}
:root[data-theme="dark"] .login-shell {
  box-shadow: 0 38px 90px rgba(0, 0, 0, .55), 0 1px 0 rgba(255, 255, 255, .04) inset;
}

.login-info {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: clamp(28px, 4vw, 46px);
  color: #f4f0e4;
  background:
    radial-gradient(420px 300px at 108% -8%, rgba(201, 162, 39, .30), transparent 62%),
    radial-gradient(480px 380px at -12% 108%, rgba(20, 128, 159, .34), transparent 64%),
    linear-gradient(150deg, #0a202d 0%, #103542 52%, #0a1a24 100%);
}
/* A faint blueprint grid keeps the panel from reading as a flat colour block. */
.login-info::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image:
    linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: 38px 38px;
  -webkit-mask-image: linear-gradient(160deg, #000, transparent 75%);
  mask-image: linear-gradient(160deg, #000, transparent 75%);
}
.login-info::after {
  content: ""; position: absolute; pointer-events: none;
  width: 320px; height: 320px;
  inset-block-end: -190px; inset-inline-end: -120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 162, 39, .22), transparent 68%);
}
.login-info > * { position: relative; z-index: 1; }

.login-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 14px; }
.login-brand-logo {
  display: inline-block;
  width: auto;
  max-width: min(240px, 78%);
  max-height: 120px;
  object-fit: contain;
  object-position: left center;
}
.login-brand-text { min-width: 0; }
.login-kicker {
  display: block;
  color: #d8b95f;
  font-size: 10px; font-weight: 800; letter-spacing: .18em;
  line-height: 1.4; text-transform: uppercase;
}
.login-brand h1 {
  margin: 4px 0 0;
  color: #fff;
  font-size: clamp(20px, 2.2vw, 28px);
  line-height: 1.1; letter-spacing: -.03em;
}
.login-info-lead {
  max-width: 46ch;
  margin: 22px 0 0;
  color: rgba(255, 255, 255, .72);
  font-size: 13px; line-height: 1.75;
}
.login-points { display: grid; gap: 11px; margin: 22px 0 0; padding: 0; list-style: none; }
.login-points li {
  display: flex; align-items: flex-start; gap: 11px;
  color: rgba(255, 255, 255, .88);
  font-size: 12.5px; line-height: 1.5;
}
.login-point-dot {
  flex: 0 0 auto;
  width: 7px; height: 7px; margin-block-start: 7px;
  border-radius: 50%;
  background: #d8b95f;
  box-shadow: 0 0 0 4px rgba(216, 185, 95, .13);
}
.login-info .login-quote {
  min-height: 72px;
  margin: auto 0 0;
  padding: 16px 20px;
  border-color: rgba(255, 255, 255, .15);
  background: linear-gradient(135deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .03));
}
.login-info .login-quote::before,
.login-info .login-quote::after { color: #d8b95f; opacity: .7; }
.login-info .login-quote-text {
  max-width: none;
  color: rgba(255, 255, 255, .9);
  text-align: start;
}
.login-info-foot {
  margin-block-start: 18px;
  padding-block-start: 14px;
  border-block-start: 1px solid rgba(255, 255, 255, .14);
  color: rgba(255, 255, 255, .48);
  font-size: 10px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase;
}

.login-shell .login-box {
  width: auto;
  min-width: 0;
  padding: clamp(30px, 3.8vw, 48px);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: start;
  overflow: auto;
}
.login-shell .login-box::before,
.login-shell .login-box::after { display: none; }
.login-form-head { margin-block-end: 22px; }
.login-form-kicker {
  display: block;
  color: var(--accent);
  font-size: 10px; font-weight: 800; letter-spacing: .16em;
  text-transform: uppercase;
}
.login-shell .login-box h2 {
  margin: 6px 0;
  text-align: start;
  font-size: clamp(24px, 2.5vw, 31px);
  letter-spacing: -.03em;
}
.login-shell .login-sub {
  max-width: none;
  margin: 0;
  text-align: start;
  font-size: 12.5px;
  line-height: 1.55;
}
.login-shell .field { margin-block-end: 16px; }
.login-shell .field > label { font-size: 11px; font-weight: 800; letter-spacing: .06em; }
.login-shell .input { padding: 12px 13px; font-size: 13.5px; }
.login-shell .login-submit { margin-block-start: 2px; padding: 12px 16px; }
.login-shell .login-foot {
  margin-block-start: 18px;
  padding-block-start: 14px;
  text-align: start;
}

@media (max-width: 900px) {
  .login-shell {
    grid-template-columns: 1fr;
    width: min(560px, calc(100vw - 24px));
    max-block-size: calc(100dvh - 24px);
  }
  .login-info { padding: 26px 26px 22px; }
  .login-brand { min-height: 0; }
  .login-brand-logo { max-width: 190px; max-height: 95px; }
  .login-brand h1 { font-size: 22px; }
  .login-info-lead { margin-block-start: 14px; font-size: 12.5px; }
  .login-points { grid-template-columns: 1fr 1fr; gap: 8px 14px; margin-block-start: 16px; }
  .login-info .login-quote { display: none; }
  .login-info-foot { display: none; }
  .login-shell .login-box { padding: 26px; }
}
@media (max-width: 560px) {
  .login-shell { width: calc(100vw - 16px); border-radius: 18px; }
  .login-info { padding: 20px; }
  .login-brand { gap: 10px; }
  .login-brand-logo { max-width: 165px; max-height: 82px; }
  .login-brand h1 { font-size: 19px; }
  .login-info-lead { font-size: 12px; line-height: 1.6; }
  .login-points { display: none; }
  .login-shell .login-box { padding: 22px 18px; }
  .login-shell .login-box h2 { font-size: 23px; }
}

@media (max-height: 640px) and (min-width: 901px) {
  .login-brand-logo { max-width: 190px; max-height: 90px; }
  .login-info .login-quote { display: none; }
}

/* ------------------------------------------------ users, roles, permissions */

/* Who is signed in, in the topbar. The role is written out so a reader never
   has to infer it from which tabs are visible. */
.user-chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  max-width: 190px; padding-inline: 8px; line-height: 1.15;
}
.user-name {
  max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; font-weight: 800;
}
.user-role {
  color: var(--muted); font-size: 9.5px; font-weight: 800;
  letter-spacing: .07em; text-transform: uppercase;
}
.logout-btn { white-space: nowrap; }

.login-first-run {
  margin-block-start: 12px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); color: var(--muted);
  font-size: 11.5px; line-height: 1.5;
}

.form-err {
  min-height: 1.1em; margin-block-start: 6px;
  color: var(--bad); font-size: 12px; font-weight: 700;
}
.check-row {
  display: flex; align-items: center; gap: 8px;
  margin-block: 10px; font-size: 12.5px; line-height: 1.4;
}
.check-row input { flex: 0 0 auto; }

.user-assignments {
  margin-block-start: 14px; padding: 12px;
  border: 1px dashed var(--line); border-radius: 10px;
  background: var(--surface-2);
}
.pay-assign-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* The receipt picker. It is a modal of its own because an accountant can be
   limited to a handful of receipts, and a list is the only honest way to show
   which handful. */
.pay-pick-tools {
  display: grid; grid-template-columns: 1fr minmax(150px, 230px);
  gap: 8px; margin-block-end: 8px;
}
.pay-pick-actions {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-block-end: 8px;
}
.pay-pick-list {
  max-height: 46vh; overflow: auto;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
}
.pay-pick-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-block-end: 1px solid var(--line-soft);
  cursor: pointer;
}
.pay-pick-row:last-child { border-block-end: 0; }
.pay-pick-row:hover { background: var(--surface-2); }
.pay-pick-main { flex: 1 1 auto; min-width: 0; }
.pay-pick-amt {
  flex: 0 0 auto; white-space: nowrap;
  font-variant-numeric: tabular-nums; font-weight: 700;
}

/* Permission grid: feature rows, three role blocks, six actions each. */
.perm-grid-wrap {
  max-width: 100%; overflow: auto;
  border: 1px solid var(--line); border-radius: 10px;
}
.perm-grid {
  width: 100%; min-width: 1160px;
  border-collapse: collapse; font-size: 11.5px;
}
.perm-grid th, .perm-grid td {
  padding: 6px 8px; border: 1px solid var(--line); text-align: center;
}
.perm-grid thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2); font-weight: 800;
}
.perm-grid .perm-feature {
  text-align: start; white-space: nowrap;
  background: var(--surface); font-weight: 700;
}
.perm-grid .perm-role-head { background: var(--surface-2); }
.perm-grid .perm-action {
  color: var(--muted); font-size: 9.5px; font-weight: 800;
  letter-spacing: .05em; text-transform: uppercase;
}
.perm-grid .perm-role { white-space: nowrap; }
.perm-check {
  display: inline-flex; align-items: center; gap: 3px;
  margin-inline: 4px; color: var(--muted);
  font-size: 10.5px; cursor: pointer;
}
.perm-check input { margin: 0; }
.perm-check input:disabled { opacity: .7; cursor: default; }
.perm-lock { margin-inline-start: 6px; font-size: 11px; }
.perm-saved { align-self: center; color: var(--ok); font-weight: 700; }

.attn.readonly { cursor: default; }
.attn.readonly .attn-arrow { display: none; }

@media (max-width: 900px) {
  .user-chip { display: none; }
  .pay-pick-tools { grid-template-columns: 1fr; }
}
