/* ============================================================
   LAYOUT OVERRIDE — Sidebar + Main Gap + Scroll Fix
   Loaded LAST → !important overrides everything
   ============================================================ */

/* ── SIDEBAR: compact, scrollable ── */
.sidebar {
    width: 220px !important;
    height: 100vh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    z-index: 200 !important;
    background: #030305 !important;
}
[data-theme="light"] .sidebar {
    background: #f8f9fb !important;
}

/* ── SIDEBAR SCROLL WRAPPER: must shrink ── */
.sidebar-scroll-wrapper {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

/* ── SIDEBAR SCROLL: the actual scrollable area ── */
.sidebar-scroll {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    overflow-y: scroll !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
}

/* Webkit scrollbar — hidden */
.sidebar-scroll::-webkit-scrollbar {
    width: 0 !important;
    display: none !important;
}

/* Kill any other sidebar scrollbar overrides */
.sidebar::-webkit-scrollbar {
    width: 0 !important;
    display: none !important;
}

/* ── MAIN CONTENT: tight against sidebar ── */
.main {
    margin-left: 220px !important;
    width: calc(100% - 220px) !important;
    padding: 0.5rem 1rem !important;
    height: 100vh !important;
    overflow-y: auto !important;
}
.main.full-width {
    margin-left: 0 !important;
    width: 100% !important;
}

/* ── HEADER: less vertical waste, reserved height prevents late-content CLS ── */
.header {
    margin-bottom: 0.75rem !important;
    min-height: 80px !important;
}

/* ── BODY: no overflow, flex layout ── */
body {
    height: 100vh !important;
    overflow: hidden !important;
    display: flex !important;
}

/* ── MOBILE (<768px): sidebar off-screen, main full ── */
@media (max-width: 767px) {
    .sidebar {
        width: 260px !important;
        transform: translateX(-100%) !important;
    }
    .sidebar.active {
        transform: translateX(0) !important;
        background: #030305 !important;
        z-index: 200 !important;
        box-shadow: 4px 0 30px rgba(0,0,0,0.7) !important;
    }
    .main {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 0.5rem !important;
        padding-bottom: 75px !important;
    }
}

/* ── TABLET (768-1023px) ── */
@media (min-width: 768px) and (max-width: 1023px) {
    .sidebar {
        width: 220px !important;
    }
    .main {
        margin-left: 220px !important;
        width: calc(100% - 220px) !important;
        padding: 0.5rem 1rem !important;
    }
}

/* ── CLS FIX: pre-apply sidebar-collapsed state before JS runs ── */
@media (min-width: 1024px) {
    html[data-sb-pre-col] .sidebar {
        width: 64px !important;
        min-width: 64px;
        overflow: visible;
    }
    html[data-sb-pre-col] .main {
        margin-left: 64px !important;
        width: calc(100% - 64px) !important;
    }
}

/* ── CLS FIX: remove main transition — prevents animated margin shifts registering as CLS ── */
.main {
    transition: none !important;
}

/* ── CLS FIX: pre-apply full-width for <1024px — matches what init-app.js does on DOMContentLoaded ── */
html[data-pre-fw] .sidebar {
    display: none !important;
}
html[data-pre-fw] .main {
    margin-left: 0 !important;
    width: 100% !important;
}

/* ── CLS FIX: date-badge reserved dimensions to prevent layout shift ── */
.date-badge {
    min-width: 190px;
    min-height: 38px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ── A11Y FIX: Skip-link — pure-CSS visibility on focus (no JS needed, Lighthouse-friendly) ── */
.skip-link {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    text-decoration: none;
}
.skip-link:focus,
.skip-link:focus-visible {
    position: fixed;
    top: 0;
    left: 0;
    width: auto;
    height: auto;
    padding: 0.5rem 1rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: var(--primary);
    color: #fff;
    font-family: var(--font-main);
    font-size: 0.875rem;
    font-weight: 600;
    z-index: 99999;
    border-radius: 0 0 8px 0;
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* ── A11Y FIX: Donut segment labels — full-opacity white for WCAG AA contrast ── */
.segment-label {
    color: #fff !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ── CLS FIX: Ghost-Mode overlays + PWA banner have their CSS only in body <style> tags.
       Without this rule they are in-flow flex items at first paint → push mainContent right.
       position:fixed removes them from the flex flow; display:none hides them visually.
       The .active / .visible class rules in the body <style> have higher specificity and
       correctly override these base rules when the features are activated. ── */
#ghostModeOverlay,
#ghostModeVSCode,
.pwa-install-banner {
    display: none;
    position: fixed;
}
