/* Rental: the frame is one tinted L, the work sits on a white sheet.
   Grid: sheet padding 24; desk row = 1fr + 24 + 384. One gutter (24) everywhere. */
:root {
  --ground: #f6f7fb; --surface: #ffffff; --raised: #f3f5f9; --active: #e8ebf2;
  --border: #e8eaee; --rule: #f0f1f4; --control: #cdd0d6;
  --text: #15171c; --muted: #5a5e67; --faint: #686c75;
  --accent: #2f66d9; --primary: #15171c; --primary-ink: #ffffff;
  --positive: #1e7b4f; --negative: #c4242a; --warning: #92400e;
  --pill-positive-bg: #dcfae5; --pill-positive-ink: #04250e;
  --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e;
  --pill-warning-bg: #fffbeb; --pill-warning-ink: #92400e;
  --pill-neutral-bg: #e8ebf2; --pill-neutral-ink: #343843;
  --chart-1: #2f66d9; --chart-2: #2f70bb; --chart-3: #a86f0c; --chart-muted: #cdd2dc; --chart-mark: var(--text); --chart-span: .06;
  --grid: var(--rule); --axis-ink: var(--muted); --ink: var(--text);
  --radius-card: 8px; --radius-control: 6px; --radius-sheet: 16px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --fs-title: 22px; --fs-section: 16px; --fs-kpi: 28px; --fs-body: 14px; --fs-small: 12px;
  --sidebar-width: 228px; --pad: 24px; --gap: 24px; --card-pad: 20px;
  --control-height: 32px; --row-height: 52px; --nav-row: 32px;
  --ease-out: cubic-bezier(.22, 1, .36, 1); --t-press: 120ms; --t-hover: 150ms; --t-ui: 200ms;
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M4.5 2.5 8 6l-3.5 3.5' fill='none' stroke='black' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--text); font: var(--fs-body)/20px var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, figure, ul, ol, dl, dd { margin: 0; }
ul { padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.num, table, .kpi-value { font-variant-numeric: tabular-nums; }
small.u { font-size: var(--fs-small); color: var(--muted); font-weight: 400; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 8px; }
.mark svg { width: 24px; height: 24px; }
.brand-name { font-size: 16px; font-weight: 600; }

/* ---------- sign in ---------- */
.auth { min-height: 100svh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); background: #fffefe; }
.auth-panel { display: flex; flex-direction: column; padding: 32px 48px; }
.auth-body { margin: auto 0; width: 100%; max-width: 380px; align-self: center; padding: 32px 0; }
.auth h1 { font-size: 28px; line-height: 34px; font-weight: 600; letter-spacing: -.01em; }
.auth-sub { margin-top: 8px; color: var(--muted); font-size: 16px; line-height: 24px; }
.auth .tabs { margin: 28px 0 24px; }
#authForm { display: grid; gap: 16px; }
.auth-art { display: grid; place-items: center; padding: 32px; }
.auth-art img { width: 100%; max-width: 620px; height: auto; }
.form-error { padding: 8px 12px; border-radius: var(--radius-control); background: var(--pill-negative-bg); color: var(--pill-negative-ink); }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr); min-height: 100svh; }
.sidebar { grid-row: 1 / -1; position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; padding: 12px; overflow: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; height: 32px; padding: 0 8px; }
.sidebar-head .close-menu { display: none; }
.scope { margin: 2px 8px 16px; color: var(--muted); font-size: var(--fs-small); }
#nav { display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 10px; height: var(--nav-row); padding: 0 8px; border-radius: 8px; color: var(--muted); transition: background-color var(--t-hover) ease, color var(--t-hover) ease; }
.nav-item svg { width: 16px; height: 16px; flex: none; }
.nav-item:hover { background: var(--raised); color: var(--text); }
.nav-item[aria-current="page"] { background: var(--active); color: var(--text); }
.nav-count { margin-left: auto; font-size: var(--fs-small); color: var(--text); font-variant-numeric: tabular-nums; }
.nav-count.late { color: var(--negative); font-weight: 600; }
.bottom { margin-top: auto; padding-top: 16px; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 0 0 0 4px; }
.avatar { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-size: var(--fs-small); font-weight: 600; color: #22252c; }
.user-text { flex: 1; min-width: 0; display: grid; line-height: 16px; }
.user-text > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.user-text small { color: var(--muted); font-size: var(--fs-small); }

.topbar { display: grid; grid-template-columns: 1fr minmax(0, 548px) 1fr; align-items: center; gap: 12px; padding-right: 16px; }
.top-right { justify-self: end; grid-column: 3; display: flex; align-items: center; gap: 16px; white-space: nowrap; }
.balance-link { display: inline-flex; align-items: center; height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface); font-weight: 500; transition: background-color var(--t-hover) ease; }
.balance-link:hover { background: var(--raised); }
.balance-link.low { color: var(--negative); }
.balance-now { font-size: var(--fs-kpi); line-height: 34px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.balance-now.low { color: var(--negative); }
#topupForm { display: grid; gap: 16px; margin-top: 16px; }
.topup-picks { display: flex; gap: 8px; flex-wrap: wrap; }
.plus { color: var(--positive); }
.topbar-title, .topbar .menu-toggle { display: none; }
.global-search { grid-column: 2; display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-control); color: var(--muted); transition: border-color var(--t-hover) ease; }
.global-search:focus-within { border-color: var(--accent); }
.global-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); }
.global-search input::placeholder { color: var(--faint); }
.global-search input::-webkit-search-cancel-button { display: none; }
.search-icon svg { width: 14px; height: 14px; }
kbd { font: inherit; font-size: var(--fs-small); color: var(--muted); }
.stamp { color: var(--muted); font-size: var(--fs-small); }

.sheet { grid-column: 2; margin: 0 8px 8px 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sheet); min-width: 0; }
.canvas { padding: var(--pad); min-width: 0; outline: 0; }

/* ---------- title and toolbars ---------- */
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: var(--gap); }
.title-row h1 { font-size: var(--fs-title); line-height: 28px; font-weight: 600; letter-spacing: -.01em; }
.title-row .sub { margin-top: 4px; color: var(--muted); }
.title-row .sub b { color: var(--negative); font-weight: 500; }
.title-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.toolbar .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.search-field { width: 280px; }
.mobile-only { display: none; }

/* ---------- panels ---------- */
.desk-grid { display: grid; grid-template-columns: minmax(0, 1fr) 384px; gap: var(--gap); align-items: start; }
.stack-col { display: grid; gap: var(--gap); min-width: 0; }
.rail-block h2 { font-size: var(--fs-section); line-height: 20px; font-weight: 600; margin-bottom: 8px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: var(--card-pad); min-width: 0; }
.panel.tight { padding: 4px var(--card-pad); }
.panel > header { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 12px; }
.panel h2 { font-size: var(--fs-section); line-height: 20px; font-weight: 600; }
.meta { color: var(--muted); font-size: var(--fs-small); }
.report-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--gap); margin-top: var(--gap); align-items: start; }
.report-grid .wide-col { grid-column: 1 / -1; }

.kpis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); border: 1px solid var(--border); border-radius: var(--radius-card); }
.kpi { padding: 14px var(--card-pad); }
.kpi + .kpi { border-left: 1px solid var(--border); }
.kpi-label { color: var(--muted); }
.kpi-value { margin-top: 4px; font-size: var(--fs-kpi); line-height: 34px; font-weight: 400; letter-spacing: -.01em; }
.kpi-value small { font-size: 14px; color: var(--muted); letter-spacing: 0; margin-left: 2px; }
.kpi-value.bad { color: var(--negative); }
.delta { margin-top: 2px; font-size: var(--fs-small); color: var(--muted); }
.delta .good { color: var(--positive); } .delta .bad { color: var(--negative); }

.legend, .chart-legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: var(--fs-small); }
.chart { position: relative; min-width: 0; }

.rows { display: grid; }
.row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 0; }
.row + .row { border-top: 1px solid var(--rule); }
.row .grow { flex: 1; min-width: 0; }
.row .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row small, td small { display: block; font-size: var(--fs-small); line-height: 16px; color: var(--muted); }
.row small.u, td small.u { display: inline; }
.amount, td.n { white-space: nowrap; }
.row .amount { text-align: right; font-variant-numeric: tabular-nums; flex: none; }
.glyph { flex: none; width: 28px; height: 28px; color: #3a3f4a; }
.glyph.big { width: 88px; height: 88px; color: var(--text); }
.glyph svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- tables ---------- */
.table-wrap { min-width: 0; }
table { width: 100%; border-collapse: collapse; }
th { height: 36px; padding: 0 12px; text-align: left; font-weight: 400; font-size: var(--fs-small); color: var(--muted); white-space: nowrap; }
td { height: var(--row-height); padding: 6px 12px; border-top: 1px solid var(--rule); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th.n, td.n { text-align: right; }
td.act { text-align: right; white-space: nowrap; width: 1%; }
td.act .btn + .btn, td.act select + .btn { margin-left: 6px; }
.item-link { display: flex; align-items: center; gap: 12px; width: 100%; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; }
.item-link .t { min-width: 0; }
.item-link .name { font-weight: 500; text-underline-offset: 3px; }
.item-link:hover .name { text-decoration: underline; }
.progress { width: 96px; height: 6px; border-radius: 999px; background: var(--raised); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--chart-1); border-radius: 999px; }
.progress.late i { background: var(--negative); }
.mono { font-family: "IBM Plex Mono", Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.dash { color: var(--muted); }

.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: var(--fs-small); font-weight: 500; background: var(--pill-neutral-bg); color: var(--pill-neutral-ink); white-space: nowrap; flex: none; }
.pill.pos { background: var(--pill-positive-bg); color: var(--pill-positive-ink); }
.pill.neg { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
.pill.warn { background: var(--pill-warning-bg); color: var(--pill-warning-ink); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--control-height); padding: 0 12px; border-radius: var(--radius-control); border: 1px solid var(--control); background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color var(--t-hover) ease, transform var(--t-press) var(--ease-out), opacity var(--t-hover) ease; }
.btn:hover { background: var(--raised); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { cursor: default; color: var(--muted); background: var(--raised); border-color: var(--border); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.primary:hover { background: #2c3039; }
.btn.primary[disabled] { background: #e3e5ea; color: var(--muted); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--raised); }
.btn.danger { color: var(--negative); }
.btn.icon { width: 32px; padding: 0; color: var(--muted); }
.btn.icon svg { width: 16px; height: 16px; }
.btn.wide { width: 100%; height: 40px; }
.field { display: grid; gap: 8px; }
.field label { font-weight: 500; }
.hint { color: var(--muted); font-size: var(--fs-small); line-height: 16px; }
.input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); transition: border-color var(--t-hover) ease; }
.input::placeholder { color: var(--faint); }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input.slim { height: var(--control-height); padding: 0 10px; }
select.input.slim { width: auto; padding-right: 4px; }
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--border); }
.tabs a, .tabs button { position: relative; padding: 8px 0; border: 0; background: none; color: var(--muted); cursor: pointer; white-space: nowrap; transition: color var(--t-hover) ease; }
.tabs a:hover, .tabs button:hover { color: var(--text); }
.tabs [aria-selected="true"] { color: var(--text); font-weight: 500; }
.tabs [aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--text); }
.tabs-row { margin-bottom: 16px; }
.segmented { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--raised); }
.segmented button { height: 28px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; transition: background-color var(--t-hover) ease, color var(--t-hover) ease; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); font-weight: 500; }

.card-link { display: inline-flex; align-items: center; gap: 2px; padding: 0; border: 0; background: none; font-weight: 500; cursor: pointer; text-underline-offset: 3px; }
.card-link::after { content: ""; width: 12px; height: 12px; background: currentColor; -webkit-mask: var(--chevron) center / 12px no-repeat; mask: var(--chevron) center / 12px no-repeat; }
.card-link:hover { text-decoration: underline; }

.empty { display: grid; place-items: center; gap: 8px; min-height: 96px; padding: 16px; border: 1px dashed var(--control); border-radius: var(--radius-control); color: var(--muted); text-align: center; }
.skeleton { background: var(--raised); border-radius: 4px; height: 240px; }
.error-state { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-radius: var(--radius-control); background: var(--pill-negative-bg); color: var(--pill-negative-ink); }

/* ---------- things that float ---------- */
dialog { padding: 0; border: 0; color: inherit; background: var(--surface); box-shadow: 0 12px 40px rgba(15, 18, 26, .18); }
dialog::backdrop { background: rgba(15, 18, 26, .32); }
.modal { width: min(460px, calc(100vw - 32px)); border-radius: var(--radius-sheet); }
.modal.small { width: min(400px, calc(100vw - 32px)); }
.modal[open] { animation: rise var(--t-ui) var(--ease-out); }
.drawer { margin: 8px 8px 8px auto; width: min(440px, calc(100vw - 16px)); height: calc(100dvh - 16px); max-height: none; border-radius: var(--radius-sheet); }
.drawer[open] { animation: slide var(--t-ui) var(--ease-out); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes slide { from { opacity: 0; transform: translateX(24px); } }
.dialog-body { display: grid; gap: 16px; padding: 24px; }
.dialog-head { display: flex; align-items: flex-start; gap: 12px; }
.dialog-head h2 { flex: 1; font-size: 18px; line-height: 24px; font-weight: 600; }
.dialog-head small { display: block; font-size: 14px; line-height: 20px; color: var(--muted); font-weight: 400; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; }
.day-picks { display: flex; gap: 8px; align-items: center; }
.day-picks .input { width: 84px; flex: none; }
.quote { display: grid; gap: 4px; padding: 12px 16px; border-radius: var(--radius-card); background: var(--raised); min-height: 92px; align-content: center; font-variant-numeric: tabular-nums; }
.quote div { display: flex; justify-content: space-between; gap: 12px; }
.quote .total { font-size: 16px; font-weight: 600; }
.quote .muted-line { color: var(--muted); }
.quote .short { color: var(--negative); font-weight: 500; }
.quote .short .card-link { color: var(--text); }
.drawer-hero { display: flex; gap: 20px; align-items: center; padding: 16px; border-radius: var(--radius-card); background: var(--raised); }
.facts { display: grid; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; }
.facts div + div { border-top: 1px solid var(--rule); }
.facts dt { color: var(--muted); }
.facts dd { font-variant-numeric: tabular-nums; text-align: right; }
.drawer h3 { font-size: var(--fs-section); font-weight: 600; line-height: 20px; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 50; transform: translateX(-50%); max-width: min(460px, calc(100vw - 32px)); padding: 10px 16px; border-radius: var(--radius-control); background: var(--primary); color: var(--primary-ink); box-shadow: 0 8px 24px rgba(15, 18, 26, .24); animation: rise var(--t-ui) var(--ease-out); }
.toast.bad { background: #831c1e; }

/* ---------- tablet and phone ---------- */
@media (max-width: 1180px) {
  .desk-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 20; background: var(--surface); padding: 16px; transform: translateX(-100%); visibility: hidden; transition: transform var(--t-ui) var(--ease-out), visibility var(--t-ui); }
  .sidebar.open { transform: none; visibility: visible; }
  .sidebar-head .close-menu { display: inline-flex; }
  .nav-item { height: 44px; }
  .topbar { grid-template-columns: auto 1fr auto; padding: 0 16px 0 4px; gap: 8px; background: var(--ground); }
  .topbar .menu-toggle { display: inline-flex; width: 44px; height: 44px; }
  .topbar-title { display: block; font-weight: 600; font-size: 16px; }
  .global-search { display: none; }
  .top-right { grid-column: auto; }
  .top-right .stamp { display: none; }
  .sheet { grid-column: 1; margin: 0; border: 0; border-radius: 0; }
  .canvas { padding: 16px; }
  .title-row { flex-wrap: wrap; align-items: flex-start; }
  .mobile-only { display: block; }
  .search-field { width: 100%; }
  .btn { min-height: 36px; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-panel { padding: 20px 16px; }
  .auth-body { padding: 24px 0; max-width: none; }
  .auth-art { order: -1; padding: 16px 16px 0; display: none; }
  .report-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .kpis { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { padding: 12px 16px; }
  .kpi + .kpi { border-left: 0; }
  .kpi:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .kpi:nth-child(2n) { border-left: 1px solid var(--border); }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .tabs-row { overflow-x: auto; }

  /* tables become two-line rows: identity and key number first, the rest as a grey line, the action last */
  table.stack thead { display: none; }
  table.stack, table.stack tbody { display: block; }
  table.stack tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 12px 0; border-top: 1px solid var(--rule); }
  table.stack tr:first-child { border-top: 0; }
  table.stack td { display: block; height: auto; padding: 0; border: 0; }
  table.stack td.id { flex: 1 1 58%; min-width: 0; }
  table.stack td.key { flex: none; text-align: right; }
  table.stack td.meta { font-size: 13px; color: var(--muted); }
  table.stack td.meta:empty { display: none; }
  table.stack td.act { width: auto; margin-left: auto; }
  table.stack td.hide-phone { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; }
}
