/* ── Inter, self-hosted ───────────────────────────────────────────────────────
   Was an @import from fonts.googleapis.com: a render-blocking remote request
   that leaves offline Electron users on a fallback face. These are the same
   Google-served subsets (Inter v20 variable, weight 300-700), vendored under
   wwwroot/lib/inter so the desktop app never reaches the network for type. */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('lib/inter/inter-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('lib/inter/inter-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('lib/inter/inter-vietnamese.woff2') format('woff2');
    unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('lib/inter/inter-greek.woff2') format('woff2');
    unicode-range: U+0370-0377, U+037A-037F, U+0384-038A, U+038C, U+038E-03A1, U+03A3-03FF;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('lib/inter/inter-greek-ext.woff2') format('woff2');
    unicode-range: U+1F00-1FFF;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('lib/inter/inter-cyrillic.woff2') format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('lib/inter/inter-cyrillic-ext.woff2') format('woff2');
    unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}

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

:root {
    /* ── Color ────────────────────────────────────────────────────────────
       These are the "default" preset, pre-derived exactly as
       UserTheme.ToCss() would derive them from Accent #2b6bff /
       BgPrimary #1a1b21 / BgSidebar #131319. ToCss() overwrites most of
       them at runtime once ThemeProvider applies the viewer's theme; these
       values are what paints before that, so they must match the default
       preset or the app flashes a different palette on load.
       Anything ToCss() does NOT emit (text, interactive, status colors) is
       fixed here across all 15 presets. */
    --dc-bg-primary: #1a1b21;
    --dc-bg-secondary: #131319;
    --dc-bg-tertiary: #0d0d11;
    --dc-bg-secondary-alt: #16171d;
    --dc-bg-floating: #0a0a0d;
    --dc-bg-modifier-hover: rgba(43,107,255,0.07);
    --dc-bg-modifier-selected: rgba(43,107,255,0.13);
    --dc-bg-modifier-active: rgba(43,107,255,0.18);
    --dc-header-primary: #e6edf6;
    --dc-header-secondary: #8da2ba;
    --dc-text-normal: #c9d4e2;
    /* Was #5a7394 — 3.53:1 on --dc-bg-primary, below the 4.5:1 body-text
       floor, and this token carries body copy app-wide. #97a0b2 holds
       >=4.8:1 against every preset background, including the lightest
       (Blurple #313338). */
    --dc-text-muted: #97a0b2;
    --dc-text-link: #5cb8ff;
    --dc-interactive-normal: #8da2ba;
    --dc-interactive-hover: #c9d4e2;
    --dc-interactive-active: #e6edf6;
    --dc-brand: #2b6bff;
    --dc-brand-hover: #2357d1;
    --dc-brand-active: #1b45a5;
    --dc-green: #23a55a;
    --dc-red: #f23f42;
    --dc-yellow: #f0b232;
    --dc-input-bg: #121217;
    /* Was #4a6580 — 2.09:1 on the Blurple preset. */
    --dc-input-placeholder: #939bad;
    --dc-channeltextarea-bg: #141519;
    --dc-scrollbar-thumb: #2a2b33;
    --dc-scrollbar-track: transparent;
    --dc-separator: rgba(43,107,255,0.08);
    --dc-blurple: #2b6bff;

    /* ── Semantic colours — fixed, not themeable ──────────────────────────
       These encode meaning rather than brand, so ToCss() does not emit them
       and they stay put under all 15 presets, exactly like --dc-green/red/
       yellow above. Verified >=4.5:1 as text on the default background and
       >=3:1 as fills on the lightest preset (Blurple #313338). */

    /* The step between red and yellow; no existing token covered it. */
    --dc-orange: #f0813a;
    /* Categorical only (calendar event dots) — a fill, never body text. */
    --dc-purple: #a855f7;

    /* Priority / severity ramp. Was four different palettes across
       ProjectBoard, MasterBoard, MyTasksPanel, PublicBoard and
       CalendarChannel — including Discord blurple for "medium", which
       collided with the brand accent. One ramp now. */
    --dc-prio-critical: var(--dc-red);
    --dc-prio-high:     var(--dc-orange);
    --dc-prio-medium:   var(--dc-yellow);
    --dc-prio-low:      var(--dc-green);

    /* Code. Inline code and code blocks in messages, wiki and docs were on
       three different palettes; this is the One Dark pair they mostly used. */
    --dc-code-fg:     #abb2bf;
    --dc-code-accent: #e06c75;

    /* Text/glyphs sitting ON a saturated accent or status fill. The fills they
       pair with (--dc-brand and the status ramp) are always saturated
       mid-tones, so the pairing is fixed rather than themeable — this is the
       one place a literal white or near-black is correct, and it lives here
       once instead of being repeated across component CSS. */
    --dc-on-accent: #fff;
    --dc-on-bright: #111;
    --font-primary: 'Inter', 'gg sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-display: 'Inter', 'gg sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    --font-code: 'Consolas', 'Andale Mono WT', 'Andale Mono', 'Lucida Console', 'Lucida Sans Typewriter', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Liberation Mono', 'Nimbus Mono L', Monaco, 'Courier New', Courier, monospace;

    /* ── Design language: non-color layer ─────────────────────────────────
       Fixed constants. UserTheme.ToCss() only ever rewrites --dc-* colors,
       so radius/space/type/motion stay identical under all 15 presets. */

    /* Radius */
    --r-xs: 6px;      /* chips, tags, small controls */
    --r-sm: 8px;      /* buttons, inputs, selects */
    --r-md: 12px;     /* cards, list rows, icon tiles */
    --r-lg: 18px;     /* panels, modals */
    --r-pill: 100px;
    --r-round: 50%;

    /* Space — 4px base */
    --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
    --s-5: 20px; --s-6: 24px; --s-8: 32px;

    /* Type — px only, no rem */
    --t-xs: 11px;    /* uppercase labels, counters */
    --t-sm: 12px;    /* meta, timestamps */
    --t-md: 13px;    /* secondary body, pills */
    --t-base: 15px;  /* body, message text */
    --t-lg: 19px;    /* h3, panel titles */
    --t-xl: 24px;    /* h2 */
    --t-2xl: 32px;   /* h1 */

    /* Motion */
    --dur: 0.22s;
    --ease: ease;
    --ease-enter: cubic-bezier(0.16, 1, 0.3, 1);

    /* Elevation */
    --shadow-panel: 0 24px 60px -30px rgba(0, 0, 0, 0.7);
    --shadow-window: 0 30px 60px -20px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.02);
}

html, body {
    width: 100%;
    height: 100%;
    background-color: var(--dc-bg-primary);
    color: var(--dc-text-normal);
    font-family: var(--font-primary);
    font-size: 16px;
    line-height: 1.375;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#blazor-error-ui {
    display: none;
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--dc-scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background-color: var(--dc-scrollbar-thumb);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--dc-bg-floating);
}

a {
    color: var(--dc-text-link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button {
    font-family: var(--font-primary);
    cursor: pointer;
    border: none;
}

input, textarea {
    font-family: var(--font-primary);
}

/* ── Focus ─────────────────────────────────────────────────────────────────
   One ring, globally. `button` and `input, textarea` used to carry
   `outline: none` with no replacement, which left keyboard users with no
   visible focus anywhere in the app. Suppress the ring for pointer focus
   only (:focus:not(:focus-visible)); never add `outline: none` without a
   :focus-visible rule beside it. */

:focus-visible {
    outline: 2px solid var(--dc-brand);
    outline-offset: 3px;
    border-radius: var(--r-xs);
}

:focus:not(:focus-visible) {
    outline: none;
}

/* ── Motion ────────────────────────────────────────────────────────────────
   No blanket `* { animation: none !important }` reset here: this codebase
   bans !important, and without it a `*` rule loses to every class selector,
   which would look like an opt-out while doing nothing. Reduced motion is
   therefore honoured where the animation is declared — the rules below cover
   what app.css itself animates, and each *.razor.css with @keyframes carries
   its own block beside them. */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .lk-tile-backdrop {
        animation: none;
    }

    .lk-tile-hover-controls,
    .lk-tile-btn,
    .lk-tile-close {
        transition: none;
    }

    .lk-tile-btn:active {
        transform: none;
    }
}

/* ── Error boundary overlay ──────────────────────────────────────────────── */

.haven-error-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(4px);
}

.haven-error-box {
    background: var(--dc-bg-secondary-alt);
    border: 1px solid var(--dc-red);
    border-radius: 12px;
    padding: 32px 36px;
    max-width: 480px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.haven-error-icon {
    font-size: 48px;
    color: var(--dc-red);
    line-height: 1;
}

.haven-error-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--dc-on-accent);
}

.haven-error-msg {
    margin: 0;
    font-size: 14px;
    color: var(--dc-text-muted);
    line-height: 1.5;
}

.haven-error-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.haven-error-btn-primary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 20px;
    border-radius: 6px;
    background: var(--dc-brand);
    color: var(--dc-on-accent);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s;
}

.haven-error-btn-primary:hover { background: var(--dc-brand-hover); }

.haven-error-btn-secondary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 20px;
    border-radius: 6px;
    background: var(--dc-bg-secondary-alt);
    color: var(--dc-text-normal);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--dc-separator);
    transition: background .15s;
}

.haven-error-btn-secondary:hover { background: var(--dc-bg-modifier-hover); }

.haven-error-details {
    width: 100%;
    text-align: left;
}

.haven-error-details summary {
    font-size: 12px;
    color: var(--dc-text-muted);
    cursor: pointer;
    user-select: none;
    margin-bottom: 6px;
}

.haven-error-details pre {
    margin: 0;
    font-size: 11px;
    color: var(--dc-red);
    background: var(--dc-bg-floating);
    border-radius: 6px;
    padding: 10px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ===== LIVEKIT CALL VIEW ─────────────────────────────────────────────────
   Global (not Blazor-scoped) on purpose: the elements below (.lk-tile and
   everything inside it, plus the theater backdrop appended to <body>) are
   created by wwwroot/js/livekit-voice.js via document.createElement, not
   rendered by a .razor component — so they never carry Blazor's CSS
   isolation scope attribute and scoped rules in Chat.razor.css would never
   match them. #lk-stage itself is Blazor-rendered, but is included here too
   so the spotlight layout rule (which reaches from .call-view down through
   .lk-stage into .lk-tile) doesn't get split across two files. ===== */

.lk-stage {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    padding: 16px;
    overflow: auto;
}
.lk-stage:empty { display: none; }

.lk-tile {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    /* Letterbox behind object-fit: contain video — true black, not a surface. */
    background: black;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.lk-tile video {
    display: block;
    max-height: 64vh;
    max-width: 100%;
    object-fit: contain;
    background: black;
}
.lk-tile.lk-screen { border-color: rgba(35, 165, 90, 0.55); }

/* Streamer's name, overlaid bottom-right of the preview */
.lk-tile-label {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
    color: var(--dc-on-accent);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.1px;
    pointer-events: none;
}
.lk-tile-label i { color: var(--dc-green); font-size: 13px; }

/* Hover controls — small icon buttons, top-right, fade in on hover
   (Discord-style: subtle, icon-only, not a big text overlay). */
.lk-tile-hover-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 3;
    display: flex;
    gap: 8px;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.lk-tile:hover .lk-tile-hover-controls,
.lk-tile.lk-expanded .lk-tile-hover-controls {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.lk-tile.lk-expanded .lk-tile-hover-controls { top: 54px; } /* clear the close button */

.lk-tile-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: var(--dc-on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: background-color 0.15s, transform 0.1s;
}
.lk-tile-btn:hover { background: rgba(0, 0, 0, 0.85); }
.lk-tile-btn:active { transform: scale(0.92); }

.lk-tile:fullscreen video { max-height: 100%; max-width: 100%; }

/* "Larger preview" — an in-app theater overlay (no OS fullscreen involved) */
.lk-tile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2500;
    background: rgba(0, 0, 0, 0.78);
    animation: lkBackdropIn 0.15s ease;
}
@keyframes lkBackdropIn { from { opacity: 0; } to { opacity: 1; } }

.lk-tile.lk-expanded {
    position: fixed;
    inset: 48px;
    z-index: 2501;
    max-width: none;
    flex: none;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.lk-tile.lk-expanded video {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
}

.lk-tile-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 4;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: var(--dc-on-accent);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    transition: background-color 0.15s;
}
.lk-tile.lk-expanded .lk-tile-close { display: flex; }
.lk-tile-close:hover { background: var(--dc-red); }

/* Spotlight layout: when a screen/camera share is active, give it most of the
   space and shrink the participant grid into a compact strip (Discord-style). */
.call-view:has(.lk-stage:not(:empty)) {
    flex-direction: column;
}
.call-view:has(.lk-stage:not(:empty)) .lk-stage {
    flex: 1 1 0;
    min-height: 0;
    flex-wrap: nowrap;
    align-items: stretch;
}
.call-view:has(.lk-stage:not(:empty)) .lk-tile {
    flex: 1 1 480px;
    max-width: 100%;
    min-height: 0;
}
.call-view:has(.lk-stage:not(:empty)) .lk-tile video {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
}
.call-view:has(.lk-stage:not(:empty)) .call-participants {
    flex: 0 0 auto;
    max-height: 116px;
    padding: 10px 16px;
    gap: 10px;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.call-view:has(.lk-stage:not(:empty)) .call-tile {
    flex-shrink: 0;
    width: 84px;
    padding: 10px 6px;
    gap: 6px;
}
.call-view:has(.lk-stage:not(:empty)) .call-tile-avatar {
    width: 48px;
    height: 48px;
    font-size: 18px;
}
.call-view:has(.lk-stage:not(:empty)) .call-tile-name {
    font-size: 11px;
    max-width: 72px;
}
