/* ============================================================
   SORYN — "Refined Crimson" theme layer
   A single shared stylesheet injected into every page after the
   page's own CSS. It re-skins the existing markup without touching
   any feature, route, or script. Remove the <link> injection in
   server.js (serveHtmlWithBase) to fully revert.
   ============================================================ */

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

:root {
    /* Surfaces — layered near-blacks with a faint cool cast */
    --bg-0: #0a0a0d;   /* app base */
    --bg-1: #101014;   /* panels / cards */
    --bg-2: #16161c;   /* inputs / nested surfaces */
    --bg-3: #1d1d25;   /* hover / elevated */

    /* Hairlines */
    --line:        rgba(255, 255, 255, 0.07);
    --line-strong: rgba(255, 255, 255, 0.12);

    /* Text */
    --text-hi: #f3f3f6;
    --text:    #b6b7c2;
    --text-lo: #76777f;
    --text-faint: #54555d;

    /* Brand crimson ramp (kept faithful to #960822, extended for screens) */
    --crimson-deep:   #960822;  /* original brand */
    --crimson:        #c11233;
    --crimson-bright: #e63657;
    --crimson-glow:   rgba(214, 31, 67, 0.40);

    /* Status accents */
    --green:  #2fd07a;
    --blue:   #4d8dff;
    --purple: #b06bff;
    --amber:  #f0b13b;

    --radius:    14px;
    --radius-sm: 10px;
    --shadow-1: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-2: 0 8px 24px -8px rgba(0,0,0,0.6), 0 2px 8px -2px rgba(0,0,0,0.5);
    --shadow-pop: 0 18px 50px -12px rgba(0,0,0,0.8);
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- Global typography & base ---------- */
html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    background-color: var(--bg-0) !important;
    color: var(--text) !important;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    letter-spacing: -0.005em;
}

/* Kill the "everything is 700" monotony: body copy settles to a calm
   weight, while structural elements opt back into bold below. */
body, p, span, li, td, label, input, textarea, select, button, a, div {
    font-weight: 450;
}

/* Display face for headings & section titles */
h1, h2, h3,
.welcome-title, .welcome-subtitle, .section-title, .card-title,
.brand-name, .news-title, .settings-title, .page-title, .stat-value {
    font-family: 'Space Grotesk', 'Inter', sans-serif !important;
    letter-spacing: -0.02em;
}

/* ---------- Signature: ambient crimson aurora ---------- */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(60% 50% at 12% -5%, rgba(193, 18, 51, 0.16), transparent 60%),
        radial-gradient(45% 45% at 105% 8%, rgba(150, 8, 34, 0.12), transparent 55%),
        radial-gradient(70% 60% at 85% 110%, rgba(120, 10, 40, 0.10), transparent 60%);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    background-color: rgba(10, 10, 13, 0.82) !important;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-right: 1px solid var(--line) !important;
}

.sidebar-header { border-bottom: 1px solid var(--line) !important; padding: 22px 20px !important; }

.sidebar-title {
    color: var(--text-hi) !important;
    font-size: 17px !important;
    letter-spacing: -0.03em !important;
}

.sidebar-logo { filter: drop-shadow(0 2px 8px var(--crimson-glow)); }

.nav-section { border-top: 1px solid var(--line) !important; }
.nav-section-title { color: var(--text-faint) !important; font-weight: 600 !important; letter-spacing: 1.4px !important; }

.nav-link {
    color: var(--text-lo) !important;
    font-weight: 500 !important;
    border-radius: var(--radius-sm) !important;
    position: relative;
    transition: color .18s var(--ease), background-color .18s var(--ease) !important;
}

.nav-link:hover {
    background-color: var(--bg-2) !important;
    color: var(--text-hi) !important;
}

/* Active item: crimson rail + tinted surface, no harsh outline */
.nav-link.active {
    background: linear-gradient(90deg, rgba(193,18,51,0.16), rgba(193,18,51,0.04)) !important;
    border: 1px solid transparent !important;
    color: #ff5e79 !important;
    box-shadow: inset 0 0 0 1px rgba(230, 54, 87, 0.18);
}
.nav-link.active::before {
    content: "";
    position: absolute;
    left: 0; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 18px;
    border-radius: 0 3px 3px 0;
    background: var(--crimson-bright);
    box-shadow: 0 0 10px var(--crimson-glow);
}
.nav-link.active svg { color: #ff5e79 !important; }

/* ---------- Sidebar footer ---------- */
.sidebar-footer { border-top: 1px solid var(--line) !important; }
.footer-username { color: var(--text-hi) !important; font-weight: 600 !important; }
.footer-content, .footer-status { font-weight: 500 !important; }

.logout-button:hover, .admin-panel-button:hover,
.notification-button:hover, .theme-toggle:hover, .arrow-icon:hover,
.inbox-close:hover, .inbox-notif-dismiss:hover {
    color: var(--crimson-bright) !important;
}

/* ============================================================
   MAIN CONTENT / HEADINGS
   ============================================================ */
.welcome-title { color: var(--text-lo) !important; letter-spacing: 2.5px !important; font-weight: 600 !important; }
.welcome-subtitle { color: var(--text-hi) !important; font-size: 34px !important; font-weight: 600 !important; }
.welcome-subtitle span { color: var(--crimson-bright) !important; }
.welcome-description { color: var(--text) !important; font-weight: 450 !important; font-size: 15px !important; }

.section-title { color: var(--text-hi) !important; font-weight: 600 !important; }
.section-title svg { color: var(--crimson-bright) !important; }
.section-header { border-bottom: 1px solid var(--line) !important; }

/* ============================================================
   CARDS / PANELS  — soft realistic depth, no red glow
   ============================================================ */
.card,
.dashboard-section,
.settings-card,
.stat-card,
.news-item,
.faq-item,
.modal-body,
.twofa-setup-form,
.warning-box,
.download-card,
.resource-card {
    background-color: var(--bg-1) !important;
    border: 1px solid var(--line) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-2) !important;
}

/* Quiet hover: lift + hairline brighten, crimson stays a whisper */
.card:hover,
.dashboard-section:hover,
.stat-card:hover,
.news-item:hover,
.resource-card:hover,
.download-card:hover {
    background-color: var(--bg-1) !important;
    border-color: var(--line-strong) !important;
    box-shadow: var(--shadow-pop) !important;
    transform: translateY(-2px);
    transition: transform .25s var(--ease), border-color .25s var(--ease), box-shadow .25s var(--ease) !important;
}

.card-title, .news-title { color: var(--text-hi) !important; font-weight: 600 !important; }
.card-description, .news-content { color: var(--text) !important; font-weight: 450 !important; }
.card-icon { background-color: var(--bg-2) !important; color: var(--crimson-bright) !important; border-radius: var(--radius-sm) !important; }

.stat-value { color: var(--crimson-bright) !important; font-weight: 700 !important; }
.stat-label { color: var(--text-lo) !important; font-weight: 500 !important; }
.stat-card { text-align: center; }

/* News meta */
.news-date, .news-author-label { color: var(--text-lo) !important; font-weight: 500 !important; }
.news-author-name { color: var(--crimson-bright) !important; }
.news-item { background-color: var(--bg-2) !important; }
.news-item:hover { transform: none; border-color: var(--crimson) !important; }

/* ============================================================
   BUTTONS
   ============================================================ */
.primary-button,
.sign-in-button,
.chat-send-button,
.news-create-button,
.download-button,
.settings-button.primary-button,
.submit-button {
    background: linear-gradient(180deg, var(--crimson) 0%, var(--crimson-deep) 100%) !important;
    border: 1px solid rgba(255,255,255,0.08) !important;
    color: #fff !important;
    font-weight: 600 !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: 0 1px 0 rgba(255,255,255,0.12) inset, var(--shadow-1) !important;
    transition: filter .18s var(--ease), transform .12s var(--ease), box-shadow .18s var(--ease) !important;
}

.primary-button:hover:not(:disabled),
.sign-in-button:hover:not(:disabled),
.chat-send-button:hover:not(:disabled),
.news-create-button:hover:not(:disabled),
.download-button:hover:not(:disabled),
.submit-button:hover:not(:disabled) {
    filter: brightness(1.12) !important;
    box-shadow: 0 1px 0 rgba(255,255,255,0.14) inset, 0 6px 18px -6px var(--crimson-glow) !important;
    transform: translateY(-1px);
}

.primary-button:active:not(:disabled),
.sign-in-button:active:not(:disabled) { transform: translateY(0); filter: brightness(0.98) !important; }

.secondary-button,
.settings-button.secondary-button,
.cancel-button {
    background-color: var(--bg-2) !important;
    border: 1px solid var(--line-strong) !important;
    color: var(--text-hi) !important;
    font-weight: 500 !important;
    border-radius: var(--radius-sm) !important;
    transition: background-color .18s var(--ease), border-color .18s var(--ease) !important;
}
.secondary-button:hover:not(:disabled),
.settings-button.secondary-button:hover:not(:disabled),
.cancel-button:hover:not(:disabled) {
    background-color: var(--bg-3) !important;
    border-color: var(--line-strong) !important;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-input, .chat-input, .form-textarea, textarea, select {
    background-color: var(--bg-2) !important;
    border: 1px solid var(--line) !important;
    color: var(--text-hi) !important;
    border-radius: var(--radius-sm) !important;
    font-weight: 450 !important;
    transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background-color .18s var(--ease) !important;
}
.form-input::placeholder, .chat-input::placeholder, textarea::placeholder { color: var(--text-faint) !important; }

.form-input:focus, .chat-input:focus, .form-textarea:focus, textarea:focus, select:focus {
    border-color: var(--crimson) !important;
    background-color: var(--bg-1) !important;
    box-shadow: 0 0 0 3px rgba(193, 18, 51, 0.18) !important;
    outline: none !important;
}
.form-label, .form-group label { color: var(--text) !important; font-weight: 500 !important; }

/* ============================================================
   CHAT
   ============================================================ */
.chat-messages { background-color: var(--bg-0) !important; border: 1px solid var(--line) !important; border-radius: var(--radius-sm) !important; }
.message-text {
    background-color: var(--bg-2) !important;
    border: 1px solid var(--line) !important;
    color: var(--text-hi) !important;
    font-weight: 450 !important;
    border-radius: 12px !important;
}
.chat-message.user .message-text {
    background: linear-gradient(180deg, rgba(193,18,51,0.22), rgba(150,8,34,0.16)) !important;
    border-color: rgba(230,54,87,0.35) !important;
}
.chat-message.system .message-text,
.chat-message.system-message .message-text {
    background-color: var(--bg-1) !important;
    border: 1px solid var(--line) !important;
    color: var(--text-lo) !important;
}
.message-username { color: var(--text-hi) !important; }
.online-indicator { background-color: var(--green) !important; box-shadow: 0 0 8px rgba(47,208,122,0.6); }

/* Role tags keep their semantic colors but read crisper */
.owner-tag { color: var(--crimson-bright) !important; }
.admin-tag { color: var(--blue) !important; }
.reseller-tag { color: var(--purple) !important; }
.paid-tag { color: var(--green) !important; }

/* ============================================================
   STATUS PILLS  (sidebar footer + badges)
   ============================================================ */
.status-value.status-paid { color: var(--green) !important; }
.status-value.status-owner { color: var(--crimson-bright) !important; }
.status-value.status-admin { color: var(--blue) !important; }
.status-value.status-reseller { color: var(--purple) !important; }

/* ============================================================
   MODALS / POPOVERS / TOOLTIPS
   ============================================================ */
.modal-content, .online-users-tooltip, .message-menu, .inbox-panel {
    background-color: var(--bg-1) !important;
    border: 1px solid var(--line-strong) !important;
    border-radius: var(--radius) !important;
    box-shadow: var(--shadow-pop) !important;
}
.modal-header, .inbox-header { border-bottom: 1px solid var(--line) !important; }
.tooltip-category-title { color: var(--crimson-bright) !important; }

/* ============================================================
   LOGIN / REGISTER
   ============================================================ */
.login-card, .register-card {
    background-color: rgba(16, 16, 20, 0.7) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--line-strong) !important;
    border-radius: 18px !important;
    box-shadow: var(--shadow-pop) !important;
}
.brand-name { color: var(--text-hi) !important; font-weight: 700 !important; letter-spacing: -0.03em !important; }
.brand-subtitle { color: var(--crimson-bright) !important; font-weight: 500 !important; letter-spacing: 3px !important; text-transform: uppercase; }
.logo { filter: drop-shadow(0 4px 20px var(--crimson-glow)); }

/* ============================================================
   LINKS & MISC ACCENTS
   ============================================================ */
a.card-link-text, .news-create-button, .inbox-notif-link { color: var(--crimson-bright) !important; }
a.card-link-text:hover { color: #ff7d93 !important; }

/* Footer copyright bar that several pages hardcode */
body > footer { border-top: 1px solid var(--line) !important; color: var(--text-faint) !important; }

/* ============================================================
   SCROLLBARS — slimmer, calmer
   ============================================================ */
* { scrollbar-width: thin; scrollbar-color: rgba(193,18,51,0.5) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: rgba(193, 18, 51, 0.45);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(230, 54, 87, 0.7); background-clip: padding-box; }

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
a:focus-visible, button:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--crimson-bright);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .card:hover, .dashboard-section:hover, .stat-card:hover { transform: none; }
}

/* ============================================================
   MOBILE NAVIGATION — hamburger drawer (paired with mobile-nav.js)
   The toggle button and overlay are created by the script; these
   rules show them only on small screens and slide the sidebar in.
   ============================================================ */
.mobile-nav-toggle { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 768px) {
    /* Never let the page scroll/zoom sideways — this is what caused the
       "everything shrunk and clipped on both edges" look on Download/Settings. */
    html, body {
        overflow-x: hidden !important;
        max-width: 100% !important;
    }

    .mobile-nav-toggle {
        display: flex;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 1200;
        width: 44px;
        height: 44px;
        align-items: center;
        justify-content: center;
        background: rgba(16, 16, 20, 0.92);
        border: 1px solid var(--line-strong);
        border-radius: 12px;
        color: var(--text-hi);
        cursor: pointer;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        box-shadow: var(--shadow-2);
        transition: transform 0.12s var(--ease), border-color 0.18s var(--ease);
    }
    .mobile-nav-toggle:active { transform: scale(0.94); }
    .mobile-nav-toggle:hover { border-color: var(--crimson); }

    /* Drawer pinned to the VISIBLE viewport (dvh accounts for the browser
       address bar) so the footer actions stay reachable. Off-canvas until open. */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        width: 286px !important;
        max-width: 86vw !important;
        transform: translateX(-100%);
        transition: transform 0.28s var(--ease) !important;
        z-index: 1100 !important;
        overflow: hidden !important; /* only the nav list scrolls (below) */
    }
    .sidebar.is-open { transform: translateX(0) !important; }

    /* Let the nav list scroll while header + footer stay pinned, so the
       admin / inbox / logout buttons are always visible. */
    .sidebar-nav {
        min-height: 0 !important;
        overflow-y: auto !important;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1050;
        background: rgba(0, 0, 0, 0.55);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s var(--ease), visibility 0.25s var(--ease);
    }
    .sidebar-overlay.visible { opacity: 1; visibility: visible; }

    /* Lock the page behind the open drawer (set by mobile-nav.js) */
    body.nav-open { overflow: hidden !important; }

    /* Page-level wrappers: full width, no leftover sidebar gutter, and room
       for the fixed hamburger. Covers both layout patterns in the app. */
    .main-content,
    .content-wrapper {
        margin-left: 0 !important;
        max-width: 100% !important;
        width: auto !important;
    }
    .main-content { padding-top: 64px !important; }
    .content-wrapper { padding-top: 64px !important; }

    /* Download page: stack the download card and status panel vertically.
       Here .main-content is an inner card, so cancel the top padding. */
    .cards-row { flex-direction: column !important; }
    .cards-row .main-content { padding-top: 0 !important; }
    .right-sidebar { width: 100% !important; }

    /* Keep every panel inside the viewport so flex/grid children wrap instead
       of forcing the page wider (fixes the Settings role pills overflowing). */
    .card, .dashboard-section, .settings-card, .account-info-card,
    .tab-content, .stat-card, .thread-card, .roles-container {
        max-width: 100% !important;
    }
}
