/* ==========================================================================
   Site shell: typography, accessibility tools, public header, staff sidebar.
   Loaded after app.css so it can refine the base styles without touching page CSS.
   ========================================================================== */

:root {
    --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --sidebar-w: 268px;
    --sidebar-w-collapsed: 76px;
    --sidebar-bg: #0c1a2e;
    --sidebar-bg-hover: rgba(255, 255, 255, 0.06);
    --sidebar-bg-active: rgba(255, 255, 255, 0.1);
    --sidebar-text: #b9c4d6;
    --sidebar-text-strong: #ffffff;
    --topbar-h: 60px;
    --focus: #1d4ed8;
}

body,
input, button, select, textarea {
    font-family: var(--font);
}

body {
    font-feature-settings: "ss01", "cv11";
    text-rendering: optimizeLegibility;
}

h1, h2, h3 { letter-spacing: -0.015em; }

/* ---- Accessibility: text size (levels chosen with the A / A+ / A++ buttons) ---- */
html[data-text-size="lg"] { zoom: 1.12; }
html[data-text-size="xl"] { zoom: 1.26; }

.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;
}

.skip-link {
    position: absolute;
    left: 12px;
    top: -60px;
    background: var(--navy);
    color: #fff;
    padding: 10px 16px;
    border-radius: 0 0 8px 8px;
    font-weight: 600;
    text-decoration: none;
    z-index: 1000;
    transition: top 0.15s ease;
}
.skip-link:focus { top: 0; }

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---- Tools: text size + language ---- */
.tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

.text-size {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.text-size button {
    border: 0;
    background: transparent;
    color: #475569;
    font-weight: 700;
    cursor: pointer;
    min-width: 36px;
    height: 34px;
    padding: 0 8px;
    line-height: 1;
}
.text-size button + button { border-left: 1px solid var(--border); }
.text-size button:hover { background: #f1f5f9; }
.text-size button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.text-size .ts-1 { font-size: 0.8rem; }
.text-size .ts-2 { font-size: 0.95rem; }
.text-size .ts-3 { font-size: 1.1rem; }

.lang-picker { position: relative; display: inline-flex; align-items: center; }
.lang-picker svg { position: absolute; left: 9px; pointer-events: none; color: #475569; }
.lang-picker select {
    appearance: none;
    -webkit-appearance: none;
    height: 36px;
    padding: 0 12px 0 32px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: #334155;
    font-size: 0.86rem;
    font-weight: 600;
    cursor: pointer;
    width: auto;
}

/* ---- Public header: brand on the left, navigation and actions on the right ---- */
.site-header .header-inner {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 18px;
    min-height: 68px;
}

.site-header .brand { flex-shrink: 0; }
.site-header .brand-title { font-size: 1.15rem; font-weight: 800; letter-spacing: 0.01em; }

.site-header .nav-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin-left: 0;
}

.site-header .nav-links { margin-left: auto; }
.site-header .nav-item { font-size: 0.92rem; font-weight: 600; padding: 8px 12px; }
.site-header .nav-actions { margin-left: 8px; gap: 10px; }
.site-header .nav-divider { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }

.btn-join { transform: none; box-shadow: 0 2px 8px rgba(197, 155, 39, 0.28); }

.mobile-toggle { margin-left: auto; }

@media (max-width: 1020px) {
    .site-header .header-inner { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
    .site-header .brand { min-width: 0; flex: 1 1 auto; }
    .site-header .brand-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .mobile-toggle { flex: 0 0 auto; }
    .mobile-toggle { display: flex; }

    .site-header .nav-container {
        display: none;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 12px 0 8px;
        border-top: 1px solid var(--border);
    }
    .site-header .nav-container.open { display: flex; }
    .site-header .nav-links { flex-direction: column; align-items: stretch; margin: 0; }
    .site-header .nav-item { padding: 12px 14px; font-size: 1rem; }
    .site-header .nav-actions { flex-wrap: wrap; margin: 0; }
    .site-header .nav-divider { display: none; }
}

/* ---- Footer ---- */
.site-footer .footer-links a { color: #cbd5e1; text-decoration: none; margin-right: 16px; }
.site-footer .footer-links a:hover { color: #fff; text-decoration: underline; }
.site-footer .credit a { color: #e2e8f0; font-weight: 600; text-decoration: none; }
.site-footer .credit a:hover { text-decoration: underline; }

/* ==========================================================================
   Staff shell: sidebar + top bar
   ========================================================================== */

body.has-sidebar { background: #f4f6fa; }

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100vh;
}
html.sidebar-collapsed .app-shell { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 60;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px;
    text-decoration: none;
    color: var(--sidebar-text-strong);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    min-height: var(--topbar-h);
}
.sidebar-brand img { height: 38px; width: auto; background: #fff; border-radius: 8px; padding: 3px; flex-shrink: 0; }
.sidebar-brand .name { font-weight: 800; font-size: 0.9rem; letter-spacing: 0.01em; line-height: 1.15; white-space: nowrap; }
.sidebar-brand .text { min-width: 0; }
.sidebar-brand .region { font-size: 0.74rem; color: #8fa1bb; font-weight: 500; }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 14px 12px 8px; scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.15) transparent; }

.nav-group + .nav-group { margin-top: 18px; }
.nav-group-title {
    padding: 0 12px 6px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #7385a1;
    white-space: nowrap;
}

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 42px;
    padding: 0 12px;
    margin-bottom: 2px;
    border-radius: 9px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 600;
    position: relative;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
}
.side-link svg { flex-shrink: 0; width: 19px; height: 19px; opacity: 0.85; }
.side-link:hover { background: var(--sidebar-bg-hover); color: var(--sidebar-text-strong); }
.side-link.active { background: var(--sidebar-bg-active); color: var(--sidebar-text-strong); }
.side-link.active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 9px;
    bottom: 9px;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--gold);
}
.side-link.active svg { opacity: 1; color: var(--gold); }
.side-link .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.side-badge {
    background: var(--gold);
    color: #0a1320;
    font-size: 0.72rem;
    font-weight: 800;
    min-width: 22px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.side-user { display: flex; align-items: center; gap: 12px; padding: 8px 8px 12px; }
.side-user .avatar {
    width: 38px; height: 38px; border-radius: 10px; background: var(--gold); color: #0a1320;
    display: flex; align-items: center; justify-content: center; font-weight: 800; flex-shrink: 0;
}
.side-user .who { min-width: 0; }
.side-user .who strong { display: block; color: #fff; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .who span { display: block; font-size: 0.74rem; color: #8fa1bb; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-signout {
    width: 100%;
    display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px;
    border-radius: 9px; border: 1px solid rgba(255, 255, 255, 0.14); background: transparent;
    color: var(--sidebar-text); font-size: 0.88rem; font-weight: 600; cursor: pointer;
}
.side-signout:hover { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }
.side-signout svg { width: 18px; height: 18px; }

/* Collapsed (icons only) */
html.sidebar-collapsed .sidebar-brand .text,
html.sidebar-collapsed .side-link .label,
html.sidebar-collapsed .nav-group-title,
html.sidebar-collapsed .side-user .who,
html.sidebar-collapsed .side-signout .label { display: none; }
html.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 18px 0; }
html.sidebar-collapsed .side-link { justify-content: center; padding: 0; }
html.sidebar-collapsed .side-link .side-badge { position: absolute; top: 3px; right: 6px; min-width: 18px; height: 18px; font-size: 0.64rem; padding: 0 4px; }
html.sidebar-collapsed .side-user { justify-content: center; padding: 8px 0 12px; }
html.sidebar-collapsed .side-signout { justify-content: center; padding: 0; }
html.sidebar-collapsed .nav-group + .nav-group { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255, 255, 255, 0.07); }

/* Top bar */
.app-main { min-width: 0; display: flex; flex-direction: column; }

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 clamp(16px, 2.5vw, 32px);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.icon-btn {
    width: 38px; height: 38px; border-radius: 9px; border: 1px solid var(--border); background: #fff;
    display: inline-flex; align-items: center; justify-content: center; color: #475569; cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: #f1f5f9; color: #0f172a; }
.icon-btn svg { width: 19px; height: 19px; }
.topbar-toggle-mobile { display: none; }

.topbar-context { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar-context strong { font-size: 0.95rem; color: #0f172a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-context span { font-size: 0.76rem; color: var(--text-muted); }
.topbar-spacer { flex: 1; }

.app-content {
    padding: clamp(20px, 3vw, 36px) clamp(16px, 3vw, 40px) 80px;
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    flex: 1;
}

.app-footer {
    padding: 16px clamp(16px, 3vw, 40px);
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}
.app-footer a { color: #334155; font-weight: 600; text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

.sidebar-backdrop { display: none; }

@media (max-width: 960px) {
    .app-shell, html.sidebar-collapsed .app-shell { grid-template-columns: minmax(0, 1fr); }

    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        width: min(300px, 86vw);
        transform: translateX(-102%);
        transition: transform 0.22s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open { overflow: hidden; }

    /* The collapsed (icon-only) state never applies to the mobile drawer. */
    html.sidebar-collapsed .sidebar-brand .text,
    html.sidebar-collapsed .side-link .label,
    html.sidebar-collapsed .nav-group-title,
    html.sidebar-collapsed .side-user .who,
    html.sidebar-collapsed .side-signout .label { display: revert; }
    html.sidebar-collapsed .side-link { justify-content: flex-start; padding: 0 12px; }
    html.sidebar-collapsed .side-link .side-badge { position: static; min-width: 22px; height: 20px; font-size: 0.72rem; }
    html.sidebar-collapsed .sidebar-brand { justify-content: flex-start; padding: 18px 20px; }
    html.sidebar-collapsed .side-user, html.sidebar-collapsed .side-signout { justify-content: flex-start; }

    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(8, 15, 28, 0.55); z-index: 55; }
    body.sidebar-open .sidebar-backdrop { display: block; }

    .topbar-toggle-mobile { display: inline-flex; }
    .topbar-toggle-desktop { display: none; }
    .topbar-tools .text-size { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media print {
    .site-header, .site-footer, .sidebar, .app-topbar, .app-footer, .skip-link, .tools { display: none !important; }
    .app-shell { display: block; }
    html[data-text-size] { zoom: 1; }
}
