/* ─── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #0f172a;
  --bg-card:     #1e293b;
  --bg-input:    #0f172a;
  --border:      #334155;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --accent:      #3b82f6;
  --accent-dark: #2563eb;
  --green:       #22c55e;
  --amber:       #f59e0b;
  --red:         #ef4444;
  --font-mono:   'Courier New', Courier, monospace;
  --radius:      0.75rem;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  display: flex;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ─────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: #0a1628;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  border-right: 1px solid var(--border);
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.nav-links { flex: 1; padding: 1rem 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.05); color: var(--text); text-decoration: none; }
.nav-item.active { background: rgba(59,130,246,0.15); color: var(--accent); border-left: 3px solid var(--accent); }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 1rem; }

.main-content {
  margin-left: 220px;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 1.5rem 2rem 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.25rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.page-body { padding: 2rem; flex: 1; }

/* ─── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
  min-height: 44px;
}

.btn:hover { opacity: 0.9; text-decoration: none; }
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger  { background: var(--red); color: #fff; }
.btn-ghost   { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-full    { width: 100%; justify-content: center; }
.btn-sm      { padding: 0.375rem 0.75rem; font-size: 0.8rem; min-height: 36px; }

/* ─── Forms ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="time"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  padding: 0.625rem 0.875rem;
  font-size: 1rem;
  min-height: 48px;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}

select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; background-size: 1.25rem; padding-right: 2.5rem; }

/* ─── Tables ─────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

th {
  text-align: left;
  padding: 0.6rem 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 0.9rem;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.02); }

.mono { font-family: var(--font-mono); letter-spacing: 0.05em; }

/* ─── Status badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-green  { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-amber  { background: rgba(245,158,11,0.15); color: var(--amber); }
.badge-red    { background: rgba(239,68,68,0.15);  color: var(--red); }
.badge-blue   { background: rgba(59,130,246,0.15); color: var(--accent); }

/* ─── Alert ──────────────────────────────────────────────────────────── */
.alert { padding: 0.875rem 1rem; border-radius: 0.5rem; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error   { background: rgba(239,68,68,0.1);  border: 1px solid rgba(239,68,68,0.3);  color: #fca5a5; }
.alert-success { background: rgba(34,197,94,0.1);  border: 1px solid rgba(34,197,94,0.3);  color: #86efac; }
.alert-info    { background: rgba(59,130,246,0.1); border: 1px solid rgba(59,130,246,0.3); color: #93c5fd; }

/* ─── Grid ───────────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 1.5rem; }

/* ─── Stats ──────────────────────────────────────────────────────────── */
.stat-card { text-align: center; }
.stat-value { font-size: 2rem; font-weight: 800; font-family: var(--font-mono); color: var(--accent); }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.25rem; }

/* ─── Login Page ─────────────────────────────────────────────────────── */
body.login-page {
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at center, #1e293b 0%, #0f172a 70%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo svg { color: var(--accent); margin-bottom: 0.75rem; }
.login-logo h1 { font-size: 1.4rem; font-weight: 800; }
.login-logo p  { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

/* ─── Live Session Screen ────────────────────────────────────────────── */
.live-page body { margin: 0; }

.split-btn-wrap {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 50;
}

.split-btn {
  width: 100%;
  min-height: 120px;
  font-size: 2rem;
  font-weight: 900;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  -webkit-tap-highlight-color: transparent;
}

.split-btn:active { background: var(--accent-dark); transform: scale(0.98); }

.split-btn.ready   { background: var(--green); }
.split-btn.resting { background: var(--amber); cursor: default; }

/* ─── Rest Countdown ─────────────────────────────────────────────────── */
.rest-ring {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 1rem;
  background: rgba(245,158,11,0.1);
  border: 1px solid rgba(245,158,11,0.3);
  border-radius: var(--radius);
  color: var(--amber);
  margin-bottom: 1rem;
}

/* ─── Finisher Slots ─────────────────────────────────────────────────── */
.finisher-slot {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
}

.finisher-num {
  font-size: 1.5rem;
  font-weight: 900;
  font-family: var(--font-mono);
  color: var(--accent);
  min-width: 2rem;
  text-align: center;
}

.finisher-time {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--green);
  min-width: 6rem;
}

.finisher-slot select { flex: 1; margin-bottom: 0; min-height: 44px; }

/* ─── Race Day Screen ────────────────────────────────────────────────── */
.race-clock {
  text-align: center;
  font-size: 5rem;
  font-weight: 900;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  color: var(--text);
  padding: 1rem 0;
  line-height: 1;
}

.banked-display {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 0.5rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.banked-display.ahead { background: rgba(34,197,94,0.15);  color: var(--green); }
.banked-display.even  { background: rgba(148,163,184,0.1); color: var(--text-muted); }
.banked-display.behind{ background: rgba(239,68,68,0.15);  color: var(--red); }

.lap-row { display: flex; align-items: center; gap: 1rem; padding: 0.75rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.05); }
.lap-row.current { background: rgba(59,130,246,0.08); border-left: 3px solid var(--accent); }
.lap-row.done    { opacity: 0.7; }

.lap-label  { font-weight: 700; min-width: 3rem; font-family: var(--font-mono); }
.lap-target { color: var(--text-muted); min-width: 6rem; font-family: var(--font-mono); }
.lap-actual { font-family: var(--font-mono); font-weight: 700; min-width: 6rem; }
.lap-delta  { font-family: var(--font-mono); font-weight: 700; min-width: 5rem; text-align: right; }

.lap-btn {
  width: 100%;
  min-height: 100px;
  font-size: 1.75rem;
  font-weight: 900;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: background 0.1s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.lap-btn:active   { transform: scale(0.98); }
.lap-btn.finish   { background: var(--green); }
.lap-btn.finished { background: var(--border); cursor: default; }

/* ─── Sync indicator ─────────────────────────────────────────────────── */
.sync-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
}
.sync-dot.green  { background: var(--green); }
.sync-dot.amber  { background: var(--amber); }
.sync-dot.red    { background: var(--red); }

/* ─── Utility ────────────────────────────────────────────────────────── */
.flex         { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-end     { display: flex; justify-content: flex-end; align-items: center; gap: 0.75rem; }
.gap-1        { gap: 0.5rem; }
.gap-2        { gap: 1rem; }
.mt-1         { margin-top: 0.5rem; }
.mt-2         { margin-top: 1rem; }
.mt-3         { margin-top: 1.5rem; }
.mb-1         { margin-bottom: 0.5rem; }
.mb-2         { margin-bottom: 1rem; }
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: 0.85rem; }
.text-lg      { font-size: 1.1rem; }
.text-center  { text-align: center; }
.font-mono    { font-family: var(--font-mono); }
.font-bold    { font-weight: 700; }
.hidden       { display: none; }
.w-full       { width: 100%; }

/* ─── Delta colouring ────────────────────────────────────────────────── */
.delta-fast   { color: var(--green); }
.delta-ok     { color: var(--text-muted); }
.delta-slow   { color: var(--amber); }
.delta-way-slow { color: var(--red); }

/* ─── Mobile responsiveness ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 100%; height: auto; min-height: unset; position: relative; flex-direction: row; flex-wrap: wrap; padding: 0.75rem; }
  .sidebar-header { border-bottom: none; padding-bottom: 0; flex: 1; }
  .nav-links { display: flex; flex-direction: row; padding: 0; width: 100%; overflow-x: auto; }
  .nav-item span { display: none; }
  .nav-item { padding: 0.5rem 0.75rem; }
  .sidebar-footer { border-top: none; padding-top: 0; }
  .main-content { margin-left: 0; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .page-body { padding: 1rem; }
  .race-clock { font-size: 3.5rem; }
}
