/* ===== Triniteq Billing — brand theme ===== */
/* .auth-card and #blazor-error-ui draw their own fixed background (a white card over the sign-in photo,
   a yellow bar), so they stay light whatever the theme is. Listing them here re-declares the light
   tokens on the element itself, which beats the dark ones inherited from :root — without repeating the
   palette. They also set `color` explicitly, since that inherits body's already-resolved value. */
:root,
.auth-card,
#blazor-error-ui {
    /* Brand */
    --tq-orange: #E68A48;
    --tq-orange-soft: rgba(230, 138, 72, .14);
    --tq-orange-text: #c9722f;
    --tq-coral: #DD5B61;
    --tq-grey: #55565B;

    /* Surfaces */
    --bg: #F0F2F6;
    --surface: #FFFFFF;
    --panel: #F4F5F8;

    /* Text */
    --text: #101828;
    --text-sub: #344054;
    --muted: #667085;

    /* Lines & status */
    --border: rgba(17, 24, 39, .10);
    --border-strong: rgba(17, 24, 39, .16);
    --success: #22c55e;
    --success-bg: #ecfdf3;
    --success-text: #176a37;
    --error: #ef4444;
    --error-bg: #fef3f2;
    --error-text: #b42318;
    --warn-bg: #fffaeb;
    --warn-text: #b54708;

    /* Surfaces that were previously hardcoded. Tokenised so the dark theme below can restate them —
       a literal #fafbfc row stripe is invisible-to-glaring depending on the mode. */
    --row-alt: #fafbfc;          /* zebra striping on grids */
    --row-nested: #fbfcfe;       /* bundle child rows, nested under their parent */
    --badge-grey-bg: #eef0f4;
    --badge-blue-bg: #e4eefc;
    --badge-blue-text: #1b4f9c;
    --knob: #ffffff;             /* the moving part of a toggle switch */
    --mention-text: #b45309;
    --code-bg: #f5f5f7;

    /* Shape & depth */
    --radius-sm: 7px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(16,24,40,.07), 0 1px 2px rgba(16,24,40,.04);
    --shadow: 0 4px 16px rgba(16,24,40,.08), 0 1px 4px rgba(16,24,40,.04);

    --sidebar-w: 232px;
    --topbar-h: 56px;
}

/* ===== Dark theme =====
   Restates the surface/text/line tokens only — brand orange, status colours and the sidebar are already
   dark-surface colours and carry over unchanged. Applied two ways: [data-theme="dark"] when the user has
   chosen explicitly (set by js/theme.js before first paint, so there is no flash), and the OS preference
   when they have not. The :root:not([data-theme]) guard is what stops a user who picked Light from being
   overridden by a dark OS setting. */
:root[data-theme="dark"] {
    --bg: #14161a;
    --surface: #1b1e24;
    --panel: #22262e;

    --text: #e8eaed;
    --text-sub: #c3c7ce;
    --muted: #949aa4;

    --border: rgba(255, 255, 255, .10);
    --border-strong: rgba(255, 255, 255, .18);

    /* Status colours: same hues, but the tinted backgrounds are rebuilt from alpha so they sit on a dark
       surface instead of glowing against it. */
    --success-bg: rgba(34, 197, 94, .16);
    --success-text: #6ee7a0;
    --error-bg: rgba(239, 68, 68, .16);
    --error-text: #ff9a92;
    --warn-bg: rgba(245, 158, 11, .16);
    --warn-text: #f4c15c;

    --row-alt: rgba(255, 255, 255, .025);
    --row-nested: rgba(255, 255, 255, .04);
    --badge-grey-bg: rgba(255, 255, 255, .09);
    --badge-blue-bg: rgba(96, 165, 250, .18);
    --badge-blue-text: #9ec5fe;
    --knob: #e8eaed;
    --mention-text: #f0b46b;
    --code-bg: #22262e;

    /* Brand text needs lifting: #c9722f on near-black fails contrast. */
    --tq-orange-text: #f0a163;

    /* Shadows do almost nothing on dark surfaces — depth comes from the border instead. */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .40);
    --shadow: 0 4px 16px rgba(0, 0, 0, .45);

    color-scheme: dark;   /* native controls, scrollbars and form widgets follow */
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg: #14161a;
        --surface: #1b1e24;
        --panel: #22262e;
        --text: #e8eaed;
        --text-sub: #c3c7ce;
        --muted: #949aa4;
        --border: rgba(255, 255, 255, .10);
        --border-strong: rgba(255, 255, 255, .18);
        --success-bg: rgba(34, 197, 94, .16);
        --success-text: #6ee7a0;
        --error-bg: rgba(239, 68, 68, .16);
        --error-text: #ff9a92;
        --warn-bg: rgba(245, 158, 11, .16);
        --warn-text: #f4c15c;
        --row-alt: rgba(255, 255, 255, .025);
        --row-nested: rgba(255, 255, 255, .04);
        --badge-grey-bg: rgba(255, 255, 255, .09);
        --badge-blue-bg: rgba(96, 165, 250, .18);
        --badge-blue-text: #9ec5fe;
        --knob: #e8eaed;
        --mention-text: #f0b46b;
        --code-bg: #22262e;
        --tq-orange-text: #f0a163;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .40);
        --shadow: 0 4px 16px rgba(0, 0, 0, .45);
        color-scheme: dark;
    }
}

/* ===== Command palette (Ctrl+K) ===== */
.cmdk-scrim { position: fixed; inset: 0; background: rgba(8, 10, 14, .45); z-index: 60; }
.cmdk {
    position: fixed; z-index: 61; left: 50%; top: 12vh; transform: translateX(-50%);
    width: min(620px, calc(100vw - 32px));
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg); box-shadow: 0 24px 64px rgba(0, 0, 0, .30);
    overflow: hidden; display: flex; flex-direction: column;
}
.cmdk-input { display: flex; align-items: center; gap: 10px; padding: 13px 15px; border-bottom: 1px solid var(--border); }
.cmdk-input svg { width: 17px; height: 17px; color: var(--muted); flex: 0 0 auto; }
.cmdk-input input { flex: 1; border: none; outline: none; background: none; font: inherit; font-size: 1rem; color: var(--text); }
.cmdk-input input::placeholder { color: var(--muted); }

.cmdk-results { max-height: min(52vh, 420px); overflow-y: auto; }
.cmdk-row {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 15px; border: none; background: none; cursor: pointer;
    font: inherit; text-align: left; color: var(--text);
}
.cmdk-row.sel { background: var(--tq-orange-soft); }
.cmdk-kind {
    flex: 0 0 auto; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); border: 1px solid var(--border); border-radius: 20px; padding: 2px 8px;
}
.cmdk-title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-sub { margin-left: auto; color: var(--muted); font-size: .82rem; white-space: nowrap; flex: 0 0 auto; }
.cmdk-empty { padding: 22px 15px; color: var(--muted); text-align: center; }

.cmdk-foot {
    display: flex; gap: 16px; padding: 8px 15px; border-top: 1px solid var(--border);
    background: var(--panel); color: var(--muted); font-size: .78rem;
}
.cmdk kbd {
    border: 1px solid var(--border-strong); border-radius: 4px; padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem; color: var(--muted);
}
@media (max-width: 560px) {
    .cmdk-sub { display: none; }   /* the title is what identifies the hit; the meta is a nicety */
}

/* Row-cap control under a long list */
.show-more {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 14px 4px 4px; font-size: .88rem;
}

/* ===== Skeleton loaders ===== */
.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;
}

.skeleton { --sk: var(--border); }
.sk-box {
    display: inline-block; height: 12px; border-radius: 5px;
    background: linear-gradient(90deg, var(--panel) 25%, var(--sk) 37%, var(--panel) 63%);
    background-size: 400% 100%;
    animation: sk-shimmer 1.4s ease-in-out infinite;
}
@keyframes sk-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.sk-toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.sk-table { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.sk-head, .sk-line { display: flex; gap: 18px; padding: 12px 14px; align-items: center; }
.sk-head { border-bottom: 1px solid var(--border-strong); }
.sk-line + .sk-line, .sk-head + .sk-line { border-top: 1px solid var(--border); }
.sk-cell { height: 11px; }
.sk-head .sk-cell { height: 9px; }

.sk-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.sk-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: block; }
.sk-detail { max-width: 560px; }

/* A skeleton is a hint that something is coming, not an animation worth insisting on. */
@media (prefers-reduced-motion: reduce) {
    .sk-box { animation: none; background: var(--panel); }
}

/* Theme toggle in the topbar */
.theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; padding: 0;
    background: none; border: 1px solid transparent; border-radius: 8px;
    color: var(--muted); cursor: pointer;
}
.theme-toggle:hover { background: var(--panel); color: var(--text-sub); }
.theme-toggle svg { width: 18px; height: 18px; }
/* One button, two glyphs: show whichever represents the mode you would switch TO. */
.theme-toggle .icon-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .theme-toggle .icon-dark { display: block; }
    :root:not([data-theme]) .theme-toggle .icon-light { display: none; }
}

/* Respect a stated preference for less motion — the nav collapse and toggle slides are decorative. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: 'Segoe UI', system-ui, -apple-system, 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 4px; }
h2 { font-size: 1.2rem; font-weight: 650; }
h3 { font-size: 1.02rem; font-weight: 650; margin: 0 0 12px; }
a { color: var(--tq-orange-text); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
h1:focus { outline: none; }

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: #1e2025;
    color: rgba(255,255,255,.80);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    /* align-self keeps the flex row from stretching the sidebar to the (tall) content height, which would
       otherwise defeat position:sticky — on a long page the menu would scroll away instead of staying pinned. */
    align-self: flex-start;
    height: 100vh;
}
.sidebar .app-version {
    margin-top: auto;
    padding: 12px 20px;
    font-size: .72rem;
    letter-spacing: .02em;
    color: rgba(255,255,255,.40);
}
.sidebar .brand {
    display: flex; align-items: center; gap: 8px;
    color: #fff; font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,.07);
    text-decoration: none;
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand img { height: 24px; width: auto; display: block; }
.sidebar .brand .brand-sub { color: rgba(255,255,255,.55); align-self: flex-end; padding-bottom: 2px; }

/* Navigation: collapsible groups, icons, and a scrollbar that's hidden but still scrollable
   so the menu never shows a bar on short viewports. */
.navmenu {
    flex: 1; min-height: 0;
    display: flex; flex-direction: column; gap: 2px;
    padding: 10px 10px 14px;
    overflow-y: auto;
    scrollbar-width: none;          /* Firefox */
}
.navmenu::-webkit-scrollbar { width: 0; height: 0; }  /* WebKit/Chromium */

/* Shared link row (top-level items + group children) */
.navmenu .nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-radius: 8px;
    color: rgba(255,255,255,.78); font-size: .9rem; font-weight: 500; line-height: 1.15;
}
.navmenu .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.navmenu .nav-link.active { background: var(--tq-orange-soft); color: #f5a26a; font-weight: 600; }

.navmenu .ng-icon { display: inline-flex; flex: 0 0 auto; color: rgba(255,255,255,.55); }
.navmenu .nav-link.active .ng-icon { color: #f5a26a; }
.navmenu .ng-icon svg, .navmenu .nav-link > .ng-icon svg { width: 17px; height: 17px; }

/* Collapsible group */
.nav-group { display: flex; flex-direction: column; }
.nav-group-head {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 9px 12px; margin: 0; border: none; background: none; cursor: pointer;
    font: inherit; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: rgba(255,255,255,.50); border-radius: 8px;
}
.nav-group-head:hover { background: rgba(255,255,255,.05); color: rgba(255,255,255,.85); }
.nav-group-head .ng-icon svg { width: 16px; height: 16px; }
.nav-group-head .ng-title { flex: 1; text-align: left; }
.nav-group-head .ng-caret { flex: 0 0 auto; opacity: .65; transition: transform .2s ease; }
.nav-group.open .nav-group-head { color: rgba(255,255,255,.72); }
.nav-group.open .nav-group-head .ng-caret { transform: rotate(180deg); }

/* Smooth height collapse via grid-template-rows (inner element clips the overflow) */
.nav-group-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .22s ease; }
.nav-group.open .nav-group-body { grid-template-rows: 1fr; }
.nav-group-inner { overflow: hidden; display: flex; flex-direction: column; gap: 2px; }
.nav-group-inner .nav-link { padding-left: 38px; font-weight: 500; }
.nav-group-inner .nav-link.active { font-weight: 600; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: var(--topbar-h); background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: flex-end; gap: 16px;
    padding: 0 28px; position: sticky; top: 0; z-index: 5;
}
.topbar .user { font-weight: 600; color: var(--text-sub); }
.topbar .signout { color: var(--muted); font-size: .88rem; }
.topbar-spacer { flex: 1; }
.content { padding: 26px 36px; width: 100%; }

/* Nav drawer toggle — only shown on small screens (see the mobile media query below) */
.nav-burger {
    display: none; align-items: center; justify-content: center;
    width: 38px; height: 38px; margin-left: -6px; padding: 0;
    background: none; border: none; cursor: pointer; color: var(--text-sub); border-radius: 8px;
}
.nav-burger svg { width: 22px; height: 22px; }
.nav-burger:hover { background: var(--panel); }
.nav-scrim { display: none; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: 7px; justify-content: center;
    padding: 8px 15px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font: inherit; font-weight: 600; font-size: .88rem; cursor: pointer; text-decoration: none;
    transition: background .12s, border-color .12s, box-shadow .12s;
    white-space: nowrap; overflow-wrap: normal;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--tq-orange); color: #fff; }
.btn-primary:hover { background: #d97b38; color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text-sub); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--panel); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel); color: var(--text); }
.btn-danger { background: var(--error); color: #fff; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-sm { padding: 5px 10px; font-size: .82rem; }

/* ===== Cards ===== */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 22px 24px;
    margin-bottom: 20px;
}
.card > h3:first-child { margin-top: 0; }

/* Stat tiles */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 16px; margin-bottom: 20px; }
/* Dashboard KPIs: tidy fixed grid on wide screens so 10 tiles sit as even rows of five. */
@media (min-width: 1280px) { .dash-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 15px 18px; }
.stat-card .stat-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 1.4rem; font-weight: 700; color: var(--text); line-height: 1.15; }
.stat-card .stat-value.sm { font-size: 1.05rem; }
.stat-card .stat-sub { font-size: .76rem; color: var(--muted); margin-top: 4px; }
.stat-card.accent { border-left: 3px solid var(--tq-orange-text, #c25e1f); }
.stat-card .ok { color: var(--success-text); }
.stat-card .bad { color: var(--error-text); }

/* Two-column tile grid for cards */
.tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; margin-bottom: 20px; }
.tile-grid > .card { margin-bottom: 0; height: 100%; }
/* Clickable dashboard stat tiles (drill into the matching list/report) */
.stat-link { text-decoration: none; color: inherit; cursor: pointer; transition: box-shadow .15s ease, border-color .15s ease, transform .05s ease; }
.stat-link:hover { border-color: var(--tq-orange); box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.stat-link:active { transform: translateY(1px); }
.tile-grid .span-2 { grid-column: 1 / -1; }
.tile-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1024px) { .tile-grid, .tile-grid.cols-3 { grid-template-columns: 1fr; } }

/* Compact deposit received/awaiting toggle (saves space vs a text button). */
.deposit-toggle { font: inherit; font-size: .82rem; line-height: 1; padding: 4px 8px; border-radius: 6px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); cursor: pointer; white-space: nowrap; }
.deposit-toggle:hover { background: var(--panel); }
.deposit-toggle.received { background: var(--success-bg); color: var(--success-text); border-color: transparent; }
.deposit-toggle[disabled] { opacity: .55; cursor: default; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head-right { display: flex; align-items: center; gap: 18px; }
.header-gp { text-align: right; line-height: 1.2; }
.header-gp .label { display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.header-gp .val { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.header-gp .val small { color: var(--muted); font-weight: 600; font-size: .82rem; }
.page-head .sub { color: var(--muted); margin: 0; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.bulk-bar { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 8px 12px; }
.grid th.sel-col, .grid td.sel-col { width: 34px; text-align: center; padding-left: 10px; padding-right: 6px; }
.spacer { flex: 1; }
.search-input {
    width: 340px; max-width: 100%; padding: 9px 13px; font: inherit; font-size: .9rem;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; border-color: var(--tq-orange); box-shadow: 0 0 0 3px var(--tq-orange-soft); }

/* ===== Tables ===== */
table.grid { width: 100%; border-collapse: collapse; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
table.grid th, table.grid td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: .89rem; }
/* Let long unbreakable content (emails, mandate ids) wrap so a table shrinks to fit its box
   instead of forcing horizontal overflow. Cells that opt into white-space:nowrap are unaffected. */
table.grid td { overflow-wrap: anywhere; }
table.grid thead th { background: var(--panel); color: var(--text-sub); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:nth-child(even) { background: var(--row-alt); }
table.grid tbody tr:hover { background: var(--tq-orange-soft); }
table.grid th.num, table.grid td.num { text-align: right; }
/* A right-hand actions column: just wide enough for its buttons, on one line. */
table.grid th.actions-col, table.grid td.actions-col { width: 1%; white-space: nowrap; text-align: right; }

/* Uniform square icon buttons for row actions — quieter than a row of text buttons. */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
    flex: 0 0 auto; padding: 0; border: 1px solid var(--border-strong); background: var(--surface);
    color: var(--text-sub); border-radius: 7px; cursor: pointer;
    transition: background .12s, color .12s, border-color .12s; }
.icon-btn:hover:not(:disabled) { background: var(--panel); color: var(--text); }
.icon-btn:disabled { opacity: .45; cursor: default; }
.icon-btn.is-on { border-color: var(--tq-orange); background: var(--tq-orange-soft); color: var(--tq-orange-text, #c25e1f); }
.icon-btn.danger:hover:not(:disabled) { color: var(--error-text); border-color: var(--error-text); background: var(--error-bg); }
/* Compact grid: tighter rows for small supporting tables (e.g. deposits). */
table.grid.compact th, table.grid.compact td { padding: 6px 10px; font-size: .85rem; }
/* List grids: full width, fixed layout so the defined column widths hold and long cells ellipsize. */
table.grid.list-table { width: 100%; table-layout: fixed; }
table.grid.list-table td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Sortable headers */
table.grid th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.grid th.sortable:hover { color: var(--text); }
table.grid th.sorted { color: var(--text); }
.sort-arrow { font-size: .68rem; margin-left: 3px; }
.sort-arrow.dim { opacity: .28; }
table.grid th.sortable:hover .sort-arrow.dim { opacity: .55; }

/* Active filter toggle + empty result row */
.btn.active { border-color: var(--tq-orange); color: var(--tq-orange-text); }
table.grid td.empty-cell { text-align: center; color: var(--muted); padding: 28px 14px; }
table.grid tfoot td { background: var(--panel); border-top: 2px solid var(--border-strong); border-bottom: none; padding: 12px 14px; }
.row-link { cursor: pointer; }
/* Clickable rows are reachable by keyboard (tabindex + role="link" in the markup), so they need a focus
   ring — without one, tabbing through a table moves an invisible cursor. :focus-visible rather than
   :focus so a mouse click doesn't leave a ring behind. outline-offset is negative because an outline on
   a table row would otherwise be clipped by the cell borders. */
.row-link:focus-visible {
    outline: 2px solid var(--tq-orange);
    outline-offset: -2px;
    background: var(--tq-orange-soft);
}
table.grid tr.group-head td { background: var(--panel); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
table.grid tr.subtotal td { background: var(--surface); border-top: 1px solid var(--border-strong); }
/* Bundle children: a free included line nested under its parent bundle line. */
table.grid tbody tr.bundle-child-row td { background: var(--row-nested); }
.bundle-child { display: inline-block; padding-left: 16px; color: var(--text-sub); }

/* Compact inputs inside grid rows */
/* Let the item tables overflow so an open combobox dropdown isn't clipped. */
table.grid.items { overflow: visible; }
table.grid.items td { vertical-align: middle; overflow: visible; }
table.grid select, table.grid input {
    width: 100%; padding: 6px 8px; border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); font: inherit; background: var(--surface);
}
table.grid input.cell-num { width: 96px; text-align: right; margin-left: auto; }
/* Hide number spin buttons so the value isn't clipped in the narrow cells. */
table.grid input.cell-num::-webkit-outer-spin-button,
table.grid input.cell-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
table.grid input.cell-num[type=number] { -moz-appearance: textfield; appearance: textfield; }
table.grid select:focus, table.grid input:focus { outline: none; border-color: var(--tq-orange); box-shadow: 0 0 0 3px var(--tq-orange-soft); }

/* Payment-setup choices (customer landing) */
.pay-choices { display:flex; flex-direction:column; gap:12px; margin-top:18px; }
.pay-choice { display:flex; flex-direction:column; gap:2px; padding:16px 18px; border:1px solid var(--border-strong);
    border-radius:10px; text-decoration:none; color:var(--text); background:var(--surface); transition:border-color .12s, box-shadow .12s; }
.pay-choice:hover { border-color:var(--tq-orange); box-shadow:0 0 0 3px var(--tq-orange-soft); }
.pay-choice .pc-title { font-weight:700; font-size:1.02rem; }
.pay-choice .pc-sub { color:var(--muted); font-size:.88rem; }

/* Email-template picker */
.tpl-pick { display:block; width:100%; text-align:left; background:none; border:none; padding:8px 10px; border-radius:6px; cursor:pointer; font:inherit; color:var(--text); }
.tpl-pick:hover { background:var(--panel); }
.tpl-pick.active { background:var(--tq-orange-soft); color:var(--tq-orange-text); font-weight:600; }

/* Template editor: a fixed list beside an editor; the list sticks while the editor scrolls. */
.tpl-layout { display:grid; grid-template-columns:240px minmax(0,1fr); gap:20px; align-items:start; }
.tpl-layout .tpl-list { position:sticky; top:76px; }
.tpl-editor-fields { max-width:880px; }   /* keep edit lines a readable length on wide screens */
.code-area { width:100%; box-sizing:border-box; font-family:ui-monospace,Consolas,monospace; font-size:.85rem;
    line-height:1.5; resize:vertical; min-height:320px; background:var(--panel); }
/* Rich-text editor (RichTextEditor.razor) */
.rte { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.rte:focus-within { border-color: var(--tq-orange); box-shadow: 0 0 0 3px var(--tq-orange-soft); }
.rte-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); }
.rte-toolbar button { min-width: 30px; padding: 4px 8px; border: 1px solid transparent; background: none;
    border-radius: 6px; cursor: pointer; font: inherit; font-size: .85rem; color: var(--text-sub); }
.rte-toolbar button:hover { background: var(--panel); color: var(--text); }
.rte-area { min-height: 120px; max-height: 360px; overflow-y: auto; padding: 10px 12px; outline: none; font: inherit; line-height: 1.5; }
.rte-area:empty:before { content: attr(data-placeholder); color: var(--muted); }
/* Rendered notes (read-only) */
.notes-html :first-child { margin-top: 0; }
.notes-html :last-child { margin-bottom: 0; }

/* @mentions — the inline chip (in the editor and rendered comments) and the autocomplete popup */
.mention { background: var(--tq-orange-soft); color: var(--mention-text); border-radius: 4px; padding: 0 4px; font-weight: 600; white-space: nowrap; }
.mention-pop { position: absolute; z-index: 3000; min-width: 220px; max-width: 340px; max-height: 260px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(17, 24, 39, .16); padding: 4px; }
.mention-opt { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.mention-opt.is-active, .mention-opt:hover { background: var(--panel); }
.mention-opt .mention-name { font-size: .9rem; color: var(--text); }
.mention-opt .mention-email { font-size: .78rem; color: var(--muted); }

/* A cell whose value reveals more detail on hover (native title tooltip). */
.has-tip { cursor: help; text-decoration: underline dotted; text-underline-offset: 3px; text-decoration-color: var(--border-strong); }
.token-chips { display:flex; flex-wrap:wrap; gap:6px; margin:6px 0 0; }
.token-chips code { background:var(--panel); border:1px solid var(--border); border-radius:6px; padding:2px 7px; font-size:.78rem; }
@media (max-width:760px) { .tpl-layout { grid-template-columns:1fr; } .tpl-layout .tpl-list { position:static; } }

/* Deliveries (order detail hardware) */
.deliveries { margin-top: 18px; }
.deliveries-title { margin: 0 0 10px; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.delivery-card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    box-shadow: var(--shadow-sm); margin-bottom: 10px; overflow: hidden; }
.delivery-card .dc-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border); }
.delivery-card .dc-supplier { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.delivery-card .dc-name { font-weight: 700; }
.delivery-card .dc-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.delivery-card .dc-body { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 12px 14px; flex-wrap: wrap; }
.delivery-card ul.dc-items { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 8px; }
.delivery-card ul.dc-items li { background: var(--panel); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: .84rem; }
.delivery-card ul.dc-items .dc-qty { font-weight: 700; color: var(--tq-orange-text); }
.delivery-card .dc-meta { display: flex; align-items: center; gap: 14px; margin-left: auto; font-size: .85rem; white-space: nowrap; }
.delivery-card .dc-track { font-weight: 600; }

/* Xero contact link card + search results */
.xero-contact-card { margin-bottom: 18px; }
.xero-contact-card .card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
ul.xero-results { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto;
    border: 1px solid var(--border); border-radius: var(--radius); }
ul.xero-results li { padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer;
    display: flex; flex-direction: column; gap: 2px; }
ul.xero-results li:last-child { border-bottom: none; }
ul.xero-results li:hover { background: var(--tq-orange-soft); }
ul.xero-results .xr-name { font-weight: 600; }
ul.xero-results .xr-sub { font-size: .82rem; }

/* FilterSelect — styled searchable combobox */
.fsel { position: relative; width: 100%; }
.fsel-input { width: 100%; padding: 6px 26px 6px 8px; border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); font: inherit; background: var(--surface); }
.fsel-input:focus { outline: none; border-color: var(--tq-orange); box-shadow: 0 0 0 3px var(--tq-orange-soft); }
.fsel-caret { position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
    pointer-events: none; color: var(--text-muted); font-size: .75rem; }
.fsel-menu { position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px;
    list-style: none; max-height: 260px; overflow-y: auto; background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-md, 0 8px 24px rgba(0,0,0,.14)); }
.fsel-opt { padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: .9rem;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fsel-opt:hover { background: var(--tq-orange-soft); color: var(--tq-orange-strong, var(--tq-orange)); }

/* Bulk action bar */
.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--tq-orange-soft); border: 1px solid var(--tq-orange); border-radius: var(--radius);
    padding: 10px 14px; margin-bottom: 14px; }
.bulk-bar select, .bulk-bar input[type="number"] { padding: 6px 9px; border: 1px solid var(--border-strong); border-radius: 6px; font: inherit; }
.bulk-bar .check { font-weight: 500; }
table.grid tbody tr.row-selected { background: var(--tq-orange-soft); }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.check { display: inline-flex; gap: 8px; align-items: center; font-weight: 500; cursor: pointer; }
.check input[type="checkbox"] { width: 16px; height: 16px; flex: 0 0 auto; margin: 0; padding: 0; }

/* ===== Forms ===== */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 760px) { .form-grid, .form-grid.cols-3 { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: .84rem; color: var(--text-sub); }
.field input, .field select, .field textarea {
    width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); font: inherit; background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--tq-orange); box-shadow: 0 0 0 3px var(--tq-orange-soft);
}
.form-actions { display: flex; gap: 10px; margin-top: 22px; }
.field .hint { font-size: .76rem; color: var(--muted); }

/* Compact form — denser 3-col grid + smaller controls for header-style detail cards */
.card.tight { padding: 16px 18px; margin-bottom: 16px; }
.card.tight > h3:first-child { font-size: .95rem; margin-bottom: 14px; }
/* Wizard step indicator (new order) */
.wizard-steps { list-style: none; display: flex; gap: 10px; margin: 0 0 18px; padding: 0; flex-wrap: wrap; }
.wizard-steps .wstep { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 180px; cursor: pointer;
    padding: 12px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--muted); }
.wizard-steps .wstep .wnum { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px;
    border-radius: 50%; background: var(--border); color: var(--text-sub); font-weight: 700; font-size: .85rem; flex: 0 0 auto; }
.wizard-steps .wstep .wlabel { font-weight: 600; font-size: .9rem; }
.wizard-steps .wstep.active { border-color: var(--tq-orange); box-shadow: 0 0 0 3px var(--tq-orange-soft); color: var(--text); }
.wizard-steps .wstep.active .wnum { background: var(--tq-orange); color: #fff; }
.wizard-steps .wstep.done { color: var(--text-sub); }
.wizard-steps .wstep.done .wnum { background: var(--tq-green, #2e9e5b); color: #fff; }
@media (max-width: 640px) { .wizard-steps { flex-direction: column; } }

/* Contacts editor (customer form) — compact inputs inside the grid table */
.contacts-edit input[type="text"], .contacts-edit input:not([type]), .contacts-edit input[type="email"] {
    width: 100%; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: 6px; box-sizing: border-box;
}

/* Toggle switch (e.g. GST exempt on the customer form) */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; min-height: 38px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .switch-track { position: relative; flex: 0 0 auto; width: 42px; height: 24px; border-radius: 999px;
    background: var(--border-strong, #c9ced6); transition: background .15s; }
.switch .switch-thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
    background: var(--knob); box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--tq-orange); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--tq-orange-soft); }
.switch .switch-label { font-size: .85rem; font-weight: 600; color: var(--text-sub);
    text-transform: none; letter-spacing: normal; }

/* Selectable option cards (radio-backed, e.g. the send-setup-link recipient chooser) */
.choice { border: 1px solid var(--border-strong); border-radius: 10px; padding: 12px 14px;
    transition: border-color .12s ease, background .12s ease; }
.choice + .choice { margin-top: 10px; }
.choice:hover { border-color: var(--tq-orange); }
.choice.is-selected { border-color: var(--tq-orange); background: var(--tq-orange-soft); }
.choice.is-disabled { opacity: .55; }
.choice.is-disabled:hover { border-color: var(--border-strong); }
.choice-head { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.choice.is-disabled .choice-head { cursor: not-allowed; }
.choice-head input[type="radio"] { flex: 0 0 auto; margin: 2px 0 0; width: 17px; height: 17px; accent-color: var(--tq-orange); }
.choice-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.choice-title { font-weight: 600; color: var(--text); }
.choice-sub { font-size: .82rem; color: var(--muted); line-height: 1.4; word-break: break-word; }
.choice-input { display: block; margin: 10px 0 0 29px; width: calc(100% - 29px); max-width: 340px; }

.form-grid.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid.compact .field { gap: 4px; }
.form-grid.compact .field label { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.form-grid.compact .field input, .form-grid.compact .field select {
    padding: 7px 10px; font-size: .88rem; border-radius: var(--radius-sm);
}
@media (max-width: 980px) { .form-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .form-grid.compact { grid-template-columns: 1fr; } }

/* ===== Badges ===== */
.badge { display: inline-block; min-width: 92px; text-align: center; box-sizing: border-box; padding: 2px 10px; border-radius: 999px; font-size: .76rem; font-weight: 600; white-space: nowrap; overflow-wrap: normal; }
.badge-grey { background: var(--badge-grey-bg); color: var(--text-sub); }
.badge-orange { background: var(--tq-orange-soft); color: var(--tq-orange-text); }
.badge-green { background: var(--success-bg); color: var(--success-text); }
.badge-red { background: var(--error-bg); color: var(--error-text); }
.badge-amber { background: var(--warn-bg); color: var(--warn-text); }
.badge-blue { background: var(--badge-blue-bg); color: var(--badge-blue-text); }

/* ===== New-customer import options (Xero / HubSpot) ===== */
.import-options { display: flex; gap: 12px; }
.import-btn { flex: 1; display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
    cursor: pointer; text-align: left; transition: border-color .12s, box-shadow .12s; }
.import-btn .import-mark { flex: 0 0 auto; display: inline-flex; }
.import-btn .import-text { display: flex; flex-direction: column; line-height: 1.25; }
.import-btn .import-text strong { font-size: .95rem; color: var(--text); }
.import-btn .import-text small { color: var(--text-sub); font-size: .78rem; }
.import-xero:hover { border-color: #13B5EA; box-shadow: 0 0 0 3px rgba(19, 181, 234, .15); }
.import-hubspot:hover { border-color: #FF7A59; box-shadow: 0 0 0 3px rgba(255, 122, 89, .15); }
.import-or { display: flex; align-items: center; text-align: center; color: var(--text-sub);
    font-size: .8rem; margin: 16px 0 10px; }
.import-or::before, .import-or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.import-or span { padding: 0 12px; }

/* ===== Notes / alerts ===== */
.note { padding: 11px 14px; border-radius: var(--radius-sm); margin: 14px 0; font-size: .9rem; }
.note.success { background: var(--success-bg); color: var(--success-text); }
.note.error { background: var(--error-bg); color: var(--error-text); }

/* Lightweight CSS bar chart. */
.barchart { display: flex; align-items: stretch; gap: 4px; width: 100%; }
.barchart .bc-col { flex: 1 1 0; display: flex; flex-direction: column; min-width: 0; }
.barchart .bc-bar-wrap { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; border-bottom: 1px solid var(--border); }
.barchart .bc-bar { width: 74%; max-width: 28px; min-height: 3px; border-radius: 3px 3px 0 0; transition: height .25s; }
.barchart .bc-val { font-size: .66rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.barchart .bc-xlabel { margin-top: 6px; font-size: .66rem; color: var(--muted); text-align: center; overflow: hidden; white-space: nowrap; }
.chart-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .88rem; background:
    repeating-linear-gradient(0deg, transparent, transparent 31px, var(--border) 31px, var(--border) 32px); border-radius: var(--radius-sm); }

/* Tab bar for combined pages (Catalogue, Access, Communications). Underline style rather than pills, so
   it reads as "sections of this page" rather than a filter control. */
/* The baseline is an inset shadow rather than a border, and the tabs carry no negative margin, so nothing
   overflows the strip. The earlier version used border-bottom + margin-bottom:-1px, which spilled 1px past
   the box — and because overflow-x:auto forces a `visible` overflow-y to compute to auto, that 1px raised a
   stray vertical scrollbar on the tab row. Clipping it with overflow-y:hidden would have shaved the active
   tab's underline instead, so the overflow is removed at the source. */
.tabstrip {
    display: flex; gap: 2px; margin-bottom: 20px;
    box-shadow: inset 0 -1px 0 var(--border);
    overflow-x: auto; overflow-y: hidden;
}
.tabstrip-tab {
    appearance: none; background: none; border: none; cursor: pointer;
    padding: 10px 15px; font: inherit; font-size: .92rem; font-weight: 600; color: var(--muted);
    border-bottom: 2px solid transparent; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 7px; transition: color .15s, border-color .15s;
}
.tabstrip-tab:hover { color: var(--text-sub); }
.tabstrip-tab.active { color: var(--tq-orange-text); border-bottom-color: var(--tq-orange); }
.tabstrip-tab:focus-visible { outline: 2px solid var(--tq-orange); outline-offset: -2px; border-radius: 3px 3px 0 0; }
.tabstrip-badge {
    background: var(--panel); color: var(--muted); border-radius: 999px;
    padding: 1px 7px; font-size: .74rem; font-weight: 600;
}
.tabstrip-tab.active .tabstrip-badge { background: var(--tq-orange-soft); color: var(--tq-orange-text); }

/* Index/landing pages (Reports, Settings). Grouped panels of rows rather than a card grid: an auto-fill
   grid strands 3–4 empty columns beside a two-item group on a wide screen, and a one-item group renders as
   a lone narrow box. Rows fill their panel at any width, and the panels themselves column-balance. */
.index-columns { columns: 2; column-gap: 20px; max-width: 1500px; }
.index-section {
    break-inside: avoid; -webkit-column-break-inside: avoid;
    display: inline-block; width: 100%; margin: 0 0 20px;
}
.index-section > h2 {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
    font-weight: 700; margin: 0 0 9px; padding-left: 2px;
}
.index-panel {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
a.index-row {
    display: flex; align-items: flex-start; gap: 13px; text-decoration: none;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    transition: background .13s;
}
.index-panel > a.index-row:last-child { border-bottom: none; }
a.index-row:hover { background: var(--panel); }
a.index-row:focus-visible { outline: 2px solid var(--tq-orange); outline-offset: -2px; }
a.index-row .ir-icon {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: 9px;
    background: var(--tq-orange-soft); color: var(--tq-orange-text);
    display: flex; align-items: center; justify-content: center;
}
a.index-row .ir-icon svg { width: 18px; height: 18px; }
a.index-row .ir-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
a.index-row .ir-title { font-weight: 640; color: var(--text); font-size: .93rem; }
a.index-row .ir-desc { color: var(--muted); font-size: .82rem; line-height: 1.45; }
a.index-row .ir-go {
    flex: 0 0 auto; align-self: center; color: var(--border-strong);
    transition: transform .15s, color .15s;
}
a.index-row .ir-go svg { width: 16px; height: 16px; display: block; }
a.index-row:hover .ir-go { color: var(--tq-orange); transform: translateX(2px); }

@media (max-width: 1100px) { .index-columns { columns: 1; } }

/* Forecast variance: ahead of target reads green, behind reads red, on the nose stays neutral. */
.var-up { color: var(--success-text); font-weight: 600; }
.var-down { color: var(--error-text); font-weight: 600; }
.var-flat { color: var(--muted); }
/* An attainment bar drawn inside a table cell, clamped so a big over-attainment doesn't blow out the column. */
.attain { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.attain .attain-track { position: relative; width: 64px; height: 6px; border-radius: 3px; background: var(--panel); overflow: hidden; }
.attain .attain-fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; }
.attain .attain-pct { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

/* Line chart (shares the .chart-empty empty-state with the bar chart). */
.linechart { display: flex; flex-direction: column; width: 100%; }
.linechart .lc-area { position: relative; flex: 1; border-bottom: 1px solid var(--border); }
.linechart .lc-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.linechart .lc-line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.linechart .lc-fill { opacity: .10; stroke: none; }
.linechart .lc-dot { position: absolute; width: 7px; height: 7px; border-radius: 50%; transform: translate(-50%, 50%); box-shadow: 0 0 0 2px var(--surface); }
.linechart .lc-val { position: absolute; transform: translateX(-50%); margin-bottom: 11px; font-size: .66rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.linechart .lc-labels { position: relative; height: 1rem; margin-top: 6px; }
.linechart .lc-xlabel { position: absolute; transform: translateX(-50%); font-size: .66rem; color: var(--muted); white-space: nowrap; }

/* Contract-status info banner (admin + portal). */
.contract-banner {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 14px 16px; margin: 0 0 18px; border-radius: var(--radius);
    border: 1px solid var(--tq-orange); background: var(--tq-orange-soft);
}
.contract-banner.ended { border-color: #d1495b; background: rgba(209, 73, 91, .10); }
.contract-banner .cb-icon { font-size: 1.2rem; line-height: 1.4; }
.contract-banner .cb-body { font-size: .9rem; }
.contract-banner .cb-body strong { display: block; margin-bottom: 4px; }
.contract-banner .cb-body ul { margin: 0; padding-left: 18px; }
.contract-banner .cb-body li { margin: 2px 0; }

/* Overdue-invoice follow-up bar: the cycle an invoice is on, what's been done, what happens next.
   Amber while the cycle is still working; red once nothing further will happen on its own. */
.dunning-bar {
    padding: 14px 16px; margin: 0 0 18px; border-radius: var(--radius); font-size: .9rem;
    border: 1px solid var(--tq-orange); border-left-width: 4px; background: var(--tq-orange-soft);
}
.dunning-bar.stalled { border-color: var(--error); background: var(--error-bg); }
.dunning-bar .db-head { display: flex; gap: 12px; align-items: flex-start; }
.dunning-bar .db-icon { font-size: 1.15rem; line-height: 1.3; }
.dunning-bar .db-headline { flex: 1; min-width: 0; }
.dunning-bar .db-headline strong { display: block; }
.dunning-bar .db-sub { color: var(--text-sub); font-size: .85rem; }

.dunning-bar .db-milestones { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.dunning-bar .db-ms-label { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; margin-right: 2px; }
.dunning-bar .db-ms { border: 1px solid var(--border-strong); border-radius: 999px; padding: 1px 9px;
    font-size: .78rem; font-weight: 600; color: var(--muted); }
.dunning-bar .db-ms.sent { border-color: transparent; background: var(--success-bg); color: var(--success-text); }

.dunning-bar .db-steps { list-style: none; margin: 12px 0 0; padding: 0; }
.dunning-bar .db-step { display: flex; gap: 10px; padding: 5px 0; position: relative; }
/* Connector threading the dots together, so the list reads as one sequence rather than loose rows. */
.dunning-bar .db-step:not(:last-child)::before {
    content: ""; position: absolute; left: 9px; top: 25px; bottom: -3px; width: 1px; background: var(--border-strong);
}
.dunning-bar .db-dot { flex: 0 0 19px; height: 19px; margin-top: 1px; border-radius: 999px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .68rem; font-weight: 700; background: var(--badge-grey-bg); color: var(--text-sub); }
.dunning-bar .db-step.done .db-dot { background: var(--success-bg); color: var(--success-text); }
.dunning-bar .db-step.failed .db-dot,
.dunning-bar .db-step.stopped .db-dot { background: var(--error-bg); color: var(--error-text); }
.dunning-bar .db-step.next .db-dot { background: var(--tq-orange); color: #3b1e08; }
.dunning-bar .db-body { min-width: 0; }
.dunning-bar .db-when { margin-right: 8px; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.dunning-bar .db-step.next .db-title { font-weight: 600; }
.dunning-bar .db-detail { margin-top: 1px; color: var(--text-sub); font-size: .84rem; }

.dunning-bar .db-blockers { display: grid; gap: 6px; margin-top: 12px; }
/* Own surface rather than a red tint — the bar itself may already be red. */
.dunning-bar .db-blocker { padding: 8px 11px; border-radius: var(--radius-sm); border-left: 3px solid var(--error);
    background: var(--surface); color: var(--text-sub); font-size: .85rem; }

.errors { color: var(--error-text); font-size: .85rem; margin-top: 8px; }
.empty { color: var(--muted); padding: 28px; text-align: center; background: var(--surface);
    border: 1px dashed var(--border-strong); border-radius: var(--radius); }

/* Two-column detail layout */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: start; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* Order detail: main content + sticky checklist aside */
.order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 0 20px; align-items: start; }
.order-aside { position: sticky; top: 76px; }
@media (max-width: 1100px) {
    .order-layout { grid-template-columns: 1fr; }
    .order-aside { position: static; }
}
.count { font-size: .8rem; font-weight: 600; color: var(--tq-orange-text); background: var(--tq-orange-soft); padding: 2px 9px; border-radius: 999px; margin-left: 6px; }

/* Gross-profit summary */
.gp .gp-row { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
.gp .gp-row:last-of-type { border-bottom: none; }
.gp .gp-row.total { font-size: 1.05rem; border-top: 2px solid var(--border-strong); margin-top: 4px; padding-top: 12px; border-bottom: none; }
.progress { height: 7px; background: var(--panel); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress .bar { height: 100%; background: var(--tq-orange); border-radius: 999px; transition: width .2s; }

/* Checklist */
ul.checklist { list-style: none; margin: 10px 0 0; padding: 0; }
ul.checklist li { display: flex; align-items: center; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); }
ul.checklist li:last-child { border-bottom: none; }
ul.checklist label { display: flex; align-items: center; gap: 9px; cursor: pointer; }
ul.checklist .done { color: var(--muted); text-decoration: line-through; }
ul.checklist .ts { color: var(--muted); font-size: .78rem; }
ul.checklist .li-actions { display: flex; align-items: center; gap: 8px; }
ul.checklist .li-del { background: none; border: none; cursor: pointer; color: var(--muted); font-size: .8rem; padding: 2px 4px; border-radius: 4px; }
ul.checklist .li-del:hover { color: var(--error-text); background: var(--error-bg); }
ul.checklist .li-move { background: none; border: none; cursor: pointer; color: var(--muted); font-size: .72rem; padding: 2px 3px; border-radius: 4px; line-height: 1; }
ul.checklist .li-move:hover:not(:disabled) { color: var(--tq-orange); background: var(--tq-orange-soft); }
ul.checklist .li-move:disabled { opacity: .3; cursor: default; }

/* Comments */
ul.comments { list-style: none; margin: 0; padding: 0; }
ul.comments li { padding: 10px 0; border-bottom: 1px solid var(--border); }
ul.comments li:last-child { border-bottom: none; }
ul.comments .meta { color: var(--muted); font-size: .82rem; margin-bottom: 3px; }

/* Definition lists for detail views */
.dl { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; }
.dl dt { color: var(--muted); font-size: .86rem; }
.dl dd { margin: 0; color: var(--text); font-weight: 500; }

/* Compact stacked key/value grid for detail tiles — fits more in less height */
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 20px; }
.kv-grid .span-2 { grid-column: 1 / -1; }
.kv { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kv .k { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
.kv .v { color: var(--text); font-weight: 500; font-size: .9rem; overflow-wrap: anywhere; }

/* ===== Portal ===== */
.portal-shell { min-height: 100vh; background: var(--bg); }
.portal-header { height: 60px; background: #1e2025; color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; }
.portal-header .brand { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.portal-header .brand:hover { text-decoration: none; }
.portal-header .brand img { height: 26px; width: auto; display: block; }
.portal-header .brand .brand-sub { color: rgba(255,255,255,.6); font-size: .78rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; align-self: flex-end; padding-bottom: 3px; }
.portal-header .inline { display: flex; align-items: center; gap: 12px; }
.portal-header .user { color: rgba(255,255,255,.75); }
.portal-header .linkbtn { color: #fff; background: none; border: none; cursor: pointer; font: inherit; }
.portal-header .portal-right { display: flex; align-items: center; gap: 24px; }
.portal-nav { display: flex; gap: 18px; }
.portal-nav a { color: rgba(255,255,255,.8); text-decoration: none; font-size: .92rem; }
.portal-nav a:hover { color: #fff; }
.portal-switch { color: rgba(255,255,255,.8); text-decoration: none; font-size: .92rem; }
.portal-switch:hover { color: #fff; }

/* Payment methods list (portal home) */
.method-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.method-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.method-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.method-name { font-weight: 600; }
.method-detail { color: var(--muted); font-size: .85rem; }
.method-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.portal-content { display: flex; justify-content: center; padding: 48px 16px; }
.portal-page { width: 100%; max-width: 960px; }

/* Standalone auth (staff sign-in) screen — full-bleed hospitality photo behind a centred card */
.auth-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; position: relative; overflow: hidden; }
/* Background photo */
.auth-shell::before { content: ""; position: fixed; inset: 0; z-index: 0;
    background: url('/img/login-bg.jpg') center 35% / cover no-repeat; }
/* Brand wash for card contrast */
.auth-shell::after { content: ""; position: fixed; inset: 0; z-index: 1;
    background: linear-gradient(135deg, rgba(20,12,8,.62) 0%, rgba(216,123,56,.45) 55%, rgba(20,12,8,.62) 100%); }
.auth-card { position: relative; z-index: 2; background: rgba(255,255,255,.98); border: 1px solid rgba(255,255,255,.25); border-radius: 18px;
    box-shadow: 0 18px 60px rgba(0,0,0,.45), 0 4px 14px rgba(0,0,0,.25);
    padding: 38px 40px 36px; width: 100%; max-width: 410px; text-align: center;
    color-scheme: light; color: var(--text); }
.auth-card h1 { font-size: 1.35rem; margin: 6px 0 8px; }
.auth-card .muted { margin-bottom: 22px; }
.auth-brand { margin-bottom: 14px; }
.auth-brand img { height: 46px; width: auto; display: inline-block; }
.auth-product-label { display: inline-block; margin: 0 0 22px; padding: 5px 14px; border-radius: 999px;
    background: var(--tq-orange-soft, rgba(229,138,71,.14)); color: var(--tq-orange, #d97b38);
    font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.auth-btn { display: block; width: 100%; margin-top: 10px; }
.account-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.account-option { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px;
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
    font-weight: 600; text-decoration: none; }
.account-option:hover { border-color: var(--tq-orange); box-shadow: var(--shadow-sm); }
.portal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 34px; max-width: 420px; width: 100%; }
.portal-card label { display: block; margin: 16px 0 6px; font-weight: 600; }
.portal-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-sizing: border-box; }
.portal-card input:focus { outline: none; border-color: var(--tq-orange); box-shadow: 0 0 0 3px var(--tq-orange-soft); }
.portal-card button { margin-top: 18px; width: 100%; background: var(--tq-orange); color: #fff; border: none; padding: 11px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; }
.portal-card button:hover { background: #d97b38; }

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 1050;
    display: flex; align-items: flex-start; justify-content: center; padding: 56px 16px; overflow-y: auto;
}
.modal-dialog {
    background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow);
    width: 100%; max-width: 660px; animation: toast-in .15s ease-out;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-x { background: none; border: none; font-size: 1.05rem; cursor: pointer; color: var(--muted); }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 22px; }

/* ===== Read-only summary header ===== */
.order-summary { padding: 0; overflow: hidden; }
.summary {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 18px 28px; padding: 20px 24px;
}
.summary-item { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.summary-item .k { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.summary-item .v { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.summary-item .v a { font-weight: 600; }

/* Financial strip inside the summary header */
.finance-strip {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px 40px;
    background: var(--panel); border-top: 1px solid var(--border);
    padding: 14px 24px;
}
.finance-stat { display: flex; flex-direction: column; gap: 2px; }
.finance-stat .k { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.finance-stat .v { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.finance-stat.gp .v { color: var(--tq-orange-text); }
.finance-stat .v small { color: var(--muted); font-weight: 600; font-size: .8rem; }
.finance-cap { margin-left: auto; color: var(--muted); font-size: .78rem; }

/* ===== Toasts (fixed bottom-right, no layout shift, no focus) ===== */
.toast-host {
    position: fixed; bottom: 20px; right: 20px; z-index: 1100;
    display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
    pointer-events: none;
}
.toast {
    pointer-events: auto; cursor: pointer; min-width: 240px; max-width: 360px;
    display: flex; align-items: center; gap: 10px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-left: 4px solid var(--muted);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 11px 14px; font-size: .9rem;
    animation: toast-in .18s ease-out;
}
.toast-icon {
    flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: .75rem; font-weight: 700; color: #fff;
}
.toast-text { flex: 1; }
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon { background: var(--success); }
.toast-error { border-left-color: var(--error); }
.toast-error .toast-icon { background: var(--error); }
.toast-info { border-left-color: var(--tq-orange); }
.toast-info .toast-icon { background: var(--tq-orange); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Blazor framework bits ===== */
.valid.modified:not([type=checkbox]) { outline: 1px solid var(--success); }
.invalid { outline: 1px solid var(--error); }
.validation-message { color: var(--error-text); font-size: .82rem; }

/* Install calendar (dashboard) */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-title { font-weight: 600; font-size: 1rem; margin-left: 6px; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 10px 14px; font-size: .8rem; color: var(--text-sub); align-items: center; }
.cal-leg { display: inline-flex; align-items: center; gap: 6px; }
.cal-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-dow { font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 2px 4px; }
.cal-cell { min-height: 86px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
    padding: 4px; display: flex; flex-direction: column; gap: 3px; }
.cal-cell.muted-day { background: var(--panel); }
.cal-cell.muted-day .cal-date { color: var(--muted); }
.cal-cell.today { border-color: var(--tq-orange); box-shadow: inset 0 0 0 1px var(--tq-orange); }
.cal-date { font-size: .74rem; font-weight: 600; color: var(--text-sub); padding: 1px 3px; }
.cal-chip { display: flex; align-items: center; gap: 4px; text-align: left; width: 100%; border: 1px solid var(--border);
    border-left: 3px solid var(--muted); border-radius: 4px; background: var(--panel); padding: 2px 5px; font-size: .72rem;
    cursor: pointer; color: var(--text); line-height: 1.2; }
.cal-chip:hover { background: var(--tq-orange-soft); }
.cal-chip-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-chip.installed { opacity: .72; }
.cal-chip.installed .cal-chip-main { text-decoration: line-through; }
.cal-check { color: var(--success-text); font-weight: 700; }

/* Inline checkbox filters (used on report toolbars) */
.filter-toggles { display: inline-flex; align-items: center; gap: 4px; }
.filter-check { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: var(--radius-sm);
    cursor: pointer; font-size: .85rem; color: var(--text-sub); }
.filter-check:hover { background: var(--tq-orange-soft); }
.filter-check input { cursor: pointer; }

#blazor-error-ui {
    color-scheme: light only; background: lightyellow; color: var(--text); bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
.blazor-error-boundary {
    background: var(--error); padding: 1rem 1rem 1rem 1rem; color: white;
}
.blazor-error-boundary::after { content: "An error has occurred." }

/* ===== Mobile / small screens ===== */
@media (max-width: 760px) {
    /* Sidebar becomes an off-canvas drawer toggled by the topbar hamburger */
    .nav-burger { display: inline-flex; }
    .sidebar {
        position: fixed; top: 0; left: 0; z-index: 60;
        width: 264px; max-width: 84vw; height: 100vh;
        transform: translateX(-100%); transition: transform .22s ease;
        box-shadow: 0 0 30px rgba(0,0,0,.4);
    }
    .app-shell.nav-open .sidebar { transform: translateX(0); }
    .app-shell.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(0,0,0,.45); }

    .topbar { padding: 0 14px; gap: 10px; }
    .content { padding: 16px 14px; }

    /* Wide tables scroll horizontally instead of clipping their right-hand columns */
    table.grid { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }

    /* Larger tap targets for touch */
    .btn-sm { padding: 8px 12px; }
    .li-del, .li-move { padding: 8px; }

    /* Stack definition lists / key-value grids */
    .dl { grid-template-columns: 1fr; gap: 2px 0; }
    .dl dt { margin-top: 8px; }
    .kv-grid { grid-template-columns: 1fr; }

    /* Install calendar scrolls rather than crushing seven columns into a half-width card */
    .cal-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .cal-grid { min-width: 560px; }

    /* Report/search toolbars: let fixed-width month/search inputs grow to the row */
    .toolbar > input[type="month"], .toolbar > .search-input { flex: 1 1 150px; min-width: 0; }

    /* Opt-in: turn a wide data table into a stack of labelled cards (one card per row) instead of
       forcing a horizontal scroll. Each <td> shows its column name from data-label. */
    table.grid.stack-mobile { display: block; border: none; box-shadow: none; background: transparent; overflow: visible; white-space: normal; }
    table.grid.stack-mobile thead { display: none; }
    table.grid.stack-mobile tbody { display: block; }
    table.grid.stack-mobile tbody tr { display: block; background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 12px; padding: 2px 0; }
    table.grid.stack-mobile tbody tr:nth-child(even),
    table.grid.stack-mobile tbody tr:hover { background: var(--surface); }
    table.grid.stack-mobile tbody td { display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
        padding: 8px 14px; border-bottom: 1px solid var(--border); text-align: right; white-space: normal; }
    table.grid.stack-mobile tbody tr td:last-child { border-bottom: none; }
    table.grid.stack-mobile tbody td::before { content: attr(data-label); flex: 0 0 auto; text-align: left;
        font-weight: 600; color: var(--text-sub); text-transform: uppercase; font-size: .7rem; letter-spacing: .03em; }
    table.grid.stack-mobile tbody td:empty { display: none; }
    table.grid.stack-mobile td.empty-cell { display: block; text-align: center; }
    table.grid.stack-mobile td.empty-cell::before { content: none; }
}

@media (max-width: 560px) {
    .modal-backdrop { padding: 16px 8px; }
    .modal-body { padding: 16px; }
}
