/* ==========================================================================
   Layout Utilities — Flex, Grid, and Accessibility
   ColorFlow / Walmart CSI Compass
   Uses CSS custom properties from variables.css
   ========================================================================== */

/* ---- Alpine.js cloak — prevent flash of unstyled content ---- */
[x-cloak] { display: none !important; }

/* ---- Reduced motion (WCAG 2.3.3) — respect user preference ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Sticky footer — pushes footer to viewport bottom on short pages ---- */
html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
}

#wrapper {
  flex: 1 0 auto;
  overflow: visible;  /* override default.css overflow:hidden — breaks sticky & clips dropdowns */
}

#footer {
  flex-shrink: 0;
}

/* ---- Skip-to-content link (accessibility) ---- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  z-index: var(--z-toast);
  padding: var(--space-sm) var(--space-lg);
  background-color: var(--color-nav-bg);
  color: var(--color-nav-text-active);
  font-family: var(--font-family);
  font-size: var(--font-size-md);
  text-decoration: none;
  border-radius: 0 0 4px 4px;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid var(--color-blue);
  outline-offset: 2px;
}

/* ---- Header bar — logo + user nav in a refined top strip ---- */
.header-bar {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: 8px 16px;
  background: linear-gradient(135deg, #fafbfc 0%, #f4f5f7 100%);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  position: relative;
}

/* Subtle orange accent line at bottom of header bar */
.header-bar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--color-orange) 0%, var(--color-orange-light) 40%, transparent 80%);
  opacity: 0.6;
}

.header-bar .logo {
  flex-shrink: 0;
  width: 200px;
}

.header-bar .logo a {
  display: block;
}

.header-bar .logo img {
  width: 200px;
  height: auto;
  display: block;
}

.header-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: auto;
  font-family: var(--font-heading);
}

.header-nav a.sel {
  color: var(--color-text-secondary);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background 180ms ease, color 180ms ease, box-shadow 180ms ease;
  white-space: nowrap;
}

/* Dot separators between nav links (replacing pipe) */
.header-nav a.sel + a.sel::before {
  content: "\00B7";
  color: var(--color-border-light);
  margin-right: 6px;
  font-weight: bold;
  font-size: 16px;
}

.header-nav a.sel:hover,
.header-nav .logout-btn:hover {
  background: rgba(210, 123, 26, 0.08);
  color: var(--color-text-primary);
}

.header-nav .logout-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--color-text-secondary);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background 180ms ease, color 180ms ease;
  white-space: nowrap;
}

.header-user {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--color-text-primary);
  padding: 4px 12px 4px 0;
  font-size: 13px;
  border-right: 1px solid var(--color-border);
  margin-right: 4px;
  letter-spacing: -0.01em;
}

/* ---- Page title bar — orange left accent ---- */
#content .sub_tit {
  font-family: var(--font-heading);
  font-size: 17px;
  font-weight: 700;
  color: #1a1d23;
  letter-spacing: -0.02em;
  border-left: 3px solid var(--color-orange);
  border-bottom: none;
  padding: 6px 0 6px 14px;
  margin-bottom: 18px;
  line-height: 1.3;
}

/* Empty sub_tit — collapse margin */
#content .sub_tit:empty {
  display: none;
}

/* Loading status indicator (centered floating) */
#status1 {
  position: sticky;
  top: 20px;
  z-index: var(--z-sticky);
  text-align: center;
  width: 90px;
  margin: auto;
  height: 0;           /* collapse when empty; grows via content/JS */
  line-height: 18px;
  overflow: hidden;
}

/* Empty menu div — kill legacy margin from default.css */
#header .menu:empty {
  margin: 0;
}

/* Override legacy #header styles (default.css) */
#header {
  margin-bottom: 0;
  overflow: visible;
  border-bottom: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.03);
}

/* ---- Footer — refined bottom bar ---- */
#footer {
  border-top: 1px solid #e8eaed;
  margin: 24px 0 0 0;
  padding: 14px 20px;
  background: linear-gradient(180deg, #f8f9fa 0%, #f1f3f5 100%);
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  overflow: visible;
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  max-width: 700px;
  margin: 0 auto;
}

.footer-logo {
  height: 22px;
  width: auto;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 200ms ease;
}

.footer-logo:hover {
  opacity: 1;
}

.footer-text {
  line-height: 22px;
  letter-spacing: 0.01em;
}

/* ---- Override legacy float-based header styles from default.css ---- */
#header .logo {
  float: none;
  width: auto;
  margin-left: 0;
}

#header .status {
  float: none;
  margin-left: 0;
  margin-top: 0;
  padding: 0;
}

/* #content — centered container with fluid max-width */
#content {
  overflow: visible;
  max-width: min(1400px, 92vw);
  margin-left: auto;
  margin-right: auto;
  padding: 16px 16px 24px;
}

/* Wide content pages (workflow, admin tables) — fill available width on any screen */
#content.content-wide {
  max-width: 96vw;
}

/* Override legacy .forms overflow:hidden — clips focus outlines */
#content .forms {
  overflow: visible;
}

/* ---- Single-column forms (login, password recover) — comfortable width ---- */
#content .forms .row {
  width: 100%;
  max-width: 420px;
}

/* Slightly wider forms on large desktops */
@media (min-width: 1440px) {
  #content .forms .row {
    max-width: 480px;
  }
}

/* Link color — WCAG AA contrast fix (default.css sets #999 = 2.85:1, need 4.5:1) */
a {
  color: var(--color-text-secondary);  /* #666 = 5.74:1 contrast on white */
}

a:hover {
  color: var(--color-text-primary);
}

/* ---- Global Focus States (WCAG 2.1 — keyboard navigation) ---- */
/* Visible only on keyboard focus, not mouse click */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-blue);
  outline-offset: 2px;
}

/* Remove default outline for mouse users */
a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
  outline: none;
}

/* Checkbox and radio get subtle ring */
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 2px solid var(--color-blue);
  outline-offset: 1px;
}

/* Button focus — add box-shadow for styled buttons */
.but:focus-visible {
  outline: 2px solid var(--color-blue);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(69, 151, 201, 0.2);
}

/* ---- Home page hero image — responsive override ---- */
#content .home .cycle {
  width: 100%;
  max-width: min(1200px, 100%);
  height: auto;
  margin: var(--space-lg) auto;
  border: none;
}

#content .home .cycle img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 2px;
}

/* ---- Active nav link ---- */
.header-nav a.sel.nav-active {
  color: var(--color-orange);
  font-weight: 600;
  background: rgba(210, 123, 26, 0.08);
}

.header-nav a.sel.nav-active:hover {
  background: rgba(210, 123, 26, 0.14);
  color: var(--color-orange);
}

/* ---- Typography: Outfit on headings and buttons ---- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--color-text-primary);
}

.but, button[type="submit"], input[type="submit"] {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ---- Footer: compact stacked on small phones ---- */
@media (max-width: 480px) {
  .footer-inner {
    flex-direction: column;
    gap: 8px;
  }
  .footer-logo {
    height: 18px;
  }
  .footer-text {
    font-size: 10px;
    line-height: 1.4;
  }
}

/* ---- Registration forms: 2-column grid on desktop ---- */
@media (min-width: 769px) {
  #reg_form .forms {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0 var(--space-xxl);
    max-width: 720px;
  }

  #reg_form .forms .row {
    width: auto;
  }

  #reg_form .forms .row input[type="text"],
  #reg_form .forms .row input[type="password"],
  #reg_form .forms .row input[type="email"],
  #reg_form .forms .row select {
    width: 100%;
    box-sizing: border-box;
  }

  /* Checkbox/radio/submit/date-format rows span full width */
  #reg_form .forms .row:has(input[type="checkbox"]),
  #reg_form .forms .row:has(input[type="radio"]),
  #reg_form .forms .row:has(input[type="submit"]),
  #reg_form .forms .row:has(#date_format) {
    grid-column: 1 / -1;
  }
}

/* ---- Flexbox utilities ---- */
.flex          { display: flex; }
.flex-col      { display: flex; flex-direction: column; }
.flex-wrap     { display: flex; flex-wrap: wrap; }
.flex-center   { display: flex; align-items: center; justify-content: center; }
.flex-between  { display: flex; align-items: center; justify-content: space-between; }
.flex-gap-sm   { gap: var(--space-sm); }
.flex-gap-md   { gap: var(--space-md); }
.flex-gap-lg   { gap: var(--space-lg); }

/* ---- Grid utilities ---- */
.grid   { display: grid; gap: var(--space-md); }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-md); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-md); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-md); }

/* ---- Responsive form grid ---- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--form-width), 1fr));
  gap: var(--space-lg) var(--space-xxl);
}

/* ---- Responsive collapse for grids ---- */
@media (max-width: 768px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}
