/* ⚠️ SCROLL GUARD — DO NOT add overflow:hidden to html, body, or main containers.
   This has caused 4+ regressions: #1515954, #1524323, #1524842, #1534925.
   If you need overflow:hidden for a specific component, scope it to that component ONLY.
   Only body gets overflow-x:hidden (line ~247). Do NOT set overflow on html —
   CSS spec forces overflow-y to compute as auto, creating a competing scroll container. */

/* ────────────────────────────────────────────────────────────
   Prizinity Global Contrast Enforcement
   ────────────────────────────────────────────────────────────
   Dark-theme safety net: ensures ALL text, buttons, inputs,
   links, and dynamically created elements are readable on the
   site's dark (#0D0D1A) background.

   Injected into every page via serveHtml() in server.js.
   Uses element-level selectors as FALLBACKS — page-specific
   class rules override these naturally via specificity.

   LAST UPDATED: 2026-04-30
   ──────────────────────────────────────────────────────────── */

/* ── Color-scheme hint: tells browser we're dark ───────────── */
html {
  color-scheme: dark;
}

/* ── Body text default ─────────────────────────────────────── */
body {
  color: #FAFAFA;
}

/* ── Links: inherit parent color instead of browser blue ───── */
a {
  color: inherit;
}

/* ── All interactive elements: inherit light text ──────────── */
/* Browser UA stylesheets set button/input/select to black.    */
/* This override ensures they inherit body's #FAFAFA instead.  */
button,
input,
select,
textarea,
optgroup {
  color: inherit;
}

/* (Old option rule removed — covered by Dropdown Global Standard below) */

/* ── Placeholder text: readable on dark backgrounds ────────── */
::placeholder {
  color: rgba(255, 255, 255, 0.5);
  opacity: 1; /* Firefox sets lower opacity by default */
}
::-webkit-input-placeholder { color: rgba(255, 255, 255, 0.5); }
::-moz-placeholder { color: rgba(255, 255, 255, 0.5); opacity: 1; }

/* ── Unstyled buttons: glass fallback so they're visible ───── */
/* Targets buttons without any CSS class applied.              */
/* Buttons WITH classes get their styling from page CSS.       */
button:not([class]):not([style*="background"]) {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, border-color 0.2s;
}
button:not([class]):not([style*="background"]):hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

/* ── Unstyled links: ensure visibility ─────────────────────── */
/* Links without class get a subtle light treatment.           */
a:not([class]):not([style*="color"]) {
  color: rgba(255, 255, 255, 0.85);
  text-decoration-color: rgba(255, 255, 255, 0.3);
}
a:not([class]):not([style*="color"]):hover {
  color: #FAFAFA;
}

/* ── Form inputs: ensure text is light on dark bg ──────────── */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="submit"]):not([type="button"]),
select,
textarea {
  color: #FAFAFA;
}

/* ── Dropdown Global Standard ──────────────────────────────── */
/* Enforces readable, tappable dropdowns on EVERY page.        */
/* Uses !important to override per-page inline styles and      */
/* class rules that previously reverted dropdowns to tiny font. */
/* Minimum 16px prevents iOS auto-zoom on focus.               */
/* Padding 12px ensures comfortable mobile tap targets.        */
select,
.form-select,
.filter-select {
  font-size: 16px !important;
  color: #FFFFFF !important;
  padding: 12px 16px !important;
  font-family: inherit;
}

/* ── Dropdown options: explicit dark bg + light text ───────── */
/* Options ignore inherited color on many browsers.            */
select option,
.form-select option,
.filter-select option {
  background: #1a1a35 !important;
  color: #FFFFFF !important;
  font-size: 16px !important;
  padding: 10px 12px;
}

/* ── Date/time input icons ─────────────────────────────────── */
::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.2);
  cursor: pointer;
}

/* ── Autofill: prevent browser from setting dark bg ────────── */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: #FAFAFA;
  transition: background-color 5000s ease-in-out 0s;
  caret-color: #FAFAFA;
}

/* ── Scrollbar: dark-themed ────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ── Table text ────────────────────────────────────────────── */
th, td {
  color: inherit;
}

/* ── Details/summary elements ──────────────────────────────── */
summary {
  color: inherit;
  cursor: pointer;
}

/* ── hr: visible on dark backgrounds ───────────────────────── */
hr {
  border-color: rgba(255, 255, 255, 0.1);
}

/* ── fieldset/legend ───────────────────────────────────────── */
legend {
  color: inherit;
}

/* ── Escape hatch: .light-bg sections ──────────────────────── */
/* Use on containers with white/light backgrounds              */
/* (e.g., flyer preview areas, print views).                   */
/* Uses !important to override the dropdown global standard.   */
.light-bg,
.light-bg input,
.light-bg select,
.light-bg .form-select,
.light-bg .filter-select,
.light-bg textarea,
.light-bg button,
.light-bg a,
.light-bg th,
.light-bg td {
  color: #1a1a1a !important;
}
.light-bg option,
.light-bg select option,
.light-bg .form-select option {
  background: #fff !important;
  color: #1a1a1a !important;
}
.light-bg ::placeholder {
  color: rgba(0, 0, 0, 0.45);
}

/* ── Nav Brand — dynamic logo loaded via /api/logo ────────── */
/* Logo is loaded dynamically by inline JS on each page (fetches /api/logo).
   No ::before pseudo-element — that caused duplicate logos on every page. */
.top-nav-brand,
.header-brand {
  display: inline-flex !important;
  align-items: center !important;
  text-decoration: none !important;
}
/* Logo img styling — consistent sizing for the dynamic <img> */
.top-nav-brand img,
.header-brand img {
  height: 28px !important;
  width: auto !important;
  max-width: 130px !important;
  object-fit: contain !important;
  display: block !important;
  flex-shrink: 0 !important;
}

/* ════════════════════════════════════════════════════════════════════════════
   GLOBAL MOBILE-FIRST RESPONSIVE FRAMEWORK
   ════════════════════════════════════════════════════════════════════════════

   Breakpoints (mobile-first):
   - ≤480px  : Extra-small devices (portrait phone)
   - ≤768px  : Small devices (tablet, landscape phone)
   - >768px  : Desktop

   This framework ensures:
   ✓ All content is readable in portrait mode
   ✓ No horizontal overflow on mobile (body-level only — NOT html)
   ✓ Full vertical + horizontal scroll on mobile (native touch)
   ✓ Flexible layouts scale from mobile → desktop
   ✓ Consistent padding/margins across pages
   ✓ Touch-friendly tap targets (≥48px)

   Applied globally to ALL pages automatically.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Base Mobile-First Defaults (applies to all screens) ────────────── */
* {
  /* Ensure box-sizing includes padding/border in width calculations */
  box-sizing: border-box;
}

html {
  /* Do NOT set overflow on html — it creates a competing scroll container
     on mobile that breaks native touch scrolling (CSS spec: non-visible
     overflow-x forces overflow-y to compute as auto, trapping content). */
  scroll-behavior: smooth;
}

body {
  /* Only body gets overflow-x: hidden to prevent horizontal scroll
     while keeping vertical scroll working natively on mobile */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* Base padding for mobile safety — content won't hit screen edges */
  padding: 0;
  margin: 0;
  /* Flexible width on all devices */
  width: 100%;
  /* Allow body to expand beyond viewport height for scrolling */
  min-height: 100vh;
  /* Prevent text zoom on device rotation */
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* ── Global Images: Responsive by Default ───────────────────────────── */
img, video, svg {
  /* Images never overflow their container */
  max-width: 100%;
  height: auto;
  display: block;
}

/* Picture element: ensure images scale properly */
picture {
  display: block;
  max-width: 100%;
}

/* ── Containers: Responsive Padding ────────────────────────────────── */
/* Core wrapper class for pages — applies smart padding by screen size */
.container,
[role="main"],
main,
section,
article {
  /* Mobile: 1rem padding on each side (safe from edges) */
  padding-left: 1rem;
  padding-right: 1rem;
  /* Prevent container from exceeding viewport */
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}

/* ── Headings: Responsive Font Sizing ──────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  /* Use clamp() for fluid typography that scales with viewport */
  /* Syntax: clamp(mobile_size, preferred_size, max_desktop_size) */
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

h1 {
  /* Mobile: 1.75rem, scales to 2.5rem on desktop */
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  margin-bottom: 1rem;
  line-height: 1.2;
}

h2 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin-bottom: 0.875rem;
  line-height: 1.25;
}

h3 {
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

h4, h5, h6 {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  margin-bottom: 0.625rem;
}

/* ── Paragraphs & Text: Readable Line Length ──────────────────────── */
p, li, dt, dd {
  /* Line length: 65-75 chars (comfort zone) */
  max-width: 65ch;
  /* Better readability */
  line-height: 1.6;
}

/* ── Forms: Mobile-Friendly Input Sizing ──────────────────────────── */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="submit"]):not([type="button"]),
textarea,
select {
  /* Minimum 44px for comfortable mobile tap targets (accessibility) */
  min-height: 44px;
  /* Full width on mobile, constrained on desktop via parent container */
  width: 100%;
  /* Consistent padding for readability */
  padding: 0.75rem 1rem;
  /* Readable font size (≥16px prevents iOS auto-zoom) */
  font-size: 16px;
  /* Rounded corners for modern look */
  border-radius: 8px;
}

/* Button tap targets */
button,
[role="button"],
a.button,
input[type="button"],
input[type="submit"] {
  /* Minimum 48px for comfortable tap targets */
  min-height: 48px;
  min-width: 48px;
  /* Consistent padding */
  padding: 0.75rem 1.5rem;
  /* Readable font size */
  font-size: 16px;
  /* Touch feedback */
  cursor: pointer;
  /* Prevent text selection on long press */
  user-select: none;
  -webkit-user-select: none;
}

/* ── Cards & Content Boxes ─────────────────────────────────────────── */
.card,
[role="article"],
.box,
.panel,
.modal,
.dialog {
  /* Mobile: full width with gutters */
  width: 100%;
  /* Safe padding inside card */
  padding: 1.5rem 1rem;
  /* Breathing room between cards */
  margin-bottom: 1.5rem;
  /* Rounded modern style */
  border-radius: 12px;
}

/* ── Flexible Grids: Mobile → Tablet → Desktop ────────────────────── */
/* Use class="flex-grid" for auto-responsive layouts */
.flex-grid,
[role="grid"] {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.flex-grid > *,
[role="grid"] > * {
  /* Items take full width on mobile */
  width: 100%;
  /* Flexible sizing */
  flex: 1 1 auto;
  min-width: 0; /* Prevent flex items from overflowing */
}

/* ── Spacing Utilities: Consistent Gaps ───────────────────────────── */
.gap-sm { gap: 0.5rem !important; }
.gap-md { gap: 1rem !important; }
.gap-lg { gap: 1.5rem !important; }
.gap-xl { gap: 2rem !important; }

.p-sm { padding: 0.5rem !important; }
.p-md { padding: 1rem !important; }
.p-lg { padding: 1.5rem !important; }
.p-xl { padding: 2rem !important; }

.m-sm { margin: 0.5rem !important; }
.m-md { margin: 1rem !important; }
.m-lg { margin: 1.5rem !important; }
.m-xl { margin: 2rem !important; }

/* ── Tables: Base Defaults ─────────────────────────────────────────── */
/* Keep normal table display by default; mobile stacking handled below. */
table {
  width: 100%;
  border-collapse: collapse;
}

td, th {
  padding: 0.75rem 0.5rem;
  text-align: left;
  word-break: break-word;
}

/* ── Tables: Horizontal scroll wrapper for admin tables ──────────── */
/* Admin pages use .table-scroll-wrap around tables for horizontal scroll. */
.table-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Visibility Utilities ──────────────────────────────────────────── */
.mobile-only {
  display: block !important;
}

.desktop-only {
  display: none !important;
}

/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Tablet & Landscape Phone (>480px) ─────────────────────────────── */
@media (min-width: 481px) {
  .container {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  .card,
  [role="article"],
  .box,
  .panel {
    padding: 2rem 1.5rem;
    margin-bottom: 2rem;
  }

  /* Begin 2-column grid on larger screens */
  .flex-grid-2,
  [role="grid"].cols-2 {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .flex-grid-2 > *,
  [role="grid"].cols-2 > * {
    flex: 1 1 calc(50% - 0.5rem);
  }
}

/* ── Desktop (>768px) ──────────────────────────────────────────────── */
@media (min-width: 769px) {
  .container {
    padding-left: 2rem;
    padding-right: 2rem;
    max-width: 1200px;
  }

  .card,
  [role="article"],
  .box,
  .panel {
    padding: 2.5rem 2rem;
    margin-bottom: 2.5rem;
  }

  body {
    padding: 0;
  }

  /* 3-column grids on desktop */
  .flex-grid-3,
  [role="grid"].cols-3 {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .flex-grid-3 > *,
  [role="grid"].cols-3 > * {
    flex: 1 1 calc(33.333% - 1rem);
  }

  /* Hide mobile-only content */
  .mobile-only {
    display: none !important;
  }

  /* Show desktop-only content */
  .desktop-only {
    display: block !important;
  }

  /* Disable text size adjust on desktop */
  html {
    -webkit-text-size-adjust: 100%;
  }
}

/* ── Extra Small Devices (≤480px) ──────────────────────────────────── */
@media (max-width: 480px) {
  /* Aggressive mobile optimizations for tiny screens */

  .container {
    padding-left: 0.875rem;
    padding-right: 0.875rem;
  }

  h1 {
    font-size: 1.5rem;
    margin-bottom: 0.875rem;
  }

  h2 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
  }

  h3 {
    font-size: 1.1rem;
    margin-bottom: 0.625rem;
  }

  .card,
  [role="article"],
  .box,
  .panel {
    padding: 1.25rem 1rem;
    margin-bottom: 1.25rem;
    border-radius: 10px;
  }

  input,
  textarea,
  select,
  button {
    font-size: 16px; /* Prevent auto-zoom */
    min-height: 44px;
  }

  p, li, dt, dd {
    font-size: 0.95rem;
    line-height: 1.5;
  }
}

/* ── Ensure Leaderboard Works on Mobile ────────────────────────────── */
/* (Preserve existing leaderboard mobile behavior — don't break it) */
.leaderboard-podium,
.leaderboard-scroll,
.scroll-bar-container {
  /* Allow horizontal scroll naturally on mobile */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  width: 100%;
}

/* ════════════════════════════════════════════════════════════════════════════
   SCROLLABLE NAV / TAB BARS ON MOBILE (2026-05-12)
   ════════════════════════════════════════════════════════════════════════════

   FIX: Admin nav bars and tab bars get cut off on narrow screens because
   body has overflow-x:hidden (correct for the page) but nav containers
   had no independent scroll context. This adds horizontal scrolling to
   common nav/tab wrapper classes on mobile so all items are reachable
   by swiping left/right — while the page itself stays locked.

   Does NOT force flex-wrap:nowrap — pages that intentionally wrap their
   nav items (e.g. admin-roles, admin-users) keep wrapping. The overflow-x
   only activates when content actually overflows.
   ════════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .header-nav,
  .nav-tabs,
  .tab-bar {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
    scrollbar-width: none;        /* Firefox */
    -ms-overflow-style: none;     /* IE/Edge */
  }
  .header-nav::-webkit-scrollbar,
  .nav-tabs::-webkit-scrollbar,
  .tab-bar::-webkit-scrollbar {
    display: none;                /* Chrome/Safari */
  }
  /* Prevent nav items from shrinking below their content width */
  .header-nav > *,
  .nav-tabs > *,
  .tab-bar > * {
    flex-shrink: 0;
  }
}

/* ════════════════════════════════════════════════════════════════════════════
   MODAL / OVERLAY SCROLLING FIX (2026-05-11)
   ════════════════════════════════════════════════════════════════════════════

   BUG FIX: Mobile modals were cut off at viewport, making bottom actions
   unreachable. Root cause: Fixed overlays with inset:0 but no scroll handling
   on inner content boxes.

   SOLUTION:
   - All fixed overlays get overflow-y: auto to enable scrolling
   - All modal content boxes get max-height and overflow-y: auto
   - Action button containers get sticky footer positioning
   - Applies to: modals, dialogs, overlays, panels, popups
   ════════════════════════════════════════════════════════════════════════════ */

/* All modal/overlay containers — enable vertical scrolling */
[class*="modal"], [class*="overlay"], [class*="dialog"], [class*="popup"],
.modal-overlay, .category-overlay, .illus-overlay,
.modal-backdrop, .backdrop, [role="dialog"] {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
}

/* All modal/dialog content boxes — ensure scrollability */
[class*="modal-box"], [class*="modal-content"], [class*="modal-body"],
[class*="modal-panel"], [class*="dialog-box"], [class*="dialog-content"],
.modal-box, .modal-content, .modal-body,
.category-panel, .illus-panel,
[role="dialog"] > div:not([role="toolbar"]) {
  max-height: calc(100vh - 2rem) !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
}

/* Modal footers / action buttons — make sticky so always visible */
[class*="modal-footer"], [class*="modal-actions"],
[class*="dialog-footer"], [class*="dialog-actions"],
.modal-actions, .modal-footer,
.category-actions, .illus-actions {
  position: sticky !important;
  bottom: 0 !important;
  background: inherit !important;
  z-index: 10 !important;
  padding-top: 1rem !important;
  border-top: 1px solid rgba(255,255,255,0.08) !important;
}

/* Ensure form inputs and textareas inside modals don't break scroll */
[class*="modal"] input,
[class*="modal"] textarea,
[class*="modal"] select,
[class*="dialog"] input,
[class*="dialog"] textarea,
[class*="dialog"] select {
  max-width: 100% !important;
  width: 100% !important;
}

/* ════════════════════════════════════════════════════════════════════════════
   SQUARE IMAGE SYSTEM (2026-05-14)
   ════════════════════════════════════════════════════════════════════════════

   Profile photos, avatars, sponsor logos, and provider images are always
   displayed as squares (1:1 aspect ratio, cover crop).

   EXCEPTION: Event flyer images keep their natural aspect ratio —
   portrait/tall formats are standard for flyers and must NOT be cropped.
   Flyers use class="event-flyer" or appear inside .event-cover / .event-photo.

   Apply .sq-img or .sq-avatar to any image that should be square.
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Explicit square helpers ──────────────────────────────────────────── */
.sq-img,
.sq-avatar {
  aspect-ratio: 1 / 1 !important;
  object-fit: cover !important;
  overflow: hidden;
}

/* ── Profile / user avatar images ───────────────────────────────────── */
img.profile-img,
img.user-avatar,
img.avatar-img,
img[class*="profile-photo"],
img[class*="profile-pic"],
img[class*="avatar-"] {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

/* ── Sponsor logo images ─────────────────────────────────────────────── */
/* Note: leaderboard sponsor slot images keep natural ratio (brand logos),
   only dedicated sponsor-logo class elements are forced square */
.sponsor-logo img,
img.sponsor-logo,
img.sponsor-img {
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
}

/* ── Provider / Gift Giver profile images ────────────────────────────── */
.provider-photo img,
.provider-avatar img,
img.provider-photo,
img.provider-img,
img.provider-avatar {
  aspect-ratio: 1 / 1;
  object-fit: cover;
}

/* ── Explicit flyer exception: natural aspect ratio kept ─────────────── */
img.event-flyer,
img.event-photo,
.event-cover img,
.event-photo-wrap img,
.event-image img,
img[class*="event-cover"],
img[class*="event-photo"] {
  aspect-ratio: auto !important;  /* override any inherited square rule */
  object-fit: contain !important;
}

/* ── Print Styles: Ensure Readability in Print ─────────────────────── */
@media print {
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  a, a:visited {
    color: #000;
    text-decoration: underline;
  }

  img {
    max-width: 100%;
  }
}
