/* Daftarcha admin panel.
   1 Tokens  2 Base  3 App frame  4 Page parts  5 Buttons  6 Forms  7 Cards, lists, tables  8 Badges, alerts, dialogs
   9 Login  10 Pages  11 Small screens, print, less motion
   Colours, spaces and corners are used only as tokens. No inline styles: the panel must work with a strict Content-Security-Policy. */

/* ===== 1 Tokens: the only place for colours (same brand as the desktop app: Themes/Brand.xaml) ===== */
:root {
    color-scheme: light;

    /* Brand and states. "-text" = text on a card or on its "-soft" background (contrast at least 4.5 : 1). */
    --c-primary: #1F4E9D;
    --c-primary-hover: #163A75;
    --c-on-primary: #FFFFFF;
    --c-link: #1F4E9D;
    --c-primary-soft: #E6EDF9;
    --c-good: #1E8E5A;
    --c-good-text: #146A43;
    --c-good-soft: #E3F4EB;
    --c-bad: #B93434;
    --c-bad-hover: #962626;
    --c-bad-text: #A82C2C;
    --c-bad-soft: #FBE9E9;
    --c-warn: #D9822B;
    --c-warn-text: #8A4B08;
    --c-warn-soft: #FCF0E1;
    --c-neutral-text: #4A566B;
    --c-neutral-soft: #E9EDF4;

    /* Page */
    --c-bg: #F4F6FA;
    --c-surface: #FFFFFF;
    --c-surface-2: #F7F9FC;
    --c-border: #DDE3EC;
    --c-input-border: #7F8CA4;
    --c-text: #1B2333;
    --c-muted: #556278;
    --c-focus: #2E6FD8;
    --c-overlay: rgb(10 18 36 / .5);
    --c-skeleton: #E3E8F0;

    /* Sidebar (dark in both themes) */
    --c-sidebar: #10213F;
    --c-sidebar-text: #C9D5EA;
    --c-sidebar-muted: #8FA0C0;
    --c-sidebar-strong: #FFFFFF;
    --c-sidebar-hover: rgb(255 255 255 / .08);
    --c-sidebar-active: rgb(255 255 255 / .15);
    --c-sidebar-line: rgb(255 255 255 / .14);
    --c-band: #E08A2E; /* the orange band of the notebook icon: it marks the open page */
    --c-on-band: #10213F;

    /* Spaces, corners, shadows, sizes */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-pill: 999px;
    --shadow: 0 1px 2px rgb(16 33 63 / .05);
    --shadow-pop: 0 4px 12px rgb(16 33 63 / .1), 0 16px 40px rgb(16 33 63 / .14);
    --control: 38px;
    --sidebar-width: 244px;
    --rail-width: 64px;
    --topbar-height: 56px;

    /* Segoe UI has good Latin and Dari letters. The others are for computers without it. */
    --font: "Segoe UI", system-ui, -apple-system, "Noto Sans", "Noto Naskh Arabic", "Noto Sans Arabic", Tahoma, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --c-primary: #2E66C2;
        --c-primary-hover: #3570D0;
        --c-link: #A9C8FA;
        --c-primary-soft: #1D3257;
        --c-good: #3FB27F;
        --c-good-text: #7FD6AA;
        --c-good-soft: #15382A;
        --c-bad: #C23B3B;
        --c-bad-hover: #CC4646;
        --c-bad-text: #F5A3A3;
        --c-bad-soft: #432025;
        --c-warn: #E29A45;
        --c-warn-text: #F0BC7A;
        --c-warn-soft: #43301A;
        --c-neutral-text: #B7C2D6;
        --c-neutral-soft: #29354D;
        --c-bg: #0F1522;
        --c-surface: #182133;
        --c-surface-2: #1F2A40;
        --c-border: #2C3A55;
        --c-input-border: #6E7F9E;
        --c-text: #E6ECF5;
        --c-muted: #A5B1C6;
        --c-focus: #8AB4F8;
        --c-overlay: rgb(3 6 14 / .65);
        --c-skeleton: #26324A;
        --c-sidebar: #0A1020;
        --shadow: none;
        --shadow-pop: 0 4px 12px rgb(0 0 0 / .4), 0 16px 40px rgb(0 0 0 / .5);
    }
}

/* ===== 2 Base ===== */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; background: var(--c-bg); color: var(--c-text); -webkit-font-smoothing: antialiased; }

h1 { margin: 0; font-size: 22px; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; }
h2 { margin: 0 0 var(--sp-3); font-size: 15px; line-height: 1.4; font-weight: 600; display: flex; align-items: center; gap: var(--sp-2); }
h3 { margin: 0 0 var(--sp-2); font-size: 13px; line-height: 1.4; font-weight: 600; color: var(--c-muted); display: flex; align-items: center; gap: var(--sp-2); }
h2 > .icon, h3 > .icon { color: var(--c-muted); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--c-link); text-underline-offset: 2px; }
code { font-family: var(--font-mono); font-size: .95em; overflow-wrap: anywhere; }
hr { width: 100%; border: 0; border-top: 1px solid var(--c-border); margin: var(--sp-4) 0; }

:focus-visible { outline: 2px solid var(--c-focus); outline-offset: 2px; }
/* The title and the page get the focus after a page change (screen readers): no frame around them. */
h1:focus, main:focus { outline: none; }

.icon { flex: none; display: inline-block; vertical-align: -0.2em; }
.muted { color: var(--c-muted); margin: 0; }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.text-good { color: var(--c-good-text); }
.text-bad { color: var(--c-bad-text); }
.text-warn { color: var(--c-warn-text); }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ===== 3 App frame: sidebar, top bar, content ===== */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.shell-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: var(--sp-6) var(--sp-8) var(--sp-8); }

.skip-link { position: fixed; top: var(--sp-2); left: var(--sp-2); z-index: 60; transform: translateY(-200%); }
.skip-link:focus { transform: none; }

.sidebar { position: sticky; top: 0; z-index: 30; flex: none; width: var(--sidebar-width); height: 100vh; height: 100dvh; display: flex; flex-direction: column; background: var(--c-sidebar); color: var(--c-sidebar-text); container: sidebar / inline-size; }
.sidebar :focus-visible { outline-color: var(--c-sidebar-strong); outline-offset: -2px; }
.sidebar-head { flex: none; height: 64px; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: 0 var(--sp-3) 0 var(--sp-4); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: inherit; text-decoration: none; }
.brand-logo { flex: none; width: 32px; height: 32px; object-fit: contain; }
.brand-text { display: block; min-width: 0; }
.brand-name { display: block; color: var(--c-sidebar-strong); font-size: 15px; font-weight: 600; line-height: 1.25; }
.brand-sub { display: block; color: var(--c-sidebar-muted); font-size: 12px; line-height: 1.25; }

.nav { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--sp-3) var(--sp-4); scrollbar-width: thin; scrollbar-color: var(--c-sidebar-line) transparent; }
.nav-group { padding-top: var(--sp-3); }
.nav-title { display: block; margin: 0 0 var(--sp-1); padding: 0 10px; color: var(--c-sidebar-muted); font-size: 12px; font-weight: 600; line-height: 20px; white-space: nowrap; }
.nav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-item { position: relative; display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--c-sidebar-text); text-decoration: none; white-space: nowrap; }
.nav-item:hover { background: var(--c-sidebar-hover); color: var(--c-sidebar-strong); }
.nav-item.active { background: var(--c-sidebar-active); color: var(--c-sidebar-strong); font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 2px 2px 0; background: var(--c-band); }
.nav-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-badge { flex: none; min-width: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--c-band); color: var(--c-on-band); font-size: 12px; font-weight: 700; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.sidebar-foot { flex: none; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--c-sidebar-line); color: var(--c-sidebar-muted); font-size: 12px; }
.version { padding-left: 10px; }
.sidebar-btn { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: var(--radius-sm); background: none; color: var(--c-sidebar-text); cursor: pointer; }
.sidebar-btn:hover { background: var(--c-sidebar-hover); color: var(--c-sidebar-strong); }
.drawer-close { display: none; }
.drawer-backdrop { display: none; }

/* A narrow sidebar shows only the icons. The words stay for screen readers; the mouse shows them as a tooltip. */
@container sidebar (max-width: 100px) {
    .nav-text, .brand-text, .version { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .nav-title { height: 1px; margin: 0 6px var(--sp-3); padding: 0; overflow: hidden; background: var(--c-sidebar-line); color: transparent; }
    .nav-group:first-child .nav-title { margin-bottom: 0; background: none; }
    .nav-item { justify-content: center; padding: 0; }
    .nav-badge { position: absolute; top: 0; right: -4px; min-width: 18px; padding: 0 4px; font-size: 11px; line-height: 18px; }
    .sidebar-head, .sidebar-foot { justify-content: center; padding-inline: 0; }
}

.topbar { position: sticky; top: 0; z-index: 20; flex: none; height: var(--topbar-height); display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-8); background: var(--c-surface); border-bottom: 1px solid var(--c-border); }
.topbar .topbar-menu { display: none; }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; color: var(--c-muted); white-space: nowrap; }
.crumb-group { display: inline-flex; align-items: center; gap: 6px; }
.crumb-page { color: var(--c-text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }

.user-menu { position: relative; flex: none; }
.user-button { display: flex; align-items: center; gap: var(--sp-2); height: 44px; padding: 0 var(--sp-2); border: 0; border-radius: var(--radius-sm); background: none; color: var(--c-text); font: inherit; cursor: pointer; }
.user-button:hover, .user-button[aria-expanded="true"] { background: var(--c-surface-2); }
.user-button > .icon { color: var(--c-muted); }
.user-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.menu-backdrop { position: fixed; inset: 0; z-index: 1; }
.menu-pop { position: absolute; top: calc(100% + 6px); right: 0; z-index: 2; min-width: 220px; padding: 6px; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); box-shadow: var(--shadow-pop); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--c-text); font: inherit; text-align: start; text-decoration: none; cursor: pointer; }
.menu-note { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; padding: 6px 10px 10px; border-bottom: 1px solid var(--c-border); color: var(--c-muted); overflow-wrap: anywhere; }
.menu-item > .icon { color: var(--c-muted); }
.menu-item:hover { background: var(--c-surface-2); }

.avatar { flex: none; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--c-primary-soft); color: var(--c-link); font-size: 13px; font-weight: 600; line-height: 1; white-space: nowrap; user-select: none; }
.avatar-small { width: 28px; height: 28px; font-size: 11px; }
.avatar-large { width: 56px; height: 56px; font-size: 20px; }

.splash { min-height: 100vh; min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: var(--sp-4); color: var(--c-muted); }
.splash img { width: 56px; height: 56px; object-fit: contain; }
.splash { padding: var(--sp-4); }
.splash .alert { max-width: 480px; margin: 0; }
.splash p { display: flex; align-items: center; gap: var(--sp-2); margin: 0; }
.spinner { display: inline-block; width: 1.1em; height: 1.1em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 4 Page parts ===== */
.back { display: inline-flex; align-items: center; gap: 6px; min-height: 24px; margin-bottom: var(--sp-3); color: var(--c-link); text-decoration: none; }
.back:hover span { text-decoration: underline; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-5); }
.page-head-main { flex: 1 1 320px; min-width: 0; display: flex; gap: var(--sp-3); }
.page-head-text { min-width: 0; }
.page-icon { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: var(--radius); background: var(--c-primary-soft); color: var(--c-link); }
.page-sub { margin: 2px 0 0; max-width: 92ch; color: var(--c-muted); }
.page-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 6px; color: var(--c-muted); }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.section-title { margin: var(--sp-6) 0 var(--sp-3); font-size: 16px; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: var(--sp-4); }
.grid-wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); }
.grid-top { align-items: start; }

.tabs { display: flex; gap: var(--sp-1); margin-bottom: var(--sp-5); border-bottom: 1px solid var(--c-border); overflow-x: auto; scrollbar-width: none; }
.tab { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 42px; padding: 0 var(--sp-3); border: 0; border-bottom: 2px solid transparent; background: none; color: var(--c-muted); font: inherit; white-space: nowrap; text-decoration: none; cursor: pointer; }
.tab:hover { color: var(--c-text); }
.tab:focus-visible { outline-offset: -2px; }
.tab.active, .tab[aria-selected="true"], .tab[aria-current="page"] { border-bottom-color: var(--c-link); color: var(--c-link); font-weight: 600; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.toolbar:has(> .field) { align-items: flex-end; }
.toolbar > .field { margin: 0; }
.search-box { position: relative; display: block; flex: 1 1 260px; max-width: 420px; }
.search-box > .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--c-muted); pointer-events: none; }
.search-box > input { width: 100%; padding-left: 36px; }
.filter-note { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); color: var(--c-muted); }

.empty-state { display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); padding: var(--sp-8) var(--sp-4); text-align: center; }
.empty-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: var(--sp-2); border-radius: 50%; background: var(--c-neutral-soft); color: var(--c-neutral-text); }
.empty-title { margin: 0; font-weight: 600; }
.empty-text { margin: 0; max-width: 60ch; color: var(--c-muted); }
.empty-action { margin-top: var(--sp-3); }

.loading { display: flex; flex-direction: column; gap: 10px; padding: var(--sp-1) 0; }
.skeleton { display: block; height: 14px; border-radius: var(--radius-sm); background: var(--c-skeleton); animation: pulse 1.4s ease-in-out infinite; }
.skeleton:nth-child(odd) { width: 72%; }
@keyframes pulse { 50% { opacity: .5; } }
.load-error { display: flex; align-items: flex-start; gap: var(--sp-2); margin: 0; color: var(--c-bad-text); }
.load-error > .icon { margin-top: 3px; }
dl + .load-error, .load-error + .load-error { margin-top: var(--sp-3); }

/* ===== 5 Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: var(--control); padding: 6px 14px; border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--c-primary); color: var(--c-on-primary); font: inherit; font-weight: 600; line-height: 1.3; text-align: center; text-decoration: none; cursor: pointer; }
.btn:hover, .btn-primary:hover { background: var(--c-primary-hover); }
.btn-danger { background: var(--c-bad); }
.btn-danger:hover { background: var(--c-bad-hover); }
.btn-secondary, .btn-ghost { border-color: var(--c-input-border); background: var(--c-surface); color: var(--c-text); }
.btn-secondary:hover, .btn-ghost:hover { background: var(--c-surface-2); }
.btn-secondary > .icon, .btn-ghost > .icon { color: var(--c-muted); }
.btn-icon { width: var(--control); padding: 0; border-color: transparent; background: transparent; color: var(--c-muted); }
.btn-icon:hover { background: var(--c-neutral-soft); color: var(--c-text); }
.btn-icon.btn-danger { background: transparent; color: var(--c-bad-text); }
.btn-icon.btn-danger:hover { background: var(--c-bad-soft); color: var(--c-bad-text); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn-icon.btn-sm { width: 32px; padding: 0; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
/* Work runs: a turning ring takes the place of the icon. */
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"] > .icon { display: none; }
.btn[aria-busy="true"]::before { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
/* A button (or a download link) that looks like a link. */
.btn-link, .btn-link-dark { display: inline-flex; align-items: center; gap: 5px; min-height: 24px; padding: 0; border: 0; background: none; color: var(--c-link); font: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.btn-link:hover, .btn-link-dark:hover { background: none; color: var(--c-text); }

/* ===== 6 Forms ===== */
:where(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea, .input) { min-height: var(--control); max-width: 100%; padding: 6px 11px; border: 1px solid var(--c-input-border); border-radius: var(--radius-sm); background: var(--c-surface); color: var(--c-text); font: inherit; }
:where(select) { padding-right: 6px; cursor: pointer; }
:where(input:not([type="checkbox"], [type="radio"], [type="file"]), select, textarea):focus { outline: 2px solid var(--c-focus); outline-offset: -1px; border-color: var(--c-focus); }
:where(input, select, textarea):disabled { opacity: .6; cursor: not-allowed; }
:where(input, textarea)::placeholder { color: var(--c-muted); opacity: 1; }
:where(input:is([type="checkbox"], [type="radio"])) { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--c-primary); cursor: pointer; }
:where(input[type="file"]) { max-width: 100%; color: var(--c-muted); font: inherit; }
::file-selector-button { min-height: 34px; margin-inline-end: 10px; padding: 4px 12px; border: 1px solid var(--c-input-border); border-radius: var(--radius-sm); background: var(--c-surface); color: var(--c-text); font: inherit; font-weight: 600; cursor: pointer; }
textarea { width: 100%; min-height: 72px; resize: vertical; line-height: 1.5; }
.input-short { width: 88px; }

/* <label class="field"><span>Name</span><input /><small class="hint">...</small><small class="field-error">...</small></label> */
.field { display: flex; flex-direction: column; gap: 5px; margin: 0 0 var(--sp-4); }
.field > span:first-child, .field > label { color: var(--c-text); font-size: 13px; font-weight: 600; }
.field > input:not([type="checkbox"], [type="radio"], .input-short), .field > select { width: 100%; }
.field > input[aria-invalid="true"], .field > select[aria-invalid="true"], .field > textarea[aria-invalid="true"] { border-color: var(--c-bad-text); }
.hint { display: block; color: var(--c-muted); font-size: 12.5px; }
.field-error { display: flex; align-items: center; gap: 6px; color: var(--c-bad-text); font-size: 12.5px; }
.field-wide { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 0 var(--sp-4); align-items: start; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.muted + .form-actions, .muted + form { margin-top: var(--sp-3); }
.form-card { margin-bottom: var(--sp-5); }
.inline-field { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: var(--control); color: var(--c-muted); }
.field > .inline-field { display: flex; min-height: 0; }
.field > .inline-field > input:first-child { flex: 1; min-width: 0; }
.date-range { display: inline-flex; flex-wrap: wrap; gap: var(--sp-2); }
.check { display: flex; align-items: flex-start; gap: 10px; padding: 6px 0; cursor: pointer; }
.check > input { margin-top: 2px; }

/* ===== 7 Cards, lists, tables ===== */
.card { min-width: 0; padding: var(--sp-5); border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); box-shadow: var(--shadow); }
.card > :last-child { margin-bottom: 0; }
.card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-2) var(--sp-3); margin: 0 0 var(--sp-4); }
.card-header > h2 { margin: 0; }
.card-note { margin: 0 0 var(--sp-4); color: var(--c-muted); }
.card-good h2 > .icon { color: var(--c-good-text); }
.card-bad { border-color: var(--c-bad); }
.card-bad h2 > .icon { color: var(--c-bad-text); }

dl { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 7px var(--sp-5); margin: 0; }
dt { color: var(--c-muted); }
dd { margin: 0; min-width: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
dl + p, dl + .muted, dl + .alert, dl + .table-wrap { margin-top: var(--sp-4); }

/* Numbers as tiles: <dl class="stat-grid"><div class="stat"><dt>Name</dt><dd>12</dd></div></dl> */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 136px), 1fr)); gap: var(--sp-2); }
.stat { display: flex; flex-direction: column; justify-content: space-between; gap: var(--sp-1); min-width: 0; padding: 10px var(--sp-3); border-radius: var(--radius-sm); background: var(--c-surface-2); }
.stat > dt, .stat-label { color: var(--c-muted); font-size: 12.5px; line-height: 1.35; }
.stat > dd, .stat-value { color: var(--c-text); font-size: 20px; font-weight: 600; line-height: 1.25; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat > dd.stat-text { font-size: 14px; line-height: 1.5; }

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
.chip { padding: 2px 10px; border-radius: var(--radius-pill); background: var(--c-neutral-soft); color: var(--c-neutral-text); font-size: 13px; }

/* <section class="card table-card"><div class="table-wrap"><table class="table"> - only the table scrolls sideways. */
.table-card { padding: 0; overflow: hidden; }
.table-card > .card-header { margin: 0; padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--c-border); }
.table-card > .loading, .table-card > .load-error { margin: 0; padding: var(--sp-5); }
.table-wrap { position: relative; max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.card:not(.table-card) > .table-wrap { border: 1px solid var(--c-border); border-radius: var(--radius-sm); }
.table-wrap:focus-visible { outline-offset: -2px; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th { padding: 9px var(--sp-4); border-bottom: 1px solid var(--c-border); background: var(--c-surface-2); color: var(--c-muted); font-size: 12.5px; font-weight: 600; text-align: start; white-space: nowrap; }
.table td { padding: 10px var(--sp-4); border-bottom: 1px solid var(--c-border); font-variant-numeric: tabular-nums; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--c-surface-2); }
.table .num { text-align: right; }
.table a:not(.btn, .link-quiet) { font-weight: 600; text-decoration: none; }
.table a:not(.btn):hover { text-decoration: underline; }
.table .btn { white-space: nowrap; }
.cell-main { min-width: 170px; max-width: 420px; overflow-wrap: anywhere; }
.cell-text { min-width: 200px; max-width: 360px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user .badge { margin-inline-start: 6px; }
.cell-actions { display: flex; justify-content: flex-end; gap: var(--sp-1); }
.cell-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--sp-2); }
.row-unread td { font-weight: 600; }
.row-unread .muted { font-weight: 400; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2) var(--sp-3); margin-top: var(--sp-3); font-variant-numeric: tabular-nums; }
.pager > .muted { margin-right: auto; }
.table-card > .pager { margin: 0; padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--c-border); }
.with-icon { display: inline-flex; align-items: center; gap: var(--sp-2); }
/* 10.33: password requests: the steps before helping, and the buttons of a row (they wrap on a phone). */
.steps { margin: 0; padding-inline-start: 1.4em; display: grid; gap: var(--sp-1); }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot-good { background: var(--c-good); }
.dot-bad { background: var(--c-bad); }
.dot-new { background: var(--c-link); }

/* Long lists: the table head stays while the rows scroll (only when the window is big enough). */
@media (min-width: 768px) and (min-height: 700px) {
    .table-wrap-tall { max-height: calc(100vh - 200px); overflow-y: auto; }
    .table-wrap-tall th { position: sticky; top: 0; z-index: 1; }
}

/* ===== 8 Badges, alerts, dialogs ===== */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius-pill); background: var(--c-neutral-soft); color: var(--c-neutral-text); font-size: 12px; font-weight: 600; line-height: 18px; white-space: nowrap; }
.badge-neutral, .badge-plan-free, .badge-ticket-closed, .badge-key-expired { background: var(--c-neutral-soft); color: var(--c-neutral-text); }
.badge-info, .badge-plan-pro, .badge-ticket-answered, .badge-key-new { background: var(--c-primary-soft); color: var(--c-link); }
.badge-success, .badge-status-active, .badge-key-active { background: var(--c-good-soft); color: var(--c-good-text); }
.badge-warning, .badge-plan-trial, .badge-ticket-open { background: var(--c-warn-soft); color: var(--c-warn-text); }
.badge-danger, .badge-status-suspended, .badge-key-blocked { background: var(--c-bad-soft); color: var(--c-bad-text); }

.alert { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 var(--sp-4); padding: 10px var(--sp-3); border: 1px solid color-mix(in srgb, currentColor 30%, transparent); border-radius: var(--radius-sm); }
.alert > .icon { margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.alert-body > :last-child { margin-bottom: 0; }
.alert-info { background: var(--c-primary-soft); color: var(--c-link); }
.alert-success, .alert-good { background: var(--c-good-soft); color: var(--c-good-text); }
.alert-warning { background: var(--c-warn-soft); color: var(--c-warn-text); }
.alert-error, .alert-bad { background: var(--c-bad-soft); color: var(--c-bad-text); }

.dialog { position: fixed; inset: 0; z-index: 50; width: min(480px, calc(100vw - 32px)); height: fit-content; max-height: calc(100vh - 32px); margin: auto; padding: 0; overflow: auto; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); color: var(--c-text); box-shadow: var(--shadow-pop); }
.dialog::backdrop { background: var(--c-overlay); }
.dialog-form { display: flex; flex-direction: column; gap: var(--sp-4); margin: 0; padding: var(--sp-5); }
.dialog-form > .alert { margin: 0; }
.dialog-head { display: flex; gap: var(--sp-3); }
.dialog-icon { flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; background: var(--c-primary-soft); color: var(--c-link); }
.dialog-icon-danger { background: var(--c-bad-soft); color: var(--c-bad-text); }
.dialog-text { min-width: 0; }
.dialog-text h2 { display: block; margin: 0; font-size: 17px; overflow-wrap: anywhere; }
.dialog-text p { margin: var(--sp-1) 0 0; color: var(--c-muted); overflow-wrap: anywhere; }
.dialog-body > p,
.dialog-body > .check { margin: 0 0 var(--sp-4); }
.dialog-body > :last-child { margin-bottom: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); }

/* "Copied" (admin.js) */
.copy-status { position: fixed; left: 50%; bottom: var(--sp-6); z-index: 70; width: max-content; max-width: calc(100vw - 32px); padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm); background: var(--c-text); color: var(--c-bg); transform: translateX(-50%); opacity: 0; pointer-events: none; }
.copy-status.show { opacity: 1; }
.copy-status.failed { background: var(--c-bad); color: var(--c-on-primary); }

/* Shown by Blazor (display: block) when the page had an unexpected error. */
#blazor-error-ui { display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--c-warn); background: var(--c-warn-soft); color: var(--c-warn-text); }
.error-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
.error-bar a { color: inherit; font-weight: 600; }
.error-bar .dismiss { margin-left: auto; color: inherit; }

/* ===== 9 Login (also the error page) ===== */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: minmax(300px, 2fr) 3fr; }
.login-brand { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: var(--sp-2); padding: var(--sp-8); background: var(--c-sidebar); color: var(--c-sidebar-text); text-align: center; }
.login-brand img { width: 104px; height: 104px; margin-bottom: var(--sp-3); object-fit: contain; }
.login-brand .brand-name { font-size: 26px; }
.login-brand .brand-sub { font-size: 15px; }
.login-main { display: grid; place-items: center; min-width: 0; padding: var(--sp-6) var(--sp-4); }
.login-card { width: 100%; max-width: 420px; padding: var(--sp-8); }
.login-card .page-icon { margin-bottom: var(--sp-4); }
.login-text { margin: var(--sp-1) 0 var(--sp-5); color: var(--c-muted); }
.login-card h1 + form { margin-top: var(--sp-5); }
.login-card .alert { margin: var(--sp-3) 0 0; }
.login-card .btn-block { min-height: 42px; margin-top: var(--sp-4); }
.login-back { margin-top: var(--sp-3); }
.qr { display: block; width: 216px; height: 216px; max-width: 100%; margin: 0 auto var(--sp-4); padding: 8px; border: 1px solid var(--c-border); border-radius: var(--radius); background: #FFFFFF; } /* white in the dark theme too: phones must read it */
.secret { display: block; margin-top: var(--sp-1); padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm); background: var(--c-surface-2); color: var(--c-text); font-size: 14px; user-select: all; }
.codes { list-style: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); margin: 0; padding: 0; }
.codes li { padding: 7px var(--sp-2); border-radius: var(--radius-sm); background: var(--c-surface-2); font-size: 15px; text-align: center; }

/* ===== 10 Pages ===== */
/* Ticket */
.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--sp-4); align-items: start; }
.ticket-side { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.chat { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.bubble-row { display: flex; align-items: flex-start; gap: 10px; max-width: 88%; }
.bubble-row-admin { align-self: flex-end; flex-direction: row-reverse; }
.bubble { min-width: 0; padding: 10px 14px; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-surface); }
.bubble-user { border-top-left-radius: 2px; }
.bubble-admin { border-top-right-radius: 2px; border-color: transparent; background: var(--c-primary-soft); }
.bubble-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 var(--sp-4); margin-bottom: var(--sp-1); font-size: 13px; }
.bubble-text { white-space: pre-wrap; overflow-wrap: anywhere; text-align: start; }
.files { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: var(--sp-2) 0 0; padding: var(--sp-2) 0 0; border-top: 1px solid var(--c-border); font-size: 13px; }
.files li { display: flex; flex-wrap: wrap; align-items: center; gap: 2px var(--sp-2); overflow-wrap: anywhere; }
.preview { display: block; max-width: 100%; max-height: 320px; margin-top: 6px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); }
.answer-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); margin-top: var(--sp-3); }
.answer-foot > .btn { margin-left: auto; }

/* Profile, admin users and roles */
.profile-who { display: flex; align-items: center; gap: var(--sp-4); margin-bottom: var(--sp-5); overflow-wrap: anywhere; }
.profile-who > div { min-width: 0; }
.profile-who .badge { margin-top: var(--sp-1); }
.form-card form + h3 { margin-top: var(--sp-5); }
.permission-list { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: var(--sp-2) var(--sp-4); margin: 0; padding: 0; }
.permission-list li { display: flex; align-items: flex-start; gap: var(--sp-2); }
.permission-list .icon { margin-top: 3px; color: var(--c-good-text); }
.permission-group { min-width: 0; margin: 0 0 var(--sp-4); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--c-border); border-radius: var(--radius-sm); }
.permission-group > legend { padding: 0 6px; color: var(--c-muted); font-size: 13px; font-weight: 600; }
.role-card { display: flex; flex-direction: column; }
.role-card > .permission-list { margin-bottom: var(--sp-4); }
.role-card > .form-actions { margin-top: auto; padding-top: var(--sp-3); border-top: 1px solid var(--c-border); }
.secret-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); margin-bottom: var(--sp-2); padding: 8px var(--sp-3); border-radius: var(--radius-sm); background: var(--c-surface-2); }
.secret-row > .muted { flex: 0 0 84px; }
.secret-row > .btn { margin-left: auto; }

/* License keys */
.key-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin: var(--sp-4) 0; padding: 0; }
.key-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-1) var(--sp-3); padding: 6px 6px 6px var(--sp-3); border-radius: var(--radius-sm); background: var(--c-surface-2); }
.key-text { font-size: 15px; letter-spacing: .04em; user-select: all; }
.keys-made textarea { font-family: var(--font-mono); }
.license-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.license-head > dl { flex: 1 1 280px; }
.give-form { margin-bottom: var(--sp-4); padding: var(--sp-4); border-radius: var(--radius-sm); background: var(--c-surface-2); }
.license-history { margin-top: var(--sp-4); }
.license-history summary { min-height: 24px; color: var(--c-link); cursor: pointer; }
.license-history ul { margin: var(--sp-2) 0 0; padding-inline-start: var(--sp-5); }
.license-history li { margin-bottom: var(--sp-1); overflow-wrap: anywhere; }

/* ===== 11 Small screens, print, less motion ===== */

/* Wide windows start with the whole menu, medium windows with the icons. The button at the bottom of the menu changes it. */
@media (min-width: 1200px) {
    .menu-toggled .sidebar { width: var(--rail-width); }
}

@media (min-width: 768px) and (max-width: 1199.98px) {
    .shell:not(.menu-toggled) .sidebar { width: var(--rail-width); }
    .content { padding: var(--sp-5) var(--sp-6) var(--sp-8); }
    .topbar { padding: 0 var(--sp-6); }
}

@media (max-width: 1023.98px) {
    .ticket-layout { grid-template-columns: minmax(0, 1fr); }
    .login-page { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    .login-brand { flex-direction: row; justify-content: flex-start; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); text-align: start; }
    .login-brand img { width: 36px; height: 36px; margin: 0; }
    .login-brand .brand-name { font-size: 16px; }
    .login-brand .brand-sub { font-size: 13px; }
}

/* Phones: the menu is a drawer over the page. */
@media (max-width: 767.98px) {
    .content { padding: var(--sp-4) var(--sp-4) var(--sp-8); }
    .topbar { gap: var(--sp-1); padding: 0 var(--sp-2) 0 var(--sp-1); }
    .topbar .topbar-menu { display: inline-flex; width: 44px; min-height: 44px; }
    .crumb-group, .user-name, .user-button > .icon { display: none; }
    .user-button { width: 44px; justify-content: center; }
    .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 41; width: min(290px, 86vw); transform: translateX(-100%); visibility: hidden; transition: transform .18s ease-out, visibility 0s .18s; }
    .drawer-open .sidebar { transform: none; visibility: visible; transition: transform .18s ease-out, visibility 0s; }
    .drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: var(--c-overlay); }
    .drawer-close { display: inline-grid; }
    .sidebar-toggle { display: none; }
    .nav-item { min-height: 44px; }
    .card { padding: var(--sp-4); }
    .table-card { padding: 0; }
    .login-card { padding: var(--sp-5); }
    .page-head .page-icon { display: none; }
    .page-actions > .btn { flex: 1 1 auto; }
    .bubble-row { max-width: 100%; }
    .search-box { flex-basis: 100%; max-width: none; }
    /* Phones zoom in on a field with smaller letters. */
    :where(input, select, textarea, .input) { font-size: 16px; }
    .pager > .muted { flex-basis: 100%; }
}

/* Fingers need bigger buttons than a mouse. */
@media (pointer: coarse) {
    :root { --control: 44px; }
    .btn-sm { min-height: 40px; }
    .btn-icon.btn-sm { width: 40px; }
}

@media (forced-colors: active) {
    .nav-item.active, .tab.active, .tab[aria-current="page"], .tab[aria-selected="true"] { outline: 2px solid; outline-offset: -2px; }
    .btn, .badge, .stat { border: 1px solid; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0s !important; transition-delay: 0s !important; }
    .skeleton { animation: none; }
    /* A ring that stands still would look broken: it turns slowly instead. */
    .spinner, .btn[aria-busy="true"]::before { animation-duration: 4s; }
}

@media print {
    .sidebar, .topbar, .page-actions, .pager { display: none; }
    .card { box-shadow: none; break-inside: avoid; }
}

/* 10.34 partners */
.partner-money-title { margin: var(--sp-4) 0 var(--sp-2); font-weight: 600; }
.row-cancelled td { color: var(--c-muted); }
.report-totals td { font-weight: 600; border-top: 2px solid var(--c-border); }
.inline-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.stat > dd.text-bad { color: var(--c-bad-text); }
.stat > dd.text-good { color: var(--c-good-text); }
