/* RoadSafetyLens look and feel: navy/red palette, white cards, Arial everywhere. */

:root {
    --navy: #12355B;
    --blue: #1E5A8A;
    --red: #C62828;
    --green: #2E7D32;
    --ink: #1F2937;
    --muted: #5B6B7C;
    --bg: #F7FAFC;
    --panel: #EAF3FA;
    --line: #D7E3EF;
    --soft: #EEF3F8;
    --font: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--ink);
    font-family: var(--font); font-size: 16px; line-height: 1.6;
}
h1, h2, h3, h4 { color: var(--navy); line-height: 1.25; }
h2 { font-size: 1.75rem; margin: 2rem 0 0.8rem; }
h3 { font-size: 1.2rem; margin: 1.4rem 0 0.6rem; }
a { color: #1565C0; }
p { margin: 0 0 0.8rem; }
ul { margin: 0 0 0.8rem; padding-left: 1.4rem; }
li { margin: 0.15rem 0; }
code { background: var(--soft); border-radius: 4px; padding: 1px 5px; font-size: 0.9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.6rem 0; }

/* ---------- Layout: sidebar + main ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: 290px; flex: 0 0 290px; background: var(--panel); padding: 20px 16px 40px;
    position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--line);
}
.sidebar-brand { font-weight: 700; color: var(--navy); font-size: 1.15rem; margin: 2px 8px 14px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
    display: flex; gap: 10px; align-items: center; padding: 6px 10px; border-radius: 8px;
    color: var(--ink); text-decoration: none; font-size: 0.95rem;
}
.nav a span { width: 1.4em; text-align: center; }
.nav a:hover { background: rgba(18, 53, 91, 0.07); }
.nav a.active { background: rgba(18, 53, 91, 0.12); font-weight: 700; color: var(--navy); }
#sidebar-extra:not(:empty) { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 6px; }
.sidebar h3 { margin: 14px 0 8px; font-size: 1.15rem; }
.sidebar h4 { margin: 18px 0 6px; font-size: 1rem; }
.main { flex: 1; min-width: 0; padding: 1.6rem 2.2rem 3rem; max-width: 1360px; margin: 0 auto; }

.topbar { display: none; }
.scrim { display: none; }

/* ---------- Loading ---------- */
.loading { text-align: center; padding: 18vh 0; color: var(--muted); }
.spinner {
    width: 38px; height: 38px; margin: 0 auto 14px; border-radius: 50%;
    border: 4px solid var(--line); border-top-color: var(--navy); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: #FCECEC; border-left: 6px solid var(--red); padding: 14px 18px; border-radius: 10px; }

/* ---------- Banner, cards, badges, callouts ---------- */
.rsl-banner {
    background: linear-gradient(90deg, var(--navy), var(--blue)); color: #fff;
    border-radius: 16px; padding: 22px 26px; margin-bottom: 18px;
}
.rsl-banner h1 { color: #fff; margin: 0; font-size: 2rem; }
.rsl-banner p { color: #EAF3FA; margin: 6px 0 0 0; font-size: 1.05rem; }
.rsl-card {
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    padding: 16px 18px; margin-bottom: 12px; color: var(--ink);
}
.rsl-badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px; line-height: 1.3;
    color: #fff; font-weight: 700; font-size: 0.85rem;
}
.rsl-callout {
    border-left: 6px solid var(--c); background: var(--bg-c); border-radius: 10px;
    padding: 14px 18px; margin: 8px 0 14px 0; color: var(--ink);
}
.rsl-callout ul { margin: 4px 0 0 0; }
.rsl-small, .caption { color: var(--muted); font-size: 0.85rem; }
.caption { margin: 0.2rem 0 0.9rem; }
.rsl-bar { background: var(--soft); border-radius: 6px; height: 12px; overflow: hidden; }
.rsl-bar > div { background: var(--navy); height: 12px; }
.score-table { width: 100%; border-collapse: separate; border-spacing: 0 8px; color: var(--ink); }
.info-box { background: #E8F1FB; color: #164A7A; border-radius: 10px; padding: 14px 18px; margin: 0 0 12px; }
.warn-box { background: #FFF8E1; color: #6D4C00; border-radius: 10px; padding: 12px 16px; margin: 6px 0 12px; }

/* ---------- Columns ---------- */
.cols { display: flex; gap: 1.2rem; align-items: flex-start; margin-bottom: 0.6rem; }
.cols > .col { min-width: 0; }
.cols.center { align-items: center; }
.metrics { display: grid; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); gap: 1rem; margin: 0 0 1rem; }

/* ---------- Metrics ---------- */
.metric {
    background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
    box-shadow: 0 2px 8px rgba(18, 53, 91, 0.05); min-width: 0;
}
.metric-label { font-size: 0.875rem; color: var(--ink); display: flex; gap: 6px; align-items: flex-start; }
.metric-value { color: var(--navy); font-weight: 700; font-size: clamp(1.35rem, 2.6vw, 2.25rem); line-height: 1.25; }

/* help "?" with a tooltip on hover or tap */
.help {
    position: relative; display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 16px; height: 16px; border-radius: 50%; border: 1px solid #9AA5B1; color: var(--muted);
    font-size: 11px; line-height: 1; cursor: help; margin-top: 2px; font-weight: 400;
}
.help .tip {
    display: none; position: absolute; z-index: 30; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%);
    width: max-content; max-width: 260px; background: #1F2937; color: #fff; padding: 8px 10px;
    border-radius: 8px; font-size: 0.8rem; line-height: 1.4; text-align: left; white-space: normal;
}
.help:hover .tip, .help:focus .tip { display: block; }

/* ---------- Buttons and inputs ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-size: 0.95rem; padding: 7px 14px; border-radius: 8px; cursor: pointer;
    background: #fff; color: var(--ink); border: 1px solid #C9D6E3; text-decoration: none; line-height: 1.4;
}
.btn:hover { border-color: var(--navy); color: var(--navy); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--blue); color: #fff; }
.btn.wide { width: 100%; }
.btn.small { padding: 4px 12px; font-size: 0.9rem; }

.field { margin-bottom: 0.9rem; min-width: 0; }
.field > label, .field > .label {
    display: flex; gap: 6px; align-items: center; font-size: 0.875rem; margin-bottom: 4px; color: var(--ink);
}
.input, .select, textarea.input {
    width: 100%; font: inherit; font-size: 0.95rem; color: var(--ink); background: #fff;
    border: 1px solid #C9D6E3; border-radius: 8px; padding: 8px 10px; line-height: 1.4;
}
textarea.input { resize: vertical; min-height: 90px; }
.input:focus, .select:focus, textarea.input:focus, .ms-box:focus-within, .combo input:focus {
    outline: 2px solid rgba(18, 53, 91, 0.35); outline-offset: 0; border-color: var(--navy);
}
.select { appearance: none; padding-right: 30px; cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, #5B6B7C 50%), linear-gradient(135deg, #5B6B7C 50%, transparent 50%);
    background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
    background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

/* multiselect */
.ms { position: relative; }
.ms-box {
    display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-height: 40px; cursor: text;
    border: 1px solid #C9D6E3; border-radius: 8px; padding: 4px 30px 4px 6px; background: #fff; position: relative;
}
.ms-box::after { content: "▾"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.8rem; }
.chip {
    display: inline-flex; align-items: center; gap: 4px; background: var(--navy); color: #fff;
    border-radius: 6px; padding: 1px 4px 1px 8px; font-size: 0.82rem; max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { background: none; border: 0; color: #fff; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 3px; }
.ms-box input { border: 0; outline: 0; flex: 1; min-width: 70px; font: inherit; font-size: 0.92rem; padding: 3px 4px; background: transparent; }
.dropdown {
    position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px); background: #fff;
    border: 1px solid #C9D6E3; border-radius: 8px; box-shadow: 0 8px 24px rgba(18, 53, 91, 0.15);
    max-height: 300px; overflow-y: auto; padding: 4px 0;
}
.dropdown .opt { padding: 7px 12px; cursor: pointer; font-size: 0.92rem; line-height: 1.35; }
.dropdown .opt:hover, .dropdown .opt.hi { background: var(--panel); }
.dropdown .opt.sel { font-weight: 700; color: var(--navy); }
.dropdown .empty { padding: 8px 12px; color: var(--muted); font-size: 0.9rem; }

/* searchable single select */
.combo { position: relative; }
.combo input { padding-right: 30px; text-overflow: ellipsis; }
.combo::after { content: "▾"; position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 0.8rem; pointer-events: none; }

/* toggle switch */
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 0.92rem; margin: 6px 0 12px; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { width: 36px; height: 20px; border-radius: 999px; background: #C9D6E3; position: relative; flex: none; transition: background 0.15s; }
.toggle .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left 0.15s; }
.toggle input:checked + .track { background: var(--navy); }
.toggle input:checked + .track::after { left: 18px; }
.toggle input:focus-visible + .track { outline: 2px solid rgba(18, 53, 91, 0.45); outline-offset: 2px; }
.toggle.disabled { opacity: 0.5; cursor: not-allowed; }

/* slider */
.slider-head { display: flex; justify-content: space-between; gap: 6px; font-size: 0.85rem; }
.slider-head b { color: var(--navy); }
input[type=range] { width: 100%; accent-color: var(--navy); }

/* expander */
details.expander { border: 1px solid var(--line); border-radius: 10px; background: #fff; margin: 0.6rem 0 1rem; }
details.expander > summary { cursor: pointer; padding: 10px 14px; font-size: 0.95rem; }
details.expander[open] > summary { border-bottom: 1px solid var(--line); }
details.expander > .body { padding: 12px 14px; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; margin-bottom: 0.8rem; }
table.data { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
table.data th {
    position: sticky; top: 0; z-index: 1; background: #F3F7FB; text-align: left; font-weight: 600;
    padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none;
    color: #374151;
}
table.data th.num, table.data td.num { text-align: right; }
table.data th .arrow { color: var(--navy); margin-left: 3px; }
/* one line per row; long text is cut with "…" (the full text shows on hover) */
table.data td {
    padding: 6px 10px; border-bottom: 1px solid #EEF2F6; vertical-align: top;
    white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis;
}
table.data tr:last-child td { border-bottom: 0; }
table.data.clickable tbody tr { cursor: pointer; }
table.data.clickable tbody tr:hover td { background: #F1F6FB; }
td.progress { min-width: 120px; }
td.progress .pbar { display: flex; align-items: center; gap: 8px; }
td.progress .pbar .rsl-bar { flex: 1; height: 8px; }
td.progress .pbar .rsl-bar > div { height: 8px; }
td.progress .pbar b { font-weight: 400; min-width: 2ch; text-align: right; }
.table-tools { display: flex; justify-content: flex-end; margin: -0.3rem 0 0.3rem; }
.link-btn { background: none; border: 0; color: #1565C0; cursor: pointer; font: inherit; font-size: 0.82rem; padding: 2px 0; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Charts and maps ---------- */
.chart { width: 100%; }
.map { width: 100%; border-radius: 10px; overflow: hidden; }

/* lists with a button on the right */
.row-item { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.row-item > .grow { flex: 1; min-width: 0; }
.row-item > .btn { flex: none; }

.footer { color: var(--muted); font-size: 0.85rem; }
.footer p { margin-bottom: 0.6rem; }

/* ---------- Phones and small tablets ---------- */
@media (max-width: 1100px) {
    .metric { padding: 10px; }
    .metric-label { font-size: 0.78rem; }
}
@media (max-width: 900px) {
    .topbar {
        display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 50;
        background: #fff; border-bottom: 1px solid var(--line); padding: 8px 12px;
    }
    .topbar-title { font-weight: 700; color: var(--navy); }
    .menu-btn { font-size: 1.3rem; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 2px 10px; cursor: pointer; color: var(--navy); }
    .sidebar {
        position: fixed; z-index: 60; left: 0; top: 0; height: 100vh; transform: translateX(-105%);
        transition: transform 0.2s; box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15); width: min(320px, 86vw); flex-basis: auto;
    }
    body.menu-open .sidebar { transform: none; }
    body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(15, 23, 42, 0.35); }
    .sidebar-brand { display: none; }
    .main { padding: 1rem 16px 2.5rem; }
}
@media (max-width: 640px) {
    .cols { flex-direction: column; gap: 0.2rem; align-items: stretch; }
    .cols > .col { width: 100%; flex: none !important; }
    .cols.keep { flex-direction: row; gap: 0.8rem; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
    .rsl-banner { padding: 16px 18px; }
    .rsl-banner h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
}
@media print {
    .sidebar, .topbar { display: none; }
}
