/* ========================================
   APP FOUNDATION
   Design tokens + shared primitives used by every page.
   Loaded after style.css / navbar.css and before page CSS,
   so page stylesheets can still override anything here.
   ======================================== */

:root {
  /* Shell dimensions */
  --shell-sidebar-w: 240px;
  --shell-rail-w: 76px;
  --shell-topbar-h: 56px;
  --shell-tabbar-h: 64px;
  --shell-nav-offset: 0px;          /* left offset taken by sidebar/rail */
  --shell-bottom-offset: 0px;       /* bottom space taken by tab bar */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  /* Surfaces (layered on --bg-color) */
  --surface-chrome: #4a5d4f;        /* sidebar / tab bar */
  --surface-1: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.1);
  --surface-3: rgba(255, 255, 255, 0.14);
  --surface-sunken: rgba(0, 0, 0, 0.12);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-default: rgba(255, 255, 255, 0.14);
  --border-strong: rgba(255, 255, 255, 0.24);

  /* Text */
  --text-strong: rgba(255, 255, 255, 0.96);
  --text-default: rgba(247, 249, 249, 0.9);
  --text-subtle: rgba(247, 249, 249, 0.68);
  --text-faint: rgba(247, 249, 249, 0.5);

  /* Spacing scale (4px base) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Page gutters: 16px on phones, growing with the viewport */
  --page-gutter: clamp(1rem, 3vw, 2rem);
  --page-max: 80rem;
  --grid-gap: clamp(0.75rem, 1.6vw, 1.25rem);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.12);
  --shadow-2: 0 4px 16px rgba(0, 0, 0, 0.14);
  --shadow-3: 0 12px 32px rgba(0, 0, 0, 0.22);

  /* Type */
  --font-sans: 'Tide Sans', 'Poppins', system-ui, sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: clamp(1.5rem, 1.2rem + 1.2vw, 2rem);

  /* Motion */
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 120ms;
  --dur-base: 200ms;

  /* Focus */
  --focus-ring: 0 0 0 2px var(--bg-color, #576C5C), 0 0 0 4px var(--yellow-light, #FFC051);
}

/* ========================================
   BASE
   ======================================== */

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--shell-topbar-h) + var(--safe-top) + 0.5rem);
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Comfortable touch targets for form controls on coarse pointers */
@media (pointer: coarse) {
  :where(input:not([type="checkbox"]):not([type="radio"]), select, button) {
    min-height: 44px;
  }
  /* Prevent iOS zoom-on-focus */
  :where(input, select, textarea) {
    font-size: max(16px, 1em);
  }
}

/* The floating blurred circles are decorative; skip them for reduced motion */
@media (prefers-reduced-motion: reduce) {
  .bg-animation { display: none; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================
   PAGE SCAFFOLD
   .app-page is the standard content column inside the shell.
   ======================================== */

.app-page {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--space-6) var(--page-gutter) var(--space-10);
}

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

.app-page-title {
  font-family: var(--font-sans);
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-transform: none; /* fonts.css uppercases every h1/h2 */
  color: var(--text-strong);
  margin: 0;
}

.app-page-subtitle {
  margin: var(--space-1) 0 0;
  font-size: var(--text-sm);
  color: var(--text-subtle);
}

/* Section eyebrow label */
.app-eyebrow {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ========================================
   CARD
   ======================================== */

.app-card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  min-width: 0;
}

.app-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.app-card-title {
  text-transform: none;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-strong);
  margin: 0;
}

.app-card-body {
  padding: var(--space-4) var(--space-5);
}

/* ========================================
   KPI / STAT TILE
   ======================================== */

.app-kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.app-kpi-value {
  font-size: clamp(1.375rem, 1.1rem + 1vw, 1.875rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--yellow-light, #FFC051);
  font-variant-numeric: tabular-nums;
}

.app-kpi-label {
  font-size: var(--text-xs);
  color: var(--text-subtle);
}

/* ========================================
   SITE FOOTER (all pages render a plain <footer>)
   ======================================== */

body > footer,
body > .container > footer,
.app-page > footer {
  color: var(--text-faint);
}

body > footer a,
body > .container > footer a,
.app-page > footer a {
  color: var(--text-subtle);
}

/* Utility: visually hidden but available to screen readers */
.sr-only-app {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
