:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --border: #2d3a4f;
    --text: #e8edf4;
    --muted: #8b9cb3;
    --accent: #3d8bfd;
    --accent-hover: #5ba3ff;
    --danger: #f87171;
    --warning: #fbbf24;
    --radius: 10px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    background: radial-gradient(1200px 600px at 10% -10%, #1e3a5f 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, #2d1f4e 0%, transparent 50%), var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Links in body copy and tables. Without this they fall back to the browser
   defaults (#0000EE blue, #551A8B visited purple), which are close to
   invisible on the dark surfaces. Component links set their own colour and
   win on specificity. */
a {
    color: #7db4ff;
    text-decoration: underline;
    text-decoration-color: rgba(125, 180, 255, 0.4);
    text-underline-offset: 2px;
}

a:visited {
    /* Keep visited links legible rather than letting the UA mute them. */
    color: #7db4ff;
}

a:hover {
    color: #a9cdff;
    text-decoration-color: currentColor;
}

body.has-sidebar {
    padding-left: 240px;
}

body.sidebar-open {
    overflow: hidden;
}

.site-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    width: 240px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1rem 0.75rem;
}

.site-sidebar-brand {
    display: block;
    padding: 0.35rem 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.02em;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.75rem;
}

.site-sidebar-brand:hover {
    color: var(--accent);
}

.site-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.site-sidebar-category {
    margin-bottom: 0.25rem;
}

.site-sidebar-category-label {
    display: block;
    padding: 0.45rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    list-style: none;
    cursor: pointer;
    user-select: none;
    border-radius: 6px;
}

.site-sidebar-category-label::-webkit-details-marker {
    display: none;
}

.site-sidebar-category > summary.site-sidebar-category-label {
    position: relative;
    padding-right: 1.5rem;
}

.site-sidebar-category > summary.site-sidebar-category-label::after {
    content: "";
    position: absolute;
    right: 0.55rem;
    top: 50%;
    width: 0.4rem;
    height: 0.4rem;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: translateY(-65%) rotate(45deg);
    transition: transform 0.15s ease;
}

.site-sidebar-category[open] > summary.site-sidebar-category-label::after {
    transform: translateY(-35%) rotate(-135deg);
}

.site-sidebar-category > summary.site-sidebar-category-label:hover {
    color: var(--text);
    background: rgba(61, 139, 253, 0.06);
}

.site-sidebar-links {
    list-style: none;
    margin: 0.15rem 0 0.5rem;
    padding: 0 0 0 0.35rem;
}

.site-sidebar-links li {
    margin: 0.1rem 0;
}

.site-sidebar-link,
.site-sidebar-logout {
    display: flex;
    align-items: center;
    padding: 0.45rem 0.65rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    border-radius: 6px;
    border: 1px solid transparent;
}

.site-sidebar-link:hover,
.site-sidebar-logout:hover {
    color: var(--text);
    background: rgba(61, 139, 253, 0.08);
}

.site-sidebar-link.is-active,
.site-sidebar-link[aria-current="page"] {
    /* --accent on the 12% tint measures 4.0:1; the lighter link blue is 6.3:1. */
    color: #7db4ff;
    background: rgba(61, 139, 253, 0.12);
    border-color: rgba(61, 139, 253, 0.35);
}

.site-sidebar-empty-group {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.site-sidebar-category.is-empty {
    opacity: 0.45;
    pointer-events: none;
}

.site-sidebar-category.is-empty .site-sidebar-category-label {
    cursor: default;
}

.site-sidebar-logout {
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.site-sidebar-logout:hover {
    color: var(--danger);
    background: rgba(248, 113, 113, 0.08);
}

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 0.75rem;
    left: 0.75rem;
    z-index: 150;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
}

.sidebar-toggle:hover {
    border-color: rgba(61, 139, 253, 0.45);
    background: rgba(61, 139, 253, 0.08);
}

.sidebar-toggle-icon,
.sidebar-toggle-icon::before,
.sidebar-toggle-icon::after {
    display: block;
    width: 1.1rem;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
}

.sidebar-toggle-icon {
    position: relative;
}

.sidebar-toggle-icon::before,
.sidebar-toggle-icon::after {
    content: "";
    position: absolute;
    left: 0;
}

.sidebar-toggle-icon::before {
    top: -6px;
}

.sidebar-toggle-icon::after {
    top: 6px;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(0, 0, 0, 0.55);
}

@media (max-width: 1023px) {
    body.has-sidebar {
        padding-left: 0;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .site-sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    }

    .site-sidebar.is-open {
        transform: translateX(0);
    }
}

.page {
    max-width: 880px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0 0 0.35rem;
    letter-spacing: -0.02em;
}

.lead {
    color: var(--muted);
    margin: 0 0 1.75rem;
    font-size: 0.95rem;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.35rem 1.25rem;
    margin-bottom: 1.25rem;
}

.card h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 1rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

/* ============================================================
   SHARED FORM INPUTS
   Appearance only (no width). Full-width is scoped to
   modal/form contexts below. Search/inline inputs that need
   var(--surface) keep it via their own class specificity.
   ============================================================ */
input[type="text"], input[type="email"], input[type="url"],
input[type="number"], input[type="password"], input[type="date"],
input[type="search"], textarea {
    padding: 0.55rem 0.65rem;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.modal-inner input, .modal-inner textarea,
.account-fieldset input, .account-fieldset textarea {
    width: 100%;
}

input:focus,
select:focus {
    outline: 2px solid rgba(61, 139, 253, 0.35);
    outline-offset: 1px;
    border-color: var(--accent);
}

/* Dropdowns — use class field-select on <select> */
select.field-select,
.field-select {
    width: 100%;
    padding: 0.55rem 0.65rem;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.field-select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
    border-color: var(--accent);
}

.field-select--compact {
    width: 100%;
    min-width: 10rem;
    max-width: 22rem;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
    color: inherit;
}

.field-select--mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Checkboxes — use checkbox-label wrapper + field-checkbox on <input type="checkbox"> */
.checkbox-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
}

.field-checkbox {
    width: 1rem;
    height: 1rem;
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

.field-checkbox:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.field-checkbox--warning {
    accent-color: var(--warning);
}

.cell-checkbox {
    width: 5rem;
    text-align: center;
    vertical-align: middle;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.2;
    /* An <a class="btn"> and a <button class="btn"> must be the same height;
       without a floor the anchor's line box made it 41px and the button 39px. */
    min-height: 2.5rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    /* White on --accent (#3d8bfd) is only 3.3:1 — below AA for button-sized
       text. A darker blue keeps the identity and reaches 4.8:1. */
    background: #2f6fd8;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #2760bb;
}

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.btn-secondary:hover {
    background: rgba(61, 139, 253, 0.12);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.12);
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ============================================================
   SHARED BUTTON / SMALL UTILITIES
   ============================================================ */
.btn-sm {
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
    min-height: 2rem;
}

.btn-remove {
    justify-self: start;
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.btn-remove:hover { color: var(--danger); border-color: rgba(248, 113, 113, 0.45); }
.btn-remove:disabled { opacity: 0.5; cursor: not-allowed; }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1rem;
}

.message {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    display: none;
}

.message.visible {
    display: block;
}

.message.success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #86efac;
}

.message.error {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #fecaca;
}

.message code {
    font-size: 0.88em;
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.25);
}

/* ============================================================
   SHARED LAYOUT UTILITIES
   ============================================================ */
.card-flush { padding: 0; overflow: hidden; }
.table-wrap { overflow: auto; max-height: calc(100vh - 6rem); }
.toolbar-hint { margin: 0; font-size: 0.85rem; color: var(--muted); }
.toolbar-label { font-size: 0.85rem; color: var(--muted); }
.field-hint { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--muted); }
.optional::after { content: " (optional)"; font-weight: 400; color: var(--muted); opacity: 0.85; }

.grid { display: grid; gap: 1rem; }
.grid-one { grid-template-columns: 1fr; }

@media (min-width: 560px) {
    .grid-two { grid-template-columns: 1fr 1fr; }
    .grid-span-two { grid-column: 1 / -1; }
}

/* ============================================================
   SHARED DATA TABLE
   Dominant look: font-size .9rem, th/td padding .6rem .75rem,
   sticky thead with background #151c28.
   ============================================================ */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.data-table th, .data-table td {
    padding: 0.5rem 0.5625rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    background: var(--surface);
}

.data-table tbody tr:hover { background: rgba(61, 139, 253, 0.06); }

/* Shared cell helpers */
.cell-num { font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.cell-stat { color: var(--muted); font-variant-numeric: tabular-nums; }
.cell-empty { color: var(--muted); font-size: 0.9rem; }
.cell-actions { white-space: nowrap; }
.cell-actions .btn + .btn { margin-left: 0.35rem; }

/* ============================================================
   SHARED TABS
   ============================================================ */
.tabs-wrap { padding: 0.75rem 0.75rem 0; margin-bottom: 1rem; overflow: hidden; }

.tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.25rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
    scrollbar-width: thin;
}

.tab {
    flex: 0 0 auto;
    max-width: 14rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.82rem;
    font-family: inherit;
    color: var(--muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.tab:hover { color: var(--text); background: rgba(61, 139, 253, 0.06); }
.tab.is-active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab .tab-count { font-weight: 400; color: var(--muted); font-size: 0.9em; }
.tab.is-missing { max-width: none; color: #fbbf24; }
.tab.is-missing.is-active { color: #fcd34d; border-bottom-color: #fbbf24; }
.tab.is-missing:hover { background: rgba(251, 191, 36, 0.08); }

/* ============================================================
   SHARED MODAL
   ============================================================ */
.modal {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.modal--sm { max-width: min(100vw - 2rem, 440px); }
.modal--md { max-width: min(100vw - 2rem, 520px); }
.modal--lg { max-width: min(100vw - 2rem, 720px); width: 100%; }

.modal::backdrop { background: rgba(0, 0, 0, 0.55); }

.modal-inner { padding: 1.25rem 1.35rem 1.35rem; }
.modal-inner h2 { margin: 0 0 1rem; font-size: 1.1rem; font-weight: 600; }
.modal-inner label { display: block; font-size: 0.8rem; font-weight: 500; color: var(--muted); margin-bottom: 0.35rem; }

.modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: flex-end;
    margin-top: 0.25rem;
    margin-bottom: 0;
}

/* ============================================================
   SHARED SUPPLIER / ORDER FORM BITS
   Per-tool grid-template-columns for .line-row stay in tool CSS.
   ============================================================ */
.lines-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.lines-toolbar p { margin: 0; font-size: 0.85rem; color: var(--muted); }

.line-row {
    display: grid;
    gap: 0.75rem;
    align-items: end;
    padding: 0.85rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.65rem;
}

/* ---- Responsive base (v1.56) ------------------------------------------ */
img,
svg,
video {
    max-width: 100%;
}

h1 {
    font-size: clamp(1.35rem, 1.1rem + 1.2vw, 1.5rem);
    overflow-wrap: anywhere;
}

.card,
.report-grid > *,
.adv-grid > * {
    min-width: 0;
}

input,
select,
textarea,
button {
    max-width: 100%;
}

.modal-inner,
dialog,
[role="dialog"] {
    max-width: min(92vw, 720px);
    max-height: 90vh;
    overflow: auto;
}

.table-wrap {
    scrollbar-width: thin;
}

/* A table placed straight in a card is its own scroll container at every
   width. Without this, a narrow grid column lets the table's minimum width
   push the whole document sideways. */
.card > table.data-table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

/* ---- Mobile pass (v1.54) ---------------------------------------------- */
@media (max-width: 767px) {
    body {
        overflow-x: hidden;
    }

    /* Must come after the base .page rule, which otherwise resets padding-top. */
    .page,
    .page.page-wide {
        max-width: 100%;
        padding: 4.25rem 1rem 3rem;
    }

    h1 {
        font-size: 1.35rem;
    }

    .lead {
        font-size: 0.9rem;
        margin-bottom: 1.25rem;
    }

    .table-wrap {
        max-height: none;
        -webkit-overflow-scrolling: touch;
    }

    .site-sidebar {
        width: min(86vw, 320px);
    }
}

/* Tablet: the sidebar is off-canvas from <=1023px, so the page needs room for
   the toggle. This block sits last on purpose — the base .page rule above
   would otherwise reset the padding-top, which is exactly how the title ended
   up underneath the button in v1.54. */
@media (min-width: 768px) and (max-width: 1023px) {
    .page,
    .page.page-wide {
        padding-top: 4.25rem;
    }
}

/* ---- Touch targets (v1.58) -------------------------------------------- */
@media (pointer: coarse) {
    /* Fingers, not cursors: 44px is the minimum comfortable target. */
    .site-sidebar-link,
    .site-sidebar-logout,
    .site-sidebar-category-label,
    .btn,
    .btn-sm {
        min-height: 44px;
    }

    .site-sidebar-category-label {
        display: flex;
        align-items: center;
    }

    /* iOS Safari zooms the whole page when a focused field is smaller than
       16px. Scoped to touch so desktop density is untouched. */
    input,
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ---- Focus visibility (v1.64) ----------------------------------------- */
/* Keyboard users get a ring on every control. :where() keeps this at zero
   specificity, so component styles can refine it rather than fight it. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid #8bc0ff;
    outline-offset: 2px;
}

/* Tables that pan inside a card: a soft inner shadow at each edge so it reads
   as scrollable. Inset shadows paint above the container background and below
   the (transparent) table cells, and do not scroll with the content. */
.table-wrap {
    box-shadow: inset -22px 0 18px -6px rgba(0, 0, 0, 0.95),
                inset 22px 0 18px -6px rgba(0, 0, 0, 0.6);
}


/* Theme layer (v2.13). Dark remains the default; light is opt-in per device. */
:root {
    color-scheme: dark;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #eef1f7;
    --surface: #ffffff;
    --border: #d7dfea;
    --text: #16202e;
    --muted: #52637a;
    --accent: #1d4ed8;
    --accent-hover: #1e40af;
    --danger: #b91c1c;
    --warning: #92400e;
}

/* Appearance control in the sidebar */
.site-sidebar-appearance {
    padding: 0.75rem 1rem 0.25rem;
    border-top: 1px solid var(--border);
}

.site-sidebar-appearance-label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.site-sidebar-appearance-options {
    display: flex;
    gap: 0.4rem;
}

.site-sidebar-appearance-options button {
    flex: 1;
    min-height: 44px;
    padding: 0.45rem 0.5rem;
    font: inherit;
    font-size: 0.85rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.site-sidebar-appearance-options button[aria-pressed="true"] {
    color: #ffffff;
    background: var(--accent);
    border-color: var(--accent);
}

.site-sidebar-appearance-note {
    display: block;
    margin-top: 0.45rem;
    font-size: 0.75rem;
    color: var(--muted);
}

/* Theme layer (v2.13): colours that were only legible on dark. */
:root[data-theme="light"] a,
:root[data-theme="light"] a:visited,
:root[data-theme="light"] a:hover {
    color: var(--accent);
}

:root[data-theme="light"] .site-sidebar-link.is-active,
:root[data-theme="light"] .site-sidebar-link[aria-current="page"] {
    color: var(--accent);
}

:root[data-theme="light"] .message.success {
    color: #166534;
}

:root[data-theme="light"] .message.error {
    color: #b91c1c;
}

:root[data-theme="light"] .tab.is-missing,
:root[data-theme="light"] .tab.is-missing.is-active {
    color: var(--warning);
}

/* Background style (v2.14). Purple is the default and matches what shipped. */
html[data-bg="blue"] body {
    background: radial-gradient(1200px 600px at 10% -10%, #173a68 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, #1c3f7d 0%, transparent 50%), var(--bg);
}

html[data-bg="slate"] body {
    background: radial-gradient(1200px 600px at 10% -10%, #2c3947 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, #24303d 0%, transparent 50%), var(--bg);
}

html[data-bg="solid"] body {
    background: var(--bg);
}

/* Light mode keeps a wash, but pale enough not to affect text contrast. */
html[data-theme="light"] body {
    background: radial-gradient(1200px 600px at 10% -10%, #dce6fb 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, #e9defa 0%, transparent 50%), var(--bg);
}

html[data-theme="light"][data-bg="blue"] body {
    background: radial-gradient(1200px 600px at 10% -10%, #d5e4fb 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, #d8e7fc 0%, transparent 50%), var(--bg);
}

html[data-theme="light"][data-bg="slate"] body {
    background: radial-gradient(1200px 600px at 10% -10%, #dfe5ec 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, #e3e9f0 0%, transparent 50%), var(--bg);
}

html[data-theme="light"][data-bg="solid"] body {
    background: var(--bg);
}

.site-sidebar-appearance-sub {
    margin-top: 0.6rem;
}

.site-sidebar-appearance-options {
    flex-wrap: wrap;
}

/* Custom background colour (v2.17): the wheel sets the two gradient stops. */
html[data-bg="custom"] body {
    background: radial-gradient(1200px 600px at 10% -10%, var(--grad-a, #1e3a5f) 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, var(--grad-b, #2d1f4e) 0%, transparent 50%), var(--bg);
}

html[data-theme="light"][data-bg="custom"] body {
    background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--grad-a, #1e3a5f), white 72%) 0%, transparent 55%),
        radial-gradient(900px 500px at 90% 0%, color-mix(in srgb, var(--grad-b, #2d1f4e), white 88%) 0%, transparent 50%), var(--bg);
}

.bg-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.bg-controls input[type="color"] {
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
}

.bg-solid {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    cursor: pointer;
}

/* Top bar + dropdown menu (v2.20). Mobile only; desktop keeps the sidebar. */
.topbar {
    display: none;
}

@media (max-width: 1023px) {
    .topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.75rem;
        position: sticky;
        top: 0;
        z-index: 40;
        /* A little breathing room at the top of the document; when the page
           scrolls, the margin leaves and the bar sits flush against the top. */
        margin-top: 0.5rem;
        padding: 0.55rem 0.85rem;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
    }

    .topbar-brand {
        font-weight: 600;
        color: var(--text);
        text-decoration: none;
    }

    .topbar .sidebar-toggle {
        position: static;
        display: inline-flex;
        width: auto;
        height: auto;
        align-items: center;
        min-height: 44px;
        padding: 0.35rem 0.85rem;
        font: inherit;
        font-size: 0.95rem;
        color: var(--text);
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 8px;
        cursor: pointer;
        box-shadow: none;
    }

    .topbar .sidebar-toggle-icon {
        display: none;
    }

    /* The aside becomes a dropdown under the bar instead of a left drawer. */
    .site-sidebar {
        position: fixed;
        top: 54px;
        left: 0.5rem;
        right: 0.5rem;
        width: auto;
        max-width: none;
        max-height: calc(100dvh - 66px);
        transform: none;
        display: none;
        translate: 0 -8px;
        transition: opacity 0.16s ease, translate 0.16s ease, visibility 0.16s;
        border: 1px solid var(--border);
        border-radius: 12px;
        box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
        z-index: 45;
    }

    .site-sidebar.is-open {
        transform: none;
        display: flex;
        translate: 0 0;
    }

    .sidebar-backdrop {
        display: none !important;
    }

    .page,
    .page.page-wide {
        padding-top: 0.75rem;
    }
}

/* v2.29 — the top bar already carries the brand on mobile; hide the duplicate
   inside the dropdown. */
@media (max-width: 1023px) {
    .site-sidebar-brand {
        display: none;
    }
}

/* v2.31 — flat menu on phones, matching SEO Studio: plain rows, no collapsible
   group headers, a generous tap target and a soft highlight for the open page. */
@media (max-width: 1023px) {
    .site-sidebar.is-flat .site-sidebar-category-label,
    .site-sidebar.is-flat .site-sidebar-empty-group {
        display: none;
    }

    .site-sidebar.is-flat .site-sidebar-category {
        margin: 0;
        padding: 0;
        border: 0;
    }

    .site-sidebar.is-flat .site-sidebar-category + .site-sidebar-category {
        margin-top: 0.35rem;
        padding-top: 0.35rem;
        border-top: 1px solid var(--border);
    }

    .site-sidebar.is-flat .site-sidebar-links {
        margin: 0;
        padding: 0;
        list-style: none;
    }

    .site-sidebar.is-flat .site-sidebar-link {
        display: block;
        padding: 0.7rem 0.65rem;
        border-radius: 10px;
        font-size: 1rem;
        letter-spacing: 0;
        text-transform: none;
        color: var(--text);
    }

    .site-sidebar.is-flat .site-sidebar-link:hover {
        background: rgba(61, 139, 253, 0.10);
    }

    .site-sidebar.is-flat .site-sidebar-link.is-active {
        background: rgba(61, 139, 253, 0.16);
        color: #3d8bfd;
        font-weight: 600;
    }
}

/* Global search (v2.53) */
.site-search-open {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    margin: 0 0 0.75rem;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.85rem;
    cursor: pointer;
}
.site-search-open kbd {
    margin-left: auto;
    padding: 0 0.3rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--muted);
}
.site-search {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 1rem 1rem;
}
.site-search[hidden] {
    display: none;
}
.site-search-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
}
.site-search-panel {
    position: relative;
    width: min(640px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}
.site-search-panel input {
    width: 100%;
    padding: 0.9rem 1rem;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 1rem;
    outline: none;
}
.site-search-results {
    max-height: 55vh;
    overflow-y: auto;
    padding: 0.4rem;
}
.site-search-group {
    padding: 0.3rem 0;
}
.site-search-group-title {
    margin: 0.4rem 0.6rem 0.25rem;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
}
.site-search-row {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.55rem 0.6rem;
    border-radius: 8px;
    color: var(--text);
    text-decoration: none;
}
.site-search-row:hover {
    background: rgba(61, 139, 253, 0.12);
}
.site-search-row span {
    font-size: 0.8rem;
    color: var(--muted);
}
.site-search-hint {
    padding: 1rem;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Sortable tables (v2.55) */
.data-table th.is-sortable,
.report-table-flat th.is-sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.data-table th.is-sortable::after,
.report-table-flat th.is-sortable::after {
    content: "↕";
    margin-left: 0.35rem;
    font-size: 0.8em;
    opacity: 0.35;
}
.data-table th.is-sorted-asc::after,
.report-table-flat th.is-sorted-asc::after {
    content: "↑";
    opacity: 0.85;
}
.data-table th.is-sorted-desc::after,
.report-table-flat th.is-sorted-desc::after {
    content: "↓";
    opacity: 0.85;
}
