/* =========================================================================
   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);
}

.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);
}

/* --- 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);
}
