/* =====================================================================
   YXTX Admin - Design System
   Direction: Data/Dashboard style with brand accents (deep navy rail + indigo accent)
   Rule: every colour comes from a CSS variable; dark mode only overrides variables, never structure
   ===================================================================== */

/* ------------------------------ 1. Tokens ------------------------------ */
:root {
    /* Brand */
    --brand: #4f46e5;
    --brand-600: #4338ca;
    --brand-700: #3730a3;
    --brand-soft: rgba(79, 70, 229, 0.09);
    --brand-soft-2: rgba(79, 70, 229, 0.16);
    --brand-ring: rgba(79, 70, 229, 0.28);

    /* Semantic */
    --success: #059669;
    --success-soft: rgba(5, 150, 105, 0.1);
    --warn: #d97706;
    --warn-soft: rgba(217, 119, 6, 0.12);
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.1);
    --info: #0284c7;
    --info-soft: rgba(2, 132, 199, 0.1);

    /* Neutral */
    --bg: #f6f8fc;
    --bg-2: #eef2f9;
    --surface: #ffffff;
    --surface-2: #f7f9fd;
    --surface-3: #eef2f8;
    --border: #e4e9f2;
    --border-strong: #d3dbe9;
    --text: #0f172a;
    --text-2: #3d4a61;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    /* Sidebar (stays dark in both themes, acting as the visual anchor) */
    --nav-bg: #0a1224;
    --nav-bg-2: #101c33;
    --nav-border: rgba(255, 255, 255, 0.07);
    --nav-text: #93a4c4;
    --nav-text-strong: #f2f6ff;
    --nav-active: rgba(109, 107, 255, 0.16);

    /* Sizing */
    --topbar-h: 64px;
    --radius-sm: 8px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px -6px rgba(16, 24, 40, 0.1);
    --shadow-md: 0 2px 4px rgba(16, 24, 40, 0.04), 0 12px 28px -12px rgba(16, 24, 40, 0.16);
    --shadow-lg: 0 8px 16px -8px rgba(16, 24, 40, 0.12), 0 24px 48px -16px rgba(16, 24, 40, 0.2);

    /* Typography */
    /* System / local fonts only, no web fonts loaded */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC",
        "Noto Sans SC", "Noto Sans CJK SC", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg: #080e1a;
    --bg-2: #0c1424;
    --surface: #111a2c;
    --surface-2: #16203a;
    --surface-3: #1b2742;
    --border: #24304a;
    --border-strong: #33415f;
    --text: #e9eefb;
    --text-2: #c3cee3;
    --text-muted: #8fa0be;
    --text-faint: #6b7d9c;

    --brand: #7c7aff;
    --brand-600: #6d6bff;
    --brand-700: #5b58f0;
    --brand-soft: rgba(124, 122, 255, 0.14);
    --brand-soft-2: rgba(124, 122, 255, 0.22);
    --brand-ring: rgba(124, 122, 255, 0.34);

    --nav-bg: #060b15;
    --nav-bg-2: #0b1424;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 16px -8px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.35), 0 16px 32px -16px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 12px 24px -12px rgba(0, 0, 0, 0.55), 0 32px 64px -24px rgba(0, 0, 0, 0.7);
}

/* ------------------------------ 2. Reset ------------------------------ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6, p, figure {
    margin: 0;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    color: var(--brand-600);
}

button {
    font: inherit;
    color: inherit;
}

img,
svg {
    display: block;
    max-width: 100%;
}

table {
    border-collapse: collapse;
    width: 100%;
}

ul, ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

::selection {
    background: var(--brand-soft-2);
    color: var(--text);
}

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Scrollbars */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border: 3px solid transparent;
    border-radius: 99px;
    background-clip: content-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--text-faint);
    background-clip: content-box;
}

/* ------------------------------ 3. Layout skeleton ------------------------------ */
/* Structure: top bar (brand / main nav / actions) -> content. No sidebar, the width belongs to content. */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.skip-link {
    position: fixed;
    top: -60px;
    left: 12px;
    z-index: 90;
    padding: 8px 14px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-md);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    transition: top 0.16s var(--ease);
}

.skip-link:focus {
    top: 12px;
}

/* ---- Top bar ---- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
}

.topbar__inner {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 1600px;
    height: var(--topbar-h);
    margin: 0 auto;
    padding: 0 20px;
}

/* ---- Brand ---- */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    color: var(--text);
}

.brand:hover {
    color: var(--text);
}

.brand__mark {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, #6d6bff 0%, #4f46e5 45%, #0ea5e9 100%);
    box-shadow: 0 6px 16px -6px rgba(109, 107, 255, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.24);
    font-weight: 800;
    font-size: 15px;
    letter-spacing: -0.4px;
}

.brand__text {
    min-width: 0;
    line-height: 1.15;
}

.brand__name {
    display: block;
    font-size: 14px;
    font-weight: 680;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand__tag {
    display: block;
    font-size: 10px;
    color: var(--text-faint);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    white-space: nowrap;
}

/* ---- Main nav (level 1 = group) ---- */
.topnav {
    display: flex;
    align-items: center;
    gap: 3px;
    min-width: 0;
    margin-left: 8px;
}

.topnav__item {
    position: relative;
}

.topnav__link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 36px;
    padding: 0 11px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-2);
    font-size: 13.5px;
    font-weight: 550;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease), border-color 0.15s var(--ease);
}

.topnav__link svg {
    flex-shrink: 0;
    opacity: 0.72;
}

.topnav__link:hover {
    background: var(--surface-3);
    color: var(--text);
}

.topnav__link:hover svg {
    opacity: 1;
}

.topnav__link.is-current {
    background: var(--brand-soft);
    border-color: var(--brand-soft-2);
    color: var(--brand);
    font-weight: 650;
}

.topnav__link.is-current svg {
    opacity: 1;
}

.topnav__caret {
    display: flex;
    margin-left: -1px;
    opacity: 0.6;
    transition: transform 0.18s var(--ease);
}

.topnav__item.is-open .topnav__caret {
    transform: rotate(180deg);
    opacity: 1;
}

.topnav__badge {
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: 99px;
    background: var(--danger);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 17px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Group dropdown */
.topnav__panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 60;
    min-width: 210px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.16s var(--ease), transform 0.16s var(--ease), visibility 0.16s;
}

/* The 8px gap between trigger and panel must not break the hover */
.topnav__panel::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -10px;
    height: 10px;
}

.topnav__item.is-open .topnav__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.topnav__sublink {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 13px;
    transition: background 0.14s var(--ease), color 0.14s var(--ease);
}

.topnav__sublink svg {
    flex-shrink: 0;
    opacity: 0.6;
}

.topnav__sublink:hover {
    background: var(--surface-2);
    color: var(--text);
}

.topnav__sublink:hover svg {
    opacity: 0.9;
}

.topnav__sublink.is-active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 600;
}

.topnav__sublink.is-active svg {
    opacity: 1;
}

/* ---- Top bar actions ---- */
.topbar__actions {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    flex-shrink: 0;
}

/* The hamburger shows on narrow screens only; higher specificity so a later .icon-btn cannot override it */
.topbar .topbar__nav-btn {
    display: none;
}

.topbar__search {
    position: relative;
    width: 232px;
}

.topbar__search input {
    width: 100%;
    height: 36px;
    padding: 0 58px 0 34px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
    transition: border-color 0.16s var(--ease), background 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.topbar__search input::placeholder {
    color: var(--text-faint);
}

.topbar__search input:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.topbar__search .icon-slot {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}

.topbar__kbd {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    padding: 1px 5px;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-faint);
    font-family: var(--font-sans);
    font-size: 10px;
    letter-spacing: 0.02em;
    pointer-events: none;
}

.icon-btn {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    transition: background 0.16s var(--ease), color 0.16s var(--ease), border-color 0.16s var(--ease);
}

.icon-btn:hover {
    background: var(--surface-3);
    color: var(--text);
}

/* Theme switch: two icon sets driven by data-theme, no DOM swapping in JS */
.icon-btn__sun {
    display: none;
}

[data-theme="dark"] .icon-btn__moon {
    display: none;
}

[data-theme="dark"] .icon-btn__sun {
    display: block;
}

.icon-btn__dot {
    position: absolute;
    top: 7px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--danger);
    box-shadow: 0 0 0 2px var(--surface);
}

/* User menu */
.user-menu {
    position: relative;
}

.user-menu__trigger {
    display: flex;
    align-items: center;
    gap: 9px;
    height: 38px;
    padding: 0 8px 0 6px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    transition: background 0.16s var(--ease), border-color 0.16s var(--ease);
}

.user-menu__trigger:hover {
    background: var(--surface-2);
    border-color: var(--border);
}

.user-menu__meta {
    text-align: left;
    line-height: 1.2;
}

.user-menu__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.user-menu__role {
    font-size: 11px;
    color: var(--text-muted);
}

.dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 216px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.16s var(--ease), transform 0.16s var(--ease), visibility 0.16s;
    z-index: 60;
}

.dropdown.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown__head {
    padding: 9px 11px 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 5px;
}

.dropdown__head strong {
    display: block;
    font-size: 13px;
}

.dropdown__head span {
    font-size: 11.5px;
    color: var(--text-muted);
}

.dropdown__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 11px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    transition: background 0.14s var(--ease), color 0.14s var(--ease);
}

.dropdown__item:hover {
    background: var(--surface-2);
    color: var(--text);
}

.dropdown__item--danger {
    color: var(--danger);
}

.dropdown__item--danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.dropdown__divider {
    height: 1px;
    background: var(--border);
    margin: 5px 0;
}

/* Quick nav (top search) */
.quicknav {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 330px;
    overflow-y: auto;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 70;
}

.quicknav__item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 13px;
    transition: background 0.12s var(--ease), color 0.12s var(--ease);
}

.quicknav__item:hover,
.quicknav__item.is-active {
    background: var(--brand-soft);
    color: var(--brand);
}

.quicknav__item span {
    margin-left: auto;
    font-size: 10.5px;
    color: var(--text-faint);
}

/* The label must not be pushed right by the span rule above: it is the primary label */
.quicknav__item .qn-label {
    margin-left: 0;
    font-size: 13px;
    color: inherit;
}

.quicknav__empty {
    padding: 16px 10px;
    text-align: center;
    font-size: 12.5px;
    color: var(--text-muted);
}

/* ---- Content area ---- */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.content {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 18px 24px 56px;
}

.content__inner {
    min-width: 0;
}

/* Breadcrumbs: first row of content, demoted to secondary information */
.crumbs {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 18px;
    margin-bottom: 10px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.crumbs a {
    color: var(--text-muted);
}

.crumbs a:hover {
    color: var(--brand);
}

.crumbs__sep {
    color: var(--text-faint);
    display: flex;
}

.crumbs__current {
    color: var(--text-2);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Page head: consistent everywhere (title + description / primary action on the right) */
.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    padding-bottom: 16px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.page-head__main {
    min-width: 0;
    flex: 1 1 320px;
}

.page-head h1 {
    font-size: 21px;
    font-weight: 680;
    line-height: 1.3;
    letter-spacing: -0.4px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-head__desc {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.65;
    max-width: 72ch;
}

.page-head__desc strong {
    color: var(--text-2);
}

.page-head__actions {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
    margin-left: auto;
}

/* ------------------------------ 4. Cards ------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card--flush {
    overflow: hidden;
}

.card__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
}

.card__title {
    font-size: 14.5px;
    font-weight: 650;
    letter-spacing: -0.1px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card__title small {
    font-weight: 500;
    font-size: 12px;
    color: var(--text-muted);
}

.card__sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.card__actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card__body {
    padding: 18px;
}

.card__body--tight {
    padding: 0;
}

/* KPI grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.kpi {
    position: relative;
    padding: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.kpi:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi::after {
    content: "";
    position: absolute;
    right: -30px;
    top: -40px;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: radial-gradient(circle, var(--kpi-glow, var(--brand-soft)) 0%, transparent 68%);
    pointer-events: none;
}

.kpi__top {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.kpi__icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: var(--kpi-bg, var(--brand-soft));
    color: var(--kpi-fg, var(--brand));
    flex-shrink: 0;
}

.kpi__label {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 550;
    letter-spacing: 0.01em;
}

.kpi__value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.9px;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.kpi__value small {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0;
}

.kpi__foot {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.kpi__spark {
    position: absolute;
    right: 12px;
    bottom: 10px;
    width: 78px;
    height: 30px;
    opacity: 0.85;
}

/* Trends */
.trend {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 12px;
    font-weight: 650;
    padding: 1px 7px 1px 5px;
    border-radius: 99px;
    font-variant-numeric: tabular-nums;
}

.trend--up {
    color: var(--danger);
    background: var(--danger-soft);
}

.trend--down {
    color: var(--success);
    background: var(--success-soft);
}

/* Grid tools */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.grid-main {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 16px;
    /* Cards size to their content, so a single left card is not stretched by two taller cards on the right */
    align-items: start;
}

/* Declare equal heights explicitly where needed (pairs with .card__body--chart to centre the chart vertically) */
.grid-main--stretch {
    align-items: stretch;
}

.card__body--chart {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ------------------------------ 5. Buttons ------------------------------ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 38px;
    padding: 0 15px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
        color 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.06s var(--ease);
}

.btn:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn:active {
    transform: translateY(1px);
}

.btn[disabled],
.btn.is-disabled {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.btn--primary {
    background: linear-gradient(180deg, var(--brand) 0%, var(--brand-600) 100%);
    border-color: var(--brand-600);
    color: #fff;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.12), 0 8px 18px -10px var(--brand-600);
}

.btn--primary:hover {
    background: linear-gradient(180deg, var(--brand-600) 0%, var(--brand-700) 100%);
    border-color: var(--brand-700);
    color: #fff;
}

.btn--danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.btn--danger:hover {
    background: #b91c1c;
    border-color: #b91c1c;
    color: #fff;
}

.btn--ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}

.btn--ghost:hover {
    background: var(--surface-3);
    color: var(--text);
}

.btn--soft {
    background: var(--brand-soft);
    border-color: transparent;
    color: var(--brand);
}

.btn--soft:hover {
    background: var(--brand-soft-2);
    color: var(--brand-700);
}

.btn--sm {
    height: 32px;
    padding: 0 11px;
    font-size: 12.5px;
    border-radius: var(--radius-sm);
}

.btn--xs {
    height: 28px;
    padding: 0 9px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    gap: 5px;
}

.btn--block {
    width: 100%;
}

.btn--lg {
    height: 44px;
    padding: 0 20px;
    font-size: 14px;
}

.btn-group {
    display: inline-flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* ------------------------------ 6. Forms ------------------------------ */
.field {
    margin-bottom: 16px;
}

.field__label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-2);
}

.field__label .req {
    color: var(--danger);
}

.field__hint {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

.field__error {
    margin-top: 6px;
    font-size: 12px;
    color: var(--danger);
    display: flex;
    align-items: center;
    gap: 5px;
}

.input,
.select,
.textarea {
    width: 100%;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 13.5px;
    font-family: inherit;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}

.textarea {
    height: auto;
    min-height: 96px;
    padding: 10px 12px;
    resize: vertical;
    line-height: 1.6;
}

.input::placeholder,
.textarea::placeholder {
    color: var(--text-faint);
}

.input:hover,
.select:hover,
.textarea:hover {
    border-color: var(--border-strong);
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.input.has-error,
.select.has-error,
.textarea.has-error {
    border-color: var(--danger);
}

.input.has-error:focus {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.22);
}

.input[disabled],
.select[disabled],
.textarea[disabled] {
    background: var(--surface-3);
    color: var(--text-muted);
    cursor: not-allowed;
}

.select {
    appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    cursor: pointer;
}

[data-theme="dark"] .select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238fa0be' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group .input {
    border-radius: var(--radius) 0 0 var(--radius);
}

.input-group__addon {
    display: grid;
    place-items: center;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-left: 0;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 12.5px;
    white-space: nowrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 18px;
}

.form-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field--full {
    grid-column: 1 / -1;
}

/* ---------------------------------------------------------------------
   Bilingual (Chinese/English) fields
   ---------------------------------------------------------------------
   Three channels state the language at once, so one failing still leaves it readable:
     1. Badge text: a Chinese glyph / "EN" (does not rely on colour)
     2. 3px bar on the left (amber = Chinese, blue = English)
     3. A language bar above long fields ("public default" / "used on /en")
   Colour values also meet >= 4.5:1 on light backgrounds, with brighter variants in dark mode.
   --------------------------------------------------------------------- */

.lang-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    margin-bottom: 14px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 12.5px;
    color: var(--text-2);
}

.lang-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.lang-legend__swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    flex: none;
}

.lang-legend__swatch--zh { background: #b45309; }
.lang-legend__swatch--en { background: #1d4ed8; }

.lang-legend__divider { color: var(--border-strong); }

.lang-legend__hint {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 11.5px;
}

.lang-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    min-width: 21px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0.02em;
}

/* Amber: Chinese / default locale. #92400E on #FEF3C7 is about 6.3:1 */
.lang-badge--zh {
    background: #fef3c7;
    color: #92400e;
    box-shadow: inset 0 0 0 1px rgba(180, 83, 9, 0.3);
}

/* Blue: English site. #1D4ED8 on #DBEAFE is about 5.5:1 */
.lang-badge--en {
    background: #dbeafe;
    color: #1d4ed8;
    box-shadow: inset 0 0 0 1px rgba(29, 78, 216, 0.26);
}

[data-theme="dark"] .lang-badge--zh {
    background: rgba(217, 119, 6, 0.2);
    color: #fcd34d;
    box-shadow: inset 0 0 0 1px rgba(252, 211, 77, 0.32);
}

[data-theme="dark"] .lang-badge--en {
    background: rgba(37, 99, 235, 0.24);
    color: #93c5fd;
    box-shadow: inset 0 0 0 1px rgba(147, 197, 253, 0.32);
}

/* Left colour bar: sits on the field edge so the language of a block is obvious at a glance */
.lang-field {
    position: relative;
    padding-left: 13px;
}

.lang-field::before {
    content: "";
    position: absolute;
    left: 0;
    top: 1px;
    bottom: 1px;
    width: 3px;
    border-radius: 2px;
}

.lang-field--zh::before { background: #b45309; }
.lang-field--en::before { background: #1d4ed8; }

[data-theme="dark"] .lang-field--zh::before { background: #f59e0b; }
[data-theme="dark"] .lang-field--en::before { background: #3b82f6; }

/* Short fields side by side (Chinese left, English right); narrow screens or containers stack them */
.lang-pair {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    column-gap: 20px;
}

/* auto-fit instead of a fixed pair of columns: with 1fr 1fr the SEO field in a narrow right
   column (about 440px) got squeezed into two 200px slots and became unreadable once Chinese wrapped.
   Sit side by side only when there is room for 2x260px; otherwise stack. */
@media (min-width: 1280px) {
    .lang-pair--split {
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    }
}

/* Language bar above the long editors */
.lang-note {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 8px;
    padding: 6px 11px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 1.5;
}

.lang-note__label { font-weight: 700; }

.lang-note--zh {
    background: #fdf6e7;
    color: #92400e;
    box-shadow: inset 3px 0 0 #b45309;
}

.lang-note--en {
    background: #eff5ff;
    color: #1e40af;
    box-shadow: inset 3px 0 0 #1d4ed8;
}

[data-theme="dark"] .lang-note--zh {
    background: rgba(217, 119, 6, 0.13);
    color: #fcd34d;
}

[data-theme="dark"] .lang-note--en {
    background: rgba(37, 99, 235, 0.16);
    color: #bfdbfe;
}

/* Sub-note for the language bar (fallback rules and the like) */
.lang-note__tail {
    color: inherit;
    opacity: 0.78;
}

/* Switch */
.switch {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    user-select: none;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch__track {
    position: relative;
    width: 40px;
    height: 23px;
    border-radius: 99px;
    background: var(--border-strong);
    transition: background 0.2s var(--ease);
    flex-shrink: 0;
}

.switch__track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
    transition: transform 0.2s var(--ease);
}

.switch input:checked + .switch__track {
    background: var(--brand);
}

.switch input:checked + .switch__track::after {
    transform: translateX(17px);
}

.switch input:focus-visible + .switch__track {
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.switch__label {
    font-size: 13px;
    color: var(--text-2);
}

/* Checkbox / radio */
.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-2);
}

.check input {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
    cursor: pointer;
}

/* Form sections */
.section {
    border-top: 1px solid var(--border);
    padding-top: 20px;
    margin-top: 20px;
}

.section:first-of-type {
    border-top: 0;
    padding-top: 0;
    margin-top: 0;
}

.section__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    font-weight: 650;
    margin-bottom: 14px;
    color: var(--text);
}

.section__title::before {
    content: "";
    width: 3px;
    height: 14px;
    border-radius: 2px;
    background: var(--brand);
}

/* Two-column form layout */
.form-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
    align-items: start;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    position: sticky;
    bottom: 0;
    z-index: 5;
}

.form-actions__spacer {
    flex: 1;
}

/* Filter bar */
.filters {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.filters .field {
    margin: 0;
}

.filters .field__label {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.filters .input,
.filters .select {
    height: 34px;
    font-size: 13px;
    min-width: 132px;
}

.filters__search {
    min-width: 236px;
}

.filters__spacer {
    flex: 1;
}

/* ------------------------------ 7. Tables ------------------------------ */
.table-wrap {
    overflow-x: auto;
}

.table {
    width: 100%;
    font-size: 13px;
}

.table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text-2);
}

.table tbody tr {
    transition: background 0.14s var(--ease);
}

.table tbody tr:hover {
    background: var(--surface-2);
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table__num {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text);
}

.table__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}

.table__check {
    width: 40px;
}

.table__check input {
    width: 16px;
    height: 16px;
    accent-color: var(--brand);
}

.table--compact tbody td {
    padding: 9px 14px;
}

.cell-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.cell-main__text {
    min-width: 0;
}

.cell-main__title {
    font-weight: 600;
    color: var(--text);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 340px;
}

.cell-main__meta {
    font-size: 11.5px;
    color: var(--text-muted);
}

.thumb {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    border: 1px solid var(--border);
    background: var(--surface-3);
    flex-shrink: 0;
}

.thumb--empty {
    display: grid;
    place-items: center;
    color: var(--text-faint);
    background: linear-gradient(135deg, var(--surface-3), var(--surface-2));
}

.avatar {
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.avatar--letter {
    display: inline-grid;
    place-items: center;
    color: #fff;
    font-weight: 700;
    background: var(--avatar-bg, var(--brand));
    border: 0;
    letter-spacing: -0.02em;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 650;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.85;
}

.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warn    { background: var(--warn-soft);    color: var(--warn); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--brand   { background: var(--brand-soft);   color: var(--brand); }
.badge--muted   { background: var(--surface-3);    color: var(--text-muted); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 24px;
    padding: 0 9px;
    border-radius: 7px;
    background: var(--surface-3);
    color: var(--text-2);
    font-size: 12px;
    font-weight: 550;
}

.chip--brand {
    background: var(--brand-soft);
    color: var(--brand);
}

/* Empty state */
.empty-state {
    display: grid;
    place-items: center;
    padding: 56px 24px;
    text-align: center;
}

.empty-state__icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: var(--surface-3);
    color: var(--text-faint);
    margin-bottom: 14px;
}

.empty-state__title {
    font-size: 14px;
    font-weight: 650;
    color: var(--text);
}

.empty-state__desc {
    margin-top: 5px;
    font-size: 12.5px;
    color: var(--text-muted);
    max-width: 340px;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}

.pagination__info {
    font-size: 12.5px;
    color: var(--text-muted);
}

.pagination__info b {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.pagination__pages {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-btn {
    display: inline-grid;
    place-items: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 12.5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    transition: all 0.14s var(--ease);
}

.page-btn:hover {
    border-color: var(--brand);
    color: var(--brand);
    background: var(--brand-soft);
}

.page-btn.is-active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.page-btn.is-disabled {
    opacity: 0.42;
    pointer-events: none;
}

.page-ellipsis {
    color: var(--text-faint);
    padding: 0 2px;
}

/* Bulk action bar */
.bulkbar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    background: var(--brand-soft);
    border-bottom: 1px solid var(--brand-soft-2);
    font-size: 12.5px;
    color: var(--brand-700);
}

.bulkbar.is-visible {
    display: flex;
}

[data-theme="dark"] .bulkbar {
    color: #cfceff;
}

/* ------------------------------ 8. Overlays ------------------------------ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(9, 15, 28, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s var(--ease), visibility 0.2s;
}

.modal-backdrop.is-open {
    opacity: 1;
    visibility: visible;
}

.modal {
    width: 100%;
    max-width: 580px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    transform: translateY(10px) scale(0.985);
    transition: transform 0.2s var(--ease);
}

.modal-backdrop.is-open .modal {
    transform: translateY(0) scale(1);
}

.modal--lg {
    max-width: 860px;
}

.modal__head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
}

.modal__title {
    font-size: 15.5px;
    font-weight: 680;
    letter-spacing: -0.2px;
}

.modal__desc {
    font-size: 12.5px;
    color: var(--text-muted);
    margin-top: 3px;
}

.modal__close {
    margin-left: auto;
    flex-shrink: 0;
}

.modal__body {
    padding: 18px 20px;
    overflow-y: auto;
}

.modal__foot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.modal__foot .spacer {
    flex: 1;
}

/* Toast */
.toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 9px;
    max-width: 380px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    color: var(--text);
    pointer-events: auto;
    animation: toast-in 0.22s var(--ease);
}

.toast.is-out {
    animation: toast-out 0.18s var(--ease) forwards;
}

.toast__icon {
    flex-shrink: 0;
    margin-top: 1px;
}

.toast--success { border-left: 3px solid var(--success); }
.toast--success .toast__icon { color: var(--success); }
.toast--error   { border-left: 3px solid var(--danger); }
.toast--error .toast__icon { color: var(--danger); }
.toast--warning { border-left: 3px solid var(--warn); }
.toast--warning .toast__icon { color: var(--warn); }
.toast--info    { border-left: 3px solid var(--info); }
.toast--info .toast__icon { color: var(--info); }

.toast__close {
    margin-left: auto;
    border: 0;
    background: transparent;
    color: var(--text-faint);
    cursor: pointer;
    padding: 0 2px;
    flex-shrink: 0;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(24px) scale(0.97); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
    to { opacity: 0; transform: translateX(24px) scale(0.97); }
}

/* ------------------------------ 9. Other components ------------------------------ */
/* Description list */
.dl {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr);
    gap: 10px 14px;
    font-size: 13px;
}

.dl dt {
    color: var(--text-muted);
}

.dl dd {
    margin: 0;
    color: var(--text);
    word-break: break-word;
}

/* Timeline */
.timeline {
    position: relative;
    padding-left: 22px;
}

.timeline::before {
    content: "";
    position: absolute;
    left: 6px;
    top: 6px;
    bottom: 6px;
    width: 1px;
    background: var(--border);
}

.timeline__item {
    position: relative;
    padding-bottom: 18px;
}

.timeline__item:last-child {
    padding-bottom: 0;
}

.timeline__item::before {
    content: "";
    position: absolute;
    left: -22px;
    top: 4px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border-strong);
}

.timeline__item.is-done::before {
    border-color: var(--brand);
    background: var(--brand);
}

.timeline__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.timeline__meta {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Alerts */
.alert {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 12.5px;
    line-height: 1.6;
    border: 1px solid transparent;
}

.alert__icon {
    flex-shrink: 0;
    margin-top: 1px;
}

.alert strong {
    display: block;
    margin-bottom: 2px;
    font-size: 13px;
}

.alert--info    { background: var(--info-soft);    border-color: rgba(2, 132, 199, 0.22);    color: var(--info); }
.alert--warning { background: var(--warn-soft);    border-color: rgba(217, 119, 6, 0.24);    color: var(--warn); }
.alert--danger  { background: var(--danger-soft);  border-color: rgba(220, 38, 38, 0.22);    color: var(--danger); }
.alert--success { background: var(--success-soft); border-color: rgba(5, 150, 105, 0.22);    color: var(--success); }

.alert p {
    color: var(--text-2);
}

/* ------------------------------ Charts (pure SVG) ------------------------------ */
/* Colours come from CSS variables only: .chart-s1..s4 map --series onto the brand palette,
   and every SVG line/dot/gradient uses var(--series), so light/dark switching needs no redraw. */
.chart {
    position: relative;
    width: 100%;
    --chart-h: 300px;
}

/* Series palette lives on :root so the legend in the card header (outside .chart) can read it too */
:root {
    --chart-1: var(--brand);
    --chart-2: var(--success);
    --chart-3: var(--info);
    --chart-4: var(--warn);
}

[data-theme="dark"] {
    --chart-2: #34d399;
    --chart-3: #38bdf8;
    --chart-4: #fbbf24;
}

.chart__plot {
    position: relative;
    width: 100%;
    height: var(--chart-h);
}

.chart svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
    font-family: var(--font-sans);
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: pan-y;
}

.chart svg:focus-visible {
    outline: 2px solid var(--brand-ring);
    outline-offset: 6px;
    border-radius: 8px;
}

/* Grid and ticks: horizontal lines only, dashed and low contrast */
.chart__grid {
    stroke: var(--border-strong);
    stroke-width: 1;
    stroke-dasharray: 3 5;
    shape-rendering: crispEdges;
}

.chart__axis {
    stroke: var(--border-strong);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.chart__tick,
.chart__xlabel {
    font-size: 10.5px;
    font-variant-numeric: tabular-nums;
    user-select: none;
}

.chart__tick { fill: var(--text-faint); }
.chart__xlabel { fill: var(--text-muted); }

/* Series colours (JS only sets class names, all values live in CSS) */
.chart-s1 { --series: var(--chart-1); }
.chart-s2 { --series: var(--chart-2); }
.chart-s3 { --series: var(--chart-3); }
.chart-s4 { --series: var(--chart-4); }

.chart__grad { stop-color: var(--series); }

.chart__area { stroke: none; }

.chart__line {
    fill: none;
    stroke: var(--series);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1;
    stroke-dashoffset: 0;
}

.chart__line.is-draw { animation: chart-line-draw 400ms var(--ease) both; }
.chart__area.is-draw { animation: chart-area-in 520ms var(--ease) 60ms both; }

@keyframes chart-line-draw {
    from { stroke-dashoffset: 1; }
    to { stroke-dashoffset: 0; }
}

@keyframes chart-area-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Hover layer: guide line plus data point */
.chart__cross {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s var(--ease);
}

.chart svg.is-active .chart__cross { opacity: 1; }

.chart__crosshair {
    stroke: var(--text-faint);
    stroke-width: 1;
    stroke-dasharray: 3 4;
    shape-rendering: crispEdges;
}

.chart__mark {
    fill: var(--surface);
    stroke: var(--series);
    stroke-width: 2;
}

/* Empty state */
.chart__empty {
    position: absolute;
    inset: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12.5px;
    color: var(--text-muted);
    pointer-events: none;
}

.chart__empty[hidden] { display: none; }

/* Value tooltip */
.chart-tip {
    position: absolute;
    z-index: 6;
    min-width: 116px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    box-shadow: var(--shadow-md);
    color: var(--text);
    font-size: 11.5px;
    line-height: 1.55;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, calc(-100% - 10px));
    transition: opacity 0.1s var(--ease);
}

.chart-tip.is-visible {
    opacity: 1;
    visibility: visible;
}
.chart-tip.is-below { transform: translate(-50%, 4px); }

.chart-tip__head {
    display: block;
    margin-bottom: 4px;
    font-weight: 650;
}

.chart-tip__row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chart-tip__dot {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    border-radius: 2px;
    background: var(--series);
}

.chart-tip__name { color: var(--text-muted); }

.chart-tip__val {
    margin-left: auto;
    padding-left: 14px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

/* Legend (click to toggle series visibility) */
.card__tools--legend { margin-left: auto; }

.chart__legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-top: 10px;
    font-size: 12px;
    color: var(--text-muted);
}

.card__tools .legend--toggle,
.chart__legend .legend--toggle {
    padding: 3px 7px;
    margin: -3px -7px;
    border: 0;
    border-radius: 7px;
    background: none;
    font: inherit;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s var(--ease), color 0.15s var(--ease), opacity 0.15s var(--ease);
}

.card__tools .legend--toggle:hover,
.chart__legend .legend--toggle:hover {
    background: var(--surface-2);
    color: var(--text);
}

.card__tools .legend--toggle:focus-visible,
.chart__legend .legend--toggle:focus-visible {
    outline: 2px solid var(--brand-ring);
    outline-offset: 1px;
}

.card__tools .legend--toggle i,
.chart__legend .legend--toggle i { background: var(--series); }

.card__tools .legend--toggle[aria-pressed="false"],
.chart__legend .legend--toggle[aria-pressed="false"] { opacity: 0.5; }

.card__tools .legend--toggle[aria-pressed="false"] i,
.chart__legend .legend--toggle[aria-pressed="false"] i { background: var(--text-faint); }

/* Height adapts to the viewport so a chart never fills the screen */
@media (max-width: 1200px) {
    .chart { --chart-h: 280px; }
}

@media (max-width: 900px) {
    .chart { --chart-h: 260px; }
}

@media (max-width: 560px) {
    .chart { --chart-h: 220px; }
}

@media (prefers-reduced-motion: reduce) {
    .chart__line.is-draw,
    .chart__area.is-draw { animation: none; }

    .chart__cross,
    .chart-tip { transition: none; }
}

/* Segmented control */
.segmented {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    border-radius: var(--radius);
    background: var(--surface-3);
}

.segmented a,
.segmented button {
    padding: 5px 11px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.14s var(--ease);
}

.segmented a:hover,
.segmented button:hover {
    color: var(--text);
}

.segmented .is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-xs);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tabs__item {
    position: relative;
    padding: 11px 14px;
    border: 0;
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: color 0.14s var(--ease);
}

.tabs__item:hover {
    color: var(--text);
}

.tabs__item.is-active {
    color: var(--brand);
}

.tabs__item.is-active::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--brand);
}

.tab-panel {
    display: none;
    padding-top: 18px;
}

.tab-panel.is-active {
    display: block;
}

/* Image upload */
.uploader {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.uploader__preview {
    width: 104px;
    height: 104px;
    border-radius: var(--radius);
    border: 1px dashed var(--border-strong);
    background: var(--surface-2);
    display: grid;
    place-items: center;
    overflow: hidden;
    color: var(--text-faint);
    flex-shrink: 0;
    position: relative;
}

.uploader__preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.uploader__body {
    flex: 1;
    min-width: 180px;
}

.uploader__hint {
    font-size: 11.5px;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Star rating */
.stars {
    display: inline-flex;
    gap: 1px;
    color: #f59e0b;
}

/* Code */
.code {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--surface-3);
    padding: 2px 6px;
    border-radius: 5px;
    color: var(--text-2);
}

/* Dividers */
.divider {
    height: 1px;
    background: var(--border);
    margin: 16px 0;
}

/* Numeric highlight */
.amount {
    font-variant-numeric: tabular-nums;
    font-weight: 650;
    letter-spacing: -0.2px;
}

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: var(--font-mono); font-size: 12.5px; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }

.hidden { display: none !important; }

/* ------------------------------ 10. Login page ------------------------------ */
.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
    background: var(--bg);
}

.auth__visual {
    position: relative;
    overflow: hidden;
    padding: 56px 56px 44px;
    display: flex;
    flex-direction: column;
    color: #eaf0ff;
    background: linear-gradient(150deg, #070d1a 0%, #0d1730 45%, #131f3d 100%);
}

.auth__visual::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(720px 420px at 8% 4%, rgba(109, 107, 255, 0.34), transparent 62%),
        radial-gradient(560px 380px at 96% 92%, rgba(14, 165, 233, 0.26), transparent 66%),
        radial-gradient(420px 260px at 72% 12%, rgba(236, 72, 153, 0.14), transparent 70%);
}

.auth__grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
    background-size: 44px 44px;
    mask-image: radial-gradient(ellipse 78% 62% at 30% 30%, #000 30%, transparent 78%);
    -webkit-mask-image: radial-gradient(ellipse 78% 62% at 30% 30%, #000 30%, transparent 78%);
}

.auth__visual > * {
    position: relative;
    z-index: 1;
}

.auth__logo {
    display: flex;
    align-items: center;
    gap: 11px;
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.2px;
}

.auth__headline {
    margin-top: auto;
    font-size: clamp(28px, 3.1vw, 40px);
    line-height: 1.2;
    font-weight: 720;
    letter-spacing: -1.2px;
}

.auth__headline span {
    background: linear-gradient(100deg, #a5a3ff, #7dd3fc 60%, #6ee7b7);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.auth__sub {
    margin-top: 14px;
    font-size: 14px;
    line-height: 1.7;
    color: #93a4c4;
    max-width: 460px;
}

.auth__stats {
    display: flex;
    gap: 34px;
    margin-top: 38px;
    padding-top: 22px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.auth__stat strong {
    display: block;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.6px;
    font-variant-numeric: tabular-nums;
}

.auth__stat span {
    font-size: 11.5px;
    color: #8194b5;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.auth__panel {
    display: grid;
    place-items: center;
    padding: 40px 28px;
}

.auth__form {
    width: 100%;
    max-width: 392px;
}

.auth__badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    padding: 0 11px;
    border-radius: 99px;
    background: var(--brand-soft);
    color: var(--brand);
    font-size: 11.5px;
    font-weight: 650;
    letter-spacing: 0.02em;
    margin-bottom: 16px;
}

.auth__title {
    font-size: 25px;
    font-weight: 720;
    letter-spacing: -0.7px;
}

.auth__desc {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.6;
}

.auth__form-body {
    margin-top: 24px;
}

.auth__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 18px;
    font-size: 12.5px;
}

.auth__foot {
    margin-top: 26px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-faint);
    line-height: 1.7;
}

.auth__theme {
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 2;
}

/* ------------------------------ 11. Error pages ------------------------------ */
.error-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
    background:
        radial-gradient(720px 420px at 50% 0%, var(--brand-soft), transparent 70%),
        var(--bg);
}

.error-card {
    text-align: center;
    max-width: 480px;
}

.error-code {
    font-size: 96px;
    font-weight: 800;
    letter-spacing: -5px;
    line-height: 1;
    background: linear-gradient(135deg, var(--brand), var(--info));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.error-title {
    margin-top: 12px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.4px;
}

.error-desc {
    margin-top: 10px;
    color: var(--text-muted);
    font-size: 13.5px;
    line-height: 1.7;
}

.error-actions {
    margin-top: 24px;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ------------------------------ 12. Responsive ------------------------------ */
@media (max-width: 1400px) {
    .topbar__search {
        width: 190px;
    }
    .brand__tag {
        display: none;
    }
}

@media (max-width: 1280px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .grid-main {
        grid-template-columns: minmax(0, 1fr);
    }
    .form-layout {
        grid-template-columns: minmax(0, 1fr);
    }
    .topnav {
        gap: 1px;
        margin-left: 2px;
    }
    .topnav__link {
        padding: 0 9px;
        font-size: 13px;
    }
    .user-menu__meta {
        display: none;
    }
    .topbar__search {
        width: 170px;
    }
}

/* Level-1 nav moves into a drawer when it does not fit (always a drawer at 1024 and below) */
@media (max-width: 1180px) {
    .topnav {
        display: none;
    }
    .topbar .topbar__nav-btn {
        display: inline-grid;
    }
    .topbar__search {
        width: 180px;
    }
    .content {
        padding: 16px 18px 48px;
    }
}

@media (max-width: 1024px) {
    .auth {
        grid-template-columns: minmax(0, 1fr);
    }
    .auth__visual {
        display: none;
    }
    .grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .page-head {
        gap: 12px;
    }
}

@media (max-width: 720px) {
    .content {
        padding: 14px 14px 40px;
    }
    .topbar__inner {
        padding: 0 14px;
        gap: 8px;
    }
    .kpi-grid,
    .grid-2,
    .grid-3 {
        grid-template-columns: minmax(0, 1fr);
    }
    .form-grid,
    .form-grid--3 {
        grid-template-columns: minmax(0, 1fr);
    }
    .page-head h1 {
        font-size: 19px;
    }
    .page-head__actions {
        margin-left: 0;
        width: 100%;
    }
    .dl {
        grid-template-columns: 88px minmax(0, 1fr);
    }
    .modal {
        max-height: calc(100vh - 24px);
    }
    .table__check {
        width: 32px;
    }
    .cell-main__title {
        max-width: 190px;
    }
}

/* ---- Mobile drawer navigation ---- */
.mobile-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    width: min(84vw, 320px);
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 0.26s var(--ease), visibility 0.26s;
}

.mobile-nav.is-open {
    transform: translateX(0);
    visibility: visible;
}

.mobile-nav__head {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--topbar-h);
    padding: 0 12px 0 14px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}

.mobile-nav__title-text {
    font-size: 13.5px;
    font-weight: 680;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mobile-nav__close {
    margin-left: auto;
}

.mobile-nav__body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 10px 20px;
}

.mobile-nav__search {
    position: relative;
    margin: 0 2px 6px;
}

.mobile-nav__search input {
    width: 100%;
    height: 38px;
    padding: 0 12px 0 34px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: 13px;
}

.mobile-nav__search input:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

.mobile-nav__search .icon-slot {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint);
    pointer-events: none;
}

.mobile-nav__group {
    padding-top: 4px;
}

.mobile-nav__group-title {
    padding: 12px 12px 5px;
    font-size: 10.5px;
    font-weight: 650;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.mobile-nav__link {
    display: flex;
    align-items: center;
    gap: 11px;
    height: 42px;
    padding: 0 12px;
    border-radius: var(--radius);
    color: var(--text-2);
    font-size: 13.5px;
    font-weight: 500;
}

.mobile-nav__link svg {
    flex-shrink: 0;
    opacity: 0.66;
}

.mobile-nav__link:hover {
    background: var(--surface-2);
    color: var(--text);
}

.mobile-nav__link.is-active {
    background: var(--brand-soft);
    color: var(--brand);
    font-weight: 650;
}

.mobile-nav__link.is-active svg {
    opacity: 1;
}

.mobile-nav__badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 99px;
    background: var(--danger);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.mobile-nav__foot {
    flex-shrink: 0;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-muted);
}

/* Drawer backdrop */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(9, 15, 28, 0.46);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s var(--ease), visibility 0.22s;
}

.drawer-backdrop.is-open {
    opacity: 1;
    visibility: visible;
}

body.is-drawer-open {
    overflow: hidden;
}

/* Skeleton screens */
.skeleton {
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
    background-size: 400% 100%;
    animation: skeleton 1.3s ease infinite;
    border-radius: 6px;
}

@keyframes skeleton {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* Print */
@media print {
    .topbar, .mobile-nav, .drawer-backdrop, .skip-link,
    .page-head__actions, .filters, .filters__actions, .bulkbar, .pagination {
        display: none !important;
    }
    .content {
        padding: 0 !important;
        max-width: none !important;
    }
    body {
        background: #fff;
    }
}

/* Respect the system reduce-motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}

/* =====================================================================
   Showcase additions: status colours, detail lists, code textarea, Markdown cheatsheet
   ===================================================================== */

/* ------------------------------ Chip state variants ------------------------------ */
.chip--ok {
    background: var(--success-soft);
    border-color: rgba(22, 163, 74, 0.28);
    color: var(--success);
}

.chip--warn {
    background: var(--warn-soft);
    border-color: rgba(217, 119, 6, 0.28);
    color: var(--warn);
}

.chip--info {
    background: var(--info-soft);
    border-color: rgba(37, 99, 235, 0.28);
    color: var(--info);
}

.chip--muted {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text-muted);
}

/* ------------------------------ Detail key/value list ------------------------------ */
.detail-list {
    display: grid;
    grid-template-columns: 108px minmax(0, 1fr);
    gap: 12px 16px;
    margin: 0;
}

.detail-list dt {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding-top: 2px;
}

.detail-list dd {
    margin: 0;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    word-break: break-word;
}

/* Inquiry body */
.inquiry-message {
    font-size: 14.5px;
    line-height: 1.85;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}

/* ------------------------------ Code-style textarea ------------------------------ */
.textarea--code {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.8;
    tab-size: 4;
}

/* ------------------------------ Compact tables (cheat sheets) ------------------------------ */
.table--mini th,
.table--mini td {
    padding: 7px 12px;
    font-size: 12.5px;
    border-bottom: 1px solid var(--line-2, var(--border));
}

.table--mini tbody tr:last-child td { border-bottom: 0; }

.table--mini td:first-child {
    width: 210px;
    white-space: nowrap;
}

.table--mini code {
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--brand);
}

/* ------------------------------ Markdown cheat-sheet disclosure ------------------------------ */
.md-help {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.md-help > summary {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 11px 14px;
    cursor: pointer;
    font-size: 12.5px;
    color: var(--text-muted);
    user-select: none;
    list-style: none;
}

.md-help > summary::-webkit-details-marker { display: none; }
.md-help > summary:hover { color: var(--text); }

.md-help__body {
    padding: 0 14px 14px;
    border-top: 1px solid var(--border);
}

.md-help__note {
    margin: 10px 0 0;
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-faint);
}

@media (max-width: 640px) {
    .detail-list { grid-template-columns: minmax(0, 1fr); gap: 4px 0; }
    .detail-list dt { padding-top: 10px; }
    .table--mini td:first-child { width: auto; }
}

/* =====================================================================
   Dashboard: extra KPIs, legends, to-do and activity lists
   ===================================================================== */

.kpi__link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 10px;
    font-size: 12.5px;
    color: var(--brand);
    transition: gap 0.2s var(--ease);
}

.kpi__link:hover { gap: 9px; }

.card__tools {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 12px;
    color: var(--text-muted);
}

.card__link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.card__link:hover { color: var(--brand); }

.legend {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend i {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 3px;
}

/* ------------------------------ Checklist ------------------------------ */
.todo-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.todo-list li { border-bottom: 1px solid var(--border); }
.todo-list li:last-child { border-bottom: 0; }

.todo-list a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 2px;
    transition: padding-left 0.2s var(--ease);
}

.todo-list a:hover { padding-left: 8px; }

.todo-list__label { font-size: 13.5px; color: var(--text); }

.todo-list__value {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-muted);
}

.todo-list__value.is-warn { color: var(--warn); }

/* ------------------------------ Dynamic lists ------------------------------ */
.feed-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.feed-list li { border-bottom: 1px solid var(--border); }
.feed-list li:last-child { border-bottom: 0; }

.feed-list a {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 2px;
}

.feed-list__main {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.feed-list__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    color: var(--text);
}

.feed-list__meta {
    font-size: 12.5px;
    color: var(--text-faint);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 340px;
}

.feed-list__time {
    flex: none;
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--text-faint);
}

/* =====================================================================
   Media picker + multi-image preview (2026-11)
   ===================================================================== */
body.is-modal-open { overflow: hidden; }

.media-modal {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(12, 13, 10, .62);
    backdrop-filter: none;
}

.media-modal[hidden] { display: none; }

.media-modal__panel {
    display: flex;
    flex-direction: column;
    width: min(960px, 100%);
    max-height: min(86vh, 760px);
    background: var(--surface, #fff);
    border: 1px solid var(--line, #e5e3dc);
    border-radius: 12px;
    overflow: hidden;
}

.media-modal__head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line, #e5e3dc);
}

.media-modal__title {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
}

.media-modal__search { flex: 1; min-width: 0; }

.media-modal__close {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line, #e5e3dc);
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    color: inherit;
}

.media-modal__body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

@media (max-width: 720px) {
    .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.media-cell {
    position: relative;
    display: block;
    padding: 0;
    aspect-ratio: 4 / 3;
    border: 1px solid var(--line, #e5e3dc);
    border-radius: 8px;
    overflow: hidden;
    background: #0d0e0b;
    cursor: pointer;
}

.media-cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.media-cell__meta {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 3px 6px;
    font-size: 10px;
    font-family: ui-monospace, monospace;
    color: #eee;
    background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .68));
}

.media-cell.is-picked {
    border-color: #7bd94a;
    box-shadow: 0 0 0 2px rgba(123, 217, 74, .45) inset;
}

.media-cell.is-picked::after {
    content: "✓";
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: #7bd94a;
    color: #10130a;
    font-size: 12px;
    font-weight: 700;
}

.media-grid__empty,
.media-grid__more {
    grid-column: 1 / -1;
}

.media-grid__empty {
    padding: 32px 8px;
    text-align: center;
    color: var(--muted, #6b6f63);
    font-size: 13px;
}

.media-modal__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--line, #e5e3dc);
}

.media-modal__count {
    font-size: 12px;
    color: var(--muted, #6b6f63);
}

.media-modal__actions { display: flex; gap: 8px; }

/* "Pick from library" button inside the uploader */
.uploader__pick {
    margin-top: 8px;
}

/* Multi-image thumbnail preview */
.gallery-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.gallery-preview__empty {
    font-size: 12px;
    color: var(--muted, #6b6f63);
}

.gallery-preview__item {
    position: relative;
    width: 84px;
    height: 84px;
    border: 1px solid var(--line, #e5e3dc);
    border-radius: 8px;
    overflow: hidden;
    background: #0d0e0b;
}

.gallery-preview__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-preview__del {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .62);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}

.gallery-preview__del:hover { background: #c0392b; }

/* =====================================================================
   Rich text editor (self-hosted, no external links)
   ---------------------------------------------------------------------
   Reuses design-system variables only (--surface / --border / --brand / --radius)
   and adds no colour tokens; dark mode follows automatically with no extra overrides.
   ===================================================================== */

.editor {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.editor:hover { border-color: var(--border-strong); }

.editor:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-ring);
}

/* ------------------------------ Toolbar ------------------------------ */
.editor__bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 5px 7px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.editor__tools,
.editor__bar-end {
    display: flex;
    align-items: center;
    gap: 1px;
    flex-wrap: wrap;
}

.editor__bar-end {
    margin-left: auto;
    gap: 4px;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}

.editor__btn {
    display: inline-grid;
    place-items: center;
    min-width: 26px;
    height: 27px;
    padding: 0 4px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font-family: inherit;
    font-size: 12.5px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.12s var(--ease), color 0.12s var(--ease);
}

.editor__btn:hover:not(:disabled) {
    background: var(--surface-3);
    color: var(--text);
}

.editor__btn:active:not(:disabled) { background: var(--brand-soft); }

.editor__btn[aria-pressed="true"] {
    background: var(--brand-soft);
    color: var(--brand);
}

.editor__btn:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

.editor__btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.editor__glyph { font-size: 13px; line-height: 1; }

/* Paragraph style dropdown: looks like a toolbar button but stays a native select for keyboard access */
.editor__select {
    height: 27px;
    max-width: 104px;
    padding: 0 22px 0 7px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background-color: transparent;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 5px center;
    color: var(--text-2);
    font-family: inherit;
    font-size: 12.5px;
    line-height: 1;
    cursor: pointer;
    appearance: none;
}

.editor__select:hover {
    background-color: var(--surface-3);
    color: var(--text);
}

.editor__select:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

[data-theme="dark"] .editor__select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238fa0be' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

.editor__sep {
    width: 1px;
    height: 16px;
    margin: 0 4px;
    background: var(--border);
}

/* Table picker popover */
.editor__menu-wrap {
    position: relative;
    display: inline-flex;
}

.editor__menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 45;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-md);
}

.editor__menu[hidden] { display: none; }

.editor__grid {
    display: grid;
    grid-template-columns: repeat(5, 19px);
    gap: 3px;
}

.editor__grid-cell {
    width: 19px;
    height: 19px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: 3px;
    background: var(--surface-2);
    cursor: pointer;
    transition: background 0.1s var(--ease), border-color 0.1s var(--ease);
}

.editor__grid-cell.is-on {
    border-color: var(--brand);
    background: var(--brand-soft-2);
}

.editor__grid-cell:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

.editor__menu-label {
    margin-top: 7px;
    color: var(--text-muted);
    font-size: 11.5px;
    text-align: center;
    white-space: nowrap;
}

/* ------------------------------ Editing surface ------------------------------ */
.editor__body {
    display: flex;
    flex: 1 1 auto;
    min-height: 140px;
    background: var(--surface);
}

.editor__canvas {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    padding: 13px 15px;
    outline: none;
    font-size: 14px;
    line-height: 1.75;
    color: var(--text);
    overflow-y: auto;
    word-break: break-word;
}

.editor__canvas.is-empty::before {
    content: attr(data-placeholder);
    position: absolute;
    top: 13px;
    left: 15px;
    right: 15px;
    color: var(--text-faint);
    pointer-events: none;
}

/* Typography preview inside the editor: matches the public body copy but uses design-system colours only */
.editor__canvas > *:first-child { margin-top: 0; }
.editor__canvas p { margin: 0 0 10px; }
.editor__canvas h2 { margin: 16px 0 8px; font-size: 17px; font-weight: 700; line-height: 1.4; }
.editor__canvas h3 { margin: 14px 0 6px; font-size: 15px; font-weight: 700; line-height: 1.4; }
.editor__canvas h4 { margin: 12px 0 6px; font-size: 14px; font-weight: 700; }
.editor__canvas ul,
.editor__canvas ol { margin: 0 0 10px; padding-left: 22px; }
.editor__canvas ul { list-style: disc; }
.editor__canvas ol { list-style: decimal; }
.editor__canvas ul ul { list-style: circle; }
.editor__canvas li { margin: 3px 0; }
.editor__canvas blockquote {
    margin: 0 0 10px;
    padding: 6px 12px;
    border-left: 3px solid var(--brand);
    background: var(--brand-soft);
    color: var(--text-2);
}
.editor__canvas a { color: var(--brand); text-decoration: underline; }
.editor__canvas img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    vertical-align: middle;
}
.editor__canvas code {
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-3);
    font-family: var(--font-mono);
    font-size: 12.5px;
}
.editor__canvas table { border-collapse: collapse; margin-bottom: 10px; }
.editor__canvas th,
.editor__canvas td { padding: 6px 10px; border: 1px solid var(--border); }
.editor__canvas th {
    background: var(--surface-2);
    font-weight: 600;
    text-align: left;
}
.editor__canvas hr {
    margin: 14px 0;
    border: 0;
    border-top: 1px solid var(--border-strong);
}
.editor__canvas pre {
    margin: 0 0 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    overflow-x: auto;
}
.editor__canvas pre code {
    padding: 0;
    background: none;
    font-size: 12.5px;
    line-height: 1.7;
}
.editor__canvas s,
.editor__canvas del { text-decoration: line-through; }
.editor__canvas mark {
    padding: 0 2px;
    background: #fde68a;
    color: #78350f;
}

/* Source view (the textarea stays in place for HTML mode) */
.editor__source { display: none; }
.editor[data-mode="html"] .editor__source { flex: 1 1 auto; }
.editor[data-mode="html"].is-source .editor__source { display: block; }
.editor[data-mode="html"].is-source .editor__canvas { display: none; }

.editor__source textarea {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 220px;
    padding: 12px 14px;
    border: 0;
    border-radius: 0;
    background: var(--surface);
    color: var(--text-2);
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.7;
    resize: vertical;
}

.editor__source textarea:focus {
    outline: none;
    box-shadow: none;
}

/* ------------------------------ Markdown split view ------------------------------ */
.editor__split {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
}

.editor__pane {
    display: flex;
    flex-direction: column;
    flex: 1 1 50%;
    min-width: 0;
}

.editor__pane + .editor__pane { border-left: 1px solid var(--border); }

.editor__pane--src textarea {
    display: block;
    flex: 1 1 auto;
    width: 100%;
    min-height: 260px;
    padding: 13px 15px;
    border: 0;
    border-radius: 0;
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.8;
    tab-size: 4;
    resize: none;
}

.editor__pane--src textarea:focus {
    outline: none;
    box-shadow: none;
}

.editor__preview {
    flex: 1 1 auto;
    padding: 13px 16px;
    overflow-y: auto;
    background: var(--surface-2);
    font-size: 13.5px;
    line-height: 1.8;
    color: var(--text-2);
}

.editor__preview > *:first-child { margin-top: 0; }
.editor__preview p { margin: 0 0 10px; }
.editor__preview h1,
.editor__preview h2,
.editor__preview h3,
.editor__preview h4 { margin: 16px 0 8px; color: var(--text); font-weight: 700; line-height: 1.4; }
.editor__preview h1 { font-size: 19px; }
.editor__preview h2 { font-size: 17px; }
.editor__preview h3 { font-size: 15px; }
.editor__preview ul,
.editor__preview ol { margin: 0 0 10px; padding-left: 22px; }
.editor__preview ul { list-style: disc; }
.editor__preview ol { list-style: decimal; }
.editor__preview ul ul { list-style: circle; }
.editor__preview blockquote {
    margin: 0 0 10px;
    padding: 6px 12px;
    border-left: 3px solid var(--brand);
    background: var(--brand-soft);
}
.editor__preview a { color: var(--brand); text-decoration: underline; }
.editor__preview img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.editor__preview code {
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-3);
    font-family: var(--font-mono);
    font-size: 12.5px;
}
.editor__preview pre {
    margin: 0 0 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-3);
    overflow-x: auto;
}
.editor__preview pre code { padding: 0; background: none; }
.editor__preview table { border-collapse: collapse; width: 100%; margin-bottom: 10px; }
.editor__preview th,
.editor__preview td { padding: 6px 10px; border: 1px solid var(--border); }
.editor__preview hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

.editor__preview-empty {
    color: var(--text-faint);
    font-size: 12.5px;
}

/* Preview off: source takes the full width */
.editor.is-preview-off .editor__pane--preview { display: none; }
.editor.is-preview-off .editor__pane--src { flex: 1 1 100%; }

/* Narrow screens: the split becomes stacked */
@media (max-width: 900px) {
    .editor__split { flex-direction: column; }
    .editor__pane + .editor__pane {
        border-left: 0;
        border-top: 1px solid var(--border);
    }
    .editor__pane--src textarea { min-height: 220px; }
    .editor__preview { max-height: 320px; }
}

/* ------------------------------ Bottom status / word count ------------------------------ */
.editor__foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 4px 11px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 11.5px;
    color: var(--text-faint);
}

/* Word count: a small pill on the right of the toolbar so it never competes with the buttons */
.editor__count {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-muted);
    font-size: 11.5px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ------------------------------ Fullscreen ------------------------------ */
.editor.is-fullscreen {
    position: fixed;
    inset: 12px;
    z-index: 90;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

/* Fullscreen pins the toolbar so buttons do not scroll away with the editing surface */
.editor.is-fullscreen .editor__bar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface-2);
}

.editor.is-fullscreen .editor__body { flex: 1 1 auto; min-height: 0; }
.editor.is-fullscreen .editor__canvas { max-height: none; }

body.is-editor-fullscreen { overflow: hidden; }

/* ------------------------------ Link / image input ------------------------------ */
.editor-dialog {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(12, 16, 28, 0.55);
}

.editor-dialog__panel {
    width: min(430px, 100%);
    padding: 16px 18px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.editor-dialog__head {
    margin-bottom: 12px;
    font-size: 13.5px;
    color: var(--text);
}

.editor-dialog__field {
    display: block;
    margin-bottom: 10px;
}

.editor-dialog__label {
    display: block;
    margin-bottom: 5px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
}

.editor-dialog__foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

.editor-dialog__spacer { flex: 1 1 auto; }

.editor-dialog__extra {
    margin-right: auto;
    color: var(--danger);
}

.editor-dialog__check {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 2px 0 4px;
    color: var(--text-2);
    font-size: 12.5px;
    cursor: pointer;
    user-select: none;
}

.editor-dialog__check input {
    width: 15px;
    height: 15px;
    margin: 0;
    accent-color: var(--brand);
    cursor: pointer;
}

/* Toolbar buttons scroll horizontally on narrow screens instead of wrapping into two rows */
@media (max-width: 640px) {
    .editor__bar { padding: 4px 5px; }
    .editor__tools { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
    .editor__tools::-webkit-scrollbar { display: none; }
}

/* Body images: consistent with the public site, shown in full at their natural ratio.
   A max-height:420px was added earlier to keep large images from filling the screen, but it
   squashed and cropped them, so the editor did not match the front end - edit what you see. */
.editor__canvas img {
    max-width: 100%;
    max-height: none;
    width: auto;
    height: auto;
    object-fit: fill;
    display: block;
    margin: 12px 0;
}

/* =====================================================================
   AI integration (inline buttons next to fields / status bar on the settings page)
   Adds only the three elements the existing design language lacks: field-level chips,
   insert highlight and the status bar.
   ===================================================================== */
.ai-chip {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 22px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--brand);
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.ai-chip:hover {
    background: var(--brand-soft);
    border-color: var(--brand-soft-2);
}

.ai-chip:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

.ai-chip.is-busy,
.ai-chip[disabled] {
    opacity: 0.7;
    cursor: progress;
}

/* Read-only badge (the key mask echoed on the settings page) */
.ai-chip--static {
    cursor: default;
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-weight: 500;
    color: var(--text-muted);
    background: var(--surface-3, #f1f5f9);
}

.ai-chip--static:hover {
    background: var(--surface-3, #f1f5f9);
    border-color: var(--border);
}

.ai-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-inline .input {
    flex: 1 1 auto;
    min-width: 0;
}

.ai-spinner {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 1.6px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ai-spin 0.7s linear infinite;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

/* Brief highlight after insertion: makes it obvious where the value landed */
.ai-flash {
    animation: ai-flash 2.4s ease-out 1;
    border-radius: var(--radius);
}

@keyframes ai-flash {
    0%   { box-shadow: 0 0 0 2px var(--brand), 0 0 0 8px var(--brand-soft); }
    60%  { box-shadow: 0 0 0 2px var(--brand-soft-2), 0 0 0 8px transparent; }
    100% { box-shadow: 0 0 0 2px transparent, 0 0 0 8px transparent; }
}

.ai-status {
    margin-top: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12.5px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-status--ok   { background: var(--success-soft); border-color: rgba(5, 150, 105, 0.22); color: var(--success); }
.ai-status--error { background: var(--danger-soft); border-color: rgba(220, 38, 38, 0.22); color: var(--danger); }
.ai-status--warn { background: var(--warn-soft);   border-color: rgba(217, 119, 6, 0.24); color: var(--warn); }

@media (prefers-reduced-motion: reduce) {
    .ai-spinner { animation: none; }
    .ai-flash { animation: none; box-shadow: 0 0 0 2px var(--brand); }
}

/* =====================================================================
   20. Layout hierarchy (follow-up to the top-nav redesign)
   - List pages: filter zone (level 1) and toolbar (level 2) are separated instead of sharing one row
   - Tables: row height, padding and type size are consistent site-wide
   - Cards / forms: spacing and sizes form four levels: h1 -> card title -> field label -> body
   ===================================================================== */

/* ---- Filters (level 1) + action row (level 2) ---- */
.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(184px, 1fr));
    align-items: end;
    gap: 12px 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.filters .field {
    margin: 0;
    min-width: 0;
}

.filters .field__label {
    font-size: 11px;
    font-weight: 650;
    color: var(--text-muted);
    margin-bottom: 5px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.filters .input,
.filters .select {
    height: 36px;
    font-size: 13px;
    width: 100%;
    min-width: 0;
}

.filters__search {
    min-width: 0;
}

/* Long fields such as keywords span two columns and fold back to one on narrow screens */
.filters .field--grow {
    grid-column: span 2;
}

.filters .filters__actions,
.filters__actions {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.filters__actions .filters__spacer {
    flex: 1;
}

/* Result row (second-level toolbar): hugs the table head and acts as a layer above it */
.list-toolbar,
.bulkbar {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    background: var(--brand-soft);
    border-bottom: 1px solid var(--brand-soft-2);
    font-size: 12.5px;
    color: var(--brand-700);
}

.bulkbar.is-visible {
    display: flex;
}

/* ---- Tables: consistent rhythm ---- */
.table {
    font-size: 13px;
}

.table thead th {
    padding: 11px 16px;
    font-size: 11px;
    letter-spacing: 0.07em;
    line-height: 1.4;
}

.table tbody td {
    padding: 13px 16px;
    line-height: 1.5;
    vertical-align: middle;
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table__num {
    font-variant-numeric: tabular-nums;
}

.table__actions {
    gap: 4px;
}

/* ---- Cards: padding and heading hierarchy ---- */
.card + .card,
.card + .stack,
.stack + .card {
    margin-top: 16px;
}

.card__head {
    padding: 15px 18px;
    gap: 10px;
}

.card__title {
    font-size: 14.5px;
    letter-spacing: -0.15px;
}

.card__body {
    padding: 18px;
}

/* ---- Forms: field spacing and label hierarchy ---- */
.form-grid {
    gap: 16px 18px;
}

.field__label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
}

.field__hint {
    line-height: 1.55;
}

.input,
.select,
textarea.input {
    border-radius: var(--radius);
}

/* Breathing room between the page head and the first block */
.page-head + .card,
.page-head + .stack,
.page-head + .grid-main,
.page-head + .kpi-grid,
.page-head + .grid-2,
.page-head + .grid-3 {
    margin-top: 0;
}

/* Uniform spacing between consecutive grid blocks in the content area */
.content__inner > .card + .card,
.content__inner > .stack + .card,
.content__inner > .card + .stack {
    margin-top: 16px;
}

/* =====================================================================
   21. Small-screen clean-up (kept at the end of the file so it overrides the grids and spacing above)
   ===================================================================== */

/* Data tables scroll horizontally on narrow screens instead of squeezing columns into vertical text */
@media (max-width: 900px) {
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
    .table {
        min-width: 680px;
    }
}

@media (max-width: 720px) {
    .topbar__search {
        display: none;
    }
    .table {
        min-width: 640px;
    }
}

/* Below 1280 filter fields share one row equally, so no single field drops to a second row */
@media (max-width: 1280px) {
    .filters .field--grow {
        grid-column: auto;
    }
}

/* 390px tier: single-column fields, equal-width buttons, no wrapping misalignment */
@media (max-width: 480px) {
    :root {
        --topbar-h: 56px;
    }
    .brand__text {
        display: none;
    }
    .topbar__inner {
        padding: 0 12px;
    }
    .content {
        padding: 12px 12px 36px;
    }
    .crumbs {
        font-size: 12px;
        margin-bottom: 8px;
    }
    .page-head {
        padding-bottom: 12px;
        margin-bottom: 14px;
    }
    .page-head__actions {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 8px;
        width: 100%;
        margin-left: 0;
    }
    .page-head__actions > .btn {
        width: 100%;
    }
    .form-grid,
    .form-grid--3,
    .grid-2,
    .grid-3 {
        grid-template-columns: minmax(0, 1fr);
    }
    .filters {
        grid-template-columns: minmax(0, 1fr);
        padding: 12px;
        gap: 10px;
    }
    .filters .field--grow {
        grid-column: auto;
    }
    /* Specificity must beat the flex layout in section 20: hence .filters .filters__actions */
    .filters .filters__actions,
    .filters__actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding-top: 10px;
    }
    .filters__actions .btn {
        width: 100%;
    }
    .form-actions {
        flex-wrap: wrap;
        gap: 8px;
        padding: 12px;
    }
    .form-actions .btn {
        flex: 1 1 auto;
    }
    .table {
        min-width: 600px;
    }
    .table tbody td {
        padding: 11px 12px;
    }
    .table thead th {
        padding: 9px 12px;
    }
    .card__head,
    .card__body {
        padding: 14px;
    }
    .card__head {
        flex-wrap: wrap;
    }
}

/* Tags inside tables never wrap (prevents CJK breaking character by character) */
.chip {
    white-space: nowrap;
}

/* =====================================================================
   22. Contrast fixes (WCAG AA: body text >= 4.5:1, large text >= 3:1)
   - Only variables and status-colour text are overridden; layout is untouched
   - The dark theme gets brighter status colours of its own so they do not look muddy
   ===================================================================== */
:root {
    --text-muted: #5b6b85;
    --chip-ok-ink: #047857;
    --chip-warn-ink: #9c4a06;
    --chip-info-ink: #0369a1;
    --chip-danger-ink: #b91c1c;
}

[data-theme="dark"] {
    --text-muted: #94a4c1;
    --chip-ok-ink: #34d399;
    --chip-warn-ink: #fbbf24;
    --chip-info-ink: #38bdf8;
    --chip-danger-ink: #f87171;
}

.chip--ok {
    color: var(--chip-ok-ink);
}

.chip--warn {
    color: var(--chip-warn-ink);
}

.chip--info {
    color: var(--chip-info-ink);
}

.chip--danger,
.chip--error {
    color: var(--chip-danger-ink);
}

/* Brand subtitle and shortcut hints used --text-faint (about 2.4:1 on white); raised to secondary text level */
.brand__tag,
.topbar__kbd {
    color: var(--text-muted);
}

/* Keep the top-bar search placeholder readable */
.topbar__search input::placeholder,
.mobile-nav__search input::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* Helper copy (form notes, empty states) must also clear 4.5:1 */
.field__hint,
.card__sub,
.cell-main__meta,
.empty__desc {
    color: var(--text-muted);
}

/* Dark-theme primary button: bright purple on white text is only 3.4:1, darkened to clear 5:1 */
[data-theme="dark"] .btn--primary {
    background: linear-gradient(180deg, #5b58f0 0%, #4a46d6 100%);
    border-color: #4a46d6;
}

[data-theme="dark"] .btn--primary:hover {
    background: linear-gradient(180deg, #514ee2 0%, #403cc9 100%);
    border-color: #403cc9;
}

/* Minimum contrast for primary-coloured text (links, active items) on dark backgrounds */
[data-theme="dark"] .btn--soft {
    color: #a5a3ff;
}

/* =====================================================================
   Media library folders (2026-11-21)
   ===================================================================== */
.media-dirbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--line, #e5e3dc);
    font-size: 13px;
}

.media-dirbar__crumb {
    border: 0;
    background: transparent;
    padding: 0;
    font: inherit;
    color: var(--brand, #4f46e5);
    cursor: pointer;
}

.media-dirbar__crumb:hover { text-decoration: underline; }

.media-dirbar__path {
    flex: 1;
    min-width: 0;
    color: var(--muted, #6b6f63);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Folder card */
.media-cell--dir {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--surface-2, #f6f5f1);
    border-style: dashed;
    aspect-ratio: 4 / 3;
}

.media-cell__folder { font-size: 26px; line-height: 1; }

.media-cell__name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text, #23241f);
    max-width: 90%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-cell--dir .media-cell__meta {
    position: static;
    background: none;
    color: var(--muted, #6b6f63);
    padding: 0;
}

/* =====================================================================
   Media library lightbox (2026-11-21)
   ===================================================================== */
.media-cell__zoom {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 6px;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s ease, background .15s ease;
}

.media-cell:hover .media-cell__zoom { opacity: 1; }
.media-cell__zoom:hover { background: rgba(0, 0, 0, .8); }

/* Touch devices have no hover, so show it permanently */
@media (hover: none) {
    .media-cell__zoom { opacity: .85; }
}

.media-lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-items: center;
    padding: 48px 24px 64px;
    background: rgba(8, 9, 7, .92);
}

.media-lightbox[hidden] { display: none; }

.media-lightbox img {
    max-width: min(1400px, 92vw);
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
    background: #111;
}

.media-lightbox__close {
    position: absolute;
    top: 18px;
    right: 22px;
    width: 40px;
    height: 40px;
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 50%;
    background: rgba(255, 255, 255, .08);
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.media-lightbox__close:hover { background: rgba(255, 255, 255, .18); }

.media-lightbox__name {
    position: absolute;
    bottom: 22px;
    left: 0;
    right: 0;
    text-align: center;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    color: rgba(255, 255, 255, .72);
}

/* =====================================================================
   Media library: delete / move / move dialog + gallery drag sorting (2026-11-21)
   ===================================================================== */
.media-cell__act {
    position: absolute;
    top: 6px;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 6px;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s ease, background .15s ease;
}

.media-cell:hover .media-cell__act { opacity: 1; }
.media-cell__act--del { right: 6px; }
.media-cell__act--del:hover { background: #c0392b; }
.media-cell__act--move { right: 38px; }
.media-cell__act--move:hover { background: rgba(0, 0, 0, .85); }

@media (hover: none) {
    .media-cell__act { opacity: .85; }
}

/* Move target picker */
.media-move {
    position: fixed;
    inset: 0;
    z-index: 210;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(8, 9, 7, .62);
}

.media-move__panel {
    width: min(420px, 100%);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
    border-radius: 12px;
    background: var(--surface, #fff);
    border: 1px solid var(--line, #e5e3dc);
}

.media-move__head { font-weight: 600; font-size: 14px; }

.media-move__list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.media-move__item {
    text-align: left;
    padding: 9px 10px;
    border: 1px solid var(--line, #e5e3dc);
    border-radius: 8px;
    background: transparent;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    color: inherit;
}

.media-move__item:hover { background: var(--surface-2, #f6f5f1); }

.media-move__cancel { align-self: flex-end; }

/* Drag to reorder gallery images */
.gallery-preview__item { cursor: grab; }
.gallery-preview__item.is-dragging { opacity: .4; }

.gallery-preview__item.is-drag-over {
    outline: 2px dashed var(--brand, #4f46e5);
    outline-offset: 2px;
}

/* Media library path breadcrumb + up button (2026-11-21) */
.media-dirbar__up {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line, #e5e3dc);
    border-radius: 7px;
    background: transparent;
    color: inherit;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}

.media-dirbar__up:hover:not(:disabled) { background: var(--surface-2, #f6f5f1); }

.media-dirbar__up:disabled {
    opacity: .35;
    cursor: default;
}

.media-dirbar__path {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.media-dirbar__sep {
    color: var(--muted, #6b6f63);
    opacity: .6;
}

.media-dirbar__current {
    font-weight: 600;
    color: var(--text, #23241f);
}
