:root {
    --bg: #0f1115;
    --card: #171a21;
    --card-border: #262b36;
    --text: #e8eaf0;
    --text-dim: #8b93a7;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #eab308;
    --blue: #3b82f6;
    --purple: #a855f7;
    --radius: 14px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

.app {
    max-width: 720px;
    margin: 0 auto;
    padding: 12px 12px 90px;
}

/* ---------- HEADER ---------- */
header.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 4px 16px;
}

header.topbar h1 {
    font-size: 18px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    font-size: 12px;
    padding: 3px 9px;
    border-radius: 999px;
    font-weight: 600;
}
.badge.on { background: rgba(34,197,94,.15); color: var(--green); }
.badge.off { background: rgba(239,68,68,.15); color: var(--red); }

button.icon-btn {
    background: var(--card);
    border: 1px solid var(--card-border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
}

/* ---------- TABS ---------- */
nav.tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card);
    border-top: 1px solid var(--card-border);
    display: flex;
    max-width: 720px;
    margin: 0 auto;
    z-index: 50;
}
nav.tabs button {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 12px 4px 10px;
    font-size: 11px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
}
nav.tabs button .ico { font-size: 19px; }
nav.tabs button.active { color: var(--blue); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- CARD ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}
.card h2 {
    font-size: 14px;
    margin: 0 0 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .03em;
}

/* ---------- SETTINGS GROUPING (tab Pengaturan) ---------- */
.settings-jumpnav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 2px 12px;
    margin-bottom: 4px;
    -webkit-overflow-scrolling: touch;
}
.settings-jumpnav a {
    flex-shrink: 0;
    background: var(--card);
    border: 1px solid var(--card-border);
    color: var(--text-dim);
    text-decoration: none;
    font-size: 12px;
    padding: 7px 14px;
    border-radius: 999px;
    white-space: nowrap;
}
.settings-jumpnav a:active { background: var(--blue); color: #fff; }

.settings-group-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin: 22px 2px 8px;
    padding-top: 10px;
    border-top: 1px solid var(--card-border);
    scroll-margin-top: 12px;
}
.settings-group-title:first-of-type {
    margin-top: 4px;
    padding-top: 0;
    border-top: none;
}

#map {
    width: 100%;
    height: 260px;
    border-radius: var(--radius);
    margin-bottom: 12px;
    background: #1b1e26;
}

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

.stat {
    background: #12151b;
    border-radius: 10px;
    padding: 10px 12px;
}
.stat .label { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.stat .value { font-size: 15px; font-weight: 600; }
.stat .value.green { color: var(--green); }
.stat .value.red { color: var(--red); }
.stat .value.yellow { color: var(--yellow); }

.actions-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}

button.btn {
    border: none;
    border-radius: 10px;
    padding: 12px 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
button.btn.stop { background: var(--red); }
button.btn.resume { background: var(--green); }
button.btn.refresh { background: var(--blue); }
button.btn.neutral { background: #2a2f3a; color: var(--text); }
button.btn.active-stat-btn { background: var(--blue); color: #fff; }
button.btn.full { width: 100%; margin-top: 8px; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

/* toggle switch row */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 2px;
    border-bottom: 1px solid var(--card-border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row .t-label { font-size: 14px; }
.toggle-row .t-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.switch {
    position: relative;
    width: 46px;
    height: 26px;
    flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #34394a;
    border-radius: 999px;
    transition: .2s;
}
.slider:before {
    content: "";
    position: absolute;
    height: 20px; width: 20px;
    left: 3px; bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: .2s;
}
input:checked + .slider { background: var(--green); }
input:checked + .slider:before { transform: translateX(20px); }

/* forms */
label.field-label {
    display: block;
    font-size: 12px;
    color: var(--text-dim);
    margin: 10px 0 5px;
}
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], textarea {
    width: 100%;
    background: #12151b;
    border: 1px solid var(--card-border);
    color: var(--text);
    border-radius: 9px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
}
textarea { resize: vertical; }

.cmd-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--card-border);
}
.cmd-item:last-child { border-bottom: none; }
.cmd-item .cname { font-weight: 600; font-size: 14px; color: var(--blue); }
.cmd-item .creply { font-size: 12px; color: var(--text-dim); margin-top: 2px; white-space: pre-wrap; }
.cmd-item button {
    background: none;
    border: none;
    color: var(--red);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}
.inline-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.inline-form > div { flex: 1; }

.zone-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--card-border);
}
.zone-item:last-child { border-bottom: none; }
.zone-item .zname { font-weight: 600; font-size: 14px; }
.zone-item .zmeta { font-size: 11px; color: var(--text-dim); }
.zone-item button {
    background: none;
    border: none;
    color: var(--red);
    font-size: 18px;
    cursor: pointer;
}

/* history */
.hist-item {
    padding: 9px 0;
    border-bottom: 1px solid var(--card-border);
    font-size: 13px;
}
.hist-item:last-child { border-bottom: none; }
.hist-item .htime { font-size: 11px; color: var(--text-dim); }

/* toast */
#toast {
    position: fixed;
    left: 50%;
    bottom: 76px;
    transform: translateX(-50%);
    background: #23262f;
    border: 1px solid var(--card-border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 13px;
    max-width: 90%;
    text-align: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
#toast.show { opacity: 1; }
#toast.error { border-color: var(--red); }

.save-status {
    font-size: 12px;
    color: var(--green);
    min-height: 16px;
    margin-top: 6px;
    text-align: center;
}
.save-status.error { color: var(--red); }

#tripMap {
    width: 100%;
    height: 280px;
    border-radius: var(--radius);
    background: #1b1e26;
}

.trip-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 4px;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
}
.trip-item:last-child { border-bottom: none; }
.trip-item:active { background: #1c2028; }
.trip-item .t-date { font-weight: 600; font-size: 14px; }
.trip-item .t-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.trip-item .t-dist { font-size: 14px; font-weight: 600; color: var(--blue); }

button.btn:active { transform: scale(.97); }

@media (max-width: 380px) {
    .stat .value { font-size: 14px; }
    #map { height: 220px; }
}

@keyframes spin { to { transform: rotate(360deg); } }

.spin {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ---------- LOGIN PAGE ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 28px 24px;
    width: 100%;
    max-width: 360px;
}
.login-card h1 {
    font-size: 20px;
    text-align: center;
    margin: 0 0 4px;
}
.login-card p.sub {
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    margin: 0 0 22px;
}
.login-card button.btn {
    width: 100%;
    padding: 13px;
    margin-top: 8px;
    background: var(--blue);
}
.login-error {
    color: var(--red);
    font-size: 13px;
    text-align: center;
    margin-top: 10px;
    min-height: 16px;
}
