/* =====================================================================
   Main application shell — Parts Inventory
   ===================================================================== */

/* ── Layout ──────────────────────────────────────────────────────────── */
/* iOS: 100vh is the LARGE viewport (as if the URL bar were hidden), so a 100vh box is taller
   than what you can actually see. The overflow then can't settle and Safari rubber-bands the
   top back out of reach. 100dvh tracks the real visible height. Keep the 100vh line above it
   as the fallback for browsers without dvh. */
body.page-app {
    min-height:  100vh;
    min-height:  100dvh;
    display:     flex;
    overflow:    hidden;
}

/* ── Sidebar (desktop) ───────────────────────────────────────────────── */
#sidebar {
    width:          var(--sidebar-width);
    background:     var(--sidebar-bg);
    display:        flex;
    flex-direction: column;
    flex-shrink:    0;
    height:         100vh;
    height:         100dvh;   /* iOS: dynamic viewport excludes the browser toolbar */
    position:       sticky;
    top:            0;
    overflow:       hidden;   /* the NAV scrolls; brand + footer stay pinned */
    z-index:        var(--z-sticky);
    transition:     transform var(--transition-slow);
}
.sidebar-brand { flex-shrink: 0; }
.sidebar-footer { flex-shrink: 0; }

.sidebar-brand {
    padding:       var(--space-5) var(--space-4) var(--space-4);
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand__logo {
    width:          40px;
    height:         40px;
    border-radius:  var(--radius-md);
    display:        block;
    object-fit:     contain;
    margin-bottom:  var(--space-3);
    flex-shrink:    0;
}
.topbar-logo {
    width:          32px;
    height:         32px;
    object-fit:     contain;
    border-radius:  var(--radius-sm);
    flex-shrink:    0;
}
.sidebar-brand__name {
    color:       var(--sidebar-text-active);
    font-size:   var(--font-size-sm);
    font-weight: 800;
    line-height: 1.3;
}
.sidebar-brand__sub {
    color:     rgba(200,216,228,.5);
    font-size: var(--font-size-xs);
}

.sidebar-nav {
    flex:       1;
    min-height: 0;
    overflow-y: auto;   /* scroll the tab list; Sign Out stays reachable at the bottom */
    padding:    var(--space-3) 0;
}
.sidebar-nav-section {
    padding:       var(--space-3) var(--space-4) var(--space-1);
    font-size:     10px;
    font-weight:   700;
    letter-spacing:.08em;
    text-transform:uppercase;
    color:         rgba(200,216,228,.4);
}
.sidebar-nav-item {
    display:       flex;
    align-items:   center;
    gap:           var(--space-3);
    padding:       var(--space-3) var(--space-4);
    color:         var(--sidebar-text);
    font-size:     var(--font-size-sm);
    font-weight:   500;
    cursor:        pointer;
    border:        none;
    background:    none;
    width:         100%;
    text-align:    left;
    border-radius: 0;
    transition:    background var(--transition-fast), color var(--transition-fast);
    border-left:   3px solid transparent;
}
.sidebar-nav-item:hover {
    background:  var(--sidebar-item-hover);
    color:       var(--sidebar-text-active);
}
.sidebar-nav-item.active {
    background:  rgba(224,112,16,.15);
    color:       var(--sidebar-text-active);
    border-left-color: var(--color-accent);
    font-weight: 600;
}
.sidebar-nav-item__icon { font-size: 18px; flex-shrink: 0; width: 20px; text-align: center; }

.sidebar-footer {
    padding:       var(--space-4);
    border-top:    1px solid rgba(255,255,255,.08);
}
.sidebar-user {
    display:       flex;
    align-items:   center;
    gap:           var(--space-3);
    margin-bottom: var(--space-3);
    padding:       var(--space-2) var(--space-2);
    border-radius: var(--radius-md);
}
.sidebar-user__avatar {
    width:          32px;
    height:         32px;
    border-radius:  50%;
    background:     var(--color-accent);
    display:        flex;
    align-items:    center;
    justify-content:center;
    font-weight:    700;
    font-size:      var(--font-size-sm);
    color:          #fff;
    flex-shrink:    0;
}
.sidebar-user__name  { color: var(--sidebar-text-active); font-size: var(--font-size-sm); font-weight: 600; }
.sidebar-user__role  { color: rgba(200,216,228,.5); font-size: var(--font-size-xs); }

/* ── Main content area ───────────────────────────────────────────────── */
#main-content {
    flex:       1;
    min-width:  0;
    display:    flex;
    flex-direction: column;
    height:     100vh;
    height:     100dvh;   /* iOS: see body.page-app — 100vh overflows the visible area and the
                             scroll snaps back, taking the topbar + search out of reach */
    overflow-y: auto;
    overscroll-behavior: contain;          /* don't hand the bounce to the page behind */
    -webkit-overflow-scrolling: touch;     /* momentum scrolling on iOS */
}

/* ── Top bar ─────────────────────────────────────────────────────────── */
#topbar {
    height:          var(--header-height);
    background:      var(--color-bg-surface);
    border-bottom:   1px solid var(--color-border-subtle);
    display:         flex;
    align-items:     center;
    padding:         0 var(--space-6);
    gap:             var(--space-4);
    position:        sticky;
    top:             0;
    z-index:         var(--z-sticky);
    box-shadow:      var(--shadow-sm);
    flex-shrink:     0;
}
#topbar-menu-btn {
    display:  none;
    padding:  var(--space-2);
    border:   none;
    background: none;
    cursor:   pointer;
    font-size: 20px;
    color:    var(--color-text-secondary);
}
#topbar-title {
    font-size:   var(--font-size-lg);
    font-weight: 700;
    flex:        1;
}
#topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

/* ── Tab panels ─────────────────────────────────────────────────────── */
.tab-panel {
    display:  none;
    padding:  var(--space-6);
    animation:fadeIn var(--transition-base) ease both;
}
.tab-panel.active { display: block; }
.tab-panel .panel-header {
    display:       flex;
    align-items:   center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
    gap:           var(--space-4);
    flex-wrap:     wrap;
}
.tab-panel .panel-title {
    font-size:   var(--font-size-xl);
    font-weight: 800;
}
.panel-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }

/* ── Dashboard grid ─────────────────────────────────────────────────── */
.dashboard-stats {
    display:               grid;
    /* 260px, not 220 — a card holds a 48px icon plus its gap and padding, which left barely
       100px for the number. Inventory value at this plant can run to 8 figures.
       min(…,100%) so the track can never demand more width than the viewport has. */
    grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
    gap:                   var(--space-4);
    margin-bottom:         var(--space-6);
}
.dashboard-grid {
    display:               grid;
    grid-template-columns: 1fr 1fr;
    gap:                   var(--space-4);
}
@media (max-width: 900px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

/* ── Mobile: bottom nav ─────────────────────────────────────────────── */
#bottom-nav {
    display: none;
}

/* ── Mobile breakpoint ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidebar {
        position:  fixed;
        left:      0; top: 0; bottom: 0;
        transform: translateX(calc(-1 * var(--sidebar-width)));
        z-index:   var(--z-modal);
    }
    #sidebar.open { transform: translateX(0); }

    #sidebar-overlay {
        display:    none;
        position:   fixed; inset: 0;
        background: rgba(0,0,0,.5);
        z-index:    calc(var(--z-modal) - 1);
    }
    #sidebar-overlay.visible { display: block; }

    #topbar-menu-btn { display: flex; }
    #topbar { padding: 0 var(--space-4); }

    .tab-panel { padding: var(--space-4) var(--space-3); padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px) + var(--space-4)); }
    /* Supervisor and up get no bottom bar — reclaim the space it was reserving. */
    body.no-bottom-nav .tab-panel { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-4)); }
    body.no-bottom-nav #bottom-nav { display: none !important; }
    /* Without the bar, the hamburger IS the navigation below 768px — make it a real target. */
    #topbar-menu-btn { min-width: 44px; min-height: 44px; font-size: 24px; margin-left: calc(var(--space-2) * -1); }

    #bottom-nav {
        display:         flex;
        position:        fixed;
        bottom:          0; left: 0; right: 0;
        height:          var(--bottom-nav-h);
        /* iOS: keep the buttons clear of the home indicator / Safari's bottom chrome, which
           otherwise sits on top of a fixed bar and eats the taps. */
        height:          calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom:  env(safe-area-inset-bottom, 0px);
        background:      var(--color-bg-surface);
        border-top:      1px solid var(--color-border-subtle);
        z-index:         var(--z-sticky);
        box-shadow:      0 -2px 8px rgba(0,0,0,.08);
    }
    .bottom-nav-item {
        flex:          1;
        display:       flex;
        flex-direction:column;
        align-items:   center;
        justify-content:center;
        gap:           2px;
        font-size:     10px;
        font-weight:   600;
        color:         var(--color-text-muted);
        border:        none;
        background:    none;
        cursor:        pointer;
        padding:       var(--space-2) var(--space-1);
        transition:    color var(--transition-fast);
    }
    .bottom-nav-item__icon { font-size: 20px; }
    .bottom-nav-item.active { color: var(--color-link); }

}

/* One card per row on a PHONE only. Two hard columns couldn't fit a money value that must not
   wrap — the track blew past the viewport and scrolled the whole page sideways. Above this the
   auto-fit rule handles it: iPad portrait (768) still gets two columns rather than one tall
   column of half-empty cards. */
@media (max-width: 560px) {
    .dashboard-stats { grid-template-columns: 1fr; }
}

/* ── Dashboard — the landing screen (2026-10-06) ───────────────── */
.dash-section { margin-bottom: var(--space-6); }
.dash-section__title {
    font-size:      var(--font-size-sm);
    font-weight:    700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color:          var(--color-text-muted);
    margin:         0 0 var(--space-3);
}
.dash-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; }
.dash-actions .btn { font-size: var(--font-size-base); padding: var(--space-3) var(--space-5); }
.dash-actions__maps { margin-left: auto; font-size: var(--font-size-sm); color: var(--color-text-muted); }
.dash-actions__maps a { color: var(--color-link); text-decoration: none; }
.dash-actions__maps a:hover { text-decoration: underline; }
.dash-queue .stat-card__note { white-space: normal; }
.dash-empty {
    padding:       var(--space-4) var(--space-5);
    border:        1px dashed var(--color-border-subtle);
    border-radius: var(--radius-lg);
    color:         var(--color-text-muted);
    font-size:     var(--font-size-sm);
}
.dash-more { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--color-border-subtle); font-size: var(--font-size-sm); }
.dash-more a { color: var(--color-link); text-decoration: none; }
.text-danger { color: var(--color-danger); }
@media (max-width: 640px) {
    .dash-actions .btn { flex: 1 1 45%; }
    .dash-actions__maps { margin-left: 0; width: 100%; }
}
/* A grid item's min-width is `auto` — a table wider than the column pushed the Deliveries card
   past the panel edge (Owner, 2026-10-06, iPad). The column holds its share; the table scrolls. */
.dashboard-grid > .card { min-width: 0; }
.dashboard-grid .card-body { overflow-x: auto; }
.dashboard-grid .data-table td, .dashboard-grid .data-table th { white-space: normal; }
.dashboard-grid .data-table .badge { white-space: nowrap; }
