/* ==========================================================================
   layout.css — app shell (sidebar / topbar / bottomnav / drawer / main)
   --------------------------------------------------------------------------
   Mobile-first. Desktop layout activates at min-width: 1024px (--bp-lg).
   Single source for shell layout.
   ========================================================================== */

/* -------------------------------------------------------------------------- */
/* Shell dimensions                                                           */
/* -------------------------------------------------------------------------- */

:root {
    --topbar-h:    56px;
    --bottomnav-h: 60px;
}

/* -------------------------------------------------------------------------- */
/* Body — Inter, neutral-1 background                                         */
/* -------------------------------------------------------------------------- */

body {
    font-family: var(--font-sans);
    background: var(--neutral-1);
    color: var(--neutral-12);
    font-size: var(--text-base);
    line-height: var(--leading-base);
    font-weight: var(--weight-regular);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

#mainContent:not(.ready) { visibility: hidden; }

/* -------------------------------------------------------------------------- */
/* App container                                                              */
/* -------------------------------------------------------------------------- */

.app-container {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

/* -------------------------------------------------------------------------- */
/* Sidebar — drawer on mobile, persistent on desktop                          */
/* -------------------------------------------------------------------------- */

.sidebar {
    width: min(280px, 86vw);
    background: var(--surface-glass-1);
    backdrop-filter: var(--blur-sm);
    -webkit-backdrop-filter: var(--blur-sm);
    border-right: 1px solid var(--border-hairline);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: var(--z-drawer);
    transform: translateX(-100%);
    transition: transform var(--duration-base) var(--ease-out);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .sidebar { background: var(--neutral-2); }
}

.sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-3);
}

@media (min-width: 1024px) {
    .sidebar {
        width: var(--sidebar-w);
        transform: none;
        box-shadow: none;
    }
}

/* -------------------------------------------------------------------------- */
/* Brand block (logo + product name + status dot)                             */
/* -------------------------------------------------------------------------- */

.brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-5) var(--space-4);
    border-bottom: 1px solid var(--border-hairline);
}

.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-9), var(--accent-10));
    display: grid;
    place-items: center;
    font-weight: var(--weight-bold);
    color: white;
    font-size: var(--text-md);
    letter-spacing: var(--tracking-tight);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), var(--shadow-1);
    flex-shrink: 0;
}

.brand-name {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--neutral-12);
    letter-spacing: var(--tracking-tight);
    flex: 1;
    min-width: 0;
}

/* -------------------------------------------------------------------------- */
/* Workspace switcher                                                         */
/* -------------------------------------------------------------------------- */

.workspace-switcher {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border-hairline);
    position: relative;
}

.workspace-current {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2-5) var(--space-3);
    background: var(--neutral-3);
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-out),
                border-color var(--duration-fast) var(--ease-out);
    min-height: 56px;
}

@media (hover: hover) and (pointer: fine) {
    .workspace-current:hover {
        background: var(--neutral-4);
        border-color: var(--border-hairline-strong);
    }
}

.workspace-info {
    flex: 1;
    min-width: 0;
    min-height: 34px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.workspace-name {
    font-size: var(--text-base);
    line-height: var(--leading-base);
    font-weight: var(--weight-semibold);
    color: var(--neutral-12);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-height: var(--leading-base);
}

.workspace-role {
    font-size: var(--text-xs);
    line-height: var(--leading-xs);
    color: var(--neutral-11);
    min-height: var(--leading-xs);
}

.workspace-arrow {
    color: var(--neutral-9);
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    transition: transform var(--duration-fast) var(--ease-out);
}

.workspace-arrow svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    fill: none;
}

.workspace-switcher.is-open .workspace-arrow {
    transform: rotate(180deg);
}

.workspace-dropdown {
    display: none;
    position: absolute;
    top: calc(100% - var(--space-3));
    left: var(--space-4);
    right: var(--space-4);
    background: var(--surface-glass-2);
    backdrop-filter: var(--blur-md);
    -webkit-backdrop-filter: var(--blur-md);
    border: 1px solid var(--border-hairline-bright);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    z-index: var(--z-dropdown);
    padding: var(--space-2);
    margin-top: var(--space-2);
    max-width: calc(var(--sidebar-w) - var(--space-8));
}

.workspace-dropdown.is-open {
    display: block;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .workspace-dropdown { background: var(--neutral-3); }
}

.workspace-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 280px;
    overflow-y: auto;
}

.workspace-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2-5) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--neutral-11);
    transition: background var(--duration-instant) var(--ease-out),
                color var(--duration-instant) var(--ease-out);
    min-height: var(--touch-target);
}

@media (hover: hover) and (pointer: fine) {
    .workspace-item:hover {
        background: rgba(255, 255, 255, 0.04);
        color: var(--neutral-12);
    }
}

.workspace-item.active {
    background: var(--accent-3);
    color: var(--accent-11);
}

.workspace-item-info { min-width: 0; flex: 1; }

.workspace-item-name {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-item-role {
    font-size: var(--text-xs);
    color: var(--neutral-9);
    margin-top: 2px;
    text-transform: capitalize;
    letter-spacing: 0;
}

.workspace-item.active .workspace-item-role {
    color: var(--accent-11);
    opacity: 0.8;
}

.workspace-check {
    color: var(--accent-11);
    font-size: var(--text-sm);
    flex-shrink: 0;
}

.workspace-actions {
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--border-hairline);
}

.workspace-action-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2-5) var(--space-3);
    background: transparent;
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-md);
    color: var(--neutral-11);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-out),
                border-color var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
    min-height: var(--touch-target);
}

@media (hover: hover) and (pointer: fine) {
    .workspace-action-btn:hover {
        background: var(--accent-3);
        border-color: var(--accent-6);
        color: var(--accent-11);
    }
}

/* -------------------------------------------------------------------------- */
/* Nav menu                                                                   */
/* -------------------------------------------------------------------------- */

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-4);
    overflow-y: auto;
}

.nav-section-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--neutral-9);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    padding: var(--space-2) var(--space-3) var(--space-1);
    margin-top: var(--space-3);
}

.nav-section-label:first-child { margin-top: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2-5) var(--space-3);
    border-radius: var(--radius-md);
    border-left: 0;          /* reset legacy */
    color: var(--neutral-11);
    text-decoration: none;
    font-size: var(--text-base);
    font-weight: var(--weight-medium);
    transition: background var(--duration-instant) var(--ease-out),
                color var(--duration-instant) var(--ease-out);
    min-height: var(--touch-target);
}

@media (hover: hover) and (pointer: fine) {
    .nav-item:hover {
        background: rgba(255, 255, 255, 0.04);
        color: var(--neutral-12);
    }
}

.nav-item.active {
    background: var(--accent-3);
    color: var(--accent-11);
    border-left: 0;
}

.nav-item .icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    color: currentColor;
}

.nav-item .icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    fill: none;
}

/* -------------------------------------------------------------------------- */
/* Sidebar footer                                                             */
/* -------------------------------------------------------------------------- */

.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border-hairline);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.user-info { min-width: 0; }

.user-email {
    font-size: var(--text-sm);
    color: var(--neutral-11);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* btn-logout: minimal upgrade — full rebuild lives in components.css (session 3) */
.btn-logout {
    width: 100%;
    padding: var(--space-2-5) var(--space-3);
    background: transparent;
    border: 1px solid var(--border-hairline);
    border-radius: var(--radius-md);
    color: var(--neutral-11);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: background var(--duration-fast) var(--ease-out),
                border-color var(--duration-fast) var(--ease-out),
                color var(--duration-fast) var(--ease-out);
    min-height: var(--touch-target);
}

@media (hover: hover) and (pointer: fine) {
    .btn-logout:hover {
        background: var(--danger-3);
        border-color: var(--danger-6);
        color: var(--danger-11);
    }
}

/* -------------------------------------------------------------------------- */
/* Main content                                                               */
/* -------------------------------------------------------------------------- */

.main-content {
    flex: 1;
    min-width: 0;
    margin-left: 0;
    padding: 0 var(--page-px-m);
    padding-top: calc(var(--topbar-h) + var(--safe-top) + var(--space-4));
    padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + var(--space-6));
    max-width: 100%;
}

@media (min-width: 1024px) {
    .main-content {
        margin-left: var(--sidebar-w);
        padding: var(--space-8) var(--page-px-d);
        max-width: calc(var(--sidebar-w) + var(--container-max));
    }
}

/* -------------------------------------------------------------------------- */
/* Mobile topbar                                                              */
/* -------------------------------------------------------------------------- */

.mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    height: calc(var(--topbar-h) + var(--safe-top));
    padding: var(--safe-top) var(--space-4) 0;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--neutral-2);
    border-bottom: 1px solid var(--border-hairline);
    z-index: var(--z-sticky);
}

.mobile-topbar-btn {
    width: var(--touch-target);
    height: var(--touch-target);
    margin-left: calc(var(--space-2) * -1);
    display: grid;
    place-items: center;
    background: transparent;
    border: none;
    color: var(--neutral-11);
    font-size: 20px;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: background var(--duration-instant) var(--ease-out),
                color var(--duration-instant) var(--ease-out);
}

.mobile-topbar .mobile-topbar-btn {
    visibility: hidden;
    pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
    .mobile-topbar-btn:hover {
        background: rgba(255, 255, 255, 0.04);
        color: var(--neutral-12);
    }
}

.mobile-topbar-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--neutral-12);
    letter-spacing: var(--tracking-tight);
    flex: 1;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 1024px) {
    .mobile-topbar { display: none; }
}

/* -------------------------------------------------------------------------- */
/* Drawer overlay (scrim)                                                     */
/* -------------------------------------------------------------------------- */

.drawer-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--scrim);
    backdrop-filter: var(--scrim-blur);
    -webkit-backdrop-filter: var(--scrim-blur);
    z-index: var(--z-overlay);
    opacity: 0;
    transition: opacity var(--duration-base) var(--ease-out);
}

.drawer-overlay.visible {
    display: block;
    opacity: 1;
}

body.is-drawer-open {
    overflow: hidden;
}

@media (min-width: 1024px) {
    .drawer-overlay { display: none !important; }
}

/* -------------------------------------------------------------------------- */
/* Mobile bottomnav                                                           */
/* -------------------------------------------------------------------------- */

.mobile-bottomnav {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    gap: var(--space-1);
    height: calc(var(--bottomnav-h) + var(--safe-bottom));
    padding: var(--space-1-5) var(--space-2) calc(var(--safe-bottom) + var(--space-1));
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--neutral-2);
    border-top: 1px solid var(--border-hairline);
    z-index: var(--z-sticky);
}

.bottomnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: var(--space-1) var(--space-1);
    border-radius: var(--radius-md);
    color: var(--neutral-9);
    text-decoration: none;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    transition: background var(--duration-instant) var(--ease-out),
                color var(--duration-instant) var(--ease-out);
}

.bottomnav-item.active {
    background: var(--accent-3);
    color: var(--accent-11);
}

.bottomnav-icon {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    line-height: 1;
}

.bottomnav-icon svg {
    width: 100%;
    height: 100%;
    stroke: currentColor;
    fill: none;
}

@media (min-width: 1024px) {
    .mobile-bottomnav { display: none; }
}

/* -------------------------------------------------------------------------- */
/* Page wrappers (used by individual templates from session 5+)               */
/* -------------------------------------------------------------------------- */

.layout-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-hairline);
}

.layout-page-header h1,
.layout-page-header .page-title {
    font-size: var(--text-2xl);
    line-height: var(--leading-2xl);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-tight);
    color: var(--neutral-12);
    margin: 0;
}

@media (max-width: 767.98px) {
    .layout-page-header {
        flex-wrap: wrap;
        gap: var(--space-3);
    }

    .layout-page-header h1,
    .layout-page-header .page-title {
        font-size: var(--text-xl);
        line-height: var(--leading-xl);
    }
}

.layout-page-header .page-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

/* Auth layout — used by login/register/invite in session 5 */
.layout-auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: var(--space-6);
    background:
        radial-gradient(ellipse at top, var(--accent-3) 0%, transparent 60%),
        radial-gradient(ellipse at bottom right, var(--accent-1) 0%, transparent 50%),
        var(--neutral-1);
}
