/* ── RideOps Global Styles ──────────────────────────────────────────────── */
:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --border: #1e1e1e;
  --surface2: #181818;
  --accent: #e8b400;
  --accent-dim: #a07c00;
  --sos: #fc8181;
  --sos-dim: #c53030;
  --green: #52b788;
  --green-dim: #2d6a4f;
  --yellow: #f6d860;
  --blue: #74c0fc;
  --gray: #4a4a4a;
  --text: #f0f0f0;
  --text-muted: #888;
  --text-dim: #555;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --min-tap: 48px;
  --shadow: 0 4px 24px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

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

/* ── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.5px; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; }
p { color: var(--text-muted); font-size: 15px; }

/* ── Layout helpers ──────────────────────────────────────────────────────── */
.container { max-width: 480px; margin: 0 auto; padding: 0 16px; }
.container-wide { max-width: 960px; margin: 0 auto; padding: 0 16px; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--min-tap);
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-primary:hover { background: #f5c400; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-danger {
  background: var(--sos);
  color: #000;
  font-weight: 700;
}
.btn-danger:hover { background: #fc6b6b; }

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: #222; }

.btn-sm {
  min-height: 36px;
  padding: 8px 16px;
  font-size: 14px;
}

.btn-lg {
  min-height: 56px;
  padding: 16px 32px;
  font-size: 18px;
  width: 100%;
  border-radius: var(--radius);
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group + .form-group { margin-top: 16px; }

label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input, select, textarea {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  padding: 12px 14px;
  min-height: var(--min-tap);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

input::placeholder, textarea::placeholder {
  color: var(--text-dim);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* ── Status badges ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-riding { background: rgba(82,183,136,0.2); color: var(--green); }
.badge-staging { background: rgba(116,192,252,0.2); color: var(--blue); }
.badge-stopped { background: rgba(246,216,96,0.2); color: var(--yellow); }
.badge-sos { background: rgba(252,129,129,0.2); color: var(--sos); animation: pulse-badge 1s infinite; }
.badge-done { background: rgba(100,100,100,0.2); color: var(--gray); }
.badge-stale { background: rgba(74,74,74,0.2); color: var(--gray); }

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* ── Status dot ──────────────────────────────────────────────────────────── */
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-riding { background: var(--green); }
.dot-staging { background: var(--blue); }
.dot-stopped { background: var(--yellow); }
.dot-sos { background: var(--sos); animation: pulse-dot 1s infinite; }
.dot-done { background: var(--gray); }
.dot-stale { background: var(--gray); }
.dot-connected { background: var(--green); }
.dot-disconnected { background: var(--sos); }

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  border-top: 1px solid var(--border);
}

/* ── Alert / Banner ──────────────────────────────────────────────────────── */
.alert {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.alert-danger {
  background: rgba(252,129,129,0.12);
  border: 1px solid rgba(252,129,129,0.3);
  color: var(--sos);
}

.alert-info {
  background: rgba(116,192,252,0.1);
  border: 1px solid rgba(116,192,252,0.25);
  color: var(--blue);
}

.alert-success {
  background: rgba(82,183,136,0.12);
  border: 1px solid rgba(82,183,136,0.3);
  color: var(--green);
}

.alert-warning {
  background: rgba(232,180,0,0.1);
  border: 1px solid rgba(232,180,0,0.3);
  color: var(--accent);
}

/* ── Map layout ──────────────────────────────────────────────────────────── */
.map-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.map-topbar {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  z-index: 1000;
}

.map-topbar .ride-name {
  font-size: 15px;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-topbar .rider-count {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

#map {
  flex: 1;
  background: #1a1a1a;
  min-height: 0;
}

.map-bottombar {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  z-index: 1000;
}

.status-btn {
  flex: 1;
  min-height: 44px;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-align: center;
}

.status-btn:active { transform: scale(0.95); }

.status-btn.active-riding { background: rgba(82,183,136,0.15); border-color: var(--green); color: var(--green); }
.status-btn.active-staging { background: rgba(116,192,252,0.15); border-color: var(--blue); color: var(--blue); }
.status-btn.active-stopped { background: rgba(246,216,96,0.15); border-color: var(--yellow); color: var(--yellow); }
.status-btn.active-done { background: rgba(100,100,100,0.15); border-color: var(--gray); color: var(--gray); }

/* ── SOS Float Button ────────────────────────────────────────────────────── */
.sos-float {
  position: fixed;
  bottom: 80px;
  right: 16px;
  z-index: 2000;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--sos);
  border: none;
  color: #000;
  font-size: 11px;
  font-weight: 800;
  font-family: var(--font);
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(252,129,129,0.5);
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  transition: transform 0.1s;
}

.sos-float:active { transform: scale(0.93); }
.sos-float .sos-icon { font-size: 18px; }

/* ── SOS Banner ──────────────────────────────────────────────────────────── */
.sos-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--sos);
  color: #000;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slide-down 0.3s ease;
  cursor: pointer;
}

@keyframes slide-down {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

/* ── Roster ──────────────────────────────────────────────────────────────── */
.rider-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

.rider-item.sos-active { border-color: var(--sos); background: rgba(252,129,129,0.05); }

.rider-info { flex: 1; min-width: 0; }
.rider-name { font-size: 16px; font-weight: 600; }
.rider-bike { font-size: 13px; color: var(--text-muted); }
.rider-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.rider-status-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Landing / hero ──────────────────────────────────────────────────────── */
.hero {
  padding: 60px 0 32px;
  text-align: center;
}

.hero-logo {
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -1px;
  line-height: 1;
}

.hero-logo span { color: var(--text); }

.hero-tag {
  font-size: 15px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ── Code display ────────────────────────────────────────────────────────── */
.ride-code {
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 6px;
  color: var(--accent);
  text-align: center;
  font-family: 'Courier New', monospace;
  padding: 16px;
  background: rgba(232,180,0,0.08);
  border: 2px dashed rgba(232,180,0,0.3);
  border-radius: var(--radius);
}

/* ── Connection indicator ────────────────────────────────────────────────── */
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray);
  transition: background 0.3s;
  flex-shrink: 0;
}
.conn-dot.connected { background: var(--green); }
.conn-dot.disconnected { background: var(--sos); animation: pulse-dot 1s infinite; }

/* ── Chat/messages ───────────────────────────────────────────────────────── */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 0;
}

.chat-msg {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 14px;
}

.chat-msg .msg-author {
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 2px;
}

.chat-msg .msg-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.chat-msg.system-msg { background: transparent; border: 1px solid var(--border); }
.chat-msg.system-msg .msg-author { color: var(--text-muted); }

/* ── Admin panel ─────────────────────────────────────────────────────────── */
.admin-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.admin-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.admin-sidebar-inner {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.admin-map-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

@media (max-width: 768px) {
  .admin-layout { flex-direction: column; }
  .admin-sidebar {
    width: 100%;
    max-height: 45vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

/* ── Stats bar ───────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  flex-wrap: wrap;
}

.stat-item { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 56px; }
.stat-value { font-size: 18px; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; }

/* ── Loading ─────────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Screen-on notice ────────────────────────────────────────────────────── */
.screen-notice {
  background: rgba(232,180,0,0.08);
  border: 1px solid rgba(232,180,0,0.25);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  color: var(--accent);
  line-height: 1.6;
}

/* ── Map marker styles (injected into leaflet) ──────────────────────────── */
.rider-marker-label {
  background: rgba(10,10,10,0.85);
  border: 2px solid currentColor;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 6px;
  white-space: nowrap;
  pointer-events: none;
  font-family: var(--font);
}

/* ── Tabs (admin mobile) ─────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  font-family: var(--font);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #333; }

/* ── Notification toast ──────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  z-index: 9000;
  white-space: nowrap;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease;
  pointer-events: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.footer-note {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  padding: 24px 0 32px;
}
