/* Shared layout primitives. Theme and screen-specific rules extend these surfaces. */
:root {
  --bg: #0c1117; --bg2: #131b24; --bg3: #1b2632;
  --text: #e8eef4; --muted: #9eacba; --border: #293745;
  --accent: #ffed00; --accent2: #7ab5e8; --green: #2ea043;
  --orange: #d29922; --red: #f85149;
  --green-bg: #2ea04326; --orange-bg: #d2992226; --red-bg: #f8514926;
  --radius: 12px; --shadow: 0 12px 36px #00000014;
  --control-radius: 8px; --panel-edge: 1px solid var(--border);
}
*, *::before, *::after { box-sizing: border-box; }
html, body { padding: 0; margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
h1, h2, h3, h4 { font-weight: 700; margin: 0 0 8px; }
a { color: var(--accent2); }
.hidden { display: none !important; }
::-webkit-scrollbar { height: 10px; width: 10px; }
::-webkit-scrollbar-thumb { border-radius: 6px; background: var(--border); }

/* Input sizes and keyboard affordances apply to every editor. */
button, input, select, textarea {
  padding: 8px 10px; border: var(--panel-edge); border-radius: var(--control-radius);
  background: var(--bg3); color: var(--text);
  font-family: inherit; font-size: 14px;
}
button { cursor: pointer; transition: border-color .15s, opacity .15s; }
button:hover { border-color: var(--accent); }
button.primary { color: #fff; font-weight: 600; border-color: var(--accent); background: var(--accent); }
button.primary:hover { opacity: .9; }
button.ghost { background: transparent; }
button.danger { color: var(--red); border-color: currentColor; }
button.small { font-size: 12px; padding: 4px 8px; border-radius: 6px; }
input[type="checkbox"] { padding: 0; height: 16px; width: 16px; }
textarea:focus-visible, .help:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { button { transition: none; } }

/* Surface borders are shared; each component owns its spacing and radius. */
.card, .login-card, .modal, .mv-block, .stat, .heat-col, .timeline { border: var(--panel-edge); }
.card, .login-card, .modal, .mv-block { background: var(--bg2); }
.card { border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid, .form-grid, .live-grid { display: grid; }
.grid { gap: 14px; }
.grid.cols-2, .form-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4,minmax(0,1fr)); }
.form-grid { gap: 12px; }
.form-grid > *, .form-row { min-width: 0; }
.section-title, .toolbar, .event-switcher, .checks label, .division-group-title, .heat-header-top { display: flex; align-items: center; }
.section-title { margin-bottom: 12px; gap: 4px; }
.toolbar { gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Common alignment and typography across component surfaces. */
#loginScreen, .modal-backdrop, .help, .timeline .block { align-items: center; justify-content: center; }
.stat .num, .heat-time, .live-timer, .mv-block .big { font-weight: 800; }
.role-badge, .login-event-badge, .badge, .heat-num, .division-group-title { font-weight: 700; }
.stat .label, .mv-block .lbl { font-size: 12px; color: var(--muted); }
main, #mobileView { margin: 0 auto; }
.role-btns, .checks, .modal-actions, .warn-list { display: flex; }
.heat-time, .mv-block .big, .mv-hero h2 { font-size: 20px; }

/* Local entry and audience identity selection. */
#loginScreen { min-height: 100vh; padding: 20px; display: flex; }
.login-card { --entry-width: 440px; width: 100%; max-width: var(--entry-width); padding: 32px; text-align: center; box-shadow: var(--shadow); border-radius: 16px; }
.login-card.athlete-mode { --entry-width: 480px; }
.login-card h1 { line-height: 1.25; font-size: 22px; margin-bottom: 4px; }
.login-card p { margin-bottom: 24px; color: var(--muted); }
.login-logo { margin-bottom: 12px; }
.login-logo img { width: auto; height: auto; max-height: 70px; max-width: 220px; opacity: .7; }
.login-event-badge { display: inline-block; margin: 8px 0 2px; padding: 5px 14px; border: var(--panel-edge); border-radius: 20px; background: var(--bg3); color: var(--accent2); font-size: 14px; }
.role-btns { margin-bottom: 18px; gap: 12px; }
.role-btns button { border-radius: 12px; flex: 1; padding: 16px; font-size: 15px; min-width: 0; overflow-wrap: anywhere; }
.participant-pick-btn { width: 100%; display: block; padding: 12px 14px; margin-bottom: 6px; text-align: left; }
.participant-pick-btn:hover { border-color: var(--accent2); }
/* Hidden entry panels must not retain inherited boot visibility in WebKit. */
#participantPicker, #volunteerPicker { visibility: visible; }
#volunteerPicker { text-align: left; margin-top: 12px; }
#volunteerPicker select { margin-top: 8px; width: 100%; }
.login-admin-choice { text-align: center; margin-bottom: 6px; }
.login-admin-choice button { width: 100%; margin-bottom: 14px; }
.login-admin-choice p { font-size: 12px; margin: 8px 0; }
#participantSearchInput { margin-top: 6px; padding: 12px; font-size: 16px; width: 100%; }
#participantDivisionFilter { width: 100%; margin-top: 8px; }
#participantResultsList { text-align: left; overflow-y: auto; max-height: 280px; margin-top: 10px; }
#btnVolunteerContinue { width: 100%; margin-top: 10px; }

/* Workspace chrome, horizontal navigation and status. */
#appShell { min-height: 100vh; flex-direction: column; display: none; }
.sticky-header { top: 0; position: sticky; z-index: 50; }
header.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 10px 16px; background: var(--bg2); border-bottom: var(--panel-edge); }
.brand { white-space: nowrap; color: var(--accent); letter-spacing: .5px; font-weight: 800; }
.event-switcher { gap: 6px; }
.event-switcher select { max-width: 220px; }
.role-badge { padding: 4px 10px; font-size: 12px; color: #fff; background: var(--accent); border-radius: 20px; }
.role-badge.volunteer { background: var(--accent2); }
nav.tabs { gap: 2px; display: flex; padding: 0 8px; overflow-x: auto; border-bottom: var(--panel-edge); background: var(--bg2); }
nav.tabs button { padding: 12px 16px; white-space: nowrap; font-weight: 600; color: var(--muted); border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; }
nav.tabs button.active { border-bottom-color: var(--accent); color: var(--text); }
main { width: 100%; max-width: 1400px; flex: 1; padding: 18px; }
footer.statusbar { display: flex; justify-content: space-between; padding: 6px 16px; border-top: var(--panel-edge); font-size: 11px; color: var(--muted); }

/* Shared semantic tones for counters, badges and warnings. */
.green { --tone: var(--green); --tone-bg: var(--green-bg); }
.orange { --tone: var(--orange); --tone-bg: var(--orange-bg); }
.red { --tone: var(--red); --tone-bg: var(--red-bg); }
.stat { padding: 14px; border-radius: 10px; background: var(--bg3); }
.stat .num { font-size: 26px; }
.stat .label { margin-top: 2px; }
.stat.green, .stat.orange, .stat.red { border-color: var(--tone); background: var(--tone-bg); }
.badge { display: inline-block; border-radius: 20px; padding: 3px 9px; font-size: 11px; }
.badge.green, .badge.orange, .badge.red { color: var(--tone); background: var(--tone-bg); }
.badge.gray { color: var(--muted); background: var(--bg3); }
.warn-list { gap: 8px; flex-direction: column; }
.warn-item { display: flex; align-items: flex-start; gap: 8px; border-radius: var(--control-radius); padding: 10px 12px; font-size: 13px; }
.warn-item.red, .warn-item.orange, .warn-item.green { border: 1px solid var(--tone); background: var(--tone-bg); }

/* Tables retain horizontal scrolling independently of the page. */
table { border-collapse: collapse; font-size: 13px; width: 100%; }
th, td { border-bottom: var(--panel-edge); padding: 8px 10px; text-align: left; }
th { font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
tr:hover td, tr:focus-within td { background: var(--bg3); }
.table-wrap { max-width: 100%; overflow: auto; }

/* Modal surfaces and form groups. */
.modal-backdrop { inset: 0; position: fixed; z-index: 500; background: #0009; padding: 16px; display: none; }
.modal-backdrop.open { display: flex; }
.modal { width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain; padding: 22px; border-radius: 14px; }
.modal h2 { margin-bottom: 16px; }
.form-row { margin-bottom: 12px; }
.form-row label, #volunteerPicker > label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.form-row input:not([type="checkbox"]):not([type="radio"]), .form-row select, .form-row textarea { width: 100%; }
.form-row input[type="checkbox"], .form-row input[type="radio"] { width: 16px; min-height: 16px; flex-shrink: 0; vertical-align: middle; }
.modal-actions { margin-top: 18px; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.checks { gap: 12px; flex-wrap: wrap; }
.checks label { gap: 6px; color: var(--text); font-weight: 400; font-size: 13px; }
.backup-preview { margin-top: 10px; font-size: 13px; }
.backup-replacement-notice { color: var(--red); }

/* Context help supports pointer and keyboard activation. */
.help { display: inline-flex; position: relative; vertical-align: middle; margin-left: 6px; width: 16px; height: 16px; border: var(--panel-edge); border-radius: 50%; background: var(--bg3); color: var(--muted); font-size: 11px; font-weight: 700; cursor: help; }
.help:hover, .help.open { border-color: var(--accent2); background: var(--accent2); color: white; }
.help .tip { display: none; position: absolute; top: 22px; left: 0; z-index: 200; width: 240px; padding: 10px 12px; border: 1px solid var(--accent2); border-radius: var(--control-radius); background: var(--bg3); color: var(--text); box-shadow: var(--shadow); line-height: 1.4; font-size: 12px; font-weight: 400; }
.help:hover .tip, .help.open .tip { display: block; }

/* Heat cards and participant placement. */
.heat-col { background: var(--bg3); padding: 10px; border-radius: 10px; min-width: 200px; flex: 0 1 210px; }
.heat-schedule, .heat-schedule-wrap { display: flex; gap: 12px; }
.heat-schedule { overflow-x: auto; padding-bottom: 8px; }
.heat-schedule-wrap { flex-wrap: wrap; }
.division-group { margin-bottom: 20px; }
.division-group-title { gap: 8px; color: var(--accent2); margin-bottom: 8px; }
.heat-header { margin-bottom: 8px; }
.heat-header-top { justify-content: space-between; }
.heat-num { color: var(--muted); font-size: 13px; }
.heat-time { color: var(--accent2); margin-top: 2px; }
.participant-chip { background: var(--bg2); border: var(--panel-edge); border-radius: 7px; display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 8px; margin-bottom: 6px; font-size: 12px; cursor: grab; }
.participant-chip.locked { border-color: var(--accent); }
.participant-chip.dragover, .heat-col.dragover { border-color: var(--accent2); }
.heat-col.dragover { background: #3b9dff14; }
.participant-chip .tag { padding: 1px 5px; border-radius: var(--control-radius); color: var(--muted); background: var(--bg3); font-size: 9px; }
.live-grid { gap: 16px; grid-template-columns: repeat(auto-fill,minmax(320px,1fr)); }
.live-heat-card { margin: 0; }
.live-heat-card.live-racing { border-color: var(--accent); box-shadow: none; }
.live-timer { font-size: 44px; font-variant-numeric: tabular-nums; letter-spacing: 1px; }

/* Shared shifts and read-only portal plans. */
.timeline { position: relative; background: var(--bg3); border-radius: var(--control-radius); overflow: hidden; margin-top: 8px; }
.timeline .hourline { position: absolute; top: 0; bottom: 0; border-left: 1px dashed #ffffff26; }
.timeline .hourlabel { position: absolute; top: 2px; padding-left: 3px; font-size: 9px; color: var(--muted); }
.timeline .block { position: absolute; display: flex; overflow: hidden; white-space: nowrap; padding: 0 4px; border-radius: 5px; font-size: 10px; color: #fff; }
.station-shift, .station-shift-partner { overflow-wrap: anywhere; display: block; }
.station-shift + .station-shift { margin-top: .45em; }
.station-shift-partner { font-size: .86em; color: var(--orange); }
#mobileView { max-width: 560px; }
.mv-hero { padding: 22px; margin-bottom: 16px; border-radius: 16px; text-align: center; background: var(--bg3); }
.mv-hero h2 { margin: 0; }
.mv-hero .sub { margin-top: 4px; opacity: .85; font-size: 13px; }
.mv-block { display: flex; gap: 14px; align-items: center; padding: 18px; margin-bottom: 14px; border-radius: 14px; }
.portal-station-row { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: var(--panel-edge); font-size: 12px; }
.portal-station-row span:first-child { color: var(--muted); }
.portal-station-row span:last-child { text-align: right; }

@media (max-width: 900px) { .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2,minmax(0,1fr)); } }
@media (max-width: 700px) {
  .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: minmax(0,1fr); }
  nav.tabs { font-size: 13px; }
  header.topbar { padding: 8px 10px; }
  main { padding: 10px; }
}
@media (max-width: 520px) { .form-grid { grid-template-columns: minmax(0,1fr); } }
@media print {
  header.topbar, nav.tabs, footer.statusbar, .no-print { display: none !important; }
  body { color: #000; background: #fff; }
  .card { border: 1px solid #999; }
  table th, table td { border-color: #999; color: #000; }
}

.workspace-skip { position: fixed; top: -100px; left: 12px; z-index: 600; padding: 10px 16px; border-radius: var(--control-radius); background: var(--bg2); }
.workspace-skip:focus { top: 12px; }
