/**
 * Dashboard Shell — Sidebar + Topbar + Content Layout
 *
 * The shared layout shell for all coach dashboard pages.
 * Provides a collapsible sidebar (240px expanded, 64px collapsed),
 * a slim topbar with page title and actions, and a wide content area.
 *
 * Usage:
 *   <div class="dashboard-shell">
 *     <nav class="ds-sidebar" id="sidebar">...</nav>
 *     <div class="ds-content">
 *       <header class="ds-topbar">...</header>
 *       <main class="ds-main">...</main>
 *     </div>
 *   </div>
 *
 * JS: dashboard-shell.js handles toggle, persistence, mobile overlay.
 */

/* ============================================================================
   Shell Container
   ============================================================================ */

.dashboard-shell {
    display: flex;
    min-height: 100vh;
    background: var(--bg-base);
}

/* ============================================================================
   Sidebar
   ============================================================================ */

.ds-sidebar {
    width: var(--sidebar-width-expanded);
    min-width: var(--sidebar-width-expanded);
    background: var(--bg-chrome);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: var(--z-sidebar);
    transition: width 0.2s var(--ease-out), min-width 0.2s var(--ease-out);
    overflow: hidden;
}

/* Collapsed rail state */
.ds-sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
}

/* Hover-peek: the collapsed rail expands to full width as an OVERLAY when the
   coach hovers (or keyboard-focuses) it. Content does NOT reflow — `.ds-content`
   margin stays at the collapsed width because `.collapsed` is still present; the
   panel floats over the content with a shadow (the GitLab/Notion pattern). The
   `.peek` class is toggled by dashboard-shell.js with a ~400ms open / ~450ms
   close delay (hover intent) + on focus (a11y, WCAG 1.4.13 hoverable/focus).
   Desktop + true-hover devices only (touch keeps the hamburger drawer). */
@media (hover: hover) and (pointer: fine) {
    .ds-sidebar.collapsed.peek {
        width: var(--sidebar-width-expanded);
        min-width: var(--sidebar-width-expanded);
        box-shadow: 6px 0 28px rgba(0, 0, 0, 0.4);
    }
    /* Reveal everything the collapsed state hid — peek looks like expanded. */
    .ds-sidebar.collapsed.peek .ds-sidebar-brand-name,
    .ds-sidebar.collapsed.peek .ds-sidebar-coach-name,
    .ds-sidebar.collapsed.peek .ds-nav-label,
    .ds-sidebar.collapsed.peek .ds-nav-section-label {
        opacity: 1;
        width: auto;
    }
    /* Peek "looks like expanded", so fully undo the collapsed icon-rail
       treatment: restore the label's height/margin AND drop the icon-rail
       group-divider border-top (it's only meant for the hidden-label rail —
       in peek the label is visible, so the border reads as a stray white
       line floating above "MANAGE"). */
    .ds-sidebar.collapsed.peek .ds-nav-section-label {
        padding: 16px 12px 6px;
        height: auto;
        margin: 0;
        border-top: none;
    }
    .ds-sidebar.collapsed.peek .ds-nav-item { justify-content: flex-start; padding: 0 12px; }
    .ds-sidebar.collapsed.peek .ds-sidebar-brand { justify-content: flex-start; padding: 0 16px; }
    .ds-sidebar.collapsed.peek .ds-mode-toggle { padding: 3px; }
}

/* Respect reduced-motion: no width-slide on collapse/peek. */
@media (prefers-reduced-motion: reduce) {
    .ds-sidebar { transition: none; }
}

/* ---- Brand ---- */

.ds-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    min-height: var(--dashboard-header-height);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.ds-sidebar-logo {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
}

.ds-sidebar-brand-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
}

.ds-sidebar-coach-name {
    font-size: 13px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    margin-top: 2px;
}

.ds-sidebar.collapsed .ds-sidebar-brand-name,
.ds-sidebar.collapsed .ds-sidebar-coach-name {
    opacity: 0;
    width: 0;
}

.ds-sidebar.collapsed .ds-sidebar-brand {
    justify-content: center;
    padding: 16px 0;
}

/* ---- Mode Toggle (Student / Gym) ---- */

.ds-mode-toggle {
    display: flex;
    gap: 0;
    margin: 8px 8px 4px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid var(--border-subtle);
}

.ds-mode-btn {
    flex: 1;
    padding: 5px 8px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.ds-mode-btn.active {
    background: var(--accent, #3b82f6);
    color: white;
}

.ds-mode-btn:hover:not(.active) {
    color: var(--text-primary);
}

/* Hide the Student/Coach mode toggle ONLY in the pure collapsed icon-rail (a
   text toggle can't fit). It MUST reappear on hover-peek (and when pinned open)
   — otherwise a coach loses the only way to switch into the coach/gym view. */
.ds-sidebar.collapsed:not(.peek) .ds-mode-toggle {
    display: none;
}

/* ---- Navigation ---- */

.ds-sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
    overflow-x: hidden;
}

.ds-nav-section-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-quaternary);
    padding: 16px 12px 6px;
    white-space: nowrap;
    overflow: hidden;
}

.ds-sidebar.collapsed .ds-nav-section-label {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 8px 0 0;
    border-top: 1px solid var(--border-subtle);
}

.ds-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 40px;
    padding: 0 12px;
    border-radius: var(--nav-item-radius);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
}

.ds-nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.ds-nav-item.active {
    background: var(--nav-item-active-bg);
    color: var(--accent);
    /* 3px left-bar accent — Stripe/Linear/Notion convention for active nav.
       inset box-shadow avoids disturbing flex layout; sits inside the rounded
       border so the bar reads as part of the pill, not as overflow. Per
       /gu light-theme rules research (fix #6). */
    box-shadow: inset 3px 0 0 var(--accent);
}

.ds-nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke-width: 1.5;
}

.ds-nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.ds-sidebar.collapsed .ds-nav-label {
    opacity: 0;
    width: 0;
}

.ds-sidebar.collapsed .ds-nav-item {
    justify-content: center;
    padding: 0;
}

/* Unread badge on nav item (e.g., Messages) */
.ds-nav-badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--accent);
    color: var(--text-on-accent);
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ds-sidebar.collapsed .ds-nav-badge {
    position: absolute;
    top: 2px;
    right: 6px;
    margin-left: 0;
    min-width: 8px;
    height: 8px;
    padding: 0;
    font-size: 0;
}

/* ---- Bottom nav section (Account, pushed to bottom) ---- */

.ds-sidebar-bottom {
    padding: 8px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* ---- Sidebar Footer ---- */

.ds-sidebar-footer {
    padding: 8px;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

/* ---- Sidebar Toggle Button ---- */

.ds-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 36px;
    border-radius: var(--nav-item-radius);
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.ds-sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.ds-sidebar-toggle svg {
    width: 18px;
    height: 18px;
    transition: transform 0.2s var(--ease-out);
}

.ds-sidebar.collapsed .ds-sidebar-toggle svg {
    transform: rotate(180deg);
}

/* Nav-item hover tooltips were REMOVED entirely (owner decision 2026-06-18):
   every nav item shows its own text label (expanded + peek), and even the
   collapsed icon-rail doesn't want a hover tooltip — so the `data-tooltip`
   `::after` is intentionally not rendered in any state. The `data-tooltip`
   attribute is left on the markup (harmless, no CSS consumes it). */

/* ============================================================================
   Content Area
   ============================================================================ */

.ds-content {
    flex: 1;
    margin-left: var(--sidebar-width-expanded);
    min-width: 0;
    transition: margin-left 0.2s var(--ease-out);
    overflow-y: auto;
    height: 100vh;
}

.ds-sidebar.collapsed ~ .ds-content {
    margin-left: var(--sidebar-width-collapsed);
}

/* ---- Topbar ---- */

.ds-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--dashboard-header-height);
    padding: 0 var(--dashboard-padding);
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-base);
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
}

.ds-topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    /* Allow the left region (hamburger + title) to shrink so a long title
       truncates instead of pushing into the right-side icons. */
    flex: 1;
    min-width: 0;
}

.ds-topbar-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    margin: 0;
    /* Single-line + ellipsis: a long page title (e.g. the classroom-week
       "Greg Souders · Week 1: Single Leg, Guard Destabilization, Mount
       Pinning") must NOT wrap to multiple lines and overflow the fixed-height
       topbar into the icons on narrow viewports. min-width:0 lets this flex
       child shrink below its content width so text-overflow can engage. */
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ds-topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Mobile hamburger (hidden on desktop) */
.ds-mobile-hamburger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--nav-item-radius);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.ds-mobile-hamburger:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.ds-mobile-hamburger svg {
    width: 20px;
    height: 20px;
}

/* Touch feedback: remove the default blue tap-flash + add a pressed state so
   taps feel responsive on mobile. */
.ds-nav-item,
.ds-mobile-hamburger,
.ds-mode-btn,
.ds-sidebar-toggle {
    -webkit-tap-highlight-color: transparent;
}
.ds-mobile-hamburger {
    transition: background 0.12s ease, color 0.12s ease, transform 0.1s ease;
}
.ds-nav-item:active,
.ds-mode-btn:active {
    background: var(--bg-hover);
}
.ds-mobile-hamburger:active {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: scale(0.92);
}

/* ---- Main Content ---- */

.ds-main {
    max-width: var(--dashboard-content-max-width);
    padding: var(--dashboard-padding);
    flex: 1;
}

/* Full-width pages (planner, etc.) override max-width */
.ds-main.planner {
    max-width: none;
    padding: 0;
    height: calc(100vh - var(--dashboard-header-height, 56px));
}

/* Contain the planner on large displays so the week grid doesn't run literally
   edge-to-edge on big / ultrawide monitors. Horizontal padding (not a hard
   max-width) keeps the grid full-flow and avoids reflowing the toolbar /
   library panel / popover layout. Laptops + 1080p (<2000px) are untouched.
   Step 2 of the responsive-scaling plan. */
@media (min-width: 2000px) { .ds-main.planner { padding: 0 2.5vw; } }
@media (min-width: 2560px) { .ds-main.planner { padding: 0 5vw; } }
@media (min-width: 3200px) { .ds-main.planner { padding: 0 8vw; } }

/* ---- Section Pattern ---- */

.ds-section {
    margin-bottom: 32px;
}

.ds-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.ds-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    margin: 0;
}

.ds-section-action {
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

.ds-section-action:hover {
    color: var(--accent-hover);
}

/* ============================================================================
   Mobile Overlay
   ============================================================================ */

.ds-sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: calc(var(--z-sidebar) - 1);
    /* Fade in/out with the drawer instead of a hard display toggle. */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.26s var(--ease-out), visibility 0.26s var(--ease-out);
}

/* ============================================================================
   Responsive — Mobile (<768px)
   ============================================================================ */

@media (max-width: 768px) {
    /* Sidebar becomes an overlay */
    .ds-sidebar {
        transform: translateX(-100%);
        width: 280px;
        min-width: 280px;
        /* Smooth slide — the base rule only transitions width, so on mobile
           (which opens via translateX) the drawer used to SNAP open/closed. */
        transition: transform 0.26s var(--ease-out);
        /* viewport-fit=cover is set, so inset the drawer clear of the notch +
           home indicator. */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .ds-sidebar.mobile-open {
        transform: translateX(0);
    }

    .ds-sidebar.collapsed {
        width: 280px;
        min-width: 280px;
    }

    .ds-sidebar.collapsed .ds-nav-label,
    .ds-sidebar.collapsed .ds-sidebar-brand-name,
    .ds-sidebar.collapsed .ds-sidebar-coach-name {
        opacity: 1;
        width: auto;
    }

    .ds-sidebar.collapsed .ds-nav-section-label {
        opacity: 1;
        height: auto;
        padding: 16px 12px 6px;
        border-top: none;
        margin: 0;
    }

    .ds-sidebar.collapsed .ds-nav-item {
        justify-content: flex-start;
        padding: 0 12px;
    }

    .ds-sidebar.collapsed .ds-nav-badge {
        position: static;
        margin-left: auto;
        min-width: 18px;
        height: 18px;
        padding: 0 5px;
        font-size: 11px;
    }

    .ds-sidebar-backdrop.show {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Content fills viewport on mobile */
    .ds-content {
        margin-left: 0;
    }

    .ds-sidebar.collapsed ~ .ds-content {
        margin-left: 0;
    }

    /* Show hamburger — 44px min touch target (was 36px). */
    .ds-mobile-hamburger {
        display: flex;
        width: 44px;
        height: 44px;
    }

    /* Comfortable thumb targets for nav items (was 40px). */
    .ds-nav-item {
        height: 48px;
    }

    /* Topbar tighter on mobile + clear the notch (viewport-fit=cover). */
    .ds-topbar {
        padding: 0 16px;
        padding-top: env(safe-area-inset-top);
        height: calc(var(--dashboard-header-height) + env(safe-area-inset-top));
    }

    .ds-main {
        padding: 16px;
    }

    /* Hide desktop collapse toggle on mobile */
    .ds-sidebar-toggle {
        display: none;
    }
}

/* ============================================================================
   Responsive — Tablet (769px–1024px)
   ============================================================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    /* Auto-collapse sidebar on tablet */
    .ds-sidebar:not(.expanded) {
        width: var(--sidebar-width-collapsed);
        min-width: var(--sidebar-width-collapsed);
    }

    .ds-sidebar:not(.expanded) .ds-nav-label,
    .ds-sidebar:not(.expanded) .ds-sidebar-brand-name,
    .ds-sidebar:not(.expanded) .ds-sidebar-coach-name {
        opacity: 0;
        width: 0;
    }

    .ds-sidebar:not(.expanded) .ds-nav-section-label {
        opacity: 0;
        height: 0;
        padding: 0;
        margin: 8px 0 0;
        border-top: 1px solid var(--border-subtle);
    }

    .ds-sidebar:not(.expanded) .ds-nav-item {
        justify-content: center;
        padding: 0;
    }

    .ds-sidebar:not(.expanded) ~ .ds-content {
        margin-left: var(--sidebar-width-collapsed);
    }
}

/* Reduced-motion: no drawer slide / backdrop fade / press-scale (2026-07-05). */
@media (prefers-reduced-motion: reduce) {
    .ds-sidebar,
    .ds-sidebar-backdrop,
    .ds-mobile-hamburger {
        transition: none;
    }
    .ds-mobile-hamburger:active { transform: none; }
}
