/* ============================================================
   Multitap Suite Admin Panel - Dark Racing Theme
   Based on LeaderboardSuite design system, JWT auth
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
  --bg-primary: #0a0d10;
  --bg-secondary: #141c25;
  --bg-tertiary: #212e3a;
  --bg-card: #1b2532;
  --bg-input: #10161e;
  --border-primary: #2c3a46;
  --border-secondary: #3c4d5b;
  --text-primary: #eef2f5;
  --text-secondary: #9aa6b0;
  --text-muted: #6f7b85;
  --primary-color: #2ea3df;
  --success: #28a745;
  --danger: #dc3545;
  --warning: #ffc107;

  /* Ice-Blue Graphite — accent + glass (restyle 2026-06-16) */
  --accent: #2ea3df;
  --accent-strong: #1d8fcf;
  --accent-contrast: #04141d;
  --accent-soft: #7fd0f4;
  --app-bg: radial-gradient(140% 120% at 18% -10%, #1a2533 0%, #0b0f14 60%);
  --border-hairline: rgba(255,255,255,0.10);
  --glass-bg: rgba(255,255,255,0.05);
  --glass-bg-2: rgba(255,255,255,0.035);
  --glass-highlight: inset 0 1px 0 rgba(255,255,255,0.12);
  --glass-shadow: 0 8px 22px rgba(0,0,0,0.32);
  --glass-blur: blur(10px);
  --focus-ring: 0 0 0 3px rgba(46,163,223,0.18);
  --radius-pill: 999px;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-light: 0 2px 4px rgba(0,0,0,0.3);
  --shadow-medium: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-heavy: 0 8px 24px rgba(0,0,0,0.5);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.35s ease;

  /* Layout */
  --header-height: 60px;
  --sidebar-width: 280px;
  --sidebar-collapsed: 70px;
  --footer-height: 96px;
}

/* ---- Reset ---- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--app-bg) no-repeat fixed;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* ---- Scrollbar ---- */
* { scrollbar-width: thin; scrollbar-color: var(--border-primary) var(--bg-primary); }
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-primary); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-secondary); }

/* ============================================================
   Login Overlay (replaces PIN)
   ============================================================ */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

#login-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.login-container {
  text-align: center;
  width: 380px;
  padding: var(--space-2xl) var(--space-xl);
  background: var(--glass-bg);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

.login-logo {
  width: 80px;
  height: 80px;
  margin: 0 auto var(--space-md);
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2em;
  color: var(--primary-color);
}

.login-logo img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
}

/* Wide brand-mark variant: hosts the Multitap wordmark / non-square logos
   without a circular crop. Used on the login overlay (pre-login) and any
   place a venue uploaded a non-square logo. */
.login-logo--brand,
.login-logo--venue {
  width: auto;
  max-width: 280px;
  height: 88px;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.login-logo--brand img,
.login-logo--venue img {
  width: auto;
  height: 100%;
  max-width: 100%;
  border-radius: 0;
  object-fit: contain;
}

/* "powered by Multitap" lockup beneath the login form when a venue's
   brand owns the top of the card. */
.powered-by {
  margin-top: var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  opacity: 0.55;
  font-size: 0.72em;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.powered-by img {
  height: 18px;
  width: auto;
}

.powered-by[hidden] {
  display: none;
}

.login-title {
  font-size: 1.5em;
  font-weight: 700;
  margin-bottom: var(--space-xs);
  color: var(--text-primary);
}

.login-subtitle {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

.login-error {
  color: var(--danger);
  font-size: 0.85em;
  min-height: 1.4em;
  margin-bottom: var(--space-sm);
}

.login-field {
  text-align: left;
  margin-bottom: var(--space-md);
}

.login-field label {
  display: block;
  font-size: 0.8em;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-field input {
  width: 100%;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 1em;
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.login-field input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(15, 146, 208, 0.15);
}

.login-field input::placeholder {
  color: var(--text-muted);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  margin-top: var(--space-md);
  transition: filter var(--transition-fast);
  font-family: inherit;
}

.login-btn:hover {
  filter: brightness(1.1);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

@keyframes loginShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.login-container.shake {
  animation: loginShake 0.4s ease;
}

/* ============================================================
   Header
   ============================================================ */
header {
  height: var(--header-height);
  background: var(--glass-bg);
  border-bottom: 1px solid var(--border-hairline);
  box-shadow: var(--glass-highlight);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  display: flex;
  align-items: center;
  padding: 0 var(--space-lg);
  gap: var(--space-md);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.nav-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1em;
  transition: all var(--transition-fast);
}

.nav-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

#title {
  font-size: 1.2em;
  font-weight: 700;
  color: var(--text-primary);
}

#logo {
  margin-left: auto;
  height: 36px;
  width: auto;
  border-radius: var(--radius-sm);
}

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar-nav {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: var(--footer-height);
  width: var(--sidebar-width);
  background: var(--glass-bg);
  border-right: 1px solid var(--border-hairline);
  box-shadow: var(--glass-highlight);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  display: flex;
  flex-direction: column;
  z-index: 900;
  transition: width var(--transition-normal);
  overflow: hidden;
}

#sidebar-nav.collapsed {
  width: var(--sidebar-collapsed);
}

.nav-menu {
  list-style: none;
  padding: var(--space-sm) 0;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 12px var(--space-lg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
  gap: 14px;
  white-space: nowrap;
  text-decoration: none;
  font-size: 0.92em;
}

.nav-item:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.04);
}

.nav-item.active {
  color: #ffffff;
  border-left-color: var(--accent);
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 16%, transparent) 0%, transparent 100%);
}

.nav-item i {
  width: 24px;
  text-align: center;
  font-size: 1.1em;
  flex-shrink: 0;
}

.nav-item.active i {
  color: var(--primary-color);
}

.nav-item span {
  transition: opacity var(--transition-fast);
}

#sidebar-nav.collapsed .nav-item span {
  opacity: 0;
  width: 0;
  overflow: hidden;
}

#sidebar-nav.collapsed .nav-item {
  padding-left: 23px;
  padding-right: 23px;
  justify-content: center;
}

/* Sidebar footer */
.nav-footer {
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--border-primary);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.footer-btn {
  width: 100%;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.footer-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

#sidebar-nav.collapsed .footer-btn span {
  display: none;
}

#sidebar-nav.collapsed .footer-btn {
  padding: 8px 0;
}

/* ============================================================
   Main Content
   ============================================================ */
.app-container {
  position: fixed;
  top: var(--header-height);
  left: var(--sidebar-width);
  right: 0;
  bottom: var(--footer-height);
  overflow: hidden;
  transition: left var(--transition-normal);
  /* Sit above the sidebar (z 900), header (z 1000), and footer (z 1000)
     so that modal-overlay descendants (z 50000 inside) — and any other
     full-viewport overlay we render from within a page — can actually
     cover the chrome. Without this, app-container's `auto` z-index left
     the modal trapped behind the fixed sidebar on small screens. The
     app-container's own painted area (top: header / left: sidebar /
     bottom: footer) doesn't overlap the chrome, so giving it a higher
     z-index only changes overlay behavior, not normal layout. */
  z-index: 1001;
}

body.sidebar-collapsed .app-container {
  left: var(--sidebar-collapsed);
}

#main-content {
  height: 100%;
  overflow-y: auto;
  padding: var(--space-lg);
}

.page-container { display: none; }
.page-container.active { display: block; }

/* ============================================================
   Footer
   ============================================================ */
footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: var(--footer-height);
  background: var(--glass-bg);
  border-top: 1px solid var(--border-hairline);
  box-shadow: var(--glass-highlight);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-lg);
  gap: var(--space-md);
  z-index: 1000;
}

/* Two-row stat grid — top: inventory (drivers/cars/tracks/laps),
   bottom: live runtime (sims/sessions/groups). Each row's items fill
   the row width evenly so the footer never has lop-sided gaps. */
.footer-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
.footer-stat-row {
  display: grid;
  gap: var(--space-md) var(--space-lg);
  align-items: center;
}
.footer-stat-row--top    { grid-template-columns: repeat(4, 1fr); }
.footer-stat-row--bottom { grid-template-columns: repeat(3, 1fr); }

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.stat-value {
  font-size: 1.2em;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.stat-label {
  font-size: 0.66em;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

/* Legacy separator no longer used (rows separate naturally). */
.stat-separator {
  display: none;
  width: 1px;
  height: 36px;
  background: var(--border-primary);
  flex-shrink: 0;
}

/* Mobile: tighten the gap and let the stats scroll horizontally if there
   still isn't enough room, instead of clipping. Hide the brand wordmark
   since the title bar already says "Multitap Suite". */
@media (max-width: 720px) {
  footer {
    padding: 4px var(--space-sm);
    min-height: auto;
  }
  .footer-stats {
    gap: var(--space-md);
    width: 100%;
  }
  .stat-value { font-size: 1.05em; }
  .stat-label { font-size: 0.62em; }
  .stat-separator { height: 24px; }
  .footer-brand { display: none; }
}

.footer-brand {
  font-size: 0.75em;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
}

/* ============================================================
   Section Pattern (replaces .card)
   ============================================================ */
.section {
  background: var(--glass-bg);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-lg);
  overflow: hidden;
  box-shadow: var(--glass-highlight), var(--glass-shadow);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-hairline);
  background: rgba(255,255,255,0.02);
}

.section-header h2,
.section-header h3 {
  font-size: 1.05em;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.section-header h2 i,
.section-header h3 i {
  color: var(--accent);
}

.section-header .actions {
  display: flex;
  gap: var(--space-sm);
}

.section-content {
  padding: var(--space-lg);
}

.section-description {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

/* ============================================================
   Forms
   ============================================================ */
.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  font-size: 0.85em;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  font-weight: 500;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--glass-bg-2);
  color: var(--text-primary);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.form-group .hint {
  font-size: 0.75em;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-md) var(--space-lg);
  align-items: start;
  margin-bottom: var(--space-md);
}

.form-row > .form-group { margin-bottom: 0; }
.form-row:last-child { margin-bottom: 0; }

/* Inline input (inside tables) */
.inline-input {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  width: 100%;
  font-size: 0.85em;
  transition: border-color var(--transition-fast);
}

.inline-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Element-level defaults so any bare <select>, <input>, <textarea> on the
   admin renders with the brand instead of browser-default chrome. Anything
   with a class (.inline-input, .btn, etc.) overrides via specificity. */
select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="url"],
textarea {
  background: var(--glass-bg-2);
  color: var(--text-primary);
  border: 1px solid var(--border-hairline);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition-fast);
  box-sizing: border-box;
}
select {
  /* Make the native dropdown caret legible on the dark theme. */
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
                    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
  cursor: pointer;
}
select option {
  background: var(--bg-card);
  color: var(--text-primary);
}
select:focus,
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="search"]:focus,
input[type="url"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}
select:disabled,
input:disabled,
textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Bare <button> default — fall back to a neutral pill so any onclick handler
   without a class doesn't render as a Windows button. Buttons WITH a .btn /
   .action-bar-btn / .sim-row-menu / etc. class still win via specificity. */
button:not([class]),
button.unclassed-btn {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88em;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
button:not([class]):hover,
button.unclassed-btn:hover {
  border-color: var(--primary-color);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  padding: 10px 18px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-sm);
  font-size: 0.85em;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--glass-bg);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
}

.btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: var(--border-secondary);
}

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
  box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 28%, transparent);
}

.btn-primary:hover {
  background: var(--accent-strong);
  filter: none;
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: var(--glass-bg);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(220, 53, 69, 0.1);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8em;
}

/* ============================================================
   Tables
   ============================================================ */
.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-hairline);
  font-size: 0.9em;
}

th.num, td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(255,255,255,0.02);
}

tr:hover td {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

tr.editing-row td {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
}

tr.editing-row td .inline-input {
  padding: 5px 8px;
  font-size: 0.85em;
}

/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-bar .form-group {
  margin-bottom: 0;
  min-width: 140px;
}

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.72em;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.badge-success { background: rgba(40, 167, 69, 0.15); color: var(--success); }
.badge-warning { background: rgba(255, 193, 7, 0.15); color: var(--warning); }
.badge-danger { background: rgba(220, 53, 69, 0.15); color: var(--danger); }
.badge-live { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--success) 30%, transparent); }
.badge-idle { background: rgba(255,255,255,0.06); color: var(--text-secondary); box-shadow: inset 0 0 0 1px var(--border-hairline); }

/* ============================================================
   Toast Notifications
   ============================================================ */
.toast {
  position: fixed;
  bottom: calc(var(--footer-height) + var(--space-md));
  right: var(--space-lg);
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  font-size: 0.9em;
  z-index: 10000;
  box-shadow: var(--shadow-medium);
  animation: toastSlideIn 0.3s ease-out;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning, #f0ad4e); }
.toast.danger { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary-color); }

/* Inline-confirm variant: two-button toast that stays visible until clicked. */
.toast-confirm {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 280px;
  max-width: 400px;
}
.toast-confirm-message {
  font-size: 0.95em;
  color: var(--text-primary);
}
.toast-confirm-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes toastSlideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}

.empty-state p {
  margin-top: var(--space-sm);
  font-size: 0.9em;
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 50000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.modal-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: color-mix(in srgb, var(--bg-card) 82%, transparent);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-highlight), 0 20px 60px rgba(0,0,0,0.5);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  padding: var(--space-lg);
  max-width: 500px;
  width: 90%;
  /* Cap height so tall modals (Board edit, URLs list) stay inside the
     viewport on small phones instead of running off-screen. Internal
     scroll handles overflow. */
  max-height: calc(100vh - var(--space-lg) * 2);
  overflow-y: auto;
  box-shadow: var(--shadow-heavy);
}

.modal-card h3 {
  margin-bottom: var(--space-md);
  font-size: 1.1em;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}

/* ============================================================
   Drop Zone
   ============================================================ */
.drop-zone {
  border: 2px dashed var(--border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
  color: var(--text-muted);
  font-size: 0.85em;
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary-color);
  background: rgba(15, 146, 208, 0.05);
}

/* ============================================================
   Theme Radio Cards (Settings page)
   ============================================================ */
.theme-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--space-md);
}

.theme-card {
  border: 2px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
  position: relative;
}

.theme-card:hover {
  border-color: var(--border-secondary);
}

.theme-card.selected {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(15, 146, 208, 0.2);
}

.theme-card input[type="radio"] {
  display: none;
}

.theme-card .theme-preview {
  width: 100%;
  height: 60px;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
}

.theme-card .theme-name {
  font-size: 0.85em;
  font-weight: 600;
}

/* ============================================================
   URL Display (read-only, copyable)
   ============================================================ */
.url-display {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.url-label {
  flex-shrink: 0;
}

.url-display input {
  flex: 1;
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85em;
  font-family: 'Consolas', 'Courier New', monospace;
}

.url-display .btn {
  flex-shrink: 0;
}

/* ============================================================
   Game Tabs (in-page segmented control)
   ============================================================ */
.game-tabs {
  display: inline-flex;
  gap: 2px;
  margin-bottom: var(--space-lg);
  background: var(--bg-secondary);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
}

.game-tab {
  padding: 6px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85em;
  font-weight: 600;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.game-tab:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.game-tab.active {
  background: var(--primary-color);
  color: white;
  box-shadow: var(--shadow-light);
}

/* Game badges for name mapping tables */
.badge-game {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 0.72em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-game-ac { background: rgba(15, 146, 208, 0.15); color: #0f92d0; }
.badge-game-acc { background: rgba(233, 69, 96, 0.15); color: #e94560; }
.badge-game-iracing { background: rgba(72, 187, 120, 0.15); color: #48bb78; }

/* ============================================================
   Disabled Buttons
   ============================================================ */
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================================
   Code Elements
   ============================================================ */
code {
  background: var(--bg-tertiary);
  color: var(--primary-color);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
  font-family: 'Consolas', 'Courier New', monospace;
}

/* ============================================================
   Custom Checkboxes
   ============================================================ */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-primary);
  border-radius: 4px;
  background: var(--bg-input);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

input[type="checkbox"]:checked {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* ============================================================
   Form Input Exclusions (file, color inputs)
   ============================================================ */
.form-group input[type="file"],
.form-group input[type="color"] {
  width: auto;
  padding: initial;
  background: transparent;
  border: none;
}

.form-group input[type="color"] {
  cursor: pointer;
}

/* ============================================================
   Split Layout (Leaderboard page: preview + activity)
   ============================================================ */
.lb-split-container {
  display: flex;
  gap: var(--space-md);
  height: 420px;
  margin-bottom: var(--space-lg);
}

.lb-split-left,
.lb-split-right {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.lb-split-left .section-header,
.lb-split-right .section-header {
  flex-shrink: 0;
  border-radius: 0;
}

.lb-split-left .section-content,
.lb-split-right .section-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

/* ============================================================
   Activity Feed
   ============================================================ */
.activity-list {
  padding: var(--space-sm);
}

.activity-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background var(--transition-fast);
}

.activity-item:last-child {
  border-bottom: none;
}

.activity-item:hover {
  background: rgba(255,255,255,0.02);
}

.activity-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7em;
  flex-shrink: 0;
  margin-top: 2px;
}

.activity-icon.icon-lap {
  background: rgba(255,255,255,0.08);
  color: var(--text-muted);
}

.activity-icon.icon-pb {
  background: rgba(15, 146, 208, 0.2);
  color: var(--primary-color);
}

.activity-icon.icon-record {
  background: rgba(255, 193, 7, 0.2);
  color: var(--warning);
}

.activity-icon.icon-first {
  background: rgba(40, 167, 69, 0.2);
  color: var(--success);
}

.activity-body {
  flex: 1;
  min-width: 0;
}

.activity-headline {
  font-size: 0.85em;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-detail {
  font-size: 0.78em;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.activity-meta {
  flex-shrink: 0;
  text-align: right;
  font-size: 0.72em;
  color: var(--text-muted);
}

.activity-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.7em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 4px;
  vertical-align: middle;
}

.activity-badge.badge-record {
  background: rgba(255, 193, 7, 0.2);
  color: var(--warning);
}

.activity-badge.badge-pb {
  background: rgba(15, 146, 208, 0.2);
  color: var(--primary-color);
}

.activity-badge.badge-first {
  background: rgba(40, 167, 69, 0.2);
  color: var(--success);
}

.activity-badge.badge-invalid {
  background: rgba(220, 53, 69, 0.15);
  color: var(--danger);
}

/* ============================================================
   Board Table Actions
   ============================================================ */
.board-actions {
  display: flex;
  gap: 4px;
}

.board-actions .btn {
  padding: 4px 8px;
  font-size: 0.78em;
  border: none;
  background: transparent;
  color: var(--text-muted);
}

.board-actions .btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.board-actions .btn.btn-danger:hover {
  color: var(--danger);
  background: rgba(220, 53, 69, 0.1);
}

/* Board row selected state */
tr.board-selected td {
  background: rgba(15, 146, 208, 0.08);
}

/* Activity filter bar in the feed header */
.activity-filter {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.activity-filter select {
  padding: 4px 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  font-size: 0.8em;
  cursor: pointer;
}

.activity-filter select:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* URL list in modal */
.url-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 1200px) {
  .lb-split-container {
    flex-direction: column;
    height: auto;
  }
  .lb-split-left,
  .lb-split-right {
    height: 350px;
  }
}

@media (max-width: 768px) {
  :root {
    --sidebar-width: var(--sidebar-collapsed);
  }
  .nav-item span { display: none; }
  .footer-btn span { display: none; }

  /* Leaderboard page — modal, URL list, boards table, split layout. */

  /* Modal: drop horizontal margin from 10% to a tighter gutter, tighten
     internal padding, and inherit the height cap from the base rule. */
  .modal-card {
    width: calc(100vw - var(--space-md) * 2);
    max-width: none;
    padding: var(--space-md);
  }
  .modal-card h3 { font-size: 1em; }
  /* Modals on this page set inline max-width (550/600px) — override so the
     viewport-width cap above always wins on small screens. */
  #board-modal .modal-card,
  #urls-modal .modal-card { max-width: none; }
  /* Stack form rows so two inputs don't squeeze into a narrow column. */
  .modal-card .form-row { flex-direction: column; gap: var(--space-sm); }
  .modal-card .form-row > .form-group { max-width: none !important; }
  /* Modal action buttons full-width and stacked-friendly so they don't
     overflow past the modal edge. */
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions .btn { width: 100%; }

  /* URL display row: label above the input on narrow screens so the URL
     itself isn't squashed into a 60-80px column. */
  .url-display { flex-wrap: wrap; }
  .url-display .url-label { min-width: 0 !important; flex: 0 0 100%; }
  .url-display input { min-width: 0; flex: 1 1 auto; }

  /* Split layout already stacks at 1200px; on phones tighten the heights
     so neither pane needs to scroll-fight the page itself. */
  .lb-split-left,
  .lb-split-right { height: auto; max-height: 60vh; }

  /* Section headers: drop the row layout so a wide title + actions row
     doesn't push the New Board button off-screen. */
  .section-header { flex-wrap: wrap; gap: var(--space-sm); padding: var(--space-sm) var(--space-md); }
  .section-header h2 { font-size: 0.95em; }

  /* Boards table is dense — let the container scroll horizontally so the
     row doesn't get squashed into illegible cells. */
  .table-container { -webkit-overflow-scrolling: touch; }
  th, td { padding: 8px 10px; }

  /* Board action buttons (preview / urls / edit / delete) compact and
     wrappable so they fit inside the narrow Actions column. */
  .board-actions { flex-wrap: wrap; gap: 4px; }
}

/* Compact footer on small phones — keeps two rows but shaves the chrome. */
@media (max-width: 640px) {
  :root { --footer-height: 78px; }
  footer { padding: 6px var(--space-md); }
  .footer-stats { gap: 3px; }
  .footer-stat-row { gap: var(--space-xs) var(--space-sm); }
  .stat-value { font-size: 1.02em; }
  .stat-label { font-size: 0.6em; }
  /* Brand hides on tight viewports so stats take the whole row width. */
  .footer-brand { display: none; }
}

/* ============================================================
   Email Marketing Page
   ============================================================ */
.email-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: var(--space-md);
}

.email-type-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  transition: border-color 0.2s;
}

.email-type-card:hover {
  border-color: var(--border-secondary);
}

/* ============================================================
   Metadata Toolbar
   ============================================================ */
.md-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border-bottom: 1px solid var(--border-primary);
  background: rgba(255,255,255,0.015);
  flex-wrap: wrap;
}

.md-toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.md-toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border-primary);
  margin: 0 var(--space-xs);
  flex-shrink: 0;
}

.md-toolbar-count {
  font-size: 0.78em;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 4px 10px;
  background: var(--bg-secondary);
  border-radius: 20px;
  border: 1px solid var(--border-primary);
  font-variant-numeric: tabular-nums;
}

/* Styled select for dark theme */
.md-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  padding: 6px 30px 6px 10px;
  font-size: 0.82em;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23808080'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  min-width: 120px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.md-select:hover {
  border-color: var(--border-secondary);
  color: var(--text-primary);
}

.md-select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(15, 146, 208, 0.15);
  color: var(--text-primary);
}

.md-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 6px;
}

/* Search input with icon */
.md-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.md-search-wrap i {
  position: absolute;
  left: 10px;
  font-size: 0.78em;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--transition-fast);
}

.md-search-wrap input {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  padding: 6px 10px 6px 30px;
  font-size: 0.82em;
  font-family: inherit;
  width: 200px;
  transition: all var(--transition-fast);
}

.md-search-wrap input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(15, 146, 208, 0.15);
}

.md-search-wrap input:focus + i,
.md-search-wrap:focus-within i {
  color: var(--primary-color);
}

/* Sortable column headers */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
  position: relative;
  padding-right: 22px;
}

th.sortable:hover {
  color: var(--text-primary);
}

th.sortable::after {
  content: '\f0dc';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7em;
  opacity: 0.3;
  transition: opacity var(--transition-fast);
}

th.sortable:hover::after {
  opacity: 0.6;
}

th.sortable.sort-asc::after {
  content: '\f0de';
  opacity: 1;
  color: var(--primary-color);
}

th.sortable.sort-desc::after {
  content: '\f0dd';
  opacity: 1;
  color: var(--primary-color);
}

th.sortable.sort-asc,
th.sortable.sort-desc {
  color: var(--text-primary);
}

/* ============================================================
   Dashboard
   ============================================================ */
.dash-card {
  background: var(--bg-tertiary);
  padding: 20px;
  border-radius: var(--radius-md);
  text-align: center;
}
.dash-card-icon {
  font-size: 1.5em;
  opacity: 0.4;
  margin-bottom: 8px;
}
.dash-card-value {
  font-size: 2em;
  font-weight: bold;
  line-height: 1.2;
}
.dash-card-label {
  font-size: 0.8em;
  color: var(--text-muted);
  margin-top: 4px;
}
.dash-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #888;
  margin-right: 6px;
}
.dash-health-item {
  display: flex;
  align-items: center;
  font-size: 0.9em;
}
.dash-attention-link {
  display: inline-block;
  padding: 6px 14px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  color: var(--warning, #f39c12);
  cursor: pointer;
  font-size: 0.9em;
  text-decoration: none;
  border-left: 3px solid var(--warning, #f39c12);
}
.dash-attention-link:hover {
  background: var(--bg-primary);
}
