/*
 * Fair Seat Purchase — enhanced, accessible UI styling (vanilla CSS, no deps).
 *
 * Visual design: a premium ticketing look — a layered gradient backdrop with
 * soft colour glows, frosted-glass panels, gradient price badges and buttons,
 * and a glowing stage. Accessibility is preserved: AA contrast in light & dark,
 * status by glyph + text (not colour alone), always-visible focus, >=44px
 * targets, and respect for prefers-color-scheme / prefers-contrast /
 * prefers-reduced-motion.
 */

:root {
  color-scheme: light dark;

  /* Light theme (default). */
  --bg: #eaeef6;
  --bg-grad-1: #eef2fb;
  --bg-grad-2: #dfe6f5;
  --glow-1: rgba(99, 102, 241, 0.18);   /* indigo */
  --glow-2: rgba(14, 165, 233, 0.16);   /* sky   */
  --glow-3: rgba(168, 85, 247, 0.14);   /* purple */

  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --surface-2: #eef2f7;
  --border: rgba(20, 40, 70, 0.14);
  --border-strong: #c2ccd8;
  --text: #14202e;
  --text-muted: #4a5765;

  --accent: #4338ca;
  --accent-2: #0ea5e9;
  --accent-text: #ffffff;

  --available: #157f37;
  --available-bg: #e6f4ea;
  --available-border: #1a7f37;
  --held: #6b2fb3;
  --held-bg: #efe3fb;
  --held-border: #6b2fb3;
  --sold: #b42318;
  --sold-bg: #fbe3e0;
  --sold-border: #b42318;

  --danger: #b42318;
  --ok: #157f37;
  --focus: #4338ca;

  --shadow: 0 6px 22px rgba(20, 34, 60, 0.12);
  --shadow-lg: 0 18px 48px rgba(20, 34, 60, 0.22);
  --radius: 16px;

  /* Tier accents (always paired with the tier's text label in markup). */
  --tier-vip: #a97400;      --tier-vip-bg: #fbf1dc;
  --tier-lower: #1d5fd0;    --tier-lower-bg: #e4eefb;
  --tier-club: #7a34c9;     --tier-club-bg: #f0e7fb;
  --tier-upper: #0e8686;    --tier-upper-bg: #dcf1f1;
  --tier-balcony: #b23a76;  --tier-balcony-bg: #fae4ef;
  --tier-default: #4a5765;  --tier-default-bg: #eef2f7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070b14;
    --bg-grad-1: #0b1326;
    --bg-grad-2: #05070f;
    --glow-1: rgba(99, 102, 241, 0.30);
    --glow-2: rgba(56, 189, 248, 0.22);
    --glow-3: rgba(168, 85, 247, 0.24);

    --surface: rgba(22, 32, 48, 0.72);
    --surface-solid: #141d2c;
    --surface-2: #1b2637;
    --border: rgba(140, 170, 210, 0.18);
    --border-strong: #35485c;
    --text: #eaf1f8;
    --text-muted: #a8b6c5;

    --accent: #6366f1;
    --accent-2: #38bdf8;
    --accent-text: #ffffff;

    --available: #4ade80;
    --available-bg: #103021;
    --available-border: #2ea562;
    --held: #c8a4f7;
    --held-bg: #241633;
    --held-border: #7d4fc0;
    --sold: #ff7a6e;
    --sold-bg: #33120f;
    --sold-border: #c0392b;

    --danger: #ff7a6e;
    --ok: #4ade80;
    --focus: #8ab4ff;

    --shadow: 0 8px 26px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 22px 60px rgba(0, 0, 0, 0.65);

    --tier-vip: #e6b84d;      --tier-vip-bg: #2c2410;
    --tier-lower: #6fb4ff;    --tier-lower-bg: #0f2237;
    --tier-club: #c19cf0;     --tier-club-bg: #241633;
    --tier-upper: #5cd2d2;    --tier-upper-bg: #0e2b2b;
    --tier-balcony: #f08bc0;  --tier-balcony-bg: #331021;
    --tier-default: #a8b6c5;  --tier-default-bg: #1e2b3a;
  }
}

@media (prefers-contrast: more) {
  :root { --border: currentColor; --text-muted: var(--text); --surface: var(--surface-solid); }
}

* { box-sizing: border-box; }
html { font-size: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 640px at 12% -8%, var(--glow-1), transparent 60%),
    radial-gradient(900px 560px at 88% 4%, var(--glow-2), transparent 60%),
    radial-gradient(1000px 700px at 60% 108%, var(--glow-3), transparent 60%),
    linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2));
  background-attachment: fixed;
}

.wrap { max-width: 72rem; margin: 0 auto; padding: 0 1.25rem; }

/* ── Skip link ────────────────────────────────────────────────────────── */
.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: var(--accent-text);
  padding: 0.6rem 1rem; border-radius: 0 0 var(--radius) 0;
  z-index: 100; text-decoration: none; font-weight: 700;
}
.skip-link:focus { left: 0; }

/* ── Header ───────────────────────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(120deg, rgba(67,56,202,0.16), rgba(14,165,233,0.10)), var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  display: flex; flex-wrap: wrap; gap: 1rem 2rem;
  align-items: center; justify-content: space-between;
  padding-top: 1rem; padding-bottom: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.9rem; max-width: 42rem; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 3rem; height: 3rem; border-radius: 14px; font-size: 1.6rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(67, 56, 202, 0.45);
}
h1 {
  margin: 0 0 0.15rem; font-size: clamp(1.25rem, 1rem + 1.2vw, 1.7rem);
  font-weight: 800; letter-spacing: -0.01em; line-height: 1.15;
  background: linear-gradient(90deg, var(--text), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-mark { flex: 0 0 auto; }
.subtitle { margin: 0; color: var(--text-muted); }

.fan-field {
  display: flex; flex-direction: column; gap: 0.3rem; min-width: 16rem;
  background: var(--surface-2); padding: 0.6rem 0.75rem; border-radius: 12px;
  border: 1px solid var(--border);
}
.fan-field label { font-weight: 700; font-size: 0.9rem; }
.hint { color: var(--text-muted); font-size: 0.78rem; margin: 0; font-weight: 400; }

/* ── Footer ───────────────────────────────────────────────────────────── */
.site-footer { margin-top: 3rem; border-top: 1px solid var(--border); }
.site-footer .wrap { padding-top: 1rem; padding-bottom: 1.5rem; }
.footnote { color: var(--text-muted); font-size: 0.82rem; margin: 0; }

main { padding-top: 1.75rem; padding-bottom: 1rem; }
main:focus { outline: none; }

/* ── Inputs ───────────────────────────────────────────────────────────── */
input[type="text"] {
  font-size: 1rem; padding: 0.6rem 0.7rem; min-height: 2.75rem;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface-solid); color: var(--text); min-width: 8rem;
}
input[type="text"]:focus-visible { border-color: var(--accent); }

/* ── Buttons ──────────────────────────────────────────────────────────── */
button {
  font-size: 1rem; font-weight: 700; min-height: 2.75rem;
  padding: 0.65rem 1.2rem; border: 1px solid transparent; border-radius: 10px;
  color: var(--accent-text); cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 16px rgba(67, 56, 202, 0.32);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
button:hover { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 10px 22px rgba(67,56,202,0.4); }
button:active { transform: translateY(0); }
button.secondary {
  background: var(--surface-2); color: var(--text);
  border-color: var(--border-strong); box-shadow: none;
}
button.secondary:hover { box-shadow: var(--shadow); }
button:disabled, button[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Status region ────────────────────────────────────────────────────── */
.status-bar { min-height: 1.5rem; margin-bottom: 0.75rem; }
.message { margin: 0; color: var(--accent-2); font-weight: 700; }
.message.error { color: var(--danger); }
.message.ok { color: var(--ok); }

/* ── View headers ─────────────────────────────────────────────────────── */
.view-head {
  display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem;
  align-items: flex-end; justify-content: space-between; margin-bottom: 1.5rem;
}
.view-title { margin: 0; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.01em; }
.view-sub { margin: 0.25rem 0 0; color: var(--text-muted); }

/* ── Tier groups (overview) ───────────────────────────────────────────── */
.tier-groups { display: flex; flex-direction: column; gap: 2rem; }
.tier-group-head {
  display: flex; align-items: center; gap: 0.7rem; margin: 0 0 1rem;
  padding-bottom: 0.5rem; border-bottom: 2px solid var(--tier-color, var(--border-strong));
}
.tier-badge {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: 1.15rem; font-weight: 800; color: var(--tier-color, var(--text)); margin: 0;
}
.tier-badge::before {
  content: ""; width: 1rem; height: 1rem; border-radius: 4px;
  background: var(--tier-color, var(--text-muted));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tier-color, #888) 22%, transparent);
}
.tier-count { color: var(--text-muted); font-size: 0.9rem; font-weight: 500; }

/* ── Section cards ────────────────────────────────────────────────────── */
.card-grid {
  display: grid; gap: 1.1rem;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}
.section-card {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 0.85rem; text-align: left;
  color: var(--text);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--tier-bg, var(--surface-2)) 55%, transparent), transparent 40%),
    var(--surface);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.2rem 1.25rem; cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}
.section-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: linear-gradient(var(--tier-color, var(--accent)), color-mix(in srgb, var(--tier-color, var(--accent)) 40%, transparent));
}
.section-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.75rem; }
.card-id { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.card-tier {
  display: inline-block; margin-top: 0.15rem; font-size: 0.75rem; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--tier-color, var(--text-muted));
}
.price-badge {
  flex: 0 0 auto; font-size: 1.15rem; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--tier-color, var(--accent)), color-mix(in srgb, var(--tier-color, var(--accent)) 55%, #000));
  border-radius: 999px; padding: 0.3rem 0.8rem; font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--tier-color, var(--accent)) 45%, transparent);
}
.card-avail-text { font-size: 0.9rem; color: var(--text-muted); font-variant-numeric: tabular-nums; margin: 0; }
.card-avail-text strong { color: var(--text); }

.meter { height: 0.6rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.meter-fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--tier-color, var(--available)), color-mix(in srgb, var(--tier-color, var(--available)) 55%, #fff));
  transition: width 0.3s ease;
}
.section-card.sold-out { opacity: 0.7; }
.section-card.sold-out .price-badge { filter: grayscale(0.5); }

/* ── Section view head ────────────────────────────────────────────────── */
.section-head {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; align-items: baseline;
  justify-content: space-between; margin-bottom: 0.85rem;
}
.section-avail {
  margin: 0; font-size: 1rem; font-weight: 700; color: var(--text);
  background: var(--surface-2); padding: 0.35rem 0.8rem; border-radius: 999px;
  border: 1px solid var(--border);
}
.section-avail #sectionAvail { font-variant-numeric: tabular-nums; }

/* ── Legend ───────────────────────────────────────────────────────────── */
.legend {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; align-items: center;
  margin-bottom: 1rem; color: var(--text-muted); font-size: 0.9rem;
}
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.5rem; height: 1.5rem; border-radius: 6px; font-weight: 700; border: 2px solid var(--border-strong);
}
.swatch-available { background: var(--available-bg); color: var(--available); border-color: var(--available-border); }
.swatch-held { background: var(--held-bg); color: var(--held); border-color: var(--held-border); }
.swatch-sold { background: var(--sold-bg); color: var(--sold); border-color: var(--sold-border); }
.legend-note { flex-basis: 100%; }

/* ── Panels ───────────────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; margin-bottom: 1.25rem; box-shadow: var(--shadow);
}

/* ── Stage / screen affordance ────────────────────────────────────────── */
.stage {
  margin: 0 auto 1.75rem; max-width: 38rem; text-align: center; font-weight: 800;
  letter-spacing: 0.45em; font-size: 0.8rem; color: var(--text);
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 30%, var(--surface-2)), var(--surface-2));
  border: 1px solid var(--border); border-bottom-width: 3px;
  border-radius: 999px / 70% 70% 100% 100%; padding: 0.7rem 1rem;
  box-shadow: 0 14px 30px -12px color-mix(in srgb, var(--accent) 60%, transparent);
}

/* ── Seat map grid ────────────────────────────────────────────────────── */
.seatmap { display: flex; flex-direction: column; gap: 0.55rem; min-height: 4rem; align-items: center; }
.seat-row { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; justify-content: center; }
.row-label { flex: 0 0 4rem; color: var(--text-muted); font-weight: 700; font-size: 0.85rem; text-align: right; }

.seat {
  min-width: 3rem; min-height: 2.75rem; padding: 0.35rem;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.92rem;
  border: 2px solid var(--border-strong); border-radius: 9px;
  background: var(--surface-2); color: var(--text);
  transition: transform 0.1s ease, filter 0.1s ease;
}
.seat::before { margin-right: 0.25rem; font-size: 0.8em; }

.seat-available { background: var(--available-bg); color: var(--available); border-color: var(--available-border); cursor: pointer; }
.seat-available::before { content: "◻"; }
.seat-available:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: 0 6px 14px color-mix(in srgb, var(--available) 40%, transparent); }

.seat-held { background: var(--held-bg); color: var(--held); border-color: var(--held-border); cursor: not-allowed; }
.seat-held::before { content: "⏳"; }

.seat-sold { background: var(--sold-bg); color: var(--sold); border-color: var(--sold-border); cursor: not-allowed; }
.seat-sold::before { content: "✕"; }

.empty-note { color: var(--text-muted); font-style: italic; margin: 0; }

/* ── Focus visibility (keyboard) ──────────────────────────────────────── */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.section-card:focus-visible { outline-offset: 3px; }
.seat:focus-visible { outline-offset: 3px; }
#seatmap-region:focus { outline: none; }

/* ── Dialogs ──────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 50; padding: 1rem;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 800px at 50% 30%, rgba(30,20,60,0.35), rgba(4,8,16,0.72));
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
/* The `hidden` attribute must win over the .overlay display rule above,
   otherwise closed dialogs stay visible and can stack on top of each other. */
.overlay[hidden] { display: none; }
.dialog {
  background: var(--surface-solid); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 1.75rem; width: min(30rem, 100%);
  border-top: 4px solid var(--accent);
}
.dialog h2 { margin-top: 0; }
.dialog-info { color: var(--text-muted); }
.dialog-amount { font-size: 1.1rem; margin: 0.35rem 0 0.5rem; }
.dialog-amount strong { color: var(--accent-2); font-variant-numeric: tabular-nums; }
.countdown { font-size: 1.05rem; }
.countdown strong { font-variant-numeric: tabular-nums; color: var(--accent-2); }
.dialog-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.1rem; }
.dialog-hint { color: var(--text-muted); font-size: 0.85rem; margin: 0.75rem 0 0; }

/* ── Screen-reader-only utility ───────────────────────────────────────── */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Reduced motion ───────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .section-card:hover, .seat-available:hover, button:hover { transform: none; }
}
