/* ─────────────────────────────────────────────────────────────────────────
   OBD2 module styles — everything is scoped under the `.obd2` root so the
   module can be injected into any host (standalone shell today, weathergpx
   later) without leaking. Host-level page background / html+body sizing lives
   in the host shell (index.html), NOT here. Relies on the shared weathergpx
   theme tokens (theme.css). Safe to tweak freely — Pierre edits this directly.
   ───────────────────────────────────────────────────────────────────────── */
.obd2, .obd2 *, .obd2 *::before, .obd2 *::after {
    box-sizing: border-box;
}

/* ── module root — fills its container, chrome on top + views below ─────────*/
.obd2 {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    color: var(--grey1);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-user-select: none;
    user-select: none;
}

/* ── top bar ─────────────────────────────────────────────────────────────*/
.obd2 .topbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.85rem;
    height: 52px;
    background: var(--blue8);
    border-bottom: 1px solid #0003;
    box-shadow: 0 2px 10px #0006;
}

/* embedded in a host that provides its own chrome → drop our topbar + nav */
.obd2--embedded .topbar {
    display: none;
}

.obd2 .topbar .brand {
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--grey0);
    white-space: nowrap;
}

.obd2 .topbar .brand small {
    color: var(--color-primary-light);
    font-weight: 600;
}

/* app-level nav (Dashboard / Data / Settings) */
.obd2 .app-nav {
    display: flex;
    gap: 0.35rem;
    margin-left: auto;
}

.obd2 .app-nav button {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--grey3);
    font: inherit;
    font-weight: 600;
    font-size: var(--font-sm);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.15s;
}

.obd2 .app-nav .nav-ico {
    width: 18px;
    height: 18px;
    flex: none;
}

/* portrait phone: the labelled bar is too long → icon-only nav so the
   brand + nav always fit */
@media (orientation: portrait) {
    .obd2 .app-nav .nav-lbl {
        display: none;
    }
    .obd2 .app-nav button {
        padding: 0.4rem 0.55rem;
    }
    .obd2 .app-nav .nav-ico {
        width: 20px;
        height: 20px;
    }
}

.obd2 .app-nav button:hover {
    color: var(--color-primary-ultralight);
}

.obd2 .app-nav button.active {
    color: var(--color-primary-light);
    background: #ffffff12;
}

/* ── views ───────────────────────────────────────────────────────────────*/
.obd2 .views {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
}

.obd2 .view {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

.obd2 .view[hidden] {
    display: none;
}

/* ── dashboard stage ───────────────────────────────────────────────────── */
.obd2 .stage {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 0.5rem 0.75rem 0.75rem;
}

/* one-tap reconnect prompt (browsers without silent launch-reconnect) */
.obd2 .reconnect-cta {
    position: absolute;
    left: 50%;
    bottom: 1.1rem;
    transform: translateX(-50%);
    z-index: 5;
    appearance: none;
    border: 1px solid var(--color-primary-light);
    background: var(--color-primary-deep);
    color: var(--color-primary-ultralight);
    font: inherit;
    font-weight: 600;
    font-size: var(--font-sm);
    padding: 0.7rem 1.4rem;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 4px 16px #00000088;
    max-width: calc(100% - 2rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.obd2 .reconnect-cta[hidden] {
    display: none;
}

/* ── scrollable pages (data / settings) ───────────────────────────────────*/
.obd2 .page {
    overflow-y: auto;
    padding: 1rem 1rem 3rem;
}

.obd2 .dim {
    color: var(--grey4);
    font-weight: 400;
}

.obd2 .mono {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.obd2 .dp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.85rem;
}

.obd2 .dp-card {
    background: #0e1621;
    border: 1px solid #ffffff14;
    border-radius: 14px;
    padding: 0.85rem 1rem;
    margin-bottom: 0.85rem;
}

.obd2 .dp-card h3 {
    margin: 0 0 0.6rem;
    font-size: var(--font-md);
    color: var(--color-primary-light);
    font-weight: 700;
}

.obd2 .dp-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.obd2 .dp-card-head h3 {
    margin: 0;
}

.obd2 .dp-note {
    margin: 0.6rem 0 0;
    font-size: var(--font-xs);
}

.obd2 .dp-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 0;
    border-bottom: 1px solid #ffffff0d;
}

.obd2 .dp-row:last-child {
    border-bottom: none;
}

.obd2 .dp-row span {
    color: var(--grey3);
    font-size: var(--font-sm);
}

.obd2 .dp-row b {
    color: var(--grey0);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.obd2 .dp-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
}

.obd2 .dp-table th {
    text-align: left;
    color: var(--grey4);
    font-weight: 600;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid #ffffff1a;
}

.obd2 .dp-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid #ffffff0d;
    color: var(--grey2);
}

.obd2 .dp-table td.mono {
    color: var(--color-primary-ultralight);
}

/* rows the connected ECU reports as unsupported PIDs */
.obd2 .dp-table tr.unsupported {
    opacity: 0.38;
}

.obd2 .dp-table tr.unsupported td.mono {
    color: var(--grey5);
}

.obd2 .dp-dtc-body {
    color: var(--grey2);
    font-size: var(--font-sm);
}

.obd2 .dtc-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid #ffffff0d;
}

.obd2 .dtc-item:last-child {
    border-bottom: none;
}

.obd2 .dtc-item b {
    color: var(--redline);
    font-weight: 700;
}

.obd2 .dtc-item span {
    color: var(--grey2);
    text-align: right;
}

.obd2 .dp-btn {
    appearance: none;
    border: 1px solid var(--color-primary-light);
    background: transparent;
    color: var(--color-primary-light);
    font: inherit;
    font-weight: 600;
    font-size: var(--font-sm);
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.obd2 .dp-btn:hover:not(:disabled) {
    background: var(--color-primary-deep);
    color: var(--color-primary-ultralight);
}

.obd2 .dp-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: var(--grey5);
    color: var(--grey5);
}

.obd2 .dp-reset {
    appearance: none;
    border: 1px solid #ffffff26;
    background: transparent;
    color: var(--grey3);
    font: inherit;
    font-size: var(--font-xs);
    padding: 0.05rem 0.4rem;
    border-radius: 5px;
    margin-left: 0.4rem;
    cursor: pointer;
}

.obd2 .dp-reset:hover {
    border-color: var(--color-primary-light);
    color: var(--color-primary-light);
}

/* compatible-dongles list */
.obd2 .dongle-list {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0;
}

.obd2 .dongle-list li {
    position: relative;
    padding: 0.3rem 0 0.3rem 1.5rem;
    font-size: var(--font-sm);
    color: var(--grey1);
    border-bottom: 1px solid #ffffff0d;
}

.obd2 .dongle-list li:last-child {
    border-bottom: none;
}

.obd2 .dongle-list li::before {
    position: absolute;
    left: 0;
    font-weight: 700;
}

.obd2 .dongle-list li.ok::before {
    content: "✓";
    color: var(--color-success-content);
}

.obd2 .dongle-list li.bad::before {
    content: "✕";
    color: var(--redline);
}

/* ── settings ──────────────────────────────────────────────────────────── */
.obd2 .settings {
    max-width: 560px;
    margin: 0 auto;
}

.obd2 .set-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    align-items: center;
}

.obd2 .set-row label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--grey1);
    font-size: var(--font-sm);
    cursor: pointer;
}

.obd2 .set-row input[type="radio"] {
    accent-color: var(--color-primary-light);
}

.obd2 .set-select {
    width: 100%;
    background: #0a0f16;
    color: var(--grey1);
    border: 1px solid #ffffff26;
    border-radius: 8px;
    padding: 0.5rem 0.6rem;
    font: inherit;
    font-size: var(--font-sm);
}

.obd2 .dp-card p.dim {
    margin: 0.5rem 0 0;
    font-size: var(--font-xs);
}

/* collapsible card body (native details/summary) — e.g. Compatible dongles */
.obd2 .dp-acc summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    user-select: none;
}

.obd2 .dp-acc summary::-webkit-details-marker {
    display: none;
}

.obd2 .dp-acc summary h3 {
    margin: 0;
    flex: 1;
}

.obd2 .dp-acc summary::after {
    content: "";
    flex: none;
    width: 9px;
    height: 9px;
    margin-right: 3px;
    border-right: 2px solid var(--grey3);
    border-bottom: 2px solid var(--grey3);
    transform: translateY(-2px) rotate(45deg);
    transition: transform 0.15s;
}

.obd2 .dp-acc[open] summary::after {
    transform: translateY(2px) rotate(-135deg);
}

/* BLE connection log */
.obd2 #ble-log-wrap {
    margin-top: 0.75rem;
}

.obd2 .ble-log {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.7rem;
    line-height: 1.35;
    color: var(--color-primary-ultralight);
    background: #05080c;
    border: 1px solid #ffffff1a;
    border-radius: 8px;
    margin: 0.4rem 0 0;
    padding: 0.5rem 0.6rem;
    max-height: 240px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.obd2 .ble-quick {
    font-size: var(--font-xs);
    padding: 0.2rem 0.5rem;
}


/* ═══════════════════════════════════════════════════════════════════════
   DIGITAL dashboard — pure-CSS tiles. Markup is rendered by js/dash/digital.js
   into .stage; values pushed from there. Reflows portrait ↔ landscape via a
   container query on .dboard. Safe to tweak freely.
   ═══════════════════════════════════════════════════════════════════════ */
.obd2 .dboard {
    width: 100%;
    height: 100%;
    container-type: size;
    color: var(--grey1);
    font-family: 'Roboto Condensed', system-ui, sans-serif;
}

.obd2 .db-grid {
    width: 100%;
    height: 100%;
    display: grid;
    gap: clamp(5px, 1.3cqmin, 13px);
    /* ── portrait (default) ── */
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: 1.5fr .5fr 1.5fr 1fr 0.75fr 0.75fr 0.5fr;
    grid-template-areas:
        "speed speed"
        "thr   thr"
        "rpm   rpm"
        "volt  gear"
        "cool  cool"
        "trip1 trip2"
        "icons icons";
}

/* when the bike reports outside/ambient temp, it shares the coolant row */
.obd2 .db-grid.has-ambient {
    grid-template-areas:
        "speed speed"
        "thr   thr"
        "rpm   rpm"
        "volt  gear"
        "cool  ambient"
        "trip1 trip2"
        "icons icons";
}

/* ── landscape (wider than tall) ── */
@container (min-aspect-ratio: 1/1) {
    .obd2 .db-grid {
        grid-template-columns: 1fr 1fr 0.75fr 0.75fr 1fr 1fr;
        grid-template-rows: 50% .5fr 1fr;
        grid-template-areas:
            "speed speed  speed  rpm  rpm   rpm"
            "thr   thr    thr    thr  thr icons"
            "gear  volt   cool   cool trip1 trip2";
    }
    .obd2 .db-grid.has-ambient {
        grid-template-areas:
            "speed speed  speed  rpm  rpm   rpm"
            "thr   thr    thr    thr  thr icons"
            "gear  volt   cool   ambient trip1 trip2";
    }
}

.obd2 .t-speed {
    grid-area: speed;
}

.obd2 .t-rpm {
    grid-area: rpm;
}

.obd2 .t-gear {
    grid-area: gear;
}

.obd2 .t-thr {
    grid-area: thr;
}

.obd2 .t-cool {
    grid-area: cool;
}

.obd2 .t-ambient {
    grid-area: ambient;
}

/* hidden unless the bike reports ambient temp (digital.js adds .has-ambient) */
.obd2 .db-grid .t-ambient {
    display: none;
}

.obd2 .db-grid.has-ambient .t-ambient {
    display: flex;
}

.obd2 .t-volt {
    grid-area: volt;
}

.obd2 .t-trip1 {
    grid-area: trip1;
}

.obd2 .t-trip2 {
    grid-area: trip2;
}

.obd2 .t-icons {
    grid-area: icons;
}

/* tile shell — rounded panel with gradient */
.obd2 .tile {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: clamp(6px, 1.6cqmin, 16px);
    border: 1px solid #ffffff14;
    border-radius: clamp(11px, 2.1cqmin, 20px);
    background: linear-gradient(158deg, #18293e 0%, #0d1420 62%, #0a0f18 100%);
    box-shadow: inset 0 1px 0 #ffffff10, 0 2px 8px #00000040;
}

/* tile-level warning emphasis — glanceable at speed. amber = advisory
   (fuel reserve), red pulse = critical (coolant hot / low voltage) */
.obd2 .tile.warn {
    border-color: var(--color-secondary-light);
    box-shadow: inset 0 1px 0 #ffffff10, 0 0 0 1px var(--color-secondary-light), 0 0 12px #f59e0b44;
}

.obd2 .tile.crit {
    border-color: var(--redline);
    box-shadow: inset 0 1px 0 #ffffff10, 0 0 0 1px var(--redline), 0 0 14px #c81e1e55;
    animation: obd2-crit 1s ease-in-out infinite;
}

@keyframes obd2-crit {
    50% {
        box-shadow: inset 0 1px 0 #ffffff10, 0 0 0 1px var(--redline), 0 0 24px #c81e1e99;
    }
}

.obd2 .tile .lbl {
    position: absolute;
    top: clamp(5px, 1.5cqmin, 13px);
    left: clamp(8px, 1.8cqmin, 15px);
    color: var(--grey4);
    font-weight: 700;
    letter-spacing: .11em;
    text-transform: uppercase;
    font-size: clamp(10px, 2.3cqmin, 14px);
    white-space: nowrap;
}

/* unit tucked in the tile's bottom-right corner */
.obd2 .tile .unit {
    position: absolute;
    right: clamp(8px, 1.8cqmin, 15px);
    bottom: clamp(5px, 1.5cqmin, 12px);
    color: var(--grey5);
    font-weight: 700;
    font-size: clamp(10px, 2.6cqmin, 16px);
}

.obd2 .tile .row {
    display: flex;
    align-items: baseline;
    gap: .28em;
}

.obd2 .tile .val {
    color: var(--grey0);
    font-weight: 800;
    line-height: .95;
    font-variant-numeric: tabular-nums;
    font-size: clamp(22px, 8cqmin, 80px);
}

/* hero tiles */
.obd2 .t-speed .val {
    font-size: clamp(46px, 25cqmin, 220px);
    color: var(--color-primary-light);
}

.obd2 .t-rpm .val {
    font-size: clamp(34px, 23cqmin, 150px);
    color: var(--grey0);
}

.obd2 .t-gear .val {
    font-size: clamp(40px, 18cqmin, 180px);
    color: var(--color-primary-light);
}

/* neutral gear = green (universal convention) */
.obd2 .t-gear .val.neutral {
    color: var(--color-success-content);
}

/* throttle */
.obd2 .t-thr {
    justify-content: center;
}

.obd2 .t-thr .bar {
    width: 100%;
    height: clamp(10px, 3.4cqmin, 26px);
    margin-top: clamp(10px, 2.6cqmin, 20px);
    background: #0a0f18;
    border-radius: 99px;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px #ffffff12;
}

.obd2 .t-thr .bar-fill {
    height: 100%;
    width: 0%;
    border-radius: 99px;
    transition: width .12s linear;
    background: linear-gradient(90deg, var(--color-primary-dark), var(--color-primary-light));
}

.obd2 .t-thr .thrval {
    position: absolute;
    top: clamp(5px, 1.5cqmin, 13px);
    right: clamp(8px, 1.8cqmin, 15px);
    color: var(--grey2);
    font-weight: 800;
    font-size: clamp(11px, 2.6cqmin, 17px);
}

/* accent: Trip 1 (tank) in amber */
.obd2 .t-trip1 .val, .obd2 .t-trip2 .val {
    color: var(--color-primary-ultralight);
}

.obd2 .t-trip1 .lbl, .obd2 .t-trip2 .lbl {
    white-space: nowrap;
}

/* status icons — engine fault / fuel reserve (dim off; glow when active) */
.obd2 .t-icons {
    flex-direction: row;
    gap: clamp(10px, 3cqmin, 26px);
}

.obd2 .ico {
    width: clamp(30px, 11cqmin, 74px);
    color: #243348;
    transition: color .15s, filter .15s;
    display: flex;
}

.obd2 .ico svg {
    width: 100%;
    height: auto;
}

.obd2 #d-ico-ce.on {
    color: var(--redline);
    filter: drop-shadow(0 0 6px #c81e1e88);
}

.obd2 #d-ico-fuel.on {
    color: var(--color-secondary-light);
    filter: drop-shadow(0 0 6px #f59e0b88);
}

