/**
 * DH Suite — Layout Utilities
 *
 * Structural layout primitives: containers, app shell (header + sidebar + main),
 * grid/flex helpers, and page header pattern.
 *
 * Sidebar *navigation item* styles live in sidebar.css.
 * This file handles sidebar *structure and mechanics* only.
 */

@layer layout {

/* ==========================================================================
   Containers
   ========================================================================== */

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-4);
}

.container-sm {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 var(--spacing-4);
}

.container-xs {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 var(--spacing-4);
}

@media (min-width: 768px) {
    .container,
    .container-sm,
    .container-xs {
        padding: 0 var(--spacing-6);
    }
}

/* ==========================================================================
   App Shell  (header + sidebar + main content)
   ==========================================================================
   Standard layout for coordinator/admin views across all apps.
   Mobile: sidebar hidden off-screen, toggled via JS.
   Desktop (>=1024px): sidebar pinned, main content offset.

   HTML structure:
     <div class="app-shell">
       <header class="app-header">…</header>
       <div class="app-layout">
         <aside class="app-sidebar">…</aside>
         <div class="sidebar-overlay"></div>
         <main class="app-main">…</main>
       </div>
     </div>
   ========================================================================== */

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* --- Header ------------------------------------------------------------- */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background-color: white;
    border-bottom: 1px solid var(--color-gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-4);
    /* The installed app on an iPhone draws edge to edge (viewport-fit=cover
       in suite_base.html): keep clear of the notch and the rounded corners.
       Each env() is 0 everywhere else. */
    padding-left: max(var(--spacing-4), env(safe-area-inset-left, 0px));
    padding-right: max(var(--spacing-4), env(safe-area-inset-right, 0px));
    z-index: 100;
}

.app-header-left,
.app-header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
}

/* --- Menu button (hamburger toggle) ------------------------------------ */

.menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--color-gray-600);
    cursor: pointer;
    border-radius: var(--radius-md);
}

.menu-btn:hover {
    background-color: var(--color-gray-100);
    color: var(--color-gray-800);
}

.menu-btn:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-ring-offset);
}

/* --- Header brand (logo + org name) ------------------------------------ */

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
}

.header-brand-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    text-decoration: none;
    color: inherit;
}

.header-brand-link:hover {
    text-decoration: none;
}

/* Full logo: 200x50px max for desktop headers */
.header-logo-full {
    height: 40px;
    max-width: 200px;
    width: auto;
    object-fit: contain;
}

/* Icon logo: hidden on desktop, shown on tablet/mobile */
.header-logo-icon {
    display: none;
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.header-brand-name {
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-lg);
    white-space: nowrap;
}

/* Tablet and below: Show icon, hide full logo */
@media (max-width: 1023px) {
    .header-logo-full {
        display: none;
    }

    .header-logo-icon {
        display: block;
    }
}

/* Mobile: Smaller sizing */
@media (max-width: 767px) {
    .header-logo-icon {
        width: 32px;
        height: 32px;
    }

    .header-brand-name {
        font-size: var(--font-size-base);
    }
}

/* --- Layout (sidebar + main) -------------------------------------------- */

.app-layout {
    display: flex;
    padding-top: 60px;
    min-height: calc(100vh - 60px);
}

/* --- Sidebar structure -------------------------------------------------- */

.app-sidebar {
    position: fixed;
    left: 0;
    top: 60px;
    bottom: 0;
    width: 240px;
    background-color: white;
    border-right: 1px solid var(--color-gray-200);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform var(--transition-slow);
    z-index: 99;
}

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

/* Overlay behind sidebar on mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 98;
}

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

/* Under the iPhone's status bar when the installed app draws edge to edge */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        height: calc(60px + env(safe-area-inset-top, 0px));
        padding-top: env(safe-area-inset-top, 0px);
    }

    .app-layout {
        padding-top: calc(60px + env(safe-area-inset-top, 0px));
    }

    .app-sidebar,
    .sidebar-overlay {
        top: calc(60px + env(safe-area-inset-top, 0px));
    }
}

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

.app-main {
    flex: 1;
    /* A flex item's minimum width is its content's unless set: without
       this a wide tab bar pushed whole pages past a phone's screen.
       Wide content scrolls inside its own box. */
    min-width: 0;
    padding: var(--spacing-6);
    margin-left: 0;
    overflow-x: hidden;
    /* clip, not hidden, where supported: hidden makes this a scroll box in
       both directions, and a sticky element inside then sticks to it rather
       than to the window, so it never moves */
    overflow-x: clip;
}

/* --- Page width ---------------------------------------------------------
   Content is 1,440 px wide at most, centered, so lines stay readable on a wide
   monitor. A wide page opts in to an "Expand" button (suite_base.html). */

.page-width {
    max-width: 1440px;
    margin-inline: auto;
}

.page-width.is-expanded {
    max-width: none;
}

.page-width-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: var(--spacing-2);
}

/* --- Desktop: sidebar always visible ------------------------------------ */

@media (min-width: 1024px) {
    .app-sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none !important;
    }

    .app-main {
        margin-left: 240px;
    }

    .app-header .menu-btn {
        display: none;
    }
}

/* ==========================================================================
   Page Header
   ==========================================================================
   Flex row with title on left, action buttons on right.

   HTML:
     <div class="page-header">
       <h1>Page Title</h1>
       <div class="page-header-actions">
         <button>…</button>
       </div>
     </div>
   ========================================================================== */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-6);
    flex-wrap: wrap;
    gap: var(--spacing-3);
}

.page-header h1 {
    margin: 0;
}

.page-header-actions {
    display: flex;
    gap: var(--spacing-2);
    flex-wrap: wrap;
}

/* A button keeps its label on one line; on a narrow screen the group
   wraps instead. */
.page-header-actions .btn,
.page-header-row .action-buttons .btn {
    white-space: nowrap;
}

/* ==========================================================================
   Grid Utilities
   ========================================================================== */

/* --- Stats row ---------------------------------------------------------- */

.stats-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-6);
}

/* From tablet width, auto-fit rather than a fixed 3 or 4 columns: a dashboard
 * showing only the tiles its viewer may open can have two or three, and a
 * fixed grid left a gap where the rest would have been. Phones keep two. */
@media (min-width: 768px) {
    .stats-row {
        grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    }
}

/* --- Dashboard grid ----------------------------------------------------- */

.dashboard-grid {
    display: grid;
    gap: var(--spacing-4);
}

@media (min-width: 768px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.card-wide {
    grid-column: 1 / -1;
}

/* --- Form grid ---------------------------------------------------------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-3) var(--spacing-6);
}

@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* --- Auto-fit grid ------------------------------------------------------ */

.grid-auto {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-4);
}

/* ==========================================================================
   Flex Utilities
   ========================================================================== */

.flex {
    display: flex;
}

.flex-col {
    display: flex;
    flex-direction: column;
}

.flex-wrap {
    flex-wrap: wrap;
}

.flex-1 {
    flex: 1;
}

.items-center {
    align-items: center;
}

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

.justify-between {
    justify-content: space-between;
}

.justify-center {
    justify-content: center;
}

.justify-end {
    justify-content: flex-end;
}

.gap-1 { gap: var(--spacing-1); }
.gap-2 { gap: var(--spacing-2); }
.gap-3 { gap: var(--spacing-3); }
.gap-4 { gap: var(--spacing-4); }
.gap-6 { gap: var(--spacing-6); }

/* ==========================================================================
   Auth / Centered Page Layout
   ==========================================================================
   Full-viewport centered layout for login, register, error pages.
   ========================================================================== */

.centered-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-8) var(--spacing-4);
}

/* ==========================================================================
   Page header row, actions and filters
   Moved from rally.css: STYLE-GUIDE.md already
   called them shared, and Reach needs them.
   ========================================================================== */

.page-header-row {
    display: flex;
    align-items: center;
    gap: var(--spacing-3);
    flex-wrap: wrap;
}

/* In the header the actions wrap below the title on a phone. Row actions
   in tables keep tables.css's single line. */
.page-header-row .action-buttons {
    flex-wrap: wrap;
}

.action-buttons {
    display: flex;
    gap: var(--spacing-2);
    flex-wrap: nowrap;
}

.filter-bar {
    padding: var(--spacing-3) 0;
}

.filter-row {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-2);
    flex-wrap: wrap;
}

.filter-search {
    flex: 1;
    min-width: 200px;
}

@media (max-width: 599px) {
    /* The sides only: sidebar.css sets the bottom for the phone's tab bar.
       A phone on its side keeps clear of the notch. */
    .app-main {
        padding-inline: max(var(--spacing-4), env(safe-area-inset-left, 0px)) max(var(--spacing-4), env(safe-area-inset-right, 0px));
    }
}

@media (max-width: 767px) {
    .filter-row {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-search {
        min-width: 100%;
    }
}

} /* end @layer layout */
