/* ==========================================================================
   Adelli Platform — Design System (Industrial / Modern)
   Brand: primary #ee8224. Dark instrument chrome, crisp light panels, mono metrics.
   ========================================================================== */

:root {
    --color-primary: #ee8224;
    --color-primary-dark: #cf6c16;
    --color-primary-light: #f59d4d;
    --color-primary-faint: rgba(238, 130, 36, 0.12);

    --color-dark: #15171d;       /* near-black instrument chrome */
    --color-dark-2: #1d212b;
    --color-sidebar-text: #aeb6c4;

    --color-bg: #edf0f4;         /* cool technical canvas */
    --color-surface: #ffffff;
    --color-surface-2: #f5f7fa;  /* panel header / zebra */
    --color-border: #dde2ea;
    --color-border-strong: #c6cdd8;
    --color-text: #18202c;
    --color-text-secondary: #58626f;
    --color-text-muted: #6b7480;   /* AA-contrast (>=4.5:1 on white & panel surfaces) */

    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-error: #dc2626;
    --color-info: #2563eb;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 10px rgba(16, 24, 40, 0.07), 0 10px 24px rgba(16, 24, 40, 0.07);
    --shadow-lg: 0 12px 28px rgba(16, 24, 40, 0.14), 0 24px 60px rgba(16, 24, 40, 0.14);
    --ring: 0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent);

    --sidebar-width: 262px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'SFMono-Regular', 'SF Mono', 'Consolas', 'Liberation Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* App-wide thin, rounded scrollbars (the dark sidebar overrides these with its own — see .sidebar__nav). */
html { scrollbar-width: thin; scrollbar-color: #c4ccd8 transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: #c4ccd8; border-radius: 9px;
    border: 3px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #9aa6b6; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }

/* Keyboard focus ring. :focus-visible only fires for keyboard navigation, so mouse users see
   nothing while keyboard users get a clear, consistent indicator on every interactive element. */
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-sm); }
.btn:focus-visible, a:focus-visible, button:focus-visible,
[tabindex]:focus-visible, input[type="checkbox"]:focus-visible, summary:focus-visible {
    outline: 2px solid var(--color-primary); outline-offset: 2px;
}
.sidebar__link:focus-visible { outline: 2px solid var(--color-primary-light); outline-offset: -2px; }
tr.is-clickable:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }

h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.015em; color: var(--color-dark); margin: 0 0 0.5em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

/* -------------------------------------------------------- App shell layout */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--color-dark) 0%, var(--color-dark-2) 100%);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    border-right: 1px solid #000;
}
.sidebar__brand {
    padding: 18px 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
/* The logo fills the brand area's full width; height follows the artwork's aspect ratio and
   is clamped so square marks can't swallow the menu. (A .sidebar__brand img height rule used
   to outrank this by specificity and pinned every logo to 36px — hence tiny logos.) */
.sidebar__brand .sidebar__logo {
    display: block; width: 100%; height: auto; max-height: 96px;
    object-fit: contain; margin: 0 auto;
}
/* Logo contrast guard (app.js measures artwork luminance and tags the img): dark artwork
   would vanish on the dark sidebar, light artwork on the light auth/onboarding surfaces —
   back each with a contrasting chip only where needed. Mid-tone logos stay bare.
   Settings › Branding can override per tenant: --light forces the white panel, --chip carries
   a custom colour inline, and "None" renders the bare img (blends with the sidebar). */
.sidebar__logo.logo-adapt--dark,
.sidebar__logo--light { background: #f4f3ee; border-radius: 10px; padding: 8px 14px; }
.sidebar__logo--chip { border-radius: 10px; padding: 8px 14px; }
.auth-card__logo img.logo-adapt--light,
.onboarding-top__brand img.logo-adapt--light { background: var(--color-dark); border-radius: 8px; padding: 6px 10px; }
.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 10px; overscroll-behavior: contain; }
/* Sidebar scrollbar: thin, subtle, themed for the dark panel (its position is preserved by app.js). */
.sidebar__nav { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.18) transparent; }
.sidebar__nav::-webkit-scrollbar { width: 9px; }
.sidebar__nav::-webkit-scrollbar-track { background: transparent; }
.sidebar__nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.16); border-radius: 8px;
    border: 2px solid transparent; background-clip: padding-box;
}
.sidebar__nav:hover::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.26); background-clip: padding-box; }
.sidebar__nav::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.42); background-clip: padding-box; }
.sidebar__group-label {
    font-family: var(--font-mono);
    text-transform: uppercase;
    font-size: 0.62rem;
    letter-spacing: 0.16em;
    color: #6b7686;
    padding: 16px 12px 6px;
    font-weight: 600;
}
.sidebar__link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 12px;
    margin: 1px 0;
    border-radius: 8px;
    color: var(--color-sidebar-text);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.13s, color 0.13s;
    position: relative;
}
.sidebar__link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.sidebar__link:hover .icon { opacity: 1; }
.sidebar__link.is-active {
    background: linear-gradient(90deg, color-mix(in srgb, var(--color-primary) 20%, transparent), color-mix(in srgb, var(--color-primary) 8%, transparent));
    color: #fff;
}
.sidebar__link.is-active::before {
    content: ''; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px;
    background: var(--color-primary); border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px color-mix(in srgb, var(--color-primary) 55%, transparent);
}
.sidebar__link .icon { width: 18px; text-align: center; opacity: 0.75; transition: opacity 0.13s; }

/* Submenu (parent → children drill-down) */
.sidebar__link--parent { cursor: pointer; }
.sidebar__link--parent .sidebar__caret {
    margin-left: auto; opacity: 0.55; display: inline-flex;
    transition: transform 0.15s ease;
}
.sidebar__link--parent .sidebar__caret svg { width: 13px; height: 13px; }
.sidebar__link--parent.is-open .sidebar__caret { transform: rotate(90deg); }
.sidebar__submenu {
    margin: 1px 0 6px 19px;
    padding-left: 10px;
    border-left: 1px solid rgba(255, 255, 255, 0.09);
    display: none;
}
.sidebar__submenu.is-open { display: block; }
.sidebar__link--child {
    padding: 6px 12px;
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--color-sidebar-text);
}
.sidebar__link--child.is-active { background: linear-gradient(90deg, color-mix(in srgb, var(--color-primary) 20%, transparent), color-mix(in srgb, var(--color-primary) 8%, transparent)); color: #fff; }
.sidebar__link--child.is-active::before { left: -11px; }

.sidebar__user {
    padding: 13px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    display: flex; align-items: center; gap: 10px;
    text-decoration: none; color: inherit; transition: background 0.12s;
}
.sidebar__user:hover { background: rgba(255, 255, 255, 0.05); text-decoration: none; }
.sidebar__avatar {
    width: 34px; height: 34px; border-radius: var(--radius-sm); overflow: hidden; flex: none;
    background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark));
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.sidebar__user-meta { flex: 1; min-width: 0; }
.sidebar__user-name { color: #fff; font-size: 0.86rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar__user-role { color: var(--color-text-muted); font-size: 0.72rem; }

.main { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 60px; background: rgba(255, 255, 255, 0.86); border-bottom: 1px solid var(--color-border);
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: space-between; padding: 0 26px;
    position: sticky; top: 0; z-index: 40;
    box-shadow: var(--shadow-sm);
}
.topbar__title { font-size: 1.1rem; font-weight: 700; color: var(--color-dark); letter-spacing: -0.01em; }
.content { padding: 26px; flex: 1; }

/* ------------------------------------------------------------------ Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 22px;
}
.card__header {
    padding: 13px 18px; border-bottom: 1px solid var(--color-border);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--color-surface-2);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}
.card__title {
    font-size: 0.78rem; font-weight: 700; margin: 0; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--color-text-secondary);
}
.card__body { padding: 20px; }
.card__footer {
    padding: 11px 18px; border-top: 1px solid var(--color-border);
    background: var(--color-surface-2);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Index search form (the filter box lives in a GET form for whole-table search) */
.table-search { display: flex; align-items: center; gap: 8px; margin: 0; flex: 1; }

/* Server-side pagination footer */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.pagination__info { font-size: 0.72rem; color: var(--color-text-secondary); }
.pagination__pages { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.pagination__gap { padding: 0 4px; color: var(--color-text-muted); }
.btn.is-disabled { opacity: 0.45; pointer-events: none; cursor: default; }

/* Saved views (per-user named searches) */
.saved-views { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: -8px 0 18px; }
.saved-views__label { font-size: 0.72rem; font-weight: 600; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.saved-view-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px 3px 10px; border: 1px solid var(--color-border); border-radius: 999px; background: var(--color-surface); font-size: 0.78rem; }
.saved-view-chip.is-active { border-color: var(--color-primary, #2b6cb0); box-shadow: inset 0 0 0 1px var(--color-primary, #2b6cb0); }
.saved-view-chip a { text-decoration: none; color: var(--color-text); }
.saved-view-chip form { margin: 0; display: inline-flex; }
.saved-view-chip button { border: none; background: none; cursor: pointer; color: var(--color-text-muted); line-height: 1; padding: 0 2px; font-size: 0.95rem; }
.saved-view-chip button:hover { color: var(--color-error, #c0392b); }
.saved-view-save { display: inline-flex; align-items: center; gap: 6px; margin: 0; }

/* Payslip / P60 */
.payslip { max-width: 760px; }
.payslip__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 2px solid var(--color-border-strong); padding-bottom: 14px; margin-bottom: 16px; }
.payslip__company { font-size: 1.15rem; font-weight: 800; color: var(--color-dark); }
.payslip__title { font-size: 1.1rem; font-weight: 800; letter-spacing: 0.08em; color: var(--color-primary-dark); }
.payslip__meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.payslip__meta > div { display: flex; flex-direction: column; gap: 2px; font-size: 0.9rem; }
.payslip__meta .muted { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; }
.payslip__cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.payslip__h { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-secondary); margin: 0 0 8px; border-bottom: 1px solid var(--color-border); padding-bottom: 5px; }
.payslip__t { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.payslip__t td { padding: 4px 0; }
.payslip__t td.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.payslip__t .payslip__total td { border-top: 1px solid var(--color-border); font-weight: 700; padding-top: 7px; }
.payslip__net { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; padding: 12px 16px; background: var(--color-primary-faint); border-radius: var(--radius-md); font-weight: 800; font-size: 1.1rem; color: var(--color-dark); }
.payslip__net span:last-child { font-family: var(--font-mono); }
@media (max-width: 560px) { .payslip__cols { grid-template-columns: 1fr; } }
@media print {
    .sidebar, .topbar, .no-print, .panel-overlay, .sidebar-backdrop { display: none !important; }
    .main { margin-left: 0 !important; }
    .content { padding: 0 !important; }
    .card, .payslip { box-shadow: none !important; border: 1px solid #ccc !important; }
    body { background: #fff !important; }
}

/* Document version history disclosure */
.doc-versions { margin-top: 6px; text-align: left; }
.doc-versions > summary { cursor: pointer; font-size: 0.74rem; color: var(--color-text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.doc-versions[open] > summary { margin-bottom: 8px; }
.doc-versions__body { background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 10px 12px; }
.doc-versions__upload { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; flex-wrap: wrap; }
.doc-versions__upload .form-control { max-width: 260px; }
.doc-versions__list { list-style: none; margin: 0; padding: 0; font-size: 0.78rem; }
.doc-versions__list li { padding: 3px 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }

/* Bulk selection on CRUD lists ("Delete selected") */
.bulk-bar { display: flex; align-items: center; gap: 10px; margin: 0; }
.bulk-bar__count { font-size: 0.72rem; color: var(--color-text-secondary); white-space: nowrap; }
.bulk-cell { width: 38px; text-align: center; }
.bulk-cell input { cursor: pointer; }

.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(195px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* Stat cards = instrument readouts. Markup order is value-then-label; column-reverse puts the
   label on top (overline) with the tone dot, big number beneath — calmer than the old 3px bar. */
.stat-card {
    display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 7px;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: var(--radius-md); padding: 16px 18px; position: relative; overflow: hidden;
    box-shadow: var(--shadow-sm); transition: transform 0.14s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--color-border-strong); text-decoration: none; }
a.stat-card:hover .stat-card__value { color: var(--color-primary-dark); }
.stat-card__value {
    font-family: var(--font-mono); font-size: 1.85rem; font-weight: 700; color: var(--color-dark);
    line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
    transition: color 0.14s ease;
}
.stat-card__label {
    font-size: 0.66rem; color: var(--color-text-secondary); margin: 0;
    text-transform: uppercase; letter-spacing: 0.09em; font-weight: 600;
    display: flex; align-items: center; gap: 7px;
}
.stat-card__label::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%; flex: none;
    background: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-faint);
}
/* Tone dot for summary readouts (e.g. maintenance cost, expenses paid vs pending). */
.stat-card--ok .stat-card__label::before { background: var(--color-success); box-shadow: 0 0 0 3px rgba(22,163,74,.14); }
.stat-card--warn .stat-card__label::before { background: var(--color-warning); box-shadow: 0 0 0 3px rgba(217,119,6,.14); }
.stat-card--bad .stat-card__label::before { background: var(--color-error); box-shadow: 0 0 0 3px rgba(220,38,38,.14); }
.stat-card--info .stat-card__label::before { background: var(--color-info); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
/* Hero tier — the handful of numbers the page is actually about. */
.stat-card--hero { padding: 20px 22px; }
.stat-card--hero .stat-card__value { font-size: 2.4rem; }
/* Secondary tier — remaining counts as a compact chip strip, not a wall of identical cards. */
.stat-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 22px; }
.stat-chip {
    display: inline-flex; align-items: center; gap: 9px; padding: 6px 13px;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 999px;
    font-size: 0.8rem; color: var(--color-text-secondary); text-decoration: none;
    box-shadow: var(--shadow-sm); transition: border-color 0.12s ease, color 0.12s ease;
}
.stat-chip:hover { border-color: var(--color-primary); color: var(--color-primary-dark); text-decoration: none; }
.stat-chip__value { font-family: var(--font-mono); font-weight: 700; color: var(--color-text); font-variant-numeric: tabular-nums; }
.stat-chip:hover .stat-chip__value { color: var(--color-primary-dark); }

/* ---------------------------------------------------------------- Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 18px; min-height: 38px;
    font-family: inherit; font-size: 0.76rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
    border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
    transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, box-shadow 0.14s ease, transform 0.1s ease;
    text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn--primary {
    background: linear-gradient(180deg, var(--color-primary-light) -40%, var(--color-primary) 55%);
    color: #fff; border-color: var(--color-primary-dark);
    box-shadow: 0 1px 2px rgba(207, 108, 22, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.btn--primary:hover { background: var(--color-primary-dark); box-shadow: 0 2px 6px rgba(207, 108, 22, 0.4); }
.btn--secondary { background: var(--color-dark); color: #fff; box-shadow: inset 0 1px 0 rgba(255,255,255,0.08); }
.btn--secondary:hover { background: var(--color-dark-2); }
.btn--outline { background: var(--color-surface); border-color: var(--color-border-strong); color: var(--color-text); box-shadow: var(--shadow-sm); }
.btn--outline:hover { border-color: var(--color-primary); color: var(--color-primary-dark); background: var(--color-primary-faint); }
.btn--danger { background: var(--color-error); color: #fff; box-shadow: 0 1px 2px rgba(185, 28, 28, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.14); }
.btn--danger:hover { background: #b91c1c; }
/* Compact in-row action: visibly a button (border + surface), but lighter-weight than btn--outline
   so dense tables stay calm. Danger variant tints red on hover. */
.btn--ghost {
    background: var(--color-surface); border-color: var(--color-border-strong);
    color: var(--color-text-secondary); box-shadow: var(--shadow-sm);
}
.btn--ghost:hover { background: var(--color-primary-faint); border-color: var(--color-primary); color: var(--color-primary-dark); }
.btn--ghost.btn--ghost-danger:hover { background: rgba(220, 38, 38, 0.08); border-color: var(--color-error); color: var(--color-error); }
.btn--sm { min-height: 30px; padding: 5px 12px; font-size: 0.68rem; gap: 6px; }
.btn svg { flex: none; }
.btn--sm svg { width: 13px; height: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn__spinner {
    width: 13px; height: 13px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
    border-radius: 50%; animation: spin 0.6s linear infinite; display: none;
}
.btn.is-loading .btn__spinner { display: inline-block; }
/* A submitting button is non-interactive so the form can't be double-submitted (duplicate records). */
.btn.is-loading { pointer-events: none; opacity: 0.75; cursor: default; }
/* Required-field marker on form labels. */
.req { color: var(--color-error); font-weight: 700; margin-left: 1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- Tables */
.table { width: 100%; border-collapse: collapse; background: var(--color-surface); font-size: 0.9rem; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.table th {
    font-family: var(--font-mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--color-text-secondary); font-weight: 600; background: var(--color-surface-2);
    border-bottom: 1px solid var(--color-border-strong);
}
.table tbody tr { transition: background 0.1s ease; }
.table tbody tr:hover { background: var(--color-surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
/* Per-row actions: compact buttons on one line, always fully visible. */
.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; white-space: nowrap; }
.row-actions form { margin: 0; display: inline-flex; }
.table th.is-sortable { cursor: pointer; user-select: none; }
.table th.is-sortable:hover { color: var(--color-primary-dark); }
.table th[data-sort-dir]::after { font-size: 0.75em; opacity: 0.85; }
.table th[data-sort-dir="asc"]::after { content: ' \25B2'; }
.table th[data-sort-dir="desc"]::after { content: ' \25BC'; }
.table td .muted, .table .muted { color: var(--color-text-muted); }
.table .num, .table td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.code-badge { font-family: var(--font-mono); background: var(--color-primary-faint); color: var(--color-primary-dark); padding: 2px 7px; border-radius: var(--radius-sm); font-size: 0.8rem; }
/* Clickable list rows (open the record view) */
.table tbody tr.is-clickable { cursor: pointer; }
/* Read-only detail (key/value) table */
.detail-table th {
    width: 38%; text-transform: none; letter-spacing: 0; font-family: var(--font);
    font-weight: 600; font-size: 0.82rem; color: var(--color-text-secondary);
    background: var(--color-surface-2); vertical-align: top; white-space: nowrap;
}
.detail-table td { font-size: 0.9rem; }
.detail-table tbody tr:hover { background: transparent; }

/* ------------------------------------------------------------------ Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.74rem; font-weight: 600; color: var(--color-text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.04em; }
.form-control {
    width: 100%; padding: 10px 12px; font-family: inherit; font-size: 0.92rem;
    border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); background: #fff; color: var(--color-text);
    transition: border-color 0.13s, box-shadow 0.13s;
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--ring); }
.form-control:disabled { background: var(--color-surface-2); color: var(--color-text-muted); }
.form-control.is-invalid { border-color: var(--color-error); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.16); }
.form-control.is-valid { border-color: var(--color-success); }
.form-hint { font-size: 0.76rem; color: var(--color-text-muted); margin-top: 5px; }
.form-error { font-size: 0.76rem; color: var(--color-error); margin-top: 5px; font-weight: 500; }
.form-error::before { content: '\26A0'; margin-right: 5px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2358626f' d='M6 8 0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; }
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--color-primary); }
.form-section {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 16px 16px 4px;
    margin: 6px 0 16px;
    background: var(--color-surface-2);
}
.form-section__legend {
    font-family: var(--font-mono);
    font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--color-text-secondary); padding: 0 6px;
}

/* --------------------------------------------------------------- Badges */
.badge {
    display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
    font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
    border: 1px solid transparent;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex: none; opacity: 0.85; }
.badge--success { background: rgba(22,163,74,.1); color: #15803d; border-color: rgba(22,163,74,.25); }
.badge--warning { background: rgba(217,119,6,.1); color: #b45309; border-color: rgba(217,119,6,.28); }
.badge--error { background: rgba(220,38,38,.08); color: #b91c1c; border-color: rgba(220,38,38,.25); }
.badge--info { background: rgba(37,99,235,.08); color: #1d4ed8; border-color: rgba(37,99,235,.24); }
.badge--muted { background: var(--color-surface-2); color: var(--color-text-secondary); border-color: var(--color-border); }
.badge--super { background: var(--color-primary-faint); color: var(--color-primary-dark); border-color: rgba(238,130,36,.3); }

/* ------------------------------------------------- Profile photo / logo card */
.profile-card__body { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.profile-pic { display: block; width: 150px; height: 150px; overflow: hidden; background: var(--color-surface-2);
    border: 1px solid var(--color-border); border-radius: var(--radius-md); flex: none; }
.profile-pic--round { border-radius: 50%; }
.profile-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-pic.is-empty { display: flex; align-items: center; justify-content: center; color: var(--color-text-muted); }
.profile-pic__icon { font-size: 3.6rem; line-height: 1; opacity: 0.45; }
.profile-upload { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; width: 100%; }
.profile-upload .form-control { flex: 1; min-width: 150px; }

/* ---------------------------------------------------------------- Alerts */
.alert { padding: 12px 38px 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.9rem; border: 1px solid; border-left-width: 3px; position: relative; }
.alert__close { position: absolute; top: 7px; right: 9px; border: none; background: none; cursor: pointer; font-size: 1.15rem; line-height: 1; color: inherit; opacity: 0.55; padding: 2px 5px; border-radius: var(--radius-sm); }
.alert__close:hover { opacity: 1; }
.alert--success { background: rgba(22,163,74,.07); border-color: var(--color-success); color: #14532d; }
.alert--error { background: rgba(220,38,38,.07); border-color: var(--color-error); color: #7f1d1d; }
.alert--info { background: rgba(37,99,235,.07); border-color: var(--color-info); color: #1e3a8a; }
.alert--warning { background: rgba(217,119,6,.07); border-color: var(--color-warning); color: #78350f; }

/* ------------------------------------------------------------ Login page */
.auth-wrap {
    min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
    background:
        linear-gradient(rgba(21,23,29,0.93), rgba(21,23,29,0.96)),
        repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(255,255,255,0.03) 24px),
        repeating-linear-gradient(90deg, transparent, transparent 23px, rgba(255,255,255,0.03) 24px),
        var(--color-dark);
}
.auth-card { width: 100%; max-width: 400px; background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); overflow: hidden; border: 1px solid rgba(255,255,255,0.06); }
.auth-card__top { height: 3px; background: linear-gradient(90deg, var(--color-primary), var(--color-primary-light)); }
.auth-card__body { padding: 34px 32px; }
.auth-card__logo { text-align: center; margin-bottom: 8px; }
.auth-card__logo img { max-width: 100%; max-height: 64px; width: auto; height: auto; }
.auth-card__subtitle { text-align: center; color: var(--color-text-secondary); font-size: 0.84rem; margin-bottom: 24px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; }
.auth-footer { text-align: center; font-size: 0.72rem; color: var(--color-text-muted); margin-top: 18px; font-family: var(--font-mono); }
.auth-alt { display: flex; flex-direction: column; gap: 8px; align-items: center; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--color-border); font-size: 0.86rem; }

/* Public applicant onboarding portal */
.onboarding-body { background: var(--color-bg); min-height: 100vh; }
.onboarding-top { height: 60px; background: var(--color-surface); border-bottom: 1px solid var(--color-border-strong); box-shadow: var(--shadow-sm);
    display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 40; }
.onboarding-top__brand img { height: 30px; width: auto; display: block; }
.onboarding-top__right { display: flex; align-items: center; gap: 12px; }
.onboarding-main { padding: 28px 16px; }
.onboarding-wrap { max-width: 760px; margin: 0 auto; }
.onboarding-progress__bar { height: 8px; border-radius: 99px; background: var(--color-surface-2); overflow: hidden; }
.onboarding-progress__bar > span { display: block; height: 100%; background: var(--color-primary); transition: width .3s; }
.onboarding-checklist { list-style: none; margin: 16px 0 0; padding: 0; }
.onboarding-checklist > li { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--color-border); }
.onboarding-checklist > li:last-child { border-bottom: none; }
.onboarding-checklist__mark { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--color-border-strong); flex: none;
    display: inline-flex; align-items: center; justify-content: center; font-size: 0.8rem; color: #fff; }
.onboarding-checklist__mark.is-done { background: var(--color-success); border-color: var(--color-success); }
.onboarding-checklist__label { flex: 1; font-weight: 600; }
@media (max-width: 600px) { .onboarding-main { padding: 16px 12px; } }

/* Input with affix (e.g. password reveal) */
.input-affix { position: relative; }
.input-affix .form-control { padding-right: 42px; }
.input-affix__btn {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; color: var(--color-text-muted);
    padding: 6px 8px; display: inline-flex; border-radius: var(--radius-sm);
}
.input-affix__btn:hover { color: var(--color-primary-dark); }

/* Exception / attention rows (dashboard) */
.exception-row { display: flex; align-items: center; gap: 11px; padding: 11px 18px; border-bottom: 1px solid var(--color-border); color: var(--color-text); font-size: 0.9rem; transition: background 0.12s ease; }
.exception-row:last-child { border-bottom: none; }
.exception-row:hover { background: var(--color-surface-2); text-decoration: none; }
.exception-row:hover .exception-row__go { color: var(--color-primary-dark); transform: translateX(3px); }
.exception-row__dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.exception-row--error .exception-row__dot { background: var(--color-error); box-shadow: 0 0 0 3px rgba(220,38,38,.13); }
.exception-row--warning .exception-row__dot { background: var(--color-warning); box-shadow: 0 0 0 3px rgba(217,119,6,.13); }
.exception-row--info .exception-row__dot { background: var(--color-info); box-shadow: 0 0 0 3px rgba(37,99,235,.13); }
.exception-row__go { margin-left: auto; color: var(--color-text-muted); transition: color 0.12s ease, transform 0.12s ease; display: inline-flex; }
.exception-row__go svg { width: 15px; height: 15px; }

/* Kanban-style board (movements logistics visibility) */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.board__col { flex: 1 0 220px; max-width: 300px; background: var(--color-surface-2); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.board__col-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--color-border); }
.board__count { font-family: var(--font-mono); font-size: 0.8rem; color: var(--color-text-muted); }
.board__col-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.board__empty { text-align: center; color: var(--color-text-muted); padding: 8px; font-size: 0.85rem; }
.board__card { display: block; background: var(--color-surface); border: 1px solid var(--color-border); border-left: 3px solid var(--color-primary); border-radius: var(--radius-sm); padding: 10px 12px; box-shadow: var(--shadow-sm); transition: transform 0.1s, box-shadow 0.1s; }
.board__card:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); text-decoration: none; }
.board__card-co { font-size: 0.82rem; font-weight: 600; color: var(--color-text); margin-top: 5px; }
.board__card-route { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; margin-top: 6px; color: var(--color-text-secondary); }
.board__arrow { color: var(--color-primary); }
.board__card-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 0.74rem; color: var(--color-text-secondary); }

.helper-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { position: relative; padding-left: 14px; }
.page-header h1::before { content: ''; position: absolute; left: 0; top: 4px; bottom: 4px; width: 4px; background: var(--color-primary); border-radius: 2px; }
.page-header__subtitle { color: var(--color-text-secondary); font-size: 0.88rem; margin-top: 2px; padding-left: 14px; }
.empty-state { text-align: center; padding: 44px 20px; color: var(--color-text-muted); }
.empty-state::before {
    content: ''; display: block; width: 34px; height: 34px; margin: 0 auto 12px; opacity: 0.9;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23c6cdd8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='22 12 16 12 14 15 10 15 8 12 2 12'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }
.muted { color: var(--color-text-muted); }
.mono { font-family: var(--font-mono); }
.mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 14px; }
.flex { display: flex; }
.gap-2 { gap: 10px; }
.items-center { align-items: center; }

/* ------------------------------------------------- Slide-over panel (forms) */
.panel-overlay {
    position: fixed; inset: 0; background: rgba(10, 12, 16, 0.55);
    opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s ease; z-index: 200;
}
.panel-overlay.is-open { opacity: 1; visibility: visible; }
.panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 580px; max-width: 94vw;
    background: var(--color-surface); box-shadow: var(--shadow-lg);
    transform: translateX(100%); transition: transform 0.24s ease; z-index: 201;
    display: flex; flex-direction: column;
}
.panel-overlay.is-open .panel { transform: translateX(0); }
.panel__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 15px 22px; border-bottom: 1px solid var(--color-border); background: var(--color-surface-2);
    flex: none;
}
.panel__title {
    font-family: var(--font-mono); font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.07em; color: var(--color-text-secondary); margin: 0; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.panel__back {
    background: none; border: 1px solid var(--color-border-strong); cursor: pointer; flex: none;
    font: inherit; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--color-text-secondary); padding: 5px 11px; margin-right: 12px; border-radius: var(--radius-sm);
}
.panel__back[hidden] { display: none; }
.panel__back:hover { border-color: var(--color-primary); color: var(--color-primary-dark); background: var(--color-primary-faint); }
.panel__expand {
    background: none; border: 1px solid var(--color-border-strong); cursor: pointer; flex: none;
    font: inherit; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
    color: var(--color-text-secondary); padding: 5px 11px; margin-right: 8px; border-radius: var(--radius-sm); white-space: nowrap;
}
.panel__expand:hover { border-color: var(--color-primary); color: var(--color-primary-dark); background: var(--color-primary-faint); }
.panel__close {
    background: none; border: none; font-size: 1.5rem; line-height: 1; cursor: pointer;
    color: var(--color-text-muted); padding: 2px 8px; border-radius: var(--radius-sm);
}
.panel__close:hover { color: var(--color-text); background: var(--color-border); }
.panel__body { padding: 22px; overflow-y: auto; flex: 1; }
/* In the panel, flatten card chrome but KEEP section headers (so dedicated spaces stay legible). */
.panel__body .card { border: none; box-shadow: none; margin: 0 0 18px; background: transparent; border-radius: 0; }
.panel__body .card + .card { border-top: 1px solid var(--color-border); padding-top: 14px; }
.panel__body .card__header { background: transparent; border-bottom: none; padding: 0 0 10px; }
.panel__body .card__body { padding: 0; }
.panel__body .record-detail, .panel__body .record-form { max-width: none; }
.panel__body .form-actions { position: sticky; bottom: -22px; background: var(--color-surface); padding: 12px 0 2px; margin: 0 -2px; }
.panel__loading { text-align: center; color: var(--color-text-muted); padding: 48px 20px; }
@media (max-width: 620px) { .panel { width: 100%; } }

/* -------------------------------------------------------------- Responsive */
.menu-toggle { display: none; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--color-dark); }
.sidebar-backdrop { display: none; }

/* Wide tables scroll inside their card rather than stretching the whole page. */
.card__body { overflow-x: auto; }

@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow-lg); }
    .sidebar.is-open { transform: translateX(0); }
    .main { margin-left: 0; }
    .menu-toggle { display: inline-flex !important; }
    .sidebar-backdrop.is-visible { display: block; position: fixed; inset: 0; background: rgba(8, 12, 20, 0.5); z-index: 49; }
}

/* Tablet/phone: collapse fixed multi-column grids (forms etc.) to a single column.
   The auto-fit grids (.grid--stats / .grid--2) already reflow, so leave them be. */
@media (max-width: 720px) {
    .grid:not(.grid--stats):not(.grid--2) { grid-template-columns: 1fr !important; }
    .record-detail, .record-form { max-width: none; }
}

/* Phone */
@media (max-width: 600px) {
    .content { padding: 14px; }
    .topbar { padding: 0 14px; }
    .topbar__title { font-size: 0.98rem; }
    .page-header { margin-bottom: 16px; }
    .page-header h1, h1 { font-size: 1.28rem; }
    .card__body { padding: 16px; }
    .panel__body { padding: 16px; }
    .panel__header { padding: 12px 14px; }

    /* Card headers hold a title + search box + action buttons: on a phone they overflowed the card
       instead of wrapping, pushing the search input off-screen. */
    .card__header { flex-wrap: wrap; }
    .table-search { flex-wrap: wrap; flex-basis: 100%; }
    .table-search .form-control { min-width: 0; flex: 1; }
    .form-actions .btn { flex: 1; }
    .auth-card__body { padding: 28px 22px; }

    /* Invoice line items: collapse the editing table into stacked, labelled blocks
       so the qty/unit/description inputs stay comfortably sized on a phone. */
    .invoice-lines, .invoice-lines tbody, .invoice-lines tfoot { display: block; width: 100%; }
    .invoice-lines thead { display: none; }
    .invoice-lines tbody tr { display: block; border: 1px solid var(--color-border); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; }
    .invoice-lines tbody td { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; border: none; }
    .invoice-lines tbody td::before { content: attr(data-label); font-family: var(--font-mono); font-size: 0.62rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--color-text-muted); }
    .invoice-lines tbody td:first-child { flex-direction: column; align-items: stretch; gap: 5px; }
    .invoice-lines tbody td .form-control { flex: 0 0 130px; }
    .invoice-lines tbody td:first-child .form-control { flex: 1 1 auto; }
    .invoice-lines tbody td:last-child { justify-content: flex-end; }
    .invoice-lines tbody td:last-child::before { display: none; }
    .invoice-lines tfoot tr { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px; }
    .invoice-lines tfoot td { border: none; padding: 0; }
    .invoice-lines tfoot td:last-child { display: none; }
}
@media (max-width: 460px) {
    .topbar .text-muted { display: none; }   /* hide the long user name; keep Sign out */
    .panel__back, .panel__expand { padding: 5px 8px; font-size: 0.62rem; }
}

/* ============================================================ Record View / Forms
   Sectioned cards + definition/field grids — "dedicated spaces" for every record. */
.record-form { max-width: 880px; }
/* Record View: full-width responsive grid of section cards so the page uses the whole space
   instead of a single left column. Cards on the same row stretch to equal height (align-items:
   stretch + height:100%). Only genuinely wide/tabular sections span the full row. */
.record-detail { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 18px; align-items: stretch; }
/* No height/align-self here: grid `align-items: stretch` only equalises a row when the item's
   height stays auto, so same-row cards grow to the tallest one. */
.record-detail > .card { margin: 0; }
/* Full-width rows (toolbar/alerts/tables) shouldn't stretch vertically — keep them at their height. */
.record-detail > .helper-row,
.record-detail > .alert,
.record-detail > .empty-state,
.record-detail > .search-page-form,
.record-detail .related-section,
.record-detail .record-wide { grid-column: 1 / -1; align-self: start; }
/* Inside the narrow slide-over panel, collapse back to a single column. */
.panel__body .record-detail { display: block; }
.panel__body .record-detail > .card { margin-bottom: 14px; }
.card__title .card__count { font-family: var(--font-mono); font-weight: 600; color: var(--color-text-muted); margin-left: 6px; }

/* Read-only View: a responsive definition grid (label above value). */
.def-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 2px 26px; margin: 0; }
.def-item { padding: 9px 0; border-bottom: 1px dashed var(--color-border); min-width: 0; }
.def-item--wide { grid-column: 1 / -1; }
.def-label { font-family: var(--font-mono); font-size: 0.64rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--color-text-muted); margin: 0 0 3px; }
.def-value { font-size: 0.92rem; color: var(--color-text); margin: 0; word-wrap: break-word; overflow-wrap: anywhere; }
.def-value .muted { color: var(--color-text-muted); }

/* Chip lists (m2m links in the View). */
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
    background: var(--color-surface-2); border: 1px solid var(--color-border); font-size: 0.78rem; color: var(--color-text);
}

/* Forms: responsive field grid inside each section card. */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 0 22px; align-items: start; }
.form-grid .form-group--wide { grid-column: 1 / -1; }
.form-grid .form-group { margin-bottom: 18px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.form-actions .spacer { flex: 1; }
.input-with-action { display: flex; gap: 8px; align-items: stretch; }
.input-with-action .form-control { flex: 1; }
.input-with-action .btn { white-space: nowrap; }

/* m2m relation grid (checkbox grid inside a form). */
.m2m-grid-wrap {
    border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
    background: var(--color-surface-2); padding: 12px 14px; max-height: 280px; overflow-y: auto;
}
.m2m-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 7px 14px; }
.m2m-grid .checkbox-row { font-size: 0.85rem; gap: 7px; align-items: flex-start; }
.m2m-group { font-family: var(--font-mono); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--color-text-muted); font-weight: 600; margin: 12px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--color-border); }
.m2m-group:first-child { margin-top: 0; }

/* Related records: blocks of clickable chips. */
.related-section { margin-top: 28px; }
.section-label { font-family: var(--font-mono); font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--color-text-secondary); margin-bottom: 12px; }
.related-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(248px, 1fr)); gap: 14px; }
.related-block { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm); padding: 13px 15px; }
.related-block__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 9px; }
.related-block__title { font-size: 0.82rem; font-weight: 700; margin: 0; display: flex; align-items: center; gap: 7px; color: var(--color-dark); }
.related-count { font-family: var(--font-mono); font-size: 0.66rem; background: var(--color-surface-2);
    border: 1px solid var(--color-border); border-radius: 999px; padding: 1px 8px; color: var(--color-text-secondary); }
.related-soft { font-size: 0.64rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.related-items { display: flex; flex-direction: column; gap: 5px; }
.related-item { display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 7px 11px; border-radius: var(--radius-sm); background: var(--color-surface-2);
    border: 1px solid transparent; font-size: 0.85rem; color: var(--color-text); cursor: pointer; transition: all 0.12s; }
a.related-item:hover { border-color: var(--color-primary); background: var(--color-primary-faint); color: var(--color-primary-dark); text-decoration: none; transform: translateX(2px); }
.related-item--static { cursor: default; }
.related-item__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.related-item__meta { font-family: var(--font-mono); font-size: 0.66rem; color: var(--color-text-muted); flex: none; }
.related-more { display: inline-block; margin-top: 10px; font-size: 0.74rem; font-weight: 600; color: var(--color-primary-dark); }

/* ============================================================ Attachments / image galleries
   Reusable image gallery + upload, embedded in every record view. */
.attach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-bottom: 16px; }
.attach-item { position: relative; margin: 0; border: 1px solid var(--color-border); border-radius: var(--radius-md);
    overflow: hidden; background: var(--color-surface-2); aspect-ratio: 4 / 3; }
.attach-item.is-primary { border-color: var(--color-primary); box-shadow: 0 0 0 1px var(--color-primary); }
.attach-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-badge { position: absolute; top: 6px; left: 6px; background: var(--color-primary); color: #fff;
    font-family: var(--font-mono); font-size: 0.58rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
    padding: 2px 7px; border-radius: 999px; }
.attach-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 5px; opacity: 0; transition: opacity 0.12s; }
.attach-item:hover .attach-actions, .attach-item:focus-within .attach-actions { opacity: 1; }
.attach-actions form { margin: 0; }
.attach-btn { width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
    border: none; border-radius: 6px; background: rgba(15, 23, 42, 0.82); color: #fff; font-size: 0.95rem; line-height: 1; }
.attach-btn:hover { background: rgba(15, 23, 42, 0.95); }
.attach-btn--danger:hover { background: var(--color-danger, #dc2626); }
.attach-upload { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.attach-upload .form-control { flex: 1; min-width: 180px; }
.attach-files { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.attach-file { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--color-border);
    border-radius: var(--radius-sm); background: var(--color-surface-2); }
.attach-file__name { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; color: var(--color-text); text-decoration: none; }
.attach-file__name:hover { color: var(--color-primary-dark); }
.attach-file__icon { flex: none; }
.attach-file__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-file__size { font-family: var(--font-mono); font-size: 0.7rem; color: var(--color-text-muted); flex: none; }
.attach-file .attach-btn { position: static; background: transparent; color: var(--color-text-muted); }
.attach-file .attach-btn:hover { background: var(--color-danger, #dc2626); color: #fff; }

/* Avatars (profile images shown around the app). */
.avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: inherit; }
.profile-avatar { width: 96px; height: 96px; border-radius: 50%; overflow: hidden; background: var(--color-surface-2);
    border: 1px solid var(--color-border); display: flex; align-items: center; justify-content: center;
    font-size: 2.2rem; font-weight: 700; color: var(--color-text-secondary); }
.topbar__avatar { width: 30px; height: 30px; border-radius: 50%; overflow: hidden; flex: none; }
.topbar__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.profile-avatar { flex: none; }
.profile-head__body { min-width: 220px; flex: 1; }
.profile-head__name { font-size: 1.2rem; font-weight: 700; color: var(--color-dark); }
.profile-head__sub { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 7px; }

/* ============================================================ Vehicle DVSA import + history */
.reg-input-row { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; }
.reg-input { flex: 1; min-width: 180px; font-family: var(--font-mono); font-size: 1.4rem; font-weight: 700;
    letter-spacing: 0.08em; text-align: center; }
.reg-input-row .btn { white-space: nowrap; }

/* Mileage history mini bar chart + entry form. */
.mileage-chart { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.mileage-chart__row { display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center; font-size: 0.82rem; }
.mileage-chart__date { color: var(--color-text-muted); font-size: 0.74rem; white-space: nowrap; }
.mileage-chart__track { height: 12px; background: var(--color-surface-2); border-radius: 999px; overflow: hidden; }
.mileage-chart__bar { display: block; height: 100%; background: linear-gradient(90deg, var(--color-primary), var(--color-primary-light)); border-radius: 999px; }
.mileage-chart__val { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; display: flex; align-items: center; gap: 7px; }
.mileage-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.mileage-form .form-group { flex: 0 0 auto; }

/* MOT history list. */
.mot-list { display: flex; flex-direction: column; gap: 12px; }
.mot-test { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 12px 14px; background: var(--color-surface-2); }
.mot-test__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mot-test__date { font-weight: 600; }
.mot-test__meta { color: var(--color-text-muted); font-size: 0.8rem; }
.mot-defects { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mot-defects li { display: flex; align-items: baseline; gap: 8px; font-size: 0.85rem; }

/* ============================================================ Global search */
.topbar__search { flex: 1; max-width: 440px; margin: 0 18px; }
.topbar__search .form-control {
    height: 36px; padding: 6px 16px; font-size: 0.86rem; border-radius: 999px;
    background: var(--color-surface-2); border-color: var(--color-border);
}
.topbar__search .form-control:focus { background: #fff; }
.search-page-form { display: flex; gap: 10px; margin-bottom: 20px; }
.search-page-form .form-control { flex: 1; }
.search-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.search-result { display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-sm); background: var(--color-surface-2);
    border: 1px solid transparent; font-size: 0.86rem; color: var(--color-text); transition: all 0.12s; }
a.search-result:hover { border-color: var(--color-primary); background: var(--color-primary-faint);
    color: var(--color-primary-dark); text-decoration: none; transform: translateX(2px); }
.search-result--static { cursor: default; }
.search-result__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result__meta { font-family: var(--font-mono); font-size: 0.68rem; color: var(--color-text-muted); flex: none; }
.search-result__thumb { flex: none; width: 30px; height: 30px; border-radius: 6px; overflow: hidden; background: var(--color-surface); }
.search-result__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
@media (max-width: 760px) { .topbar__search { display: none; } }

/* Primary-image thumbnails in list tables (opt-in per controller). */
.list-thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; display: block; }
.list-thumb--empty { background: var(--color-surface-2); border: 1px dashed var(--color-border); }

/* ============================================================ Live topbar search dropdown */
.search-live {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 70; display: none;
    background: var(--color-surface); border: 1px solid var(--color-border-strong); border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg); overflow: hidden; max-height: 72vh;
}
.search-live.is-open { display: block; }
.search-live__status { padding: 16px; color: var(--color-text-muted); font-size: 0.86rem; }
.search-live__cats { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--color-border); background: var(--color-surface-2); }
.search-live__cat { border: 1px solid var(--color-border-strong); background: var(--color-surface); border-radius: 999px;
    padding: 3px 10px; font-size: 0.74rem; cursor: pointer; color: var(--color-text-secondary); display: inline-flex; gap: 5px; align-items: center; }
.search-live__cat:hover { border-color: var(--color-primary); color: var(--color-primary-dark); }
.search-live__cat span { font-family: var(--font-mono); font-size: 0.64rem; color: var(--color-text-muted); }
.search-live__cat.is-active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.search-live__cat.is-active span { color: rgba(255, 255, 255, 0.85); }
.search-live__results { max-height: 48vh; overflow-y: auto; padding: 6px; }
.search-live__group-label { font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--color-text-muted); padding: 8px 8px 4px; }
.search-live__item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; text-decoration: none; color: var(--color-text); }
.search-live__item:hover, .search-live__item.is-active { background: var(--color-primary-faint); color: var(--color-primary-dark); text-decoration: none; }
.search-live__thumb { flex: none; width: 28px; height: 28px; border-radius: 6px; overflow: hidden; background: var(--color-surface-2); display: flex; }
.search-live__thumb img { width: 100%; height: 100%; object-fit: cover; }
.search-live__thumb--ph { border: 1px dashed var(--color-border); }
.search-live__label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.86rem; }
.search-live__meta { font-family: var(--font-mono); font-size: 0.68rem; color: var(--color-text-muted); flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-live__all { display: block; text-align: center; padding: 10px; font-size: 0.78rem; font-weight: 600;
    color: var(--color-primary-dark); border-top: 1px solid var(--color-border); background: var(--color-surface-2); text-decoration: none; }
.search-live__all:hover { background: var(--color-primary-faint); }

/* ============================================================ Searchable comboboxes (enhanced selects) */
.combobox { position: relative; }
.combobox__native { position: absolute; left: 0; top: 0; width: 100%; height: 100%; visibility: hidden; pointer-events: none; }
.combobox__input { cursor: pointer; padding-right: 30px; width: 100%; text-overflow: ellipsis; }
.combobox__caret { position: absolute; right: 12px; top: 50%; width: 0; height: 0; margin-top: -2px;
    border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 6px solid var(--color-text-muted);
    cursor: pointer; transition: transform 0.15s; }
.combobox.is-open .combobox__caret { transform: rotate(180deg); }
.combobox__panel {
    position: fixed; z-index: 1200; display: none;
    background: var(--color-surface); border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg); max-height: 280px; overflow-y: auto; padding: 4px;
}
.combobox__panel.is-open { display: block; }
.combobox__option { padding: 7px 10px; border-radius: 6px; font-size: 0.88rem; cursor: pointer; color: var(--color-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combobox__option.is-active, .combobox__option:hover { background: var(--color-primary-faint); color: var(--color-primary-dark); }
.combobox__option.is-selected { font-weight: 600; }
.combobox__option.is-disabled { color: var(--color-text-muted); cursor: default; }
.combobox__option mark { background: transparent; color: inherit; font-weight: 700; }
.combobox__empty { padding: 10px; color: var(--color-text-muted); font-size: 0.85rem; }

/* Planning run-form sub-section headings */
.planning-subhead { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--color-text-secondary); font-weight: 700; margin: 18px 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--color-border); }

/* Route-map legend (Existing/Offered layer toggles) */
.map-legend { position: absolute; top: 12px; right: 12px; z-index: 2; background: var(--color-surface); border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-md); padding: 10px 12px; font-size: 0.78rem; max-width: 230px; }
.map-legend__title { font-family: var(--font-mono); font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); font-weight: 700; margin-bottom: 6px; }
.map-legend__row { display: flex; align-items: center; gap: 7px; padding: 2px 0; cursor: pointer; color: var(--color-text); }
.map-legend__row.is-off { opacity: 0.42; }
.map-legend__row.map-legend__key { cursor: default; }
.map-legend__swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,0.15); }

/* On-map statistics panel (mirrors the original analyzer's left-side controls). */
.map-stats { position: absolute; top: 12px; left: 12px; z-index: 2; background: var(--color-surface); border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm); box-shadow: var(--shadow-md); padding: 10px 12px; font-size: 0.78rem; min-width: 196px; max-width: 240px; }
.map-stats__title { font-family: var(--font-mono); font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); font-weight: 700; margin-bottom: 6px; }
.map-stats__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 2px 0; color: var(--color-text-secondary); }
.map-stats__row strong { color: var(--color-text); font-variant-numeric: tabular-nums; }
.map-stats__active { margin-top: 6px; font-size: 0.68rem; color: var(--color-primary); min-height: 0; }
.map-stats__active:empty { display: none; }

/* Map popup (Mapbox) — dark, compact, matches the analyzer popups. */
.map-popup .mapboxgl-popup-content { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 12px 14px; }
.map-popup .mapboxgl-popup-close-button { color: var(--color-text-muted); font-size: 18px; padding: 2px 6px; }
.map-popup__src { font-family: var(--font-mono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-muted); }
.map-popup__ref { font-size: 1.02rem; font-weight: 700; color: var(--color-primary); margin: 3px 0 2px; }
.map-popup__veh { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.map-popup__pos { font-size: 0.76rem; color: var(--color-text-muted); margin-bottom: 6px; }
.map-popup__loc { font-size: 0.82rem; margin-bottom: 7px; }
.map-popup__loc span { display: block; font-size: 0.62rem; letter-spacing: 0.05em; color: var(--color-text-muted); margin-bottom: 2px; }
.map-popup__detail { font-size: 0.8rem; padding: 6px 8px; border-radius: var(--radius-sm); margin-bottom: 6px; }
.map-popup__detail--mv { background: rgba(76, 175, 80, 0.14); }
.map-popup__detail--prev { background: rgba(255, 193, 7, 0.14); }
.map-popup__sum { margin-top: 8px; padding-top: 9px; border-top: 1px solid var(--color-border); font-size: 0.82rem; }
.map-popup__sum-h { font-weight: 700; color: var(--color-primary); margin-bottom: 4px; }
.map-popup__btn { margin-top: 8px; width: 100%; border: none; border-radius: var(--radius-sm); padding: 7px 12px; font-weight: 600; font-size: 0.8rem;
    cursor: pointer; color: #fff; background: var(--color-primary); }
.map-popup__btn:hover { filter: brightness(1.08); }
.map-badge { display: inline-block; margin-left: 7px; padding: 2px 8px; border-radius: 4px; color: #fff; font-size: 0.62rem; font-weight: 700; vertical-align: middle; }

/* ============================================================ Background tasks panel */
.task-panel__body { display: flex; flex-direction: column; gap: 10px; }
.task-card { border: 1px solid var(--color-border); border-left: 3px solid var(--color-primary); border-radius: var(--radius-sm);
    padding: 10px 12px; background: var(--color-surface-2, var(--color-surface)); }
.task-card--completed { border-left-color: #4CAF50; }
.task-card--failed { border-left-color: #dc3545; }
.task-card--queued { border-left-color: var(--color-text-muted); }
.task-card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.task-card__label { font-weight: 600; font-size: 0.9rem; }
.task-card__msg { margin-top: 6px; font-size: 0.8rem; color: var(--color-text-secondary); font-variant-numeric: tabular-nums; }
.task-card__msg--err { color: #dc3545; }
.task-card__actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.task-pill { font-family: var(--font-mono); font-size: 0.66rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.task-pill--run { background: color-mix(in srgb, var(--color-primary) 15%, transparent); color: var(--color-primary); }
.task-pill--new { background: #4CAF50; color: #fff; text-transform: uppercase; letter-spacing: 0.04em; }
.task-pill--fail { background: rgba(220, 53, 69, 0.15); color: #dc3545; }
.task-bar { margin-top: 8px; height: 8px; border-radius: 999px; background: var(--color-border); overflow: hidden; }
.task-bar__fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--color-primary), #f59944);
    transition: width 0.5s ease; background-size: 24px 24px;
    background-image: linear-gradient(45deg, rgba(255,255,255,0.18) 25%, transparent 25%, transparent 50%, rgba(255,255,255,0.18) 50%, rgba(255,255,255,0.18) 75%, transparent 75%);
    animation: task-bar-stripe 0.8s linear infinite; }
.task-card--queued .task-bar__fill { animation: none; }
@keyframes task-bar-stripe { from { background-position: 0 0; } to { background-position: 24px 0; } }

/* ============================================================ Universal file / image viewer */
.fviewer { position: fixed; inset: 0; z-index: 3000; display: none; align-items: center; justify-content: center;
    background: rgba(8, 12, 20, 0.82); padding: 3vh 3vw; }
.fviewer.is-open { display: flex; }
.fviewer__dialog { position: relative; display: flex; flex-direction: column; width: 100%; max-width: 1100px; max-height: 94vh;
    background: var(--color-surface); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); overflow: hidden; }
.fviewer__bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-2); }
.fviewer__title { font-weight: 600; color: var(--color-dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.fviewer__counter { font-family: var(--font-mono); font-size: 0.72rem; color: var(--color-text-muted); }
.fviewer__spacer { flex: 1; }
.fviewer__btn { display: inline-flex; align-items: center; justify-content: center; height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-strong); background: var(--color-surface); color: var(--color-text); cursor: pointer;
    font-size: 0.82rem; font-weight: 600; text-decoration: none; }
.fviewer__btn:hover { border-color: var(--color-primary); color: var(--color-primary-dark); background: var(--color-primary-faint); text-decoration: none; }
.fviewer__close { width: 32px; padding: 0; font-size: 1.3rem; line-height: 1; }
.fviewer__body { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center;
    background: var(--color-surface-2); }
.fviewer__loading { color: var(--color-text-muted); padding: 40px; }
.fviewer__img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.fviewer__frame { width: 100%; height: 86vh; border: 0; background: #fff; }
.fviewer__text { margin: 0; padding: 18px 20px; width: 100%; height: 100%; overflow: auto; align-self: stretch;
    font-family: var(--font-mono); font-size: 0.82rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; color: var(--color-text); background: var(--color-surface); }
.fviewer__scroll { align-self: stretch; width: 100%; height: 100%; overflow: auto; background: var(--color-surface); }
.fviewer__csv { border-collapse: collapse; width: 100%; font-size: 0.84rem; }
.fviewer__csv th, .fviewer__csv td { border: 1px solid var(--color-border); padding: 6px 10px; text-align: left; white-space: nowrap; }
.fviewer__csv th { background: var(--color-surface-2); position: sticky; top: 0; font-weight: 700; }
.fviewer__fallback { text-align: center; padding: 48px 24px; color: var(--color-text-secondary); }
.fviewer__fileicon { width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    background: var(--color-primary-faint); color: var(--color-primary-dark); font-family: var(--font-mono); font-weight: 700; font-size: 1rem; }
.fviewer__fname { font-weight: 600; color: var(--color-dark); margin-bottom: 4px; word-break: break-word; }
.fviewer__fallback p { margin: 6px 0 18px; font-size: 0.88rem; }
.fviewer__nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border-radius: 50%;
    border: none; background: rgba(15, 23, 42, 0.55); color: #fff; font-size: 1.5rem; line-height: 1; cursor: pointer; z-index: 2; }
.fviewer__nav:hover { background: rgba(15, 23, 42, 0.8); }
.fviewer__prev { left: 12px; }
.fviewer__next { right: 12px; }
@media (max-width: 600px) {
    .fviewer { padding: 0; }
    .fviewer__dialog { max-width: 100%; max-height: 100vh; height: 100vh; border-radius: 0; }
    .fviewer__frame { height: 78vh; }
}

/* ============================================================ Activity timeline (per record) */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__item { position: relative; display: flex; gap: 12px; padding: 0 0 14px 4px; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot { flex: none; width: 9px; height: 9px; border-radius: 50%; margin-top: 5px;
    background: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-faint); }
.timeline__item:not(:last-child)::before { content: ''; position: absolute; left: 8px; top: 16px; bottom: -2px;
    width: 1px; background: var(--color-border); }
.timeline__body { min-width: 0; }
.timeline__main { font-size: 0.88rem; color: var(--color-text); }
.timeline__main .muted { color: var(--color-text-muted); }
.timeline__meta { font-size: 0.72rem; color: var(--color-text-muted); margin-top: 2px; }

/* ==========================================================================
   Accessibility + shared utilities (added in the system-wide polish pass)
   ========================================================================== */

/* Skip-to-content link — visible only on keyboard focus. */
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 10000;
    background: var(--color-dark); color: #fff; padding: 10px 16px; border-radius: 0 0 var(--radius-md) 0;
    font-weight: 600; box-shadow: var(--shadow-md); }
.skip-link:focus { left: 0; text-decoration: none; outline: 2px solid var(--color-primary); }
#main-content:focus { outline: none; }   /* programmatic focus target, no ring */

/* Screen-reader-only text (give an accessible name to icon/visual-only controls). */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Flush card body for tables (replaces repeated inline style="padding:0"). */
.card__body--flush { padding: 0 !important; }

/* Shared "flag" chips — advisory warnings / clashes / notes (consolidates the per-view inline pills
   in the leave + tasks views). Tinted via colour-mix off the design tokens. */
.flag-list { display: flex; flex-wrap: wrap; gap: 6px; font-size: 0.74rem; }
.flag { display: inline-flex; align-items: center; gap: 4px; border-radius: var(--radius-md); padding: 2px 8px;
    border: 1px solid var(--color-border); background: var(--color-surface-2); color: var(--color-text-secondary); }
.flag--warn { background: color-mix(in srgb, var(--color-warning) 12%, #fff);
    color: var(--color-warning); border-color: color-mix(in srgb, var(--color-warning) 40%, #fff); }
.flag--clash { background: color-mix(in srgb, var(--color-info) 11%, #fff);
    color: var(--color-info); border-color: color-mix(in srgb, var(--color-info) 38%, #fff); }
.flag--bad { background: color-mix(in srgb, var(--color-error) 11%, #fff);
    color: var(--color-error); border-color: color-mix(in srgb, var(--color-error) 38%, #fff); }
.flag--ok { background: color-mix(in srgb, var(--color-success) 11%, #fff);
    color: var(--color-success); border-color: color-mix(in srgb, var(--color-success) 38%, #fff); }

/* Colour-coded "dot + label" badge driven by a CSS variable (set inline as --c). Injection-safe because
   the controller passes a validated hex via hex_colour(). */
.colour-badge { display: inline-flex; align-items: center; gap: 6px; }
.colour-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto;
    background: var(--c, var(--color-text-muted)); }

/* Respect reduced-motion: neutralise animations/transitions across the whole design system. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- Operations Tasks board + My tasks (moved out of the per-view <style> blocks) ---- */
.task-board th, .task-board td { vertical-align: top; padding: 6px 8px; }
.task-board .cl-task { font-size: .84rem; font-weight: 500; }
.cl-today { background: rgba(37, 99, 235, .06); }
.cl-inst { display: flex; align-items: center; gap: 5px; font-size: .76rem; padding: 1px 0; }
.cl-who { font-weight: 600; }
.cl-inst.is-done .cl-who { color: var(--color-success); }
.cl-inst.is-missed .cl-who { color: var(--color-error); }
.cl-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: 0 0 auto; background: #cbd2dc; }
.cl-dot.is-done { background: var(--color-success); } .cl-dot.is-pending { background: var(--color-warning); }
.cl-dot.is-na { background: var(--color-text-muted); } .cl-dot.is-missed { background: var(--color-error); }
.cl-actions { display: inline-flex; gap: 3px; margin-left: 2px; }
.cl-signoff { font-size: .72rem; line-height: 1; color: var(--color-warning); flex: 0 0 auto; }
.cl-signoff.is-signed { color: var(--color-success); }
.cl-inst.needs-signoff { outline: 1px dashed color-mix(in srgb, var(--color-warning) 55%, transparent); outline-offset: 1px; border-radius: 4px; }
.cl-actions form { margin: 0; display: inline; }
.cl-btn { border: 1px solid var(--color-border); background: var(--color-surface); border-radius: 5px; cursor: pointer; font-size: .68rem; line-height: 1; padding: 2px 5px; }
.cl-btn:hover { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.cl-btn--muted:hover { background: var(--color-text-muted); border-color: var(--color-text-muted); color: #fff; }
.cl-reassign { margin: 2px 0 4px; }
.cl-reassign > summary { font-size: .68rem; color: var(--color-text-secondary); cursor: pointer; }
.cl-reassign form { display: flex; gap: 4px; margin-top: 4px; align-items: center; }
.form-control--sm { padding: 2px 6px; font-size: .76rem; max-width: 140px; }
.myl-balance { display: flex; gap: 28px; flex-wrap: wrap; }
.myl-stat__v { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.myl-stat__l { font-size: .72rem; color: var(--color-text-secondary); margin-top: 4px; text-transform: uppercase; letter-spacing: .03em; }
.cl-myrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--color-border); }
.cl-myrow:last-child { border-bottom: 0; }
.cl-myrow.is-complete .cl-myrow__title { text-decoration: line-through; color: var(--color-text-secondary); }
.cl-myrow__title { font-weight: 600; font-size: .9rem; }
.cl-myrow__meta { font-size: .76rem; margin-top: 2px; }
.cl-myrow__actions { display: flex; gap: 6px; flex: 0 0 auto; }
.cl-myrow__main { flex: 1 1 auto; min-width: 0; }
.cl-myrow__right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.cl-myrow.is-overdue { background: color-mix(in srgb, var(--color-warning) 8%, transparent); }
.cl-myrow.is-missed { background: color-mix(in srgb, var(--color-error) 7%, transparent); }
.cl-act { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin: 0; }
.cl-act__btns { display: flex; gap: 6px; }
.cl-note > summary { font-size: .7rem; color: var(--color-text-secondary); cursor: pointer; list-style: none; }
.cl-note > summary::-webkit-details-marker { display: none; }
.cl-note > summary::before { content: '+ '; font-weight: 700; }
.cl-note[open] > summary::before { content: '\2212 '; font-weight: 700; }
/* My-tasks completion progress bar */
.task-progress { height: 8px; border-radius: 999px; background: var(--color-border); overflow: hidden; margin-top: 12px; }
.task-progress > span { display: block; height: 100%; background: var(--color-success); border-radius: 999px; transition: width .3s ease; }

/* ---- Notification bell (topbar) + notifications page ---- */
.notif { position: relative; }
.notif__btn { position: relative; background: none; border: 0; cursor: pointer; color: var(--color-text-secondary); padding: 6px; border-radius: 8px; display: inline-flex; }
.notif__btn:hover { background: var(--color-surface-2, #f3f4f6); color: var(--color-text); }
.notif__btn svg { width: 20px; height: 20px; }
.notif__badge { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; padding: 0 3px; border-radius: 999px; background: var(--color-error); color: #fff; font-size: .62rem; font-weight: 700; line-height: 16px; text-align: center; }
.notif__badge[hidden] { display: none; }
.notif__panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 70; width: 340px; max-height: 440px; overflow-y: auto; background: var(--color-surface, #fff); border: 1px solid var(--color-border); border-radius: 12px; box-shadow: 0 16px 44px rgba(2, 6, 23, .18); }
.notif__panel[hidden] { display: none; }
.notif__head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--color-border); font-weight: 600; font-size: .9rem; position: sticky; top: 0; background: var(--color-surface, #fff); }
.notif__readall { background: none; border: 0; color: var(--color-primary); cursor: pointer; font-size: .78rem; }
.notif__list { list-style: none; margin: 0; padding: 0; }
.notif__item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--color-border); cursor: pointer; text-decoration: none; color: inherit; }
.notif__item:hover { background: var(--color-surface-2, #f7f8fa); }
.notif__item.is-unread { background: color-mix(in srgb, var(--color-primary) 7%, transparent); }
.notif__ico { flex: 0 0 auto; color: var(--color-text-secondary); margin-top: 1px; }
.notif__ico svg { width: 16px; height: 16px; }
.notif__txt { flex: 1 1 auto; min-width: 0; }
.notif__t { font-size: .84rem; font-weight: 600; }
.notif__b { font-size: .78rem; color: var(--color-text-secondary); }
.notif__time { font-size: .7rem; color: var(--color-text-muted); margin-top: 2px; }
.notif__empty { padding: 20px 14px; text-align: center; color: var(--color-text-secondary); font-size: .85rem; }
.notif__all { display: block; text-align: center; padding: 10px; font-size: .82rem; color: var(--color-primary); text-decoration: none; border-top: 1px solid var(--color-border); }
.notif__all:hover { background: var(--color-surface-2, #f7f8fa); }
.notif-page { list-style: none; margin: 0; padding: 0; }
.notif-page__item { display: flex; gap: 14px; align-items: flex-start; padding: 14px 18px; border-bottom: 1px solid var(--color-border); }
.notif-page__item:last-child { border-bottom: 0; }
.notif-page__item.is-unread { background: color-mix(in srgb, var(--color-primary) 5%, transparent); }
.notif-page__icon { flex: 0 0 auto; color: var(--color-text-secondary); margin-top: 2px; }
.notif-page__icon svg { width: 18px; height: 18px; }
.notif-page__main { flex: 1 1 auto; min-width: 0; }
.notif-page__title { font-weight: 600; text-decoration: none; color: inherit; }
.notif-page__title:hover { color: var(--color-primary); }
.notif-page__body { font-size: .86rem; margin-top: 2px; }
.notif-page__meta { font-size: .74rem; margin-top: 4px; }
.notif-page__item--success .notif-page__icon { color: var(--color-success); }
.notif-page__item--warning .notif-page__icon { color: var(--color-warning); }
.notif-page__item--error .notif-page__icon { color: var(--color-error); }
