/* =========================================================
   DRIVER AWAKE VISION - Dashboard v3
   Warna hanya dipakai untuk arti: hijau = sadar/aktif,
   kuning = waspada, merah = ngantuk. Sisanya netral.
========================================================= */

/* ---------- Token ---------- */

body {
    --font-ui: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-num: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;

    --r-lg: 14px;
    --r-md: 10px;
    --r-sm: 8px;

    --bg: #0d1218;
    --surface: #151c24;
    --surface-2: #1b242e;
    --line: #2a3541;
    --line-soft: #212b35;
    --ink: #e7ecf0;
    --ink-2: #9facb8;
    --ink-3: #7a8793;

    --ok: #35d6a0;
    --ok-bg: rgba(53, 214, 160, .13);
    --warn: #f2b93b;
    --warn-bg: rgba(242, 185, 59, .15);
    --bad: #ff6372;
    --bad-bg: rgba(255, 99, 114, .15);

    --btn-bg: #e7ecf0;
    --btn-fg: #0d1218;
    --focus: #7fb6ff;

    --chart-line: #e7ecf0;
    --chart-fill: rgba(231, 236, 240, .07);
    --chart-grid: rgba(231, 236, 240, .07);
    --chart-text: #8b98a5;
    --chart-limit: #f2b93b;

    color-scheme: dark;
}

body.light {
    --bg: #e8ebed;
    --surface: #ffffff;
    --surface-2: #f2f4f5;
    --line: #d1d7db;
    --line-soft: #e3e7ea;
    --ink: #101820;
    --ink-2: #47545f;
    --ink-3: #6b7783;

    --ok: #0b7f5f;
    --ok-bg: #e0f3ec;
    --warn: #8f6200;
    --warn-bg: #fbf0d3;
    --bad: #c42b3a;
    --bad-bg: #fbe5e8;

    --btn-bg: #101820;
    --btn-fg: #ffffff;
    --focus: #1f5fd1;

    --chart-line: #101820;
    --chart-fill: rgba(16, 24, 32, .06);
    --chart-grid: rgba(16, 24, 32, .08);
    --chart-text: #5f6c78;
    --chart-limit: #8f6200;

    color-scheme: light;
}

/* ---------- Dasar ---------- */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd, ol {
    margin: 0;
    padding: 0;
}

ol {
    list-style: none;
}

button {
    font-family: inherit;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

small {
    font-size: .85em;
}

/* ---------- Tombol ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 18px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--ink);
    font: 600 14px/1 var(--font-ui);
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}

.btn-sm {
    min-height: 36px;
    padding: 0 14px;
}

.btn-solid {
    background: var(--btn-bg);
    color: var(--btn-fg);
}

.btn-solid:hover {
    opacity: .88;
}

.btn-line {
    border-color: var(--line);
}

.btn-line:hover {
    background: var(--surface-2);
}

.btn-danger {
    border-color: var(--bad);
    color: var(--bad);
}

.btn-danger:hover {
    background: var(--bad-bg);
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--ink);
    cursor: pointer;
    transition: background-color .15s;
}

.icon-btn:hover {
    background: var(--surface-2);
}

/* ikon matahari dan bulan di tombol tema */
.i-sun { display: none; }
body:not(.light) .i-sun { display: block; }
body.light .i-moon { display: block; }
body:not(.light) .i-moon { display: none; }

/* ---------- Header ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px max(24px, calc((100vw - 1360px) / 2 + 24px));
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: inherit;
    text-decoration: none;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #101820;
    color: #38dda6;
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.brand-text strong {
    font: 600 19px/1.1 var(--font-num);
    letter-spacing: .01em;
}

.brand-text small {
    color: var(--ink-2);
    font-size: 12.5px;
    margin-top: 2px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.link-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.link-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-3);
}

.link-chip[data-state="ok"] { border-color: var(--ok); }
.link-chip[data-state="ok"] .dot { background: var(--ok); }
.link-chip[data-state="check"] .dot { background: var(--warn); }
.link-chip[data-state="stale"] { border-color: var(--bad); color: var(--bad); }
.link-chip[data-state="stale"] .dot { background: var(--bad); }

.clock {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
    white-space: nowrap;
}

.clock span {
    color: var(--ink-2);
    font-size: 12px;
}

.clock strong {
    font: 600 18px/1.1 var(--font-num);
    font-variant-numeric: tabular-nums;
}

.user-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 14px;
    border-left: 1px solid var(--line);
}

.avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--btn-bg);
    color: var(--btn-fg);
    font: 600 16px/1 var(--font-num);
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.user-info strong {
    font-size: 14px;
    font-weight: 600;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-info small {
    color: var(--ink-2);
    font-size: 12px;
}

/* ---------- Halaman ---------- */

.page {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 1360px;
    margin: 0 auto;
    padding: 20px 24px 40px;
}

.page-foot {
    margin-top: 8px;
    color: var(--ink-3);
    font-size: 13px;
    text-align: center;
}

/* ---------- Panel ---------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line-soft);
}

.panel-head h2 {
    font: 600 19px/1.2 var(--font-num);
    letter-spacing: .01em;
}

.panel-head p {
    margin-top: 2px;
    color: var(--ink-2);
    font-size: 13px;
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
}

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

.pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
}

.pill.active {
    background: var(--ok-bg);
    color: var(--ok);
}

/* =========================================================
   STATUS PENGEMUDI (unsur utama halaman)
========================================================= */

.cluster {
    --cl-bg: #101820;
    --cl-fg: #f2f5f7;
    --cl-dim: #9dabb7;
    --cl-line: rgba(255, 255, 255, .14);
    --cl-state: #9dabb7;
    --level: 0%;

    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    background: var(--cl-bg);
    color: var(--cl-fg);
    border-radius: var(--r-lg);
    overflow: hidden;
    transition: background-color .4s;
}

.cluster[data-state="normal"] {
    --cl-state: #38dda6;
}

.cluster[data-state="waspada"] {
    --cl-bg: #e9a800;
    --cl-fg: #17130a;
    --cl-dim: rgba(23, 19, 10, .72);
    --cl-line: rgba(23, 19, 10, .22);
    --cl-state: #17130a;
}

.cluster[data-state="ngantuk"] {
    --cl-bg: #c8202f;
    --cl-fg: #ffffff;
    --cl-dim: rgba(255, 255, 255, .85);
    --cl-line: rgba(255, 255, 255, .3);
    --cl-state: #ffffff;
    animation: alarm 1.2s ease-in-out infinite;
}

@keyframes alarm {
    50% { background-color: #a3151f; }
}

.cluster-main {
    padding: 28px 32px 30px;
    min-width: 0;
}

.cluster-label {
    color: var(--cl-dim);
    font-size: 14px;
    font-weight: 500;
}

.cluster-state {
    margin-top: 6px;
    color: var(--cl-state);
    font: 700 clamp(60px, 9.5vw, 116px)/.92 var(--font-num);
    letter-spacing: .01em;
    overflow-wrap: anywhere;
}

.cluster-note {
    margin-top: 12px;
    color: var(--cl-dim);
    font-size: 16px;
}

.cluster-readouts {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr;
}

.readout {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    padding: 24px 22px;
    border-left: 1px solid var(--cl-line);
}

.readout dt {
    color: var(--cl-dim);
    font-size: 14px;
    font-weight: 500;
}

.readout dt small {
    font-weight: 400;
}

.readout dd {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
}

.readout .num {
    font: 600 clamp(34px, 3.6vw, 48px)/1 var(--font-num);
    font-variant-numeric: tabular-nums;
}

.readout .num small {
    margin-left: 3px;
    color: var(--cl-dim);
    font-size: .5em;
    font-weight: 500;
}

.cluster .pill {
    background: rgba(255, 255, 255, .14);
    color: var(--cl-fg);
}

.cluster .pill[data-level="normal"] { color: #38dda6; }
.cluster[data-state="waspada"] .pill,
.cluster[data-state="ngantuk"] .pill { color: var(--cl-fg); background: rgba(255, 255, 255, .22); }
.cluster[data-state="waspada"] .pill { background: rgba(23, 19, 10, .12); }

.level-bar {
    height: 6px;
    margin-top: 6px;
    border-radius: 3px;
    background: var(--cl-line);
    overflow: hidden;
}

.level-bar i {
    display: block;
    width: var(--level);
    height: 100%;
    border-radius: 3px;
    background: var(--cl-state);
    transition: width .4s;
}

/* =========================================================
   DATA SENSOR
========================================================= */

.telemetry {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
}

.tile h3 {
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 500;
}

.tile-value {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 8px;
    font: 600 36px/1.05 var(--font-num);
    font-variant-numeric: tabular-nums;
}

.tile-value small {
    color: var(--ink-2);
    font: 500 15px/1 var(--font-ui);
}

.tile-value .pill {
    align-self: center;
    font-family: var(--font-ui);
}

#gpsBadge {
    width: 12px;
    height: 12px;
    padding: 0;
    border-radius: 50%;
    background: var(--ink-3);
    font-size: 0;
}

#gpsBadge.active {
    background: var(--ok);
}

.tile p {
    color: var(--ink-3);
    font-size: 13px;
}

.bpm-bar {
    position: relative;
    height: 6px;
    margin-top: 2px;
    border-radius: 3px;
    background: var(--surface-2);
}

.bpm-bar #heartProgress {
    height: 100%;
    width: 0;
    border-radius: 3px;
    background: var(--ink);
    transition: width .4s;
}

/* penanda batas 62 BPM: (62-40)/100 = 22% */
.bpm-bar::after {
    content: "";
    position: absolute;
    left: 22%;
    top: -3px;
    bottom: -3px;
    width: 2px;
    border-radius: 1px;
    background: var(--warn);
}

/* =========================================================
   KAMERA DAN PETA
========================================================= */

.monitor {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    gap: 16px;
    align-items: stretch;
}

.camera-panel {
    display: flex;
    flex-direction: column;
}

.camera-feed {
    position: relative;
    flex: 1 1 auto;
    min-height: 320px;
    background: #0a0f14;
    overflow: hidden;
}

.camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    color: #8a97a3;
    text-align: center;
}

.camera-placeholder strong {
    color: #d5dce2;
    font-size: 17px;
    font-weight: 600;
}

.camera-placeholder span {
    max-width: 320px;
    font-size: 14px;
}

#cameraImg {
    position: absolute;
    inset: 0;
    display: none;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.camera-feed:fullscreen {
    width: 100vw;
    height: 100vh;
}

.camera-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    padding: 14px 18px;
    border-top: 1px solid var(--line-soft);
}

.camera-state {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.camera-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
}

.camera-status::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--ink-3);
}

.camera-status.on::before {
    background: var(--ok);
}

.camera-mode {
    color: var(--ink-2);
    font-size: 13px;
}

.camera-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.segmented {
    display: inline-flex;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface-2);
}

.seg {
    min-height: 34px;
    padding: 0 16px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink-2);
    font: 600 14px/1 var(--font-ui);
    cursor: pointer;
    transition: background-color .15s, color .15s;
}

.seg.active {
    background: var(--btn-bg);
    color: var(--btn-fg);
}

.system-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--ink);
    font: 600 14px/1 var(--font-ui);
    cursor: pointer;
    transition: background-color .15s, border-color .15s;
}

.system-toggle::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--ink-3);
}

.system-toggle:hover {
    background: var(--surface-2);
}

.system-toggle.active {
    border-color: var(--ok);
    color: var(--ok);
}

.system-toggle.active::before {
    background: var(--ok);
}

.monitor-side {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.map-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
}

#map {
    flex: 1 1 auto;
    min-height: 260px;
    background: var(--surface-2);
    z-index: 0;
}

#map:fullscreen {
    width: 100vw;
    height: 100vh;
}

body:not(.light) .leaflet-tile-pane {
    filter: brightness(.78) contrast(1.05) saturate(.75);
}

.coords {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-top: 1px solid var(--line-soft);
}

.coords > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 18px;
}

.coords > div + div {
    border-left: 1px solid var(--line-soft);
}

.coords span {
    color: var(--ink-2);
    font-size: 13px;
}

.coords strong {
    font: 600 18px/1.2 var(--font-num);
    font-variant-numeric: tabular-nums;
}

.facts > div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--line-soft);
}

.facts > div:last-child {
    border-bottom: 0;
}

.facts dt {
    color: var(--ink-2);
    font-size: 14px;
}

.facts dd {
    font-size: 14px;
    font-weight: 600;
    text-align: right;
    overflow-wrap: anywhere;
}

/* =========================================================
   GRAFIK
========================================================= */

.chart-container {
    position: relative;
    height: 240px;
    padding: 12px 16px 14px;
}

/* =========================================================
   TABEL
========================================================= */

.table-wrap {
    overflow-x: auto;
}

.table-scroll {
    max-height: 340px;
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.data-table th {
    position: sticky;
    top: 0;
    padding: 10px 18px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
}

.data-table td {
    padding: 11px 18px;
    border-bottom: 1px solid var(--line-soft);
    font-variant-numeric: tabular-nums;
    vertical-align: top;
}

.data-table tbody tr:hover {
    background: var(--surface-2);
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

td.history-empty {
    padding: 36px 18px;
    color: var(--ink-3);
    text-align: center;
}

.history-status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--bad-bg);
    color: var(--bad);
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
}

.history-table {
    min-width: 760px;
}

.lokasi-link {
    color: var(--ink);
    text-decoration: underline;
    text-decoration-color: var(--ink-3);
    text-underline-offset: 3px;
    white-space: nowrap;
}

.lokasi-link:hover {
    text-decoration-color: var(--ink);
}

.howto {
    padding: 10px 18px;
    border-bottom: 1px solid var(--line-soft);
    color: var(--ink-2);
    font-size: 13.5px;
}

.howto summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--ink);
}

.howto p {
    margin-top: 8px;
    max-width: 78ch;
}

.stat-groups {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-top: 1px solid var(--line-soft);
}

.stat-groups:empty {
    display: none;
}

.stat-group {
    padding: 16px 18px;
}

.stat-group + .stat-group {
    border-left: 1px solid var(--line-soft);
}

.stat-group h3 {
    font: 600 17px/1.2 var(--font-num);
}

.stat-group h3 small {
    margin-left: 8px;
    color: var(--ink-2);
    font: 400 13px var(--font-ui);
}

.stats {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.stats dt {
    color: var(--ink-2);
    font-size: 12.5px;
}

.stats dd {
    font: 600 20px/1.2 var(--font-num);
    font-variant-numeric: tabular-nums;
}

.stats dd small {
    margin-left: 2px;
    color: var(--ink-2);
    font: 500 12px var(--font-ui);
}

/* =========================================================
   KALIBRASI DAN INFO
========================================================= */

.bottom {
    display: grid;
    grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
    gap: 16px;
    align-items: start;
}

.steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.step {
    display: flex;
    gap: 12px;
    padding: 18px;
}

.step + .step {
    border-left: 1px solid var(--line-soft);
}

.step-no {
    display: grid;
    place-items: center;
    flex: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--btn-bg);
    color: var(--btn-fg);
    font: 600 15px/1 var(--font-num);
}

.step-body h3 {
    font-size: 15px;
    font-weight: 600;
}

.step-body p {
    margin: 2px 0 12px;
    color: var(--ink-2);
    font-size: 13.5px;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.calibration-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-top: 1px solid var(--line-soft);
}

.calibration-message {
    flex: 1 1 260px;
    color: var(--ink-2);
    font-size: 14px;
}

.info-body {
    display: flex;
    flex-direction: column;
}

.info-item {
    padding: 16px 18px;
}

.info-item + .info-item {
    border-top: 1px solid var(--line-soft);
}

.info-item h3 {
    font-size: 15px;
    font-weight: 600;
}

.info-item p {
    margin-top: 4px;
    max-width: 62ch;
    color: var(--ink-2);
    font-size: 14px;
}

.info-item strong {
    color: var(--ink);
}

/* =========================================================
   NOTIFIKASI
========================================================= */

.notification-container {
    position: fixed;
    top: 76px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}

.notification-toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 14px 14px 16px;
    border: 1px solid var(--bad);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .28);
    pointer-events: auto;
    animation: toast-in .25s ease-out;
}

.notification-toast.info {
    border-color: var(--line);
}

@keyframes toast-in {
    from { transform: translateY(-8px); opacity: 0; }
}

.notification-icon {
    display: grid;
    place-items: center;
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bad);
    color: #fff;
}

.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-title {
    font: 600 17px/1.2 var(--font-num);
}

.notification-message {
    margin-top: 2px;
    color: var(--ink-2);
    font-size: 14px;
}

.notification-time {
    margin-top: 2px;
    color: var(--ink-3);
    font-size: 12.5px;
}

.notification-close {
    flex: none;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink-2);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.notification-close:hover {
    background: var(--surface-2);
}

/* =========================================================
   LOGIN
========================================================= */

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
}

.login-container {
    width: min(420px, 100%);
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.login-logo .brand-text strong {
    font-size: 22px;
}

.login-card {
    padding: 28px 26px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
}

.login-header h1 {
    font: 600 26px/1.15 var(--font-num);
}

.login-header p {
    margin-top: 6px;
    color: var(--ink-2);
    font-size: 14.5px;
}

.form-group {
    margin-top: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"] {
    width: 100%;
    min-height: 46px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--surface-2);
    color: var(--ink);
    font: 400 16px var(--font-ui);
}

.form-group input:focus {
    outline: 2px solid var(--focus);
    outline-offset: 0;
    border-color: transparent;
}

.password-wrapper {
    position: relative;
}

.password-wrapper input {
    padding-right: 76px;
}

.password-toggle {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    min-height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--ink-2);
    font: 600 13px var(--font-ui);
    cursor: pointer;
}

.password-toggle:hover {
    background: var(--surface);
}

.login-options {
    margin-top: 14px;
}

.remember {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--ink-2);
    font-size: 14px;
    cursor: pointer;
}

.login-message {
    min-height: 20px;
    margin-top: 12px;
    font-size: 14px;
}

.login-message.error { color: var(--bad); }
.login-message.success { color: var(--ok); }

.login-button {
    width: 100%;
    min-height: 48px;
    margin-top: 8px;
    border: 0;
    border-radius: var(--r-sm);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font: 600 16px var(--font-ui);
    cursor: pointer;
}

.login-button:hover { opacity: .88; }
.login-button:disabled { opacity: .55; cursor: wait; }

.login-footer {
    margin-top: 16px;
    color: var(--ink-3);
    font-size: 13px;
    text-align: center;
}

/* =========================================================
   LAYAR SEDANG
========================================================= */

@media (max-width: 1099px) {
    .camera-feed {
        flex: none;
        min-height: 0;
        aspect-ratio: 16 / 10;
    }

    .monitor,
    .bottom {
        grid-template-columns: minmax(0, 1fr);
    }

    .telemetry {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tile-bpm {
        grid-column: 1 / -1;
    }

    .cluster {
        grid-template-columns: minmax(0, 1fr);
    }

    .readout:first-child {
        border-left: 0;
    }

    .cluster-readouts {
        border-top: 1px solid var(--cl-line);
    }

    .readout {
        padding: 18px 22px;
    }

    #map {
        min-height: 320px;
    }

    .clock span {
        display: none;
    }
}

/* =========================================================
   HP
========================================================= */

@media (max-width: 720px) {
    body {
        font-size: 15px;
    }

    .topbar {
        flex-wrap: wrap;
        padding: 10px 16px 12px;
        gap: 10px;
    }

    .topbar-right {
        display: contents;
    }

    .brand {
        order: 1;
        flex: 1 1 0;
    }

    .brand-text strong {
        font-size: 18px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .brand-text small,
    .user-box,
    .clock {
        display: none;
    }

    #themeToggle {
        order: 2;
    }

    #logoutBtn {
        order: 3;
    }

    .link-chip {
        order: 4;
        flex: 1 0 100%;
        justify-content: center;
        padding: 6px 10px;
        font-size: 13px;
    }

    .btn,
    .btn-sm,
    .seg,
    .system-toggle {
        min-height: 44px;
    }

    .icon-btn {
        width: 44px;
        height: 44px;
    }

    .page {
        padding: 14px 16px 32px;
        gap: 14px;
    }

    .cluster-main {
        padding: 22px 20px 22px;
    }

    .cluster-state {
        font-size: clamp(56px, 20vw, 88px);
    }

    .cluster-note {
        font-size: 15px;
    }

    .cluster-readouts {
        grid-template-columns: 1fr 1fr;
    }

    .readout-level {
        grid-column: 1 / -1;
        border-left: 0;
    }

    .readout {
        padding: 14px 20px;
    }

    .readout:nth-child(2) {
        border-left: 0;
        border-top: 1px solid var(--cl-line);
    }

    .readout:nth-child(3) {
        border-top: 1px solid var(--cl-line);
    }

    .tile {
        padding: 14px 16px;
    }

    .tile-value {
        font-size: 30px;
    }

    .panel-head {
        flex-wrap: wrap;
        padding: 14px 16px;
    }

    .camera-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .camera-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .segmented {
        width: 100%;
    }

    .seg {
        flex: 1;
    }

    .system-toggle {
        justify-content: center;
    }

    .chart-container {
        height: 210px;
        padding: 10px 8px 12px;
    }

    .steps {
        grid-template-columns: minmax(0, 1fr);
    }

    .step + .step {
        border-left: 0;
        border-top: 1px solid var(--line-soft);
    }

    .stat-groups {
        grid-template-columns: minmax(0, 1fr);
    }

    .stat-group + .stat-group {
        border-left: 0;
        border-top: 1px solid var(--line-soft);
    }

    .stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .notification-container {
        top: auto;
        bottom: 16px;
        right: 16px;
        left: 16px;
        width: auto;
    }

    /* Tabel berubah jadi kartu di HP */
    .history-table {
        min-width: 0;
    }

    .data-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .data-table,
    .data-table tbody {
        display: block;
        width: 100%;
    }

    .data-table tr {
        display: grid;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 12px 10px;
        padding: 14px 16px;
        border-bottom: 1px solid var(--line);
    }

    .data-table tbody tr:last-child {
        border-bottom: 0;
    }

    .data-table td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        min-width: 0;
        padding: 0;
        border-bottom: 0;
        font-size: 15px;
        text-align: left;
        overflow-wrap: anywhere;
    }

    .data-table td::before {
        color: var(--ink-2);
        font-size: 12.5px;
        font-weight: 500;
    }

    .history-table td:nth-child(1) { grid-column: span 2; }
    .history-table td:nth-child(2) { grid-column: span 4; }
    .history-table td:nth-child(3),
    .history-table td:nth-child(4) { grid-column: span 3; }
    .history-table td:nth-child(5),
    .history-table td:nth-child(6),
    .history-table td:nth-child(7) { grid-column: span 2; }
    .history-table td:nth-child(8) { grid-column: 1 / -1; }

    .test-table td:nth-child(1) { grid-column: 1 / -1; }
    .test-table td:nth-child(2) { grid-column: span 2; }
    .test-table td:nth-child(3) { grid-column: span 2; }
    .test-table td:nth-child(4) { grid-column: span 2; }
    .test-table td:nth-child(5),
    .test-table td:nth-child(6) { grid-column: span 3; }

    .data-table td.history-empty:nth-child(1) {
        display: block;
        grid-column: 1 / -1;
        padding: 20px 0;
        text-align: center;
    }

    .data-table td.history-empty::before {
        content: none;
    }

    .history-table td:nth-child(1)::before { content: "No"; }
    .history-table td:nth-child(2)::before { content: "Waktu"; }
    .history-table td:nth-child(3)::before { content: "Status"; }
    .history-table td:nth-child(4)::before { content: "Denyut jantung"; }
    .history-table td:nth-child(5)::before { content: "EAR"; }
    .history-table td:nth-child(6)::before { content: "MAR"; }
    .history-table td:nth-child(7)::before { content: "Kecepatan"; }
    .history-table td:nth-child(8)::before { content: "Lokasi"; }

    .test-table td:nth-child(1)::before { content: "Uji ke-"; }
    .test-table td:nth-child(2)::before { content: "Deteksi (T1)"; }
    .test-table td:nth-child(3)::before { content: "Peringatan alat"; }
    .test-table td:nth-child(4)::before { content: "Notifikasi web"; }
    .test-table td:nth-child(5)::before { content: "Respons alat"; }
    .test-table td:nth-child(6)::before { content: "Respons web"; }

    .table-scroll {
        max-height: 420px;
    }
}

/* =========================================================
   GERAK DIKURANGI
========================================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}


/* =========================================================
   KALIBRASI TERSAMBUNG KE RASPBERRY PI (v4)
========================================================= */

.step-body .step-info {
    margin: 0 0 12px;
    min-height: 19px;
    color: var(--ink-2);
    font: 500 13px/1.4 var(--font-num);
    font-variant-numeric: tabular-nums;
}

.step-body .step-info.is-active { color: var(--warn); }

.step-body .step-info.is-done { color: var(--ok); }

.step-meter {
    height: 4px;
    margin: 0 0 8px;
    border-radius: 2px;
    background: var(--line-soft);
    overflow: hidden;
}

.step-meter > span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--ink-2);
    transition: width .35s ease;
}

.step-meter.is-active > span { background: var(--warn); }

.step-meter.is-done > span { background: var(--ok); }

.calibration-values {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 6px 22px;
    padding: 12px 18px;
    border-top: 1px solid var(--line-soft);
    color: var(--ink-2);
    font-size: 13.5px;
}

.calibration-values b {
    margin-left: 4px;
    color: var(--ink);
    font: 600 16px/1 var(--font-num);
    font-variant-numeric: tabular-nums;
}

.calibration-tag:not(:empty) {
    padding: 2px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
}

.calibration-message.is-error { color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
    .step-meter > span { transition: none; }
}
