/**
 * =====================================================================
 * PAGE LAYOUTS  assets/css/layout.css
 * =====================================================================
 * High-level page structure for admin and resident-facing areas.
 * These classes define HOW major sections are arranged, not their
 * individual styling (components.css handles that).
 *
 * MOBILE-FIRST APPROACH:
 * Default styles make everything work on a phone: single-column layout,
 * stacked sections, hidden sidebar. Media queries at the bottom enhance
 * the layout for tablets and desktops (wider screens).
 *
 * Two main layouts are available:
 *   .admin-container   for staff/Record Management System pages
 *   .resident-container  for public portal pages (future)
 * =====================================================================
 */

/* =====================================================================
 * ADMIN LAYOUT
 * Typical structure:
 *   <div class="admin-container">
 *     <header class="navbar">...</header>
 *     <div class="admin-layout">
 *       <nav class="sidebar">...</nav>
 *       <div class="main-content">...</div>
 *     </div>
 *   </div>
 * ===================================================================== */

.admin-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.admin-layout {
    display: flex;
    /* Mobile: stack the (collapsible) sidebar above the content. The
       >=768px query below switches this back to a row with a fixed-width
       sidebar. Without this the opened mobile sidebar and the content
       fight for space side by side in a flex row. */
    flex-direction: column;
    flex: 1;
}

.main-content {
    flex: 1;
    /* min-width:0 lets this flex child shrink below its content width so a
       wide table scrolls inside its own .table-container instead of
       stretching the whole page (horizontal scroll on mobile). */
    min-width: 0;
    padding: var(--spacing-24);
    background-color: var(--color-secondary);
    overflow-y: auto;
}

/* On mobile, sidebar takes full width and is hidden by default */
.sidebar {
    display: none;
    width: 100%;
    order: -1; /* appears above main-content when shown */
}

.sidebar.mobile-open {
    display: block;
}

/* =====================================================================
 * RESIDENT LAYOUT (public portal)
 * Typical structure (see modules/resident/partials/header.php + footer.php):
 *   <div class="resident-container">
 *     <header class="resident-header">
 *       <div class="resident-navbar">...</div>   (see components.css)
 *     </header>
 *     <main class="resident-content">...</main>
 *     <footer class="resident-footer">...</footer>
 *   </div>
 * Distinct from .admin-container on purpose: a top navbar for
 * everyone, no sidebar  this is the warmer, public-facing side of the
 * app, not the staff utility panel.
 * ===================================================================== */

.resident-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Sticky: the Home page is a long scroll (hero, Services, About), and
   the nav + Login should stay one tap away. z-index 950 sits above page
   content but below the chatbot (1000) and modal overlays (1000).
   .is-scrolled (toggled by initResidentNav() in ui.js once the page
   moves) tightens the padding and deepens the shadow. */
.resident-header {
    position: sticky;
    top: 0;
    z-index: 950;
    background-color: var(--color-primary);
    color: var(--color-white);
    padding: var(--spacing-12) var(--spacing-16);
    box-shadow: var(--shadow-md);
    transition: padding 0.2s ease, box-shadow 0.2s ease;
}

.resident-header.is-scrolled {
    padding-top: var(--spacing-8);
    padding-bottom: var(--spacing-8);
    box-shadow: var(--shadow-lg);
}

/* The Services/About nav links jump to #services/#about on Home; without
   this the sticky bar would cover each section's heading on arrival. */
html:has(.resident-header) {
    scroll-padding-top: 88px;
}

@media (min-width: 768px) {
    .resident-header {
        padding: var(--spacing-16) var(--spacing-24);
    }

    .resident-header.is-scrolled {
        padding-top: var(--spacing-8);
        padding-bottom: var(--spacing-8);
    }
}

@media (prefers-reduced-motion: reduce) {
    .resident-header {
        transition: none;
    }
}

.resident-content {
    flex: 1;
    padding: var(--spacing-24);
    background-color: var(--color-secondary);
}

.resident-content-inner {
    max-width: 1100px;
    margin: 0 auto;
}

/* Resident footer (see partials/footer.php): a row of icon + contact
   items, then a copyright/legal row. Sits on the brand blue in BOTH
   themes, same as .resident-header, so its text colours are its own
   tokens rather than the theme's --color-text. The muted tone is white
   at 80%, which keeps >= 4.5:1 contrast on #1e3a8a. No wordmark: the
   navbar brand is right above on every page, so a second one here only
   repeated it. */
.resident-footer {
    --footer-text: #ffffff;
    --footer-muted: rgba(255, 255, 255, 0.8);
    --footer-rule: rgba(255, 255, 255, 0.15);
    --footer-icon-bg: rgba(255, 255, 255, 0.12);

    position: relative;
    /* Brand blue easing slightly darker toward the bottom, with a thin
       lighter-blue accent line along the top edge (::before below) to
       separate it from the page without a heavy border. */
    background-color: var(--color-primary);
    background-image: linear-gradient(180deg, var(--color-primary) 0%, #172e6e 100%);
    color: var(--footer-muted);
    /* Body size, not --font-size-small: this is the contact info and the
       legal links people actually come down here to read and tap. */
    font-size: var(--font-size-base);
    /* Phone: the floating chatbot button (.chatbot, 56px + 24px offset,
       components.css) sits over the bottom once scrolled all the way
       down; 96px bottom padding keeps the legal links clear of it. */
    padding: var(--spacing-32) var(--spacing-16) 96px;
}

.resident-footer::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, #60a5fa, transparent);
}

/* Contact items: address, hours, phone, email. One column on phone,
   2x2 from tablet up. Not a row of four on desktop: at 1100px that
   squeezed the email address until it broke mid-word. */
.resident-footer-contacts {
    max-width: 1100px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-16);
}

.resident-footer-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-12);
    min-height: 44px;
}

/* Inline SVG icon in a soft translucent circle; currentColor so it
   follows --footer-text. */
.resident-footer-icon {
    flex-shrink: 0;
    /* content-box: the global border-box reset would otherwise let the
       8px padding eat the 20px box and shrink the glyph to a dot. */
    box-sizing: content-box;
    width: 20px;
    height: 20px;
    padding: 8px;
    color: var(--footer-text);
    background-color: var(--footer-icon-bg);
    border-radius: 50%;
}

/* Address/hours text and phone/email links. Long values (the email,
   a long address) wrap instead of overflowing a 360px screen. */
.resident-footer-text,
.resident-footer-link {
    margin: 0;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.resident-footer a {
    color: var(--footer-muted);
    transition: color 0.2s ease;
}

.resident-footer a:hover {
    color: var(--footer-text);
}

.resident-footer a:focus-visible {
    outline: 2px solid var(--footer-text);
    outline-offset: 2px;
    border-radius: 2px;
}

.resident-footer-link {
    text-decoration: none;
}

.resident-footer-link:hover {
    text-decoration: underline;
}

/* Copyright + Terms/Privacy. Stacked and centered on phone, one row on
   tablet+. */
.resident-footer-bottom {
    max-width: 1100px;
    margin: var(--spacing-24) auto 0;
    padding-top: var(--spacing-16);
    border-top: 1px solid var(--footer-rule);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-8);
    text-align: center;
}

.resident-footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--spacing-24);
}

/* Legal links: full white and always underlined so they read as links
   without relying on colour alone (WCAG 1.4.1), with a 44px tap height
   at every width. */
.resident-footer-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--footer-text);
    font-weight: 600;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 4px;
}

.resident-footer-links a:hover {
    text-decoration-thickness: 2px;
}

@media (min-width: 768px) {
    .resident-content {
        padding: var(--spacing-32);
    }

    .resident-footer {
        /* The chatbot button sits in the bottom-RIGHT corner here, which
           .resident-footer-bottom's padding-right already clears, so the
           bottom edge needs no extra reserve. */
        padding: var(--spacing-32) var(--spacing-32) var(--spacing-16);
    }

    .resident-footer-contacts {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: var(--spacing-24);
    }

    .resident-footer-bottom {
        flex-direction: row;
        justify-content: space-between;
        text-align: left;
        /* Reserve the bottom-right corner for the chatbot button. */
        padding-right: 88px;
    }

    .resident-footer-links {
        gap: var(--spacing-32);
    }
}

@media print {
    .resident-footer,
    #chatbot {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .resident-footer a {
        transition: none;
    }
}

/* =====================================================================
 * CONTENT SECTIONS
 * ===================================================================== */

.page-header {
    margin-bottom: var(--spacing-24);
    padding-bottom: var(--spacing-16);
    border-bottom: 1px solid var(--color-border);
}

.page-header h1 {
    margin-bottom: 0;
}

/* Optional one-line subtitle inside a .page-header (e.g. Document
   Requests, Revenue). */
.page-header p {
    margin: var(--spacing-4) 0 0;
    color: var(--color-text-light);
    font-size: var(--font-size-small);
}

/* Modifier for a .page-header that also carries an action button
   (e.g. Announcements' RSS feed link) alongside the title/subtitle. */
.page-header--with-action {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--spacing-16);
    flex-wrap: wrap;
}

/* A stray <p> right after the header (older pages put the back-link
   here  new form.php pages put .back-link above the header instead). */
.page-header + p {
    margin-top: 0;
    margin-bottom: var(--spacing-16);
    font-size: var(--font-size-small);
}

/* Page tabs: two or more pages sharing one sidebar item, each a real
   link with its own URL (Document Requests: Walk-in Issuance / Requests,
   includes/docreq-tabs.php). Sits above the .page-header. */
.page-tabs {
    display: flex;
    gap: var(--spacing-4);
    margin-bottom: var(--spacing-24);
    /* The baseline is an inset shadow (not a border + negative-margin
       tabs) so nothing overflows vertically and no scrollbar/arrow shows. */
    box-shadow: inset 0 -1px 0 var(--color-border);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.page-tabs::-webkit-scrollbar {
    display: none;
}

.page-tab {
    padding: var(--spacing-8) var(--spacing-16);
    flex: 0 0 auto;
    border-bottom: 2px solid transparent;
    color: var(--color-text-light);
    font-weight: var(--font-weight-bold);
    text-decoration: none;
    white-space: nowrap;
}

.page-tab:hover {
    color: var(--color-text);
}

.page-tab.is-active {
    color: var(--color-accent);
    border-bottom-color: var(--color-accent);
}

/* The back-link's own <p> wrapper, sitting above the page header. */
p:has(> .back-link) {
    margin: 0 0 var(--spacing-16);
}

.breadcrumb {
    display: flex;
    gap: var(--spacing-8);
    margin-bottom: var(--spacing-24);
    font-size: var(--font-size-small);
    color: var(--color-text-light);
}

.breadcrumb a {
    color: var(--color-primary-light);
}

.section {
    background-color: var(--color-surface);
    padding: var(--spacing-24);
    margin-bottom: var(--spacing-24);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
}

/* =====================================================================
 * TOOLBAR / ACTION BARS
 * ===================================================================== */

.toolbar {
    display: flex;
    gap: var(--spacing-16);
    margin-bottom: var(--spacing-24);
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-search {
    flex: 1;
    display: flex;
    gap: var(--spacing-8);
    min-width: 200px;
}

.toolbar-search input {
    flex: 1;
}

.toolbar-actions {
    display: flex;
    gap: var(--spacing-8);
    flex-wrap: wrap;
}

/*
 * LIST-PAGE SEARCH + FILTER BAR ("Approach B")
 * Full-width search box, the filter dropdowns always in view (no toggle
 * to open first), and removable chips for the active constraints.
 * Markup: render_filter_bar() in includes/list-controls.php. One GET
 * <form>; a <select> applies only on submit (Search / Apply filters),
 * never mid-choice. Below 768px each control stacks full-width  see
 * the media query at the end of this section.
 */
.filterbar {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-8);
    flex: 1;
}

.filterbar__main {
    display: flex;
    gap: var(--spacing-8);
    align-items: center;
    flex-wrap: wrap;
}

.filterbar__search {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 260px;
}

.filterbar__search svg {
    position: absolute;
    left: 12px;
    width: 16px;
    height: 16px;
    color: var(--color-text-light);
    pointer-events: none;
}

.filterbar__search input {
    width: 100%;
    padding-left: 38px;
}

.filterbar__panel {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--spacing-16);
    padding: var(--spacing-16);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-md);
    box-shadow: var(--shadow-sm);
}

.filterbar__panel .form-group {
    margin-bottom: 0;
    min-width: 160px;
    flex: 1 1 160px;
}

.filterbar__panel-actions {
    display: flex;
    gap: var(--spacing-8);
    align-items: center;
}

.filterbar__chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-8);
    align-items: center;
}

.filterbar__chips-label {
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-light);
}

.filterbar__clear {
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-bold);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-4);
    padding: var(--spacing-2) var(--spacing-4) var(--spacing-2) var(--spacing-8);
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
}

.chip__x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    color: var(--color-text-light);
    font-size: 15px;
    line-height: 1;
    text-decoration: none;
}

.chip__x:hover {
    background: var(--color-border);
    color: var(--color-text);
    text-decoration: none;
}

/* Mobile/tablet: one control per row instead of a cramped multi-column
   wrap  the filter bar is always visible now (no toggle to collapse it
   out of the way first), so it needs to read cleanly at every width. */
@media (max-width: 767.98px) {
    .filterbar__main {
        flex-direction: column;
        align-items: stretch;
    }

    .filterbar__search {
        flex-basis: auto;
    }

    .filterbar__panel {
        flex-direction: column;
        align-items: stretch;
    }

    .filterbar__panel .form-group {
        /* Reset the desktop row's flex-basis: 160px  in this column
           layout flex-basis sizes height, not width, and left unset here
           it was stretching every field to a 160px-tall box. */
        flex: 0 1 auto;
        min-width: 0;
        width: 100%;
    }

    .filterbar__panel-actions .btn {
        width: 100%;
    }
}

/* =====================================================================
 * GRID SYSTEM
 * Simple flexbox-based grid for flexible layouts
 * Usage:
 *   <div class="grid grid-cols-2">
 *     <div class="grid-item">...</div>
 *     <div class="grid-item">...</div>
 *   </div>
 * ===================================================================== */

.grid {
    display: grid;
    gap: var(--spacing-24);
    margin-bottom: var(--spacing-24);
}

.grid-cols-1 {
    grid-template-columns: 1fr;
}

.grid-cols-2 {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid-cols-3 {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.grid-item {
    /* content styles handled by .card or other components */
}

/* =====================================================================
 * RESPONSIVE BREAKPOINTS
 * ===================================================================== */

@media (min-width: 768px) {
    /* Tablet and up: show sidebar, use side-by-side layout */
    .admin-layout {
        flex-direction: row;
    }

    .sidebar {
        display: block !important;
        width: 250px;
        flex-shrink: 0;
        transition: width 0.2s ease;
    }

    /* Desktop collapse toggle (components.css's .sidebar-toggle)  only
       makes sense once the sidebar is a real side-by-side column, so it
       stays hidden below this breakpoint; the mobile hamburger covers
       show/hide there instead. */
    .sidebar-toggle {
        display: flex;
    }

    /* Icon-only collapsed rail. Labels, the group expand arrow, and
       submenus all hide  a 64px rail has no room for a flyout, so
       initSidebarCollapse() (assets/js/ui.js) expands the sidebar back
       out and opens the group instead when its icon is clicked. */
    .sidebar.sidebar-collapsed {
        /* components.css's base .sidebar has an unconditional
           min-width:240px (sized for the full label+icon layout)  it
           wins over this width unless overridden here too, which is
           what kept the "collapsed" rail stuck at 240px. */
        width: 64px;
        min-width: 64px;
    }

    .sidebar.sidebar-collapsed .sidebar-toggle {
        margin: 0 auto var(--spacing-8);
    }

    .sidebar.sidebar-collapsed .sidebar-menu a span,
    .sidebar.sidebar-collapsed .nav-group__summary span,
    .sidebar.sidebar-collapsed .nav-group__summary::after {
        display: none;
    }

    .sidebar.sidebar-collapsed .sidebar-menu a,
    .sidebar.sidebar-collapsed .nav-group__summary {
        justify-content: center;
        padding: 9px;
    }

    .sidebar.sidebar-collapsed .nav-group__menu {
        display: none !important;
    }

    .sidebar.sidebar-collapsed .nav-divider {
        margin-left: var(--spacing-8);
        margin-right: var(--spacing-8);
    }

    .main-content {
        padding: var(--spacing-32);
    }

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

    .toolbar-search {
        max-width: 400px;
    }

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

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

@media (min-width: 1024px) {
    /* Desktop: larger padding, wider main content area */
    .main-content {
        padding: var(--spacing-48);
    }

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

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

    .toolbar-actions {
        justify-content: flex-start;
    }
}

/* =====================================================================
 * UTILITY CLASSES
 * ===================================================================== */

.mt-8 { margin-top: var(--spacing-8); }
.mt-16 { margin-top: var(--spacing-16); }
.mt-24 { margin-top: var(--spacing-24); }
.mt-32 { margin-top: var(--spacing-32); }

.mb-8 { margin-bottom: var(--spacing-8); }
.mb-16 { margin-bottom: var(--spacing-16); }
.mb-24 { margin-bottom: var(--spacing-24); }
.mb-32 { margin-bottom: var(--spacing-32); }

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-muted { color: var(--color-text-light); }
.text-bold { font-weight: var(--font-weight-bold); }

.display-none { display: none; }
.display-block { display: block; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}
