/* ---------- Tokens. --brand is replaced per organization by the layout. ---------- */
/* Shades are re-derived wherever --brand can be overridden: a custom property is resolved where it is declared. */
:root, .shell, .auth {
    --brand-strong: color-mix(in srgb, var(--brand) 82%, #000);
    --brand-soft: color-mix(in srgb, var(--brand) 10%, #fff);
    --brand-softer: color-mix(in srgb, var(--brand) 5%, #fff);
}
:root {
    --brand: #4338ca;
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-2: #eef2f6;
    --surface: #ffffff;
    --bg: #f6f7fb;
    --ok: #047857;
    --ok-soft: #ecfdf5;
    --err: #b91c1c;
    --err-soft: #fef2f2;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgb(15 23 42 / .06);
    --shadow: 0 1px 3px rgb(15 23 42 / .06), 0 8px 24px -12px rgb(15 23 42 / .12);
    --sidebar: 268px;
    --topbar: 64px;
    --bottombar: 64px;
    --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    /* Two-series chart pair, validated together for colour-blind separation (blue, aqua). Aqua is under 3:1 on white,
       so every chart also has a table view. */
    --series-1: #2a78d6;
    --series-2: #1baf7a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.55 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-underline-offset: 2px; }
h1 { font-size: 1.6rem; line-height: 1.25; letter-spacing: -.02em; margin: .25rem 0 1.25rem; font-weight: 700; }
h2 { font-size: 1.1rem; letter-spacing: -.01em; margin: 1.75rem 0 .75rem; font-weight: 650; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; font-weight: 600; }
small { color: var(--muted); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 2px; border-radius: 6px; }
.icon { flex: none; display: block; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--sidebar);
    display: flex; flex-direction: column;
    background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 1rem 1rem .75rem; min-height: var(--topbar); }
.org { display: flex; align-items: center; gap: .75rem; text-decoration: none; color: var(--ink); min-width: 0; }
.org-text { display: flex; flex-direction: column; min-width: 0; }
.org-text strong { font-size: .95rem; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-text small { font-size: .78rem; }

.monogram {
    flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
    background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #fff;
    font-weight: 700; font-size: .95rem; letter-spacing: .02em; box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--brand) 60%, transparent);
}
.monogram.light { background: rgb(255 255 255 / .16); box-shadow: none; border: 1px solid rgb(255 255 255 / .25); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .25rem .75rem 1rem; }
.nav-group { margin-top: .75rem; }
.nav-title { padding: .5rem .75rem .35rem; font-size: .7rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: #94a3b8; }
.nav-item {
    display: flex; align-items: center; gap: .75rem; padding: .6rem .75rem; margin: 2px 0;
    border-radius: var(--radius-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: .93rem;
    transition: background-color .15s, color .15s;
}
.nav-item .icon { color: #94a3b8; transition: color .15s; }
.nav-item:hover { background: var(--line-2); color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
.nav-item.active .icon { color: var(--brand); }
.badge { margin-left: auto; min-width: 22px; padding: 0 .45rem; border-radius: 999px; background: var(--brand); color: #fff; font-size: .72rem; font-weight: 700; line-height: 20px; text-align: center; }

.sidebar-foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .85rem 1rem; border-top: 1px solid var(--line); }
.sidebar-foot form { margin: 0; }
.me { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text strong { font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: .74rem; }
.avatar { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; font-size: .85rem; }
.avatar.small { width: 34px; height: 34px; }

.main { margin-left: var(--sidebar); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 30; height: var(--topbar);
    display: flex; align-items: center; gap: .75rem; padding: 0 1.5rem;
    background: rgb(246 247 251 / .82); backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid transparent;
}
.topbar-title { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.topbar-title strong { font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-org { font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.icon-button {
    position: relative; display: inline-grid; place-items: center; width: 40px; height: 40px; margin: 0; padding: 0;
    border: 1px solid transparent; border-radius: var(--radius-sm); background: transparent; color: var(--ink-2); cursor: pointer; text-decoration: none;
}
.icon-button:hover { background: var(--line-2); color: var(--ink); }
.dot { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: #ef4444; color: #fff; font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center; border: 2px solid var(--bg); }
.chip {
    display: inline-flex; align-items: center; gap: .4rem; padding: .4rem .8rem; border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--ink-2); font-size: .84rem; font-weight: 500; text-decoration: none; box-shadow: var(--shadow-sm);
}
.chip:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); color: var(--brand-strong); }

.menu-button, .drawer-close, .backdrop, .bottombar { display: none; }

.content { width: 100%; max-width: 1120px; margin: 0 auto; padding: 1.25rem 1.5rem 3rem; animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.skeleton { display: grid; gap: .9rem; }
.skeleton div { height: 96px; border-radius: var(--radius); background: linear-gradient(90deg, var(--line-2), #f8fafc, var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
.skeleton div:first-child { height: 36px; width: 40%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Mobile: drawer and bottom bar ---------- */
@media (max-width: 960px) {
    .sidebar { width: min(86vw, 320px); transform: translateX(-102%); transition: transform .25s cubic-bezier(.2, .8, .2, 1); box-shadow: 0 0 40px rgb(15 23 42 / .2); }
    .drawer-open .sidebar { transform: none; }
    .drawer-close, .menu-button { display: inline-grid; }
    .backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgb(15 23 42 / .4); opacity: 0; pointer-events: none; transition: opacity .2s; }
    .drawer-open .backdrop { opacity: 1; pointer-events: auto; }
    .main { margin-left: 0; }
    .topbar { padding: 0 .75rem; background: var(--surface); border-bottom-color: var(--line); }
    .topbar .chip span, .profile-name { display: none; }
    .topbar .chip { padding: .5rem; }
    .content { padding: 1rem 1rem calc(var(--bottombar) + 1.5rem + env(safe-area-inset-bottom)); }
    h1 { font-size: 1.35rem; }

    .bottombar {
        display: flex; position: fixed; inset: auto 0 0 0; z-index: 30;
        height: calc(var(--bottombar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
        background: rgb(255 255 255 / .94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
    }
    .bottombar a, .bottombar button {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; margin: 0; padding: 0;
        border: 0; border-radius: 0; background: none; color: var(--muted); font: 500 .7rem/1 var(--font); text-decoration: none; cursor: pointer;
    }
    .bottom-icon { position: relative; display: grid; place-items: center; width: 56px; height: 30px; border-radius: 999px; transition: background-color .15s; }
    .bottom-icon .dot { top: 2px; right: 12px; min-width: 10px; height: 10px; padding: 0; border-width: 2px; border-color: #fff; }
    .bottombar .active { color: var(--brand-strong); font-weight: 650; }
    .bottombar .active .bottom-icon { background: var(--brand-soft); }
}

/* ---------- Sign-in pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(380px, 46%) minmax(0, 1fr); }
.auth-hero {
    position: relative; overflow: hidden; color: #fff; padding: 3rem;
    background:
        radial-gradient(circle at 15% 15%, rgb(255 255 255 / .16), transparent 40%),
        radial-gradient(circle at 85% 90%, rgb(255 255 255 / .1), transparent 45%),
        linear-gradient(150deg, var(--brand) 0%, var(--brand-strong) 100%);
    display: flex; align-items: center;
}
.auth-hero::after { content: ""; position: absolute; width: 420px; height: 420px; right: -140px; top: -140px; border-radius: 50%; border: 60px solid rgb(255 255 255 / .06); }
.auth-hero-inner { position: relative; z-index: 1; max-width: 440px; }
.auth-hero h2 { font-size: 2.1rem; line-height: 1.15; letter-spacing: -.03em; margin: 2.5rem 0 .75rem; font-weight: 700; }
.auth-hero p { color: rgb(255 255 255 / .82); font-size: 1.05rem; margin: 0 0 2rem; }
.auth-hero ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .85rem; }
.auth-hero li { display: flex; align-items: center; gap: .7rem; color: rgb(255 255 255 / .92); }
.auth-brand { display: inline-flex; align-items: center; gap: .7rem; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.auth-main { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 2rem 1.25rem; }
.auth-main > .card { width: 100%; max-width: 420px; margin: 0; padding: 2rem; border: 1px solid var(--line); box-shadow: var(--shadow); }
.auth-main h1 { margin-top: 0; }
.auth-main .primary { width: 100%; justify-content: center; padding: .8rem 1rem; }
.auth-foot { display: flex; align-items: center; gap: .4rem; margin-top: 1.5rem; color: var(--muted); font-size: .8rem; }

.auth-main > .card > h1 + .muted { margin-top: -.35rem; }

/* Phones and small tablets: the brand panel becomes a short header and the card sits over its lower edge. */
@media (max-width: 860px) {
    .auth { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100dvh; }
    .auth-hero { display: block; padding: calc(1.25rem + env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 4.25rem max(1.25rem, env(safe-area-inset-left)); }
    .auth-hero::after { width: 240px; height: 240px; right: -90px; top: -110px; border-width: 38px; }
    .auth-hero-inner { max-width: 420px; margin: 0 auto; }
    .auth-hero h2 { font-size: 1.45rem; margin: 1.6rem 0 .35rem; }
    .auth-hero p { font-size: .95rem; margin: 0; }
    .auth-hero ul { display: none; }
    .auth-main { justify-content: flex-start; padding: 0 1rem calc(1.25rem + env(safe-area-inset-bottom)); }
    .auth-main > .card { position: relative; margin-top: -2.75rem; padding: 1.5rem 1.25rem; }
    /* The footer sits at the bottom of the screen, not straight under the card. */
    .auth-foot { display: block; margin-top: auto; padding-top: 1.5rem; text-align: center; }
    .auth-foot .icon { display: inline-block; vertical-align: -2px; margin-right: .2rem; }
}

/* Tall phones have room to say what the portal is for. */
@media (max-width: 860px) and (min-height: 760px) and (orientation: portrait) {
    .auth-hero ul { display: grid; gap: .45rem; margin-top: 1.1rem; }
    .auth-hero li { gap: .5rem; font-size: .88rem; }
    .auth-hero li .icon { width: 16px; height: 16px; flex: none; }
}

/* Phones on their side: keep the form in view, the header shrinks to the brand alone. */
@media (max-width: 960px) and (max-height: 500px) and (orientation: landscape) {
    .auth-hero { padding-bottom: 3.25rem; padding-top: calc(.9rem + env(safe-area-inset-top)); }
    .auth-hero h2, .auth-hero p { display: none; }
    .auth-main > .card { margin-top: -2rem; }
}

/* ---------- Building blocks used across the pages ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow-sm); }
.narrow { max-width: 440px; margin: 2rem auto; }
.doc > * { margin: .2rem 0; }
.unread { border-left: 4px solid var(--brand); background: linear-gradient(90deg, var(--brand-softer), var(--surface) 40%); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .9rem; margin-bottom: 1.25rem; }
.tile {
    position: relative; overflow: hidden; display: flex; flex-direction: column; gap: .2rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow-sm);
}
.tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--brand); opacity: .7; }
.tile span, .muted { color: var(--muted); font-size: .88rem; }
.tile span { font-weight: 500; }
.tile strong { font-size: 1.35rem; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile strong a { text-decoration: none; }

.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; padding: .55rem 0; border-bottom: 1px solid var(--line-2); }
.row:last-child { border-bottom: 0; }
.row label { flex: 1 1 160px; margin: 0; }

label { display: block; margin: .75rem 0; font-size: .88rem; font-weight: 500; color: var(--ink-2); }
input, select, textarea {
    display: block; width: 100%; margin-top: .35rem; padding: .65rem .8rem; font: inherit; font-size: 1rem; color: var(--ink);
    background: var(--surface); border: 1px solid #cbd5e1; border-radius: var(--radius-sm); transition: border-color .15s, box-shadow .15s;
}
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 .4rem 0 0; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 15%, transparent); }

button, .button {
    display: inline-flex; align-items: center; gap: .45rem; margin: .25rem .25rem .25rem 0; padding: .6rem 1rem;
    font: inherit; font-size: .92rem; font-weight: 550; color: var(--ink-2); text-decoration: none; cursor: pointer;
    background: var(--surface); border: 1px solid #cbd5e1; border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
    transition: background-color .15s, border-color .15s, transform .05s;
}
button:hover, .button:hover { background: var(--line-2); }
button:active, .button:active { transform: translateY(1px); }
.primary, button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--brand) 70%, transparent); }
.primary:hover, button.primary:hover, .button.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
button:disabled { opacity: .5; cursor: default; transform: none; }

.ok { color: var(--ok); }
.error { color: var(--err); }
p.ok, p.error { padding: .65rem .85rem; border-radius: var(--radius-sm); font-size: .9rem; }
p.ok { background: var(--ok-soft); }
p.error { background: var(--err-soft); }
.space { margin-left: 1rem; }
.staff { background: var(--brand-softer); border: 1px solid var(--brand-soft); padding: .6rem .75rem; border-radius: var(--radius-sm); }
.wide { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
th, td { padding: .6rem .5rem; border-bottom: 1px solid var(--line-2); }

/* DevExpress grids sit inside our cards rather than on their own grey slab. */
.dxbl-grid { border-radius: var(--radius) !important; overflow: hidden; border-color: var(--line) !important; box-shadow: var(--shadow-sm); }

/* ---------- Overview dashboard ---------- */
.overview-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.overview-head h1 { margin: 0; }
.overview-head p { margin: .15rem 0 0; }

.account-switch { display: flex; gap: .6rem; overflow-x: auto; padding: .15rem .1rem .6rem; margin-bottom: .6rem; scrollbar-width: thin; }
.account-pill {
    flex: none; display: flex; align-items: center; gap: .65rem; margin: 0; padding: .5rem .95rem .5rem .5rem;
    border: 1px solid var(--line); border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-sm); text-align: left;
}
.account-pill:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--surface); }
.account-pill.active { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.pill-avatar { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; font-size: .8rem; }
.account-pill.active .pill-avatar { background: var(--brand); color: #fff; }
.pill-avatar.light { background: rgb(255 255 255 / .18); color: #fff; border: 1px solid rgb(255 255 255 / .25); width: 40px; height: 40px; }
.pill-text { display: flex; flex-direction: column; line-height: 1.2; }
.pill-text strong { font-size: .88rem; color: var(--ink); white-space: nowrap; }
.pill-text small { font-size: .75rem; }

.hero-row { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr); gap: 1rem; margin-bottom: 1rem; }
.hero {
    position: relative; overflow: hidden; color: #fff; border-radius: calc(var(--radius) + 4px); padding: 1.5rem 1.6rem 1.25rem;
    background:
        radial-gradient(circle at 100% 0%, rgb(255 255 255 / .18), transparent 45%),
        linear-gradient(135deg, var(--brand) 0%, var(--brand-strong) 100%);
    box-shadow: 0 18px 40px -22px color-mix(in srgb, var(--brand) 80%, transparent);
}
.hero::after { content: ""; position: absolute; width: 260px; height: 260px; right: -90px; bottom: -120px; border-radius: 50%; border: 40px solid rgb(255 255 255 / .07); }
.hero > * { position: relative; z-index: 1; }
.hero-top { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.hero-label { font-size: .85rem; color: rgb(255 255 255 / .8); font-weight: 500; }
.hero-amount { font-size: 2.3rem; font-weight: 750; letter-spacing: -.03em; line-height: 1.15; margin: .2rem 0; font-variant-numeric: tabular-nums; }
.shimmer-text { color: transparent; background: linear-gradient(90deg, rgb(255 255 255 / .15), rgb(255 255 255 / .35), rgb(255 255 255 / .15)); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; animation: shimmer 1.2s infinite linear; }
.hero-note { display: inline-block; font-size: .8rem; font-weight: 600; padding: .2rem .6rem; border-radius: 999px; background: rgb(255 255 255 / .16); }
.hero-account { display: flex; align-items: center; gap: .65rem; align-self: flex-start; padding: .45rem .8rem .45rem .45rem; border-radius: 999px; background: rgb(255 255 255 / .1); }
.hero-account span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.hero-account strong { font-size: .88rem; }
.hero-account small { color: rgb(255 255 255 / .75); font-size: .75rem; }

.ageing-bar { display: flex; gap: 3px; height: 10px; margin: 1.25rem 0 .6rem; border-radius: 999px; overflow: hidden; background: rgb(255 255 255 / .15); }
.ageing-bar .seg { min-width: 6px; }
.ageing-legend { display: flex; flex-wrap: wrap; gap: .35rem 1rem; font-size: .78rem; color: rgb(255 255 255 / .85); }
.ageing-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.ageing-legend strong { color: #fff; font-variant-numeric: tabular-nums; }
.ageing-legend i { width: 8px; height: 8px; border-radius: 2px; }
.t-current { background: #a5b4fc; } .hero .t-current { background: rgb(255 255 255 / .85); }
.t-30 { background: #fcd34d; } .t-60 { background: #fb923c; } .t-90 { background: #f87171; } .t-over { background: #dc2626; } .t-ok { background: #10b981; }

.hero { display: flex; flex-direction: column; }
.hero-actions { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-top: auto; padding-top: 1.1rem; }
.hero-link { display: inline-flex; align-items: center; gap: .35rem; color: #fff; font-size: .88rem; font-weight: 600; text-decoration: none; opacity: .92; }
.hero-link:hover { opacity: 1; text-decoration: underline; }

.facts { display: grid; gap: .6rem; align-content: start; }
.fact {
    display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; color: var(--ink); text-decoration: none;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
a.fact:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.fact > span:last-child { display: flex; flex-direction: column; line-height: 1.25; }
.fact small { font-size: .78rem; }
.fact strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.fact-icon { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--brand-soft); color: var(--brand-strong); }

.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.dash-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.dash-card > header { display: flex; align-items: center; gap: .6rem; padding: .85rem 1rem .6rem; }
.dash-card h2 { margin: 0; font-size: .95rem; }
.dash-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--brand-soft); color: var(--brand-strong); }
.count { min-width: 22px; padding: 0 .45rem; border-radius: 999px; background: var(--brand); color: #fff; font-size: .72rem; font-weight: 700; line-height: 20px; text-align: center; }
.dash-link { margin-left: auto; display: inline-flex; align-items: center; gap: .25rem; font-size: .8rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.dash-link:hover { text-decoration: underline; }
.dash-body { padding: 0 1rem .85rem; }
.empty { margin: .25rem 0 .2rem; color: var(--muted); font-size: .88rem; }
.line-skeleton { display: grid; gap: .55rem; padding: .25rem 0 .35rem; }
.line-skeleton span { height: 34px; border-radius: 8px; background: linear-gradient(90deg, var(--line-2), #f8fafc, var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: .75rem; padding: .6rem 0; border-top: 1px solid var(--line-2); }
.list li:first-child { border-top: 0; }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.list-main strong { font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-main small { font-size: .77rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.amount { font-size: .88rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.credit { color: var(--ok); }
.icon-button.small { width: 32px; height: 32px; }
.unread-item .list-main strong::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: .4rem; border-radius: 50%; background: var(--brand); vertical-align: middle; }

.status { flex: none; padding: .15rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.status.ok { background: #d1fae5; color: #065f46; }
.status.wait { background: #fef3c7; color: #92400e; }
.status.bad { background: #fee2e2; color: #991b1b; }
.grade { flex: none; display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 .4rem; border-radius: 9px; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; font-size: .85rem; }

.timeline .time { flex: none; width: 46px; font-size: .78rem; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline li.now { background: var(--brand-softer); margin: 0 -1rem; padding-left: 1rem; padding-right: 1rem; box-shadow: inset 3px 0 0 var(--brand); }

.attendance { display: grid; gap: .55rem; padding-top: .2rem; }
.att-row { display: grid; grid-template-columns: 70px 1fr 28px; align-items: center; gap: .6rem; font-size: .85rem; }
.att-row strong { text-align: right; font-variant-numeric: tabular-nums; }
.att-bar { height: 8px; border-radius: 999px; background: var(--line-2); overflow: hidden; }
.att-bar span { display: block; height: 100%; border-radius: 999px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; font-size: .88rem; padding-top: .2rem; }
.kv span { color: var(--muted); }
.kv strong { font-weight: 600; }

@media (max-width: 960px) {
    .hero-row { grid-template-columns: minmax(0, 1fr); }
    .facts { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .hero-amount { font-size: 2rem; }
    .dash-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Charts. SVG draws the grid and line; text, dots and tooltips are HTML so they never scale with the plot. ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.chart-row { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; }
.chart-row.single { grid-template-columns: minmax(0, 1fr); }
.chart-card .dash-body { padding-bottom: .5rem; }

.chart { --plot-h: 180px; padding-top: .35rem; }
.chart-frame { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: .5rem; }
.y-axis { position: relative; height: var(--plot-h); min-width: 34px; }
.y-axis span { position: absolute; right: 0; transform: translateY(-50%); font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1; }
.plot { position: relative; height: var(--plot-h); }
.plot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.plot .grid { stroke: var(--line-2); stroke-width: 1; }
.plot .grid.zero { stroke: var(--line); }
.plot .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .area { opacity: .1; }

.x-axis { position: relative; height: 1.6rem; }
.x-axis span { position: absolute; top: .45rem; transform: translateX(-50%); font-size: .72rem; color: var(--muted); white-space: nowrap; }
.x-axis.bands { display: flex; }
.x-axis.bands span { position: static; transform: none; flex: 1; text-align: center; }

/* Line: the end is marked and labelled; every month answers on hover or focus. */
.end-dot, .hit .point { position: absolute; width: 10px; height: 10px; border-radius: 50%; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px var(--surface); pointer-events: none; }
.end-label { position: absolute; transform: translate(-100%, -170%); font-size: .78rem; font-weight: 650; color: var(--ink); white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums; }
.hits { position: absolute; inset: 0; }
.hit { position: absolute; top: 0; bottom: 0; outline: none; }
.hit .cross { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line); opacity: 0; }
.hit .point { left: 50%; opacity: 0; }
.hit:hover .cross, .hit:focus-visible .cross, .hit:hover .point, .hit:focus-visible .point { opacity: 1; }

/* Bars: capped width, rounded data end, square at the baseline, a 2px gap between neighbours. */
.groups { position: absolute; inset: 0; display: flex; }
.group { flex: 1; display: flex; justify-content: center; align-items: stretch; gap: 2px; padding: 0 4px; }
.bar-hit { position: relative; flex: 0 1 18px; display: flex; align-items: flex-end; outline: none; cursor: default; }
.bar { position: relative; display: block; width: 100%; border-radius: 4px 4px 0 0; transition: box-shadow .15s; }
.bar-hit:hover .bar, .bar-hit:focus-visible .bar { box-shadow: inset 0 0 0 999px rgb(255 255 255 / .2); }
/* The tooltip sits just above the column it describes, so it never covers the title or legend. */
.bar .tip { top: auto; bottom: calc(100% + 6px); transform: translateX(-50%); }
.start .bar .tip { left: 0; transform: none; }
.end .bar .tip { left: auto; right: 0; transform: none; }

/* Tooltip: value first, label second; kept inside the card at the edges. */
.tip {
    position: absolute; z-index: 5; top: -.25rem; left: 50%; transform: translate(-50%, -100%);
    display: none; flex-direction: column; align-items: flex-start; gap: 1px; padding: .4rem .6rem; border-radius: 8px;
    background: var(--ink); color: #fff; white-space: nowrap; box-shadow: var(--shadow); pointer-events: none;
}
.tip strong { font-size: .82rem; font-variant-numeric: tabular-nums; }
.tip small { color: rgb(255 255 255 / .72); font-size: .72rem; }
.hit .tip { top: .25rem; transform: translate(-50%, 0); }
.start .tip { left: 0; transform: translate(0, -100%); }
.end .tip { left: auto; right: 0; transform: translate(0, -100%); }
.hit.start .tip, .hit.end .tip { transform: none; }
.hit:hover .tip, .hit:focus-visible .tip, .bar-hit:hover .tip, .bar-hit:focus-visible .tip { display: flex; }
.hit:focus-visible, .bar-hit:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--brand) 35%, transparent); border-radius: 6px; }

.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin: 0 0 .6rem; font-size: .8rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

.chart-table { margin-top: .35rem; font-size: .82rem; }
.chart-table summary { cursor: pointer; color: var(--muted); font-size: .78rem; width: max-content; }
.chart-table summary:hover { color: var(--brand); }
.chart-table table { margin-top: .5rem; }
.chart-table th, .chart-table td { padding: .35rem .4rem; }
.chart-table tbody th { text-transform: none; letter-spacing: 0; font-size: .82rem; font-weight: 500; color: var(--ink-2); }
.chart-table .num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 960px) {
    .chart-row { grid-template-columns: minmax(0, 1fr); }
    .chart { --plot-h: 160px; }
}

/* ---------- Nav icon tiles, organization logo ---------- */
.nav-item { padding: .4rem .6rem; }
.nav-ico { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--line-2); color: #64748b; transition: background-color .15s, color .15s, box-shadow .15s; }
.nav-item .nav-ico .icon { color: inherit; }
.nav-item:hover .nav-ico { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
.nav-item.active .nav-ico { background: var(--brand); color: #fff; box-shadow: 0 6px 14px -6px color-mix(in srgb, var(--brand) 70%, transparent); }
.org-logo { flex: none; width: 40px; height: 40px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--line); padding: 3px; }
.auth-logo { display: block; width: 64px; height: 64px; object-fit: contain; border-radius: 16px; background: #fff; padding: 6px; box-shadow: 0 8px 24px -10px rgb(15 23 42 / .35); }

/* ---------- Account pills as the picker on every page ---------- */
.account-pill.static, .account-pill.static:disabled { opacity: 1; cursor: default; transform: none; }
.account-pill.skeleton { width: 220px; height: 48px; background: linear-gradient(90deg, var(--line-2), #f8fafc, var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }

/* ---------- Statement ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.page-head h1 { margin-bottom: .1rem; }
.page-head p { margin: 0; font-size: .9rem; }
.page-head .button { flex: none; margin: .35rem 0 0; }

.period-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem; margin: .25rem 0 1rem; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--line-2); border-radius: 12px; }
.chip-toggle { margin: 0; padding: .4rem .85rem; font-size: .85rem; font-weight: 550; color: var(--ink-2); background: transparent; border: 0; border-radius: 9px; box-shadow: none; }
.chip-toggle:hover { background: rgb(255 255 255 / .7); }
.chip-toggle.active { background: var(--surface); color: var(--brand-strong); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.period-text { display: inline-flex; align-items: center; gap: .4rem; font-size: .86rem; }
.date-range { display: flex; align-items: flex-end; gap: .5rem; }
.date-range label { margin: 0; font-size: .75rem; color: var(--muted); }
.date-range input { margin-top: .2rem; padding: .45rem .6rem; font-size: .88rem; }

.summary-strip { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr auto 1.15fr; align-items: stretch; gap: .5rem; margin-bottom: 1rem; transition: opacity .15s; }
.summary-strip.loading { opacity: .55; }
.sum { display: flex; flex-direction: column; gap: .15rem; padding: 1rem 1.1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.sum small { font-size: .78rem; font-weight: 550; color: var(--muted); }
.sum strong { font-size: 1.3rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum > span { font-size: .78rem; align-self: flex-start; }
.sum.closing { background: linear-gradient(135deg, var(--brand), var(--brand-strong)); border-color: transparent; color: #fff; box-shadow: 0 10px 24px -14px color-mix(in srgb, var(--brand) 80%, transparent); }
.sum.closing small, .sum.closing .muted { color: rgb(255 255 255 / .8); }
.sum.closing .status.ok { background: rgb(255 255 255 / .2); color: #fff; }
.sum-op { align-self: center; font-size: 1.1rem; font-weight: 600; color: #94a3b8; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; font-size: 1rem; }
.card-head > .muted { font-size: .82rem; }
.ageing-bar.light { margin: .25rem 0 .7rem; background: var(--line-2); }
.ageing-legend.light { color: var(--ink-2); }
.ageing-legend.light strong { color: var(--ink); }
.ageing-legend .zero { color: #94a3b8; }
.ageing-legend .zero i { opacity: .4; }

.ledger { padding: 1.1rem 0 .5rem; }
.ledger .card-head { padding: 0 1.25rem; }
.ledger .search { margin: 0; flex: 0 1 280px; }
.ledger .search input { margin: 0; padding: .5rem .75rem; font-size: .88rem; background: var(--line-2); border-color: transparent; }
.ledger .search input:focus { background: var(--surface); }
.ledger .empty { display: grid; justify-items: center; gap: .25rem; padding: 2.5rem 1rem; text-align: center; color: #94a3b8; }
.ledger .empty p { margin: 0; color: var(--muted); }
.row-skeleton { height: 44px; margin: .5rem 1.25rem; border-radius: 8px; background: linear-gradient(90deg, var(--line-2), #f8fafc, var(--line-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }

.ledger-table { font-size: .88rem; }
.ledger-table th:first-child, .ledger-table td:first-child { padding-left: 1.25rem; }
.ledger-table th:last-child, .ledger-table td:last-child { padding-right: 1.25rem; }
.ledger-table thead th { padding-top: .4rem; padding-bottom: .5rem; border-bottom: 1px solid var(--line); font-size: .72rem; }
.ledger-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ledger-table td { vertical-align: middle; }
.ledger-table tbody tr:not(.month-row):hover td { background: var(--brand-softer); }
.month-row th { padding-top: .7rem; padding-bottom: .45rem; background: #f8fafc; border-bottom: 1px solid var(--line); color: var(--ink-2); font-size: .74rem; }
.month-row th > span:first-child { font-weight: 700; }
.month-totals { float: right; display: inline-flex; gap: .9rem; font-weight: 600; text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.c-date { width: 64px; }
.c-date .day { display: block; font-size: 1.05rem; font-weight: 700; line-height: 1.1; color: var(--ink); }
.c-date .mon { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.details-in { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.details .what { display: flex; flex-direction: column; min-width: 0; }
.details strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Table cells grow to fit one-line text; width 100% with max-width 0 makes this one take what is left and truncate instead. */
.ledger-table td.details { width: 100%; max-width: 0; }
.details small { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; font-size: .77rem; }
.details .status { font-size: .7rem; padding: .05rem .45rem; }
.kind { flex: none; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 999px; }
.kind.out { background: var(--brand-soft); color: var(--brand-strong); }
.kind.in { background: #d1fae5; color: #047857; }
.ledger-table .credit { color: #047857; }
.ledger-table .bal { font-weight: 600; color: var(--ink); }
.ledger-table tr.reversed td { color: #94a3b8; }
.ledger-table tr.reversed .c-debit, .ledger-table tr.reversed .c-credit, .ledger-table tr.reversed .c-amount { text-decoration: line-through; }
.ledger-table tr.reversed .kind { background: var(--line-2); color: #94a3b8; }
.ledger-table .c-amount { display: none; }
.ledger-foot { margin: .75rem 1.25rem .5rem; font-size: .78rem; }

.hero.balance-only { max-width: 560px; }
.hero.balance-only .hero-note { align-self: flex-start; }

@media (max-width: 960px) {
    .summary-strip { grid-template-columns: 1fr 1fr; }
    .sum-op { display: none; }
}
@media (max-width: 640px) {
    .page-head { flex-direction: column; }
    .page-head .button { width: 100%; justify-content: center; }
    .ledger .card-head { flex-direction: column; align-items: stretch; }
    .ledger .search { flex: none; }
    .ledger-table .c-debit, .ledger-table .c-credit, .ledger-table .c-date { display: none; }
    .ledger-table .c-amount { display: table-cell; }
    .ledger-table { font-size: .84rem; }
    .ledger-table th, .ledger-table td { padding-left: .35rem; padding-right: .35rem; }
    .ledger-table th:first-child, .ledger-table td:first-child { padding-left: .9rem; }
    .ledger-table th:last-child, .ledger-table td:last-child { padding-right: .9rem; }
    .ledger .card-head { padding: 0 .9rem; }
    .details .kind { display: none; }
    .chips { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
    .chip-toggle { flex: none; }
    .sum strong { font-size: 1.1rem; }
    .month-totals { float: none; display: flex; margin-top: .15rem; }
}

/* ---------- Shared: counts on filter chips, inline search, small text ---------- */
.chip-count { margin-left: .35rem; padding: 0 .4rem; border-radius: 999px; background: rgb(15 23 42 / .06); font-size: .72rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.chip-toggle.active .chip-count { background: var(--brand-soft); color: var(--brand-strong); }
.inline-search { position: relative; margin: 0; flex: 0 1 300px; }
.inline-search .icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: #94a3b8; pointer-events: none; }
.inline-search input { margin: 0; padding: .5rem .75rem .5rem 2.2rem; font-size: .88rem; }
.small { font-size: .8rem; }

/* ---------- Documents ---------- */
.doc-list { padding: .35rem 0; }
.doc-list .empty { display: grid; justify-items: center; gap: .25rem; padding: 2.5rem 1rem; text-align: center; color: #94a3b8; }
.doc-list .empty p { margin: 0; color: var(--muted); }
.doc-list .more { display: flex; justify-content: center; padding: .75rem; border-top: 1px solid var(--line-2); }
.doc-row { border-top: 1px solid var(--line-2); }
.doc-row:first-child { border-top: 0; }
.doc-summary {
    display: flex; align-items: center; gap: .85rem; width: 100%; margin: 0; padding: .8rem 1.25rem; text-align: left;
    background: transparent; border: 0; border-radius: 0; box-shadow: none; font-weight: 400; color: var(--ink);
}
.doc-summary:hover { background: var(--brand-softer); }
.doc-summary:active { transform: none; }
.doc-row.open .doc-summary { background: var(--brand-softer); }
.doc-ico { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; }
.doc-ico.out { background: var(--brand-soft); color: var(--brand-strong); }
.doc-ico.in { background: #d1fae5; color: #047857; }
.doc-ico.credit { background: #fef3c7; color: #b45309; }
.doc-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.doc-main strong { font-size: .92rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-main small { font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-tags { display: flex; gap: .35rem; }
.doc-tags .status { display: inline-flex; align-items: center; gap: .25rem; font-size: .7rem; max-width: none; overflow: visible; }
.doc-amount { flex: none; min-width: 120px; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.doc-amount.credit { color: #047857; }
.doc-chevron { flex: none; color: #94a3b8; transition: transform .2s; }
.doc-row.open .doc-chevron { transform: rotate(180deg); color: var(--brand); }
.doc-row.reversed .doc-main strong, .doc-row.reversed .doc-amount { color: #94a3b8; }
.doc-row.reversed .doc-amount { text-decoration: line-through; }

.doc-detail { padding: .5rem 1.25rem 1.25rem calc(1.25rem + 38px + .85rem); background: var(--brand-softer); animation: rise .2s ease-out; }
.lines { margin-bottom: .9rem; font-size: .85rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); border-collapse: separate; border-spacing: 0; overflow: hidden; }
.lines th { padding: .5rem .75rem; font-size: .7rem; background: #f8fafc; }
.lines td { padding: .55rem .75rem; }
.lines tbody tr:last-child td { border-bottom: 0; }
.lines td strong { display: block; font-weight: 550; }
.lines td small { display: block; font-size: .74rem; }
.lines .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-facts { display: flex; flex-wrap: wrap; gap: .9rem; align-items: flex-start; }
.doc-facts dl { margin: 0; display: grid; gap: .3rem; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: .84rem; }
.doc-facts dl > div { display: flex; justify-content: space-between; gap: 2rem; }
.doc-facts dt { color: var(--muted); }
.doc-facts dd { margin: 0; font-weight: 550; font-variant-numeric: tabular-nums; }
.totals { min-width: 240px; margin-left: auto !important; order: 2; }
.totals .total { padding-top: .35rem; border-top: 1px solid var(--line-2); }
.totals .total dt, .totals .total dd { color: var(--ink); font-weight: 700; }
.etims-box { border-color: #a7f3d0 !important; background: #f0fdf4 !important; }
.etims-box a { display: inline-flex; align-items: center; gap: .3rem; font-weight: 600; font-size: .82rem; text-decoration: none; }
.doc-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.doc-actions .button { margin: 0; }

/* ---------- Pay ---------- */
.pay-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.pay-card { padding: 0; overflow: hidden; margin-bottom: 0; }
.pay-balance {
    display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; padding: 1.25rem 1.5rem;
    background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #fff;
}
.pay-balance span { display: flex; flex-direction: column; }
.pay-balance small { font-size: .8rem; color: rgb(255 255 255 / .8); }
.pay-balance strong { font-size: 1.8rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.pay-balance .pay-account { text-align: right; }
.pay-balance .pay-account strong { font-size: .95rem; font-weight: 600; }
.pay-form { padding: 1.25rem 1.5rem 1.5rem; }
.pay-form > label { margin: 1rem 0 .4rem; font-weight: 600; }
.pay-form > label:first-child { margin-top: 0; }
.amount-input, .phone-input { display: flex; align-items: center; gap: .6rem; padding: 0 .9rem; background: var(--surface); border: 1px solid #cbd5e1; border-radius: var(--radius-sm); transition: border-color .15s, box-shadow .15s; }
.amount-input:focus-within, .phone-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 15%, transparent); }
.amount-input input, .phone-input input { margin: 0; padding: .7rem 0; border: 0; box-shadow: none !important; background: transparent; }
.amount-input span { font-weight: 650; color: var(--muted); }
.amount-input input { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.phone-input .icon { color: #94a3b8; }
.phone-input input { font-size: 1.05rem; letter-spacing: .02em; }
.quick-amounts { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.quick-amounts .chip-toggle { background: var(--line-2); }
.quick-amounts .chip-toggle.active { background: var(--brand-soft); color: var(--brand-strong); box-shadow: 0 0 0 1px var(--brand); }
.field-hint, .field-error { display: flex; align-items: center; gap: .3rem; margin: .4rem 0 0; font-size: .8rem; }
.field-hint { color: var(--ok); }
.field-error { color: var(--err); }
.pay-button { width: 100%; justify-content: center; margin: 1.4rem 0 0; padding: .85rem 1rem; font-size: 1rem; }
.pay-note { display: flex; align-items: center; gap: .4rem; margin: .9rem 0 0; font-size: .78rem; color: var(--muted); }
.spinner { width: 16px; height: 16px; border-radius: 999px; border: 2px solid rgb(255 255 255 / .4); border-top-color: #fff; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.stk-status { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 2rem 1.5rem; }
.stk-status h2 { margin: .9rem 0 .35rem; font-size: 1.2rem; }
.stk-status p { margin: 0 0 .4rem; max-width: 380px; }
.stk-status button { margin-top: 1rem; }
.stk-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 999px; }
.stk-status.wait .stk-icon { background: var(--brand-soft); color: var(--brand); animation: pulse 1.6s ease-out infinite; }
.stk-status.ok .stk-icon { background: #d1fae5; color: #047857; }
.stk-status.bad .stk-icon { background: #fee2e2; color: #b91c1c; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 35%, transparent); } 100% { box-shadow: 0 0 0 18px transparent; } }
.stk-steps { display: flex; gap: .4rem; margin: .9rem 0 .8rem; padding: 0; list-style: none; font-size: .78rem; }
.stk-steps li { padding: .3rem .7rem; border-radius: 999px; background: var(--line-2); color: var(--muted); }
.stk-steps li.done { background: #d1fae5; color: #065f46; }
.stk-steps li.now { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }

.pay-side .card h2 { margin: 0 0 .75rem; font-size: 1rem; }
.how ol { margin: 0; padding: 0; list-style: none; display: grid; gap: .85rem; }
.how li { display: flex; gap: .75rem; }
.how li > span { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); font-size: .8rem; font-weight: 700; }
.how li div { display: flex; flex-direction: column; line-height: 1.35; }
.how strong { font-size: .88rem; }
.how small { font-size: .8rem; color: var(--muted); }
.recent .card-head { margin-bottom: .25rem; }
.recent .row-skeleton { margin: .5rem 0; }

@media (max-width: 960px) {
    .pay-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .inline-search { flex: 1 1 100%; }
    .doc-summary { padding: .75rem .9rem; gap: .65rem; }
    .doc-tags { display: none; }
    .doc-amount { min-width: 0; font-size: .88rem; }
    .doc-chevron { display: none; }
    .doc-detail { padding: .5rem .9rem 1rem; }
    .lines th:nth-child(3), .lines td:nth-child(3), .lines th:nth-child(4), .lines td:nth-child(4) { display: none; }
    .totals { margin-left: 0 !important; width: 100%; }
    .doc-actions .button { flex: 1; justify-content: center; }
    .pay-balance { padding: 1.1rem 1.15rem; }
    .pay-balance strong { font-size: 1.5rem; }
    .pay-form { padding: 1.1rem 1.15rem 1.25rem; }
    .stk-steps { flex-direction: column; align-items: center; }
}

/* ---------- School ---------- */
.student-card {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1.25rem; margin-bottom: 1rem; padding: 1.35rem 1.5rem;
    border-radius: var(--radius); color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-strong));
    box-shadow: 0 14px 30px -18px color-mix(in srgb, var(--brand) 80%, transparent);
}
.student-card.skeleton-card { display: block; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm); }
.student-id { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.student-avatar { flex: none; display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: rgb(255 255 255 / .18); border: 1px solid rgb(255 255 255 / .28); font-size: 1.15rem; font-weight: 700; }
.student-id h2 { margin: 0 0 .35rem; font-size: 1.25rem; color: #fff; }
.student-tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.student-tags span { padding: .15rem .6rem; border-radius: 999px; background: rgb(255 255 255 / .16); font-size: .78rem; font-weight: 550; }
.student-stats { display: flex; flex-wrap: wrap; gap: .75rem; }
.student-stats .stat { display: flex; flex-direction: column; gap: .1rem; min-width: 150px; padding: .75rem 1rem; border-radius: 12px; background: rgb(255 255 255 / .12); border: 1px solid rgb(255 255 255 / .18); }
.student-stats small { font-size: .74rem; color: rgb(255 255 255 / .8); }
.student-stats strong { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.student-stats .muted { font-size: .74rem; color: rgb(255 255 255 / .75); }
.meter { display: block; height: 6px; margin-top: .35rem; border-radius: 999px; background: var(--line-2); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.student-stats .meter { background: rgb(255 255 255 / .2); }
.student-stats .meter i { background: #fff; }

.tabs { display: flex; gap: .25rem; margin-bottom: -1px; overflow-x: auto; scrollbar-width: none; position: relative; z-index: 1; }
.tab {
    flex: none; display: inline-flex; align-items: center; gap: .45rem; margin: 0; padding: .65rem 1rem; font-size: .9rem; font-weight: 550; color: var(--muted);
    background: transparent; border: 1px solid transparent; border-bottom: 0; border-radius: 12px 12px 0 0; box-shadow: none;
}
.tab:hover { background: var(--line-2); color: var(--ink); }
.tab:active { transform: none; }
.tab.active { background: var(--surface); color: var(--brand-strong); border-color: var(--line); }
.tab.active .icon { color: var(--brand); }
.tab-panel { border-top-left-radius: 0; min-height: 260px; }
.tab-panel .empty { display: grid; justify-items: center; gap: .25rem; padding: 2.5rem 1rem; text-align: center; color: #94a3b8; }
.tab-panel .empty p { margin: 0; color: var(--muted); }
.tab-panel p.empty { display: block; padding: .5rem 0; text-align: left; }
h3.sub { margin: 1.25rem 0 .5rem; font-size: .8rem; font-weight: 650; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tab-panel > h3.sub:first-child, .fees-grid h3.sub { margin-top: 0; }

.day-picker { display: flex; gap: .4rem; margin-bottom: 1rem; overflow-x: auto; scrollbar-width: none; }
.day-btn { position: relative; flex: none; min-width: 56px; justify-content: center; margin: 0; padding: .5rem .8rem; font-size: .88rem; background: var(--line-2); border: 0; box-shadow: none; }
.day-btn.today::after { content: ""; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; margin-left: -2px; border-radius: 999px; background: var(--brand); }
.day-btn.active { background: var(--brand); color: #fff; }
.day-btn.active.today::after { background: #fff; }
.lessons { margin: 0; padding: 0; list-style: none; }
.lessons li { display: flex; align-items: center; gap: 1rem; padding: .75rem .25rem; border-top: 1px solid var(--line-2); }
.lessons li:first-child { border-top: 0; }
.lessons li.now { margin: 0 -1.25rem; padding-left: 1.5rem; padding-right: 1.5rem; background: var(--brand-softer); box-shadow: inset 3px 0 0 var(--brand); }
.lesson-time { flex: none; width: 58px; display: flex; flex-direction: column; line-height: 1.2; font-variant-numeric: tabular-nums; }
.lesson-time strong { font-size: .92rem; }
.lesson-time small { font-size: .76rem; color: var(--muted); }
.lesson-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; padding-left: 1rem; border-left: 3px solid var(--brand-soft); }
.lesson-main strong { font-weight: 600; }
.lesson-main small { font-size: .8rem; }

.att-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 2rem; margin-bottom: 1.1rem; }
.att-big { display: flex; flex-direction: column; line-height: 1.1; }
.att-big strong { font-size: 2.2rem; font-weight: 750; letter-spacing: -.03em; color: var(--ink); }
.att-big small { font-size: .8rem; color: var(--muted); }
.att-legend { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin: 0; padding: 0; list-style: none; font-size: .85rem; color: var(--ink-2); }
.att-legend li { display: inline-flex; align-items: center; gap: .4rem; }
.att-legend i { width: 10px; height: 10px; border-radius: 3px; }
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; }
.att-day { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 46px; border-radius: 9px; font-size: .85rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.att-day small { font-size: .62rem; font-weight: 600; opacity: .75; }
.present { background: #d1fae5; color: #065f46; }
.late { background: #fef3c7; color: #92400e; }
.absent { background: #fee2e2; color: #991b1b; }
.excused { background: #e0e7ff; color: #3730a3; }
.att-day.none { background: var(--line-2); color: #94a3b8; }
.att-legend i.present { background: #10b981; } .att-legend i.late { background: #f59e0b; } .att-legend i.absent { background: #ef4444; } .att-legend i.excused { background: #818cf8; }
.att-dot { flex: none; width: 10px; height: 10px; border-radius: 999px; }
.att-dot.absent { background: #ef4444; } .att-dot.late { background: #f59e0b; } .att-dot.excused { background: #818cf8; }

.results { font-size: .88rem; }
.results td { vertical-align: middle; }
.results td strong { display: block; font-weight: 600; }
.results td small { display: block; font-size: .77rem; }
.results .num { text-align: right; }
.score { min-width: 180px; }
.score-bar { display: block; height: 8px; margin-bottom: .25rem; border-radius: 999px; background: var(--line-2); overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: inherit; }
.score-bar.good i { background: #10b981; } .score-bar.fair i { background: #f59e0b; } .score-bar.low i { background: #ef4444; }
.score-text { font-weight: 600; font-variant-numeric: tabular-nums; }
.results td .score-text small { display: inline; }
.results .grade { display: inline-grid; place-items: center; min-width: 34px; height: 30px; padding: 0 .4rem; border-radius: 8px; background: var(--brand-soft); color: var(--brand-strong); font-weight: 700; }

.transport-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .9rem; }
.transport { padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.transport.current { border-color: color-mix(in srgb, var(--brand) 40%, var(--line)); box-shadow: 0 0 0 3px var(--brand-softer); }
.transport header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.transport p { margin: .2rem 0 .8rem; font-size: .84rem; }
.trips { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.trips div { display: flex; flex-direction: column; padding: .6rem .75rem; border-radius: 10px; background: var(--line-2); line-height: 1.3; }
.trips small { font-size: .72rem; color: var(--muted); }
.trips strong { font-size: .9rem; }
.trips .muted { font-size: .78rem; }
.transport footer { display: flex; justify-content: space-between; margin-top: .8rem; padding-top: .7rem; border-top: 1px solid var(--line-2); font-size: .88rem; }

.fees-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.fee-list { margin: 0; display: grid; }
.fee-list > div { display: flex; justify-content: space-between; gap: 1rem; padding: .6rem 0; border-bottom: 1px solid var(--line-2); font-size: .9rem; }
.fee-list dt { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.fee-list dt .status { font-size: .7rem; max-width: none; }
.fee-list dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fee-list .total { border-bottom: 0; font-weight: 700; }
.fee-list .total dd { font-size: 1.02rem; }
.fee-list.quiet dd { color: var(--ink-2); font-weight: 500; }
.fee-list.quiet .total dd { font-weight: 650; }

.terms { margin: 0; padding: 0; list-style: none; position: relative; }
.terms li { position: relative; display: flex; align-items: center; gap: 1rem; padding: .8rem 0 .8rem 1.75rem; }
.terms li::before { content: ""; position: absolute; left: 6px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.terms li:first-child::before { top: 50%; } .terms li:last-child::before { bottom: 50%; }
.term-dot { position: absolute; left: 0; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 999px; background: var(--surface); border: 2px solid #cbd5e1; }
.terms li.current .term-dot { border-color: var(--brand); background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.terms .meter { max-width: 260px; }

/* ---------- Student access ---------- */
.access-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 1fr); gap: 1rem; align-items: start; }
.access-card { padding: 0; overflow: hidden; margin-bottom: 0; }
.access-card > .row-skeleton { margin: 1rem 1.25rem; }
.access-head { display: flex; gap: 1rem; padding: 1.35rem 1.5rem; background: var(--line-2); border-bottom: 1px solid var(--line); }
.access-head h2 { margin: .1rem 0 .25rem; font-size: 1.2rem; }
.access-head small { font-size: .78rem; color: var(--muted); font-weight: 550; }
.access-head p { margin: 0; font-size: .9rem; color: var(--ink-2); }
.access-icon { flex: none; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--surface); color: var(--muted); box-shadow: var(--shadow-sm); }
.access-head.ok { background: #ecfdf5; } .access-head.ok .access-icon { background: #10b981; color: #fff; }
.access-head.wait { background: #fffbeb; } .access-head.wait .access-icon { background: #f59e0b; color: #fff; }
.access-head.bad { background: #fef2f2; } .access-head.bad .access-icon { background: #ef4444; color: #fff; }
.access-steps { margin: 0; padding: 1.25rem 1.5rem .5rem; list-style: none; }
.access-steps li { position: relative; display: flex; gap: .9rem; padding-bottom: 1.1rem; }
.access-steps li:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 30px; bottom: 4px; width: 2px; background: var(--line); }
.access-steps li.done:not(:last-child)::before { background: #10b981; }
.step-dot { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; background: var(--line-2); color: var(--muted); font-size: .8rem; font-weight: 700; }
.access-steps li.done .step-dot { background: #10b981; color: #fff; }
.access-steps li.now .step-dot { background: var(--brand); color: #fff; box-shadow: 0 0 0 4px var(--brand-soft); }
.access-steps li.stopped .step-dot { background: #fee2e2; color: #b91c1c; }
.access-steps li div { display: flex; flex-direction: column; line-height: 1.35; padding-top: .2rem; }
.access-steps strong { font-size: .92rem; }
.access-steps small { font-size: .8rem; }
.access-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: 1rem 1.5rem 1.4rem; border-top: 1px solid var(--line-2); }
.access-actions button { margin: 0; }
.consent-check { display: flex; align-items: flex-start; gap: .6rem; width: 100%; margin: 0 0 .5rem; padding: .85rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--brand-softer); font-weight: 400; font-size: .86rem; color: var(--ink-2); cursor: pointer; }
.consent-check input { margin-top: .2rem; }
.danger-link { margin-left: auto !important; color: var(--err); border-color: transparent; background: transparent; box-shadow: none; }
.danger-link:hover { background: var(--err-soft); }
button.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
button.danger:hover { background: #b91c1c; border-color: #b91c1c; }
.confirm { width: 100%; padding: 1rem 1.1rem; border-radius: var(--radius-sm); background: var(--brand-softer); border: 1px solid var(--brand-soft); }
.confirm.danger { background: var(--err-soft); border-color: #fecaca; }
.confirm p { display: flex; flex-direction: column; gap: .2rem; margin: 0 0 .8rem; font-size: .88rem; }
.confirm-buttons { display: flex; flex-wrap: wrap; gap: .5rem; }
.confirm-buttons button { margin: 0; }
.can-see h2 { margin: 0 0 .6rem; font-size: 1rem; }
.can-see h2.never { margin-top: 1.1rem; }
.see-list { margin: 0; padding: 0; list-style: none; display: grid; gap: .45rem; font-size: .88rem; }
.see-list li { display: flex; align-items: center; gap: .55rem; }
.see-list.yes .icon { color: #10b981; }
.see-list.no li { color: var(--muted); }
.see-list.no .icon { color: #ef4444; }
.access-side .card h2 { font-size: 1rem; }
.access-side .how h2 { margin: 0 0 .75rem; }

@media (max-width: 960px) {
    .access-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .student-card { padding: 1.1rem; }
    .student-stats { width: 100%; }
    .student-stats .stat { flex: 1 1 130px; min-width: 0; }
    .fees-grid { grid-template-columns: 1fr; }
    .c-res-date { display: none; }
    .score { min-width: 110px; }
    .lessons li.now { margin: 0 -1rem; padding-left: 1.25rem; padding-right: 1.25rem; }
    .access-head, .access-steps, .access-actions { padding-left: 1.1rem; padding-right: 1.1rem; }
    .danger-link { margin-left: 0 !important; }
}

/* ---------- Top bar menus: notices panel and account menu ---------- */
.menu-anchor { position: relative; }
.menu-scrim { position: fixed; inset: 0; z-index: 40; }
.icon-button.open { background: var(--brand-soft); color: var(--brand-strong); }
/* Collapsed to initials and a chevron; the name slides out on hover, on keyboard focus and while the menu is open. */
.profile-button {
    display: inline-flex; align-items: center; gap: .3rem; margin: 0; padding: .25rem .45rem .25rem .25rem;
    background: transparent; border: 1px solid transparent; border-radius: 999px; box-shadow: none; font-weight: 550; color: var(--ink);
    transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.profile-button:hover, .profile-button.open { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow-sm); }
/* On a page from the avatar menu: tinted like an active nav item, with the avatar filled in the brand colour. */
.profile-button.active { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 25%, transparent); color: var(--brand-strong); }
.profile-button.active .avatar { background: var(--brand); color: #fff; }
.profile-button.active .profile-chevron { color: var(--brand); }
.profile-button:active { transform: none; }
.profile-name {
    max-width: 0; opacity: 0; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: max-width .25s ease, opacity .2s ease, margin .25s ease;
}
.profile-button:hover .profile-name, .profile-button:focus-visible .profile-name, .profile-button.open .profile-name { max-width: 180px; opacity: 1; margin: 0 .15rem 0 .25rem; }
@media (prefers-reduced-motion: reduce) { .profile-name { transition: none; } }
.topbar-actions .icon-button { box-shadow: none; }
.switch-button {
    display: inline-flex; align-items: center; gap: .45rem; height: 40px; padding: 0 .8rem; border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--ink-2); font-size: .86rem; font-weight: 550; text-decoration: none; white-space: nowrap;
    transition: background-color .15s, border-color .15s, color .15s;
}
.switch-button .icon { color: var(--muted); }
.switch-button:hover { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); background: var(--brand-softer); color: var(--brand-strong); }
.switch-button:hover .icon { color: var(--brand); }
@media (max-width: 960px) { .switch-button { height: 36px; padding: 0 .65rem; font-size: .8rem; } }
.switch-short { display: none; }
@media (max-width: 520px) { .switch-long { display: none; } .switch-short { display: inline; } .switch-button { gap: .3rem; padding: 0 .6rem; } }
.popover-actions { display: inline-flex; align-items: center; gap: .15rem; }
.link-button.quiet { color: var(--muted); }
.link-button.quiet:hover { color: var(--err); background: var(--err-soft); }
.profile-chevron { flex: none; color: var(--muted); transition: transform .2s; }
.profile-button.open .profile-chevron { transform: rotate(180deg); }

.popover {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 41; width: 380px; max-width: calc(100vw - 1.5rem);
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 20px 48px -16px rgb(15 23 42 / .28), 0 2px 6px rgb(15 23 42 / .06); overflow: hidden; animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.popover-head { display: flex; align-items: center; justify-content: space-between; padding: .85rem 1rem; border-bottom: 1px solid var(--line-2); }
.popover-head strong { font-size: .95rem; }
.popover-body { max-height: min(70vh, 520px); overflow-y: auto; overscroll-behavior: contain; }
.popover-body .row-skeleton { margin: .6rem 1rem; }
.popover-empty { display: grid; justify-items: center; gap: .2rem; padding: 2.25rem 1rem; text-align: center; color: #94a3b8; }
.popover-empty strong { color: var(--ink); font-size: .92rem; margin-top: .35rem; }
.popover-empty small { color: var(--muted); }
.link-button { margin: 0; padding: .2rem .4rem; background: transparent; border: 0; box-shadow: none; color: var(--brand); font-size: .8rem; font-weight: 600; }
.link-button:hover { background: var(--brand-softer); }

.notice-list { margin: 0; padding: 0; list-style: none; }
.notice-list li { border-top: 1px solid var(--line-2); }
.notice-list li:first-child { border-top: 0; }
.notice { display: flex; align-items: flex-start; gap: .7rem; width: 100%; margin: 0; padding: .85rem 1rem; text-align: left; background: transparent; border: 0; border-radius: 0; box-shadow: none; font-weight: 400; color: var(--ink-2); }
.notice:hover { background: var(--line-2); }
.notice:active { transform: none; }
.notice-dot { flex: none; width: 8px; height: 8px; margin-top: .45rem; border-radius: 999px; background: transparent; }
.notice-list li.unread .notice { background: var(--brand-softer); }
.notice-list li.unread .notice-dot { background: var(--brand); }
.notice-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.notice-top { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; }
.notice-top strong { font-size: .88rem; color: var(--ink); font-weight: 600; }
.notice-list li.unread .notice-top strong { font-weight: 700; }
.notice-top small { flex: none; font-size: .72rem; color: var(--muted); }
.notice-body { font-size: .82rem; line-height: 1.45; color: var(--muted); white-space: pre-line; }
.notice-list li.open .notice-body { color: var(--ink-2); }

.profile-menu { width: 290px; }
.profile-head { display: flex; align-items: center; gap: .75rem; padding: 1rem; background: var(--brand-softer); border-bottom: 1px solid var(--line-2); }
.profile-head .avatar { width: 42px; height: 42px; }
.menu-items { display: flex; flex-direction: column; padding: .35rem; margin: 0; }
.menu-items + .menu-items { border-top: 1px solid var(--line-2); }
.menu-item { display: flex; align-items: center; gap: .7rem; width: 100%; margin: 0; padding: .6rem .7rem; border: 0; border-radius: 9px; background: transparent; box-shadow: none; color: var(--ink-2); font-size: .9rem; font-weight: 500; text-decoration: none; text-align: left; }
.menu-item .icon { color: #94a3b8; }
.menu-item:hover { background: var(--line-2); color: var(--ink); }
.menu-item:hover .icon { color: var(--brand); }
.menu-item:active { transform: none; }
.menu-item.active { background: var(--brand-softer); color: var(--brand-strong); font-weight: 600; }
.menu-item.active .icon { color: var(--brand); }
.danger-item { color: var(--err); }
.danger-item .icon { color: var(--err); }
.danger-item:hover { background: var(--err-soft); color: var(--err); }
.danger-item:hover .icon { color: var(--err); }

/* ---------- Queries ---------- */
.inbox { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 1rem; align-items: start; }
.inbox-list { padding: .75rem 0 .5rem; margin: 0; position: sticky; top: calc(var(--topbar) + 1rem); max-height: calc(100vh - var(--topbar) - 2rem); overflow-y: auto; }
.inbox-filter { display: flex; flex-wrap: nowrap; margin: 0 .75rem .6rem; overflow-x: auto; scrollbar-width: none; }
.inbox-filter .chip-toggle { flex: 1 0 auto; justify-content: center; padding: .4rem .4rem; font-size: .8rem; }
.inbox-filter .chip-count { margin-left: .25rem; }
.inbox-list .row-skeleton { margin: .5rem .75rem; }
.inbox-list .empty { display: grid; justify-items: center; gap: .25rem; padding: 2rem 1rem; color: #94a3b8; text-align: center; }
.inbox-list .empty p { margin: 0; color: var(--muted); }
.thread-list { margin: 0; padding: 0; list-style: none; }
.thread { display: flex; flex-direction: column; align-items: stretch; gap: .25rem; width: 100%; margin: 0; padding: .8rem 1rem; text-align: left; background: transparent; border: 0; border-top: 1px solid var(--line-2); border-radius: 0; box-shadow: none; font-weight: 400; color: var(--ink-2); }
.thread-list li:first-child .thread { border-top: 0; }
.thread:hover { background: var(--line-2); }
.thread:active { transform: none; }
.thread.active { background: var(--brand-softer); box-shadow: inset 3px 0 0 var(--brand); }
.thread-top { display: flex; justify-content: space-between; gap: .75rem; }
.thread-top strong { font-size: .9rem; color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread.replied .thread-top strong { font-weight: 700; }
.thread-top small { flex: none; font-size: .74rem; color: var(--muted); }
.thread-snippet { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .15rem; }
.thread-tags .status { font-size: .7rem; }
.tag { padding: .05rem .5rem; border-radius: 999px; background: var(--line-2); font-size: .7rem; font-weight: 600; color: var(--ink-2); white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }

.inbox-detail { padding: 0; margin: 0; min-height: 420px; display: flex; flex-direction: column; overflow: hidden; }
.detail-head { display: flex; align-items: flex-start; gap: .75rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line-2); }
.detail-head > div { flex: 1; min-width: 0; }
.detail-head h2 { margin: 0 0 .15rem; font-size: 1.1rem; }
.detail-head p { margin: 0; font-size: .82rem; }
.detail-head .back { display: none; flex: none; transform: rotate(180deg); }
.messages { flex: 1; margin: 0; padding: 1.25rem; list-style: none; display: flex; flex-direction: column; gap: .9rem; background: #fafbfd; }
.messages li { display: flex; flex-direction: column; max-width: 78%; }
.messages li.mine { align-self: flex-end; align-items: flex-end; }
.messages li.theirs { align-self: flex-start; }
.bubble { padding: .65rem .9rem; border-radius: 16px; font-size: .9rem; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.mine .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 5px; }
.theirs .bubble { background: var(--surface); border: 1px solid var(--line); color: var(--ink); border-bottom-left-radius: 5px; }
.messages small { margin-top: .25rem; font-size: .72rem; color: var(--muted); }
.reply { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; padding: .9rem 1.25rem 1.1rem; border-top: 1px solid var(--line-2); }
.reply p { width: 100%; margin: 0; }
.reply textarea { flex: 1; margin: 0; min-height: 46px; resize: vertical; }
.reply button { margin: 0; }
.detail-empty { flex: 1; display: grid; place-content: center; justify-items: center; gap: .5rem; padding: 3rem 1rem; text-align: center; color: #94a3b8; }
.detail-empty p { margin: 0; color: var(--muted); }

.compose { padding: 1rem 1.25rem 1.4rem; }
.field-label { margin: 1rem 0 .4rem; font-weight: 600; }
.compose > .field-label:first-child { margin-top: 0; }
.compose .account-switch { margin-bottom: 0; }
.compose input, .compose textarea { margin-top: 0; }
.about-doc { display: inline-flex; align-items: center; gap: .4rem; margin: .5rem 0 0; padding: .35rem .7rem; border-radius: 999px; background: var(--brand-softer); color: var(--brand-strong); font-size: .84rem; }
.reason-chips { background: transparent; padding: 0; gap: .4rem; }
.reason-chips .chip-toggle { background: var(--line-2); }
.reason-chips .chip-toggle.active { background: var(--brand-soft); color: var(--brand-strong); box-shadow: 0 0 0 1px var(--brand); }
.compose-actions { display: flex; gap: .5rem; margin-top: 1.1rem; }
.compose-actions button { margin: 0; }

@media (max-width: 960px) {
    .inbox { grid-template-columns: 1fr; }
    .inbox-list { position: static; max-height: none; }
    .inbox.has-detail .inbox-list { display: none; }
    .inbox:not(.has-detail) .inbox-detail { display: none; }
    .detail-head .back { display: inline-grid; }
    .messages li { max-width: 90%; }
    .popover { position: fixed; left: .75rem; right: .75rem; top: calc(var(--topbar) + 6px); width: auto; max-width: none; }
}

/* ---------- Profile and contact details ---------- */
.profile-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.25rem; align-items: start; }
.profile-main { min-width: 0; }
.profile-hero {
    display: flex; align-items: center; gap: 1.1rem; margin: 0; padding: 1.4rem 1.5rem;
    background: linear-gradient(135deg, var(--brand-softer), var(--surface) 70%);
}
.avatar.large { width: 64px; height: 64px; font-size: 1.35rem; background: var(--brand); color: #fff; box-shadow: 0 10px 24px -12px color-mix(in srgb, var(--brand) 80%, transparent); }
.profile-hero-text { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: .3rem; }
.profile-hero-text h2 { margin: 0; font-size: 1.3rem; }
.profile-hero-text p { display: inline-flex; align-items: center; gap: .4rem; margin: 0; font-size: .88rem; color: var(--muted); }
.profile-hero-text .tag { font-size: .72rem; padding: .1rem .6rem; background: var(--surface); border: 1px solid var(--line); }
.section-title { margin: 1.6rem 0 .6rem; font-size: 1.02rem; }
.section-sub { margin: -.35rem 0 .75rem; font-size: .86rem; }
.profile-main .account-switch { margin-bottom: 0; }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.field-tile { display: flex; flex-direction: column; gap: .75rem; margin: 0; padding: 1.1rem 1.15rem; transition: border-color .15s, box-shadow .15s; }
.field-tile.editing { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field-head { display: flex; align-items: flex-start; gap: .75rem; }
.field-ico { flex: none; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--brand-soft); color: var(--brand-strong); }
.field-text { min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.field-text strong { font-size: .95rem; }
.field-text small { font-size: .8rem; color: var(--muted); line-height: 1.4; }
.field-pending { display: flex; align-items: flex-start; gap: .45rem; margin: 0; padding: .5rem .7rem; border-radius: var(--radius-sm); background: #fffbeb; color: #92400e; font-size: .82rem; overflow-wrap: anywhere; }
.field-pending .icon { flex: none; margin-top: .1rem; }
.field-edit { align-self: flex-start; margin: auto 0 0; padding: .45rem .8rem; font-size: .85rem; }
.field-form { display: flex; flex-direction: column; gap: .5rem; }
.field-form input { margin: 0; }
.field-form input[aria-invalid="true"] { border-color: var(--err); }
.field-problem { margin: 0; font-size: .8rem; color: var(--err); }
.field-note { margin: 0; font-size: .8rem; color: var(--muted); }
.field-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.field-actions button { margin: 0; }
.profile-sent { display: flex; align-items: center; gap: .5rem; margin: .9rem 0 0; padding: .65rem .9rem; border-radius: var(--radius-sm); background: var(--ok-soft); color: var(--ok); font-size: .88rem; font-weight: 550; }

.request-list { margin: 0; padding: .35rem 0; }
.request-list ol { margin: 0; padding: 0; list-style: none; }
.request-list .row-skeleton { margin: .6rem 1.1rem; }
.request-list .empty { display: grid; justify-items: center; gap: .25rem; padding: 2rem 1rem; color: #94a3b8; text-align: center; }
.request-list .empty p { margin: 0; color: var(--muted); }
.request { display: flex; gap: .8rem; padding: .85rem 1.1rem; border-top: 1px solid var(--line-2); }
.request:first-child { border-top: 0; }
.request-ico { flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--line-2); color: var(--ink-2); }
.request-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.request-top { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.request-top strong { font-size: .9rem; }
.request-value { font-size: .9rem; color: var(--ink); overflow-wrap: anywhere; }
.request-main small { font-size: .76rem; color: var(--muted); }
.request-note { margin-top: .3rem; padding: .45rem .65rem; border-radius: var(--radius-sm); background: var(--err-soft); color: #991b1b; font-size: .82rem; }

.profile-side { display: flex; flex-direction: column; gap: 1rem; position: sticky; top: calc(var(--topbar) + 1rem); }
.side-card { margin: 0; padding: 1.1rem 1.15rem; }
.side-card h3 { margin: 0 0 .75rem; font-size: .98rem; }
.side-card p { margin: 0 0 .8rem; font-size: .86rem; }
.side-card .button { margin: 0; }
.how-steps { margin: 0; padding: 0; list-style: none; display: grid; gap: .85rem; }
.how-steps li { display: flex; gap: .7rem; }
.how-steps li > span { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); font-size: .78rem; font-weight: 700; }
.how-steps div { display: flex; flex-direction: column; gap: .1rem; }
.how-steps strong { font-size: .87rem; }
.how-steps small { font-size: .8rem; color: var(--muted); }

@media (max-width: 1100px) {
    .profile-layout { grid-template-columns: 1fr; }
    .profile-side { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
@media (max-width: 640px) {
    .field-grid { grid-template-columns: 1fr; }
    .profile-hero { padding: 1.1rem; gap: .85rem; }
    .avatar.large { width: 52px; height: 52px; font-size: 1.1rem; }
    .profile-hero-text h2 { font-size: 1.12rem; }
}

.field-current { display: flex; flex-direction: column; gap: .1rem; padding: .55rem .75rem; border-radius: var(--radius-sm); background: var(--line-2); }
.field-current small { font-size: .7rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.field-current strong { font-size: .92rem; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.field-current .muted { font-size: .88rem; }
.field-skeleton { display: block; height: 1.1rem; width: 60%; border-radius: 6px; background: linear-gradient(90deg, #e2e8f0, #f8fafc, #e2e8f0); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }

/* ---------- Alert settings ---------- */
.alerts-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1.25rem; align-items: start; }
.alerts-main { min-width: 0; display: flex; flex-direction: column; gap: 1rem; }
.delivery, .alert-list { margin: 0; }
.delivery { padding: 1.1rem 1.25rem .5rem; }
.delivery h2, .alert-list h2 { margin: 0; font-size: 1.02rem; }
.delivery h2 { margin-bottom: .4rem; }
.delivery-row { display: flex; align-items: center; gap: .8rem; padding: .75rem 0; border-top: 1px solid var(--line-2); }
.delivery h2 + .delivery-row { border-top: 0; }
.delivery-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.delivery-text strong { font-size: .8rem; font-weight: 600; color: var(--muted); }
.delivery-text > span { font-size: .95rem; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.delivery-text > span.muted { font-weight: 500; color: var(--muted); }
.delivery-text small { font-size: .76rem; color: var(--muted); }
.delivery-edit { flex: none; margin: 0; padding: .4rem .75rem; font-size: .84rem; }
.delivery-form { padding: 0 0 .9rem 3.05rem; }
.delivery-form .danger-link { margin: 0 !important; }

.alert-list { padding: 0; overflow: hidden; }
.alert-list ul { margin: 0; padding: 0; list-style: none; }
.alert-list .row-skeleton { margin: .7rem 1.25rem; }
.alert-list .empty { display: grid; justify-items: center; gap: .25rem; padding: 2rem 1rem; color: #94a3b8; text-align: center; }
.alert-list .empty p { margin: 0; color: var(--muted); }
.alert-list-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem .7rem; border-bottom: 1px solid var(--line-2); }
.alert-cols { display: flex; gap: .5rem; }
.alert-cols span { width: 52px; text-align: center; font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.alert-row { display: flex; align-items: flex-start; gap: .85rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line-2); }
.alert-row:first-child { border-top: 0; }
.alert-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .15rem; }
.alert-text strong { font-size: .92rem; }
.alert-text small { font-size: .82rem; color: var(--muted); }
.alert-example { display: inline-flex; align-items: flex-start; gap: .4rem; margin-top: .4rem; padding: .45rem .65rem; border-radius: 10px 10px 10px 3px; background: var(--line-2); font-size: .78rem; line-height: 1.4; color: var(--ink-2); align-self: flex-start; max-width: 100%; }
.alert-example .icon { flex: none; margin-top: .15rem; color: #94a3b8; }
.alert-toggles { flex: none; display: flex; gap: .5rem; padding-top: .1rem; }
.alert-hint { display: flex; align-items: center; gap: .45rem; margin: 0; padding: .75rem 1.25rem; border-top: 1px solid var(--line-2); background: var(--brand-softer); font-size: .84rem; color: var(--ink-2); }

/* A switch, not a checkbox: the state is the point, and it reads on a phone. */
.toggle { width: 52px; display: flex; flex-direction: column; align-items: center; gap: .25rem; margin: 0; padding: .15rem 0; background: transparent; border: 0; box-shadow: none; }
.toggle:hover { background: transparent; }
.toggle:active { transform: none; }
.toggle-track { position: relative; width: 40px; height: 24px; border-radius: 999px; background: #cbd5e1; transition: background-color .18s; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 999px; background: #fff; box-shadow: 0 1px 3px rgb(15 23 42 / .3); transition: transform .18s; }
.toggle.on .toggle-track { background: var(--brand); }
.toggle.on .toggle-thumb { transform: translateX(16px); }
.toggle:focus-visible { outline: none; }
.toggle:focus-visible .toggle-track { box-shadow: 0 0 0 3px var(--brand-soft); }
.toggle:disabled { opacity: .45; cursor: not-allowed; }
.toggle-label { display: none; font-size: .7rem; font-weight: 600; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .toggle-track, .toggle-thumb { transition: none; } }

.know-list { margin: 0; padding: 0; list-style: none; display: grid; gap: .7rem; font-size: .85rem; color: var(--ink-2); }
.know-list li { display: flex; gap: .55rem; }
.know-list .icon { flex: none; margin-top: .1rem; color: var(--brand); }

@media (max-width: 1100px) {
    .alerts-layout { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .alert-cols { display: none; }
    .alert-row { flex-wrap: wrap; padding: .9rem 1rem; }
    .alert-row .request-ico { display: none; }
    .alert-toggles { width: 100%; gap: 1.25rem; }
    .toggle { width: auto; flex-direction: row; gap: .5rem; }
    .toggle-label { display: inline; font-size: .82rem; color: var(--ink-2); }
    .delivery-form { padding-left: 0; }
    .alert-list-head { padding: .9rem 1rem .6rem; }
}

/* ---------- Document lists: quotations, orders, purchase orders, payments to you ---------- */
.li-card { padding: 0; overflow: hidden; }
.li-card .row-skeleton { margin: .8rem 1.1rem; }
.li-card .empty { display: grid; justify-items: center; gap: .25rem; padding: 2.25rem 1rem; color: #94a3b8; text-align: center; }
.li-card .empty p { margin: 0; color: var(--muted); }
.li-row { padding: .9rem 1.1rem; border-top: 1px solid var(--line-2); }
.li-row:first-child { border-top: 0; }
.li-row.open { background: #fafbfd; }
.li-main { display: flex; align-items: flex-start; gap: .8rem; }
.li-ico { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-strong); }
.li-ico.ok { background: var(--ok-soft); color: var(--ok); }
.li-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.li-text strong { font-size: .93rem; overflow-wrap: anywhere; }
.li-text small { font-size: .8rem; }
.li-ref { overflow-wrap: anywhere; }
.li-end { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; text-align: right; }
.li-end strong { font-size: .95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.li-end .status { max-width: none; }
.li-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .7rem 0 0 calc(36px + .8rem); }
.li-actions button { margin: 0; padding: .45rem .8rem; font-size: .85rem; }
.li-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.li-summary > div { display: flex; flex-direction: column; gap: .1rem; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); min-width: 0; }
.li-summary small { font-size: .76rem; }
.li-summary strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.struck { text-decoration: line-through; color: #94a3b8; }
.icon.flip { transform: rotate(180deg); }

.line-items { margin: .8rem 0 0 calc(36px + .8rem); padding: 0; list-style: none; border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface); }
.line-items li { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; padding: .6rem .8rem; border-top: 1px solid var(--line-2); }
.line-items li:first-child { border-top: 0; }
.line-items .row-skeleton { margin: .6rem .8rem; }
.line-items p { margin: 0; padding: .7rem .8rem; }
.line-text { min-width: 0; display: flex; flex-direction: column; gap: .05rem; }
.line-text strong { font-size: .86rem; font-weight: 550; overflow-wrap: anywhere; }
.line-text small { font-size: .77rem; font-variant-numeric: tabular-nums; }
.line-amount { flex: none; font-size: .86rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line-total { background: var(--line-2); font-size: .86rem; font-weight: 650; }

.invoice-form { margin: .8rem 0 0 calc(36px + .8rem); padding: .9rem 1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid label { margin: .4rem 0; }
.invoice-form .muted.small { margin: .4rem 0 .8rem; }

/* ---------- Payment plan ---------- */
.plan-card h2 { margin: 0 0 .5rem; font-size: 1.02rem; }
.instalments { margin: 0; padding: 0; list-style: none; }
.instalments li { display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr) 40px; align-items: end; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--line-2); }
.instalments label { margin: 0; }
.instalment-no { display: grid; place-items: center; width: 28px; height: 28px; margin-bottom: .55rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); font-size: .78rem; font-weight: 700; }
.instalments .icon-button { margin-bottom: .2rem; }
.plan-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin: .75rem 0 .25rem; }
.plan-foot button { margin: 0; }
.plan-total { display: flex; flex-direction: column; align-items: flex-end; }
.plan-total small { font-size: .76rem; }
.plan-total strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
    .li-row { padding: .85rem .9rem; }
    .li-main { flex-wrap: wrap; }
    .li-ico { width: 32px; height: 32px; }
    /* Amount and status drop under the text, lined up with it, so a long number never squeezes the name. */
    .li-end { flex-basis: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; padding-left: calc(32px + .8rem); text-align: left; }
    .li-actions, .line-items, .invoice-form { margin-left: 0; }
    .li-actions button { flex: 1 1 auto; justify-content: center; }
    .li-summary { grid-template-columns: 1fr 1fr; }
    .li-summary > div:last-child { grid-column: 1 / -1; }
    .form-grid { grid-template-columns: 1fr; }
    .instalments li { grid-template-columns: 24px minmax(0, 1fr) 36px; grid-template-areas: "no date x" "no amount x"; row-gap: .4rem; }
    .instalments li > :nth-child(1) { grid-area: no; align-self: start; margin: 1.6rem 0 0; width: 24px; height: 24px; }
    .instalments li > :nth-child(2) { grid-area: date; }
    .instalments li > :nth-child(3) { grid-area: amount; }
    .instalments li > :nth-child(4) { grid-area: x; align-self: start; margin-top: 1.4rem; width: 36px; height: 36px; }
    .plan-card > .primary { width: 100%; justify-content: center; }
}

/* ---------- Responsive foundation: every screen from a 320px phone to a wide monitor ---------- */
/* Mobile browsers count their own toolbars in 100vh; dvh is the space actually visible. */
.shell, .main { min-height: 100dvh; }
@supports not (min-height: 100dvh) { .shell, .main { min-height: 100vh; } }
/* A safety net, not a fix: one stray wide element must never make the whole page slide sideways. clip keeps sticky headers working. */
body { overflow-x: clip; overflow-wrap: break-word; }
img, video, canvas { max-width: 100%; height: auto; }

/* Notches and home bars. Needs viewport-fit=cover (App.razor). Matters most when the portal is installed as an app. */
.topbar { padding-left: max(1.5rem, env(safe-area-inset-left)); padding-right: max(1.5rem, env(safe-area-inset-right)); }
.sidebar { padding-left: env(safe-area-inset-left); }
@media (display-mode: standalone) {
    .topbar { height: calc(var(--topbar) + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
    .sidebar-head { padding-top: calc(1rem + env(safe-area-inset-top)); }
}

/* iOS zooms into any field under 16px when it is tapped. Phones and tablets get no field smaller than that, DevExpress editors
   included. :where keeps the rule at zero specificity so fields drawn larger on purpose, like the M-PESA amount, stay large. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (pointer: coarse), (max-width: 960px) {
    :where(input:not([type=checkbox], [type=radio], [type=range], [type=file]), select, textarea) { font-size: 16px !important; }
    .amount-input input { font-size: 1.6rem !important; }
    .phone-input input { font-size: 1.05rem !important; }
}

/* Touch screens: fingers need bigger targets than a mouse. */
@media (pointer: coarse) {
    .toggle { min-height: 44px; }
    .link-button { min-height: 36px; }
    .chip-toggle, .account-pill { min-height: 40px; }
}
@media (hover: none) {
    /* A tap leaves :hover stuck on touch screens; keep the name tucked away unless the menu is open. */
    .profile-button:hover:not(.open) .profile-name { max-width: 0; opacity: 0; margin: 0; }
}

@media (max-width: 960px) {
    .topbar { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); }
    .content { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
    .bottombar { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
    .popover-body { max-height: calc(100dvh - var(--topbar) - var(--bottombar) - 5.5rem); }
}

/* Small phones (iPhone SE, older Androids). */
@media (max-width: 380px) {
    body { font-size: 14.5px; }
    .content { padding-left: max(.75rem, env(safe-area-inset-left)); padding-right: max(.75rem, env(safe-area-inset-right)); }
    h1 { font-size: 1.25rem; }
    .topbar-actions { gap: .3rem; }
    .topbar .icon-button { width: 36px; height: 36px; }
    .bottombar a, .bottombar button { font-size: .7rem; letter-spacing: -.01em; }
    .bottom-icon { width: 48px; }
}

/* Phones on their side: little height, so the bars get thinner. */
@media (max-height: 500px) and (orientation: landscape) and (max-width: 960px) {
    :root { --topbar: 52px; --bottombar: 52px; }
    .bottom-icon { height: 26px; }
}

/* Large monitors: a little more room, still a comfortable reading width. */
@media (min-width: 1600px) {
    .content { max-width: 1280px; }
}

/* Statement rows on phones: the document number is the point, so it wraps rather than being cut to "Receipt R...". */
@media (max-width: 640px) {
    .details strong { white-space: normal; overflow-wrap: anywhere; }
    .details .status { max-width: none; }
}

/* Narrow top bar: every pixel goes to the page title. The org name is already in the drawer. */
@media (max-width: 400px) {
    .topbar { gap: .5rem; }
    .topbar-org { display: none; }
    .topbar-title strong { font-size: .98rem; }
    .profile-chevron { display: none; }
    .profile-button { padding: .2rem; }
    .switch-button { padding: 0 .55rem; gap: .3rem; }
}
