/* Rental invoicing: design tokens, app shell and components. No external fonts or assets (CSP: own files only). */

:root {
  color-scheme: light;
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f8f9fb; --surface-3: #eef0f4;
  --border: #e3e6ec; --border-strong: #cfd4dd;
  --text: #0f1729; --text-2: #46526a; --text-3: #6b7489;
  --brand: #4338ca; --brand-soft: #eef0ff; --brand-ring: rgba(67, 56, 202, .22);
  --fill: #4338ca; --fill-hover: #3730a3; --fill-ink: #ffffff;
  --ok: #067647; --ok-bg: #ecfdf3; --ok-line: #abefc6;
  --warn: #b54708; --warn-bg: #fffaeb; --warn-line: #fedf89;
  --danger: #c0271d; --danger-bg: #fef3f2; --danger-line: #fecdca;
  --info: #175cd3; --info-bg: #eff8ff; --info-line: #b2ddff;
  --side-bg: #111735; --side-text: #c6cbe0; --side-muted: #8c93b3; --side-active: rgba(255, 255, 255, .09); --side-line: rgba(255, 255, 255, .08);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 20px 24px -4px rgba(16, 24, 40, .1), 0 8px 8px -4px rgba(16, 24, 40, .04);
  --radius: 12px; --radius-sm: 8px;
  --font: Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font: 14px/1.5 var(--font); color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0a0e1a; --surface: #111728; --surface-2: #161d31; --surface-3: #1d253b;
    --border: #232c43; --border-strong: #313b55;
    --text: #e7eaf3; --text-2: #a9b1c7; --text-3: #7e879f;
    --brand: #8b93ff; --brand-soft: rgba(139, 147, 255, .14); --brand-ring: rgba(139, 147, 255, .3);
    --fill: #4f46e5; --fill-hover: #5b54f0; --fill-ink: #ffffff;
    --ok: #4ade80; --ok-bg: rgba(74, 222, 128, .1); --ok-line: rgba(74, 222, 128, .3);
    --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, .1); --warn-line: rgba(251, 191, 36, .3);
    --danger: #f87171; --danger-bg: rgba(248, 113, 113, .1); --danger-line: rgba(248, 113, 113, .32);
    --info: #60a5fa; --info-bg: rgba(96, 165, 250, .1); --info-line: rgba(96, 165, 250, .3);
    --side-bg: #0d1224; --side-line: rgba(255, 255, 255, .06);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow-md: 0 4px 10px rgba(0, 0, 0, .35); --shadow-lg: 0 20px 40px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); min-height: 100vh; }
h1, h2, h3, p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.icon { flex: none; display: block; }
.num, .money { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.block { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 20px 14px;
  background: var(--side-bg); color: var(--side-text); }
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 22px; color: #fff; text-decoration: none; border-radius: var(--radius-sm); }
a.brand:hover { text-decoration: none; opacity: .92; }
.brand small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 170px; }
.brand strong { display: block; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.brand small { display: block; color: var(--side-muted); font-size: 12px; }
.logo .logo-bg { fill: #5b5ff0; } .logo .logo-sheet { fill: #fff; } .logo .logo-ink { fill: none; stroke: #5b5ff0; stroke-width: 1.6; stroke-linecap: round; }
.side-label { padding: 6px 12px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--side-muted); }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a, .side-foot button { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--side-text); font-weight: 500; text-decoration: none; transition: background .15s, color .15s; }
.side-nav a:hover, .side-foot button:hover { background: var(--side-active); color: #fff; }
.side-nav a[aria-current="page"] { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #8b93ff; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--side-line); }
.profile { display: flex; align-items: center; gap: 10px; padding: 8px 6px 8px 8px; border-radius: var(--radius-sm); background: rgba(255, 255, 255, .04); }
.profile .avatar { width: 34px; height: 34px; border-radius: 50%; background: #5b5ff0; color: #fff; }
.profile-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.profile-text strong { color: #fff; font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-text small { color: var(--side-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .profile-out { flex: none; width: 32px; height: 32px; padding: 0; justify-content: center; background: none; border: 0; box-shadow: none;
  color: var(--side-muted); border-radius: 8px; cursor: pointer; }
.side-foot .profile-out:hover { background: var(--side-active); color: #fff; }

/* Footer and the main column. */
.main-col { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }
.main-col > .content { flex: 1; }
.app-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px; margin: 0 40px; padding: 18px 0 24px;
  border-top: 1px solid var(--border); color: var(--text-3); font-size: 12.5px; max-width: 1200px; }  /* the content's width inside its padding */
.app-footer a { color: var(--text-2); font-weight: 550; }

/* Profile menu in the phone top bar. */
.profile-menu { position: relative; }
.profile-menu > summary { list-style: none; cursor: pointer; border-radius: 50%; }
.profile-menu > summary::-webkit-details-marker { display: none; }
.profile-menu > summary .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--fill); color: var(--fill-ink); }
.menu-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; width: 250px; padding: 6px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-lg); }
.menu-panel a, .menu-panel button { display: flex; align-items: center; gap: 10px; width: 100%; height: 38px; padding: 0 10px; border: 0; border-radius: 8px;
  background: none; box-shadow: none; color: var(--text); font: inherit; font-weight: 520; text-decoration: none; justify-content: flex-start; cursor: pointer; }
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-3); text-decoration: none; }
.menu-panel .menu-signout { color: var(--danger); }
.menu-who { display: flex; align-items: center; gap: 10px; padding: 8px 10px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.menu-who .avatar { width: 36px; height: 36px; border-radius: 50%; }
.menu-who .profile-text strong { color: var(--text); } .menu-who .profile-text small { color: var(--text-3); }

.content { width: 100%; max-width: 1280px; padding: 32px 40px 72px; }
.topbar, .tabbar { display: none; }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar { display: none; }
  .topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px 16px;
    background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
  .topbar .brand { padding: 0; margin-right: auto; color: var(--text); gap: 10px; }
  .topbar .brand strong { font-size: 15px; font-weight: 650; }
  .topbar .brand small { color: var(--text-3); font-size: 11.5px; max-width: 220px; }
  .app-footer { margin: 0 16px; padding: 16px 0 100px; justify-content: center; text-align: center; }
  .tabbar { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; border-radius: var(--radius-sm);
    color: var(--text-3); font-size: 11.5px; font-weight: 550; text-decoration: none; }
  .tabbar a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }
  .content { padding: 20px 16px 104px; }
}

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head h1 { font-size: 24px; line-height: 1.25; font-weight: 680; letter-spacing: -.02em; }
.page-head p { margin-top: 4px; color: var(--text-3); }
.page-head .actions { margin: 0; }
.page-head .actions select { width: auto; min-width: 170px; }
.crumbs { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; color: var(--text-3); font-size: 13px; }
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--text); }
@media (max-width: 640px) {
  .page-head h1 { font-size: 21px; }
  .page-head > .actions { width: 100%; }
  .page-head > .actions > * { flex: 1 1 auto; }
  .page-head .segmented { width: 100%; } .page-head .segmented button { flex: 1; }
}

/* ---------- Buttons ---------- */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  font: inherit; font-weight: 580; line-height: 1; white-space: nowrap; cursor: pointer; text-decoration: none;
  border-radius: var(--radius-sm); border: 1px solid var(--fill); background: var(--fill); color: var(--fill-ink);
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, color .15s, box-shadow .15s; }
button:hover, .button:hover { background: var(--fill-hover); border-color: var(--fill-hover); text-decoration: none; }
button.secondary, .button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-2); box-shadow: none; }
button.ghost:hover { background: var(--surface-3); color: var(--text); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger:hover { filter: brightness(.94); background: var(--danger); }
button.danger-ghost { background: transparent; border-color: transparent; color: var(--danger); box-shadow: none; }
button.danger-ghost:hover { background: var(--danger-bg); }
button.small, .button.small { height: 30px; padding: 0 10px; font-size: 13px; gap: 6px; }
button.large { height: 44px; padding: 0 18px; font-size: 15px; }
button.block { width: 100%; }
button.icon-only { width: 32px; padding: 0; }
button.icon-only.small { width: 30px; }
button.link { height: auto; padding: 0; border: 0; background: none; box-shadow: none; color: var(--brand); font-weight: 550; }
button:disabled { opacity: .55; cursor: not-allowed; }
button.loading { position: relative; color: transparent !important; }
button.loading::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--fill-ink) var(--fill-ink) transparent transparent; animation: spin .7s linear infinite; }
button.secondary.loading::after { border-color: var(--text-2) var(--text-2) transparent transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions.end { justify-content: flex-end; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card + .card { margin-top: 20px; }
.stats > .card + .card, .cards > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; font-weight: 650; }
.card-head p { color: var(--text-3); font-size: 13px; margin-top: 2px; }
.card-body { padding: 20px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { position: relative; padding: 18px 20px; }
.stat .stat-label { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; font-weight: 550; }
.stat .stat-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); }
.stat .stat-icon.ok { background: var(--ok-bg); color: var(--ok); }
.stat .stat-icon.warn { background: var(--warn-bg); color: var(--warn); }
.stat .stat-icon.info { background: var(--info-bg); color: var(--info); }
.stat .stat-value { margin-top: 12px; font-size: 24px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .stat-meta { margin-top: 2px; color: var(--text-3); font-size: 12.5px; }
.stat-summary { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; padding: 18px 20px; }
.stat-summary > div:nth-child(2) { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.stat-summary strong { font-size: 15px; font-weight: 650; }
.stat-summary .stat-icon { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); }
.stat-summary .stat-icon.warn { background: var(--warn-bg); color: var(--warn); }
.stat-summary .stat-total { text-align: right; }
.stat-summary .stat-value { font-size: 22px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 560px) { .stat-summary { flex-wrap: wrap; } .stat-summary .stat-total { width: 100%; text-align: left; } }
@media (max-width: 640px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 14px; }
  .stat .stat-value { margin-top: 10px; font-size: 18px; }
}

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 999px; white-space: nowrap;
  font-size: 12px; font-weight: 580; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.pill.plain::before { display: none; }
.pill.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.danger { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-line); }
.pill.info { color: var(--info); background: var(--info-bg); border-color: var(--info-line); }
.pill.brand { color: var(--brand); background: var(--brand-soft); border-color: transparent; }

/* ---------- Alerts and toasts ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 20px; border-radius: 10px;
  border: 1px solid var(--danger-line); background: var(--danger-bg); color: var(--text); }
.alert[hidden] { display: none; }
.alert > .icon { margin-top: 1px; color: var(--danger); }
.alert.warn { border-color: var(--warn-line); background: var(--warn-bg); } .alert.warn > .icon { color: var(--warn); }
.alert.info { border-color: var(--info-line); background: var(--info-bg); } .alert.info > .icon { color: var(--info); }
.alert.ok { border-color: var(--ok-line); background: var(--ok-bg); } .alert.ok > .icon { color: var(--ok); }
.alert strong { display: block; font-weight: 620; }
.alert ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); }
.alert p + p { margin-top: 2px; }
.alert .alert-body { flex: 1; min-width: 0; }
.toasts { position: fixed; z-index: 60; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-lg); font-weight: 550; animation: toast-in .2s ease-out; }
.toast .icon { color: #4ade80; }
.toast.error .icon { color: #f87171; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 900px) { .toasts { right: 16px; left: 16px; bottom: 84px; max-width: none; } }

/* ---------- Forms ---------- */
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.fields.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full, .fields > .full { grid-column: 1 / -1; }
.field .label { font-size: 13px; font-weight: 580; color: var(--text-2); }
.field .hint { font-size: 12.5px; color: var(--text-3); }
@media (max-width: 720px) { .fields, .fields.three { grid-template-columns: minmax(0, 1fr); } }
input, select, textarea { width: 100%; height: 38px; padding: 0 12px; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; padding: 9px 12px; resize: vertical; line-height: 1.5; }
select { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 16px, calc(100% - 12px) 16px; background-size: 5px 5px; background-repeat: no-repeat; }
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: .8; }
/* Browser-filled fields keep the theme's colours instead of the browser's yellow. */
input:-webkit-autofill, input:-webkit-autofill:hover { -webkit-text-fill-color: var(--text); caret-color: var(--text);
  box-shadow: 0 0 0 1000px var(--surface) inset, var(--shadow-sm); transition: background-color 600000s 0s, color 600000s 0s; }
input:-webkit-autofill:focus { -webkit-text-fill-color: var(--text); box-shadow: 0 0 0 1000px var(--surface) inset, 0 0 0 4px var(--brand-ring); }
input[type=file] { height: auto; padding: 8px; border-style: dashed; box-shadow: none; cursor: pointer; }
input[type=file]::file-selector-button { font: inherit; font-weight: 580; margin-right: 12px; height: 30px; padding: 0 12px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface-2); color: var(--text); }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon > input { padding-left: 38px; }
.input-icon > button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.input-icon.has-button > input { padding-right: 44px; }

.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.field.invalid input:focus, .field.invalid select:focus, .field.invalid textarea:focus { box-shadow: 0 0 0 4px var(--danger-bg); }
.field-error { display: flex; align-items: center; gap: 5px; color: var(--danger); font-size: 12.5px; font-weight: 550; }
.row-edit .field-error { white-space: normal; }

/* Toggle switch: a checkbox styled as a switch, with its label and hint beside it. */
.toggle { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.toggle .toggle-text { display: flex; flex-direction: column; gap: 2px; }
.toggle .toggle-text strong { font-weight: 580; font-size: 13.5px; }
.toggle .toggle-text small { color: var(--text-3); font-size: 12.5px; }
input[type=checkbox].switch { appearance: none; flex: none; width: 38px; height: 22px; padding: 0; margin: 0; border-radius: 999px; cursor: pointer;
  border: 0; background: var(--border-strong); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .04); position: relative; transition: background .15s; }
input[type=checkbox].switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .15s; }
input[type=checkbox].switch:checked { background: var(--fill); }
input[type=checkbox].switch:checked::after { transform: translateX(16px); }
input[type=checkbox].switch:focus { box-shadow: 0 0 0 4px var(--brand-ring); }
input[type=checkbox]:not(.switch) { width: 16px; height: 16px; padding: 0; accent-color: var(--brand); box-shadow: none; }

/* Sectioned forms: a sticky list of sections beside the form cards, and a sticky save bar. */
.with-aside { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 32px; align-items: start; }
.section-nav { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 2px; }
.section-nav button { justify-content: flex-start; height: 34px; padding: 0 10px; gap: 9px; background: none; border: 0; box-shadow: none;
  color: var(--text-2); font-weight: 520; }
.section-nav button:hover { background: var(--surface-3); color: var(--text); }
.section-nav button.current { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); outline: 1px solid var(--border); }
.form-section { scroll-margin-top: 24px; }
.form-section .card-head { align-items: flex-start; justify-content: flex-start; }
.form-section .card-head .head-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--brand-soft); color: var(--brand); }
.savebar { position: sticky; bottom: 16px; z-index: 10; display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 20px;
  padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); box-shadow: var(--shadow-md); }
.savebar .dirty { margin-right: auto; display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 13px; }
.savebar .dirty.on { color: var(--warn); }
@media (max-width: 900px) { .with-aside { grid-template-columns: minmax(0, 1fr); } .section-nav { display: none; } .savebar { bottom: 80px; } }
@media (max-width: 640px) { .savebar .dirty:not(.on) { display: none; } .savebar .dirty.on { flex-basis: 100%; } .savebar { flex-wrap: wrap; } .savebar > .button, .savebar > button { flex: 1; } }

/* Signature preview: a white card so dark ink shows in both themes. */
.sig-preview { display: flex; align-items: center; justify-content: center; min-height: 112px; margin-bottom: 16px; padding: 14px;
  border: 1px dashed var(--border-strong); border-radius: 10px; background: var(--surface-2); text-align: center; }
.sig-preview figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sig-preview img { max-height: 90px; max-width: 100%; padding: 8px 14px; border-radius: 8px; background: #fff; box-shadow: var(--shadow-sm); }

/* Placeholder chips. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chips code { padding: 2px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.card-body > .actions, .card-body > .rows + .actions { margin-top: 14px; }
.hint { color: var(--text-3); font-size: 12.5px; }
p.hint.subsection { margin-bottom: 18px; }

/* Editable rows (extra charges, number series). */
.subsection { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border); }
.subsection > .label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 620; color: var(--text-2); }
.rows { display: flex; flex-direction: column; gap: 10px; }
.row-edit { display: grid; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.row-edit.charge { grid-template-columns: minmax(0, 1fr) 110px 150px auto; }
.row-edit.series { grid-template-columns: 90px minmax(0, 1fr) 120px 120px auto auto; }
.row-edit .example { grid-column: 1 / -1; margin-top: -2px; font-size: 12.5px; color: var(--text-3); }
.row-edit .example strong { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.row-edit label.check { display: flex; align-items: center; gap: 8px; height: 38px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
@media (max-width: 720px) { .row-edit.charge, .row-edit.series { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .row-edit .field:first-child, .row-edit.series .field:nth-child(2) { grid-column: 1 / -1; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
.data th { position: sticky; top: 0; padding: 10px 16px; text-align: left; white-space: nowrap; font-size: 12px; font-weight: 620;
  letter-spacing: .03em; text-transform: uppercase; color: var(--text-3); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.data td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr:hover td { background: var(--surface-2); }
.data .num { text-align: right; white-space: nowrap; }
.data th.num { text-align: right; }
.data tr.credit td { color: var(--text-2); }
.data tr.credit .doc { padding-left: 22px; position: relative; }
.data tr.credit .doc::before { content: ""; position: absolute; left: 6px; top: 2px; width: 9px; height: 10px; border-left: 1.5px solid var(--border-strong); border-bottom: 1.5px solid var(--border-strong); border-bottom-left-radius: 4px; }
.data tfoot td { padding: 13px 16px; font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border); }
.data .neg { color: var(--danger); }
.doc strong { font-weight: 620; white-space: nowrap; }
.data td.nowrap, .data .doc small { white-space: nowrap; }
.data .doc .tenant { display: block; max-width: 340px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-size: 13px; }
.doc small, .sub { display: block; color: var(--text-3); font-size: 12.5px; }
@media (max-width: 760px) {
  table.data.stack thead { display: none; }
  table.data.stack, .data.stack tbody, .data.stack tfoot, .data.stack tr, .data.stack td { display: block; }
  .data.stack tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .data.stack td { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; border: 0; text-align: right; }
  .data.stack td::before { content: attr(data-label); color: var(--text-3); font-size: 12.5px; text-align: left; }
  .data.stack td.lead { display: block; text-align: left; padding-bottom: 6px; }
  .data.stack td.lead::before { display: none; }
  .data.stack tbody tr:hover td { background: none; }
  .data.stack tfoot tr { background: var(--surface-2); }
  .data.stack td.hide-sm { display: none; }
  .data.stack .doc small, .data.stack .doc .tenant { white-space: normal; max-width: none; }
  .toolbar select { flex: 1 1 140px; min-width: 0; }
}

/* ---------- Payments ---------- */
.modal-body .fields.pay-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 560px) { .modal-body .fields.pay-form { grid-template-columns: minmax(0, 1fr); } }
.pay-section { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.pay-section > .label { font-size: 12px; font-weight: 620; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }
.pay-list { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.pay-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; font-size: 13.5px; }
.pay-row + .pay-row { border-top: 1px solid var(--border); }
.pay-row strong { font-variant-numeric: tabular-nums; }
.pay-row .sub { display: inline; margin-left: 6px; }
.pay-row > .sub { margin: 0; }
.inv-meta .pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.status-pills { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
@media (max-width: 760px) { .status-pills { align-items: flex-end; } }
.inv-meta .pills .pill { margin-top: 0; }
.inv-meta .pills.first { margin: 0 0 2px; }

/* ---------- Tenancy invoices ---------- */
.tenancy-invoices { margin-bottom: 24px; }
.card-foot { display: flex; justify-content: center; padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---------- Activity ---------- */
.activity td.details { min-width: 320px; }
.activity td.details strong { display: block; font-weight: 620; }
.changes { margin-top: 6px; }
.changes summary { cursor: pointer; color: var(--brand); font-size: 12.5px; font-weight: 580; width: fit-content; }
.changes dl { margin: 8px 0 0; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); font-size: 12.5px; }
.changes dl > div { display: grid; grid-template-columns: minmax(120px, 30%) 1fr; gap: 10px; padding: 4px 0; }
.changes dl > div + div { border-top: 1px dashed var(--border); }
.changes dt { color: var(--text-3); }
.changes dd { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; word-break: break-word; }
.changes del { color: var(--danger); text-decoration: line-through; }
.changes ins { color: var(--ok); text-decoration: none; font-weight: 580; }
.changes em { color: var(--text-3); }
@media (max-width: 760px) { .activity td.details { min-width: 0; display: block; text-align: left; } .activity td.details::before { display: block; margin-bottom: 2px; } .changes dl > div { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- Toolbar, segmented control ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .grow { flex: 1 1 240px; }
.toolbar select { width: auto; min-width: 150px; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border); }
.segmented button { height: 30px; padding: 0 12px; border: 0; background: transparent; color: var(--text-2); box-shadow: none; font-weight: 560; }
.segmented button:hover { background: transparent; color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented .count { min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px; font-size: 11.5px; line-height: 18px; background: var(--surface-3); color: var(--text-2); }

/* ---------- Overview tenancy rows ---------- */
.tenancy-rows > li { list-style: none; display: grid; grid-template-columns: minmax(240px, 1.5fr) minmax(190px, 1fr) minmax(150px, .8fr) auto;
  align-items: center; gap: 16px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.tenancy-rows { margin: 0; padding: 0; }
.tenancy-rows > li:last-child { border-bottom: 0; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who strong { display: block; font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { display: block; color: var(--text-3); font-size: 12.5px; }
.who > div { min-width: 0; }
.avatar { display: grid; place-items: center; flex: none; width: 38px; height: 38px; border-radius: 10px; font-size: 13px; font-weight: 700;
  background: var(--brand-soft); color: var(--brand); letter-spacing: .02em; }
.avatar.c1 { background: var(--info-bg); color: var(--info); } .avatar.c2 { background: var(--ok-bg); color: var(--ok); } .avatar.c3 { background: var(--warn-bg); color: var(--warn); }
.amounts { text-align: right; }
.amounts strong { display: block; font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }
.amounts small { color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.inv-meta strong { font-weight: 620; font-variant-numeric: tabular-nums; }
.inv-meta .sub { margin-top: 2px; }
.inv-meta .pill { margin-top: 6px; }
/* Wide screens: every row shares one set of columns, so names get the room and the columns line up across rows. */
@media (min-width: 1101px) {
  .tenancy-rows { display: grid; grid-template-columns: minmax(220px, 2fr) minmax(170px, 1fr) max-content max-content; }
  .tenancy-rows > li { grid-column: 1 / -1; grid-template-columns: subgrid; }
}
@media (max-width: 1100px) {
  .tenancy-rows > li { grid-template-columns: minmax(0, 1fr) auto; }
  .tenancy-rows .who { grid-column: 1 / -1; }
  .tenancy-rows .inv-meta { grid-column: 1; } .tenancy-rows .amounts { grid-column: 2; grid-row: 2; }
  .tenancy-rows .row-actions { grid-column: 1 / -1; }
}
@media (max-width: 560px) { .tenancy-rows > li { padding: 16px; } .row-actions button { flex: 1; } }

/* ---------- Tenancy cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
a.tcard { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px; color: var(--text); text-decoration: none;
  transition: border-color .15s, box-shadow .15s, transform .15s; }
a.tcard:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); text-decoration: none; transform: translateY(-1px); }
a.tcard.inactive { opacity: .7; }
.tcard .who strong { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tcard .rent { font-size: 22px; font-weight: 680; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tcard .rent small { font-size: 13px; font-weight: 500; color: var(--text-3); letter-spacing: 0; }
.tcard dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.tcard dt { color: var(--text-3); } .tcard dd { margin: 0; text-align: right; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tcard .tags { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---------- Empty and loading states ---------- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 56px 24px; text-align: center; }
.empty .empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 6px; border-radius: 14px;
  background: var(--brand-soft); color: var(--brand); }
.empty h2 { font-size: 16px; font-weight: 650; }
.empty p { max-width: 420px; color: var(--text-3); }
.empty .actions { margin-top: 10px; justify-content: center; }
.loading-page { display: flex; align-items: center; gap: 10px; padding: 48px 0; color: var(--text-3); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--brand); animation: spin .7s linear infinite; }

/* ---------- Dialogs ---------- */
dialog.modal { width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface);
  color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal[open] { animation: modal-in .18s ease-out; }
dialog.modal::backdrop { background: rgba(10, 14, 26, .5); backdrop-filter: blur(2px); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 22px 24px 0; }
.modal-head .modal-icon { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); }
.modal-head .modal-icon.danger { background: var(--danger-bg); color: var(--danger); }
.modal-head .modal-icon.warn { background: var(--warn-bg); color: var(--warn); }
.modal-head h2 { font-size: 17px; font-weight: 650; line-height: 1.35; }
.modal-head p { margin-top: 4px; color: var(--text-2); }
.modal-body { padding: 18px 24px 4px; }
.modal-body .fields { grid-template-columns: minmax(0, 1fr); gap: 14px; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 20px 24px 22px; }
.modal-foot .left { margin-right: auto; }
.facts { margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.facts > div { display: flex; justify-content: space-between; gap: 16px; padding: 9px 14px; font-size: 13.5px; }
.facts > div + div { border-top: 1px solid var(--border); }
.facts dt { color: var(--text-3); } .facts dd { margin: 0; font-weight: 560; text-align: right; font-variant-numeric: tabular-nums; }
.facts > div.total { background: var(--surface-2); } .facts > div.total dd { font-weight: 700; }
.note { margin-top: 12px; color: var(--text-3); font-size: 12.5px; }

/* ---------- Sign in ---------- */
.auth { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); min-height: 100vh; }
.auth-side { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 44px 56px; color: #e8eaff;
  background: radial-gradient(1200px 600px at -10% -20%, #3b3fd8 0%, transparent 60%), radial-gradient(900px 600px at 120% 120%, #1e1b6b 0%, transparent 55%), #12164a; }
.auth-side::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .5;
  background-image: linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
  background-size: 44px 44px; mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent); }
.auth-side > * { position: relative; z-index: 1; }
.auth-side .brand { padding: 0; }
.auth-side .auth-headline { max-width: 460px; font-size: 34px; line-height: 1.15; font-weight: 700; letter-spacing: -.025em; color: #fff; }
.auth-side .lede { max-width: 440px; margin-top: 14px; color: #b9bef0; font-size: 15px; }
.auth-points { display: flex; flex-direction: column; gap: 14px; margin: 32px 0 0; padding: 0; list-style: none; }
.auth-points li { display: flex; align-items: flex-start; gap: 12px; color: #d9dcff; }
.auth-points .icon-wrap { display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 8px; background: rgba(255, 255, 255, .1); color: #fff; }
.auth-points strong { display: block; color: #fff; font-weight: 600; }
.auth-points small { color: #aab0e6; font-size: 13px; }
.auth-foot { color: #8f95cf; font-size: 12.5px; }
.auth-main { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; padding: 40px 24px 0; background: var(--surface); }
.auth-main > .auth-form { margin: auto 0; }
.auth-main > .app-footer { width: 100%; max-width: none; margin: 0; justify-content: center; border-top: 0; padding: 24px 0 44px; text-align: center; }
.auth-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 18px; }
.auth-form .mobile-brand { display: none; }
.auth-form h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.auth-form .lede { color: var(--text-3); margin-top: 6px; }
.auth-form .alert { margin: 0; }
.auth-form .caps-warn:not([hidden]) { display: flex; align-items: center; gap: 5px; color: var(--warn); font-size: 12.5px; font-weight: 550; }
.auth-form .secure { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--text-3); font-size: 12.5px; }
@media (max-width: 900px) {
  .auth { grid-template-columns: minmax(0, 1fr); background: var(--bg); }
  .auth-side { display: none; }
  .auth-main { justify-content: flex-start; padding-top: 10vh; background: var(--bg); }
  .auth-main > .auth-form { margin: 0; }
  .auth-main > .app-footer { padding-bottom: 24px; }
  .auth-form { padding: 28px 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-md); }
  .auth-form .mobile-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
}
