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

:root {
  --bg:          #0a0b0e;
  --sidebar-bg:  #0f1014;
  --surface:     #161820;
  --surface2:    #1e2028;
  --border:      #252830;
  --border-h:    #353844;
  --accent:      #5b8def;
  --accent-dim:  rgba(91,141,239,.12);
  --accent-h:    #4a7de8;
  --green:       #34d399;
  --green-dim:   rgba(52,211,153,.12);
  --red:         #f87171;
  --yellow:      #fbbf24;
  --text:        #e8eaf0;
  --text-muted:  #9ca3af;
  --text-3:      #4b5563;
  --radius:      6px;
  --shadow:      0 4px 24px rgba(0,0,0,.45);
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85em;
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
}

/* ── Sidebar ── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.sidebar-brand:hover { text-decoration: none; }

.brand-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -.02em;
  color: var(--text);
}

.sidebar-section {
  padding: 12px 8px 4px;
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0 8px;
  margin-bottom: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, color .12s;
  position: relative;
}
.nav-item:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.nav-icon { width: 16px; height: 16px; opacity: 0.8; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
}

.nav-badge-warn {
  margin-left: auto;
  background: rgba(251,191,36,.15);
  color: var(--yellow);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
}

.nav-live {
  margin-left: auto;
  width: 7px; height: 7px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.3; } }

.sidebar-spacer { flex: 1; }

.sidebar-user {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
}
.user-row:hover { background: var(--surface2); text-decoration: none; }

.user-avatar {
  width: 28px; height: 28px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 0.825rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.user-role { font-size: 0.7rem; color: var(--text-3); }

/* ── Main layout ── */
.main {
  margin-left: 220px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 52px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 40;
  gap: 12px;
}

.topbar-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-crumb { color: var(--text-3); font-weight: 400; flex-shrink: 0; }
.topbar-sep { color: var(--text-3); flex-shrink: 0; }

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ── Content area ── */
.content {
  padding: 24px 28px;
  flex: 1;
}

/* Legacy .page compatibility */
.page {
  padding: 24px 28px;
  flex: 1;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); border-color: var(--border-h); color: var(--text); text-decoration: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: .9; color: #fff; background: var(--accent); border-color: var(--accent); }

.btn-sm { padding: 4px 9px; font-size: 0.78rem; }

.btn-warn   { background: var(--yellow); border-color: var(--yellow); color: #000; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 4px 0;
}
.btn-link:hover { color: var(--text); }

/* ── Alerts ── */
.alert {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: .875rem;
}
.alert-error   { background: rgba(248,113,113,.12); border: 1px solid rgba(248,113,113,.35); color: #fca5a5; }
.alert-success { background: rgba(52,211,153,.12);  border: 1px solid rgba(52,211,153,.35);  color: #6ee7b7; }

/* ── Auth pages ── */
.auth-page {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 5rem 1rem;
  min-height: 100vh;
}

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

.auth-card h1 { margin-bottom: 1.5rem; font-size: 1.4rem; }
.auth-card form { display: flex; flex-direction: column; gap: 1rem; }

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .875rem;
  color: var(--text-muted);
}

.auth-card input[type="email"],
.auth-card input[type="password"] {
  padding: .55rem .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}
.auth-card input:focus { border-color: var(--accent); }

.auth-footer {
  margin-top: 1.25rem;
  font-size: .875rem;
  color: var(--text-muted);
  text-align: center;
}

.hint { font-size: .8rem; color: var(--text-muted); margin-left: .25rem; }

/* ── Page header (legacy) ── */
.page-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}
.page-header h1 { font-size: 1.4rem; font-weight: 700; }

.back-link {
  font-size: .82rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: .2rem;
}
.back-link:hover { color: var(--text); text-decoration: none; }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table thead { background: var(--surface2); }

.data-table th {
  padding: .65rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

.data-table td {
  padding: .7rem 1rem;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: rgba(255,255,255,.025); }

.mono { font-family: monospace; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.small { font-size: .82rem; }
.row-inactive { opacity: .5; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  background: var(--surface2);
  color: var(--text-muted);
}
.badge-green { background: var(--green-dim);           color: var(--green); }
.badge-red   { background: rgba(248,113,113,.12);      color: var(--red); }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.card h2 {
  font-size: .72rem;
  font-weight: 600;
  margin-bottom: .9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Route meta grid ── */
.route-meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.meta-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1.25rem;
  min-width: 130px;
}

.meta-label {
  display: block;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin-bottom: .2rem;
  font-weight: 600;
}

.meta-value {
  font-size: 1rem;
  font-weight: 600;
}

/* ── Inline form ── */
.inline-form {
  display: flex;
  gap: .75rem;
  align-items: center;
  flex-wrap: wrap;
}

.input-text {
  padding: .5rem .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .875rem;
  outline: none;
  width: 220px;
  transition: border-color .15s;
}
.input-text:focus { border-color: var(--accent); }
.input-text--sm   { width: 160px; font-size: .85rem; padding: .35rem .6rem; }

/* ── Vehicle select ── */
.vehicle-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .82rem;
  padding: .3rem .55rem;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}
.vehicle-select:focus { border-color: var(--accent); }

/* ── Token display ── */
.token-display {
  font-size: .82rem;
  word-break: break-all;
  padding: 3px 8px;
  background: var(--surface2);
  border-radius: 4px;
  user-select: all;
}
.token-short { color: var(--text-muted); cursor: help; }

/* ── Help text ── */
.help-text {
  font-size: .875rem;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 1.5rem;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: .95rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* ── Actions ── */
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ── Admin form ── */
.create-user-form .form-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.create-user-form label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .85rem;
  color: var(--text-muted);
}

.label-checkbox {
  flex-direction: row !important;
  align-items: center;
  gap: .5rem !important;
  font-size: .9rem !important;
  color: var(--text) !important;
  padding-bottom: .1rem;
}

.label-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Map markers ── */
.map-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: bold;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
}
.map-marker--start { background: #22c55e; color: #fff; }
.map-marker--end   { background: #ef4444; color: #fff; }

/* ── Map toolbar ── */
.map-toolbar {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
  margin-bottom: .5rem;
}
.layer-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .35rem .85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.layer-btn:hover  { background: var(--surface); color: var(--text); }
.layer-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.layer-sep        { width: 1px; height: 24px; background: var(--border); margin: 0 .2rem; }

/* ── Share panel ── */
.share-panel {
  margin-top: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.share-panel h3 {
  font-size: .72rem;
  font-weight: 600;
  margin-bottom: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.share-url-row {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}
.share-url-input {
  flex: 1;
  min-width: 0;
  padding: .45rem .75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .85rem;
  font-family: monospace;
  outline: none;
}
.share-hint    { font-size: .8rem; color: var(--text-muted); }
.share-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.share-option {
  display: flex; align-items: center; gap: .5rem;
  margin-bottom: .75rem; font-size: .88rem;
}
.share-option input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }

/* ── Shared public page ── */
.shared-badge {
  display: inline-block;
  font-size: .8rem;
  padding: .2rem .65rem;
  background: rgba(91,141,239,.15);
  border: 1px solid rgba(91,141,239,.35);
  border-radius: 999px;
  color: #93c5fd;
}
.shared-readonly-hint {
  margin-top: 1rem;
  font-size: .82rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Live indicator ── */
.route-live {
  display: inline-block;
  color: var(--green);
  font-size: .65rem;
  vertical-align: middle;
  margin-left: .3rem;
  animation: pulse-live 1.6s ease-in-out infinite;
}
@keyframes pulse-live {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

/* ── Legacy navbar (shared page, login fallback) ── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 52px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { color: var(--text-muted); font-size: .875rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links .active { color: var(--text); }
.nav-links .nav-admin { color: var(--yellow); }

/* ── Mobile Top Nav ── */
.mobile-topnav {
  display: none;
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 52px;
  align-items: center;
  justify-content: space-between;
}
.mobile-brand {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
}
.mobile-brand:hover { text-decoration: none; color: var(--text); }
.mobile-menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius);
}
.mobile-menu-btn:hover { color: var(--text); background: var(--surface); }
.mobile-menu {
  display: none;
  position: absolute;
  top: 52px;
  left: 0;
  right: 0;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
  box-shadow: var(--shadow);
}
.mobile-topnav.open .mobile-menu { display: block; }
.mobile-nav-item {
  display: block;
  padding: 10px 20px;
  color: var(--text-muted);
  font-size: .875rem;
  text-decoration: none;
}
.mobile-nav-item:hover { color: var(--text); background: var(--surface); text-decoration: none; }
.mobile-nav-item.active { color: var(--text); background: var(--accent-dim); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .mobile-topnav { display: flex; }
  .main { margin-left: 0; }
  .topbar { padding: 0 16px; }
  .content, .page { padding: 16px; }
}

@media (max-width: 640px) {
  .auth-card { padding: 1.75rem 1.25rem; }
  .route-meta-grid { flex-direction: column; }
  .create-user-form .form-row { flex-direction: column; align-items: stretch; }
  .share-url-row { flex-direction: column; align-items: stretch; }
  .share-actions  { flex-direction: column; }
  .map-toolbar    { gap: .4rem; }

  /* Compact table for mobile */
  .data-table th,
  .data-table td { padding: .45rem .5rem; font-size: .78rem; }
  .data-table .actions { gap: .25rem !important; }
  .data-table .btn-sm { padding: 3px 6px; font-size: .7rem; }
  .hide-mobile { display: none !important; }
  #bulkToolbar { display: none !important; }

  /* Topbar compact */
  .topbar { flex-wrap: wrap; gap: .5rem; padding: 0 12px; }
  .topbar-title { font-size: .82rem; }
  .topbar-actions .btn { padding: 4px 8px; font-size: .75rem; }

  /* Page header */
  .page-header h1 { font-size: 1.1rem; }
}
