/* BabyMoover settings page - phone first, light and dark. */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --border: #dfe2e7;
    --text: #15181d;
    --text-dim: #646b76;
    --accent: #2f7d5b;
    --accent-text: #ffffff;
    --warn-bg: #fff4dc;
    --warn-text: #7a5200;
    --bad-bg: #fde6e6;
    --bad-text: #9b1c1c;
    --ok: #2f7d5b;
    --bad: #c03030;

    --c-vel: #2f6fd6;
    --c-target: #2f6fd6;
    --c-vq: #d0782a;
    --chart-grid: #e3e6ea;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --surface: #171b21;
        --surface-2: #1f242c;
        --border: #2a303a;
        --text: #eef1f5;
        --text-dim: #8b939f;
        --accent: #3fae7d;
        --accent-text: #08130e;
        --warn-bg: #3a2e12;
        --warn-text: #f3cf7a;
        --bad-bg: #3a1717;
        --bad-text: #f3a0a0;
        --ok: #3fae7d;
        --bad: #ef6b6b;

        --c-vel: #6ea6ff;
        --c-target: #6ea6ff;
        --c-vq: #f0a050;
        --chart-grid: #262c35;

        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.app {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stack[aria-disabled="true"] {
    opacity: .45;
    pointer-events: none;
}

/* --- header ---------------------------------------------------------- */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -.01em;
}

.subtitle {
    color: var(--text-dim);
    font-size: 13px;
}

.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-dim);
    display: inline-block;
}

.dot[data-state="connected"] { background: var(--ok); }
.dot[data-state="connecting"] { background: var(--c-vq); }

/* --- buttons --------------------------------------------------------- */

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    border-radius: 12px;
    padding: 11px 16px;
    min-height: 44px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-primary,
.btn-run {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.btn-run {
    min-width: 120px;
    font-size: 17px;
}

.btn-run.running {
    background: var(--bad);
    border-color: var(--bad);
    color: #fff;
}

.btn-small {
    min-height: 34px;
    padding: 6px 12px;
    font-size: 13px;
}

.btn[data-armed] {
    background: var(--bad);
    border-color: var(--bad);
    color: #fff;
}

/* --- cards ----------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px;
}

.notice {
    margin: 0 0 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--warn-bg);
    color: var(--warn-text);
}

.notice.error {
    background: var(--bad-bg);
    color: var(--bad-text);
}

.hint {
    margin: 8px 0 0;
    color: var(--text-dim);
    font-size: 13px;
}

/* --- status ---------------------------------------------------------- */

.status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.state-badge {
    font-size: 20px;
    font-weight: 700;
}

.state-badge[data-state="3"] { color: var(--c-vel); }
.state-badge[data-state="4"],
.state-badge[data-state="5"] { color: var(--bad); }
.state-badge[data-state="1"] { color: var(--text-dim); }

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 14px 0 12px;
}

.stat {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 8px 10px;
    min-width: 0;
}

.stat-label {
    display: block;
    color: var(--text-dim);
    font-size: 12px;
}

.stat-value {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

@media (max-width: 420px) {
    .stats { grid-template-columns: repeat(2, 1fr); }
}

.chart-head,
.chart-foot {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    color: var(--text-dim);
    font-size: 12px;
}

.chart-foot {
    justify-content: space-between;
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

.legend {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sw {
    width: 14px;
    height: 0;
    border-top: 2px solid;
    display: inline-block;
}

.sw-vel { border-color: var(--c-vel); }
.sw-target { border-color: var(--c-target); border-top-style: dashed; }
.sw-vq { border-color: var(--c-vq); }

.chart {
    width: 100%;
    height: 180px;
    display: block;
    margin-top: 6px;
}

/* --- banners --------------------------------------------------------- */

.banners {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.banners:empty { display: none; }

.banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    font-size: 14px;
}

.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.bad { background: var(--bad-bg); color: var(--bad-text); }

/* --- settings -------------------------------------------------------- */

#settings {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.group-title {
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.group-title::-webkit-details-marker { display: none; }
.group-title::after { content: "▾"; color: var(--text-dim); transition: transform .15s; }
details:not([open]) .group-title::after { transform: rotate(-90deg); }

.setting {
    display: block;
    padding: 14px 0 4px;
    border-top: 1px solid var(--border);
    margin-top: 12px;
}

.group > .setting:first-of-type,
.group > .hint + .setting { margin-top: 10px; }

.setting-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.setting-label { font-weight: 600; }

.tag {
    color: var(--text-dim);
    font-weight: 400;
    font-size: 13px;
}

.setting-value {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
}

.num {
    width: 92px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.unit {
    color: var(--text-dim);
    font-size: 13px;
    min-width: 42px;
}

.setting-help {
    color: var(--text-dim);
    font-size: 13px;
    margin-top: 4px;
}

.range {
    width: 100%;
    margin: 12px 0 2px;
    accent-color: var(--accent);
    height: 28px;
}

/* toggle */
.toggle { cursor: pointer; }

.switch {
    position: relative;
    width: 50px;
    height: 30px;
    flex: none;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 30px;
    transition: background .15s;
}

.slider::before {
    content: "";
    position: absolute;
    width: 24px;
    height: 24px;
    left: 2px;
    top: 2px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
    transition: transform .15s;
}

.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* segmented */
.segmented {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.seg {
    flex: 1;
    min-height: 40px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    border-radius: 10px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.seg.on {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

/* peak summary */
.peak {
    margin-top: 14px;
    padding: 12px;
    border-radius: 12px;
    background: var(--surface-2);
    font-size: 14px;
}

.peak-title {
    font-weight: 700;
    margin-bottom: 4px;
}

.peak-row.short span { color: var(--warn-text); }

.peak b { font-variant-numeric: tabular-nums; }

/* calibration */
.calibration {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cal-info {
    font-size: 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ok { color: var(--ok); }
.bad { color: var(--bad); }

/* actions */
.actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* --- presets --------------------------------------------------------- */

.card-title {
    margin: 0 0 10px;
    font-size: 17px;
    font-weight: 700;
}

.text {
    width: 100%;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
}

.preset-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset.active {
    border-color: var(--accent);
    box-shadow: inset 3px 0 0 var(--accent);
}

.preset-main {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}

.preset-name {
    appearance: none;
    border: 0;
    background: none;
    padding: 0;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    font-size: 16px;
    cursor: text;
    text-align: left;
}

.preset-rename {
    min-height: 36px;
    flex: 1;
}

.preset-badge {
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border-radius: 999px;
    padding: 1px 8px;
}

.preset-summary {
    flex-basis: 100%;
    color: var(--text-dim);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.preset-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
}

.preset-actions .btn {
    padding: 6px 4px;
    font-size: 13px;
}

.preset-new {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-top: 12px;
}

@media (max-width: 400px) {
    .preset-new { grid-template-columns: 1fr; }
}

.heat {
    margin-top: 6px;
    color: var(--text-dim);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
