/* EchoPMS application UI — derived from the marketing-site brand tokens.
   See BRAND.md for the source of these values and the design rationale. */

:root {
    --color-primary: #0b1a33;
    --color-accent: #2dd4bf;
    --color-accent-2: #0d9488;       /* slightly deeper teal — better contrast vs old #00a884 */
    --color-accent-soft: #ccfbf1;    /* light teal background */
    --color-bg: #ffffff;
    --color-section: #f6f8fb;        /* slightly cooler section background */
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-text-subtle: #94a3b8;
    --color-text-strong: #1e293b;
    --color-border: #e2e8f0;
    --color-border-strong: #cbd5e1;
    --color-danger: #dc2626;
    --color-danger-soft: #fee2e2;
    --color-warning: #f59e0b;
    --color-warning-soft: #fef3c7;
    --color-success: #16a34a;
    --color-success-soft: #dcfce7;
    --color-info: #2563eb;
    --color-info-soft: #dbeafe;

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;

    /* Type scale */
    --fs-xs: 0.78rem;
    --fs-sm: 0.875rem;
    --fs-base: 1rem;
    --fs-lg: 1.125rem;
    --fs-xl: 1.375rem;
    --fs-2xl: 1.75rem;
    --fs-3xl: 2.25rem;

    /* Spacing scale */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.5rem;
    --sp-6: 2rem;
    --sp-7: 3rem;

    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-full: 9999px;

    /* Multi-layer shadows for real depth */
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 12px 28px -4px rgba(15, 23, 42, 0.12), 0 4px 8px -2px rgba(15, 23, 42, 0.06);
    --shadow-focus: 0 0 0 3px rgba(45, 212, 191, 0.35);

    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;

    /* Aliases several components already ask for. They were only ever
       reached through `var(--x, #fallback)`, so those rules were pinned to
       a light value and stayed white whatever the theme. Defining them here
       is what lets the theme reach that markup. */
    --color-surface: var(--color-bg);
    --color-bg-soft: var(--color-section);
    --color-bg-hover: var(--color-border);
    --color-muted: var(--color-text-muted);

    /* Alert borders, which were hardcoded per variant. */
    --color-danger-border: #fecaca;
    --color-info-border: #bfdbfe;
    --color-success-border: #bbf7d0;
    --color-warning-border: #fde68a;
    --color-danger-text: #991b1b;
    --color-info-text: #1e40af;
    --color-success-text: #166534;
    --color-warning-text: #92400e;
}


/* ===================================================================
   THEMES
   ===================================================================
   Two independent axes, both set on <html>:

     data-theme  = "light" | "dark"   — the surface palette
     data-accent = "teal" | "blue" | "violet" | "amber" | "rose"
                                      — the brand colour

   They are independent on purpose: a dark surface with an amber accent
   is a combination somebody will want, and coupling them would mean
   ten palettes to maintain instead of two plus five.

   WHY ONLY TOKENS BELOW
     Everything here redefines variables already declared in :root and
     nothing else. A rule that sets a colour directly would apply in one
     theme and be missing from the other, which is exactly how a theme
     ends up with unreadable text in half its panels.

   NO data-theme AT ALL
     Falls back to the operating system via `prefers-color-scheme`, so a
     first visit matches the rest of the machine. An explicit
     data-theme always wins over the media query because the attribute
     selector below is more specific.
   ------------------------------------------------------------------ */

:root[data-theme="dark"] {
    --color-primary: #0f1b2d;
    --color-bg: #121821;          /* cards, menus, inputs            */
    --color-section: #0b1017;     /* page behind the cards           */
    --color-text: #e7edf5;
    --color-text-strong: #f5f8fc;
    --color-text-muted: #9aa8bb;
    --color-text-subtle: #6b7b90;
    --color-border: #243044;
    --color-border-strong: #33425c;

    /* Status colours lifted for contrast on a dark surface — the light
       values are too dark to read against #121821. The *-soft pairs
       become low-alpha tints rather than pale washes. */
    --color-danger: #f87171;
    --color-danger-soft: rgba(248, 113, 113, 0.16);
    --color-warning: #fbbf24;
    --color-warning-soft: rgba(251, 191, 36, 0.16);
    --color-success: #4ade80;
    --color-success-soft: rgba(74, 222, 128, 0.16);
    --color-info: #60a5fa;
    --color-info-soft: rgba(96, 165, 250, 0.16);

    /* Shadows read as haze on a dark background, so they go darker and
       tighter rather than lighter. */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.6), 0 4px 8px -2px rgba(0, 0, 0, 0.45);

    /* Alerts: the light scheme's deep text (#991b1b and friends) is barely
       legible on #121821, so the tinted background keeps a low alpha and
       the text takes the bright status colour instead. */
    --color-danger-border: rgba(248, 113, 113, 0.4);
    --color-info-border: rgba(96, 165, 250, 0.4);
    --color-success-border: rgba(74, 222, 128, 0.4);
    --color-warning-border: rgba(251, 191, 36, 0.4);
    --color-danger-text: #fca5a5;
    --color-info-text: #93c5fd;
    --color-success-text: #86efac;
    --color-warning-text: #fcd34d;

    color-scheme: dark;           /* native scrollbars, form controls */
}

/* Follow the OS when the user has not chosen. Guarded on :not([data-theme])
   so an explicit light choice is never overridden by a dark OS. */
@media (prefers-color-scheme: dark) {
    /* Generated from the :root[data-theme="dark"] block above — the two
       must carry the same tokens or "Match my device" gives a half-dark
       page. `test_the_os_fallback_mirrors_the_dark_block` holds them
       together; this is the copy it checks against. */
    :root:not([data-theme]) {
        --color-primary: #0f1b2d;
        --color-bg: #121821;          /* cards, menus, inputs            */
        --color-section: #0b1017;     /* page behind the cards           */
        --color-text: #e7edf5;
        --color-text-strong: #f5f8fc;
        --color-text-muted: #9aa8bb;
        --color-text-subtle: #6b7b90;
        --color-border: #243044;
        --color-border-strong: #33425c;

        /* Status colours lifted for contrast on a dark surface — the light
           values are too dark to read against #121821. The *-soft pairs
           become low-alpha tints rather than pale washes. */
        --color-danger: #f87171;
        --color-danger-soft: rgba(248, 113, 113, 0.16);
        --color-warning: #fbbf24;
        --color-warning-soft: rgba(251, 191, 36, 0.16);
        --color-success: #4ade80;
        --color-success-soft: rgba(74, 222, 128, 0.16);
        --color-info: #60a5fa;
        --color-info-soft: rgba(96, 165, 250, 0.16);

        /* Shadows read as haze on a dark background, so they go darker and
           tighter rather than lighter. */
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.6), 0 4px 8px -2px rgba(0, 0, 0, 0.45);

        /* Alerts: the light scheme's deep text (#991b1b and friends) is barely
           legible on #121821, so the tinted background keeps a low alpha and
           the text takes the bright status colour instead. */
        --color-danger-border: rgba(248, 113, 113, 0.4);
        --color-info-border: rgba(96, 165, 250, 0.4);
        --color-success-border: rgba(74, 222, 128, 0.4);
        --color-warning-border: rgba(251, 191, 36, 0.4);
        --color-danger-text: #fca5a5;
        --color-info-text: #93c5fd;
        --color-success-text: #86efac;
        --color-warning-text: #fcd34d;

        color-scheme: dark;           /* native scrollbars, form controls */
    }
}

/* --- Accent colours -------------------------------------------------
   `--color-accent` is the bright brand tone (highlights, focus rings),
   `--color-accent-2` the deeper one used for buttons and links, which
   must hold white text at 4.5:1. `--color-accent-soft` is the pale
   background wash, redefined per theme below so it stays a *wash* on
   both surfaces rather than a near-white block on dark.
   ------------------------------------------------------------------ */

:root[data-accent="blue"]   { --color-accent: #60a5fa; --color-accent-2: #2563eb; --color-accent-soft: #dbeafe; --shadow-focus: 0 0 0 3px rgba(96, 165, 250, 0.35); }
:root[data-accent="violet"] { --color-accent: #a78bfa; --color-accent-2: #7c3aed; --color-accent-soft: #ede9fe; --shadow-focus: 0 0 0 3px rgba(167, 139, 250, 0.35); }
:root[data-accent="amber"]  { --color-accent: #fbbf24; --color-accent-2: #b45309; --color-accent-soft: #fef3c7; --shadow-focus: 0 0 0 3px rgba(251, 191, 36, 0.35); }
:root[data-accent="rose"]   { --color-accent: #fb7185; --color-accent-2: #be123c; --color-accent-soft: #ffe4e6; --shadow-focus: 0 0 0 3px rgba(251, 113, 133, 0.35); }

/* The focus ring is the one token that has to track the accent as well as
   the theme: left at the teal default it would stay teal on an amber
   theme, which is the sort of detail that makes a theme look unfinished. */

/* On dark, the pale washes above would be near-white blocks. Tint the
   accent itself instead, so the wash stays a wash. */
:root[data-theme="dark"]                      { --color-accent-soft: rgba(45, 212, 191, 0.16); }
:root[data-theme="dark"][data-accent="blue"]   { --color-accent-soft: rgba(96, 165, 250, 0.16); }
:root[data-theme="dark"][data-accent="violet"] { --color-accent-soft: rgba(167, 139, 250, 0.16); }
:root[data-theme="dark"][data-accent="amber"]  { --color-accent-soft: rgba(251, 191, 36, 0.16); }
:root[data-theme="dark"][data-accent="rose"]   { --color-accent-soft: rgba(251, 113, 133, 0.16); }

/* The brighter accent carries buttons better on a dark surface; the
   deeper one goes muddy against #121821. */
:root[data-theme="dark"]                       { --color-accent-2: #14b8a6; }
:root[data-theme="dark"][data-accent="blue"]   { --color-accent-2: #3b82f6; }
:root[data-theme="dark"][data-accent="violet"] { --color-accent-2: #8b5cf6; }
:root[data-theme="dark"][data-accent="amber"]  { --color-accent-2: #d97706; }
:root[data-theme="dark"][data-accent="rose"]   { --color-accent-2: #e11d48; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme])                      { --color-accent-2: #14b8a6; --color-accent-soft: rgba(45, 212, 191, 0.16); }
    :root:not([data-theme])[data-accent="blue"]   { --color-accent-2: #3b82f6; --color-accent-soft: rgba(96, 165, 250, 0.16); }
    :root:not([data-theme])[data-accent="violet"] { --color-accent-2: #8b5cf6; --color-accent-soft: rgba(167, 139, 250, 0.16); }
    :root:not([data-theme])[data-accent="amber"]  { --color-accent-2: #d97706; --color-accent-soft: rgba(251, 191, 36, 0.16); }
    :root:not([data-theme])[data-accent="rose"]   { --color-accent-2: #e11d48; --color-accent-soft: rgba(251, 113, 133, 0.16); }
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-section);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

a { color: var(--color-accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* User-menu link inside the topbar dropdown.
   Slice 36 swept the old horizontal `.app-navbar` + all nav-recent / nav-dropdown
   variants — only `.nav-tools-link` survived the cut because the new topbar
   user dropdown still uses it. */
.nav-tools-link {
    display: flex; flex-direction: column;
    padding: 0.4rem 0.75rem 0.5rem;
    color: var(--color-text-strong);
    border-radius: 4px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.4rem; padding-bottom: 0.6rem;
}
.nav-tools-link:hover { background: var(--color-section); text-decoration: none; }
.nav-tools-link strong { color: var(--color-primary); font-size: 0.92rem; }
.nav-tools-link .muted { font-size: 0.78rem; }

/* Search auto-suggest dropdown — `position: fixed` so it escapes any
   stacking context (e.g. sticky topbar). JS sets `top`/`left`/`width`
   at runtime via `getBoundingClientRect()` on the search input. */
.search-suggest-panel {
    position: fixed;
    z-index: 100;
    min-width: 18rem; max-width: 28rem;
    background: var(--color-bg); color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.35rem 0;
    text-align: left;
}
.search-suggest-panel ul { list-style: none; padding: 0; margin: 0; }
.search-suggest-panel li + li { border-top: 1px solid var(--color-border); }
.search-suggest-panel a {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    color: var(--color-text); text-decoration: none;
    font-size: 0.82rem;
}
.search-suggest-panel li.highlighted a,
.search-suggest-panel a:hover { background: var(--color-section); text-decoration: none; }
.search-suggest-panel a strong { font-variant-numeric: tabular-nums; }
.search-suggest-panel a .section-tag { margin: 0; font-size: 0.65rem; padding: 0.1rem 0.35rem; flex-shrink: 0; }
.search-suggest-panel a .muted {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-suggest-empty {
    padding: 0.5rem 0.75rem; margin: 0;
    color: var(--color-text-muted); font-size: 0.82rem;
}

/* Reports index — grouped by entity (Tenants / Landlords / Properties). */
.reports-section + .reports-section { margin-top: 1.5rem; }
.reports-section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-strong);
    margin: 0 0 0.6rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--color-border);
    display: flex; align-items: baseline; gap: 0.6rem;
    font-weight: 700;
}
.reports-section-title .muted {
    text-transform: none; letter-spacing: 0; font-weight: 400;
    font-size: 0.82rem;
}
.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}
/* a.card already gives us color:inherit + hover-lift via the global card rule. */
.reports-grid a.card h3 { margin: 0.25rem 0 0; font-size: 1rem; color: var(--color-text-strong); }
.reports-grid a.card p { margin: 0.4rem 0 0; font-size: 0.9rem; }

/* Main content wrapper — fills the whole shell (everything to the right of
   the sidebar). Internal pages can self-constrain prose with `max-width: 64ch`
   on their own elements where needed. */
.app-main {
    margin: 0;
    padding: var(--sp-5);
    min-width: 0;
}

/* Page header */
.page-header {
    margin-bottom: var(--sp-5);
    padding-bottom: var(--sp-4);
    border-bottom: 1px solid var(--color-border);
}
.page-header h1 {
    font-size: var(--fs-2xl);
    margin: 0;
    font-weight: 700;
    color: var(--color-text-strong);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.page-header p {
    margin: var(--sp-2) 0 0;
    color: var(--color-text-muted);
    font-size: var(--fs-base);
    max-width: 64ch;
}

/* Section tag (small caps pill above page titles) */
.section-tag {
    display: inline-block;
    text-transform: uppercase;
    font-size: var(--fs-xs);
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--color-accent-2);
    background: var(--color-accent-soft);
    padding: 0.25rem 0.7rem;
    border-radius: var(--radius-full);
    margin-bottom: var(--sp-3);
}

/* Card */
.card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-5);
    transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.card h2 {
    font-size: var(--fs-lg);
    color: var(--color-text-strong);
    margin: 0 0 var(--sp-3);
    font-weight: 600;
    letter-spacing: -0.01em;
}
.card h3 { font-size: var(--fs-base); margin: 0 0 var(--sp-2); }
a.card { color: inherit; text-decoration: none; display: block; }
a.card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    text-decoration: none;
    border-color: var(--color-border-strong);
}

/* Tables */
.table-wrap {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}
.table-scroll { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-sm);
    /* Comfortable reading without wasting height. */
    line-height: 1.45;
}

/* A wide grid scrolls sideways rather than squeezing every column to an
   unreadable width — but only where a scrolling wrapper exists to
   contain it. On a grid without one the same min-width would push the
   whole PAGE sideways, which is worse than narrow columns. */
.table-wrap > .data-table,
.table-scroll > .data-table {
    min-width: 44rem;
}
.data-table th {
    background: var(--color-section);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: var(--fs-xs);
    font-weight: 700;
    text-align: left;
    padding: 0.7rem var(--sp-4);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    position: sticky;
    top: 0;
}
.data-table td {
    padding: 0.62rem var(--sp-4);
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-strong);
    vertical-align: top;
    overflow-wrap: anywhere;
}
.data-table tbody tr {
    transition: background var(--transition-fast);
}
.data-table tbody tr:nth-child(even) { background: rgba(246, 248, 251, 0.5); }
.data-table tbody tr:hover {
    background: var(--color-accent-soft);
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .muted { color: var(--color-text-muted); }
.data-table a { color: var(--color-accent-2); font-weight: 500; }
.data-table a strong { font-weight: 600; }

/* Pills (status badges) */
.pill {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    font-weight: 600;
    background: var(--color-accent-soft);
    color: var(--color-accent-2);
    letter-spacing: 0.01em;
}
.pill.inactive { background: rgba(148, 163, 184, 0.18); color: var(--color-text-muted); }
.pill.danger { background: var(--color-danger-soft); color: var(--color-danger); }
.pill.warning { background: var(--color-warning-soft); color: var(--color-warning-text); }
.pill.success { background: var(--color-success-soft); color: var(--color-success-text); }
.pill.info { background: var(--color-info-soft); color: var(--color-info-text); }

/* Empty / error states */
.empty {
    text-align: center;
    padding: var(--sp-6) var(--sp-4);
    color: var(--color-text-muted);
    font-style: italic;
    font-size: var(--fs-sm);
}
.alert-error, .alert-info, .alert-success, .alert-warning {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    font-size: var(--fs-sm);
    border: 1px solid transparent;
}
.alert-error   { background: var(--color-danger-soft);  border-color: var(--color-danger-border); color: var(--color-danger-text); }
.alert-info    { background: var(--color-info-soft);    border-color: var(--color-info-border); color: var(--color-info-text); }
.alert-success { background: var(--color-success-soft); border-color: var(--color-success-border); color: var(--color-success-text); }
.alert-warning { background: var(--color-warning-soft); border-color: var(--color-warning-border); color: var(--color-warning-text); }

/* Footer */
.app-footer {
    text-align: center;
    color: var(--color-text-subtle);
    font-size: var(--fs-xs);
    padding: var(--sp-6) var(--sp-4);
}
.app-footer a { color: var(--color-text-muted); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: var(--fs-sm);
    line-height: 1.25;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition-fast), border-color var(--transition-fast),
                box-shadow var(--transition-fast), transform var(--transition-fast),
                color var(--transition-fast);
    font-family: inherit;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--color-accent-2);
    color: #ffffff;
    border-color: var(--color-accent-2);
    box-shadow: 0 1px 2px rgba(13, 148, 136, 0.18);
}
.btn-primary:hover {
    background: #0f766e; border-color: #0f766e;
    text-decoration: none; color: #ffffff;
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.25);
}
/* Upload blocked until a document type is chosen (static/js/doc-type-gate.js). */
form[data-doc-type-gate] .btn:disabled,
form[data-doc-type-gate] .btn:disabled:hover {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    background: var(--color-accent-2);
    border-color: var(--color-accent-2);
}
form[data-doc-type-gate] input[type="file"]:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.btn-outline {
    background: var(--color-bg);
    color: var(--color-text-strong);
    border-color: var(--color-border-strong);
}
.btn-outline:hover {
    background: var(--color-section);
    border-color: var(--color-text-muted);
    text-decoration: none;
    color: var(--color-text-strong);
}
.btn-danger {
    background: var(--color-danger);
    color: #ffffff;
    border-color: var(--color-danger);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #ffffff; text-decoration: none; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: var(--fs-xs); }

/* Lifecycle "Add" page form (landlord / property / tenant create).
   Uses the same .profile-fs fieldset styling as inline edit forms — see
   templates/_includes/profile_form_fields.html. This block styles the
   page-level wrapper, top Identity card, and the sticky-feeling action bar. */
.lifecycle-page-form { max-width: 70rem; margin: 0 auto; }
.lifecycle-page-form .form-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
}
.lifecycle-page-form .form-card > .form-card__hint {
    margin: -0.2rem 0 0.8rem;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}
.lifecycle-page-form .form-card__title {
    margin: 0 0 0.6rem;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}
.lifecycle-page-form .form-row {
    display: grid;
    grid-template-columns: minmax(160px, 12rem) 1fr;
    gap: 0.55rem 1rem;
    align-items: center;
    margin-bottom: 0.55rem;
}
@media (max-width: 640px) {
    .lifecycle-page-form .form-row {
        grid-template-columns: 1fr;
        gap: 0.2rem;
    }
}
.lifecycle-page-form .form-row > label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
}
.required { color: var(--color-danger-text); margin-left: 0.15rem; font-weight: 600; }
.lifecycle-page-form .form-row > label .required { color: var(--color-danger-text); margin-left: 0.15rem; }
.lifecycle-page-form .form-row input[type="text"],
.lifecycle-page-form .form-row input[type="number"],
.lifecycle-page-form .form-row input[type="date"],
.lifecycle-page-form .form-row select {
    width: 100%;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--color-border);
    border-radius: 0.3rem;
    background: var(--color-bg);
    font: inherit;
}
.lifecycle-page-form .form-row input:focus,
.lifecycle-page-form .form-row select:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: -1px;
    border-color: var(--color-accent);
}
.lifecycle-page-form .form-row .entity-picker { width: 100%; }
.lifecycle-page-form .form-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    align-items: center;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(6px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 -2px 6px rgba(15, 23, 42, 0.05);
}
.lifecycle-page-form .form-actions .spacer { flex: 1; }
.lifecycle-page-form .form-actions .muted { font-size: 0.8rem; }

/* Filters bar above tables */
.filters {
    display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap;
    margin-bottom: var(--sp-4);
}
.filters input[type="search"],
.filters input[type="text"],
.filters input[type="number"],
.filters input[type="date"],
.filters select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    background: var(--color-bg);
    font-size: var(--fs-sm);
    font-family: inherit;
    color: var(--color-text-strong);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.filters input:focus, .filters select:focus {
    outline: none;
    border-color: var(--color-accent-2);
    box-shadow: var(--shadow-focus);
}
.filters .count { margin-left: auto; color: var(--color-text-muted); font-size: var(--fs-sm); }

/* Utility */
.muted { color: var(--color-text-muted); }
.spacer { flex: 1; }

/* ---------- Tablet & phone breakpoints ----------
   The big sidebar-drawer rule lives further down in the Slice-33 block;
   these media queries only carry bits the sidebar layout doesn't own. */
@media (max-width: 720px) {
    .search-suggest-panel {
        min-width: 14rem; max-width: calc(100vw - 2rem);
    }
}
@media (max-width: 860px) {
    .page-header h1 { font-size: 1.25rem; }
    .card { padding: 0.85rem 1rem; }
    .search-suggest-panel { max-width: calc(100vw - 1rem); }
    .filters { gap: 0.4rem; }
    .filters input[type="search"], .filters select { flex: 1 1 100%; }
    .filters .count { margin-left: 0; flex-basis: 100%; }
    .filters .btn { flex: 1 1 100%; }
}
@media (max-width: 480px) {
    .app-main { padding: 0 0.5rem; }
    .data-table { font-size: 0.82rem; }
    .data-table th, .data-table td { padding: 0.45rem 0.6rem; }
}


/* --- Markdown editor toolbar (used by data-md-editor textareas) --------- */
.md-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.3rem;
    padding: 0.25rem;
    border: 1px solid var(--color-border);
    border-bottom: none;
    border-radius: 0.4rem 0.4rem 0 0;
    background: var(--color-section);
}
.md-toolbar-btn {
    appearance: none;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    border-radius: 0.3rem;
    padding: 0.2rem 0.55rem;
    font-size: 0.85rem;
    line-height: 1;
    min-width: 2rem;
    font-weight: 600;
    cursor: pointer;
}
.md-toolbar-btn:hover { background: var(--color-section); border-color: var(--color-text-subtle); }
.md-toolbar-btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 1px; }
.md-toolbar-hint {
    margin-left: auto;
    color: var(--color-text-subtle);
    font-size: 0.72rem;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
}
textarea[data-md-editor] {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}
@media (max-width: 480px) {
    .md-toolbar-hint { display: none; }
}

/* --- Responsive list tables (.data-table--responsive) -------------------
   Mobile-first opt-in: list pages add this class and a `data-label="…"`
   on each <td>. Below 720px the table collapses into stacked cards where
   each cell renders as a label/value row. From 720px upwards it reverts
   to the standard `.data-table` look. Going-forward convention for any
   new list view in the directory. */

.data-table--responsive thead {
    /* Visually hide but keep accessible for screen readers. */
    border: 0;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
}
.data-table--responsive,
.data-table--responsive tbody,
.data-table--responsive tr,
.data-table--responsive td {
    display: block;
    width: 100%;
}
/* Card mode stacks each row, so the grid's min-width would only make the
   cards scroll sideways. It applies again above the breakpoint. */
.data-table--responsive,
.table-wrap > .data-table--responsive,
.table-scroll > .data-table--responsive { min-width: 0; }
.data-table--responsive tr {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    box-shadow: var(--shadow-sm);
    margin: 0 0 0.6rem;
    padding: 0.7rem 0.85rem;
}
.data-table--responsive tbody tr:hover { background: var(--color-bg); }
.data-table--responsive td {
    border-bottom: 0;
    padding: 0.25rem 0;
    display: flex;
    gap: 0.75rem;
    align-items: baseline;
    justify-content: space-between;
    word-break: break-word;
}
.data-table--responsive td::before {
    content: attr(data-label);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.66rem;
    font-weight: 700;
    flex: 0 0 6.5rem;
    align-self: flex-start;
    padding-top: 0.15rem;
}
.data-table--responsive td[data-label=""]::before,
.data-table--responsive td:not([data-label])::before {
    content: "";
    flex: 0;
}
.data-table--responsive td > * {
    text-align: right;
}
/* Action cell — let the buttons stack as a row, full width, with wrap. */
.data-table--responsive td[data-label=""] {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed var(--color-border);
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.4rem;
}
.data-table--responsive td[data-label=""] .btn { flex: 1 1 auto; }
/* First-cell heading: emphasise the primary code. */
.data-table--responsive tr > td:first-child {
    border-bottom: 1px solid var(--color-border);
    margin-bottom: 0.4rem;
    padding-bottom: 0.45rem;
    font-size: 1rem;
    font-weight: 700;
}
.data-table--responsive tr > td:first-child::before {
    /* Hide the redundant "Code" label — the value is large and obvious. */
    display: none;
}

@media (min-width: 720px) {
    .data-table--responsive thead {
        position: static;
        clip: auto; height: auto; width: auto;
        margin: 0; padding: 0; overflow: visible;
    }
    .data-table--responsive,
    .data-table--responsive tbody,
    .data-table--responsive tr,
    .data-table--responsive td {
        display: revert;
        width: auto;
    }
    .data-table--responsive { width: 100%; }
    .data-table--responsive tr {
        border: 0;
        border-radius: 0;
        margin: 0;
        padding: 0;
        background: transparent;
        box-shadow: none;
    }
    .data-table--responsive tbody tr:hover { background: var(--color-section); }
    .data-table--responsive td {
        border-bottom: 1px solid var(--color-border);
        padding: 0.55rem 0.9rem;
        display: table-cell;
        text-align: left;
    }
    .data-table--responsive td > * { text-align: inherit; }
    .data-table--responsive td::before { content: none; }
    .data-table--responsive td[data-label=""] {
        margin: 0; padding: 0.55rem 0.9rem; border-top: 0;
        white-space: nowrap;
    }
    .data-table--responsive tr > td:first-child {
        border-bottom: 1px solid var(--color-border);
        margin: 0; padding: 0.55rem 0.9rem;
        font-size: inherit; font-weight: inherit;
    }
}

/* Phones: a couple of extra niceties for the responsive list. */
@media (max-width: 480px) {
    .data-table--responsive tr { padding: 0.6rem 0.7rem; }
    .data-table--responsive td::before { flex-basis: 5.5rem; font-size: 0.62rem; }
    /* Hint scrolling area shouldn't double up — kill the outer overflow. */
    .table-wrap:has(.data-table--responsive) { overflow: visible; border: 0; box-shadow: none; background: transparent; }
}

/* Rendered note bodies (output of safe_markdown) — keep paragraph margins
   tight inside cards. */
.note-body p { margin: 0 0 0.4em; }
.note-body p:last-child { margin-bottom: 0; }
.note-body ul { margin: 0.2em 0 0.4em 1.2em; padding: 0; }
.note-body code {
    background: var(--color-section);
    padding: 0.05em 0.3em;
    border-radius: 0.2em;
    font-size: 0.9em;
}


/* --- Inline link-style buttons (used on note rows for Edit/Delete) ------ */
.btn-link {
    appearance: none;
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: var(--color-accent-2);
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    text-decoration: underline;
}
.btn-link:hover { color: var(--color-text-strong); }
.btn-link-danger { color: var(--color-danger); }
.btn-link-danger:hover { color: var(--color-danger-text); }

/* When `.btn-link` is layered on `.btn` (secondary action next to a primary
   button), keep the button's padding/shape rather than collapsing to a tiny
   inline link. Reads as a transparent ghost button. */
.btn.btn-link {
    padding: 0.55rem 1.1rem;
    font-size: var(--fs-sm);
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
}
.btn.btn-link:hover {
    background: var(--color-section);
    color: var(--color-text-strong);
    text-decoration: none;
}

/* --- Address form fields ----------------------------------------------- */
.address-field {
    display: flex;
    flex-direction: column;
    font-size: 0.78rem;
    gap: 0.2rem;
}
.address-field > span {
    color: var(--color-text-muted);
    font-weight: 600;
}
.address-field input,
.address-field select {
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.35rem 0.45rem;
    border: 1px solid var(--color-border);
    border-radius: 0.35rem;
    background: var(--color-bg);
}
.address-field input:focus,
.address-field select:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}
.address-field input:disabled,
.address-field input.input--disabled {
    background: var(--color-section);
    color: var(--color-text-muted);
    cursor: not-allowed;
}

/* --- Settings sortable tables ---------------------------------------- */
tbody[data-settings-sortable] tr[data-settings-row] {
    cursor: grab;
}
tbody[data-settings-sortable] tr[data-settings-row]:active {
    cursor: grabbing;
}
.settings-drag-handle {
    user-select: none;
    color: var(--color-text-subtle);
    font-size: 1rem;
    line-height: 1;
    width: 1.4rem;
    text-align: center;
}
tr.is-dragging {
    opacity: 0.4;
}
tr.is-drag-over td {
    border-top: 2px solid var(--color-accent);
}
.settings-sortable-status {
    margin: 0.4rem 0 0.6rem;
    font-size: 0.82rem;
    min-height: 1.2em;
}
.settings-sortable-status[data-kind="pending"] { color: var(--color-text-muted); }
.settings-sortable-status[data-kind="ok"]      { color: var(--color-accent-2); }
.settings-sortable-status[data-kind="error"]   { color: var(--color-danger); }
.settings-sortable-hint {
    color: var(--color-text-subtle);
    font-size: 0.78rem;
    margin: 0 0 0.4rem;
}

/* --- Entity picker (transaction forms) ------------------------------- */
.entity-picker {
    position: relative;
    display: block;
}
.entity-picker__row {
    display: flex;
    align-items: stretch;
    gap: 0;
}
.entity-picker__input {
    flex: 1 1 auto;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.35rem 0.45rem;
    border: 1px solid var(--color-border);
    border-radius: 0.35rem 0 0 0.35rem;
    border-right: none;
    background: var(--color-surface, #fff);
}
.entity-picker__input:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}
.entity-picker__list-btn {
    flex: 0 0 auto;
    padding: 0 0.55rem;
    border: 1px solid var(--color-border);
    border-radius: 0 0.35rem 0.35rem 0;
    background: var(--color-bg-soft, #f1f5f9);
    color: var(--color-text-strong, #0b1a33);
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
}
.entity-picker__list-btn:hover {
    background: var(--color-bg-hover, #e2e8f0);
}
.entity-picker__panel {
    /* Slice 41 — `position: fixed` + appended to <body> so the dropdown
       escapes any clipping/stacking context (sticky topbar, sticky table
       headers, overflow:auto containers). JS sets top/left/width on every
       show via getBoundingClientRect() on the visible input. */
    position: fixed;
    z-index: 100;
    max-height: 16rem;
    overflow-y: auto;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.entity-picker__panel ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.entity-picker__panel li {
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--color-border, #e2e8f0);
}
.entity-picker__panel li:last-child {
    border-bottom: none;
}
.entity-picker__panel li:hover,
.entity-picker__panel li.highlighted {
    background: var(--color-accent-soft, #e0e7ff);
}
.entity-picker__panel li strong {
    font-weight: 600;
}
.entity-picker__empty {
    margin: 0;
    padding: 0.5rem 0.6rem;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Directory pages use the picker as a wide search bar (navigate mode). */
.entity-picker.directory-picker {
    flex: 1 1 18rem;
    max-width: 36rem;
}

/* --- Numbered pager (shared `_includes/paginator.html`) ----------------- */
.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    margin: 0.75rem 0 0.25rem;
    font-size: 0.85rem;
}
.pager__info { color: var(--color-text-muted); }
.pager__info .muted { color: var(--color-text-muted); }
.pager__pages {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
}
.pager__link {
    display: inline-block;
    min-width: 1.85rem;
    padding: 0.3rem 0.55rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text-strong);
    text-align: center;
    text-decoration: none;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
}
.pager__link:hover { background: var(--color-section); border-color: var(--color-accent-2); }
/* Client-side pagers (e.g. the rent-demand routine grid) use <button> so a
   page change can't submit the surrounding form. Buttons don't inherit font. */
button.pager__link { font: inherit; cursor: pointer; }
.pager__link.is-current {
    background: var(--color-accent-2);
    border-color: var(--color-accent-2);
    color: #fff;
    font-weight: 600;
    cursor: default;
}
.pager__link--nav { padding-left: 0.6rem; padding-right: 0.6rem; }
.pager__link.is-disabled {
    color: var(--color-text-muted);
    background: var(--color-section);
    border-style: dashed;
    cursor: not-allowed;
}
.pager__ellipsis {
    display: inline-block;
    padding: 0.3rem 0.35rem;
    color: var(--color-text-muted);
}

/* --- Export menu (shared `_includes/export_menu.html`) ------------------ */
.export-menu {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    margin-left: 0.5rem;
    font-size: 0.78rem;
}
.export-menu__label { color: var(--color-text-muted); margin-right: 0.15rem; }
.export-menu__link {
    display: inline-block;
    padding: 0.2rem 0.45rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text-strong);
    text-decoration: none;
    font-variant: tabular-nums;
    line-height: 1.15;
}
.export-menu__link:hover {
    border-color: var(--color-accent-2);
    color: var(--color-accent-2);
}

/* --- Sortable column headings (shared `_includes/sort_header.html`) ----- */
.data-table th .sort-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px dotted transparent;
}
.data-table th .sort-link:hover { border-bottom-color: var(--color-accent-2); }
.data-table th .sort-link.is-active {
    color: var(--color-text-strong);
    border-bottom-color: var(--color-accent-2);
}
.data-table th .sort-arrow {
    font-size: 0.7em;
    color: var(--color-accent-2);
}
@media (max-width: 720px) {
    /* In stacked card mode the <thead> is hidden — sort links live in
       a separate "Sort by" select. The CSS still applies if any view
       opts in. */
    .pager { font-size: 0.8rem; }
    .pager__link { min-width: 1.5rem; padding: 0.25rem 0.45rem; }
}

/* ============================================================
   Slice 32 — modern dashboard / metric cards / quick actions
   ============================================================ */

/* Grid wrapper for metric cards on the dashboard */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
}

/* Metric card — used on the dashboard for KPIs */
.metric-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base), transform var(--transition-base),
                border-color var(--transition-base);
    color: inherit;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    position: relative;
    overflow: hidden;
    min-height: 8.5rem;
}
.metric-card::before {
    /* Decorative accent stripe on the left edge */
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--metric-accent, var(--color-accent-2));
    opacity: 0.85;
}
a.metric-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--color-border-strong);
    text-decoration: none;
    color: inherit;
}
.metric-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
}
.metric-card__label {
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: var(--color-text-muted);
}
.metric-card__icon {
    flex: 0 0 auto;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius);
    background: var(--metric-icon-bg, var(--color-accent-soft));
    color: var(--metric-icon-fg, var(--color-accent-2));
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.metric-card__icon svg { width: 1.35rem; height: 1.35rem; display: block; }
.metric-card__value {
    font-size: var(--fs-3xl);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.025em;
    color: var(--color-text-strong);
    font-variant-numeric: tabular-nums;
}
.metric-card__sub {
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
    margin-top: -0.2rem;
}
.metric-card__delta {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-success);
    background: var(--color-success-soft);
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-full);
}
.metric-card__delta--down { color: var(--color-danger); background: var(--color-danger-soft); }
.metric-card__list {
    list-style: none;
    margin: var(--sp-2) 0 0;
    padding: var(--sp-3) 0 0;
    border-top: 1px dashed var(--color-border);
    font-size: var(--fs-sm);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}
.metric-card__list li {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    align-items: baseline;
}
.metric-card__list li .muted { font-size: var(--fs-xs); }

/* Per-card accent variants — apply with `<a class="metric-card metric-card--danger">` */
.metric-card--danger { --metric-accent: var(--color-danger); --metric-icon-bg: var(--color-danger-soft); --metric-icon-fg: var(--color-danger); }
.metric-card--warning { --metric-accent: var(--color-warning); --metric-icon-bg: var(--color-warning-soft); --metric-icon-fg: #b45309; }
.metric-card--info { --metric-accent: var(--color-info); --metric-icon-bg: var(--color-info-soft); --metric-icon-fg: var(--color-info); }
.metric-card--success { --metric-accent: var(--color-success); --metric-icon-bg: var(--color-success-soft); --metric-icon-fg: var(--color-success); }
.metric-card--primary { --metric-accent: var(--color-primary); --metric-icon-bg: rgba(11, 26, 51, 0.08); --metric-icon-fg: var(--color-primary); }

/* Section heading (e.g. "Quick actions", "Recent activity") */
.section-heading {
    margin: var(--sp-6) 0 var(--sp-3);
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--sp-3);
}
.section-heading h2 {
    margin: 0; font-size: var(--fs-xl); font-weight: 700;
    color: var(--color-text-strong); letter-spacing: -0.015em;
}
.section-heading p {
    margin: 0; color: var(--color-text-muted); font-size: var(--fs-sm);
}

/* Quick-action grid (compact card-like buttons) */
.quick-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--sp-3);
    margin-bottom: var(--sp-5);
}
.quick-action {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text-strong);
    text-decoration: none;
    font-weight: 600;
    transition: background var(--transition-fast), border-color var(--transition-fast),
                transform var(--transition-fast);
}
.quick-action:hover {
    background: var(--color-section);
    border-color: var(--color-accent-2);
    color: var(--color-accent-2);
    text-decoration: none;
    transform: translateY(-1px);
}
.quick-action__icon {
    width: 2rem; height: 2rem;
    border-radius: var(--radius);
    background: var(--color-accent-soft);
    color: var(--color-accent-2);
    display: inline-flex; align-items: center; justify-content: center;
    flex: 0 0 auto;
}
.quick-action__icon svg { width: 1.1rem; height: 1.1rem; }
.quick-action__label { font-size: var(--fs-base); }
.quick-action__hint { font-size: var(--fs-xs); color: var(--color-text-muted); display: block; font-weight: 400; }

/* Sparkline / chart wrapper for dashboard analytics */
.chart-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
}
.chart-card h3 {
    margin: 0 0 var(--sp-3);
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--color-text-strong);
}
.chart-card svg { max-width: 100%; height: auto; display: block; }

/* Form-input fallback — make the default browser inputs feel consistent
   with the modernised filters bar (used everywhere we don't have a
   bespoke form layout class) */
input[type="text"], input[type="number"], input[type="date"],
input[type="email"], input[type="password"], input[type="search"],
input[type="tel"], input[type="url"],
textarea, select {
    font-family: inherit;
    font-size: var(--fs-sm);
    color: var(--color-text-strong);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--color-accent-2);
    box-shadow: var(--shadow-focus);
}

/* Tighter mobile typography (avoid the bigger base wrapping titles awkwardly) */
@media (max-width: 720px) {
    .page-header h1 { font-size: var(--fs-xl); }
    .metric-card__value { font-size: var(--fs-2xl); }
    .app-main { padding: 0 var(--sp-3); }
}

/* ============================================================
   Slice 33 — sidebar + topbar layout
   ============================================================ */

/* Layout grid: sidebar | shell. Sidebar is 16rem expanded, 4.5rem collapsed. */
.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w, 16rem) 1fr;
    min-height: 100vh;
    background: var(--color-section);
}
.app-layout--anon {
    display: block;
    background: var(--color-section);
}
html[data-sidebar-collapsed="1"] .app-layout {
    --sidebar-w: 4.5rem;
}

/* Sidebar shell */
.app-sidebar {
    grid-row: 1 / -1;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100vh;
    overflow-y: auto;
    background: var(--color-primary);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    transition: width var(--transition-base);
    z-index: 30;
}
.app-sidebar::-webkit-scrollbar { width: 6px; }
.app-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

.app-sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) var(--sp-4);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    gap: var(--sp-2);
}
.app-sidebar__logo {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    color: #fff;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
    text-decoration: none;
    flex: 1;
    min-width: 0;
}
.app-sidebar__logo img { width: 28px; height: 28px; flex-shrink: 0; }
.app-sidebar__brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-sidebar__collapse {
    background: transparent;
    border: 0;
    padding: 0.35rem;
    color: rgba(255,255,255,0.65);
    cursor: pointer;
    border-radius: var(--radius);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.app-sidebar__collapse:hover { background: rgba(255,255,255,0.08); color: #fff; }
.app-sidebar__collapse svg { transition: transform var(--transition-base); }
html[data-sidebar-collapsed="1"] .app-sidebar__collapse svg { transform: rotate(180deg); }

/* Navigation links */
.app-sidebar__nav {
    display: flex;
    flex-direction: column;
    padding: var(--sp-3) var(--sp-2);
    gap: 2px;
    flex: 1;
}
.sidenav-link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    color: #cbd5e1;
    font-weight: 500;
    text-decoration: none;
    font-size: var(--fs-sm);
    transition: background var(--transition-fast), color var(--transition-fast);
    position: relative;
    white-space: nowrap;
    overflow: hidden;
}
.sidenav-link__icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    color: rgba(203, 213, 225, 0.7);
    transition: color var(--transition-fast);
}
.sidenav-link__label {
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--transition-fast);
}
.sidenav-link:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
    text-decoration: none;
}
.sidenav-link:hover .sidenav-link__icon { color: #fff; }
.sidenav-link.is-active {
    background: rgba(45, 212, 191, 0.18);
    color: #fff;
}
.sidenav-link.is-active .sidenav-link__icon { color: var(--color-accent); }
.sidenav-link.is-active::before {
    content: "";
    position: absolute;
    left: -0.5rem;
    top: 0.4rem;
    bottom: 0.4rem;
    width: 3px;
    background: var(--color-accent);
    border-radius: 0 2px 2px 0;
}

.app-sidebar__recent {
    padding: var(--sp-3) var(--sp-3) var(--sp-4);
    border-top: 1px solid rgba(255,255,255,0.08);
}
.app-sidebar__section-title {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(203, 213, 225, 0.55);
    font-weight: 700;
    padding: 0 0.25rem;
}
.app-sidebar__recent ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.app-sidebar__recent a {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.4rem 0.5rem;
    border-radius: var(--radius);
    color: rgba(203, 213, 225, 0.85);
    text-decoration: none;
    font-size: var(--fs-xs);
    transition: background var(--transition-fast), color var(--transition-fast);
}
.app-sidebar__recent a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.app-sidebar__recent .section-tag {
    margin: 0; font-size: 0.6rem; padding: 0.05rem 0.35rem;
    background: rgba(45, 212, 191, 0.15); color: var(--color-accent);
    flex-shrink: 0;
}

/* Collapsed state — only icons visible, labels fade out */
html[data-sidebar-collapsed="1"] .sidenav-link__label,
html[data-sidebar-collapsed="1"] .app-sidebar__brand-text,
html[data-sidebar-collapsed="1"] .app-sidebar__recent {
    display: none;
}
html[data-sidebar-collapsed="1"] .sidenav-link {
    justify-content: center;
    padding: 0.65rem;
}
html[data-sidebar-collapsed="1"] .app-sidebar__brand {
    justify-content: center;
    padding: var(--sp-4) var(--sp-3);
}

/* App shell (everything to the right of the sidebar) */
.app-shell {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Top bar — solid bg (removed `backdrop-filter: blur` because it creates a
   stacking context that clipped the search-suggest dropdown). */
.app-topbar {
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0.65rem var(--sp-5);
    position: sticky;
    top: 0;
    /* Above sticky page content, below the mobile sidebar backdrop (29)
       and the sidebar itself (30).

       This has to out-rank anything sticky inside `.app-main` — notably
       `.dash-range`, which was also 20 and, being later in the document,
       won the tie and painted over the account dropdown. The dropdown's
       own z-index cannot rescue it: a positioned element with a z-index
       creates a stacking context, so `.topbar-user__panel` at 50 is only
       50 *within* this bar, and the whole bar competes with page content
       at the value set here. */
    z-index: 25;
}
.topbar-toggle {
    background: transparent; border: 0;
    padding: 0.4rem; cursor: pointer;
    color: var(--color-text-muted);
    border-radius: var(--radius);
    display: none; align-items: center; justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.topbar-toggle:hover { background: var(--color-section); color: var(--color-text-strong); }

.topbar-search {
    position: relative;
    flex: 1;
    max-width: 30rem;
    margin: 0;
}
.topbar-search__icon {
    position: absolute;
    top: 50%; left: 0.65rem;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    pointer-events: none;
}
.topbar-search input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.2rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-section);
    font-size: var(--fs-sm);
    font-family: inherit;
    color: var(--color-text-strong);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
.topbar-search input:focus {
    outline: none;
    background: var(--color-bg);
    border-color: var(--color-accent-2);
    box-shadow: var(--shadow-focus);
}

.topbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.topbar-company select {
    padding: 0.35rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-section);
    font-size: var(--fs-sm);
    font-family: inherit;
    color: var(--color-text-strong);
}
.topbar-company__chip {
    background: var(--color-accent-soft);
    color: var(--color-accent-2);
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: var(--fs-xs);
}

.topbar-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem; height: 2.25rem;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.topbar-icon-link:hover { background: var(--color-section); color: var(--color-accent-2); text-decoration: none; }

.topbar-user {
    position: relative;
}
.topbar-user > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.3rem 0.65rem 0.3rem 0.3rem;
    border-radius: var(--radius-full);
    background: var(--color-section);
    border: 1px solid var(--color-border);
    color: var(--color-text-strong);
    font-size: var(--fs-sm);
    font-weight: 600;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}
.topbar-user > summary::-webkit-details-marker { display: none; }
.topbar-user > summary:hover { background: var(--color-bg); border-color: var(--color-accent-2); }
.topbar-user__avatar {
    width: 1.65rem; height: 1.65rem;
    border-radius: 50%;
    background: var(--color-accent-2);
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700;
    font-size: 0.82rem;
}
.topbar-user__name { max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user__panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    z-index: 50;
    min-width: 16rem;
    max-height: calc(100vh - 5rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.4rem;
}
.topbar-user__panel .nav-tools-link {
    padding: 0.45rem 0.6rem;
    gap: 0.05rem;
}
.topbar-user__panel .nav-tools-link strong { font-size: 0.88rem; }
.topbar-user__panel .nav-tools-link .muted { font-size: 0.72rem; }

/* Mobile / tablet — sidebar becomes a slide-in drawer */
@media (max-width: 820px) {
    .app-layout {
        grid-template-columns: 1fr;
        --sidebar-w: 16rem;
    }
    .app-sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 16rem;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform var(--transition-base);
        box-shadow: var(--shadow-lg);
    }
    body.sidebar-open .app-sidebar {
        transform: translateX(0);
    }
    body.sidebar-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 29;
    }
    .app-sidebar__collapse { display: none; }
    .topbar-toggle { display: inline-flex; }
    .app-topbar { padding: 0.5rem var(--sp-3); }
    .topbar-search { max-width: none; }
    .topbar-user__name { display: none; }
}

/* Login / anonymous page layout — full-bleed, no constraints. Each
   auth template wraps its content in its own `.auth-page` shell. */
.app-layout--anon .app-main {
    max-width: none;
    margin: 0;
    padding: 0;
}

/* ============================================================
   Slice 34 — auth-page redesign (login / forgot / register)
   ============================================================ */

.app-layout--anon .app-footer { display: none; }

.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    background: var(--color-section);
}

.auth-brand {
    background:
        radial-gradient(circle at 18% 10%, rgba(45, 212, 191, 0.35), transparent 55%),
        radial-gradient(circle at 88% 88%, rgba(45, 212, 191, 0.18), transparent 55%),
        linear-gradient(135deg, #0b1a33 0%, #102849 100%);
    color: #f8fafc;
    padding: var(--sp-7) var(--sp-6);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: var(--sp-6);
    position: relative;
    overflow: hidden;
}
.auth-brand::after {
    content: "";
    position: absolute; inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(circle at 30% 40%, black, transparent 75%);
    pointer-events: none;
}
.auth-brand__logo {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.01em;
    position: relative;
    z-index: 1;
}
.auth-brand__logo img { width: 36px; height: 36px; }
.auth-brand__hero {
    position: relative; z-index: 1;
    max-width: 32rem;
}
.auth-brand__eyebrow {
    display: inline-block;
    background: rgba(45, 212, 191, 0.18);
    color: var(--color-accent);
    padding: 0.3rem 0.85rem;
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    margin-bottom: var(--sp-4);
}
.auth-brand__title {
    font-size: clamp(1.875rem, 3vw, 2.5rem);
    line-height: 1.15;
    margin: 0 0 var(--sp-3);
    font-weight: 800;
    letter-spacing: -0.025em;
    color: #fff;
}
.auth-brand__title em {
    font-style: normal;
    color: var(--color-accent);
}
.auth-brand__lead {
    font-size: var(--fs-lg);
    line-height: 1.55;
    color: rgba(248, 250, 252, 0.78);
    margin: 0 0 var(--sp-5);
    max-width: 30rem;
}
.auth-brand__features {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}
.auth-brand__features li {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-3);
    color: rgba(248, 250, 252, 0.88);
    font-size: var(--fs-sm);
}
.auth-brand__check {
    flex: 0 0 auto;
    width: 1.5rem; height: 1.5rem;
    border-radius: 50%;
    background: rgba(45, 212, 191, 0.2);
    color: var(--color-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.auth-brand__check svg { width: 0.85rem; height: 0.85rem; }
.auth-brand__footer {
    font-size: var(--fs-xs);
    color: rgba(248, 250, 252, 0.55);
    position: relative;
    z-index: 1;
}
.auth-brand__footer a { color: rgba(248, 250, 252, 0.8); }

/* Form column */
.auth-form-col {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-6) var(--sp-5);
}
.auth-card {
    width: 100%;
    max-width: 26rem;
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    padding: var(--sp-6);
}
.auth-card h1 {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-2xl);
    font-weight: 800;
    color: var(--color-text-strong);
    letter-spacing: -0.025em;
}
.auth-card p.lead {
    margin: 0 0 var(--sp-5);
    color: var(--color-text-muted);
    font-size: var(--fs-base);
}
.auth-field {
    display: block;
    margin-bottom: var(--sp-4);
}
.auth-field__label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--color-text-strong);
    margin-bottom: var(--sp-2);
}
.auth-field__label a {
    font-size: var(--fs-xs);
    font-weight: 500;
}
.auth-field input,
.auth-field textarea,
.auth-field select {
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    background: var(--color-bg);
    font-size: var(--fs-base);
    font-family: inherit;
    color: var(--color-text-strong);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.auth-field input:focus {
    outline: none;
    border-color: var(--color-accent-2);
    box-shadow: var(--shadow-focus);
}
.auth-submit {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: var(--fs-base);
    margin-top: var(--sp-2);
    justify-content: center;
}
.auth-card .divider {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: var(--sp-5) 0;
}
.auth-card .help-links {
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
    margin: 0;
}
.auth-card .help-links a { font-weight: 600; }

/* Stack to single column on tablets / phones */
@media (max-width: 880px) {
    .auth-page {
        grid-template-columns: 1fr;
    }
    .auth-brand {
        padding: var(--sp-5) var(--sp-4);
        min-height: auto;
    }
    .auth-brand__hero { max-width: none; }
    .auth-brand__features { display: none; }
    .auth-form-col { padding: var(--sp-5) var(--sp-4); }
    .auth-brand__title { font-size: 1.5rem; }
    .auth-brand__lead { font-size: var(--fs-base); }
}

/* ============================================================
   Slice 35 — auth pages: wide card + form grid + section header
   ============================================================ */

.auth-card--wide { max-width: 40rem; }

.auth-form-section {
    margin-top: var(--sp-5);
    margin-bottom: var(--sp-3);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    font-weight: 700;
    padding-bottom: var(--sp-2);
    border-bottom: 1px solid var(--color-border);
}
.auth-form-section:first-child { margin-top: 0; }

.auth-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-3);
}
.auth-form-grid > .auth-field { margin-bottom: 0; }
.auth-form-grid > .auth-field--full { grid-column: 1 / -1; }

@media (max-width: 540px) {
    .auth-form-grid { grid-template-columns: 1fr; }
}

/* "Big primary CTA button" used on the result/confirmation screens */
.auth-card .btn.auth-cta {
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: var(--fs-base);
    margin-top: var(--sp-3);
}

/* Helper for the chunky monospace "code" display on token screens */
.auth-token-display {
    background: var(--color-section);
    border: 1px dashed var(--color-border-strong);
    color: var(--color-text-strong);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 1.05rem;
    letter-spacing: 0.05em;
    text-align: center;
    margin: var(--sp-3) 0;
    word-break: break-all;
}

/* Bigger info-icon for the email-sent / activation screens */
.auth-result-icon {
    width: 4.5rem; height: 4.5rem;
    border-radius: 50%;
    background: var(--color-accent-soft);
    color: var(--color-accent-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--sp-4);
}
.auth-result-icon svg { width: 2rem; height: 2rem; }
.auth-result-icon--info { background: var(--color-info-soft); color: var(--color-info); }
.auth-result-icon--warning { background: var(--color-warning-soft); color: var(--color-warning-text); }

/* ============================================================
   Slice 38 — detail-page + settings polish
   ============================================================ */

/* Section header used between cards/sections on a detail page.
   Replaces the `<h2 style="margin-top:1.5rem;font-size:1rem">` pattern. */
.detail-section {
    margin: var(--sp-5) 0 var(--sp-3);
    display: flex;
    align-items: baseline;
    gap: var(--sp-2);
    flex-wrap: wrap;
}
.detail-section h2 {
    margin: 0;
    font-size: var(--fs-lg);
    font-weight: 600;
    color: var(--color-text-strong);
    letter-spacing: -0.01em;
}
.detail-section .count {
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
    font-weight: 500;
}
.detail-section .actions {
    margin-left: auto;
    display: inline-flex;
    gap: var(--sp-2);
}

/* Key-value list inside a card (e.g. Profile, Bank details).
   Replaces the "data-table inside a card" pattern which used a real
   table for what's really just label/value pairs. */
.kv-list {
    display: grid;
    grid-template-columns: minmax(7rem, max-content) 1fr;
    gap: var(--sp-2) var(--sp-4);
    margin: 0;
    font-size: var(--fs-sm);
}
.kv-list dt {
    color: var(--color-text-muted);
    font-weight: 500;
    align-self: baseline;
}
.kv-list dd {
    margin: 0;
    color: var(--color-text-strong);
}
.kv-list dd strong { font-weight: 600; }

/* Card header bar — title on the left, action-button(s) on the right. */
.card-head {
    display: flex;
    align-items: baseline;
    gap: var(--sp-3);
    margin-bottom: var(--sp-3);
}
.card-head h2 {
    margin: 0;
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--color-text-strong);
    flex: 1;
}
.card-head .actions {
    display: inline-flex;
    gap: var(--sp-2);
}

/* "Add ___" reveal — used on landlord/property/tenant/maintenance detail
   pages and on the settings entity page. Wraps the `<details>+<form>`
   pattern in consistent chrome. */
.add-reveal {
    margin-top: var(--sp-4);
}
.add-reveal > summary {
    list-style: none;
    cursor: pointer;
}
.add-reveal > summary::-webkit-details-marker { display: none; }
.add-reveal__form {
    margin-top: var(--sp-3);
    padding: var(--sp-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
}
.add-reveal__form > .actions {
    margin-top: var(--sp-3);
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    flex-wrap: wrap;
}

/* Page-header tighter status pills row */
.page-header__meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    align-items: center;
    margin-top: var(--sp-3);
}
.page-header__meta a { color: var(--color-text-muted); }
.page-header__meta a:hover { color: var(--color-accent-2); }
.page-header__meta .pill { font-size: var(--fs-xs); }

/* Address-card cleanup — the per-address `.card` blocks on detail pages */
.address-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--sp-4);
}
.address-card {
    /* Already a `.card`, but slightly tighter padding on detail pages */
    padding: var(--sp-4);
}

/* Two-up grid wrapper used by Profile + Bank details cards etc. */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--sp-4);
    align-items: start;
}

/* ============================================================
   Slice 40 — list page polish
   ============================================================ */

/* Action button cluster at the end of a list row. Buttons are smaller,
   ghost-styled, and lay out in a single row with a tight gap. */
.row-actions {
    display: inline-flex;
    gap: var(--sp-2);
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.row-actions .btn,
.row-actions form { margin: 0; }
.row-actions .btn-outline {
    /* Slightly lighter border so the cluster doesn't dominate the row */
    border-color: var(--color-border);
    color: var(--color-text-muted);
    background: var(--color-bg);
    font-weight: 500;
}
.row-actions .btn-outline:hover {
    color: var(--color-accent-2);
    border-color: var(--color-accent-2);
    background: var(--color-bg);
}

/* Empty state — replaces the generic single-row "No records found." */
.empty-state {
    text-align: center;
    padding: var(--sp-6) var(--sp-4);
    color: var(--color-text-muted);
}
.empty-state__icon {
    width: 3.5rem; height: 3.5rem;
    border-radius: 50%;
    background: var(--color-section);
    color: var(--color-text-subtle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--sp-3);
}
.empty-state__icon svg { width: 1.5rem; height: 1.5rem; }
.empty-state__title {
    font-weight: 600;
    color: var(--color-text-strong);
    font-size: var(--fs-base);
    margin: 0 0 var(--sp-2);
}
.empty-state__message {
    font-size: var(--fs-sm);
    max-width: 36ch;
    margin: 0 auto var(--sp-4);
}
.empty-state__actions {
    display: inline-flex;
    gap: var(--sp-3);
    justify-content: center;
    margin-top: var(--sp-2);
}

/* List-page sub-header — slightly more compact than the detail-page
   page-header__meta. */
.list-sub {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-3);
    margin-top: var(--sp-2);
    color: var(--color-text-muted);
    font-size: var(--fs-sm);
}
.list-sub a { color: var(--color-text-muted); }
.list-sub a:hover { color: var(--color-accent-2); }
.list-sub .scope-pill {
    background: var(--color-info-soft);
    color: var(--color-info);
    padding: 0.15rem 0.55rem;
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    font-weight: 600;
}

/* Tighten the .filters bar slightly + make the count more prominent */
.filters .count {
    color: var(--color-text-strong);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.filters .count::before {
    content: "";
    display: inline-block;
    width: 0.4rem; height: 0.4rem;
    border-radius: 50%;
    background: var(--color-accent-2);
    margin-right: var(--sp-2);
    vertical-align: middle;
}

/* Compact table-cell address rendering — replaces the <br>-separated
   address lines with a tighter visual block. */
.cell-stack {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    line-height: 1.35;
}
.cell-stack .muted { font-size: var(--fs-xs); }

/* ---------------------------------------------------------------------------
   Print — clean report output.
   Strips the app chrome (sidebar, topbar, footer), filter forms and action
   buttons so a browser "Print" (or Save-as-PDF) yields just the report title
   + table. Fixes the QA "Print option includes the page design as well".
   Add `.no-print` to anything that must never print; `.print-only` shows
   only when printing.
   --------------------------------------------------------------------------- */
@media print {
    /* Neutralise the app shell so content starts at the top-left. */
    .app-sidebar,
    .app-topbar,
    .app-footer,
    .topbar-toggle,
    .no-print,
    form.filters,
    .filters,
    .pagination,
    .paginator,
    .btn,
    button,
    .entity-picker,
    ._subnav,
    nav {
        display: none !important;
    }

    html, body, .app-layout, .app-shell, .app-main {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        color: #000 !important;
        display: block !important;
        width: auto !important;
        max-width: none !important;
        box-shadow: none !important;
    }

    .print-only { display: block !important; }

    /* Page header: keep the title, drop the meta/nav row + jump box. */
    .page-header__meta,
    .page-header .entity-picker,
    .section-tag { display: none !important; }
    .page-header h1 { font-size: 16pt; margin: 0 0 0.3rem; }

    /* Tables: full width, hairline borders, avoid row splits. */
    table.data-table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 9pt;
        box-shadow: none !important;
    }
    table.data-table th,
    table.data-table td {
        border: 1px solid #999 !important;
        padding: 2px 4px !important;
        color: #000 !important;
        background: #fff !important;
    }
    table.data-table thead th {
        background: #eee !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    thead { display: table-header-group; }  /* repeat header on each page */
    tr, img { page-break-inside: avoid; }

    .card, .table-wrap, .table-scroll {
        border: 0 !important;
        box-shadow: none !important;
        padding: 0 !important;
        overflow: visible !important;
    }
    a { color: #000 !important; text-decoration: none !important; }
    .pill { border: 1px solid #999; padding: 0 4px; }

    @page { margin: 12mm; }
}

/* ============================================================
   EchoPMS Copilot — docked panel (AI_PLAN.md §11 C2/C3)
   ============================================================ */
#copilot-fab {
    position: fixed; right: 1.1rem; bottom: 1.1rem; z-index: 900;
    width: 3.1rem; height: 3.1rem; border-radius: var(--radius-full);
    border: none; cursor: pointer;
    background: var(--color-accent-2); color: #fff;
    display: flex; align-items: center; justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
#copilot-fab:hover { transform: translateY(-2px); }
#copilot-fab.copilot-fab--open { background: var(--color-primary, #1e293b); }

#copilot-panel {
    position: fixed; right: 1.1rem; bottom: 4.8rem; z-index: 900;
    width: min(26rem, calc(100vw - 2rem));
    height: min(34rem, calc(100vh - 7rem));
    display: flex; flex-direction: column;
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-border, #e2e8f0);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
#copilot-panel[hidden] { display: none; }

.copilot__head {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--color-border, #e2e8f0);
}
.copilot__reset { margin-left: auto; font-size: 0.78rem; }
.copilot__close {
    border: none; background: none; cursor: pointer;
    font-size: 1.3rem; line-height: 1; padding: 0 0.2rem; color: inherit;
}

.copilot__messages {
    flex: 1; overflow-y: auto; padding: 0.8rem;
    display: flex; flex-direction: column; gap: 0.55rem;
}
.copilot__msg {
    max-width: 88%; padding: 0.5rem 0.7rem;
    border-radius: var(--radius); font-size: 0.88rem;
    white-space: pre-wrap; word-wrap: break-word;
}
.copilot__msg--user {
    align-self: flex-end;
    background: var(--color-accent-soft, #ccfbf1);
}
.copilot__msg--ai {
    align-self: flex-start;
    background: var(--color-section, #f1f5f9);
}
.copilot__msg--thinking { opacity: 0.6; font-style: italic; }

.copilot__card {
    align-self: stretch;
    border: 1px solid var(--color-accent-2);
    border-radius: var(--radius);
    padding: 0.65rem 0.75rem;
    background: var(--color-accent-soft, #ccfbf1);
}
.copilot__card-title { font-weight: 600; font-size: 0.88rem; }
.copilot__card-summary {
    font-size: 0.8rem; margin: 0.2rem 0 0.5rem; opacity: 0.85;
    white-space: pre-wrap;
}
.copilot__card-field {
    display: block; font-size: 0.75rem; margin: 0.35rem 0;
}
.copilot__card-field input,
.copilot__card-field textarea {
    display: block; width: 100%; margin-top: 0.15rem;
    font-size: 0.83rem; padding: 0.35rem 0.5rem;
}

.copilot__inputrow {
    display: flex; gap: 0.45rem; padding: 0.6rem 0.8rem 0.3rem;
    border-top: 1px solid var(--color-border, #e2e8f0);
}
.copilot__inputrow input {
    flex: 1; padding: 0.45rem 0.6rem; font-size: 0.9rem;
}
.copilot__foot {
    margin: 0; padding: 0.15rem 0.8rem 0.6rem; font-size: 0.68rem;
}

@media (max-width: 620px) {
    #copilot-panel {
        right: 0.5rem; left: 0.5rem; width: auto;
        height: min(30rem, calc(100vh - 6.5rem));
    }
}
@media print {
    #copilot-fab, #copilot-panel { display: none !important; }
}

/* C4 — anomaly hints on transaction-entry forms */
.anomaly-hints {
    margin-top: 0.6rem;
    border: 1px solid var(--color-warning, #d97706);
    border-radius: var(--radius);
    background: var(--color-warning-soft, #fef3c7);
    padding: 0.45rem 0.7rem;
    font-size: 0.82rem;
}
.anomaly-hints p { margin: 0.15rem 0; }

/* Rent-demand format picker — horizontal card slider */
.fmt-picker {
    margin: 0 0 1.1rem;
    padding: 0.9rem 1rem 0.4rem;
    background: var(--color-section);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}
.fmt-picker__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}
.fmt-picker__title {
    margin: 0;
    font-size: var(--fs-base);
    font-weight: 600;
    color: var(--color-text-strong);
}
.fmt-picker__sub {
    margin: 0.15rem 0 0;
    font-size: var(--fs-xs);
    color: var(--color-text-muted);
    max-width: 62ch;
}
.fmt-picker__nav { display: flex; gap: 0.35rem; flex: none; }
.fmt-nav {
    width: 1.9rem;
    height: 1.9rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--color-border-strong);
    background: var(--color-bg);
    color: var(--color-text-strong);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition-fast), opacity var(--transition-fast);
}
.fmt-nav:hover:not(:disabled) { background: var(--color-section); }
.fmt-nav:disabled { opacity: 0.35; cursor: default; }
.fmt-nav:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.fmt-track {
    display: flex;
    gap: 0.75rem;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    padding-bottom: 0.65rem;
    scrollbar-width: thin;
}
.fmt-card {
    flex: 0 0 15.5rem;
    scroll-snap-align: start;
    cursor: pointer;
    min-width: 0;
}
/* Keep the radio focusable but invisible — the card is the control. */
.fmt-card input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}
.fmt-card__inner {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    height: 100%;
    padding: 0.7rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition-fast),
                box-shadow var(--transition-fast),
                transform var(--transition-fast);
}
.fmt-card:hover .fmt-card__inner {
    border-color: var(--color-border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.fmt-card input:checked ~ .fmt-card__inner {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-accent-soft), var(--shadow-md);
}
.fmt-card input:focus-visible ~ .fmt-card__inner {
    box-shadow: var(--shadow-focus);
}
.fmt-card__name {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem;
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--color-text-strong);
}
.fmt-card__note {
    font-size: 0.66rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--color-text-subtle);
    white-space: nowrap;
}
.fmt-card input:checked ~ .fmt-card__inner .fmt-card__note {
    color: var(--color-text-muted);
}
.fmt-card__blurb {
    font-size: var(--fs-xs);
    line-height: 1.4;
    color: var(--color-text-muted);
}

/* Miniature page schematics — four bars positioned per format. */
.fmt-thumb {
    position: relative;
    display: block;
    height: 4.6rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    overflow: hidden;
}
.fmt-thumb i {
    position: absolute;
    background: var(--color-border-strong);
    border-radius: 1px;
}
/* As saved — plain document */
.fmt-thumb--stored i:nth-child(1) { left: 18%; right: 18%; top: 22%; height: 5%; }
.fmt-thumb--stored i:nth-child(2) { left: 18%; right: 28%; top: 40%; height: 5%; }
.fmt-thumb--stored i:nth-child(3) { left: 18%; right: 34%; top: 58%; height: 5%; }
.fmt-thumb--stored i:nth-child(4) { left: 18%; right: 52%; top: 76%; height: 5%; }
/* Classic — caption/value ladder down the left */
.fmt-thumb--RentDemandDocument i { background: var(--color-accent); }
.fmt-thumb--RentDemandDocument i:nth-child(1) { left: 12%; width: 24%; top: 16%; height: 6%; }
.fmt-thumb--RentDemandDocument i:nth-child(2) { left: 12%; width: 24%; top: 36%; height: 6%; }
.fmt-thumb--RentDemandDocument i:nth-child(3) { left: 12%; width: 24%; top: 56%; height: 6%; }
.fmt-thumb--RentDemandDocument i:nth-child(4) { left: 12%; width: 24%; top: 76%; height: 6%; }
.fmt-thumb--RentDemandDocument::after {
    content: "";
    position: absolute;
    left: 46%; width: 20%; top: 16%; height: 66%;
    border-left: 1px solid var(--color-border);
}
/* Invoice — header block then a ruled table */
.fmt-thumb--RentDemandsReport1 i:nth-child(1) { left: 10%; width: 34%; top: 12%; height: 7%; background: var(--color-accent); }
.fmt-thumb--RentDemandsReport1 i:nth-child(2) { left: 10%; right: 10%; top: 40%; height: 4%; }
.fmt-thumb--RentDemandsReport1 i:nth-child(3) { left: 10%; right: 10%; top: 56%; height: 4%; }
.fmt-thumb--RentDemandsReport1 i:nth-child(4) { right: 10%; width: 26%; top: 76%; height: 6%; background: var(--color-text-strong); }
.fmt-thumb--RentDemandsReport1::after {
    content: "";
    position: absolute;
    left: 10%; right: 10%; top: 33%;
    border-top: 1px solid var(--color-border-strong);
}
/* Notice — full-width banner and a heavy total. The banner is drawn in the
   app accent, not a band colour: the printed colour comes from
   tblgen_reports_colourfields per tenant, so the thumbnail must not imply
   this format is always red. */
.fmt-thumb--RentDemandNotice i:nth-child(1) { left: 0; right: 0; top: 0; height: 20%; background: var(--color-accent); border-radius: 0; }
.fmt-thumb--RentDemandNotice i:nth-child(2) { left: 10%; width: 40%; top: 34%; height: 5%; }
.fmt-thumb--RentDemandNotice i:nth-child(3) { right: 10%; width: 34%; top: 54%; height: 4%; }
.fmt-thumb--RentDemandNotice i:nth-child(4) { right: 10%; width: 34%; top: 70%; height: 9%; background: var(--color-accent); }
/* Compact — offset address block and one horizontal strip */
.fmt-thumb--RentDemandCompact i:nth-child(1) { left: 10%; width: 30%; top: 10%; height: 4%; }
.fmt-thumb--RentDemandCompact i:nth-child(2) { left: 22%; width: 34%; top: 34%; height: 4%; }
.fmt-thumb--RentDemandCompact i:nth-child(3) { left: 22%; width: 26%; top: 46%; height: 4%; }
.fmt-thumb--RentDemandCompact i:nth-child(4) { left: 10%; right: 10%; top: 72%; height: 12%; background: var(--color-accent-soft); border: 1px solid var(--color-accent); }

/* A company's own report-designer template. */
.fmt-thumb--template i { background: var(--color-primary); opacity: 0.55; }
.fmt-thumb--template i:nth-child(1) { left: 10%; right: 10%; top: 10%; height: 12%; opacity: 0.85; }
.fmt-thumb--template i:nth-child(2) { left: 10%; width: 36%; top: 32%; height: 5%; }
.fmt-thumb--template i:nth-child(3) { left: 10%; right: 10%; top: 48%; height: 5%; }
.fmt-thumb--template i:nth-child(4) { left: 54%; right: 10%; top: 66%; height: 9%; }

@media (max-width: 640px) {
    .fmt-card { flex-basis: 12.5rem; }
    .fmt-picker__sub { display: none; }
}

/* Per-row format preview. Expands in flow rather than overlaying, because
   .table-wrap scrolls on x and would clip an absolutely-placed panel. */
.row-actions { white-space: nowrap; }
.row-menu { display: inline-block; vertical-align: middle; }
.row-menu__btn {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    background: var(--color-bg);
    font-size: var(--fs-xs);
    color: var(--color-text-strong);
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.row-menu__btn::-webkit-details-marker { display: none; }
.row-menu__btn::after {
    content: " \25BE";
    color: var(--color-text-subtle);
}
.row-menu[open] .row-menu__btn {
    border-color: var(--color-accent);
    background: var(--color-accent-soft);
}
.row-menu__btn:hover { background: var(--color-section); }
.row-menu__btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.row-menu__panel {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.4rem;
    padding: 0.35rem;
    background: var(--color-section);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.row-menu__panel a {
    padding: 0.22rem 0.5rem;
    border-radius: var(--radius);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    font-size: var(--fs-xs);
    color: var(--color-text-strong);
    text-decoration: none;
    white-space: nowrap;
}
.row-menu__panel a:hover {
    border-color: var(--color-accent);
    background: var(--color-accent-soft);
}

/* --- Report "as at" strip + footer watermark ---------------------------- */
/* `reports/_as_of.html` sits under the page-header on every report screen;
   `reports/_watermark.html` is appended by base.html for the whole reports
   namespace. Both must survive printing — that is the whole point of them. */
.report-as-of {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.25rem;
    margin: 0 0 0.9rem;
    padding: 0.45rem 0.7rem;
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-accent-2);
    border-radius: var(--radius);
    background: var(--color-section);
    font-size: 0.82rem;
    line-height: 1.35;
}
.report-as-of__item { white-space: nowrap; }
.report-as-of__label {
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.72rem;
    margin-right: 0.3rem;
}

.report-watermark {
    margin-top: 1.5rem;
    padding-top: 0.6rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    color: var(--color-text-muted);
    font-size: 0.75rem;
}
.report-watermark__name {
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0.45;
}
.report-watermark__meta { font-variant-numeric: tabular-nums; }

@media print {
    /* Keep both on paper — the strip once at the top, the watermark repeated
       at the foot of every sheet (position:fixed repeats per page in print). */
    .report-as-of {
        display: flex !important;
        background: transparent !important;
        border: 0 !important;
        border-bottom: 1pt solid #000 !important;
        padding-left: 0;
        color: #000 !important;
    }
    .report-watermark {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        margin: 0;
        padding: 2pt 0;
        border-top: 0.5pt solid #666 !important;
        background: #fff !important;
        color: #444 !important;
        font-size: 8pt;
    }
    .report-watermark__name { opacity: 0.55; }
    /* Reserve the strip's height so table rows never print underneath it. */
    @page { margin-bottom: 16mm; }
}

/* --- Password reveal toggle (auth pages) -------------------------------- */
/* The wrapper + button are injected by the script in
   `auth_bridge/_auth_base.html`, so no auth template carries this markup.
   With JS off the field stays a plain password input — still usable. */
.pw-field {
    position: relative;
    display: block;
}
/* Room for the button so a long password never runs under it. Matches the
   .auth-field input padding, with the right side opened up. */
.pw-field input {
    padding-right: 2.9rem;
}
.pw-toggle {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 0 var(--radius) var(--radius) 0;
}
.pw-toggle:hover { color: var(--color-text-strong); }
.pw-toggle:focus-visible {
    outline: 2px solid var(--color-accent-2);
    outline-offset: -2px;
}
.pw-toggle svg {
    width: 1.15rem;
    height: 1.15rem;
    pointer-events: none;   /* clicks always land on the button */
}
/* Edge/IE render their own reveal control — two eyes side by side. */
.pw-field input::-ms-reveal,
.pw-field input::-ms-clear { display: none; }

/* --- Sidebar dropdown submenu (Transactions) --------------------------- */
/* <details>/<summary> disclosure: keyboard-operable, open-by-default while
   you are in the section, and no JS. The summary reuses .sidenav-link so the
   parent row is pixel-identical to every other top-level item. */
.sidenav-group { border: 0; }
.sidenav-group > summary {
    cursor: pointer;
    user-select: none;
    list-style: none;                 /* drop the native disclosure triangle */
}
.sidenav-group > summary::-webkit-details-marker { display: none; }
.sidenav-group > summary::marker { content: ""; }
.sidenav-group > summary:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}
.sidenav-group__chevron {
    margin-left: auto;
    flex: 0 0 auto;
    opacity: 0.5;
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}
.sidenav-group > summary:hover .sidenav-group__chevron { opacity: 0.9; }
.sidenav-group[open] > summary .sidenav-group__chevron {
    transform: rotate(90deg);
    opacity: 0.9;
}

/* The panel. Indented under the parent label and tied to it by a hairline
   spine, so 14 links read as belonging to Transactions rather than floating
   as a second top-level list. */
.sidenav-sub {
    display: flex;
    flex-direction: column;
    margin: 0.25rem 0 0.5rem 1.15rem;
    padding-left: 0.72rem;
    border-left: 1px solid rgba(203, 213, 225, 0.18);
}
.sidenav-group[open] > .sidenav-sub {
    animation: sidenav-sub-in 160ms ease-out;
}
@keyframes sidenav-sub-in {
    from { opacity: 0; transform: translateY(-3px); }
    to   { opacity: 1; transform: none; }
}

/* Group headings carry the context, which is what lets the links below stay
   short — "Routine" under Rent demands, not "Rent demand routine". */
.sidenav-sub__heading {
    margin: 0.55rem 0 0.2rem;
    padding: 0 0.5rem;
    font-size: 0.63rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: rgba(203, 213, 225, 0.45);
}
.sidenav-sub__heading:first-child { margin-top: 0.15rem; }

.sidenav-sublink {
    position: relative;
    display: block;
    padding: 0.33rem 0.55rem;
    border-radius: var(--radius);
    color: #b6c2d1;
    font-size: 0.795rem;
    line-height: 1.35;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.sidenav-sublink:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}
.sidenav-sublink.is-active {
    color: #fff;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.10);
}
/* Marker on the spine, so the current page is findable at a glance without
   relying on the fill alone. */
.sidenav-sublink.is-active::before {
    content: "";
    position: absolute;
    left: -0.73rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 1.05rem;
    border-radius: 1px;
    background: var(--color-accent);
}
.sidenav-sublink:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

/* Collapsed rail is icons only — children and chevron have nowhere to sit. */
html[data-sidebar-collapsed="1"] .sidenav-sub,
html[data-sidebar-collapsed="1"] .sidenav-group__chevron {
    display: none;
}
html[data-sidebar-collapsed="1"] .sidenav-group > summary {
    justify-content: center;
    padding: 0.65rem;
}

@media (prefers-reduced-motion: reduce) {
    .sidenav-group[open] > .sidenav-sub { animation: none; }
    .sidenav-group__chevron { transition: none; }
}

/* --- Deep-linked ledger row (Reconciliation history -> document) -------- */
/* Marks the single row a ?line= link points at. These documents run to
   hundreds of lines, so the row needs to be findable the instant the page
   settles, not merely scrolled into view. */
.data-table tr.is-linked-row > td {
    background: var(--color-accent-soft, #fff8e1);
    box-shadow: inset 0 1px 0 var(--color-accent), inset 0 -1px 0 var(--color-accent);
}
.data-table tr.is-linked-row > td:first-child {
    box-shadow: inset 3px 0 0 var(--color-accent),
                inset 0 1px 0 var(--color-accent),
                inset 0 -1px 0 var(--color-accent);
    font-weight: 700;
}
/* One pulse on arrival draws the eye, then leaves the row plainly marked. */
@keyframes linked-row-flash {
    0%   { background: var(--color-accent); }
    100% { background: var(--color-accent-soft, #fff8e1); }
}
.data-table tr.is-linked-row > td { animation: linked-row-flash 900ms ease-out 1; }
/* Anchor jumps land the row below any sticky header rather than under it. */
.data-table tr[id^="line-"] { scroll-margin-top: 5rem; }

@media (prefers-reduced-motion: reduce) {
    .data-table tr.is-linked-row > td { animation: none; }
}

/* ===========================================================================
   Dashboard date range + range-scoped panels
   ---------------------------------------------------------------------------
   One range control drives every card, list and chart on the dashboard.
   The bar is sticky so the period stays readable while scrolling a long
   page — losing sight of which period you are looking at is the failure
   mode these panels are most exposed to.
   =========================================================================== */

.dash-range {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    margin-bottom: var(--sp-4);
    padding: var(--sp-3) var(--sp-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.dash-range__row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.dash-range__label {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
}

.dash-range__label strong { color: var(--color-text-strong); }
.dash-range__label svg { color: var(--color-accent-2); flex-shrink: 0; }

.dash-range__presets {
    display: flex;
    gap: var(--sp-1);
    flex-wrap: wrap;
    margin-left: auto;
}

.dash-chip {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-section);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.dash-chip:hover {
    color: var(--color-text-strong);
    border-color: var(--color-border-strong);
}

.dash-chip.is-active {
    color: #fff;
    background: var(--color-accent-2);
    border-color: var(--color-accent-2);
}

.dash-range__custom {
    padding-top: var(--sp-3);
    border-top: 1px dashed var(--color-border);
    font-size: var(--fs-sm);
}

.dash-range__custom label {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.dash-range__custom input[type="date"] {
    padding: 0.35rem 0.5rem;
    font: inherit;
    font-size: var(--fs-sm);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
}

.dash-range__note { margin-left: auto; font-size: var(--fs-xs); }

/* "as of today" marks the cards that have no date to filter on, so a
   point-in-time number is never mistaken for a range-scoped one. */
.dash-asof {
    display: inline-block;
    margin-left: 0.35rem;
    padding: 0.05rem 0.4rem;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: var(--color-text-subtle);
    background: var(--color-section);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    vertical-align: middle;
    cursor: help;
}

/* Two linked halves inside one card — property vs tenant unposted docs. */
.dash-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-2);
    margin-top: var(--sp-3);
}

.dash-split__half {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: var(--sp-2) var(--sp-3);
    background: var(--color-section);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.dash-split__half:hover {
    background: var(--color-bg);
    border-color: var(--color-accent-2);
}

.dash-split__n {
    font-size: var(--fs-xl);
    font-weight: 700;
    line-height: 1.1;
    color: var(--color-text-strong);
    font-variant-numeric: tabular-nums;
}

.dash-split__label {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-text-muted);
}

.dash-split__hint { font-size: 0.7rem; color: var(--color-text-subtle); }

/* Header strip above a dashboard list. */
.dash-listbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-wrap: wrap;
    margin-bottom: var(--sp-3);
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
}

/* --- Chart ---------------------------------------------------------------
   Two series on one count axis. Series colours are the existing accent-2
   and info tokens: that pair validates clean for deuteranopia and
   protanopia (worst adjacent dE 20.7) against the white card surface. */

.dash-chart__stats {
    display: flex;
    gap: var(--sp-6);
    flex-wrap: wrap;
    margin-bottom: var(--sp-4);
}

.dash-chart__stat-label {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-text-muted);
}

.dash-chart__stat {
    font-size: var(--fs-2xl);
    font-weight: 700;
    line-height: 1.2;
    color: var(--color-text-strong);
    font-variant-numeric: tabular-nums;
}

.dash-legend {
    display: flex;
    gap: var(--sp-4);
    list-style: none;
    padding: 0;
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-xs);
    color: var(--color-text-muted);
}

.dash-legend li { display: inline-flex; align-items: center; gap: 0.4rem; }

.dash-swatch {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 0.2rem;
    display: inline-block;
}

.dash-chart__plot { overflow-x: auto; }
.dash-chart__plot svg { display: block; min-width: 20rem; }

.dash-chart__axis {
    display: flex;
    justify-content: space-between;
    gap: 2px;
    min-width: 20rem;
    margin-top: var(--sp-1);
    font-size: 0.68rem;
    color: var(--color-text-subtle);
}

.dash-chart__axis span { flex: 1; text-align: center; }

.dash-figures { margin-top: var(--sp-4); }

.dash-figures summary {
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
    cursor: pointer;
}

.dash-figures summary:hover { color: var(--color-accent-2); }
.dash-figures .table-wrap { margin-top: var(--sp-2); }

@media (max-width: 40rem) {
    .dash-range { position: static; }
    .dash-range__presets, .dash-range__note { margin-left: 0; }
    .dash-chart__stats { gap: var(--sp-4); }
}

@media print {
    .dash-range { position: static; }
}

/* ===========================================================================
   Aged debtors — tenant arrears by payment frequency
   ---------------------------------------------------------------------------
   The report bands its columns per frequency (a monthly tenant's "This
   Month" is not a quarterly tenant's "This Quarter"), so each group gets
   its own header row. These rules keep the money columns aligned and the
   subtotal rows readable across those repeated tables.
   =========================================================================== */

.aged-filters {
    align-items: flex-start;
    gap: var(--sp-4);
    flex-wrap: wrap;
}

.aged-filters__field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.aged-filters__field > span:first-child {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.aged-filters input[type="date"] {
    padding: 0.35rem 0.5rem;
    font: inherit;
    font-size: var(--fs-sm);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
}

.aged-freq-list {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding: 0.35rem 0.6rem;
    background: var(--color-section);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.aged-freq {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: var(--fs-sm);
    white-space: nowrap;
}

.aged-filters__hint { font-size: 0.7rem; }

.aged-filters__inline {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--fs-sm);
    align-self: center;
}

/* --- Grouped tables ------------------------------------------------------ */

.aged-group { margin-bottom: var(--sp-6); }

.aged-group__head {
    margin-bottom: var(--sp-2);
    padding-bottom: var(--sp-2);
    border-bottom: 2px solid var(--color-accent-2);
}

.aged-group__head h2 { font-size: var(--fs-lg); }

.aged-table th.num,
.aged-table td.num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The Total column is the one people read first — separate it from the
   ageing buckets with a rule rather than relying on position alone. */
.aged-table .aged-total-col {
    border-left: 2px solid var(--color-border-strong);
    background: var(--color-section);
}

.aged-table tfoot .aged-subtotal td,
.aged-table tbody .aged-subtotal td {
    font-weight: 700;
    background: var(--color-section);
    border-top: 2px solid var(--color-border-strong);
}

/* --- Detail level -------------------------------------------------------- */

.aged-tenant { margin-bottom: var(--sp-3); }

.aged-tenant__head {
    caption-side: top;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0.4rem 0.6rem;
    text-align: left;
    background: var(--color-section);
    border: 1px solid var(--color-border);
    border-bottom: 0;
    border-radius: var(--radius) var(--radius) 0 0;
    font-size: var(--fs-sm);
}

.aged-tenant__total {
    margin-left: auto;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-strong);
}

.aged-periods {
    display: block;
    font-size: 0.68rem;
}

.aged-grand { margin-top: var(--sp-5); }
.aged-grand h2 { margin-top: 0; font-size: var(--fs-lg); }

@media print {
    /* Filters and the level toggle are navigation, not report content. */
    .aged-filters, .filters { display: none !important; }
    .aged-group { break-inside: avoid; }
}

/* dd-mm-yyyy date display (static/js/date-dmy.js). The native date input
   stays visible with its own styling and calendar icon; a borderless text
   box sits over its text area showing the date as dd-mm-yyyy. */
.date-dmy {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    max-width: 100%;
}
.date-dmy--full,
.lifecycle-page-form .form-row .date-dmy { display: block; width: 100%; }
.date-dmy--full > input[type="date"] { width: 100%; }
.date-dmy > input[type="date"]::-webkit-datetime-edit { color: transparent; }
.date-dmy > .date-dmy__text {
    position: absolute;
    margin: 0;
    padding-top: 0;
    padding-bottom: 0;
    padding-right: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    outline: none;
    min-width: 0;
    width: auto;
    height: auto;
}
.date-dmy > .date-dmy__text:focus { outline: none; box-shadow: none; }
.date-dmy:focus-within > input[type="date"] {
    border-color: var(--color-accent-2);
    box-shadow: var(--shadow-focus);
}

/* ---------------------------------------------------------------------
   Theme picker — topbar dropdown, same shape as .topbar-user.
   Every colour here is a token, so the picker itself themes correctly;
   the one exception is --swatch, set inline per button because it has to
   show the accent you would be switching *to*, not the current one.
   ------------------------------------------------------------------ */

.topbar-theme { position: relative; }

.topbar-theme > summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius);
    color: var(--color-text-muted);
    cursor: pointer;
    list-style: none;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.topbar-theme > summary::-webkit-details-marker { display: none; }
.topbar-theme > summary:hover {
    background: var(--color-section);
    color: var(--color-text);
}
.topbar-theme > summary:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
}

.topbar-theme__panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    z-index: 50;
    min-width: 13rem;
    padding: var(--sp-3);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.topbar-theme__label {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-subtle);
}
.theme-modes + .topbar-theme__label { margin-top: var(--sp-4); }

.theme-modes { display: grid; gap: 0.25rem; }

.theme-mode {
    display: block;
    width: 100%;
    padding: 0.4rem 0.6rem;
    text-align: left;
    font: inherit;
    font-size: var(--fs-sm);
    color: var(--color-text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
}
.theme-mode:hover { background: var(--color-section); }
.theme-mode.is-active {
    background: var(--color-accent-soft);
    border-color: var(--color-accent-2);
    font-weight: 600;
}

.theme-accents {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.35rem;
}

.theme-accent {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.1rem;
    font: inherit;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
}
.theme-accent:hover { background: var(--color-section); }
.theme-accent.is-active { border-color: var(--color-border-strong); }

.theme-accent__dot {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: var(--radius-full);
    background: var(--swatch);
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.theme-accent.is-active .theme-accent__dot {
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12),
                0 0 0 2px var(--color-bg),
                0 0 0 4px var(--swatch);
}

/* The names are for the picker only; at five across they would wrap, so
   they carry the label for screen readers and show on hover/focus. */
.theme-accent__name {
    font-size: 0.625rem;
    color: var(--color-text-muted);
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

@media (max-width: 40rem) {
    .topbar-theme__panel { right: -2rem; }
}
