/* Falcon Flex — Custom styles layered on top of Tailwind CDN */

:root {
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --bg-muted: #f1f5f9;
  --fg: #0f172a;
  --fg-muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #059669;
  --primary-hover: #047857;
  --primary-soft: #d1fae5;
  --primary-bg: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --info: #2563eb;
  --info-soft: #dbeafe;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.08);
  --shadow-lg: 0 12px 32px rgba(15,23,42,0.12);
  --shadow-emerald: 0 8px 24px rgba(5,150,105,0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --bg-soft: #111a2c;
    --bg-muted: #1a2540;
    --fg: #f1f5f9;
    --fg-muted: #94a3b8;
    --border: #1f2a44;
    --border-strong: #334155;
    --primary-soft: rgba(16,185,129,0.16);
    --primary-bg: rgba(5,150,105,0.10);
    --danger-soft: rgba(220,38,38,0.12);
    --warning-soft: rgba(217,119,6,0.12);
    --info-soft: rgba(37,99,235,0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.45);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ── Layout ────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.full { min-height: 100vh; min-height: 100svh; }
.flex { display: flex; }
.center { display: flex; align-items: center; justify-content: center; }
.col { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
@media (prefers-color-scheme: dark) {
  .topbar { background: rgba(11,18,32,0.85); }
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 12px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; letter-spacing: -0.01em;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #10b981);
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; box-shadow: var(--shadow-emerald);
}
.brand-mark svg { width: 20px; height: 20px; stroke-width: 2.4; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card.elevated { box-shadow: var(--shadow-md); }
.card-body { padding: 20px; }
.card-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0; color: var(--fg); }
.card-sub { font-size: 12px; color: var(--fg-muted); margin: 0; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--bg-muted); color: var(--fg);
  font-weight: 600; font-size: 14px; transition: transform .04s ease, background .15s ease, box-shadow .15s ease, opacity .15s;
  white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: 0 6px 16px rgba(5,150,105,0.25);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border-color: var(--border-strong); }
.btn-outline:hover { background: var(--bg-muted); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 38px; height: 38px; padding: 0; }

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  background: var(--bg-muted); color: var(--fg-muted);
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-online {
  background: var(--primary-soft); color: var(--primary);
}
.live-dot {
  position: relative; width: 8px; height: 8px; border-radius: 999px; background: var(--primary);
}
.live-dot::after {
  content: ""; position: absolute; inset: 0; border-radius: 999px;
  background: var(--primary); opacity: 0.5;
  animation: ping 1.4s cubic-bezier(0,0,0.2,1) infinite;
}
@keyframes ping {
  75%, 100% { transform: scale(2.2); opacity: 0; }
}

/* ── Inputs ─────────────────────────────────────────────── */
.label { display: block; font-size: 13px; font-weight: 500; color: var(--fg); margin-bottom: 6px; }
.input, .textarea, .select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-strong); background: var(--bg);
  color: var(--fg); border-radius: var(--radius-sm); font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.15);
}
.input.with-icon { padding-left: 38px; }
.input-wrap { position: relative; }
.input-wrap .input-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--fg-muted); pointer-events: none;
}
.input-wrap .input-action {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-muted); background: transparent; border: 0; border-radius: 6px;
}
.input-wrap .input-action:hover { background: var(--bg-muted); color: var(--fg); }
.textarea { min-height: 100px; resize: vertical; }

/* ── Switch ─────────────────────────────────────────────── */
.switch {
  position: relative; display: inline-block; width: 44px; height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border-strong); transition: 0.2s; border-radius: 999px;
}
.switch-slider::before {
  content: ""; position: absolute; height: 18px; width: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: 0.2s; box-shadow: var(--shadow-sm);
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13.5px; border: 1px solid;
}
.alert-danger { background: var(--danger-soft); border-color: rgba(220,38,38,0.25); color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: rgba(217,119,6,0.25); color: var(--warning); }
.alert-info { background: var(--info-soft); border-color: rgba(37,99,235,0.25); color: var(--info); }
.alert-success { background: var(--primary-soft); border-color: rgba(5,150,105,0.25); color: var(--primary); }
.alert .icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* ── Tabs ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-muted); border-radius: var(--radius-sm); }
.tab-btn {
  flex: 1; padding: 8px 12px; border-radius: 6px; background: transparent; border: 0;
  color: var(--fg-muted); font-weight: 600; font-size: 13px;
}
.tab-btn.active { background: var(--bg); color: var(--fg); box-shadow: var(--shadow-sm); }

/* ── Mobile bottom nav ──────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
}
.bottom-nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border: 0; background: transparent; color: var(--fg-muted);
  font-size: 11px; font-weight: 500; border-radius: var(--radius-sm);
  transition: color .15s;
}
.bottom-nav button.active { color: var(--primary); }
.bottom-nav button svg { width: 22px; height: 22px; stroke-width: 2; }

/* ── Driver list (admin) ────────────────────────────────── */
.driver-row {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.driver-row:last-child { border-bottom: 0; }
.avatar {
  width: 40px; height: 40px; border-radius: 999px;
  background: linear-gradient(135deg, #10b981, #059669); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px; flex-shrink: 0;
}

/* ── Skeleton ───────────────────────────────────────────── */
.skel {
  background: linear-gradient(90deg, var(--bg-muted) 0%, var(--border) 50%, var(--bg-muted) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Toast ──────────────────────────────────────────────── */
.toast-stack {
  position: fixed; right: 16px; bottom: 80px; z-index: 100;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
@media (min-width: 768px) {
  .toast-stack { bottom: 24px; }
}
.toast {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 16px; box-shadow: var(--shadow-lg); pointer-events: auto;
  display: flex; align-items: center; gap: 10px; max-width: 360px;
  animation: slidein 0.25s ease;
}
.toast.success { border-left: 3px solid var(--primary); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info { border-left: 3px solid var(--info); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Glow background ────────────────────────────────────── */
.bg-glow { position: relative; overflow: hidden; }
.bg-glow::before, .bg-glow::after {
  content: ""; position: absolute; width: 500px; height: 500px;
  border-radius: 999px; filter: blur(80px); pointer-events: none; z-index: 0;
}
.bg-glow::before { top: -200px; right: -200px; background: rgba(16,185,129,0.10); }
.bg-glow::after  { bottom: -200px; left: -200px; background: rgba(5,150,105,0.10); }
.bg-glow > * { position: relative; z-index: 1; }

/* ── Stat tile ──────────────────────────────────────────── */
.stat {
  padding: 16px; border-radius: var(--radius);
  background: var(--bg-soft); border: 1px solid var(--border);
}
.stat-label { font-size: 12px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }

/* ── Trip card ──────────────────────────────────────────── */
.trip-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  background: var(--bg); display: flex; flex-direction: column; gap: 12px;
}
.trip-card .row { display: flex; justify-content: space-between; align-items: center; }

/* ── Helpers ────────────────────────────────────────────── */
.muted { color: var(--fg-muted); }
.text-xs { font-size: 12px; } .text-sm { font-size: 13px; }
.font-semibold { font-weight: 600; } .font-bold { font-weight: 700; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; } .mt-8 { margin-top: 32px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.p-2 { padding: 8px; } .p-3 { padding: 12px; } .p-4 { padding: 16px; } .p-6 { padding: 24px; }
.text-center { text-align: center; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 640px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .hide-mobile { display: none !important; }
}
@media (min-width: 641px) {
  .show-mobile-only { display: none !important; }
}

/* Loader spinner */
.spinner {
  width: 16px; height: 16px; border-radius: 999px;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Bottom safe area for mobile screens with bottom nav */
.with-bottom-nav { padding-bottom: 88px; }

/* ── WS connection pill ─────────────────────────────────── */
.ws-pill {
  background: var(--bg-muted);
  color: var(--fg-muted);
  padding: 4px 10px;
  font-size: 11px;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-pill.connected   { background: var(--primary-soft); color: var(--primary); }
.ws-pill.disconnected{ background: var(--danger-soft);  color: var(--danger); }
.ws-pill.connecting  { background: var(--warning-soft); color: var(--warning); }
@media (max-width: 480px) {
  .ws-pill .ws-label { display: none; }
  .ws-pill { padding: 4px 8px; }
}

/* ── Leaflet map container ──────────────────────────────── */
.leaflet-map {
  width: 100%;
  height: 260px;
  background: var(--bg-muted);
  position: relative;
  z-index: 0;
}
@media (min-width: 768px) {
  .leaflet-map { height: 320px; }
}
.leaflet-container { font-family: inherit; }
.leaflet-control-attribution { font-size: 10px !important; opacity: 0.7; }
.driver-marker {
  background: var(--primary);
  width: 18px; height: 18px; border-radius: 999px;
  border: 3px solid #fff;
  box-shadow: 0 0 0 4px rgba(5,150,105,0.25), 0 4px 8px rgba(0,0,0,0.3);
}
.driver-marker.online::after {
  content: ""; position: absolute; inset: -8px; border-radius: 999px;
  background: var(--primary); opacity: 0.4;
  animation: ping 1.6s cubic-bezier(0,0,0.2,1) infinite;
}

/* ── Tighter mobile spacing ────────────────────────────── */
@media (max-width: 640px) {
  .driver-shell { padding: 12px; }
  .topbar-inner { padding: 10px 12px; gap: 8px; }
  .brand { font-size: 14px; gap: 8px; }
  .brand-mark { width: 32px; height: 32px; border-radius: 10px; }
  .brand-mark svg { width: 18px; height: 18px; }
  .stat { padding: 12px; }
  .stat-value { font-size: 18px; }
  .stat-label { font-size: 10px; }
  .card-head { padding: 12px 14px; }
  .card-body { padding: 14px; }
  .section-title { font-size: 14px; margin: 18px 0 10px; }
  h2 { font-size: 18px !important; }
  .modal { border-radius: 14px; max-height: calc(100vh - 16px); }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .btn { padding: 10px 14px; font-size: 14px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }
  .grid-2 { gap: 10px; }
  .grid-3 { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .driver-row { padding: 12px 14px; gap: 10px; }
  .avatar { width: 36px; height: 36px; font-size: 13px; }
  .topbar .btn-sm { padding: 6px 8px; }
}
@media (max-width: 380px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-3 > :nth-child(3) { grid-column: 1 / -1; }
  .stat-value { font-size: 17px; }
}

/* Section header */
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 700; color: var(--fg); margin: 24px 0 12px;
}

/* Empty state */
.empty {
  text-align: center; padding: 40px 20px; color: var(--fg-muted);
}
.empty svg { width: 48px; height: 48px; opacity: 0.4; margin-bottom: 12px; }

/* Login layout */
.login-shell {
  min-height: 100vh; min-height: 100svh;
  display: grid; grid-template-columns: 1fr; align-items: center; justify-items: center;
  padding: 24px; position: relative;
}
@media (min-width: 1024px) {
  .login-shell { grid-template-columns: 1fr 1fr; gap: 60px; max-width: 1100px; margin: 0 auto; }
}
.login-card { width: 100%; max-width: 420px; }
.login-hero {
  display: none;
}
@media (min-width: 1024px) {
  .login-hero {
    display: flex; flex-direction: column; gap: 20px;
    padding: 40px;
  }
  .login-hero h1 { font-size: 40px; line-height: 1.1; letter-spacing: -0.02em; margin: 0; }
  .login-hero p { color: var(--fg-muted); font-size: 16px; line-height: 1.6; }
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: fadein 0.15s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg); border-radius: var(--radius-lg);
  width: 100%; max-width: 480px; box-shadow: var(--shadow-lg);
  animation: slideup 0.2s ease;
  max-height: calc(100vh - 32px); overflow-y: auto;
}
@keyframes slideup { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head { padding: 20px 20px 12px; }
.modal-body { padding: 0 20px 12px; }
.modal-foot { padding: 12px 20px 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* JSON viewer */
.json-pre {
  background: var(--bg-muted); border-radius: 8px; padding: 12px;
  font-family: ui-monospace, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow: auto;
}

/* Driver dashboard layout */
.driver-shell { padding: 16px; }
@media (min-width: 768px) {
  .driver-shell { padding: 24px; }
}
.status-card {
  background: linear-gradient(135deg, var(--primary-bg), transparent);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px;
}
.status-card.online { background: linear-gradient(135deg, rgba(5,150,105,0.10), rgba(16,185,129,0.04)); border-color: rgba(5,150,105,0.25); }
