:root {
    /* =========================================================
       XERION — GLOBAL DESIGN TOKENS
    ========================================================== */

    --white: #ffffff;
    --black: #0b1220;

    --background: #f8fafc;
    --surface: #ffffff;
    --surface-soft: #f4f6f9;
    --surface-hover: #f1f4f8;

    --text: #111827;
    --text-soft: #334155;
    --muted: #64748b;
    --muted-light: #94a3b8;

    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Phase 13: matches the real logo asset's exact fill color
       (assets/xerion-logo-icon.svg's .cls-1, #3259a5), replacing the
       hand-picked approximation this token held before real brand art
       existed. */
    --blue: #3259a5;
    --blue-dark: #244582;
    --blue-hover: #294d96;
    --blue-light: #f3f6fb;

    --success: #16845b;
    --success-light: #edf8f3;

    --warning: #a66a00;
    --warning-light: #fff8e8;

    --danger: #c23b3b;
    --danger-light: #fdf0f0;

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 64px;

    --radius-xs: 6px;
    --radius-small: 9px;
    --radius: 12px;
    --radius-large: 16px;
    --radius-xl: 20px;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-small: 0 4px 14px rgba(15, 23, 42, 0.045);
    --shadow: 0 8px 28px rgba(15, 23, 42, 0.055);

    --surface-translucent: rgba(255, 255, 255, 0.96);

    --transition-fast: 120ms ease;
    --transition: 160ms ease;
    --transition-slow: 220ms ease;

    --font-sans:
        Inter,
        ui-sans-serif,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Roboto,
        Helvetica,
        Arial,
        sans-serif;
}


/* =========================================================
   DARK MODE
   ------------------------------------------------------------
   Phase 13: `general.settings` → appearance.theme persisted to
   Supabase (Phase 12) and set `<html data-theme="dark">` via
   settings.js's applyTheme(), but nothing anywhere defined what
   that attribute should actually change — same "persists with
   zero visible effect" bug class as several earlier settings.
   Same token names, dark values — every component already reads
   these via var(...), so this covers the whole app shell (chat,
   sidebar, all app.html pages) with no per-component changes.
   Scoped to the logged-in app only: index.html/auth.html are
   pre-login marketing/auth pages with no theme control, and the
   VELYN floating widget (velyn-widget.css) uses its own fully
   hardcoded palette — flagged separately, not covered here.
========================================================== */

:root[data-theme="dark"],
:root[data-theme="system"] {
    --white: #171c2b;
    --black: #e7eaf2;

    --background: #0e1220;
    --surface: #171c2b;
    --surface-soft: #1c2233;
    --surface-hover: #232a3d;

    --text: #e7eaf2;
    --text-soft: #b6bdd0;
    --muted: #8891a8;
    --muted-light: #626b82;

    --border: #2a3145;
    --border-strong: #3a4258;

    --blue: #6d93d6;
    --blue-dark: #9ab6e6;
    --blue-hover: #7ea0dc;
    --blue-light: #1c2740;

    --success: #34ab7d;
    --success-light: #142b21;

    --warning: #d9a13f;
    --warning-light: #2c2312;

    --danger: #e0716c;
    --danger-light: #2c1717;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-small: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);

    --surface-translucent: rgba(23, 28, 43, 0.92);
}

@media (prefers-color-scheme: light) {
    :root[data-theme="system"] {
        --white: #ffffff;
        --black: #0b1220;

        --background: #f8fafc;
        --surface: #ffffff;
        --surface-soft: #f4f6f9;
        --surface-hover: #f1f4f8;

        --text: #111827;
        --text-soft: #334155;
        --muted: #64748b;
        --muted-light: #94a3b8;

        --border: #e2e8f0;
        --border-strong: #cbd5e1;

        --blue: #3259a5;
        --blue-dark: #244582;
        --blue-hover: #294d96;
        --blue-light: #f3f6fb;

        --success: #16845b;
        --success-light: #edf8f3;

        --warning: #a66a00;
        --warning-light: #fff8e8;

        --danger: #c23b3b;
        --danger-light: #fdf0f0;

        --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
        --shadow-small: 0 4px 14px rgba(15, 23, 42, 0.045);
        --shadow: 0 8px 28px rgba(15, 23, 42, 0.055);

        --surface-translucent: rgba(255, 255, 255, 0.96);
    }
}

body {
    transition:
        background var(--transition),
        color var(--transition);
}


/* =========================================================
   RESET
========================================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;

    background: var(--background);
    color: var(--text);

    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;

    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body,
button,
input,
textarea,
select {
    font-family: var(--font-sans);
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    border: 0;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

img,
svg {
    display: block;
}

img {
    max-width: 100%;
}

svg {
    flex-shrink: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

ul,
ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

h1,
h2,
h3,
h4,
h5,
h6,
p {
    margin: 0;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--black);
    font-weight: 700;
}

textarea {
    resize: vertical;
}

input,
textarea,
select {
    color: var(--text);
}


/* =========================================================
   SELECTION
========================================================== */

::selection {
    background: rgba(49, 88, 168, 0.16);
    color: var(--black);
}


/* =========================================================
   SCROLLBARS
========================================================== */

* {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #cbd5e1;
}

::-webkit-scrollbar-thumb:hover {
    background: #b8c4d3;
}


/* =========================================================
   FOCUS
========================================================== */

:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}


/* =========================================================
   GLOBAL BUTTON
========================================================== */

.button {
    min-height: 42px;
    padding: 0 16px;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    border: 1px solid transparent;
    border-radius: var(--radius-small);

    background: transparent;
    color: var(--text);

    font-size: 13px;
    font-weight: 600;
    line-height: 1;

    cursor: pointer;

    transition:
        background var(--transition),
        border-color var(--transition),
        color var(--transition),
        box-shadow var(--transition),
        transform var(--transition);
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.button:active:not(:disabled) {
    transform: translateY(0);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
}


/* =========================================================
   BUTTON VARIANTS
========================================================== */

.button-primary {
    background: var(--blue);
    color: var(--white);

    box-shadow: var(--shadow-xs);
}

.button-primary:hover:not(:disabled) {
    background: var(--blue-hover);
    box-shadow: 0 4px 12px rgba(49, 88, 168, 0.13);
}

.button-dark {
    background: var(--black);
    color: var(--white);
}

.button-dark:hover:not(:disabled) {
    background: #172033;
}

.button-outline {
    border-color: var(--border-strong);
    background: var(--white);
    color: var(--text-soft);
}

.button-outline:hover:not(:disabled) {
    border-color: #aebaca;
    background: var(--surface-soft);
}

.button-ghost {
    color: var(--text-soft);
}

.button-ghost:hover:not(:disabled) {
    background: var(--surface-hover);
    color: var(--text);
}


/* =========================================================
   BUTTON SIZES
========================================================== */

.button-small {
    min-height: 36px;
    padding: 0 13px;
    font-size: 12px;
}

.button-large {
    min-height: 48px;
    padding: 0 20px;
    font-size: 14px;
}


/* =========================================================
   GLOBAL INPUTS
========================================================== */

input,
textarea,
select {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-small);

    background: var(--white);
    color: var(--text);

    outline: none;

    transition:
        border-color var(--transition),
        box-shadow var(--transition),
        background var(--transition);
}

input:hover,
textarea:hover,
select:hover {
    border-color: #b7c3d3;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(49, 88, 168, 0.08);
}

input::placeholder,
textarea::placeholder {
    color: var(--muted-light);
}


/* =========================================================
   SELECT
========================================================== */

select {
    min-height: 40px;
    padding: 0 34px 0 12px;

    cursor: pointer;

    appearance: none;

    background-image:
        linear-gradient(45deg, transparent 50%, #64748b 50%),
        linear-gradient(135deg, #64748b 50%, transparent 50%);
    background-position:
        calc(100% - 15px) 17px,
        calc(100% - 11px) 17px;
    background-size:
        4px 4px,
        4px 4px;
    background-repeat: no-repeat;
}


/* =========================================================
   TEXT UTILITIES
========================================================== */

.text-primary {
    color: var(--text);
}

.text-secondary {
    color: var(--text-soft);
}

.text-muted {
    color: var(--muted);
}

.text-blue {
    color: var(--blue);
}

.text-success {
    color: var(--success);
}

.text-warning {
    color: var(--warning);
}

.text-danger {
    color: var(--danger);
}


/* =========================================================
   VISIBILITY UTILITIES
========================================================== */

.is-hidden {
    display: none !important;
}

.is-visible {
    display: block !important;
}

.is-disabled {
    pointer-events: none;
    opacity: 0.5;
}


/* =========================================================
   STATUS
========================================================== */

.status-dot {
    width: 7px;
    height: 7px;

    flex-shrink: 0;

    border-radius: 50%;
    background: var(--muted-light);
}

.status-dot.is-online {
    background: var(--success);
}

.status-dot.is-warning {
    background: var(--warning);
}

.status-dot.is-error {
    background: var(--danger);
}


/* =========================================================
   BADGES
========================================================== */

.badge {
    min-height: 24px;
    padding: 0 8px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border: 1px solid var(--border);
    border-radius: 999px;

    background: var(--surface-soft);
    color: var(--text-soft);

    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}

.badge-blue {
    border-color: #d8e2f4;
    background: var(--blue-light);
    color: var(--blue);
}

.badge-success {
    border-color: #d5eee3;
    background: var(--success-light);
    color: var(--success);
}


/* =========================================================
   CARDS
========================================================== */

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);

    background: var(--surface);

    box-shadow: var(--shadow-xs);
}


/* =========================================================
   DIVIDERS
========================================================== */

.divider {
    width: 100%;
    height: 1px;
    background: var(--border);
}


/* =========================================================
   TOOLTIP BASE
========================================================== */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);

    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);

    padding: 6px 8px;

    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 6px;

    background: var(--black);
    color: var(--white);

    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;

    white-space: nowrap;

    opacity: 0;
    visibility: hidden;
    pointer-events: none;

    transform: translate(-50%, 3px);

    transition:
        opacity var(--transition-fast),
        visibility var(--transition-fast),
        transform var(--transition-fast);

    z-index: 1000;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}


/* =========================================================
   LOADING
========================================================== */

.loading-spinner {
    width: 18px;
    height: 18px;

    border: 2px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;

    animation: xerion-spin 0.75s linear infinite;
}

.loading-spinner-small {
    width: 14px;
    height: 14px;
    border-width: 1.5px;
}

@keyframes xerion-spin {
    to {
        transform: rotate(360deg);
    }
}


/* =========================================================
   SKELETON
========================================================== */

.skeleton {
    border-radius: var(--radius-small);
    background: var(--surface-soft);

    animation: xerion-pulse 1.5s ease-in-out infinite;
}

@keyframes xerion-pulse {
    0%,
    100% {
        opacity: 0.55;
    }

    50% {
        opacity: 1;
    }
}


/* =========================================================
   EMPTY STATES
========================================================== */

.empty-state {
    width: 100%;
    min-height: 220px;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    padding: 32px;

    text-align: center;
}

.empty-state-icon {
    width: 44px;
    height: 44px;

    display: flex;
    align-items: center;
    justify-content: center;

    margin-bottom: 14px;

    border: 1px solid var(--border);
    border-radius: var(--radius);

    background: var(--surface);
    color: var(--muted);
}

.empty-state-icon svg {
    width: 20px;
    height: 20px;
}

.empty-state h3 {
    margin-bottom: 5px;

    color: var(--text);
    font-size: 15px;
    line-height: 1.3;
}

.empty-state p {
    max-width: 360px;

    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
}


/* =========================================================
   FORM HELPERS
========================================================== */

.form-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.form-field label {
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 600;
}

.form-help {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.form-error {
    color: var(--danger);
    font-size: 12px;
    line-height: 1.5;
}


/* =========================================================
   TOAST BASE
========================================================== */

.toast-container {
    position: fixed;
    right: 20px;
    bottom: 20px;

    width: min(360px, calc(100vw - 40px));

    display: flex;
    flex-direction: column;
    gap: 8px;

    z-index: 2000;

    pointer-events: none;
}

.toast {
    padding: 12px 14px;

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    background: var(--white);
    color: var(--text);

    box-shadow: var(--shadow);

    font-size: 13px;
    line-height: 1.45;

    pointer-events: auto;

    animation: xerion-toast-in 180ms ease forwards;
}

.toast.is-clickable {
    cursor: pointer;
}

.toast.is-clickable:hover {
    border-color: var(--blue);
}

@keyframes xerion-toast-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* =========================================================
   ACCESSIBILITY
========================================================== */

.visually-hidden {
    position: absolute !important;

    width: 1px !important;
    height: 1px !important;

    padding: 0 !important;
    margin: -1px !important;

    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;

    white-space: nowrap !important;

    border: 0 !important;
}


/* =========================================================
   REDUCED MOTION
========================================================== */

@media (prefers-reduced-motion: reduce) {

    html {
        scroll-behavior: auto;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}


/* =========================================================
   COMPACT MODE (Settings → Appearance → Compact mode)
========================================================== */
/* Real bug fix (2026-09-29): settings.js's applyCompactMode() has always
   correctly toggled body.is-compact on/off (confirmed live — the setting
   itself saves and reads correctly) — but zero CSS anywhere in the repo
   ever defined what that class should actually do, the exact same
   "toggle a class nothing styles" bug class this project has found and
   fixed repeatedly (dark mode, .reduce-animations' sibling case, etc.).
   Reuses the same real, existing layout tokens/selectors
   (--sidebar-width/--topbar-height, .sidebar-item, .page-content,
   .chat-messages, .chat-message) rather than inventing a parallel
   layout system — same convention this file's own responsive
   breakpoints already use for overriding these exact two variables. */

body.is-compact {
    --sidebar-width: 216px;
    --topbar-height: 52px;
}

body.is-compact .sidebar-item {
    min-height: 32px;
    padding: 0 8px;
    gap: 9px;

    font-size: 12.5px;
}

body.is-compact .sidebar-item-icon {
    width: 16px;
    height: 16px;
}

body.is-compact .sidebar-new-chat {
    padding: 10px 12px 6px;
}

body.is-compact .new-chat-button {
    min-height: 36px;
    padding: 0 10px;

    font-size: 12.5px;
}

body.is-compact .sidebar-section {
    margin-bottom: 10px;
}

body.is-compact .app-topbar {
    padding: 0 16px;
}

body.is-compact .page-content {
    padding: 22px 24px 40px;
}

body.is-compact .page-toolbar {
    margin-bottom: 10px;
}

body.is-compact .chat-messages {
    padding: 18px 20px 120px;
}

body.is-compact .chat-message {
    gap: 10px;

    margin-bottom: 18px;
}

body.is-compact .chat-message-user .chat-message-content {
    padding: 8px 11px;
}

body.is-compact .composer-top textarea {
    min-height: 40px;

    padding: 10px 13px 6px;
}

body.is-compact .sidebar-user {
    min-height: 40px;

    margin-top: 3px;
}