:root {
    --bg: #05090c;
    --panel: #0b1116;
    --panel-2: #111920;
    --line: rgba(255,255,255,.1);
    --muted: #9ca7b2;
    --text: #f4f7fa;
    --red: #f11221;
    --green: #27e34b;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { background: radial-gradient(circle at 50% 0%, rgba(241,18,33,.13), transparent 34%), #05090c; }
a { color: var(--text); text-decoration: none; }
button, input { font: inherit; }

.brand-mark { display: flex; align-items: center; gap: 10px; letter-spacing: 0; }
.brand-mark span { color: var(--red); font-size: 28px; font-weight: 1000; font-style: italic; line-height: 1; }
.brand-mark strong { font-size: 15px; letter-spacing: .04em; }
.brand-mark.compact { display: none; }

.login-screen { display: grid; min-height: 100vh; place-items: center; padding: 22px; }
.login-shell { width: min(440px, 100%); }
.login-panel { border: 1px solid var(--line); background: linear-gradient(145deg, rgba(17,25,32,.96), rgba(5,9,12,.96)); border-radius: 8px; padding: 28px; box-shadow: 0 22px 60px rgba(0,0,0,.45); }
.login-panel h1 { margin: 30px 0 18px; font-size: 30px; }
.login-form { display: grid; gap: 16px; }
.login-form label { display: grid; gap: 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 800; }
.login-form input { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #05090c; color: var(--text); padding: 14px 13px; }
.login-form .check-row { display: flex; align-items: center; gap: 10px; text-transform: none; color: #dce3e9; }
.login-form .check-row input { width: 18px; height: 18px; accent-color: var(--red); }
.alert { border: 1px solid rgba(241,18,33,.45); background: rgba(241,18,33,.12); color: #ff98a0; border-radius: 6px; padding: 10px 12px; margin-bottom: 16px; }
.primary-button, .primary-link { border: 0; border-radius: 6px; background: linear-gradient(135deg, var(--red), #b90914); color: white; padding: 13px 18px; font-weight: 900; cursor: pointer; text-align: center; }

.app-body { min-height: 100vh; padding-left: 116px; padding-bottom: 92px; }
.sidebar { position: fixed; inset: 0 auto 0 0; width: 116px; border-right: 1px solid var(--line); background: rgba(5,9,12,.92); display: flex; flex-direction: column; align-items: center; padding: 26px 12px; z-index: 5; }
.sidebar .brand-mark { flex-direction: column; gap: 2px; margin-bottom: 44px; }
.sidebar .brand-mark strong { font-size: 12px; }
.sidebar nav { display: grid; gap: 12px; width: 100%; }
.sidebar a { color: var(--muted); font-size: 12px; font-weight: 900; text-transform: uppercase; padding: 12px 8px; border-radius: 6px; text-align: center; }
.sidebar a.active, .sidebar a:hover { color: var(--red); background: rgba(241,18,33,.08); }
.logout-link { margin-top: auto; color: var(--red) !important; }

.dashboard { width: min(1160px, 100%); margin: 0 auto; padding: 22px; }
.topbar, .page-header { min-height: 54px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.page-header h1 { margin: 0; font-size: 28px; }
.status-pill { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; font-size: 12px; font-weight: 1000; color: var(--muted); }
.status-pill.tracking { color: var(--green); border-color: rgba(39,227,75,.35); background: rgba(39,227,75,.09); }
.status-pill.paused { color: #ffd75a; border-color: rgba(255,215,90,.35); }
.status-pill.idle { color: var(--muted); }

.hero-grid, .card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.card-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-top: 12px; }
.metric, .panel { border: 1px solid var(--line); background: linear-gradient(145deg, rgba(17,25,32,.86), rgba(7,12,16,.92)); border-radius: 8px; box-shadow: inset 0 1px 0 rgba(255,255,255,.035); }
.metric { min-height: 104px; padding: 16px; position: relative; overflow: hidden; }
.metric:after { content: ""; position: absolute; left: 16px; right: 16px; bottom: 12px; height: 2px; background: linear-gradient(90deg, var(--red), transparent); }
.metric label { display: block; color: var(--muted); font-size: 12px; font-weight: 1000; text-transform: uppercase; margin-bottom: 14px; }
.metric output { display: block; font-family: "Arial Black", Impact, system-ui, sans-serif; font-size: clamp(26px, 5vw, 56px); line-height: .95; letter-spacing: 0; }
.metric small { color: var(--muted); display: block; margin-top: 8px; text-align: center; }
.metric:not(.hero) output { font-size: 27px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.speed-tile > div:first-of-type { display: flex; align-items: end; gap: 8px; }
.speed-tile span { color: var(--muted); margin-bottom: 5px; }
.speed-ring { position: absolute; right: 22px; top: 34px; width: 96px; aspect-ratio: 1; border-radius: 50%; border: 12px solid rgba(255,255,255,.08); border-left-color: var(--red); border-top-color: var(--red); }
.speed-ring i { position: absolute; width: 3px; height: 40px; background: white; left: 50%; bottom: 50%; transform-origin: bottom center; transform: rotate(-110deg); }

.panel { margin-top: 12px; padding: 16px; }
.panel header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.panel h2 { margin: 0 0 12px; font-size: 15px; text-transform: uppercase; }
.panel h2 span { color: var(--muted); font-weight: 600; }
.panel header h2 { margin: 0; }
.panel header a { color: var(--red); font-weight: 900; font-size: 12px; text-transform: uppercase; }
.summary-line { color: var(--muted); margin: 0; }
.filter-form, .edit-form { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; align-items: end; }
.filter-form label, .edit-form label { display: grid; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.filter-form input, .edit-form input, .edit-form textarea { border: 1px solid var(--line); border-radius: 6px; background: #05090c; color: var(--text); padding: 11px 10px; width: 100%; }
.edit-form textarea { min-height: 78px; resize: vertical; }
.secondary-button, .table-button { border: 1px solid var(--line); border-radius: 6px; color: var(--text); padding: 12px 14px; font-weight: 900; text-align: center; background: rgba(255,255,255,.04); }
.table-button { padding: 8px 10px; display: inline-block; }
.route-map { height: 330px; width: 100%; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #0b1116; }
.leaflet-container { background: #0b1116; color: #111; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 620px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
td { color: #dce3e9; font-size: 14px; }
tbody tr:hover { background: rgba(255,255,255,.03); }
#lastLaps td:first-child { color: var(--red); font-weight: 1000; font-size: 18px; }
.log-strip #liveNotes { color: var(--muted); min-height: 24px; }

.action-bar { position: fixed; left: 116px; right: 0; bottom: 0; min-height: 78px; padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); background: rgba(5,9,12,.92); backdrop-filter: blur(16px); border-top: 1px solid var(--line); display: flex; justify-content: center; gap: 10px; z-index: 10; }
.action-bar button { width: min(180px, 30vw); border: 1px solid var(--line); border-radius: 8px; color: white; padding: 16px; font-weight: 1000; text-transform: uppercase; cursor: pointer; }
.action-bar button:disabled { opacity: .45; cursor: not-allowed; }
.start { background: #0f7e26; }
.pause { background: #28313a; }
.stop { background: linear-gradient(135deg, var(--red), #a80812); }

@media (max-width: 1180px) {
    .card-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filter-form, .edit-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
    .app-body { padding-left: 0; }
    .sidebar { display: none; }
    .dashboard { padding: 14px 12px 108px; }
    .brand-mark.compact { display: flex; }
    .topbar { position: sticky; top: 0; z-index: 4; background: rgba(5,9,12,.9); backdrop-filter: blur(14px); }
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-form, .edit-form { grid-template-columns: 1fr; }
    .route-map { height: 270px; }
    .action-bar { left: 0; border-radius: 18px 18px 0 0; }
    .action-bar button { width: 33.3%; min-height: 72px; }
}

@media (max-width: 560px) {
    .hero-grid { grid-template-columns: 1fr 1fr; }
    .metric { min-height: 84px; padding: 13px; }
    .metric label { font-size: 10px; margin-bottom: 10px; }
    .metric.hero output { font-size: clamp(34px, 11vw, 46px); }
    .metric:not(.hero) output { font-size: 19px; }
    .speed-ring { width: 76px; right: 12px; top: 42px; border-width: 9px; opacity: .85; }
    .speed-ring i { height: 31px; }
    .speed-tile > div:first-of-type span { font-size: 12px; }
    .panel { padding: 12px; }
    th, td { padding: 10px 8px; font-size: 12px; }
}
