/* =========================================================================
   dashboard.css — app shell layout (sidebar + topbar + content)
   ========================================================================= */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

/* The content column (topbar + main-content). Grid items default to
   min-width: auto, meaning they refuse to shrink below their content's
   natural width — so wide content (a many-column table, a form with
   several fields) would otherwise drag this whole column wider than the
   viewport instead of triggering .table-wrap's own overflow-x:auto.
   min-width: 0 lets the column shrink to the viewport correctly, so
   internal scroll containers actually do their job. */
.app-shell > div {
    min-width: 0;
}

/* --- Sidebar --- */
.sidebar {
    grid-row: 1 / -1;
    background: rgba(255, 255, 255, 0.02);
    border-right: 1px solid var(--border-glass);
    padding: var(--space-6) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    position: sticky;
    top: 0;
    /* Needed so the flyout submenu's own z-index actually has effect
       against the main content area — without an explicit z-index here,
       .sidebar (a sticky-positioned stacking context) has no elevation
       of its own in the page's overall stacking order, so a child's
       z-index only ever wins against OTHER children of this same
       sidebar, never against later, unrelated siblings like
       .main-content's cards and tables — which is exactly why the
       flyout was rendering underneath page content instead of over it. */
    z-index: 50;
    /* No height constraint and no overflow-y — the scroll mechanism is
       removed entirely, not just visually hidden. The sidebar is exactly
       as tall as its content; if that's taller than the viewport, it
       simply extends past it as part of the page (no separate internal
       scroll container to reach the rest). position: sticky is kept so
       it still stays pinned in view as the main content scrolls. */
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-2);
}

.sidebar__brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
}

.brand-mark-glow {
    display: inline-flex;
    align-items: center;
    /* Reuses --accent-glow directly rather than deriving a color from
       --accent here — it's already a low-opacity rgba tuned per theme
       for exactly this kind of soft glow, so this rule needs zero
       per-theme logic of its own and just tracks whatever theme is
       currently active, site-wide default or a user's own override. */
    filter: drop-shadow(0 0 6px var(--accent-glow)) drop-shadow(0 0 14px var(--accent-glow));
    transition: filter 0.3s ease;
}

.brand-mark-glow img {
    display: block;
}

.sidebar__brand-name {
    font-weight: 700;
    font-size: var(--text-lg);
    letter-spacing: -0.01em;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-group__label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: var(--space-2) var(--space-3);
}

/* --- Collapsible nav groups (Admin sidebar categories) ---
   Modeled on WordPress admin's own sidebar, not an original pattern:
   - The group containing the CURRENT page (.nav-group--active, set
     server-side — see $__navActiveGroup in sidebar.php) stays
     permanently expanded inline, no interaction needed, no toggle
     arrow — matches WP showing the active section's submenu open at
     all times while you're working within it.
   - Every other group shows just its label plus a right-pointing
     chevron by default. On hover (real mouse only, scoped via
     @media (hover: hover) so touch never gets a stuck phantom-hover
     flyout), its submenu appears as a flyout positioned to the right
     of the sidebar — overlapping the main content area rather than
     pushing the sidebar's own items down, exactly like WP's own
     flyout behavior.
   - Click/tap (.nav-group--expanded, toggled via JS) expands inline
     instead of a flyout — a side flyout doesn't make sense on a
     narrow mobile screen, so touch gets the same inline-push behavior
     the active group always has. */
.nav-group--collapsible {
    position: relative;
}

.nav-group--collapsible > .nav-group__label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    font: inherit;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    cursor: pointer;
    text-align: left;
}

.nav-group--collapsible > .nav-group__label::after {
    content: 'chevron_right';
    font-family: 'Material Symbols Rounded';
    font-size: 16px;
}

.nav-group--active > .nav-group__label::after,
.nav-group--expanded > .nav-group__label::after {
    content: 'expand_more';
}

.nav-group__items {
    display: none;
}

/* Active group — always inline, always open, normal document flow. */
.nav-group--active > .nav-group__items {
    display: block;
}

/* Click/tap — inline, same as active (the only sensible behavior on a
   narrow screen with no room for a side flyout). */
.nav-group--expanded > .nav-group__items {
    display: block;
}

/* Hover — flyout to the right, only for devices with real hover AND
   only for non-active groups (the active one is already open inline,
   a flyout on top of that would be redundant/confusing). */
@media (hover: hover) {
    .nav-group--collapsible:not(.nav-group--active):hover > .nav-group__items {
        display: block;
        position: absolute;
        left: 100%;
        top: 0;
        min-width: 220px;
        background: var(--bg-elevated);
        border: 1px solid var(--border-glass);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-elevated);
        padding: var(--space-2);
        z-index: 40;
    }
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 9px var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: background var(--duration-fast) var(--ease-standard),
                color var(--duration-fast) var(--ease-standard);
}

.nav-item .material-symbols-rounded {
    font-size: 20px;
    color: var(--text-tertiary);
    transition: color var(--duration-fast) var(--ease-standard);
}

.nav-item:hover {
    background: var(--surface-glass);
    color: var(--text-primary);
}

.nav-item:hover .material-symbols-rounded {
    color: var(--text-primary);
}

.nav-item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.nav-item.is-active .material-symbols-rounded {
    color: var(--accent);
}

/* "Play Index Dunk" — animated promo entry shown to every tier.
   Bouncing ball + pulsing pill; app.css's prefers-reduced-motion rule
   stops both animations for users who asked for less motion. */
.nav-group--game:empty { display: none; }

.nav-item--game {
    margin-bottom: var(--space-2);
    position: relative;
    align-items: flex-start;
    margin-top: var(--space-2);
    border: 1px solid rgba(249, 115, 22, 0.35);
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.14), rgba(99, 102, 241, 0.10));
    color: var(--text-primary);
    animation: game-glow 2.8s ease-in-out infinite;
}

.nav-item--game:hover {
    background: linear-gradient(135deg, rgba(249, 115, 22, 0.24), rgba(99, 102, 241, 0.18));
}

.nav-item--game .material-symbols-rounded,
.nav-item--game:hover .material-symbols-rounded {
    color: #fb923c;
}

.nav-item--game__ball {
    display: inline-block;
    transform-origin: 50% 100%;
    animation: game-bounce 1.1s cubic-bezier(0.28, 0.84, 0.42, 1) infinite;
}

.nav-item--game__text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.nav-item--game__title {
    font-weight: 600;
    white-space: nowrap;
}

.nav-item--game__pill {
    align-self: flex-start;
    display: inline-block;
    margin: 2px 0 1px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #f97316;
    color: #fff;
    font-size: 9.5px;
    line-height: 1.4;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    transform-origin: left center;
    animation: game-pulse 1.6s ease-in-out infinite;
}

.nav-item--game__hint {
    font-size: 11px;
    font-weight: 400;
    line-height: 1.35;
    color: var(--text-secondary);
    white-space: normal;
}

@keyframes game-bounce {
    0%, 100% { transform: translateY(0) scaleX(1) scaleY(1); }
    30%      { transform: translateY(-6px) scaleX(0.96) scaleY(1.04); }
    50%      { transform: translateY(-7px); }
    85%      { transform: translateY(0) scaleX(1.06) scaleY(0.92); }
}

@keyframes game-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.55); }
    50%      { transform: scale(1.04); box-shadow: 0 0 0 5px rgba(249, 115, 22, 0); }
}

@keyframes game-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0); }
    50%      { box-shadow: 0 0 18px 0 rgba(249, 115, 22, 0.28); }
}

.sidebar__footer {
    margin-top: auto;
    padding-top: var(--space-4);
    border-top: 1px solid var(--border-glass);
}

/* --- Topbar --- */
.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 var(--space-8);
    border-bottom: 1px solid var(--border-glass);
    background: rgba(10, 10, 15, 0.92);
    position: sticky;
    top: 0;
    z-index: 50;
}

/* backdrop-filter on a sticky element forces a per-frame compositor
   repaint that iOS Safari/WebKit (incl. Chrome iOS) handles very poorly,
   causing visible scroll jank on the dashboard. Only apply the frosted
   glass effect on devices with a precise pointer (i.e. not touchscreens),
   where it's cheap; touch devices get the near-opaque fallback above. */
@media (hover: hover) and (pointer: fine) {
    .topbar {
        background: rgba(10, 10, 15, 0.6);
        backdrop-filter: blur(16px);
    }
}

.topbar__menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: var(--space-2);
}

.topbar__title {
    font-weight: 600;
    font-size: var(--text-lg);
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-sm);
    flex-shrink: 0;
    overflow: hidden;
}

.avatar__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.avatar__fallback {
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
}

/* --- Main content --- */
.main-content {
    padding: var(--space-8);
    max-width: 1320px;
    width: 100%;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-8);
    flex-wrap: wrap;
}

.page-header h1 {
    margin-bottom: 4px;
}

.page-header p {
    margin: 0;
}

.grid {
    display: grid;
    gap: var(--space-5);
}

.grid--stats {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.grid--2 {
    grid-template-columns: repeat(2, 1fr);
}

/* Narrow "action panel" + wide "content/table" detail layout (e.g. a
   search result's manage panel next to its history table) — same
   1024px collapse as .grid--2 in responsive.css, just a 1:1.5 ratio
   instead of an even split. minmax(0, ...), not plain 1fr/1.5fr: a
   grid item's default min-width is "auto", which resolves to its
   content's intrinsic width — a bare `1fr` track still won't shrink a
   wide table below that, on any number of columns including the
   collapsed single-column mobile case below. Without minmax(0, ...)
   here, the collapse rule alone still isn't enough: the whole PAGE
   scrolls horizontally instead of the table's own .table-wrap
   (overflow-x:auto) scrolling on its own — confirmed live via
   scrollWidth/clientWidth before this fix (table-wrap's own two
   values were equal — nothing to scroll internally — while
   document.body.scrollWidth exceeded window.innerWidth). */
.grid--detail {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
    align-items: start;
}

/* --- Mobile drawer overlay --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 5, 10, 0.6);
    z-index: 199;
}

.sidebar-overlay.is-visible {
    display: block;
}

/* ---- Topbar user menu (avatar dropdown, contains Sign out) ---- */
.user-menu {
    position: relative;
}

/* .avatar is now a <button> (was a <div>) so it's clickable — reset the
   default button chrome so it looks identical to before. */
button.avatar {
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

.user-menu__dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-elevated);
    padding: var(--space-2);
    z-index: 100;
}

.user-menu__dropdown.is-open {
    display: block;
}

.user-menu__name {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-glass);
    margin-bottom: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-menu__item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--status-danger);
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.user-menu__item:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ---- Topbar theme-color swatch picker (reuses .user-menu/.user-menu__dropdown
   for positioning/open-close — see [data-user-menu] in app.js) ---- */
.theme-swatch-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: var(--space-2) var(--space-3) var(--space-1);
    max-width: 168px;
}

.theme-swatch-grid form {
    display: contents;
}

.theme-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: var(--swatch-color, var(--accent));
    cursor: pointer;
    padding: 0;
    transition: transform var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard);
}

.theme-swatch:hover {
    transform: scale(1.12);
}

.theme-swatch.is-active {
    border-color: var(--text-primary);
}

.theme-swatch--default {
    background: #6366f1;
}
