/**
 * DriveAI Layout System — layout.css
 * ====================================
 * Depends on: design-system.css (must load first)
 *
 * Contents:
 *   1. Page shell (.da-page)
 *   2. Container system (.da-container-*)
 *   3. Section patterns (.da-section-*)
 *   4. Grid framework (.da-grid-*)
 *   5. Flex utilities (.da-flex-*)
 *   6. Navbar layout overrides
 *   7. Sidebar layout (.da-layout-sidebar)
 *   8. Auth layout (.da-layout-auth)
 *   9. Dashboard layout (.da-layout-dashboard)
 *  10. Responsive breakpoints summary (comment block)
 */


/* ============================================================
   BREAKPOINTS (reference — used in media queries below)
   xs:   < 480px   (tiny phones)
   sm:   ≥ 480px   (phones)
   md:   ≥ 768px   (tablets)
   lg:   ≥ 1024px  (laptops)
   xl:   ≥ 1280px  (desktops)
   2xl:  ≥ 1536px  (wide screens)
   ============================================================ */


/* ============================================================
   1. PAGE SHELL
   ============================================================ */
.da-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

.da-page__main {
  flex: 1 1 auto;
  padding-top: var(--space-6);
  padding-bottom: var(--space-12);
}

/* Full-width sections that break out of constrained content */
.da-page__section--full {
  width: 100%;
}


/* ============================================================
   2. CONTAINER SYSTEM
   ============================================================ */
.da-container {
  width: 100%;
  max-width: 1280px;
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.da-container--sm  { max-width: 640px;  }
.da-container--md  { max-width: 768px;  }
.da-container--lg  { max-width: 1024px; }
.da-container--xl  { max-width: 1280px; }
.da-container--2xl { max-width: 1536px; }
.da-container--full{ max-width: none;   }

@media (min-width: 480px) {
  .da-container {
    padding-inline: var(--space-5);
  }
}

@media (min-width: 768px) {
  .da-container {
    padding-inline: var(--space-6);
  }
}

@media (min-width: 1280px) {
  .da-container {
    padding-inline: var(--space-8);
  }
}


/* ============================================================
   3. SECTION PATTERNS
   ============================================================ */

/* Standard content section with vertical breathing room */
.da-section {
  padding-block: var(--space-16);
}

.da-section--sm {
  padding-block: var(--space-8);
}

.da-section--lg {
  padding-block: var(--space-24);
}

/* Hero — full viewport or near-full */
.da-section--hero {
  padding-block: var(--space-20);
  min-height: 85vh;
  display: flex;
  align-items: center;
}

/* Colored band sections */
.da-section--brand {
  background: var(--gradient-brand);
  color: var(--text-on-brand);
}

.da-section--muted {
  background-color: var(--bg-secondary);
}

.da-section--dark {
  background-color: var(--bg-inverse);
  color: var(--text-inverse);
}

/* Section heading group — icon + title + subtitle */
.da-section__header {
  text-align: center;
  margin-bottom: var(--space-12);
}

.da-section__eyebrow {
  display: inline-block;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-widest);
  text-transform: uppercase;
  color: var(--text-brand);
  margin-bottom: var(--space-3);
}

.da-section--brand .da-section__eyebrow,
.da-section--dark .da-section__eyebrow {
  color: var(--palette-accent-300);
}

.da-section__title {
  font-size: var(--text-4xl);
  font-weight: var(--font-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-4);
}

.da-section__subtitle {
  font-size: var(--text-xl);
  color: var(--text-secondary);
  max-width: 640px;
  margin-inline: auto;
  line-height: var(--leading-relaxed);
}

.da-section--brand .da-section__subtitle,
.da-section--dark .da-section__subtitle {
  color: rgba(255, 255, 255, 0.75);
}

@media (max-width: 767px) {
  .da-section          { padding-block: var(--space-10); }
  .da-section--lg      { padding-block: var(--space-16); }
  .da-section--hero    { padding-block: var(--space-16); min-height: 70vh; }
  .da-section__title   { font-size: var(--text-3xl); }
  .da-section__subtitle{ font-size: var(--text-lg); }
  .da-section__header  { margin-bottom: var(--space-8); }
}


/* ============================================================
   4. GRID FRAMEWORK
   ============================================================ */

/* Auto-responsive card grid — no breakpoint classes needed */
.da-grid {
  display: grid;
  gap: var(--space-6);
}

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

.da-grid--2 {
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .da-grid--2 { grid-template-columns: repeat(2, 1fr); }
}

.da-grid--3 {
  grid-template-columns: 1fr;
}
@media (min-width: 640px) {
  .da-grid--3 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .da-grid--3 { grid-template-columns: repeat(3, 1fr); }
}

.da-grid--4 {
  grid-template-columns: 1fr;
}
@media (min-width: 480px) {
  .da-grid--4 { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .da-grid--4 { grid-template-columns: repeat(4, 1fr); }
}

/* Auto-fill — good for card galleries (min 260px wide) */
.da-grid--auto {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

/* Gap modifiers */
.da-grid--gap-sm  { gap: var(--space-4); }
.da-grid--gap-lg  { gap: var(--space-8); }
.da-grid--gap-xl  { gap: var(--space-12); }


/* ============================================================
   5. FLEX UTILITIES
   ============================================================ */
.da-flex        { display: flex; }
.da-flex--center { display: flex; align-items: center; justify-content: center; }
.da-flex--between { display: flex; align-items: center; justify-content: space-between; }
.da-flex--col   { display: flex; flex-direction: column; }
.da-flex--wrap  { display: flex; flex-wrap: wrap; gap: var(--space-3); }

.da-flex__grow  { flex: 1 1 auto; }
.da-flex__shrink{ flex: 0 0 auto; }


/* ============================================================
   6. NAVBAR LAYOUT OVERRIDES
   Override Bootstrap navbar to use design tokens.
   ============================================================ */
.navbar {
  /* Toggler (hamburger) vars live HERE, not on :root. Bootstrap 5.3.3 declares
     --bs-navbar-toggler-* inside its own `.navbar{...}`; `.navbar-toggler-icon`
     is a descendant, and an inherited custom property takes its value from the
     NEAREST ancestor that declares it. So `.navbar` beats `:root`,
     `[data-theme="dark"]` and the prefers-color-scheme mirror however specific
     those are — the dark overrides used to sit in those blocks and reached
     nothing, leaving a near-black glyph on the near-black dark navbar at
     1.11:1 (reported from a phone, 2026-09-18). These light values restate
     Bootstrap's own defaults so all three theme paths are visible together and
     a vendor upgrade cannot move light mode silently; design-system.css loads
     before this file, and this rule ties with Bootstrap's on specificity and
     wins on source order. They are restated VERBATIM: the icon URL is
     byte-identical to Bootstrap's and the border keeps Bootstrap's own
     --bs-emphasis-color-rgb expression (0,0,0 in light), so light mode is
     unchanged. The dead :root copy this replaces had drifted to a literal
     rgba(33, 37, 41, 0.15) — it never reached the toggler, so nobody noticed.
     Guarded by tests/test_dark_mode_chrome_contrast.py, which resolves the
     property the way the cascade does rather than trusting the declaration. */
  --bs-navbar-toggler-border-color: rgba(var(--bs-emphasis-color-rgb), 0.15);
  --bs-navbar-toggler-icon-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%2833, 37, 41, 0.75%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
  background-color: var(--bg-primary) !important;
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xs);
  transition: var(--transition-colors);
  padding-block: var(--space-3);
}

.navbar > .da-container {
  display: flex;
  flex-wrap: inherit;
  align-items: center;
  justify-content: space-between;
}

.navbar-brand {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--text-brand) !important;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  letter-spacing: var(--tracking-tight);
}

.navbar-brand .da-brand-logo {
  width: 32px;
  height: 32px;
}

.navbar-nav .nav-link {
  color: var(--text-secondary) !important;
  font-weight: var(--font-medium);
  font-size: var(--text-sm);
  padding-inline: var(--space-3);
  transition: color var(--duration-normal) var(--ease-default);
  position: relative;
}

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link:focus {
  color: var(--text-brand) !important;
}

/* Active underline indicator */
.navbar-nav .nav-link.active {
  color: var(--text-brand) !important;
}

.navbar-nav .nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: var(--space-3);
  right: var(--space-3);
  height: 2px;
  background-color: var(--bg-brand);
  border-radius: var(--radius-full);
}

/* Dropdown */
.dropdown-menu {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-xl);
  padding: var(--space-2);
  min-width: 200px;
}

.dropdown-item {
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  transition: var(--transition-colors);
}

.dropdown-item:hover,
.dropdown-item:focus {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.dropdown-divider {
  border-color: var(--border-subtle);
  margin: var(--space-2) 0;
}

/* Sticky navbar with blur backdrop */
.da-navbar--sticky {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background-color: rgba(255, 255, 255, 0.85) !important;
}

[data-theme="dark"] .da-navbar--sticky {
  background-color: rgba(17, 24, 39, 0.85) !important;
}

/* Dark hamburger — white stroke + light border. Scoped to .navbar for the
   reason spelled out on the .navbar rule above: on :root it is shadowed by
   Bootstrap's own .navbar declaration and never reaches the icon. */
[data-theme="dark"] .navbar {
  --bs-navbar-toggler-border-color: rgba(255, 255, 255, 0.2);
  --bs-navbar-toggler-icon-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.85%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .da-navbar--sticky {
    background-color: rgba(17, 24, 39, 0.85) !important;
  }

  /* Mirror of the [data-theme="dark"] toggler rule above — a dark OS
     preference gets the same white-stroke icon. */
  :root:not([data-theme="light"]) .navbar {
    --bs-navbar-toggler-border-color: rgba(255, 255, 255, 0.2);
    --bs-navbar-toggler-icon-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.85%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
  }
}


/* ============================================================
   7. SIDEBAR LAYOUT — app pages (dashboard, diagnostics)
   ============================================================ */
.da-layout-dashboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-6);
  align-items: start;
}

@media (min-width: 1024px) {
  .da-layout-dashboard {
    grid-template-columns: 2fr 1fr;
  }

  .da-layout-dashboard--reverse {
    grid-template-columns: 1fr 2fr;
  }
}

.da-layout-dashboard__main {
  min-width: 0; /* prevent grid blowout */
}

.da-layout-dashboard__aside {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}


/* ============================================================
   8. AUTH LAYOUT — centered card for login/register
   ============================================================ */
.da-layout-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 72px); /* subtract navbar */
  padding: var(--space-8) var(--space-4);
}

.da-layout-auth__card {
  width: 100%;
  max-width: 440px;
}

.da-layout-auth__card--wide {
  max-width: 560px;
}

/* Consent card: the sign-up consent + optionals screen. unified_auth.html's
   showState() adds this modifier only while the register / consent states are
   shown. Below 768px the card is full width inside the .da-layout-auth gutters
   and the optional consent controls are a single column; from 768px it widens
   to 760px so the consent text wraps less. The account-type toggle is not
   restyled here: it keeps its base side-by-side columns (components.css) at
   every width, so the phone layout stays short. */
.da-layout-auth__card--consent {
  max-width: none;
}

.da-layout-auth__card--consent .da-consent-options {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

.da-layout-auth__card--consent .da-consent-options > .da-consent-option + .da-consent-option {
  margin-top: 0;
}

@media (min-width: 768px) {
  .da-layout-auth__card--consent {
    max-width: 760px;
  }

  .da-layout-auth__card--consent .da-consent-options {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }
}


/* ============================================================
   9. STATS ROW — horizontal metric strip
   ============================================================ */
.da-stats-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
}

@media (min-width: 768px) {
  .da-stats-row {
    grid-template-columns: repeat(4, 1fr);
  }
}


/* ============================================================
   10. FOOTER LAYOUT
   ============================================================ */
.da-footer {
  /* FIXED INK on purpose — NOT var(--bg-inverse). --bg-inverse flips by design
     (gray-950 light -> gray-50 dark) while every foreground in this section is
     a hardcoded white, so in dark mode the whole footer rendered
     white-on-near-white at ~1.04:1 (reported from a phone, 2026-09-18). Same
     family as the #598 hero fix, mirrored: there a FLIPPING text token sat on
     a FIXED ink surface. The footer is an ink slab in every theme by design,
     so its surface must not flip either.
     Guarded by tests/test_dark_mode_chrome_contrast.py. */
  background-color: var(--palette-gray-950);
  color: rgba(255, 255, 255, 0.75);
  padding-block: var(--space-12);
  margin-top: auto;
}

.da-footer__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-8);
}

@media (min-width: 768px) {
  .da-footer__grid {
    grid-template-columns: 2fr 1fr 1fr;
  }
}

.da-footer__brand {
  color: #ffffff;
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.da-footer__tagline {
  font-size: var(--text-sm);
  color: rgba(255, 255, 255, 0.55);
  line-height: var(--leading-relaxed);
}

.da-footer__heading {
  color: #ffffff;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin-bottom: var(--space-4);
}

.da-footer__links {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.da-footer__links a {
  color: rgba(255, 255, 255, 0.60);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: color var(--duration-normal) var(--ease-default);
}

.da-footer__links a:hover {
  color: #ffffff;
}

.da-footer__divider {
  border-color: rgba(255, 255, 255, 0.12);
  margin-block: var(--space-8);
}

.da-footer__bottom {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  align-items: center;
  text-align: center;
  font-size: var(--text-xs);
  /* 0.40 measured 3.77:1 on the ink slab — below AA for 12px text even before
     the dark-mode defect above. 0.55 is 6.28:1. */
  color: rgba(255, 255, 255, 0.55);
}

@media (min-width: 768px) {
  .da-footer__bottom {
    flex-direction: row;
    justify-content: space-between;
  }
}
