/*
 * SEO Content Engine — admin UI
 *
 * A small hand-written design system rather than a vendored framework: it ships
 * as one file, needs no build step, and uses CSS logical properties throughout
 * so the entire interface mirrors correctly for RTL locales without a separate
 * stylesheet.
 */

/* ------------------------------------------------------------------ Tokens */

:root {
    color-scheme: light;

    /* Neutrals */
    --c-bg: #f7f8fa;
    --c-surface: #ffffff;
    --c-surface-2: #fbfcfd;
    --c-surface-3: #f2f4f7;
    --c-border: #e4e7ec;
    --c-border-strong: #d0d5dd;

    /* Text */
    --c-text: #101828;
    --c-text-2: #475467;
    --c-text-3: #98a2b3;
    --c-text-inverse: #ffffff;

    /* Brand */
    --c-primary: #4f46e5;
    --c-primary-hover: #4338ca;
    --c-primary-soft: #eef2ff;
    --c-primary-border: #c7d2fe;

    /* Semantic */
    --c-ok: #067647;
    --c-ok-soft: #ecfdf3;
    --c-ok-border: #abefc6;
    --c-warn: #b54708;
    --c-warn-soft: #fffaeb;
    --c-warn-border: #fedf89;
    --c-danger: #b42318;
    --c-danger-soft: #fef3f2;
    --c-danger-border: #fecdca;
    --c-info: #175cd3;
    --c-info-soft: #eff8ff;
    --c-info-border: #b2ddff;

    /* Charts */
    --c-chart-1: #4f46e5;
    --c-chart-2: #0891b2;
    --c-chart-3: #059669;
    --c-chart-4: #d97706;
    --c-chart-5: #db2777;

    /* Type */
    --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-fa: "Vazirmatn", "IRANSans", "Segoe UI", Tahoma, system-ui, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;

    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-base: 0.875rem;
    --fs-md: 0.9375rem;
    --fs-lg: 1.0625rem;
    --fs-xl: 1.25rem;
    --fs-2xl: 1.5rem;
    --fs-3xl: 1.875rem;

    /* Space */
    --sp-1: 0.25rem;
    --sp-2: 0.5rem;
    --sp-3: 0.75rem;
    --sp-4: 1rem;
    --sp-5: 1.25rem;
    --sp-6: 1.5rem;
    --sp-8: 2rem;
    --sp-10: 2.5rem;
    --sp-12: 3rem;

    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 999px;

    /* Deliberately restrained: the design relies on borders, not shadows. */
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow: 0 4px 8px -2px rgba(16, 24, 40, 0.06), 0 2px 4px -2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 12px 24px -6px rgba(16, 24, 40, 0.1), 0 4px 8px -4px rgba(16, 24, 40, 0.06);

    --sidebar-w: 248px;
    --sidebar-w-collapsed: 64px;
    --topbar-h: 60px;

    --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    color-scheme: dark;

    --c-bg: #0f1117;
    --c-surface: #171a21;
    --c-surface-2: #1c1f27;
    --c-surface-3: #22262f;
    --c-border: #2a2f39;
    --c-border-strong: #3a404c;

    --c-text: #e7eaf0;
    --c-text-2: #a3aab8;
    --c-text-3: #6c7484;

    --c-primary: #7c74f0;
    --c-primary-hover: #8f88f5;
    --c-primary-soft: #1e1c3a;
    --c-primary-border: #35306b;

    --c-ok-soft: #0d2419;
    --c-ok-border: #14532d;
    --c-ok: #4ade80;
    --c-warn-soft: #2a1c07;
    --c-warn-border: #4d3410;
    --c-warn: #fbbf24;
    --c-danger-soft: #2b1214;
    --c-danger-border: #4d1f22;
    --c-danger: #f87171;
    --c-info-soft: #0f2036;
    --c-info-border: #1b3a63;
    --c-info: #60a5fa;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 4px 8px -2px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 24px -6px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------------- Base */

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

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

html[lang="fa"] body,
html[dir="rtl"] body {
    font-family: var(--font-fa);
    line-height: 1.85;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0 0 var(--sp-3);
    font-weight: 600;
    line-height: 1.3;
    color: var(--c-text);
}

h1 { font-size: var(--fs-2xl); letter-spacing: -0.01em; }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }

/* Persian and Arabic scripts break badly with negative tracking. */
html[dir="rtl"] h1,
html[dir="rtl"] h2,
html[dir="rtl"] h3 {
    letter-spacing: normal;
}

p { margin: 0 0 var(--sp-3); }

a {
    color: var(--c-primary);
    text-decoration: none;
    transition: color var(--transition);
}

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

code, pre, kbd {
    font-family: var(--font-mono);
    font-size: 0.9em;
    direction: ltr;
    unicode-bidi: embed;
}

code {
    background: var(--c-surface-3);
    padding: 0.1em 0.35em;
    border-radius: var(--radius-sm);
}

pre {
    background: var(--c-surface-3);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: var(--sp-4);
    overflow-x: auto;
    margin: 0 0 var(--sp-4);
}

hr {
    border: 0;
    border-top: 1px solid var(--c-border);
    margin: var(--sp-6) 0;
}

img { max-width: 100%; height: auto; }

:focus-visible {
    outline: 2px solid var(--c-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    inset-block-start: -60px;
    inset-inline-start: var(--sp-4);
    z-index: 200;
    background: var(--c-primary);
    color: #fff;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius);
    transition: inset-block-start var(--transition);
}

.skip-link:focus { inset-block-start: var(--sp-3); }

/* ----------------------------------------------------------------- Layout */

.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--c-surface);
    border-inline-end: 1px solid var(--c-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width var(--transition), flex-basis var(--transition);
    z-index: 40;
}

.app.is-collapsed .sidebar {
    width: var(--sidebar-w-collapsed);
    flex-basis: var(--sidebar-w-collapsed);
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    height: var(--topbar-h);
    border-block-end: 1px solid var(--c-border);
    flex-shrink: 0;
}

.sidebar__logo {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--c-primary), #7c3aed);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: var(--fs-sm);
}

.sidebar__name {
    font-weight: 650;
    font-size: var(--fs-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--c-text);
}

.app.is-collapsed .sidebar__name,
.app.is-collapsed .sidebar__group-label,
.app.is-collapsed .nav-link span,
.app.is-collapsed .sidebar__footer-text {
    display: none;
}

.sidebar__nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-4) var(--sp-3);
    scrollbar-width: thin;
}

.sidebar__group + .sidebar__group { margin-block-start: var(--sp-5); }

.sidebar__group-label {
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--c-text-3);
    padding: 0 var(--sp-3) var(--sp-2);
}

html[dir="rtl"] .sidebar__group-label { letter-spacing: normal; }

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius);
    color: var(--c-text-2);
    font-weight: 500;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition);
}

.nav-link:hover {
    background: var(--c-surface-3);
    color: var(--c-text);
    text-decoration: none;
}

.nav-link.is-active {
    background: var(--c-primary-soft);
    color: var(--c-primary);
    font-weight: 600;
}

.nav-link svg { flex: 0 0 18px; width: 18px; height: 18px; }

.nav-link__badge {
    margin-inline-start: auto;
    background: var(--c-surface-3);
    color: var(--c-text-2);
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 0 var(--sp-2);
    border-radius: var(--radius-full);
    min-width: 20px;
    text-align: center;
}

.nav-link.is-active .nav-link__badge {
    background: var(--c-primary);
    color: #fff;
}

.sidebar__footer {
    border-block-start: 1px solid var(--c-border);
    padding: var(--sp-3);
    flex-shrink: 0;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-h);
    background: var(--c-surface);
    border-block-end: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 0 var(--sp-5);
    position: sticky;
    top: 0;
    z-index: 30;
}

.topbar__search {
    flex: 1;
    max-width: 460px;
    position: relative;
}

.topbar__search input {
    width: 100%;
    padding-inline-start: 2.25rem;
}

.topbar__search svg {
    position: absolute;
    inset-inline-start: var(--sp-3);
    inset-block-start: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--c-text-3);
    pointer-events: none;
}

.topbar__spacer { flex: 1; }

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}

.content {
    flex: 1;
    padding: var(--sp-6);
    max-width: 1500px;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-block-end: var(--sp-6);
}

.page-header__title { margin: 0 0 var(--sp-1); }

.page-header__subtitle {
    color: var(--c-text-2);
    margin: 0;
    font-size: var(--fs-md);
}

.page-header__actions {
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
}

.breadcrumbs {
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    font-size: var(--fs-sm);
    color: var(--c-text-3);
    margin-block-end: var(--sp-2);
    flex-wrap: wrap;
}

.breadcrumbs a { color: var(--c-text-2); }
.breadcrumbs span::after { content: "/"; margin-inline-start: var(--sp-2); color: var(--c-text-3); }
html[dir="rtl"] .breadcrumbs span::after { content: "\\"; }

/* ------------------------------------------------------------------ Cards */

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

.card + .card { margin-block-start: var(--sp-5); }

.card__header {
    padding: var(--sp-4) var(--sp-5);
    border-block-end: 1px solid var(--c-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.card__title {
    margin: 0;
    font-size: var(--fs-md);
    font-weight: 600;
}

.card__subtitle {
    margin: var(--sp-1) 0 0;
    font-size: var(--fs-sm);
    color: var(--c-text-2);
}

.card__body { padding: var(--sp-5); }
.card__body--flush { padding: 0; }

.card__footer {
    padding: var(--sp-4) var(--sp-5);
    border-block-start: 1px solid var(--c-border);
    background: var(--c-surface-2);
    border-end-start-radius: var(--radius-lg);
    border-end-end-radius: var(--radius-lg);
    display: flex;
    gap: var(--sp-2);
    align-items: center;
    flex-wrap: wrap;
}

/* ------------------------------------------------------------------- Grid */

.grid { display: grid; gap: var(--sp-5); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: var(--sp-5);
    align-items: start;
}

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

/* ------------------------------------------------------------------ Stats */

.stat {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    padding: var(--sp-4) var(--sp-5);
    box-shadow: var(--shadow-sm);
}

.stat__label {
    font-size: var(--fs-sm);
    color: var(--c-text-2);
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    margin-block-end: var(--sp-2);
}

.stat__value {
    font-size: var(--fs-2xl);
    font-weight: 650;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat__meta {
    font-size: var(--fs-xs);
    color: var(--c-text-3);
    margin-block-start: var(--sp-1);
}

/* --------------------------------------------------------------- Buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 0.5rem 0.875rem;
    border-radius: var(--radius);
    border: 1px solid var(--c-border-strong);
    background: var(--c-surface);
    color: var(--c-text);
    font: inherit;
    font-weight: 550;
    font-size: var(--fs-base);
    line-height: 1.4;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
    text-decoration: none;
}

.btn:hover { background: var(--c-surface-3); text-decoration: none; color: var(--c-text); }
.btn:active { transform: translateY(0.5px); }

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

.btn svg { width: 16px; height: 16px; flex: 0 0 16px; }

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

.btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); color: #fff; }

.btn--danger {
    background: var(--c-surface);
    border-color: var(--c-danger-border);
    color: var(--c-danger);
}

.btn--danger:hover { background: var(--c-danger-soft); }

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

.btn--sm { padding: 0.3125rem 0.625rem; font-size: var(--fs-sm); }
.btn--lg { padding: 0.625rem 1.125rem; font-size: var(--fs-md); }
.btn--block { width: 100%; }

.btn--icon {
    padding: 0.45rem;
    border-color: transparent;
    background: transparent;
    color: var(--c-text-2);
}

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

.btn-group { display: inline-flex; gap: var(--sp-2); flex-wrap: wrap; }

.btn.is-loading::after {
    content: "";
    width: 13px;
    height: 13px;
    border: 2px solid currentColor;
    border-block-start-color: transparent;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
}

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

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

/* ----------------------------------------------------------------- Forms */

.field { margin-block-end: var(--sp-4); }

.field--inline {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.label {
    display: block;
    font-weight: 550;
    font-size: var(--fs-sm);
    margin-block-end: var(--sp-2);
    color: var(--c-text);
}

.label__hint {
    font-weight: 400;
    color: var(--c-text-3);
    font-size: var(--fs-xs);
    margin-inline-start: var(--sp-2);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="tel"],
input[type="number"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
select,
textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    background: var(--c-surface);
    color: var(--c-text);
    font: inherit;
    font-size: var(--fs-base);
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px var(--c-primary-soft);
}

input::placeholder, textarea::placeholder { color: var(--c-text-3); }

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

textarea { min-height: 96px; resize: vertical; line-height: 1.6; }

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2398a2b3' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    padding-inline-end: 2rem;
}

html[dir="rtl"] select { background-position: left 0.65rem center; }

.field-error {
    color: var(--c-danger);
    font-size: var(--fs-xs);
    margin-block-start: var(--sp-1);
    display: block;
}

.field-help {
    color: var(--c-text-2);
    font-size: var(--fs-xs);
    margin-block-start: var(--sp-1);
    display: block;
}

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

.checkbox, .radio {
    display: flex;
    align-items: flex-start;
    gap: var(--sp-2);
    cursor: pointer;
    font-size: var(--fs-base);
}

.checkbox input, .radio input {
    width: 16px;
    height: 16px;
    margin: 0.2rem 0 0;
    accent-color: var(--c-primary);
    flex: 0 0 16px;
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    cursor: pointer;
}

.switch input {
    appearance: none;
    width: 38px;
    height: 21px;
    border-radius: var(--radius-full);
    background: var(--c-border-strong);
    position: relative;
    transition: background var(--transition);
    flex: 0 0 38px;
    margin: 0;
    cursor: pointer;
}

.switch input::after {
    content: "";
    position: absolute;
    inset-block-start: 2.5px;
    inset-inline-start: 2.5px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: inset-inline-start var(--transition);
    box-shadow: var(--shadow-sm);
}

.switch input:checked { background: var(--c-primary); }
.switch input:checked::after { inset-inline-start: 19.5px; }

fieldset {
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: var(--sp-4);
    margin: 0 0 var(--sp-5);
}

legend {
    font-weight: 600;
    font-size: var(--fs-sm);
    padding: 0 var(--sp-2);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
    gap: 0 var(--sp-5);
}

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

/* One heading of a proposed outline: the text, its level, and the buttons that
   move or remove it. Collapses to one column on a phone. */
.outline-row {
    display: grid;
    grid-template-columns: 1fr 9rem auto;
    gap: var(--sp-2);
    align-items: center;
    margin-block-end: var(--sp-2);
}

@media (max-width: 640px) {
    .outline-row { grid-template-columns: 1fr; }
}

/* ---------------------------------------------------------------- Tables */

.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-lg);
}

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--fs-base);
}

.table th {
    text-align: start;
    font-weight: 600;
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--c-text-2);
    padding: var(--sp-3) var(--sp-4);
    background: var(--c-surface-2);
    border-block-end: 1px solid var(--c-border);
    white-space: nowrap;
}

html[dir="rtl"] .table th { letter-spacing: normal; }

.table td {
    padding: var(--sp-3) var(--sp-4);
    border-block-end: 1px solid var(--c-border);
    vertical-align: middle;
}

.table tbody tr:last-child td { border-block-end: 0; }
.table tbody tr:hover { background: var(--c-surface-2); }

.table__actions {
    display: flex;
    gap: var(--sp-1);
    justify-content: flex-end;
}

.table__primary {
    font-weight: 550;
    color: var(--c-text);
    display: block;
}

.table__secondary {
    font-size: var(--fs-xs);
    color: var(--c-text-3);
}

.table--fixed { table-layout: fixed; }

.num { font-variant-numeric: tabular-nums; text-align: end; }

/* ---------------------------------------------------------------- Badges */

.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    font-weight: 550;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge--ok { background: var(--c-ok-soft); color: var(--c-ok); border-color: var(--c-ok-border); }
.badge--warn { background: var(--c-warn-soft); color: var(--c-warn); border-color: var(--c-warn-border); }
.badge--danger { background: var(--c-danger-soft); color: var(--c-danger); border-color: var(--c-danger-border); }
.badge--info { background: var(--c-info-soft); color: var(--c-info); border-color: var(--c-info-border); }
.badge--muted { background: var(--c-surface-3); color: var(--c-text-2); border-color: var(--c-border); }
.badge--primary { background: var(--c-primary-soft); color: var(--c-primary); border-color: var(--c-primary-border); }

.badge__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* --------------------------------------------------------------- Alerts */

.alert {
    display: flex;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    border: 1px solid;
    margin-block-end: var(--sp-4);
    font-size: var(--fs-base);
    align-items: flex-start;
}

.alert svg { flex: 0 0 18px; width: 18px; height: 18px; margin-block-start: 1px; }
.alert p:last-child { margin-block-end: 0; }

.alert--ok { background: var(--c-ok-soft); border-color: var(--c-ok-border); color: var(--c-ok); }
.alert--success { background: var(--c-ok-soft); border-color: var(--c-ok-border); color: var(--c-ok); }
.alert--warn { background: var(--c-warn-soft); border-color: var(--c-warn-border); color: var(--c-warn); }
.alert--warning { background: var(--c-warn-soft); border-color: var(--c-warn-border); color: var(--c-warn); }
.alert--danger { background: var(--c-danger-soft); border-color: var(--c-danger-border); color: var(--c-danger); }
.alert--error { background: var(--c-danger-soft); border-color: var(--c-danger-border); color: var(--c-danger); }
.alert--info { background: var(--c-info-soft); border-color: var(--c-info-border); color: var(--c-info); }

.alert__title { font-weight: 600; margin: 0 0 var(--sp-1); }
.alert__body { flex: 1; min-width: 0; }

/* The owner's announcement: its text takes the room, its button sits at the
   end of the line and keeps its label on one line. */
.portal-notice {
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

.portal-notice .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

/* ------------------------------------------------- Support sign-in band */

/* Deliberately loud, and above the content rather than inside it: a support
   session that looks like an ordinary one is how staff order articles on a
   customer's wallet by mistake. */
.impersonation-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    background: #92400e;
    color: #fff;
    font-size: var(--fs-sm);
}

.impersonation-bar .btn {
    flex: 0 0 auto;
    white-space: nowrap;
    background: #fff;
    color: #92400e;
    border-color: #fff;
}

/* --------------------------------------------------------------- Toasts */

.toasts {
    position: fixed;
    inset-block-end: var(--sp-5);
    inset-inline-end: var(--sp-5);
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    max-width: min(400px, calc(100vw - 2rem));
}

.toast {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-inline-start: 3px solid var(--c-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-3) var(--sp-4);
    display: flex;
    gap: var(--sp-3);
    align-items: flex-start;
    animation: toast-in 200ms ease-out;
}

.toast--success { border-inline-start-color: var(--c-ok); }
.toast--error { border-inline-start-color: var(--c-danger); }
.toast--warning { border-inline-start-color: var(--c-warn); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- Tabs */

.tabs {
    display: flex;
    gap: var(--sp-1);
    border-block-end: 1px solid var(--c-border);
    margin-block-end: var(--sp-5);
    overflow-x: auto;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

/* The one-time code field: large, centred, digits read left to right. No
   letter-spacing, which breaks joined scripts and misaligns the caret. */
.otp-input {
    text-align: center;
    font-family: var(--font-mono);
    font-size: 1.5rem;
    direction: ltr;
}

/* Printable invoice. The toolbar never prints; the page keeps to one A4. */
.print-page {
    background: var(--c-bg);
    padding: var(--sp-6) var(--sp-4);
}

.invoice-toolbar {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    max-width: 780px;
    margin: 0 auto var(--sp-4);
}

.invoice {
    max-width: 780px;
    margin: 0 auto;
    padding: var(--sp-8);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    background: var(--c-surface);
}

.invoice__head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--sp-6);
    padding-block-end: var(--sp-6);
    border-block-end: 1px solid var(--c-border);
}

.invoice__brand {
    display: flex;
    gap: var(--sp-3);
    align-items: flex-start;
}

.invoice__seller {
    margin: 0 0 var(--sp-1);
    font-weight: 700;
    font-size: var(--fs-lg);
}

.invoice__title {
    margin: 0 0 var(--sp-3);
    font-size: var(--fs-2xl);
}

.invoice__muted {
    margin: 0;
    color: var(--c-text-2);
    font-size: var(--fs-sm);
}

.invoice__party {
    padding-block: var(--sp-5);
}

.invoice__label {
    margin: 0 0 var(--sp-2);
    color: var(--c-text-3);
    font-size: var(--fs-xs);
    font-weight: 600;
}

.invoice__lines tfoot td {
    border-block-start: 1px solid var(--c-border);
}

.invoice__total td {
    font-size: var(--fs-lg);
    font-weight: 700;
}

.invoice__note {
    margin: var(--sp-6) 0 0;
    color: var(--c-text-3);
    font-size: var(--fs-xs);
}

@media print {
    .no-print {
        display: none !important;
    }

    .print-page {
        background: #fff;
        padding: 0;
    }

    .invoice {
        max-width: none;
        border: 0;
        padding: 0;
    }
}

/* Support ticket thread. Bodies are escaped plain text; pre-wrap keeps the
   customer's own line breaks without turning them into markup. */
.ticket-thread {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
}

.ticket-message {
    padding: var(--sp-4);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
}

.ticket-message--staff {
    border-color: var(--c-primary);
    background: var(--c-primary-soft);
}

.ticket-message__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-2);
    margin-block-end: var(--sp-2);
    font-size: var(--fs-sm);
}

.ticket-message__body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.8;
}

.faq-row {
    margin: 0 0 var(--sp-4);
    padding: var(--sp-4);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
}

.faq-row__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    margin-block-end: var(--sp-2);
}

.serp-preview {
    font-family: arial, sans-serif;
    overflow-wrap: anywhere;
}

.serp-preview__title { color: #1a0dab; font-size: 18px; line-height: 1.3; }
.serp-preview__url { color: #006621; font-size: 13px; }
.serp-preview__meta { color: #545454; font-size: 13px; line-height: 1.45; }

.schema-editor {
    min-height: 320px;
    font-family: var(--font-mono, ui-monospace, Consolas, monospace);
    font-size: var(--fs-sm, 13px);
    direction: ltr;
    text-align: left;
    white-space: pre;
    tab-size: 2;
}

.tab {
    padding: var(--sp-3) var(--sp-4);
    border: 0;
    background: transparent;
    color: var(--c-text-2);
    font: inherit;
    font-weight: 550;
    cursor: pointer;
    border-block-end: 2px solid transparent;
    margin-block-end: -1px;
    white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
}

.tab:hover { color: var(--c-text); text-decoration: none; }

.tab.is-active {
    color: var(--c-primary);
    border-block-end-color: var(--c-primary);
}

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

/* --------------------------------------------------------------- Progress */

.progress {
    height: 6px;
    background: var(--c-surface-3);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress__bar {
    /* The markup uses a <span>, and an inline box ignores width and height:
       without this the fill was invisible at every percentage. */
    display: block;
    height: 100%;
    background: var(--c-primary);
    border-radius: var(--radius-full);
    transition: width 400ms ease;
}

.progress__bar--ok { background: var(--c-ok); }
.progress__bar--warn { background: var(--c-warn); }
.progress__bar--danger { background: var(--c-danger); }

/* Score ring */
.score {
    --score: 0;
    --score-color: var(--c-primary);
    width: 68px;
    height: 68px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: conic-gradient(var(--score-color) calc(var(--score) * 1%), var(--c-surface-3) 0);
    position: relative;
    flex-shrink: 0;
}

.score::before {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    background: var(--c-surface);
}

.score__value {
    position: relative;
    font-weight: 700;
    font-size: var(--fs-lg);
    font-variant-numeric: tabular-nums;
    color: var(--score-color);
}

.score--sm { width: 44px; height: 44px; }
.score--sm::before { inset: 4px; }
.score--sm .score__value { font-size: var(--fs-sm); }

/* ----------------------------------------------------------------- Comments */

.comment {
    padding: var(--sp-4) var(--sp-5);
    border-block-end: 1px solid var(--c-border);
}

.comment:last-child { border-block-end: 0; }

/* Indented on the inline start, so the thread reads correctly in both
   directions rather than hanging off the wrong edge in Persian. */
.comment--reply {
    margin-inline-start: var(--sp-6);
    border-inline-start: 2px solid var(--c-border);
    background: var(--c-surface-2);
}

.comment__head {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
    margin-block-end: var(--sp-2);
}

.comment__author { font-weight: 600; }

.comment__body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: var(--c-text);
}

.comment__body[contenteditable="true"] {
    outline: 2px solid var(--c-primary);
    outline-offset: 3px;
    border-radius: var(--radius-sm);
}

.comment__actions {
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
    margin-block-start: var(--sp-3);
}

/* ----------------------------------------------------------- Customer panel */

.balance-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 0.3125rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--c-primary-border);
    background: var(--c-primary-soft);
    color: var(--c-primary);
    font-weight: 600;
    font-size: var(--fs-sm);
    white-space: nowrap;
}

.balance-chip:hover { text-decoration: none; filter: brightness(0.97); }
.balance-chip svg { width: 16px; height: 16px; }

.wallet-card {
    padding: var(--sp-4);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface-2);
}

/* Latin digits in fixed-width groups. word-spacing, not letter-spacing:
   letter-spacing on anything that might hold Persian breaks the joins. */
.card-number {
    font-family: var(--font-mono);
    direction: ltr;
    unicode-bidi: isolate;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* The destination card: four groups on one line whatever the column width,
   sized to the container rather than the screen, so the narrow side column
   of the wallet page no longer breaks it over two lines. */
.card-number--groups {
    display: flex;
    justify-content: space-between;
    gap: 0.5em;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--c-primary), var(--c-primary-hover));
    color: #fff;
    font-size: clamp(1rem, 5.5cqi, 1.5rem);
    box-shadow: 0 6px 16px rgb(79 70 229 / 0.25);
}

.wallet-card {
    container-type: inline-size;
}

.quick-amounts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
    margin-block-start: var(--sp-2);
}

.amount-in { color: var(--c-ok); }
.amount-out { color: var(--c-danger); }

.receipt-preview {
    display: block;
    max-width: 100%;
    max-height: 32rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
}

/* Off-screen rather than display:none: some bots skip hidden inputs. */
.honeypot {
    position: absolute;
    inset-inline-start: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* -------------------------------------------------------------- Empty state */

.empty {
    text-align: center;
    padding: var(--sp-12) var(--sp-5);
    color: var(--c-text-2);
}

.empty__icon {
    width: 44px;
    height: 44px;
    margin: 0 auto var(--sp-4);
    color: var(--c-text-3);
}

.empty__title {
    font-weight: 600;
    font-size: var(--fs-lg);
    color: var(--c-text);
    margin-block-end: var(--sp-2);
}

/* --------------------------------------------------------------- Dropdown */

.dropdown { position: relative; }

.dropdown__menu {
    position: absolute;
    inset-block-start: calc(100% + 6px);
    inset-inline-end: 0;
    min-width: 200px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-1);
    z-index: 60;
    display: none;
    max-height: 70vh;
    overflow-y: auto;
}

.dropdown.is-open .dropdown__menu { display: block; }

.dropdown__item {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    border: 0;
    background: transparent;
    color: var(--c-text);
    font: inherit;
    text-align: start;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.dropdown__item:hover { background: var(--c-surface-3); text-decoration: none; color: var(--c-text); }
.dropdown__item--danger { color: var(--c-danger); }

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

.dropdown__header {
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-transform: uppercase;
    color: var(--c-text-3);
}

/* ---------------------------------------------------------------- Avatar */

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 600;
    font-size: var(--fs-xs);
    flex-shrink: 0;
}

.avatar--sm { width: 24px; height: 24px; font-size: 10px; }
.avatar--lg { width: 44px; height: 44px; font-size: var(--fs-base); }

/* ---------------------------------------------------------------- Modal */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, 0.45);
    z-index: 200;
    display: grid;
    place-items: center;
    padding: var(--sp-5);
    animation: fade-in 150ms ease-out;
}

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

.modal {
    background: var(--c-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: min(560px, 100%);
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal--wide { width: min(900px, 100%); }

.modal__header {
    padding: var(--sp-5);
    border-block-end: 1px solid var(--c-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--sp-3);
}

.modal__body { padding: var(--sp-5); overflow-y: auto; flex: 1; }

.modal__footer {
    padding: var(--sp-4) var(--sp-5);
    border-block-start: 1px solid var(--c-border);
    display: flex;
    justify-content: flex-end;
    gap: var(--sp-2);
}

/* ------------------------------------------------------------ Pagination */

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-block-start: 1px solid var(--c-border);
    flex-wrap: wrap;
}

.pagination__info { font-size: var(--fs-sm); color: var(--c-text-2); }

.pagination__pages { display: flex; gap: var(--sp-1); }

.pagination__page {
    min-width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--c-border);
    background: var(--c-surface);
    color: var(--c-text-2);
    font-size: var(--fs-sm);
    padding: 0 var(--sp-2);
}

.pagination__page:hover { background: var(--c-surface-3); text-decoration: none; }

.pagination__page.is-active {
    background: var(--c-primary);
    border-color: var(--c-primary);
    color: #fff;
}

.pagination__page.is-gap { border: 0; background: transparent; pointer-events: none; }

/* -------------------------------------------------------------- Filters */

.filters {
    display: flex;
    gap: var(--sp-3);
    flex-wrap: wrap;
    align-items: flex-end;
    padding: var(--sp-4) var(--sp-5);
    border-block-end: 1px solid var(--c-border);
    background: var(--c-surface-2);
    border-start-start-radius: var(--radius-lg);
    border-start-end-radius: var(--radius-lg);
}

.filters .field { margin: 0; min-width: 150px; flex: 1 1 150px; }
.filters .field--wide { flex: 2 1 240px; }

/* --------------------------------------------------------------- Charts */

.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart__grid line { stroke: var(--c-border); stroke-width: 1; }
.chart__axis { fill: var(--c-text-3); font-size: 10px; }
.chart__line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart__area { opacity: 0.1; }
.chart__bar { transition: opacity var(--transition); }
.chart__bar:hover { opacity: 0.8; }
.chart__point { stroke: var(--c-surface); stroke-width: 2; }

.chart-legend {
    display: flex;
    gap: var(--sp-4);
    flex-wrap: wrap;
    font-size: var(--fs-xs);
    color: var(--c-text-2);
    margin-block-start: var(--sp-3);
}

.chart-legend__item { display: flex; align-items: center; gap: var(--sp-2); }
.chart-legend__swatch { width: 10px; height: 10px; border-radius: 3px; }

/* -------------------------------------------------------------- Editor */

.editor {
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--c-surface);
}

.editor__toolbar {
    display: flex;
    gap: var(--sp-1);
    padding: var(--sp-2);
    border-block-end: 1px solid var(--c-border);
    background: var(--c-surface-2);
    flex-wrap: wrap;
    align-items: center;
}

.editor__tool {
    min-width: 30px;
    height: 30px;
    border: 1px solid transparent;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--c-text-2);
    cursor: pointer;
    display: grid;
    place-items: center;
    font: inherit;
    font-size: var(--fs-sm);
    padding: 0 var(--sp-2);
}

.editor__tool:hover { background: var(--c-surface-3); color: var(--c-text); }
.editor__tool.is-active { background: var(--c-primary-soft); color: var(--c-primary); }

.editor__divider { width: 1px; height: 20px; background: var(--c-border); margin: 0 var(--sp-1); }

.editor__surface {
    min-height: 520px;
    max-height: 75vh;
    overflow-y: auto;
    padding: var(--sp-6);
    outline: none;
    line-height: 1.75;
}

.editor__surface:focus { outline: none; }

.editor__source {
    min-height: 520px;
    max-height: 75vh;
    border: 0;
    border-radius: 0;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: 1.6;
    resize: none;
    display: none;
}

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

.editor.is-source .editor__surface { display: none; }
.editor.is-source .editor__source { display: block; }

.editor__status {
    padding: var(--sp-2) var(--sp-4);
    border-block-start: 1px solid var(--c-border);
    background: var(--c-surface-2);
    font-size: var(--fs-xs);
    color: var(--c-text-2);
    display: flex;
    gap: var(--sp-4);
    flex-wrap: wrap;
}

/* Rendered article typography, shared by editor and preview. */
.prose { line-height: 1.75; color: var(--c-text); }
.prose h2 { font-size: var(--fs-xl); margin: var(--sp-8) 0 var(--sp-3); }
.prose h3 { font-size: var(--fs-lg); margin: var(--sp-6) 0 var(--sp-2); }
.prose h4 { font-size: var(--fs-md); margin: var(--sp-5) 0 var(--sp-2); }
.prose > *:first-child { margin-block-start: 0; }
.prose p { margin: 0 0 var(--sp-4); }
.prose ul, .prose ol { margin: 0 0 var(--sp-4); padding-inline-start: var(--sp-6); }
.prose li { margin-block-end: var(--sp-2); }

.prose table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 var(--sp-5);
    font-size: var(--fs-base);
}

.prose th, .prose td {
    border: 1px solid var(--c-border);
    padding: var(--sp-2) var(--sp-3);
    text-align: start;
}

.prose th { background: var(--c-surface-3); font-weight: 600; }

.prose blockquote {
    margin: 0 0 var(--sp-4);
    padding-inline-start: var(--sp-4);
    border-inline-start: 3px solid var(--c-primary-border);
    color: var(--c-text-2);
}

.prose a { text-decoration: underline; }
.prose img { border-radius: var(--radius); margin: var(--sp-4) 0; }

.prose mark.sce-link-target {
    background: var(--c-warn-soft);
    outline: 1px dashed var(--c-warn-border);
}

/* ------------------------------------------------------------ Outline UI */

.outline-list { list-style: none; margin: 0; padding: 0; }

.outline-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: var(--c-surface);
    margin-block-end: var(--sp-2);
    cursor: grab;
}

.outline-item.is-dragging { opacity: 0.4; }
.outline-item.is-over { border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-soft); }
.outline-item--h3 { margin-inline-start: var(--sp-6); background: var(--c-surface-2); }

.outline-item__handle { color: var(--c-text-3); cursor: grab; flex-shrink: 0; }
.outline-item__input { border: 0; padding: 0; background: transparent; font-weight: 550; flex: 1; }
.outline-item__input:focus { box-shadow: none; }
.outline-item__words { width: 80px; flex-shrink: 0; }

/* ------------------------------------------------------------- Checklist */

.checklist { list-style: none; margin: 0; padding: 0; }

.checklist li {
    display: flex;
    gap: var(--sp-3);
    align-items: flex-start;
    padding: var(--sp-2) 0;
    border-block-end: 1px solid var(--c-border);
    font-size: var(--fs-base);
}

.checklist li:last-child { border-block-end: 0; }

.checklist__icon { flex: 0 0 18px; width: 18px; height: 18px; margin-block-start: 2px; }
.checklist__icon--ok { color: var(--c-ok); }
.checklist__icon--warn { color: var(--c-warn); }
.checklist__icon--fail { color: var(--c-danger); }

/* ---------------------------------------------------------------- Timeline */

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }

.timeline::before {
    content: "";
    position: absolute;
    inset-block: 8px;
    inset-inline-start: 5px;
    width: 2px;
    background: var(--c-border);
}

.timeline li {
    position: relative;
    padding-inline-start: var(--sp-6);
    padding-block-end: var(--sp-4);
}

.timeline li::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    inset-block-start: 6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--c-surface);
    border: 2px solid var(--c-border-strong);
}

.timeline li.is-done::before { border-color: var(--c-ok); background: var(--c-ok); }
.timeline li.is-active::before { border-color: var(--c-primary); background: var(--c-primary); }
.timeline li.is-failed::before { border-color: var(--c-danger); background: var(--c-danger); }

/* ---------------------------------------------------------------- Calendar */

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    background: var(--c-border);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.calendar-head {
    background: var(--c-surface-2);
    padding: var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: 600;
    text-align: center;
    color: var(--c-text-2);
}

.calendar-cell {
    background: var(--c-surface);
    min-height: 108px;
    padding: var(--sp-2);
    font-size: var(--fs-xs);
}

.calendar-cell.is-outside { background: var(--c-surface-2); color: var(--c-text-3); }
.calendar-cell.is-today { box-shadow: inset 0 0 0 2px var(--c-primary); }
.calendar-cell__date { font-weight: 600; margin-block-end: var(--sp-1); }

.calendar-event {
    display: block;
    padding: 2px var(--sp-2);
    border-radius: var(--radius-sm);
    margin-block-end: 2px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-inline-start: 2px solid;
}

.calendar-event--draft { background: var(--c-surface-3); color: var(--c-text-2); border-color: var(--c-text-3); }
.calendar-event--scheduled { background: var(--c-info-soft); color: var(--c-info); border-color: var(--c-info); }
.calendar-event--published { background: var(--c-ok-soft); color: var(--c-ok); border-color: var(--c-ok); }
.calendar-event--failed { background: var(--c-danger-soft); color: var(--c-danger); border-color: var(--c-danger); }

/* ---------------------------------------------------------------- Utility */

.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.stack--sm { gap: var(--sp-2); }
.stack--lg { gap: var(--sp-5); }

.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.row--tight { gap: var(--sp-2); }

.muted { color: var(--c-text-2); }
.dim { color: var(--c-text-3); }
.small { font-size: var(--fs-sm); }
.tiny { font-size: var(--fs-xs); }
.strong { font-weight: 600; }
.mono { font-family: var(--font-mono); direction: ltr; unicode-bidi: embed; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break { word-break: break-word; overflow-wrap: anywhere; }
.text-ok { color: var(--c-ok); }
.text-warn { color: var(--c-warn); }
.text-danger { color: var(--c-danger); }
.text-center { text-align: center; }
.text-end { text-align: end; }

.mt-0 { margin-block-start: 0; }
.mt-2 { margin-block-start: var(--sp-2); }
.mt-3 { margin-block-start: var(--sp-3); }
.mt-4 { margin-block-start: var(--sp-4); }
.mt-5 { margin-block-start: var(--sp-5); }
.mt-6 { margin-block-start: var(--sp-6); }
.mb-0 { margin-block-end: 0; }
.mb-2 { margin-block-end: var(--sp-2); }
.mb-3 { margin-block-end: var(--sp-3); }
.mb-4 { margin-block-end: var(--sp-4); }
.mb-5 { margin-block-end: var(--sp-5); }
.mb-6 { margin-block-end: var(--sp-6); }

.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.w-full { width: 100%; }

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: var(--sp-2) var(--sp-4); font-size: var(--fs-base); }
.kv dt { color: var(--c-text-2); }
.kv dd { margin: 0; color: var(--c-text); word-break: break-word; }

.chip-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 0.125rem 0.5rem;
    background: var(--c-surface-3);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-full);
    font-size: var(--fs-xs);
    color: var(--c-text-2);
}

.chip button {
    border: 0;
    background: transparent;
    color: var(--c-text-3);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: 14px;
}

/* --------------------------------------------------------------- Auth page */

.auth {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-5);
    padding: var(--sp-5);
    background:
        radial-gradient(1000px 500px at 50% -10%, var(--c-primary-soft), transparent 70%),
        var(--c-bg);
}

.auth__card {
    width: min(420px, 100%);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--sp-8);
}

/* The brand takes people back to the site: someone who landed on the
   sign-in page and wanted the home page had no way out of it. */
.auth__brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    justify-content: center;
    color: inherit;
    text-decoration: none;
}

.auth__bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-2);
    color: var(--c-text-3);
    font-size: var(--fs-sm);
    text-align: center;
}

.auth__home {
    color: var(--c-primary);
    text-decoration: none;
    font-weight: 600;
}

.auth__home:hover {
    text-decoration: underline;
}

.auth__title { text-align: center; margin-block-end: var(--sp-2); }

.auth__subtitle {
    text-align: center;
    color: var(--c-text-2);
    margin-block-end: var(--sp-6);
    font-size: var(--fs-base);
}

.auth__footer {
    text-align: center;
    margin-block-start: var(--sp-5);
    font-size: var(--fs-sm);
}

/* -------------------------------------------------------------- Responsive */

.sidebar-toggle { display: none; }

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        transition: transform var(--transition);
    }

    html[dir="rtl"] .sidebar { transform: translateX(100%); }

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

    .app.is-menu-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(16, 24, 40, 0.4);
        z-index: 35;
    }

    .sidebar-toggle { display: inline-flex; }
    .content { padding: var(--sp-4); }
    .topbar { padding: 0 var(--sp-4); }
    .topbar__search { max-width: none; }
    .kv { grid-template-columns: 1fr; gap: var(--sp-1); }
    .kv dt { font-size: var(--fs-xs); }
}

@media (max-width: 600px) {
    .page-header { flex-direction: column; align-items: stretch; }
    .modal { max-height: 92vh; }
    .toasts { inset-inline: var(--sp-3); inset-block-end: var(--sp-3); max-width: none; }
}

@media print {
    .sidebar, .topbar, .page-header__actions, .toasts, .filters, .pagination { display: none !important; }
    .content { padding: 0; }
    .card { border: 0; box-shadow: none; }
    body { background: #fff; }
}

/* A fold-out section whose toggle looks like what it is: a button. The
   default marker disappears as soon as a summary is display:block, which left
   "More options" looking like a plain label nobody would think to click. */
.disclosure > summary {
    list-style: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border: 1px dashed var(--c-primary-border);
    border-radius: var(--radius-sm);
    background: var(--c-primary-soft);
    color: var(--c-primary);
    font-weight: 600;
    user-select: none;
    transition: background var(--transition), border-color var(--transition);
}

.disclosure > summary::-webkit-details-marker { display: none; }

.disclosure > summary:hover { border-color: var(--c-primary); }

.disclosure > summary::after {
    content: '';
    width: 0.45rem;
    height: 0.45rem;
    border-inline-end: 2px solid currentColor;
    border-block-end: 2px solid currentColor;
    transform: rotate(45deg);
    transition: transform var(--transition);
    margin-inline-start: 0.25rem;
}

.disclosure[open] > summary::after { transform: rotate(-135deg); }

.disclosure > summary .label__hint { color: var(--c-text-2); font-weight: 400; }

/* An option that exists but cannot be chosen right now. */
.is-unavailable { opacity: 0.6; }
