@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
    /* ── Haven "Deep Space" palette ─────────────────────── */
    --dc-bg-primary: #101827;
    --dc-bg-secondary: #0c1220;
    --dc-bg-tertiary: #080e18;
    --dc-bg-secondary-alt: #0e1624;
    --dc-bg-floating: #060a12;
    --dc-bg-modifier-hover: rgba(100,170,255,0.07);
    --dc-bg-modifier-selected: rgba(100,170,255,0.13);
    --dc-bg-modifier-active: rgba(100,170,255,0.18);
    --dc-header-primary: #e6edf6;
    --dc-header-secondary: #8da2ba;
    --dc-text-normal: #c9d4e2;
    --dc-text-muted: #5a7394;
    --dc-text-link: #5cb8ff;
    --dc-interactive-normal: #8da2ba;
    --dc-interactive-hover: #c9d4e2;
    --dc-interactive-active: #e6edf6;
    --dc-brand: #4a9eff;
    --dc-brand-hover: #3580d9;
    --dc-brand-active: #2968b5;
    --dc-green: #23a55a;
    --dc-red: #f23f42;
    --dc-yellow: #f0b232;
    --dc-input-bg: #0a1019;
    --dc-input-placeholder: #4a6580;
    --dc-channeltextarea-bg: #141e2e;
    --dc-scrollbar-thumb: #0f1a28;
    --dc-scrollbar-track: transparent;
    --dc-separator: rgba(80,150,255,0.08);
    --dc-blurple: #4a9eff;
    --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;
}

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: #0d0d0e;
}

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

a:hover {
    text-decoration: underline;
}

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

input, textarea {
    font-family: var(--font-primary);
    outline: 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: #1e2030;
    border: 1px solid #ed4245;
    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: #ed4245;
    line-height: 1;
}

.haven-error-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
}

.haven-error-msg {
    margin: 0;
    font-size: 14px;
    color: #b9bbbe;
    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: #5865f2;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s;
}

.haven-error-btn-primary:hover { background: #4752c4; }

.haven-error-btn-secondary {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 20px;
    border-radius: 6px;
    background: #2c2f3b;
    color: #dcddde;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid #3a3d4d;
    transition: background .15s;
}

.haven-error-btn-secondary:hover { background: #3a3d4d; }

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

.haven-error-details summary {
    font-size: 12px;
    color: #72767d;
    cursor: pointer;
    user-select: none;
    margin-bottom: 6px;
}

.haven-error-details pre {
    margin: 0;
    font-size: 11px;
    color: #ed4245;
    background: #111318;
    border-radius: 6px;
    padding: 10px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ═══════════════════════════ MOBILE: modals & panels (≤768px) ═══════════════════════════ */
@media (max-width: 768px) {
    /* Centered modals shrink to fit the viewport */
    .asm-modal, .cl-modal, .ks-modal, .psm-modal, .mb-sprint-modal, .upc-card {
        width: calc(100vw - 20px) !important;
        max-width: calc(100vw - 20px) !important;
        max-height: calc(100vh - 32px) !important;
        overflow-y: auto !important;
    }

    /* Board card detail modal: stack its two panes */
    .pb-modal {
        width: calc(100vw - 14px) !important;
        max-width: calc(100vw - 14px) !important;
        max-height: calc(100vh - 20px) !important;
    }
    .pb-modal-body { flex-direction: column !important; }
    .pb-modal-sidebar { width: 100% !important; }

    /* User Settings: full-screen, nav becomes a horizontal strip on top */
    .us-overlay { flex-direction: column !important; }
    .us-sidebar {
        width: 100% !important;
        flex: 0 0 auto !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        gap: 4px;
    }
    .us-content { width: 100% !important; min-width: 0 !important; }

    /* Server Settings: same stacking treatment */
    .ssm-layout {
        flex-direction: column !important;
        width: calc(100vw - 14px) !important;
        max-width: calc(100vw - 14px) !important;
        max-height: calc(100vh - 20px) !important;
    }
    .ssm-sidebar {
        width: 100% !important;
        flex: 0 0 auto !important;
        flex-direction: row !important;
        overflow-x: auto !important;
    }
}

/* ===== 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;
    background: #000;
    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: #000;
}
.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: #fff;
    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: #fff;
    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: #fff;
    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;
}
