/* ============================================================
   SMLib design tokens — link once, in the document head:

     <link rel="stylesheet" href="_content/SMLib/smlib.css" />

   Every layout, form, dashboard and feedback component reads these. The palette is Tailwind's
   (slate + indigo), and dark mode follows Tailwind's class strategy: a `dark` class on <html>
   (which SmartThemeProvider / SmartAdminLayout manage) switches SMLib and your own `dark:`
   utilities together. A `dark` or `light` class on any element re-themes just that subtree.

   Re-brand by overriding tokens after this file, e.g.
     :root { --smt-accent: #0d9488; --smt-accent-hover: #0f766e; --smt-accent-soft: #f0fdfa; }
   ============================================================ */

:root,
.light {
    color-scheme: light;

    /* Surfaces */
    --smt-page-bg: #f8fafc;
    --smt-bg: #ffffff;
    --smt-bg-alt: #f8fafc;
    --smt-bg-hover: #f1f5f9;
    --smt-bg-input: #ffffff;
    --smt-bg-inset: #f1f5f9;
    --smt-border: #e2e8f0;
    --smt-border-strong: #cbd5e1;

    /* Text */
    --smt-text: #0f172a;
    --smt-text-muted: #64748b;
    --smt-text-subtle: #94a3b8;

    /* Brand */
    --smt-accent: #4f46e5;
    --smt-accent-hover: #4338ca;
    --smt-accent-soft: #eef2ff;
    --smt-accent-text: #4338ca;
    --smt-on-accent: #ffffff;

    /* Status — each has a solid, a soft background and a readable text colour on the soft one */
    --smt-success: #059669;
    --smt-success-soft: #ecfdf5;
    --smt-success-text: #047857;
    --smt-warn: #d97706;
    --smt-warn-soft: #fffbeb;
    --smt-warn-text: #b45309;
    --smt-danger: #e11d48;
    --smt-danger-hover: #be123c;
    --smt-danger-soft: #fff1f2;
    --smt-danger-text: #be123c;
    --smt-danger-solid: #e11d48;
    --smt-danger-solid-hover: #be123c;
    --smt-info: #0284c7;
    --smt-info-soft: #f0f9ff;
    --smt-info-text: #0369a1;

    /* Sidebar — its own tokens so it can be dark on a light page (set them to the dark values) */
    --smt-sidebar-bg: #ffffff;
    --smt-sidebar-border: #e2e8f0;
    --smt-sidebar-text: #475569;
    --smt-sidebar-text-strong: #0f172a;
    --smt-sidebar-hover: #f1f5f9;
    --smt-sidebar-active-bg: #eef2ff;
    --smt-sidebar-active-text: #4338ca;
    --smt-sidebar-section: #94a3b8;

    /* Shape & depth */
    --smt-radius: 12px;
    --smt-radius-sm: 8px;
    --smt-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
    --smt-shadow-lg: 0 10px 30px rgba(15, 23, 42, .12), 0 2px 6px rgba(15, 23, 42, .06);
    --smt-ring: 0 0 0 3px rgba(79, 70, 229, .18);
    --smt-ring-danger: 0 0 0 3px rgba(225, 29, 72, .16);

    --smt-font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

    /* Density — control heights, padding and gaps. A brand theme's Density sets these. */
    --smt-control-h: 2.375rem;
    --smt-control-h-sm: 2rem;
    --smt-control-h-lg: 2.75rem;
    --smt-nav-h: 2.375rem;
    --smt-topbar-h: 4rem;
    --smt-pad: 1.25rem;
    --smt-pad-lg: 1.5rem;
    --smt-gap: 1.25rem;
}

.dark {
    color-scheme: dark;

    --smt-page-bg: #13141f;
    --smt-bg: #1c1d2b;
    --smt-bg-alt: #181927;
    --smt-bg-hover: #252638;
    --smt-bg-input: #151621;
    --smt-bg-inset: #151621;
    --smt-border: #2e3046;
    --smt-border-strong: #3d4060;

    /* Secondary text keeps 4.5:1 (WCAG AA) on every surface it sits on, hover included. */
    --smt-text: #e8e9f2;
    --smt-text-muted: #a1a4ba;
    --smt-text-subtle: #8a8ca3;

    --smt-accent: #8b85f4;
    --smt-accent-hover: #a5a0f7;
    --smt-accent-soft: #26264a;
    --smt-accent-text: #b4b0fa;
    --smt-on-accent: #11121c;

    --smt-success: #34d399;
    --smt-success-soft: #12302a;
    --smt-success-text: #6ee7b7;
    --smt-warn: #fbbf24;
    --smt-warn-soft: #33290f;
    --smt-warn-text: #fcd34d;
    --smt-danger: #fb7185;
    --smt-danger-hover: #f43f5e;
    --smt-danger-soft: #3a1f29;
    --smt-danger-text: #fda4af;
    --smt-danger-solid: #e11d48;
    --smt-danger-solid-hover: #be123c;
    --smt-info: #38bdf8;
    --smt-info-soft: #0f2a3a;
    --smt-info-text: #7dd3fc;

    --smt-sidebar-bg: #181927;
    --smt-sidebar-border: #2e3046;
    --smt-sidebar-text: #a1a4ba;
    --smt-sidebar-text-strong: #e8e9f2;
    --smt-sidebar-hover: #252638;
    --smt-sidebar-active-bg: #26264a;
    --smt-sidebar-active-text: #c4c1fb;
    --smt-sidebar-section: #8a8ca3;

    --smt-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .4);
    --smt-shadow-lg: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
    --smt-ring: 0 0 0 3px rgba(139, 133, 244, .28);
    --smt-ring-danger: 0 0 0 3px rgba(251, 113, 133, .25);
}

/* A page that does not manage the class itself can opt into the OS preference instead:
   <html class="smt-auto">. SmartThemeProvider resolves Auto to `dark`/`light`, so this is
   only the no-JavaScript path. */
@media (prefers-color-scheme: dark) {
    .smt-auto:not(.light) {
        color-scheme: dark;
        --smt-page-bg: #13141f;
        --smt-bg: #1c1d2b;
        --smt-bg-alt: #181927;
        --smt-bg-hover: #252638;
        --smt-bg-input: #151621;
        --smt-bg-inset: #151621;
        --smt-border: #2e3046;
        --smt-border-strong: #3d4060;
        --smt-text: #e8e9f2;
        --smt-text-muted: #a1a4ba;
        --smt-text-subtle: #8a8ca3;
        --smt-accent: #8b85f4;
        --smt-accent-hover: #a5a0f7;
        --smt-accent-soft: #26264a;
        --smt-accent-text: #b4b0fa;
        --smt-on-accent: #11121c;
        --smt-success: #34d399;
        --smt-success-soft: #12302a;
        --smt-success-text: #6ee7b7;
        --smt-warn: #fbbf24;
        --smt-warn-soft: #33290f;
        --smt-warn-text: #fcd34d;
        --smt-danger: #fb7185;
        --smt-danger-hover: #f43f5e;
        --smt-danger-soft: #3a1f29;
        --smt-danger-text: #fda4af;
        --smt-danger-solid: #e11d48;
        --smt-danger-solid-hover: #be123c;
        --smt-info: #38bdf8;
        --smt-info-soft: #0f2a3a;
        --smt-info-text: #7dd3fc;
        --smt-sidebar-bg: #181927;
        --smt-sidebar-border: #2e3046;
        --smt-sidebar-text: #a1a4ba;
        --smt-sidebar-text-strong: #e8e9f2;
        --smt-sidebar-hover: #252638;
        --smt-sidebar-active-bg: #26264a;
        --smt-sidebar-active-text: #c4c1fb;
        --smt-sidebar-section: #8a8ca3;
        --smt-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .4);
        --smt-shadow-lg: 0 12px 32px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .35);
        --smt-ring: 0 0 0 3px rgba(139, 133, 244, .28);
        --smt-ring-danger: 0 0 0 3px rgba(251, 113, 133, .25);
    }
}

/* Visually hidden, still announced. */
.smt-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Theme switches should not animate every border and background on the page. */
.smt-theme-switching,
.smt-theme-switching * {
    transition: none !important;
}

/* ============================================================
   Forms — global on purpose: every SMLib input shares these, and your
   own controls can wear them too (class="smt-input", "smt-field", …).
   ============================================================ */

.smt-grid {
    display: grid;
    grid-template-columns: repeat(var(--smt-cols, 1), minmax(0, 1fr));
    gap: var(--smt-gap);
    align-items: start;
}

.smt-span-2 { grid-column: span 2; }
.smt-span-3 { grid-column: span 3; }
.smt-span-4 { grid-column: span 4; }
.smt-span-full { grid-column: 1 / -1; }

/* Dashboard grids step down to ColumnsMedium on tablets; wide cells then take the whole row. */
@media (max-width: 1023.98px) {
    .smt-dash-grid { --smt-cols: var(--smt-cols-md, 2) !important; }
    .smt-dash-grid > .smt-span-3,
    .smt-dash-grid > .smt-span-4 { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
    .smt-grid { grid-template-columns: minmax(0, 1fr); }
    .smt-grid > * { grid-column: 1 / -1; }
}

/* ─────────── Field frame ─────────── */
.smt-field {
    display: flex;
    flex-direction: column;
    gap: .375rem;
    min-width: 0;
    font-family: var(--smt-font);
}

.smt-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: .75rem;
}

.smt-label {
    display: block;
    padding: 0;
    font-size: .875rem;
    font-weight: 550;
    line-height: 1.25rem;
    color: var(--smt-text);
}

.smt-req {
    margin-left: .125rem;
    color: var(--smt-danger);
}

.smt-optional {
    margin-left: .375rem;
    font-size: .75rem;
    font-weight: 450;
    color: var(--smt-text-subtle);
}

.smt-field-foot {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
}

.smt-hint {
    margin: 0;
    font-size: .8125rem;
    line-height: 1.35;
    color: var(--smt-text-muted);
}

.smt-counter {
    margin-left: auto;
    flex-shrink: 0;
    font-size: .75rem;
    color: var(--smt-text-subtle);
    font-variant-numeric: tabular-nums;
}

.smt-field-error p {
    margin: 0;
    font-size: .8125rem;
    line-height: 1.35;
    color: var(--smt-danger-text);
}

/* ─────────── Controls ─────────── */
.smt-input {
    display: block;
    width: 100%;
    height: var(--smt-control-h);
    padding: 0 .75rem;
    font: 400 .9375rem/1.4 var(--smt-font);
    color: var(--smt-text);
    background-color: var(--smt-bg-input);
    border: 1px solid var(--smt-border-strong);
    border-radius: var(--smt-radius-sm);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
    box-sizing: border-box;
    transition: border-color .15s, box-shadow .15s;
    appearance: none;
}

.smt-input::placeholder { color: var(--smt-text-subtle); opacity: 1; }

.smt-input:hover:not(:disabled):not([readonly]) { border-color: var(--smt-text-subtle); }

.smt-input:focus {
    outline: none;
    border-color: var(--smt-accent);
    box-shadow: var(--smt-ring);
}

.smt-input[aria-invalid="true"],
.smt-invalid { border-color: var(--smt-danger) !important; }

.smt-input[aria-invalid="true"]:focus { box-shadow: var(--smt-ring-danger); }

.smt-input:disabled {
    color: var(--smt-text-muted);
    background-color: var(--smt-bg-inset);
    cursor: not-allowed;
    box-shadow: none;
}

.smt-input[readonly] {
    background-color: var(--smt-bg-inset);
    border-color: var(--smt-border);
    box-shadow: none;
}

.smt-input-sm { height: var(--smt-control-h-sm); padding: 0 .625rem; font-size: .8125rem; }
.smt-input-lg { height: var(--smt-control-h-lg); font-size: 1rem; }

.smt-textarea {
    height: auto;
    min-height: 5rem;
    padding: .5rem .75rem;
    resize: vertical;
}

.smt-autogrow { field-sizing: content; max-height: 24rem; }

.smt-number { font-variant-numeric: tabular-nums; }

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

.smt-select option { color: var(--smt-text); background: var(--smt-bg); }

.smt-date::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }
.dark .smt-date::-webkit-calendar-picker-indicator { filter: invert(1); }

/* Prefix / suffix addons share one border with the control. */
.smt-input-group {
    display: flex;
    align-items: stretch;
    width: 100%;
    background: var(--smt-bg-input);
    border: 1px solid var(--smt-border-strong);
    border-radius: var(--smt-radius-sm);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
    transition: border-color .15s, box-shadow .15s;
    overflow: hidden;
    box-sizing: border-box;
}

.smt-input-group:focus-within {
    border-color: var(--smt-accent);
    box-shadow: var(--smt-ring);
}

.smt-input-group.smt-invalid:focus-within { box-shadow: var(--smt-ring-danger); }
.smt-input-group.smt-disabled { background: var(--smt-bg-inset); }

.smt-input-group .smt-input {
    flex: 1;
    min-width: 0;
    height: calc(var(--smt-control-h) - 2px);
    border: none;
    border-radius: 0;
    box-shadow: none;
    background-color: transparent;
}

.smt-input-group .smt-input:focus { box-shadow: none; }

.smt-addon {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    padding: 0 .75rem;
    font-size: .875rem;
    color: var(--smt-text-muted);
    background: var(--smt-bg-alt);
    white-space: nowrap;
}

.smt-addon:first-child { border-right: 1px solid var(--smt-border); }
.smt-addon:not(:first-child) { border-left: 1px solid var(--smt-border); }

.smt-addon-icon { padding-right: 0; background: transparent; border: none !important; }

.smt-addon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.375rem;
    flex-shrink: 0;
    color: var(--smt-text-muted);
    background: none;
    border: none;
    cursor: pointer;
}

.smt-addon-btn:hover { color: var(--smt-text); }
.smt-addon-btn:focus-visible { outline: none; color: var(--smt-accent); }

/* ─────────── Checkbox, radio, switch ─────────── */
.smt-check,
.smt-radio {
    flex-shrink: 0;
    width: 1rem;
    height: 1rem;
    margin: .1875rem 0 0;
    accent-color: var(--smt-accent);
    cursor: pointer;
}

.smt-check:disabled,
.smt-radio:disabled { cursor: not-allowed; }

.smt-check:focus-visible,
.smt-radio:focus-visible {
    outline: 2px solid var(--smt-accent);
    outline-offset: 2px;
}

.smt-check-row,
.smt-switch-row {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
}

.smt-switch-row {
    justify-content: space-between;
    gap: 1.5rem;
}

.smt-switch-compact { justify-content: flex-end; flex-direction: row-reverse; gap: .75rem; }

.smt-check-text {
    display: flex;
    flex-direction: column;
    gap: .125rem;
    min-width: 0;
}

.smt-check-label {
    font-size: .875rem;
    font-weight: 550;
    line-height: 1.375rem;
    color: var(--smt-text);
    cursor: pointer;
}

.smt-check-desc {
    margin: 0;
    font-size: .8125rem;
    line-height: 1.4;
    color: var(--smt-text-muted);
}

.smt-switch-wrap {
    display: inline-flex;
    align-items: center;
    gap: .625rem;
    flex-shrink: 0;
}

.smt-switch {
    position: relative;
    flex-shrink: 0;
    width: 2.75rem;
    height: 1.5rem;
    margin: 0;
    background: var(--smt-border-strong);
    border-radius: 999px;
    cursor: pointer;
    appearance: none;
    transition: background-color .2s;
}

.smt-switch::after {
    content: "";
    position: absolute;
    top: .1875rem;
    left: .1875rem;
    width: 1.125rem;
    height: 1.125rem;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
    transition: transform .2s cubic-bezier(.4, 0, .2, 1);
}

.smt-switch:checked { background: var(--smt-accent); }
.smt-switch:checked::after { transform: translateX(1.25rem); }
.smt-switch:disabled { opacity: .5; cursor: not-allowed; }
.smt-switch:focus-visible { outline: none; box-shadow: var(--smt-ring); }

.smt-switch-state {
    min-width: 3.5rem;
    font-size: .8125rem;
    font-weight: 550;
    color: var(--smt-text-muted);
}

fieldset.smt-radios {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
}

.smt-radios > legend {
    float: left;
    width: 100%;
    margin-bottom: .625rem;
}

.smt-radios-list {
    clear: both;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.smt-radios-row .smt-radios-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: .75rem 1.5rem;
}

.smt-radio-item {
    display: flex;
    align-items: flex-start;
    gap: .625rem;
    cursor: pointer;
}

.smt-radio-locked { cursor: not-allowed; opacity: .6; }

/* Radio cards */
.smt-radios-cards .smt-radios-list {
    display: grid;
    grid-template-columns: repeat(var(--smt-card-cols, 3), minmax(0, 1fr));
    gap: .75rem;
}

@media (max-width: 640px) {
    .smt-radios-cards .smt-radios-list { grid-template-columns: minmax(0, 1fr); }
}

.smt-radios-cards .smt-radio-item {
    flex-direction: row-reverse;
    justify-content: space-between;
    padding: .875rem 1rem;
    background: var(--smt-bg);
    border: 1px solid var(--smt-border-strong);
    border-radius: var(--smt-radius-sm);
    transition: border-color .15s, box-shadow .15s;
}

.smt-radios-cards .smt-radio-item:hover:not(.smt-radio-locked) { border-color: var(--smt-text-subtle); }

.smt-radios-cards .smt-radio-on {
    border-color: var(--smt-accent) !important;
    box-shadow: 0 0 0 1px var(--smt-accent);
}

.smt-radios-cards .smt-radio-item:has(:focus-visible) { box-shadow: var(--smt-ring); }

/* ─────────── Form shell ─────────── */
.smt-form {
    font-family: var(--smt-font);
}

.smt-form-inner {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.smt-form-summary {
    padding: .875rem 1rem;
    font-size: .875rem;
    color: var(--smt-text);
    background: var(--smt-danger-soft);
    border: 1px solid color-mix(in srgb, var(--smt-danger) 25%, transparent);
    border-radius: var(--smt-radius-sm);
}

.smt-form-summary-title {
    margin: 0 0 .375rem;
    font-weight: 650;
    color: var(--smt-danger-text);
}

.smt-form-summary ul {
    margin: 0;
    padding-left: 1.25rem;
}

.smt-form-summary li + li { margin-top: .125rem; }

.smt-form-summary a {
    color: var(--smt-danger-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.smt-form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .75rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--smt-border);
}

.smt-form-actions-end {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
    margin-left: auto;
}

.smt-form-actions-sticky {
    position: sticky;
    bottom: 0;
    z-index: 20;
    margin: 0 -1rem;
    padding: .875rem 1rem;
    background: color-mix(in srgb, var(--smt-page-bg) 88%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.smt-form-dirty {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: .8125rem;
    font-weight: 550;
    color: var(--smt-warn-text);
}

.smt-form-dirty span {
    width: .5rem;
    height: .5rem;
    border-radius: 50%;
    background: var(--smt-warn);
}

@media (max-width: 640px) {
    .smt-form-actions-end { width: 100%; }
    .smt-form-actions-end > * { flex: 1; }
}

/* ─────────── Sections ─────────── */
.smt-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.smt-section-head { min-width: 0; }

.smt-section-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 650;
    line-height: 1.5rem;
    color: var(--smt-text);
}

.smt-section-desc {
    margin: .25rem 0 0;
    font-size: .875rem;
    line-height: 1.5;
    color: var(--smt-text-muted);
}

.smt-section-card {
    background: var(--smt-bg);
    border: 1px solid var(--smt-border);
    border-radius: var(--smt-radius);
    box-shadow: var(--smt-shadow);
}

.smt-section-body { padding: var(--smt-pad-lg); }

.smt-section-foot {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: .875rem 1.5rem;
    background: var(--smt-bg-alt);
    border-top: 1px solid var(--smt-border);
    border-radius: 0 0 var(--smt-radius) var(--smt-radius);
}

.smt-section-plain .smt-section-card {
    background: none;
    border: none;
    box-shadow: none;
}

.smt-section-plain .smt-section-body { padding: 0; }

@media (min-width: 1024px) {
    .smt-section-aside {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
        gap: 2rem;
    }

    .smt-section-aside .smt-section-head { padding-top: .25rem; }
}

@media (max-width: 640px) {
    .smt-section-body { padding: 1.125rem; }
}

/* One-time codes (SmartCodeInput): one field, spaced like boxes. */
.smt-code {
    height: 3.25rem;
    padding-left: calc(.75rem + .45em);
    font: 600 1.5rem/1 ui-monospace, 'SFMono-Regular', Consolas, monospace;
    letter-spacing: .45em;
    text-align: center;
}

.smt-code::placeholder { letter-spacing: .45em; color: var(--smt-border-strong); }
