/* ═══════════════════════════════════════════════════
   Road Data v3 — Styles
   ═══════════════════════════════════════════════════ */

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --border:     rgba(255,255,255,0.08);
  --border2:    rgba(255,255,255,0.14);
  --text:       #f0f2f8;
  --muted:      #7b82a0;
  --accent:     #3b82f6;
  --accent-dim: rgba(59,130,246,0.15);
  --green:      #22c55e;
  --green-dim:  rgba(34,197,94,0.12);
  --amber:      #f59e0b;
  --amber-dim:  rgba(245,158,11,0.12);
  --red:        #ef4444;
  --red-dim:    rgba(239,68,68,0.12);
  --radius:     14px;
  --radius-sm:  8px;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { display: flex; flex-direction: column; max-width: 480px; margin: 0 auto; position: relative; }

/* ── Auth ── */
.auth-wrap {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 32px 24px;
}
.auth-logo  { font-size: 52px; margin-bottom: 16px; }
.auth-title { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 6px; }
.auth-sub   { font-size: 14px; color: var(--muted); margin-bottom: 32px; text-align: center; line-height: 1.5; }
.auth-card  { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.auth-card h2 { font-size: 17px; font-weight: 600; margin-bottom: 20px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth-switch a { color: var(--accent); cursor: pointer; }
.auth-error { background: var(--red-dim); border: 1px solid rgba(239,68,68,.25); color: var(--red); border-radius: var(--radius-sm); padding: 10px 13px; font-size: 13px; margin-bottom: 14px; display: none; }
.auth-error.show { display: block; }

/* ── Form fields ── */
.field { margin-bottom: 14px; }
.field label, .input-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .input-field {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
  padding: 11px 13px; outline: none; transition: border-color .2s;
}
.field input:focus, .field select:focus, .input-field:focus { border-color: var(--accent); }
.field select option, .input-field option { background: var(--surface2); }
.input-field { font-size: 13px; padding: 10px 12px; }

/* ── Buttons ── */
.btn-primary {
  width: 100%; padding: 13px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
  cursor: pointer; transition: opacity .2s; margin-top: 4px;
}
.btn-primary:active   { opacity: .85; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-sm {
  padding: 9px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface2); color: var(--text); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-sm:active          { transform: scale(.97); }
.btn-sm.primary         { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-sm.danger          { background: var(--red-dim); border-color: rgba(239,68,68,.3); color: var(--red); }
.btn-sm.success         { background: var(--green-dim); border-color: rgba(34,197,94,.3); color: var(--green); }

.toggle-btn {
  width: 100%; padding: 15px; border: none; border-radius: var(--radius);
  font-size: 16px; font-weight: 700; cursor: pointer; transition: all .2s;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.toggle-btn.start { background: var(--accent); color: #fff; }
.toggle-btn.stop  { background: var(--red-dim); border: 1px solid rgba(239,68,68,.3); color: var(--red); }
.toggle-btn:active { transform: scale(.98); }

/* ── Header ── */
.header {
  padding: max(env(safe-area-inset-top), 16px) 20px 0;
  background: var(--bg); z-index: 10; display: none;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 14px; border-bottom: 1px solid var(--border);
}
.logo           { display: flex; align-items: center; gap: 10px; }
.logo-icon      { width: 34px; height: 34px; background: var(--accent); border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.logo-text      { font-size: 18px; font-weight: 700; letter-spacing: -.3px; }
.logo-sub       { font-size: 11px; color: var(--muted); margin-top: 1px; }
.header-right   { display: flex; align-items: center; gap: 10px; }
.status-pill    { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid transparent; transition: all .3s; }
.status-pill.inactive { background: rgba(255,255,255,.05); border-color: var(--border); color: var(--muted); }
.status-pill.active   { background: var(--green-dim); border-color: rgba(34,197,94,.25); color: var(--green); }
.status-pill .dot     { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.5s infinite; }
.avatar-btn { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-dim); border: 1px solid var(--border2); color: var(--accent); font-size: 13px; font-weight: 700; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* ── Tabs ── */
.tabs { display: none; gap: 4px; padding: 14px 20px 0; background: var(--bg); }
.tab  { flex: 1; padding: 8px; border: none; background: none; color: var(--muted); font-size: 12px; font-weight: 500; border-radius: var(--radius-sm); cursor: pointer; transition: all .2s; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

/* ── Scroll / pages ── */
.scroll { flex: 1; overflow-y: auto; padding: 16px 20px; padding-bottom: max(env(safe-area-inset-bottom, 16px), 16px); -webkit-overflow-scrolling: touch; display: none; }
.page        { display: none; }
.page.active { display: block; }
.section-gap { height: 8px; }

/* ── Cards ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.card-label { font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }

/* ── Live meter ── */
.meter-value  { font-size: 42px; font-weight: 700; letter-spacing: -2px; line-height: 1; }
.meter-unit   { font-size: 14px; color: var(--muted); font-weight: 400; }
.meter-bar-bg { height: 8px; background: rgba(255,255,255,.06); border-radius: 99px; overflow: hidden; margin: 8px 0 5px; }
.meter-bar    { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--green)); transition: width .15s, background .3s; will-change: width; }
.meter-bar.warn { background: linear-gradient(90deg, var(--amber), var(--red)); }
#waveform-canvas { width: 100%; height: 72px; display: block; border-radius: var(--radius-sm); }

/* ── Stats ── */
.stats-row { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-bottom: 12px; }
.stat-card      { background: var(--surface2); border-radius: var(--radius-sm); padding: 10px; text-align: center; }
.stat-card .val { font-size: 20px; font-weight: 700; }
.stat-card .lbl { font-size: 10px; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .4px; }
.stat-card.red   .val { color: var(--red); }
.stat-card.amber .val { color: var(--amber); }
.stat-card.green .val { color: var(--green); }

/* ── Sensitivity sliders ── */
.sens-row       { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sens-row label { font-size: 13px; color: var(--muted); white-space: nowrap; min-width: 88px; }
input[type=range] { flex: 1; accent-color: var(--accent); cursor: pointer; }
.sens-val       { font-size: 13px; font-weight: 600; min-width: 34px; text-align: right; }

/* ── Event list ── */
.event-item       { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.event-item:last-child { border-bottom: none; }
.event-icon       { width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.event-icon.critical { background: var(--red-dim); }
.event-icon.high     { background: var(--amber-dim); }
.event-icon.medium   { background: var(--accent-dim); }
.event-info  { flex: 1; min-width: 0; }
.event-type  { font-size: 13px; font-weight: 600; }
.event-road  { font-size: 11px; color: var(--accent); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-loc   { font-size: 10px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-meta  { text-align: right; flex-shrink: 0; }
.event-g     { font-size: 15px; font-weight: 700; }
.event-g.critical { color: var(--red); }
.event-g.high     { color: var(--amber); }
.event-g.medium   { color: var(--accent); }
.event-time  { font-size: 10px; color: var(--muted); margin-top: 2px; }
.empty-state { text-align: center; padding: 40px 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.empty-state .icon { font-size: 36px; margin-bottom: 10px; display: block; opacity: .4; }

/* ── Settings ── */
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.setting-info .title { font-size: 14px; font-weight: 500; }
.setting-info .desc  { font-size: 12px; color: var(--muted); margin-top: 2px; }

.toggle-switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-switch .track { position: absolute; inset: 0; border-radius: 99px; background: rgba(255,255,255,.1); cursor: pointer; transition: background .2s; }
.toggle-switch input:checked + .track { background: var(--accent); }
.toggle-switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.toggle-switch input:checked + .track::after { transform: translateX(20px); }

/* ── Driver profile ── */
.profile-header  { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; }
.profile-avatar  { width: 52px; height: 52px; border-radius: 50%; background: var(--accent-dim); border: 2px solid var(--accent); display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; color: var(--accent); flex-shrink: 0; }
.profile-name    { font-size: 17px; font-weight: 700; }
.profile-role    { font-size: 12px; color: var(--muted); margin-top: 2px; }
.profile-stats   { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 14px; }
.p-stat          { background: var(--surface2); border-radius: var(--radius-sm); padding: 10px; text-align: center; }
.p-stat .v       { font-size: 18px; font-weight: 700; color: var(--accent); }
.p-stat .l       { font-size: 10px; color: var(--muted); margin-top: 2px; text-transform: uppercase; }

/* ── Modals ── */
.perm-modal    { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: flex-end; z-index: 200; backdrop-filter: blur(4px); }
.perm-sheet    { width: 100%; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; padding: 24px 24px max(env(safe-area-inset-bottom),24px); }
.perm-sheet h2 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.perm-sheet p  { font-size: 14px; color: var(--muted); line-height: 1.6; margin-bottom: 20px; }
.perm-item     { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.perm-item:last-child { border-bottom: none; margin-bottom: 20px; }
.perm-item .icon { width: 32px; height: 32px; border-radius: 9px; background: var(--accent-dim); display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; align-items: flex-end; z-index: 150; backdrop-filter: blur(3px); }
.modal-sheet   { width: 100%; background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; padding: 24px 24px max(env(safe-area-inset-bottom),24px); max-height: 90vh; overflow-y: auto; }
.modal-sheet h2 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal-actions  { display: flex; gap: 8px; margin-top: 20px; }

/* ── Misc ── */
.weather-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; background: var(--surface2); border: 1px solid var(--border); border-radius: 99px; font-size: 11px; color: var(--muted); }
.upload-row    { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.upload-dot    { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.upload-dot.syncing { background: var(--amber); animation: pulse 1s infinite; }
.upload-dot.synced  { background: var(--green); }
.upload-dot.error   { background: var(--red); }
.upload-text   { font-size: 12px; color: var(--muted); }

.data-badge          { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.data-badge.critical { background: var(--red-dim);   color: var(--red); }
.data-badge.high     { background: var(--amber-dim); color: var(--amber); }
.data-badge.medium   { background: var(--accent-dim);color: var(--accent); }

.diag-box { display: none; font-size: 11px; color: var(--amber); font-family: monospace; white-space: pre-wrap; line-height: 1.5; background: var(--surface2); padding: 10px; border-radius: var(--radius-sm); margin-top: 10px; word-break: break-all; }

.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface2); border: 1px solid var(--border); border-radius: 99px; padding: 10px 20px; font-size: 13px; font-weight: 500; white-space: nowrap; z-index: 999; opacity: 0; transition: all .3s; pointer-events: none; max-width: 92vw; text-align: center; }
.toast.show    { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error   { border-color: rgba(239,68,68,.4);  color: var(--red); }
.toast.success { border-color: rgba(34,197,94,.4);  color: var(--green); }
.toast.info    { border-color: rgba(59,130,246,.4); color: var(--accent); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-4px)} 40%{transform:translateX(4px)} 60%{transform:translateX(-3px)} 80%{transform:translateX(3px)} }
.shake { animation: shake .4s ease; }
