/* =========================================================
   StadiumMind AI — Design tokens
   Palette (broadcast / night-match command center):
     --pitch-night   #0B1F17  deep turf-black background
     --turf          #1F6F4A  primary brand green
     --turf-bright   #2FA36B  interactive green
     --floodlight    #F2C94C  amber accent (attention, highlights)
     --signal        #E3543D  red accent (incidents/danger)
     --chalk         #EDEFEA  light text on dark
     --steel         #7C8B85  muted secondary text
   Type: Barlow Condensed (display/scoreboard), Barlow (body), IBM Plex Mono (data)
   ========================================================= */

:root {
  --turf: #1f6f4a;
  --turf-bright: #2fa36b;
  --floodlight: #f2c94c;
  --signal: #e3543d;
  --signal-text: #ea6a54; /* WCAG AA-compliant (4.98:1) variant of --signal, used for text/labels */
  --radius: 14px;
  --font-display: 'Barlow Condensed', sans-serif;
  --font-body: 'Barlow', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

[data-theme="dark"] {
  --bg: #0b1f17;
  --bg-alt: #0f281e;
  --panel: rgba(237, 239, 234, 0.05);
  --panel-border: rgba(237, 239, 234, 0.1);
  --text: #edefea;
  --text-muted: #9db3a8;
  --card-bg: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] {
  --bg: #f2f5f1;
  --bg-alt: #e7ede7;
  --panel: rgba(11, 31, 23, 0.03);
  --panel-border: rgba(11, 31, 23, 0.1);
  --text: #0f2018;
  --text-muted: #506357;
  --card-bg: #ffffff;
}

* { box-sizing: border-box; }

/* ---------- Accessibility utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -60px;
  left: 12px;
  background: var(--turf, #1f6f4a);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 999;
  font-family: var(--font-body);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 12px;
}

/* Visible focus ring for keyboard users on interactive elements */
button:focus-visible,
a:focus-visible,
.side__item:focus-visible,
.iconbtn:focus-visible {
  outline: 2px solid var(--turf-bright);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% 0%, rgba(47, 163, 107, 0.12), transparent 45%),
    radial-gradient(circle at 90% 10%, rgba(242, 201, 76, 0.06), transparent 40%);
}

.mono { font-family: var(--font-mono); }

/* ---------- Scoreboard header ---------- */
.scorebug {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 22px;
  background: linear-gradient(180deg, var(--bg-alt), var(--bg));
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(10px);
}

.scorebug__brand { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 700; font-size: 20px; letter-spacing: 0.5px; }
.scorebug__mark { color: var(--turf-bright); font-size: 20px; }
.scorebug__name b { color: var(--turf-bright); font-weight: 800; }

.scorebug__stats { display: flex; gap: 26px; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.stat__label { font-size: 10px; letter-spacing: 1.2px; color: var(--text-muted); font-family: var(--font-display); }
.stat__value { font-size: 16px; font-weight: 600; }

.iconbtn {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 50%;
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.iconbtn:hover { background: var(--turf); color: #fff; transform: scale(1.06); }

/* ---------- Shell layout ---------- */
.shell { display: flex; min-height: calc(100vh - 58px); }

.side {
  width: 232px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 10px;
  border-right: 1px solid var(--panel-border);
  background: var(--panel);
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow-y: auto;
}

.side__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 10px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.side__item:hover { background: var(--card-bg); color: var(--text); }
.side__item.is-active { background: var(--turf); color: #fff; }
.side__item svg { flex-shrink: 0; }

.main { flex: 1; padding: 26px 32px 80px; max-width: 1180px; }

.view { display: none; animation: fadeUp 0.35s ease; }
.view.is-active { display: block; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.view__head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.eyebrow { font-family: var(--font-display); letter-spacing: 2px; font-size: 12px; color: var(--turf-bright); margin: 0 0 4px; text-transform: uppercase; }
h1 { font-family: var(--font-display); font-weight: 700; font-size: 34px; margin: 0; letter-spacing: 0.3px; }
.sub { color: var(--text-muted); margin: 6px 0 0; max-width: 60ch; }
.head__note { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

/* ---------- Panels / cards ---------- */
.panel {
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
}
.panel__title { font-family: var(--font-display); font-size: 18px; margin: 0 0 10px; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 8px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
  overflow: hidden;
}
.card__label { font-size: 11px; letter-spacing: 1px; color: var(--text-muted); font-family: var(--font-display); text-transform: uppercase; }
.card__value { font-family: var(--font-mono); font-size: 24px; font-weight: 600; margin-top: 4px; }
.card__bar { height: 6px; border-radius: 4px; background: rgba(124,139,133,0.25); margin-top: 10px; overflow: hidden; }
.card__bar-fill { height: 100%; border-radius: 4px; background: var(--turf-bright); transition: width 0.6s ease; }

.level--low .card__bar-fill { background: var(--turf-bright); }
.level--moderate .card__bar-fill { background: var(--floodlight); }
.level--high .card__bar-fill { background: #e08a2c; }
.level--critical .card__bar-fill { background: var(--signal); }

/* ---------- Stadium Pulse (signature element) ---------- */
.pulse-wrap { display: flex; align-items: center; gap: 32px; flex-wrap: wrap; }
.pulse-map { width: 340px; height: 340px; flex-shrink: 0; }
.pulse-legend { display: flex; flex-direction: column; gap: 10px; font-size: 13px; color: var(--text-muted); }
.legend__row { display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot--low { background: var(--turf-bright); }
.dot--mod { background: var(--floodlight); }
.dot--high { background: #e08a2c; }
.dot--crit { background: var(--signal); }

.zone-node circle.zone-core { transition: r 0.6s ease, fill 0.6s ease; }
.zone-node text { font-family: var(--font-mono); font-size: 1.6px; fill: var(--text); }
.zone-pulse { animation: pulseRing 2.4s ease-out infinite; transform-origin: center; }
@keyframes pulseRing { 0% { opacity: 0.5; transform: scale(0.9);} 100% { opacity: 0; transform: scale(1.9);} }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); font-weight: 500; }
.form-grid .span-2 { grid-column: span 2; }
input, select, textarea {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--turf-bright); outline-offset: 1px; }
.checkbox { flex-direction: row !important; align-items: center; gap: 8px !important; }
.checkbox input { width: auto; }

.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.4px;
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn--primary { background: var(--turf); color: #fff; }
.btn--danger { background: var(--signal); color: #fff; }
.linklike { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; text-decoration: underline; }

.result-area { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.result-line { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--panel-border); font-size: 14px; }
.result-line span:first-child { color: var(--text-muted); }
.ai-note {
  background: linear-gradient(135deg, rgba(47,163,107,0.12), rgba(242,201,76,0.08));
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.ai-note::before { content: "✦ AI GUIDANCE"; display: block; font-family: var(--font-display); font-size: 11px; letter-spacing: 1.4px; color: var(--turf-bright); margin-bottom: 6px; }

.incident-list { display: flex; flex-direction: column; gap: 10px; }
.incident-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-radius: 8px; background: var(--panel); font-size: 13px; }
.badge { font-family: var(--font-mono); font-size: 11px; padding: 3px 8px; border-radius: 20px; text-transform: uppercase; }
.badge--critical { background: rgba(227,84,61,0.2); color: var(--signal-text); }
.badge--high { background: rgba(224,138,44,0.2); color: #e08a2c; }
.badge--medium { background: rgba(242,201,76,0.2); color: var(--floodlight); }
.badge--low { background: rgba(47,163,107,0.2); color: var(--turf-bright); }

/* ---------- Skeleton loading ---------- */
.skeleton { position: relative; overflow: hidden; background: var(--panel); border-radius: 8px; height: 16px; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%);} to { transform: translateX(100%);} }

/* ---------- Copilot floating console ---------- */
.copilot { position: fixed; right: 22px; bottom: 22px; z-index: 60; }
.copilot__toggle {
  display: flex; align-items: center; gap: 8px;
  background: var(--turf); color: #fff; border: none;
  padding: 12px 18px; border-radius: 30px; cursor: pointer;
  font-family: var(--font-display); font-weight: 600; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.copilot__panel {
  position: absolute; bottom: 60px; right: 0;
  width: 360px; max-width: 90vw; height: 480px;
  background: var(--bg-alt); border: 1px solid var(--panel-border);
  border-radius: 16px; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  overflow: hidden;
}
.copilot__head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--panel-border); font-family: var(--font-display); font-weight: 600; }
.copilot__head .iconbtn { width: 26px; height: 26px; }
.copilot__messages { flex: 1; padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 13.5px; line-height: 1.45; }
.msg--bot { background: var(--panel); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg--user { background: var(--turf); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg--typing { display: flex; gap: 4px; align-items: center; }
.msg--typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: blink 1.2s infinite ease-in-out; }
.msg--typing span:nth-child(2) { animation-delay: 0.2s; }
.msg--typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.copilot__input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--panel-border); }
.copilot__input input { flex: 1; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 70px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--bg-alt); border: 1px solid var(--panel-border); border-left: 4px solid var(--turf-bright);
  padding: 12px 16px; border-radius: 8px; font-size: 13.5px; max-width: 300px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  animation: slideIn 0.25s ease;
}
.toast.toast--error { border-left-color: var(--signal); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px);} to { opacity: 1; transform: translateX(0);} }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .scorebug__stats { display: none; }
  .shell { flex-direction: column; }
  .side {
    flex-direction: row; width: 100%; height: auto; position: sticky; top: 58px;
    overflow-x: auto; padding: 8px; gap: 6px; border-right: none; border-bottom: 1px solid var(--panel-border);
  }
  .side__item span { display: none; }
  .side__item { padding: 10px; }
  .main { padding: 18px 16px 90px; }
  .pulse-map { width: 100%; height: auto; }
  .copilot__panel { width: 92vw; }
  h1 { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}