/*
 * CRM GROUP — default theme stylesheet / design system.
 *
 * Structure:
 *   1. Design tokens (the only place raw colors/sizes live)
 *   2. Base & typography
 *   3. Icons
 *   4. App shell: sidebar, topbar, content, guest/auth shell
 *   5. Components: cards, page headers, buttons, forms, tables, badges,
 *      alerts, tabs, dropdowns, tooltips, dialogs, pagination,
 *      breadcrumbs, empty/loading states, lists, kanban, dashboard
 *   6. Widgets: date picker, tag input, recipient picker
 *   7. Responsive & accessibility
 *
 * Direction: everything uses logical properties (inline/block, start/
 * end) so the same rules serve fa/ar (RTL) and en/tr (LTR). The only
 * physical left/right values are where a value is mirrored explicitly
 * under [dir="rtl"].
 *
 * Every class name used by templates before this redesign is still
 * defined here — templates were never required to change to benefit.
 */

/* Vazirmatn (SIL OFL 1.1, fonts/vazirmatn/OFL.txt), self-hosted: one
   variable file covers every weight 100–900. Used first for fa/ar
   (--font-rtl) and as a fallback in --font-sans. */
@font-face {
    font-family: "Vazirmatn";
    src: url("../fonts/vazirmatn/Vazirmatn-Variable.woff2") format("woff2");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

/* ===================================================================
   1. Design tokens
   =================================================================== */
:root {
    /* Brand */
    --brand-50: #eef3ff;
    --brand-100: #dce6fe;
    --brand-200: #bccffd;
    --brand-500: #4673ee;
    --brand-600: #2f5fd6;
    --brand-700: #2449b0;

    /* Neutrals (cool slate) */
    --gray-0: #ffffff;
    --gray-25: #fbfcfd;
    --gray-50: #f6f7f9;
    --gray-100: #eef0f4;
    --gray-200: #e3e6ec;
    --gray-300: #cdd3dc;
    --gray-400: #98a2b3;
    --gray-500: #667085;
    --gray-600: #475467;
    --gray-700: #344054;
    --gray-800: #1d2939;
    --gray-900: #101828;

    /* Semantic */
    --success-50: #ecfdf3; --success-200: #abefc6; --success-600: #067647; --success-700: #05603a;
    --warning-50: #fffaeb; --warning-200: #fedf89; --warning-600: #b54708; --warning-700: #93370d;
    --danger-50: #fef3f2;  --danger-200: #fecdca;  --danger-600: #d92d20;  --danger-700: #b42318;
    --info-50: #eff8ff;    --info-200: #b2ddff;    --info-600: #1570c7;    --info-700: #175cd3;

    /* Surfaces / roles */
    --color-bg: var(--gray-50);
    --color-surface: var(--gray-0);
    --color-surface-raised: var(--gray-0);
    --color-surface-sunken: var(--gray-50);
    --color-surface-hover: var(--gray-50);
    --color-text: var(--gray-900);
    --color-text-secondary: var(--gray-700);
    --color-muted: var(--gray-500);
    --color-text-muted: var(--gray-500);
    --color-border: var(--gray-200);
    --color-border-strong: var(--gray-300);
    --color-accent: var(--brand-600);
    --color-primary: var(--brand-600);
    --color-primary-light: var(--brand-50);
    --color-focus: rgba(47, 95, 214, 0.35);

    /* Typography */
    --font-sans: "Segoe UI", system-ui, -apple-system, "Vazirmatn", "Noto Sans", "Noto Sans Arabic", Tahoma, Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-rtl: "Vazirmatn", "Segoe UI", "Noto Sans Arabic", Tahoma, system-ui, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --text-xs: 0.75rem;    /* 12 */
    --text-sm: 0.8125rem;  /* 13 */
    --text-base: 0.875rem; /* 14 */
    --text-md: 0.9375rem;  /* 15 */
    --text-lg: 1.0625rem;  /* 17 */
    --text-xl: 1.25rem;    /* 20 */
    --text-2xl: 1.5rem;    /* 24 */
    --text-3xl: 1.875rem;  /* 30 */
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-bold: 700;
    --leading-tight: 1.3;
    --leading-normal: 1.6;

    /* Spacing (4px base) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Shape & depth */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 999px;
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 4px 8px -2px rgba(16, 24, 40, 0.08), 0 2px 4px -2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 12px 24px -4px rgba(16, 24, 40, 0.12), 0 4px 8px -4px rgba(16, 24, 40, 0.06);

    /* Controls */
    --control-h: 2.375rem;     /* 38px */
    --control-h-sm: 2rem;      /* 32px */
    --field-sm: 12rem;         /* codes, numbers, dates */
    --field-md: 26rem;         /* names, emails, phones, selects */
    --field-lg: 40rem;         /* addresses, titles, free text */

    /* Layout */
    --sidebar-w: 16.5rem;
    --sidebar-w-collapsed: 4.5rem;
    --topbar-h: 3.75rem;
    --content-max: 80rem;
    --z-sticky: 20;
    --z-dropdown: 40;
    --z-drawer: 60;
    --z-popover: 70;

    --transition: 150ms ease;

    font-family: var(--font-sans);
    color-scheme: light;
}

:root:lang(fa),
:root:lang(ar) {
    font-family: var(--font-rtl);
}

/* ===================================================================
   2. Base & typography
   =================================================================== */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.dir-rtl { direction: rtl; }
body.dir-ltr { direction: ltr; }

h1, h2, h3, h4 {
    color: var(--color-text);
    line-height: var(--leading-tight);
    font-weight: var(--weight-semibold);
    margin: 0 0 var(--space-3);
}
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
h4 { font-size: var(--text-base); }

p { margin: 0 0 var(--space-3); }
p:last-child { margin-bottom: 0; }

a {
    color: var(--brand-600);
    text-decoration: none;
    text-underline-offset: 2px;
}
a:hover { color: var(--brand-700); text-decoration: underline; }

ul, ol { padding-inline-start: var(--space-5); margin: 0 0 var(--space-3); }

hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-5) 0; }

code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--gray-100);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    direction: ltr;
    unicode-bidi: isolate;
}

img, svg { vertical-align: middle; }

.muted { color: var(--color-muted); }
.text-danger { color: var(--danger-700); }
.text-success { color: var(--success-700); }
.text-sm { font-size: var(--text-sm); }
.nowrap { white-space: nowrap; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.mono { font-family: var(--font-mono); font-size: var(--text-sm); direction: ltr; text-align: left; }

.visually-hidden {
    position: absolute !important; /* utility: must win over any component rule */
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

:focus { outline: none; }
:focus-visible {
    outline: 2px solid var(--brand-600);
    outline-offset: 2px;
    border-radius: 4px;
}

::selection { background: var(--brand-100); }

/* ===================================================================
   3. Icons
   =================================================================== */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
    width: 1.125rem;
    height: 1.125rem;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: -0.2em;
}
.icon--sm { width: 1rem; height: 1rem; }
.icon--lg { width: 1.5rem; height: 1.5rem; }
.icon--xl { width: 2rem; height: 2rem; stroke-width: 1.75; }

[dir="rtl"] .icon--dir { transform: scaleX(-1); }

/* ===================================================================
   4. App shell
   =================================================================== */
.skip-link {
    position: absolute;
    inset-inline-start: var(--space-4);
    top: -100px;
    z-index: 100;
    background: var(--gray-900);
    color: #fff;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
}
.skip-link:focus { top: var(--space-3); color: #fff; }

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
    transition: grid-template-columns var(--transition);
}
.sidebar-collapsed .app-shell { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

/* ---- Sidebar ---- */
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-inline-end: 1px solid var(--color-border);
    min-width: 0;
}

.sidebar__head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--topbar-h);
    padding-inline: var(--space-5) var(--space-3);
    border-bottom: 1px solid var(--color-border);
    flex: none;
}
.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
    color: var(--color-text);
    font-weight: var(--weight-bold);
    font-size: var(--text-md);
    white-space: nowrap;
    overflow: hidden;
    flex: none;
}
.sidebar__brand:hover { text-decoration: none; color: var(--color-text); }

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff;
    flex: none;
}
.brand-mark .icon { width: 1.125rem; height: 1.125rem; }

.btn.sidebar__close { display: none; margin-inline-start: auto; }

.sidebar__nav {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: var(--space-3) var(--space-3) var(--space-6);
    scrollbar-width: thin;
}

.nav-group + .nav-group { margin-top: var(--space-4); }

.nav-group__label {
    margin: 0 0 var(--space-1);
    padding-inline: var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--gray-400);
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 2.375rem;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--gray-600);
    font-weight: var(--weight-medium);
    font-size: var(--text-base);
    line-height: 1.3;
    transition: background var(--transition), color var(--transition);
}
.nav-item .icon { color: var(--gray-400); transition: color var(--transition); }
.nav-item:hover { background: var(--gray-50); color: var(--gray-900); text-decoration: none; }
.nav-item:hover .icon { color: var(--gray-600); }
.nav-item[aria-current="page"] {
    background: var(--brand-50);
    color: var(--brand-700);
}
.nav-item[aria-current="page"] .icon { color: var(--brand-600); }
.nav-item__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.sidebar__footer {
    flex: none;
    border-top: 1px solid var(--color-border);
    padding: var(--space-3);
}

/* Collapsed (desktop) — icons only; labels stay in the DOM for screen
   readers and appear as tooltips (title attribute) on hover. */
.sidebar-collapsed .app-shell .sidebar__head { padding-inline: 0; justify-content: center; }
.sidebar-collapsed .app-shell .sidebar__brand-name,
.sidebar-collapsed .app-shell .nav-item__label,
.sidebar-collapsed .app-shell .nav-group__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.sidebar-collapsed .app-shell .nav-item { justify-content: center; padding-inline: 0; }
.sidebar-collapsed .app-shell .nav-group + .nav-group {
    border-top: 1px solid var(--color-border);
    padding-top: var(--space-3);
    margin-top: var(--space-3);
}

/* ---- Main column & topbar ---- */
.app-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: var(--topbar-h);
    padding-inline: var(--space-6);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--color-border);
}

.btn.topbar__menu { display: none; }

.topbar__spacer { flex: 1; min-width: 0; }
.topbar__crumbs { flex: 0 1 auto; min-width: 0; }

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: var(--text-sm);
    color: var(--color-muted);
    white-space: nowrap;
}
.breadcrumb li { display: inline-flex; align-items: center; gap: var(--space-1); min-width: 0; }
.breadcrumb li + li::before {
    content: "";
    width: 0.875rem;
    height: 0.875rem;
    background: currentColor;
    opacity: 0.6;
    -webkit-mask: var(--mask-chevron) center / contain no-repeat;
    mask: var(--mask-chevron) center / contain no-repeat;
}
[dir="rtl"] .breadcrumb li + li::before { transform: scaleX(-1); }
.breadcrumb [aria-current="page"] {
    color: var(--color-text);
    font-weight: var(--weight-medium);
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-search {
    position: relative;
    flex: 0 1 20rem;
    min-width: 9rem;
}
.topbar-search .icon {
    position: absolute;
    inset-inline-start: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
}
.topbar-search input[type="search"] {
    width: 100%;
    max-width: none;
    height: var(--control-h-sm);
    padding-inline-start: 2.25rem;
    background: var(--gray-50);
}
.topbar-search input[type="search"]:focus { background: var(--color-surface); }

.lang-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin: 0;
}
.lang-switch .icon {
    position: absolute;
    inset-inline-start: var(--space-2);
    color: var(--gray-500);
    pointer-events: none;
}
.lang-switch select {
    height: var(--control-h-sm);
    min-width: 0;
    width: auto;
    max-width: none;
    padding-inline-start: 2rem;
    font-size: var(--text-sm);
}

.app-main {
    width: 100%;
    max-width: var(--content-max);
    margin: 0 auto;
    padding: var(--space-6);
    display: grid;
    gap: var(--space-5);
    align-content: start;
    flex: 1;
}
.app-main > * { min-width: 0; }

.app-footer {
    text-align: center;
    color: var(--color-muted);
    padding: var(--space-6) var(--space-4);
    font-size: var(--text-xs);
}

/* ---- Guest / auth shell ---- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(60rem 30rem at 50% -10%, var(--brand-50), transparent 70%),
        var(--color-bg);
}
.auth-shell__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-6);
}
.auth-shell__brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    font-weight: var(--weight-bold);
    color: var(--color-text);
}
.auth-shell__brand:hover { text-decoration: none; color: var(--color-text); }
.auth-shell__links { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.auth-shell .app-main {
    max-width: 30rem;
    flex: 1;
    align-content: center;
    padding-block: var(--space-8);
}
.auth-shell .card--form { max-width: none; padding: var(--space-8); box-shadow: var(--shadow-md); }
.auth-shell .card--form h1 { font-size: var(--text-2xl); }
.auth-shell .card--form form > .btn--primary { justify-self: stretch; }

/* ===================================================================
   5. Components
   =================================================================== */

/* ---- Cards ---- */
/* Form cards cap their own width so a form never stretches across a
   wide screen; auth pages override this in the guest shell. */
.card--form { width: 100%; max-width: 52rem; }

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-xs);
    min-width: 0;
}
.card > h1:first-child,
.card > h2:first-child { margin-top: 0; }
.card h2 + .muted,
.card h1 + .muted { margin-top: calc(-1 * var(--space-2)); }
.card > * + h2,
.card > * + h3 { margin-top: var(--space-6); }

.card--error {
    text-align: center;
    padding-block: var(--space-12);
}
.card--error h1 { font-size: var(--text-3xl); color: var(--gray-400); }

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}
.card__header h2 { margin: 0; display: inline-flex; align-items: center; gap: var(--space-2); }
.card__header h2 .icon { color: var(--gray-400); }
.card__footer {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
}

/* ---- Standalone error pages ---- */
.error-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--space-6);
}
.error-page .card { max-width: 30rem; width: 100%; }
.error-page .card--error h1 { font-size: var(--text-xl); color: var(--color-text); }
.error-page p:has(> .btn) { justify-content: center; margin-top: var(--space-5); }
.error-page p:empty { display: none; }
.error-page__code { display: block; font-size: 3.5rem; font-weight: var(--weight-bold); color: var(--brand-600); line-height: 1; margin-bottom: var(--space-3); }

/* User-entered text (names, titles, notes) may be in a different
   script than the UI; let each block pick its own base direction so
   punctuation lands on the correct side in fa/ar and en/tr alike. */
.kanban__card > a, .item-list__main a, .note-list p, .timeline-list > li, .tag-pill { unicode-bidi: plaintext; }

/* ---- Page header ---- */
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: var(--text-2xl); }
.page-head p { margin: var(--space-1) 0 0; color: var(--color-muted); }

/* Action rows: a paragraph or div that only holds buttons/links */
.actions,
p:has(> .btn):not(:has(> :not(.btn, form, br))) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--control-h);
    padding: 0 var(--space-4);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--gray-700);
    font: inherit;
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: var(--shadow-xs);
    transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition);
}
.btn:hover { background: var(--gray-50); color: var(--gray-900); text-decoration: none; }
.btn:active { background: var(--gray-100); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--color-focus); }
.btn .icon { width: 1.0625rem; height: 1.0625rem; }

.btn--primary {
    background: var(--brand-600);
    border-color: var(--brand-600);
    color: #fff;
}
.btn--primary:hover { background: var(--brand-700); border-color: var(--brand-700); color: #fff; opacity: 1; }
.btn--primary:active { background: var(--brand-700); }

.btn--danger {
    background: var(--color-surface);
    border-color: var(--danger-200);
    color: var(--danger-700);
}
.btn--danger:hover { background: var(--danger-50); color: var(--danger-700); }

.btn--danger-solid { background: var(--danger-600); border-color: var(--danger-600); color: #fff; }
.btn--danger-solid:hover { background: var(--danger-700); border-color: var(--danger-700); color: #fff; }

.btn--ghost {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    color: var(--gray-600);
}
.btn--ghost:hover { background: var(--gray-100); }

.btn--sm { min-height: var(--control-h-sm); padding-inline: var(--space-3); font-size: var(--text-sm); }

.btn--icon {
    width: var(--control-h);
    min-height: var(--control-h);
    padding: 0;
}
.btn--icon.btn--sm { width: var(--control-h-sm); min-height: var(--control-h-sm); }

.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; pointer-events: none; }

.link-button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    background: none;
    border: none;
    padding: 0;
    color: var(--brand-600);
    cursor: pointer;
    font: inherit;
    font-weight: var(--weight-medium);
    text-decoration: none;
}
.link-button:hover { color: var(--brand-700); text-decoration: underline; }
.link-button .icon { width: 1rem; height: 1rem; }
.link-button--danger { color: var(--danger-700); }
.link-button--danger:hover { color: var(--danger-700); }

.inline-form { display: inline; margin: 0; }

/* ---- Forms ---- */
:where(input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="file"], [type="submit"], [type="button"], [type="range"], [type="color"]), select, textarea) {
    display: block;
    width: 100%;
    min-height: var(--control-h);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    font-size: var(--text-base);
    line-height: 1.4;
    box-shadow: var(--shadow-xs);
    transition: border-color var(--transition), box-shadow var(--transition);
}
:where(textarea) { min-height: 6rem; resize: vertical; }
:where(select) {
    appearance: none;
    -webkit-appearance: none;
    padding-inline-end: 2.25rem;
    background-image: var(--mask-chevron-down-gray);
    background-repeat: no-repeat;
    background-size: 1rem;
    background-position: right 0.75rem center;
    cursor: pointer;
}
[dir="rtl"] :where(select) { background-position: left 0.75rem center; }
:where(select[multiple]) { background-image: none; padding-inline-end: var(--space-3); min-height: 6rem; }

:where(input, select, textarea)::placeholder { color: var(--gray-400); opacity: 1; }

:where(input, select, textarea):hover:not(:disabled) { border-color: var(--gray-400); }
:where(input, select, textarea):focus,
:where(input, select, textarea):focus-visible {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--color-focus);
}
:where(input, select, textarea):disabled,
:where(input, select, textarea)[readonly]:not(.crm-datepicker) {
    background: var(--gray-50);
    color: var(--gray-500);
    cursor: not-allowed;
}

/* Error state: any control directly followed by a .field-error */
:where(input, select, textarea):has(+ .field-error),
.is-invalid {
    border-color: var(--danger-600);
}
:where(input, select, textarea):has(+ .field-error):focus { box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.2); }

input[type="checkbox"], input[type="radio"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--brand-600);
    cursor: pointer;
    vertical-align: -0.15em;
}

input[type="file"] {
    font: inherit;
    font-size: var(--text-sm);
    color: var(--gray-600);
    max-width: 100%;
}
input[type="file"]::file-selector-button {
    font: inherit;
    font-weight: var(--weight-semibold);
    margin-inline-end: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--gray-700);
    cursor: pointer;
}

/* Number-ish fields read left-to-right even in RTL locales */
input[type="email"], input[type="url"], input[type="tel"], input[type="number"] { direction: ltr; }
[dir="rtl"] input[type="email"], [dir="rtl"] input[type="url"], [dir="rtl"] input[type="tel"], [dir="rtl"] input[type="number"] { text-align: right; }

/* Stacked forms: label above control. Applies to every form card plus
   bare forms placed directly inside a card. */
.card--form form,
form.card--form,
.card > form:not([class]),
.form-stack {
    display: grid;
    gap: var(--space-1);
    margin-top: var(--space-4);
    justify-items: start;
}
.card--form h1 + form, .card--form h2 + form { margin-top: var(--space-2); }
form.card--form { margin-top: var(--space-3); }

.card--form form > *, form.card--form > *, .card > form:not([class]) > *, .form-stack > * { max-width: 100%; }
.card--form form > :is(input, select, textarea, .tag-input-wrapper, .tab-panel, .table-responsive, div, table),
form.card--form > :is(input, select, textarea, div),
.card > form:not([class]) > :is(input, select, textarea, div),
.form-stack > :is(input, select, textarea, div) { width: 100%; }

.card--form label,
form.card--form label,
.card > form:not([class]) > label,
.form-stack > label,
.form-label {
    display: block;
    margin-top: var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--gray-700);
}
.card--form form > label:first-of-type,
.card--form form > input[type="hidden"] + label { margin-top: 0; }

/* Required marker, derived purely from the control's own `required` */
.card--form label:has(+ :is(input, select, textarea)[required])::after,
.card > form:not([class]) > label:has(+ :is(input, select, textarea)[required])::after {
    content: " *";
    color: var(--danger-600);
}

/* Inline (checkbox/radio) labels keep their own flow */
.card--form label:has(> input[type="checkbox"]),
.card--form label:has(> input[type="radio"]),
.card > form label:has(> input[type="checkbox"]),
.card > form label:has(> input[type="radio"]),
.check {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: var(--weight-regular);
    color: var(--color-text);
    font-size: var(--text-base);
    cursor: pointer;
}
.card--form label:has(> input[type="checkbox"])::after,
.card--form label:has(> input[type="radio"])::after { content: none; }

/* Field widths: sized to the data they hold, never "everything huge" */
.card--form form > :is(input, select),
form.card--form > :is(input, select),
.card > form:not([class]) > :is(input, select),
.tab-panel > :is(input, select),
.form-stack > :is(input, select) { max-width: var(--field-lg); }

.card--form :is(input[type="email"], input[type="tel"], input[type="password"], select),
.card > form:not([class]) :is(input[type="email"], input[type="tel"], input[type="password"], select) { max-width: var(--field-md); }

.card--form :is(input[type="number"], input.crm-datepicker, input[name$="code"], input[name$="_code]"], input[name*="extension"], input[name*="postal"], input[name$="percent"], input[name$="rate"]),
.card > form:not([class]) :is(input[type="number"], input.crm-datepicker) { max-width: var(--field-sm); }

.card--form textarea, form.card--form textarea, .card > form:not([class]) textarea { max-width: none; width: 100%; }

.field-sm { max-width: var(--field-sm) !important; } /* utility override */
.field-md { max-width: var(--field-md) !important; } /* utility override */
.field-lg { max-width: var(--field-lg) !important; } /* utility override */

.card--form form > .btn,
form.card--form > .btn,
.card > form:not([class]) > .btn { margin-top: var(--space-4); }

.btn--primary { margin-top: 0; }

.field-error {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--danger-700);
    font-size: var(--text-sm);
    margin-top: var(--space-1);
}
.field-error::before {
    content: "";
    flex: none;
    width: 0.875rem;
    height: 0.875rem;
    background: currentColor;
    -webkit-mask: var(--mask-alert-circle) center / contain no-repeat;
    mask: var(--mask-alert-circle) center / contain no-repeat;
}

.field-hint {
    color: var(--color-muted);
    font-size: var(--text-sm);
    margin-top: var(--space-1);
}

.form-section-title {
    margin: var(--space-6) 0 var(--space-2);
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
    font-size: var(--text-md);
}

.fieldset, fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin: var(--space-3) 0;
    min-width: 0;
}
legend { padding-inline: var(--space-2); font-weight: var(--weight-semibold); font-size: var(--text-sm); }
/* A fieldset used only to group/disable controls, with no visual box. */
.fieldset--plain { border: 0; padding: 0; margin: 0; min-width: 0; width: 100%; }
.fieldset--plain > * { max-width: 100%; }
.fieldset--plain > :is(input, select, textarea, div) { width: 100%; }

/* Organization logo preview (settings page). */
.logo-preview { display: flex; align-items: center; gap: var(--space-4); margin-block: var(--space-2); }
.logo-preview img { max-height: 4rem; max-width: 12rem; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-1); background: var(--color-surface); }

/* Toolbar / filter bar (existing .inline-form-row) */
.inline-form-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    margin-top: var(--space-4);
}
.inline-form-row:first-child { margin-top: 0; }
.inline-form-row > :is(input, select) { width: auto; flex: 0 1 14rem; min-width: 9rem; }
.inline-form-row > input[type="text"]:first-of-type,
.inline-form-row > input[type="search"]:first-of-type { flex: 1 1 16rem; max-width: 26rem; }
.inline-form-row > input[type="file"] { flex: 0 1 auto; min-width: 0; }
.inline-form-row > textarea { flex: 1 1 100%; }
.inline-form-row label { font-size: var(--text-sm); color: var(--gray-600); }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}
.toolbar__end { margin-inline-start: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ---- Tables ---- */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-block: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface);
}
.table-responsive > .table { margin: 0; }

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: var(--space-4) 0;
    font-size: var(--text-base);
}
.table th, .table td {
    text-align: start;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    vertical-align: middle;
}
/* List tables with row actions: a long unbreakable value (an email, a
   dotted username) wraps instead of widening the table and pushing the
   actions out of view; the min-width keeps short values (a phone number)
   on one line. */
.table:has(.actions-cell) td { overflow-wrap: anywhere; min-width: 7rem; }
.table thead th {
    position: sticky;
    top: 0;
    background: var(--gray-50);
    color: var(--gray-600);
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
    white-space: nowrap;
}
.table th { color: var(--gray-600); font-weight: var(--weight-semibold); font-size: var(--text-sm); }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--gray-25); }
.table tbody tr:last-child > * { border-bottom: 0; }
.table td > a:first-child { font-weight: var(--weight-medium); }
.table tbody td:first-child { min-width: 8rem; }
.table td :is(select, input:not([type="checkbox"], [type="radio"])) { min-height: var(--control-h-sm); padding-block: var(--space-1); font-size: var(--text-sm); width: auto; max-width: 16rem; }
.table td .inline-form + .inline-form,
.table td .link-button + .inline-form,
.table td a + .inline-form,
.table td .inline-form + a { margin-inline-start: var(--space-3); }
.table tfoot td, .table tfoot th { background: var(--gray-50); font-weight: var(--weight-semibold); }

.table .num, .table td.num, .table th.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions-cell { text-align: end; white-space: nowrap; width: 1%; }
.table:has(.actions-cell) td:is(.actions-cell, .cell-check) { overflow-wrap: normal; min-width: 0; }

.table--compact th, .table--compact td { padding: var(--space-2) var(--space-3); font-size: var(--text-sm); }

/* Empty-state row: the single full-width muted cell every list uses */
.table td[colspan].muted,
.table td.muted[colspan] {
    text-align: center;
    padding: var(--space-10) var(--space-4);
    color: var(--color-muted);
}
.table td[colspan].muted::before {
    content: "";
    display: block;
    width: 2.5rem;
    height: 2.5rem;
    margin: 0 auto var(--space-3);
    border-radius: var(--radius-full);
    background: var(--gray-100) var(--icon-inbox-gray) center / 1.25rem no-repeat;
}

/* ---- Small shared states ---- */
.stat-value { font-size: var(--text-3xl); font-weight: var(--weight-bold); line-height: 1.2; margin: var(--space-1) 0 var(--space-2); font-variant-numeric: tabular-nums; }
.check--spaced { margin-block-start: var(--space-2); margin-inline-end: var(--space-4); }
/* A radio/checkbox option with a longer explanation next to it. */
.card--form .check--block, .check--block { display: flex; align-items: flex-start; gap: var(--space-2); margin-block: var(--space-2); }
.check--block input { margin-block-start: 0.35em; flex: none; }
/* Proforma / invoice line items: product code · name · description, then amounts. */
.line-items { display: grid; gap: var(--space-3); width: 100%; margin-block: var(--space-4) var(--space-2); }
.line-items h3 { margin: 0; }
.line-items > .field-hint { margin: calc(-1 * var(--space-2)) 0 0; }
.line-items__rows { display: grid; gap: var(--space-3); }
.line-item {
    display: grid;
    gap: var(--space-3);
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--gray-50);
}
.line-item__main { display: grid; grid-template-columns: minmax(7rem, 1fr) minmax(10rem, 2fr) minmax(10rem, 2fr); gap: var(--space-3); }
.line-item__amounts { display: grid; grid-template-columns: repeat(4, minmax(6.5rem, 1fr)) auto; gap: var(--space-3); align-items: end; }
.line-item label.li-field { display: grid; gap: var(--space-1); min-width: 0; margin: 0; }
.li-field > span { font-size: var(--text-xs); color: var(--color-muted); font-weight: var(--weight-medium); }
.line-item .li-field > :is(input, select) { width: 100%; max-width: none; }
.line-item__remove { align-self: center; white-space: nowrap; }
@media (max-width: 720px) {
    .line-item__main { grid-template-columns: 1fr; }
    .line-item__amounts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .line-item__remove { grid-column: 1 / -1; justify-self: start; }
}

/* Search-as-you-type suggestions (product picker). Positioned by app.js. */
.lookup-list {
    position: absolute;
    z-index: 60;
    margin: 0;
    padding: var(--space-1) 0;
    list-style: none;
    max-height: 18rem;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}
.lookup-list[hidden] { display: none; }
.lookup-list__item { display: flex; gap: var(--space-3); padding: var(--space-2) var(--space-3); cursor: pointer; }
.lookup-list__item:hover, .lookup-list__item.is-active { background: var(--brand-50); }
.lookup-list__code { flex: none; min-width: 4.5rem; color: var(--color-muted); direction: ltr; font-variant-numeric: tabular-nums; }
.lookup-list__empty { padding: var(--space-2) var(--space-3); color: var(--color-muted); }

/* A group of fields inside a form that is shown/hidden as a whole. */
.field-group { display: grid; gap: var(--space-1); justify-items: start; width: 100%; margin: 0; padding: 0; border: 0; min-width: 0; }
.field-group[hidden] { display: none; }
.field-group > :is(input, select) { width: 100%; max-width: var(--field-lg); }
.table tr.row--danger > td { background: var(--danger-50); }
.table tr.is-unread > td { font-weight: var(--weight-semibold); }
.note--internal,
.note-list > li.note--internal { background: var(--warning-50); border: 1px solid var(--warning-200); border-radius: var(--radius-md); padding: var(--space-3); margin-block: var(--space-1); }

/* ---- Settings hub ---- */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
    gap: var(--space-4);
}
.settings-tile { padding: var(--space-5); }
.settings-tile h2 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
    font-size: var(--text-md);
}
.settings-tile__links { display: grid; gap: 2px; margin-inline: calc(-1 * var(--space-2)); }
.settings-tile__links a {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--gray-700);
    font-weight: var(--weight-medium);
}
.settings-tile__links a .icon { color: var(--gray-400); width: 1rem; height: 1rem; }
.settings-tile__links a::after {
    content: "";
    margin-inline-start: auto;
    width: 1rem;
    height: 1rem;
    background: var(--gray-300);
    -webkit-mask: var(--mask-chevron) center / contain no-repeat;
    mask: var(--mask-chevron) center / contain no-repeat;
}
[dir="rtl"] .settings-tile__links a::after { transform: scaleX(-1); }
.settings-tile__links a:hover { background: var(--gray-50); color: var(--brand-700); text-decoration: none; }
.settings-tile__links a:hover .icon { color: var(--brand-600); }

/* ---- Badges / status pills ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0.125rem var(--space-2);
    border-radius: var(--radius-full);
    border: 1px solid var(--gray-200);
    background: var(--gray-50);
    color: var(--gray-700);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1.5;
    white-space: nowrap;
}
.badge::before {
    content: "";
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.8;
}
.badge--plain::before { content: none; }
.badge--success { background: var(--success-50); border-color: var(--success-200); color: var(--success-700); }
.badge--warning { background: var(--warning-50); border-color: var(--warning-200); color: var(--warning-700); }
.badge--danger  { background: var(--danger-50);  border-color: var(--danger-200);  color: var(--danger-700); }
.badge--info    { background: var(--info-50);    border-color: var(--info-200);    color: var(--info-700); }
.badge--brand   { background: var(--brand-50);   border-color: var(--brand-200);   color: var(--brand-700); }

/* ---- Alerts ---- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    margin: 0 0 var(--space-4);
}
.app-main > .alert { margin: 0; }
.alert::before {
    content: "";
    flex: none;
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.125rem;
    background: currentColor;
    -webkit-mask: var(--mask-info) center / contain no-repeat;
    mask: var(--mask-info) center / contain no-repeat;
}
.alert__body { flex: 1; min-width: 0; }
.alert__close { margin-inline-start: auto; margin-block: -0.25rem; color: inherit; }
.alert--success { background: var(--success-50); border-color: var(--success-200); color: var(--success-700); }
.alert--success::before { -webkit-mask-image: var(--mask-check-circle); mask-image: var(--mask-check-circle); }
.alert--error { background: var(--danger-50); border-color: var(--danger-200); color: var(--danger-700); }
.alert--error::before { -webkit-mask-image: var(--mask-alert-circle); mask-image: var(--mask-alert-circle); }
.alert--warning { background: var(--warning-50); border-color: var(--warning-200); color: var(--warning-700); }
.alert--warning::before { -webkit-mask-image: var(--mask-alert-triangle); mask-image: var(--mask-alert-triangle); }
.alert--info { background: var(--info-50); border-color: var(--info-200); color: var(--info-700); }

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: var(--space-1);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-5);
    overflow-x: auto;
    scrollbar-width: none;
}
.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    color: var(--gray-500);
    font: inherit;
    font-weight: var(--weight-semibold);
    font-size: var(--text-base);
    white-space: nowrap;
    text-decoration: none;
}
.tab-btn:hover { color: var(--gray-800); text-decoration: none; }
.tab-btn.active, .tab-btn[aria-current="page"], .tab-btn[aria-selected="true"] { color: var(--brand-700); border-bottom-color: var(--brand-600); }

.tab-panel { display: grid; gap: var(--space-1); justify-items: start; }
/* `display: grid` above would otherwise override the hidden attribute. */
.tab-panel[hidden] { display: none; }
.tab-panel > h3 { margin: var(--space-5) 0 var(--space-1); font-size: var(--text-md); }
.tab-panel > p + h3, .tab-panel > h3:first-child { margin-top: var(--space-2); }
/* Page-level tabs: a tab bar card followed by panels of full-width cards.
   .page-stack: any wrapper (e.g. a form) around several page cards. */
.tab-group, .page-stack { display: grid; gap: var(--space-5); min-width: 0; }
.table--map select { width: 100%; min-width: 12rem; max-width: var(--field-md); }
.tab-panel--stack { justify-items: stretch; gap: var(--space-5); }
.tab-panel > * { max-width: 100%; }
.tab-panel > :is(input, select, textarea, div) { width: 100%; }

/* Segmented "pill" nav (e.g. mail folders, board/list switch) */
.segmented {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--gray-100);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}
.segmented .btn { box-shadow: none; border-color: transparent; background: transparent; min-height: var(--control-h-sm); }
.segmented .btn[aria-current="page"] { background: var(--color-surface); box-shadow: var(--shadow-sm); color: var(--gray-900); }

/* ---- Dropdown (details/summary based, works without JS) ---- */
.dropdown { position: relative; }
.dropdown > summary { list-style: none; cursor: pointer; }
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown__panel {
    position: absolute;
    inset-inline-end: 0;
    top: calc(100% + var(--space-2));
    z-index: var(--z-dropdown);
    min-width: 15rem;
    padding: var(--space-2);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.dropdown__header { padding: var(--space-2) var(--space-3) var(--space-3); border-bottom: 1px solid var(--color-border); margin-bottom: var(--space-2); }
.dropdown__header strong { display: block; color: var(--color-text); }
.dropdown__header span { display: block; font-size: var(--text-sm); color: var(--color-muted); overflow: hidden; text-overflow: ellipsis; }
.dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--gray-700);
    font: inherit;
    font-size: var(--text-base);
    text-align: start;
    cursor: pointer;
}
.dropdown__item .icon { color: var(--gray-500); }
.dropdown__item:hover { background: var(--gray-50); color: var(--gray-900); text-decoration: none; }
.dropdown__item--danger, .dropdown__item--danger .icon { color: var(--danger-700); }
.dropdown__item--danger:hover { background: var(--danger-50); color: var(--danger-700); }

.user-menu > summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1);
    padding-inline-end: var(--space-2);
    border-radius: var(--radius-full);
    color: var(--gray-700);
}
.user-menu > summary:hover { background: var(--gray-100); }
.user-menu__name { font-weight: var(--weight-medium); max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    flex: none;
    border-radius: 50%;
    background: var(--brand-100);
    color: var(--brand-700);
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
    text-transform: uppercase;
}

/* ---- Tooltip (CSS-only; also exposed via aria-label on the trigger) ---- */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-popover);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    background: var(--gray-900);
    color: #fff;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    width: max-content;
    max-width: min(18rem, 80vw);
    white-space: normal;
    pointer-events: none;
    /* display:none (not opacity:0) while hidden: an invisible absolute box
       still widens its scroll container — e.g. a horizontal scrollbar on
       lists with disabled row actions. */
    display: none;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after, [data-tooltip]:focus-within::after { display: block; }

/* ---- Dialog / modal (native <dialog>) ---- */
dialog.modal {
    width: min(32rem, calc(100vw - 2rem));
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    color: var(--color-text);
}
dialog.modal::backdrop { background: rgba(16, 24, 40, 0.45); }
.modal__body { padding: var(--space-6); display: flex; gap: var(--space-4); }
.modal__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--danger-50);
    color: var(--danger-600);
    box-shadow: 0 0 0 6px rgba(254, 243, 242, 0.6);
}
.modal__title { margin: 0 0 var(--space-1); font-size: var(--text-lg); }

/* Wide content dialog (e.g. a related-records list), header + scrolling body. */
dialog.modal--wide { width: min(56rem, calc(100vw - 2rem)); }
.modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
}
.modal__head .modal__title { margin: 0; }
.modal__content { padding: var(--space-4) var(--space-6) var(--space-6); max-height: min(70vh, 40rem); overflow-y: auto; }
.modal__content .table-responsive { margin: 0; }
.modal__content > .fact-row:first-child { margin: 0 0 var(--space-4); padding-top: 0; border-top: 0; }
.modal__text { margin: 0; color: var(--gray-600); }
.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-6);
    background: var(--gray-50);
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ---- Pagination ---- */
.pagination { display: flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; margin-top: var(--space-4); }
.pagination a, .pagination span {
    display: inline-grid;
    place-items: center;
    min-width: var(--control-h-sm);
    height: var(--control-h-sm);
    padding-inline: var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--gray-600);
    font-weight: var(--weight-medium);
}
.pagination a:hover { background: var(--gray-100); text-decoration: none; }
.pagination [aria-current="page"] { background: var(--brand-50); color: var(--brand-700); }

/* List toolbar under the filters: summary · rows per page · page links. */
.pagination-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    margin: var(--space-4) 0 var(--space-3);
}
.pagination-bar__summary { font-size: var(--text-sm); }
.pagination-bar__size { display: inline-flex; align-items: center; gap: var(--space-2); margin: 0; }
.pagination-bar__size label { font-size: var(--text-sm); color: var(--gray-600); white-space: nowrap; }
.pagination-bar__size select { width: auto; min-height: var(--control-h-sm); padding-block: 0; }
.pagination-bar .pagination { margin: 0; margin-inline-start: auto; }
.table-responsive + .pagination-bar { margin: var(--space-3) 0 0; }

/* ---- Empty / loading states ---- */
.empty-state {
    display: grid;
    justify-items: center;
    gap: var(--space-2);
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--color-muted);
}
.empty-state__icon {
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--gray-100);
    color: var(--gray-500);
}
.empty-state p { margin: 0; max-width: 32rem; }

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-inline-end-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.btn.is-loading { pointer-events: none; opacity: 0.8; }
.btn.is-loading .icon { display: none; }
.btn.is-loading::before {
    content: "";
    width: 1rem;
    height: 1rem;
    border: 2px solid currentColor;
    border-inline-end-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    display: block;
    height: 0.875rem;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--gray-100), var(--gray-50), var(--gray-100));
    background-size: 200% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Lists: notes, timeline, attachments ---- */
.note-list, .timeline-list, .attachment-list {
    list-style: none;
    padding: 0;
    margin: var(--space-4) 0 0;
    display: grid;
    gap: 0;
}
.note-list > li, .attachment-list > li {
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border);
}
.note-list > li:first-child, .attachment-list > li:first-child { padding-top: 0; }
.note-list > li:last-child, .attachment-list > li:last-child { border-bottom: 0; padding-bottom: 0; }
.note-list p { margin: 0 0 var(--space-1); }
.note-list .muted, .attachment-list .muted { font-size: var(--text-sm); }
.note-list .inline-form, .attachment-list .inline-form { margin-inline-start: var(--space-3); }
.attachment-list > li { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-1) var(--space-2); }
.attachment-list > li > a::before {
    content: "";
    display: inline-block;
    width: 1rem;
    height: 1rem;
    margin-inline-end: var(--space-2);
    vertical-align: -0.15em;
    background: currentColor;
    -webkit-mask: var(--mask-paperclip) center / contain no-repeat;
    mask: var(--mask-paperclip) center / contain no-repeat;
}

.timeline-list { position: relative; padding-inline-start: var(--space-5); }
.timeline-list::before {
    content: "";
    position: absolute;
    inset-block: var(--space-2);
    inset-inline-start: 0.3125rem;
    width: 2px;
    background: var(--gray-200);
    border-radius: 2px;
}
.timeline-list > li {
    position: relative;
    padding: var(--space-1) 0 var(--space-3);
    font-size: var(--text-base);
}
.timeline-list > li::before {
    content: "";
    position: absolute;
    inset-inline-start: calc(-1 * var(--space-5) + 1px);
    top: 0.6rem;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 50%;
    background: var(--color-surface);
    border: 2px solid var(--brand-500);
}
.timeline-list > li.muted::before { border-color: var(--gray-300); }
.timeline-list > li > .muted:first-child { display: block; font-size: var(--text-xs); }

/* Description list for record details */
.detail-list {
    display: grid;
    grid-template-columns: minmax(8rem, max-content) 1fr;
    gap: var(--space-2) var(--space-6);
    margin: 0;
}
.detail-list dt { color: var(--color-muted); font-size: var(--text-sm); }
.detail-list dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---- Tags ---- */
.tag-list { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-2); }

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    background: var(--brand-50);
    color: var(--brand-700);
    border: 1px solid var(--brand-100);
    border-radius: var(--radius-full);
    padding: 0.0625rem var(--space-3);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: 1.6;
}
.tag-pill__remove,
.tag-pill-remove {
    display: inline-grid;
    place-items: center;
    width: 1.125rem;
    height: 1.125rem;
    margin-inline-end: calc(-1 * var(--space-1));
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
}
.tag-pill__remove:hover, .tag-pill-remove:hover { opacity: 1; background: var(--brand-100); color: var(--danger-700); }

/* ---- Checkbox toggle (task done) ---- */
.checkbox-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    border: 1.5px solid var(--gray-300);
    border-radius: 5px;
    background: var(--color-surface);
    color: #fff;
    font-size: 0.75rem;
    line-height: 1;
    cursor: pointer;
    margin-inline-end: var(--space-2);
    vertical-align: middle;
    padding: 0;
}
.checkbox-toggle:hover { border-color: var(--brand-500); }
.checkbox-toggle.is-checked { background: var(--success-600); border-color: var(--success-600); }
.checkbox-toggle .icon { width: 0.75rem; height: 0.75rem; stroke-width: 3; }

/* Task rows: a finished task stays in the list, struck through. */
.task-list > li { flex-wrap: wrap; }
.task-list .checkbox-toggle { margin-inline-end: 0; }
.task-row__title { unicode-bidi: plaintext; }
.task-row--closed .task-row__title { color: var(--color-muted); }
.task-row--done .task-row__title { text-decoration: line-through; }

/* ---- Repeatable rows (multi-value fields, line items) ---- */
.repeat-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
    margin-bottom: var(--space-2);
    padding: var(--space-3);
    background: var(--gray-25);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    width: 100%;
}
.repeat-row > :is(input, select) { width: auto; flex: 1 1 8rem; min-width: 0; max-width: none; }
.repeat-row > select { flex: 0 1 11rem; }
.repeat-row > input[type="number"] { flex: 0 1 7rem; }
.repeat-row__primary {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-sm);
    font-weight: var(--weight-regular);
    color: var(--gray-600);
}

/* ---- Kanban ---- */
.kanban {
    display: flex;
    gap: var(--space-4);
    overflow-x: auto;
    padding-bottom: var(--space-4);
    align-items: flex-start;
    scroll-snap-type: x proximity;
}
.kanban__column {
    flex: 0 0 17.5rem;
    background: var(--gray-100);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    scroll-snap-align: start;
}
.kanban__column h3 {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    margin: var(--space-1) var(--space-1) var(--space-3);
    font-size: var(--text-base);
}
.kanban__column h3 .muted { font-size: var(--text-xs); font-weight: var(--weight-medium); }
.kanban__card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
    font-size: var(--text-base);
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition), border-color var(--transition);
}
.kanban__card:hover { box-shadow: var(--shadow-md); border-color: var(--gray-300); }
.kanban__card > a { font-weight: var(--weight-semibold); color: var(--color-text); }
.kanban__card > a:hover { color: var(--brand-700); }
.kanban__column > .muted { text-align: center; font-size: var(--text-sm); padding: var(--space-4) 0; margin: 0; }
.kanban__move { margin-top: var(--space-2); }
.kanban__move select { width: 100%; min-height: var(--control-h-sm); padding-block: 0; font-size: var(--text-sm); }

/* ---- Dashboard ---- */
.dashboard-grid,
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: var(--space-4);
}
.dashboard-tile h2 { font-size: var(--text-sm); color: var(--color-muted); margin: 0 0 var(--space-2); font-weight: var(--weight-medium); }
.dashboard-tile__number { font-size: var(--text-3xl); font-weight: var(--weight-bold); margin: 0 0 var(--space-2); line-height: 1.2; font-variant-numeric: tabular-nums; }
.dashboard-tile__unit { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--color-muted); }

.kpi {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-5);
    color: inherit;
    transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
}
a.kpi:hover { text-decoration: none; color: inherit; border-color: var(--brand-200); box-shadow: var(--shadow-md); }
/* A KPI tile that opens something (e.g. a related-records dialog). */
button.kpi { width: 100%; font: inherit; text-align: start; cursor: pointer; background: var(--color-surface); }
button.kpi:hover, button.kpi:focus-visible { border-color: var(--brand-200); box-shadow: var(--shadow-md); }
.kpi-grid--compact { grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); gap: var(--space-3); }
.kpi-grid--compact .kpi { padding: var(--space-4); }
.kpi-grid--compact .kpi__value { font-size: var(--text-2xl); }

/* Long single-line value in a dense table cell: clip with an ellipsis. */
.cell-note { min-width: 12rem; }
/* Freshly generated gift codes, one per line, easy to select and copy. */
.gift-codes { margin: var(--space-2) 0 0; padding: var(--space-3); background: var(--color-surface); border-radius: var(--radius-md); font-family: var(--font-mono); font-size: var(--text-base); white-space: pre; overflow-x: auto; user-select: all; }

/* Bulk selection: checkbox column + action bar above the table. */
.table .cell-check { width: 2.75rem; padding-inline-end: 0; }
.cell-check input { width: 1.05rem; height: 1.05rem; margin: 0; vertical-align: middle; cursor: pointer; }
.cell-check input:disabled { cursor: not-allowed; opacity: 0.4; }
.bulk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin: 0 0 var(--space-3); }
.bulk-bar__count { font-size: var(--text-sm); }
.cell-clip { display: inline-block; max-inline-size: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.kpi__top { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.kpi__label { font-size: var(--text-sm); color: var(--color-muted); font-weight: var(--weight-medium); }
.kpi__icon {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-md);
    background: var(--brand-50);
    color: var(--brand-600);
    flex: none;
}
.kpi__icon--success { background: var(--success-50); color: var(--success-600); }
.kpi__icon--warning { background: var(--warning-50); color: var(--warning-600); }
.kpi__icon--info { background: var(--info-50); color: var(--info-600); }
.kpi__icon--danger { background: var(--danger-50); color: var(--danger-600); }
.kpi__value {
    font-size: var(--text-3xl);
    font-weight: var(--weight-bold);
    line-height: 1.15;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    color: var(--color-text);
    overflow-wrap: anywhere;
}
.kpi__unit { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--color-muted); }
.kpi__link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--brand-600);
}

.dashboard-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
    gap: var(--space-5);
    align-items: start;
}

.quick-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.search-hero {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}
.search-hero__field { position: relative; flex: 1; }
.search-hero__field .icon {
    position: absolute;
    inset-inline-start: var(--space-3);
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    pointer-events: none;
}
.search-hero__field input { padding-inline-start: 2.5rem; max-width: none; }

.task-group + .task-group { margin-top: var(--space-5); }
.task-group__title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--gray-700);
}
.count {
    display: inline-grid;
    place-items: center;
    min-width: 1.375rem;
    height: 1.375rem;
    padding-inline: var(--space-1);
    border-radius: var(--radius-full);
    background: var(--gray-100);
    color: var(--gray-600);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
}
.count--danger { background: var(--danger-50); color: var(--danger-700); }
.count--warning { background: var(--warning-50); color: var(--warning-700); }

.item-list { list-style: none; margin: 0; padding: 0; }
.item-list > li {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
    min-width: 0;
}
.item-list > li:last-child { border-bottom: 0; }
.item-list__main { flex: 1; min-width: 0; }
.item-list__main a { font-weight: var(--weight-medium); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--color-text); }
.item-list__main a:hover { color: var(--brand-700); }
.item-list__meta { font-size: var(--text-sm); color: var(--color-muted); }
.item-list--empty { padding: var(--space-2) 0; color: var(--color-muted); font-size: var(--text-sm); }

/* Priority dot used in task/follow-up lists */
.dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--gray-300); flex: none; }
.dot--high, .dot--urgent { background: var(--danger-600); }
.dot--medium, .dot--normal { background: var(--warning-600); }
.dot--low { background: var(--success-600); }

/* ---- Record profile (client records) ---- */
/* Profile header: avatar, identity, quick facts, primary actions. */
.profile-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--space-4) var(--space-5);
    align-items: start;
}
.avatar--lg { width: 3.5rem; height: 3.5rem; font-size: var(--text-xl); }
.profile-head__title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0; font-size: var(--text-2xl); }
.profile-head__sub { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin: var(--space-1) 0 0; color: var(--color-muted); font-size: var(--text-sm); }
.profile-head__sub > span { display: inline-flex; align-items: center; gap: var(--space-1); }
.profile-head__sub .icon { width: 1rem; height: 1rem; }

.fact-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
    gap: var(--space-3);
    margin: var(--space-5) 0 0;
    padding-top: var(--space-4);
    border-top: 1px solid var(--color-border);
}
.fact { min-width: 0; }
.fact dt { display: flex; align-items: center; gap: var(--space-1); color: var(--color-muted); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.fact dt .icon { width: 0.875rem; height: 0.875rem; }
.fact dd { margin: var(--space-1) 0 0; font-weight: var(--weight-semibold); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* Main column + aside; stacks below tablet width. */
.record-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: var(--space-5);
    align-items: start;
}
.record-layout > div { display: grid; gap: var(--space-5); min-width: 0; }

.card--tabs { padding-block-end: 0; }
.card--tabs .tabs { margin-bottom: 0; border-bottom: 0; }

/* Icon + text event feed (unified timeline). */
.event-list { list-style: none; margin: 0; padding: 0; display: grid; }
.event-list > li { display: flex; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); min-width: 0; }
.event-list > li:last-child { border-bottom: 0; }
.event__icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--gray-100);
    color: var(--gray-600);
}
.event__icon .icon { width: 1rem; height: 1rem; }
.event__icon--brand { background: var(--brand-50); color: var(--brand-600); }
.event__icon--success { background: var(--success-50); color: var(--success-600); }
.event__icon--info { background: var(--info-50); color: var(--info-600); }
.event__icon--warning { background: var(--warning-50); color: var(--warning-600); }
.event__icon--danger { background: var(--danger-50); color: var(--danger-600); }
.event__body { flex: 1; min-width: 0; }
.event__title { display: block; font-weight: var(--weight-medium); unicode-bidi: plaintext; }
.event__meta { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); color: var(--color-muted); font-size: var(--text-sm); }

/* Service-course cards with a session progress bar. */
.course-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); gap: var(--space-4); }
.course { display: grid; gap: var(--space-2); align-content: start; }
.course__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-2); }
.course__title { margin: 0; font-size: var(--text-md); unicode-bidi: plaintext; }
/* Native <progress> so the value needs no inline style. */
progress.progress {
    display: block;
    width: 100%;
    height: 0.375rem;
    border: 0;
    border-radius: var(--radius-full);
    background: var(--gray-100);
    color: var(--brand-500);
    overflow: hidden;
    appearance: none;
    -webkit-appearance: none;
}
progress.progress::-webkit-progress-bar { background: var(--gray-100); border-radius: var(--radius-full); }
progress.progress::-webkit-progress-value { background: var(--brand-500); border-radius: var(--radius-full); }
progress.progress::-moz-progress-bar { background: var(--brand-500); border-radius: var(--radius-full); }
progress.progress--done { color: var(--success-600); }
progress.progress--done::-webkit-progress-value { background: var(--success-600); }
progress.progress--done::-moz-progress-bar { background: var(--success-600); }
.course .actions { margin-top: var(--space-2); }

/* Before/after media grid. */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 11rem), 1fr)); gap: var(--space-4); margin-top: var(--space-4); }
.media-card { display: grid; gap: var(--space-2); align-content: start; min-width: 0; }
.media-card__thumb {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--gray-50);
    color: var(--gray-400);
    overflow: hidden;
}
.media-card__thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-card__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); font-size: var(--text-sm); color: var(--color-muted); }
.media-card__notes { margin: 0; font-size: var(--text-sm); unicode-bidi: plaintext; overflow-wrap: anywhere; }

/* File library: folder path, thumbnails (list + grid), per-file menu.
   A thumbnail stacks the type icon under the <img>; if the image can't
   be made (404, empty alt) only the icon shows. */
.file-crumbs { margin-block: var(--space-4) var(--space-3); }
.file-crumbs .breadcrumb { white-space: normal; flex-wrap: wrap; }
.file-folder-tools { margin-bottom: var(--space-3); }
.file-thumb {
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
    color: var(--gray-400);
}
.file-thumb > * { grid-area: 1 / 1; }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-thumb--sm {
    width: 3rem;
    height: 3rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    background: var(--gray-50);
}
.file-thumb--folder { color: var(--brand-600); }
.file-table td:first-child { width: 3.5rem; }
.file-table td:nth-child(2) { min-width: 14rem; }
.file-name { font-weight: var(--weight-medium); unicode-bidi: plaintext; overflow-wrap: break-word; }
.file-sub { font-size: var(--text-sm); unicode-bidi: plaintext; overflow-wrap: break-word; display: flex; align-items: center; gap: var(--space-1); }
.file-card figcaption { display: grid; gap: var(--space-1); min-width: 0; }
.file-card__name {
    font-weight: var(--weight-medium);
    unicode-bidi: plaintext;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-actions { flex-wrap: nowrap; gap: var(--space-3); }
.file-menu { display: grid; gap: var(--space-3); min-width: 16rem; }
.file-menu__form { display: grid; gap: var(--space-2); justify-items: start; margin: 0; }
.file-menu__form select, .file-menu__form input[type="text"] { width: 100%; }
.file-menu .muted { margin: 0; font-size: var(--text-sm); }
.file-inbox .alert__body { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.file-inbox .alert__body > span { display: inline-flex; align-items: center; gap: var(--space-2); }
.file-inbox-hint { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); margin-top: var(--space-4); font-size: var(--text-sm); }
.file-inbox-hint code { overflow-wrap: anywhere; }

/* Locked / restricted content placeholder. */
.locked { display: flex; align-items: center; gap: var(--space-2); color: var(--color-muted); font-size: var(--text-sm); }
.locked .icon { width: 1rem; height: 1rem; }

/* Multi-column label/control groups inside a form card. */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 0 var(--space-5); width: 100%; }
.form-grid > div { min-width: 0; }
.form-grid > div > :is(input, select) { max-width: none; }
.card--form .form-grid label { margin-top: var(--space-3); }

/* User-entered multi-line text shown read-only. */
.prose-text { margin: 0; white-space: pre-line; unicode-bidi: plaintext; overflow-wrap: anywhere; }

/* ---- Appointments calendar ---- */
/* View switch + date navigation above the calendar. */
.appt-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
.appt-datenav { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.appt-datenav__label { margin-inline-start: var(--space-2); font-size: var(--text-md); }

/* Day grid: time rows × resource columns. */
.appt-grid th, .appt-grid td { vertical-align: top; }
.appt-grid thead th { white-space: nowrap; }
.appt-grid__time { width: 4.5rem; white-space: nowrap; color: var(--color-muted); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.appt-slot { min-width: 11rem; padding: var(--space-1) var(--space-2); }
.appt-slot--closed { background: var(--gray-100); }
.appt-slot--busy { background: var(--brand-50); }
.appt-slot__add {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--text-xs);
    color: var(--color-muted);
    text-decoration: none;
}
.appt-slot__add:hover, .appt-slot__add:focus-visible { color: var(--color-primary); }

/* One appointment, as a link card. Status shows in the start border. */
.appt-chip {
    display: grid;
    gap: 2px;
    margin-block: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--brand-100);
    border-inline-start: 3px solid var(--brand-500);
    border-radius: var(--radius-sm);
    background: var(--brand-50);
    color: var(--color-text);
    font-size: var(--text-sm);
    text-decoration: none;
    min-width: 0;
}
.appt-chip:hover, .appt-chip:focus-visible { border-color: var(--brand-200); border-inline-start-color: var(--brand-700); }
.appt-chip__time { color: var(--color-text-secondary); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.appt-chip__who { font-weight: var(--weight-medium); unicode-bidi: plaintext; overflow-wrap: anywhere; }
.appt-chip__what { color: var(--color-muted); font-size: var(--text-xs); unicode-bidi: plaintext; overflow-wrap: anywhere; }
.appt-chip--requested { background: var(--warning-50); border-color: var(--warning-200); border-inline-start-color: var(--warning-600); }
.appt-chip--confirmed, .appt-chip--in_progress { border-inline-start-color: var(--info-600); }
.appt-chip--completed { background: var(--success-50); border-color: var(--success-200); border-inline-start-color: var(--success-600); }
.appt-chip--cancelled, .appt-chip--no_show { background: var(--gray-50); border-color: var(--color-border); border-inline-start-color: var(--gray-400); color: var(--color-muted); }
.appt-chip--cancelled .appt-chip__who, .appt-chip--no_show .appt-chip__who { text-decoration: line-through; }

.appt-legend { display: flex; flex-wrap: wrap; gap: var(--space-4); margin: var(--space-3) 0 0; color: var(--color-muted); font-size: var(--text-xs); }
.appt-legend__item { display: inline-flex; align-items: center; gap: var(--space-1); }
.appt-legend__item::before { content: ""; width: 0.875rem; height: 0.875rem; border: 1px solid var(--color-border); border-radius: 3px; }
.appt-legend__item--busy::before { background: var(--brand-50); }
.appt-legend__item--closed::before { background: var(--gray-100); }

/* Week overview: seven day columns, wrapping on narrow screens. */
.appt-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2); margin-top: var(--space-4); }
.appt-day { display: grid; align-content: start; gap: var(--space-1); min-width: 0; padding: var(--space-2); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); }
.appt-day--today { border-color: var(--brand-500); box-shadow: inset 0 2px 0 var(--brand-500); }
.appt-day__head { margin: 0 0 var(--space-1); font-size: var(--text-sm); }
.appt-day__head a { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-1); color: inherit; text-decoration: none; }
.appt-day__head a:hover { color: var(--color-primary); }
@media (max-width: 1100px) {
    .appt-week { grid-template-columns: repeat(auto-fill, minmax(min(100%, 13rem), 1fr)); }
}

.appt-cancel { margin-top: var(--space-4); }

/* Weekly working-hours editor (resource form). */
.hours-table th[scope="row"] { white-space: nowrap; font-weight: var(--weight-medium); }
.hours-range { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.card--form .hours-range input[type="time"] { width: auto; min-width: 7rem; }

/* ===================================================================
   6. Widgets
   =================================================================== */

/* ---- Date picker (datepicker.js) ---- */
input.crm-datepicker { cursor: pointer; background-image: var(--icon-calendar-gray); background-repeat: no-repeat; background-size: 1rem; background-position: right 0.75rem center; padding-inline-end: 2.25rem; }
[dir="rtl"] input.crm-datepicker { background-position: left 0.75rem center; }

.crm-datepicker__popup {
    position: absolute;
    z-index: var(--z-popover);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-3);
    width: 260px;
}
.crm-datepicker__tabs {
    display: flex;
    gap: 2px;
    margin-bottom: var(--space-3);
    padding: 2px;
    background: var(--gray-100);
    border-radius: var(--radius-md);
}
.crm-datepicker__tab {
    flex: 1;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    padding: var(--space-1) var(--space-2);
    font: inherit;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    cursor: pointer;
    color: var(--gray-500);
}
.crm-datepicker__tab.active { color: var(--gray-900); background: var(--color-surface); box-shadow: var(--shadow-xs); }
.crm-datepicker__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
}
.crm-datepicker__header button {
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    color: var(--gray-700);
}
.crm-datepicker__header button:hover { background: var(--gray-100); }
/* prev/next are the first/last header buttons; mirror their arrows in RTL */
[dir="rtl"] .crm-datepicker__header > button:not(.crm-datepicker__label) { transform: scaleX(-1); }
.crm-datepicker__header .crm-datepicker__label { font-weight: var(--weight-semibold); font-size: var(--text-base); }
.crm-datepicker__labels { display: inline-flex; gap: var(--space-1); }
.crm-datepicker__header .crm-datepicker__label.is-open { background: var(--brand-50); color: var(--brand-700); }
.crm-datepicker__popup { box-sizing: border-box; max-width: calc(100vw - 16px); overflow-y: auto; }
input.crm-datepicker { cursor: text; }
.crm-datepicker__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}
.crm-datepicker__grid button {
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    padding: var(--space-1) 0;
    font: inherit;
    font-size: var(--text-sm);
    cursor: pointer;
    color: var(--gray-800);
    font-variant-numeric: tabular-nums;
}
.crm-datepicker__grid button:hover { background: var(--brand-50); color: var(--brand-700); }
.crm-datepicker__grid button.selected { background: var(--brand-600); color: #fff; }
.crm-datepicker__grid--months { grid-template-columns: repeat(3, 1fr); }
.crm-datepicker__grid--months button { padding: var(--space-3) 0; }
.crm-datepicker__today {
    display: block;
    width: 100%;
    margin-top: var(--space-2);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-1);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    cursor: pointer;
    color: var(--brand-600);
}
.crm-datepicker__today:hover { background: var(--brand-50); }

/* ---- Tag-pill input (tag-input.js) & recipient picker ---- */
.tag-input-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-1);
    min-height: var(--control-h);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    padding: var(--space-1) var(--space-2);
    background: var(--color-surface);
    box-shadow: var(--shadow-xs);
    max-width: var(--field-lg);
}
.tag-input-wrapper:focus-within { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--color-focus); }
.tag-input-pills { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.tag-input-text,
:where(.tag-input-wrapper) input.tag-input-text {
    border: none;
    outline: none;
    box-shadow: none;
    flex: 1;
    min-width: 7.5rem;
    min-height: 1.75rem;
    padding: 0 var(--space-1);
    background: transparent;
    width: auto;
}
.tag-input-text:focus { box-shadow: none; }

.recipient-picker-wrapper { max-width: 100%; }
.recipient-picker-suggestions {
    position: absolute;
    top: 100%;
    inset-inline: 0;
    z-index: var(--z-dropdown);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-top: var(--space-1);
    box-shadow: var(--shadow-lg);
    max-height: 220px;
    overflow-y: auto;
    padding: var(--space-1);
}
.recipient-picker-suggestion {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--text-base);
}
.recipient-picker-suggestion.is-active,
.recipient-picker-suggestion:hover { background: var(--brand-50); color: var(--brand-700); }

/* ===================================================================
   Icon masks (data URIs) for CSS-generated icons — same Lucide
   geometry as the sprite.
   =================================================================== */
:root {
    --mask-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
    --mask-chevron-down-gray: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    --mask-info: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E");
    --mask-check-circle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E");
    --mask-alert-circle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4'/%3E%3Cpath d='M12 16h.01'/%3E%3C/svg%3E");
    --mask-alert-triangle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E");
    --mask-paperclip: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48'/%3E%3C/svg%3E");
    --icon-inbox-gray: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-6l-2 3h-4l-2-3H2'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E");
    --icon-calendar-gray: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4'/%3E%3Cpath d='M8 2v4'/%3E%3Cpath d='M3 10h18'/%3E%3C/svg%3E");
}

/* ===================================================================
   7. Responsive & accessibility
   =================================================================== */

.btn.topbar__search-link { display: none; }

/* Drawer backdrop (tablet/mobile) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-drawer) - 1);
    background: rgba(16, 24, 40, 0.45);
}

/* Tablet & mobile: sidebar becomes an off-canvas drawer */
@media (max-width: 1023.98px) {
    .app-shell, .sidebar-collapsed .app-shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        z-index: var(--z-drawer);
        width: min(18rem, 86vw);
        height: 100%;
        transform: translateX(-100%);
        transition: transform 200ms ease, visibility 0s linear 200ms;
        visibility: hidden;
        box-shadow: var(--shadow-lg);
    }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .app-shell.nav-open .sidebar { transform: none; visibility: visible; transition: transform 200ms ease, visibility 0s; }
    .app-shell.nav-open .sidebar-backdrop { display: block; }
    .btn.sidebar__close { display: inline-flex; }
    .btn.topbar__menu { display: inline-flex; }
    .btn.topbar__collapse { display: none; }
    /* Collapsed mode is desktop-only; the drawer always shows labels */
    .sidebar-collapsed .app-shell .sidebar__head { padding-inline: var(--space-5) var(--space-3); justify-content: flex-start; }
    .sidebar-collapsed .app-shell .sidebar__brand-name,
    .sidebar-collapsed .app-shell .nav-item__label,
    .sidebar-collapsed .app-shell .nav-group__label { position: static; width: auto; height: auto; overflow: hidden; clip: auto; }
    .sidebar-collapsed .app-shell .nav-item { justify-content: flex-start; padding-inline: var(--space-3); }
    .topbar { padding-inline: var(--space-4); }
    .app-main { padding: var(--space-5) var(--space-4); }
    .record-layout { grid-template-columns: minmax(0, 1fr); }
}
body.nav-locked { overflow: hidden; }

@media (max-width: 767.98px) {
    .topbar-search { display: none; }
    .btn.topbar__search-link { display: inline-flex; }
    .user-menu__name, .user-menu > summary > .icon { display: none; }
    .user-menu > summary { padding-inline-end: var(--space-1); }
    .breadcrumb li:not(:last-child) { display: none; }
    .breadcrumb li + li::before { display: none; }

    .app-main { padding: var(--space-4) var(--space-3); gap: var(--space-4); }
    .card { padding: var(--space-4); border-radius: var(--radius-md); }
    .card--form { max-width: 100%; }
    .page-head h1 { font-size: var(--text-xl); }

    .inline-form-row { align-items: stretch; }
    .inline-form-row > :is(input, select, textarea, label, .tag-input-wrapper),
    .inline-form-row > input[type="text"]:first-of-type { width: 100%; max-width: none; flex: 1 1 100%; }
    .inline-form-row > .btn { flex: 1 1 auto; }

    .card--form form > :is(input, select),
    .card--form :is(input[type="email"], input[type="tel"], input[type="password"], select) { max-width: none; }

    .table th, .table td { padding: var(--space-2) var(--space-3); }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
    .kpi { padding: var(--space-4); }
    .kpi__icon { width: 2rem; height: 2rem; }
    .kpi__value { font-size: var(--text-xl); }
    .kpi__unit { display: block; font-size: var(--text-xs); }
    .page-head .quick-actions { width: 100%; }
    .kanban__column { flex-basis: 85vw; }
    .detail-list { grid-template-columns: 1fr; gap: 0; }
    .detail-list dd { margin-bottom: var(--space-3); }
    .search-hero { flex-direction: column; align-items: stretch; }
    .profile-head { grid-template-columns: auto minmax(0, 1fr); }
    .profile-head > .actions { grid-column: 1 / -1; }
    .profile-head__title { font-size: var(--text-xl); }
    .fact-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
    .auth-shell .card--form { padding: var(--space-6); }
    .auth-shell__top { padding: var(--space-3) var(--space-4); }
    .modal__body { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important; /* honor user OS setting */
        transition-duration: 0.01ms !important; /* honor user OS setting */
    }
}

@media (forced-colors: active) {
    .btn, .nav-item[aria-current="page"], .badge { border: 1px solid CanvasText; }
    .icon { stroke: CanvasText; }
}

@media print {
    .sidebar, .topbar, .app-footer, .sidebar-backdrop, .skip-link { display: none !important; } /* print only */
    .app-shell { display: block; }
    .app-main { max-width: none; padding: 0; }
    .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

/* Announcements: Super Admin → org admin bell (top bar) and message cards */
.announcement-bell > summary { position: relative; }
.announcement-bell--unread > summary,
.announcement-bell--unread > summary .icon { color: var(--danger-600); }
.announcement-bell__count {
    position: absolute;
    top: 0;
    inset-inline-end: 0;
    min-width: 1.1rem;
    padding: 0 var(--space-1);
    border-radius: var(--radius-full);
    background: var(--danger-600);
    color: var(--color-surface-raised);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1.1rem;
    text-align: center;
}
.announcement-bell__panel { width: min(24rem, calc(100vw - 2 * var(--space-4))); max-height: 70vh; overflow-y: auto; }
.announcement-bell__empty { padding: var(--space-2) var(--space-3); margin: 0; }
.announcement-list { display: grid; gap: var(--space-3); }
.announcement { padding: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-block-end: var(--space-2); }
.announcement--unread { border-color: var(--danger-200); background: var(--danger-50); }
.announcement__head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); margin-block-end: var(--space-1); }
.announcement-body { white-space: normal; overflow-wrap: anywhere; color: var(--color-text); }
.announcement__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-block-start: var(--space-2); }
.announcement-audience { border: 0; padding: 0; margin: 0 0 var(--space-2); }
@media (max-width: 640px) {
    .announcement-bell__panel { position: fixed; inset-inline: var(--space-4); top: 3.5rem; width: auto; }
}

/* Internal mail: original attachments to carry along when forwarding */
.forward-attachments { border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-2) var(--space-3); margin: var(--space-3) 0; }
.forward-attachments legend { padding-inline: var(--space-1); font-weight: var(--weight-medium); }

/* Shared form helpers: a row of submit buttons, a narrower form card, a spaced section heading */
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-3); }
.card--narrow { max-width: 40rem; }
.section-heading { margin-top: var(--space-6); }

/* ---- Help center ----
   .help-link: the "?" button help_link() prints next to a title/field.
   .help-content: Super-Admin-authored HTML (sanitized) — readable prose,
   tables, callouts (.help-callout, --tip / --warning) and an example
   block (.help-example). Logical properties only. */
.help-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    width: 1.75rem;
    height: 1.75rem;
    margin-inline-start: var(--space-1);
    border-radius: var(--radius-full);
    color: var(--color-muted);
    transition: color var(--transition), background var(--transition);
}
.help-link:hover, .help-link:focus-visible { color: var(--brand-600); background: var(--brand-50); }
.help-link .icon { width: 1.125rem; height: 1.125rem; }

.help-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: var(--space-4); }
.help-card { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; }
.help-card__title { margin: 0; font-size: var(--text-lg); }
.help-card__title a { display: inline-flex; align-items: flex-start; gap: var(--space-2); color: var(--color-text); text-decoration: none; }
.help-card__title a:hover { color: var(--brand-600); }
.help-card__title .icon { flex: none; margin-top: 0.15em; color: var(--brand-600); }
.help-card__summary { margin: 0; color: var(--color-muted); }
.help-card__admin { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
.help-card__spacer { flex: 1; }

.help-content { max-width: 52rem; line-height: 1.8; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.help-content > :first-child { margin-top: 0; }
.help-content h2 { font-size: var(--text-xl); margin: var(--space-8) 0 var(--space-3); padding-bottom: var(--space-2); border-bottom: 1px solid var(--color-border); }
.help-content h3 { font-size: var(--text-lg); margin: var(--space-6) 0 var(--space-2); }
.help-content h4 { margin: var(--space-4) 0 var(--space-2); }
.help-content p, .help-content ul, .help-content ol, .help-content dl { margin: 0 0 var(--space-3); }
.help-content ul, .help-content ol { padding-inline-start: var(--space-6); }
.help-content li { margin-bottom: var(--space-1); }
.help-content a { color: var(--brand-600); }
.help-content code, .help-content kbd { padding: 0 var(--space-1); border-radius: var(--radius-sm); background: var(--gray-100); font-size: 0.92em; }
.help-content pre { padding: var(--space-3); border-radius: var(--radius-md); background: var(--gray-100); overflow-x: auto; direction: ltr; text-align: start; }
.help-content img { max-width: 100%; height: auto; border-radius: var(--radius-md); }
.help-content hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-6) 0; }
.help-content blockquote { margin: 0 0 var(--space-3); padding: var(--space-2) var(--space-4); border-inline-start: 3px solid var(--brand-200); color: var(--color-text-secondary); }
.help-content table { width: 100%; border-collapse: collapse; margin: 0 0 var(--space-4); font-size: var(--text-base); }
.help-content th, .help-content td { padding: var(--space-2) var(--space-3); border: 1px solid var(--color-border); text-align: start; vertical-align: top; overflow-wrap: break-word; }
.help-content thead th { background: var(--gray-50); color: var(--gray-700); font-weight: var(--weight-semibold); }
.help-content .table-wrap { overflow-x: auto; margin: 0 0 var(--space-4); }
.help-content .table-wrap > table { margin: 0; min-width: 44rem; }
.help-content details { margin: 0 0 var(--space-3); padding: var(--space-2) var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.help-content summary { cursor: pointer; font-weight: var(--weight-semibold); }
.help-callout { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); border: 1px solid var(--info-200); background: var(--info-50); }
.help-callout--tip { border-color: var(--success-200); background: var(--success-50); }
.help-callout--warning { border-color: var(--warning-200); background: var(--warning-50); }
.help-callout > :last-child { margin-bottom: 0; }
.help-example { margin: 0 0 var(--space-4); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--gray-50); border: 1px dashed var(--color-border-strong); }
.help-example > :last-child { margin-bottom: 0; }
.help-flow { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-4); padding: 0; list-style: none; }
.help-content .help-flow { padding-inline-start: 0; }
.help-flow > li { display: inline-flex; align-items: center; gap: var(--space-2); margin: 0; padding: var(--space-1) var(--space-3); border-radius: var(--radius-full); background: var(--brand-50); color: var(--brand-700); font-weight: var(--weight-medium); }
.help-flow > li + li::before { content: "←"; color: var(--color-muted); }
[dir="ltr"] .help-flow > li + li::before { content: "→"; }
.help-fragment__title { margin: 0 0 var(--space-3); font-size: var(--text-lg); }
.help-fragment__more { margin: var(--space-4) 0 0; }
.help-source { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: var(--text-sm); }
.help-content:lang(fa) ol { list-style-type: persian; }
.help-content:lang(ar) ol { list-style-type: arabic-indic; }
