/* WizNET app 3.1: tabs for Map, Stations and Alerts (plus Admin for staff). */

:root {
    --ink: #111418;
    --ink-2: #3a4048;
    --muted: #5b6470;
    --line: #e3e6ea;
    --line-soft: #eef0f2;
    --ground: #f4f5f7;
    --white: #ffffff;
    --green: #1a9a55;
    --green-text: #12804a;
    --red: #d3202c;
    --red-text: #b81b26;
    --black: #14171a;
    --blue: #2563eb;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --card-h: 110px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

body {
    background: var(--ground);
    color: var(--ink);
    font: 16px/1.4 var(--font);
    -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

.wiznet-app-regular .admin-only,
.wiznet-app-admin .regular-only { display: none !important; }

#app {
    position: fixed;
    inset: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
}

.view {
    grid-row: 1;
    grid-column: 1;
    position: relative;
    min-height: 0;
    overflow: hidden;
}

.page {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--ground);
    padding-bottom: 28px;
}

/* ---------- Tab bar ---------- */

.tabbar {
    grid-row: 2;
    display: flex;
    padding: 4px 6px calc(4px + var(--safe-bottom));
    background: var(--white);
    border-top: 1px solid var(--line);
    z-index: 700;
}

.tab {
    position: relative;
    flex: 1;
    min-height: 54px;
    border: 0;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}

.tab[aria-current="page"] { color: var(--ink); font-weight: 800; }
.tab[aria-current="page"] svg { stroke-width: 2.4; }

.tab-dot {
    position: absolute;
    top: 7px;
    left: calc(50% + 8px);
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--red);
    border: 2px solid var(--white);
}

/* ---------- Map ---------- */

#map {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: #c9e1ea;
}

.leaflet-container { font-family: var(--font); }
.leaflet-top.leaflet-right { top: calc(var(--safe-top) + 62px); }
.leaflet-control-attribution { font-size: 10px; border-radius: 6px 0 0 6px; }

.mk { position: relative; display: block; width: 24px; height: 24px; }
.mk svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.35)); transition: transform 0.15s; }

.mk-label {
    display: none;
    position: absolute;
    top: 25px;
    left: 50%;
    transform: translateX(-50%);
    font: 700 11px/1 var(--font);
    color: #23272d;
    white-space: nowrap;
    text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff, 0 0 4px #fff;
    pointer-events: none;
}

#map.show-labels .mk-label,
.mk.selected .mk-label { display: block; }
.mk.selected svg { transform: scale(1.35); }

.you {
    display: block;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--blue);
    border: 3px solid var(--white);
    box-shadow: 0 0 0 8px rgba(37, 99, 235, 0.18);
}

.topbar {
    position: absolute;
    top: calc(var(--safe-top) + 10px);
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    z-index: 500;
    pointer-events: none;
}

.pill {
    pointer-events: auto;
    height: 44px;
    padding: 0 14px;
    border: 0;
    border-radius: 22px;
    background: var(--white);
    box-shadow: 0 2px 10px rgba(17, 20, 24, 0.16);
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--ink);
}

.brand { gap: 8px; }
.brand img { height: 19px; width: auto; display: block; }

.admin-badge {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    padding: 3px 7px;
    border-radius: 6px;
    background: var(--ink);
    color: var(--white);
}

.counts { font-size: 15px; font-weight: 700; cursor: pointer; }
.counts span { display: flex; align-items: center; gap: 5px; }

.map-notices {
    position: absolute;
    top: calc(var(--safe-top) + 62px);
    left: 12px;
    right: 12px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.map-notices .notice { box-shadow: 0 2px 10px rgba(17, 20, 24, 0.16); }

.fab {
    position: absolute;
    right: 14px;
    bottom: calc(var(--card-h) + 26px);
    z-index: 450;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 0;
    background: var(--white);
    color: var(--ink);
    box-shadow: 0 2px 10px rgba(17, 20, 24, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* The floating card above the tab bar */

.map-card {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 12px;
    z-index: 600;
    max-height: 62%;
    overflow-y: auto;
    padding: 14px 16px;
    border-radius: 20px;
    background: var(--white);
    box-shadow: 0 2px 14px rgba(17, 20, 24, 0.2);
}

.map-card:empty { display: none; }

.map-card.down { background: var(--black); color: var(--white); }
.map-card.down .overline,
.map-card.down .card-detail { color: #c8ced5; }
.map-card.down .status-word { color: var(--white); }

.card-main {
    width: 100%;
    border: 0;
    background: none;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    cursor: pointer;
    color: inherit;
}

.card-main .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.card-name { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.15; }
.status-word { font-size: 17px; font-weight: 700; }
.card-detail { margin: 8px 0 0; font-size: 14.5px; color: var(--ink-2); }
.card-main > svg:last-child { color: var(--muted); flex: none; }

.card-head { display: flex; align-items: center; gap: 12px; }
.card-head .grow { flex: 1; min-width: 0; }

.find { display: flex; flex-direction: column; gap: 10px; }
.find p { margin: 0; color: var(--ink-2); font-size: 15px; }

.relocate { display: flex; flex-direction: column; gap: 10px; font-size: 15px; }
.relocate div { display: flex; gap: 8px; }

.close {
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: var(--ground);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: none;
}

.facts {
    margin: 12px 0 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 9px 16px;
    font-size: 15px;
}

.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Shared bits ---------- */

.overline {
    margin: 0;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.st-green { color: var(--green-text); }
.st-red { color: var(--red-text); }
.st-black { color: var(--black); }

.notice {
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--white);
    font-size: 14px;
}

.stale { background: #fff6e0; color: #5c3d00; }

.announcement { display: flex; align-items: flex-start; gap: 8px; }
.announcement-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.badge {
    align-self: flex-start;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    padding: 2px 7px;
    border-radius: 6px;
    background: #e8eefc;
    color: #1e3a8a;
}

.badge.maintenance { background: #fff1d6; color: #7a4a00; }
.badge.important { background: #fde2e4; color: #9b111e; }

.icon-button {
    width: 44px;
    height: 44px;
    margin: -10px -8px -10px 0;
    border: 0;
    background: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--muted);
}

.btn {
    min-height: 52px;
    padding: 0 18px;
    border-radius: 14px;
    border: 0;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.btn.primary { background: var(--ink); color: var(--white); }
.btn.outline { background: var(--white); color: var(--ink); border: 1.5px solid var(--ink); }
.btn.plain { background: none; color: var(--ink-2); font-weight: 600; min-height: 46px; }
.btn.small { min-height: 42px; font-size: 14.5px; padding: 0 14px; border-radius: 12px; }
.btn.danger { background: var(--red-text); color: var(--white); }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Pages (Stations, Alerts, Admin) ---------- */

.page-head {
    padding: calc(var(--safe-top) + 18px) 20px 6px;
}

.page-head h1 { margin: 0; font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }

.live-line { margin: 2px 0 0; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); flex: none; }

.page-notices { padding: 4px 16px 0; display: flex; flex-direction: column; gap: 8px; }
.page-notices:not(:has(:not([hidden]):not(:empty))) { padding: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px; }
.chips.inset { padding: 4px 16px 14px 52px; }

.chip {
    min-height: 40px;
    padding: 0 14px;
    border-radius: 20px;
    border: 1px solid #cfd4da;
    background: var(--white);
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--white); }

.chip .count {
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--red);
    color: var(--white);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.list { background: var(--white); border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }

.row {
    width: 100%;
    min-height: 58px;
    padding: 6px 20px;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    background: none;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
    cursor: pointer;
}

.row:last-child { border-bottom: 0; }

.row-name { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 700; }
.row-status { font-size: 14px; font-weight: 600; text-align: right; }
.row-km { min-width: 58px; text-align: right; font-size: 14px; color: var(--muted); }

.yours {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.05em;
    padding: 3px 7px;
    border-radius: 6px;
    background: var(--line-soft);
    color: var(--ink-2);
}

.empty { padding: 22px 20px; color: var(--muted); font-size: 15px; background: var(--white); }
.empty .btn { margin-top: 12px; width: 100%; }

.page-body {
    padding: 8px 16px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.page-body > * { flex-shrink: 0; }
.page-body .overline { margin: 10px 4px 0; }

.group { background: var(--white); border-radius: 16px; overflow: hidden; }

.opt {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 62px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--line-soft);
    cursor: pointer;
}

.opt:last-child { border-bottom: 0; }

.opt input[type="radio"] {
    width: 22px;
    height: 22px;
    margin: 0;
    flex: none;
    accent-color: var(--ink);
}

.opt-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.opt-text > span { font-size: 16px; font-weight: 600; }
.opt-text small { font-size: 13.5px; color: var(--muted); }

.switch {
    appearance: none;
    -webkit-appearance: none;
    flex: none;
    width: 51px;
    height: 31px;
    margin: 0;
    border-radius: 16px;
    background: #c3c9d0;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: var(--white);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: left 0.2s;
}

.switch:checked { background: var(--green); }
.switch:checked::after { left: 22px; }
.switch:disabled { opacity: 0.45; cursor: default; }

.status-text { margin: 0 4px; font-size: 14px; color: var(--ink-2); }
.status-text:empty { display: none; }

.card {
    background: var(--white);
    border-radius: 16px;
    padding: 14px 16px;
    font-size: 14.5px;
}

.card p { margin: 6px 0 0; }
.card.note { margin: 0; color: var(--ink-2); }
.card.install { background: #fff6e0; color: #4a3200; }

/* ---------- Modals ---------- */

.modal {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: rgba(17, 20, 24, 0.45);
    display: flex;
    align-items: flex-end;
}

.modal-sheet {
    width: 100%;
    max-height: 92%;
    overflow-y: auto;
    padding: 10px 24px calc(24px + var(--safe-bottom));
    background: var(--white);
    border-radius: 24px 24px 0 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    animation: rise 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-sheet > * { flex-shrink: 0; }

.handle {
    align-self: center;
    width: 38px;
    height: 5px;
    border-radius: 3px;
    background: #cfd4da;
}

.modal-sheet h2 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.modal-sheet p { margin: 0; font-size: 15.5px; line-height: 1.5; color: var(--ink-2); }
.modal-sheet .fine { text-align: center; font-size: 13px; color: var(--muted); }

.primer-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--ink);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ticks { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 15px; color: var(--ink-2); }
.ticks li { padding-left: 28px; position: relative; }
.ticks li::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 4px;
    width: 12px;
    height: 7px;
    border-left: 2.4px solid var(--green-text);
    border-bottom: 2.4px solid var(--green-text);
    transform: rotate(-45deg);
}

@keyframes rise { from { transform: translateY(60px); opacity: 0.4; } }

@media (prefers-reduced-motion: reduce) {
    .modal-sheet { animation: none; }
}

/* ---------- Admin tab ---------- */

.segmented {
    margin: 6px 16px 0;
    padding: 3px;
    border-radius: 12px;
    background: #e4e7eb;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px;
}

.segmented button {
    min-height: 40px;
    border: 0;
    border-radius: 9px;
    background: none;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink-2);
    cursor: pointer;
}

.segmented button[aria-pressed="true"] { background: var(--white); color: var(--ink); box-shadow: 0 1px 3px rgba(17, 20, 24, 0.14); }

.field { display: flex; flex-direction: column; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.field:last-child { border-bottom: 0; }
.field > span { font-size: 14px; font-weight: 700; color: var(--ink-2); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; }
.field > span small { font-weight: 500; color: var(--muted); }

.field input[type="text"],
.field input[type="number"],
.field input[type="email"],
.field input[type="password"],
.field textarea,
.field select {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid #cfd4da;
    border-radius: 12px;
    background: var(--white);
    font-size: 16px;
}

.field textarea { min-height: 110px; resize: vertical; line-height: 1.4; }

.type-chips { display: flex; gap: 8px; flex-wrap: wrap; }

.preview {
    display: flex;
    gap: 10px;
    padding: 11px 13px;
    border-radius: 18px;
    background: #eceef1;
}

.preview img { width: 36px; height: 36px; border-radius: 9px; flex: none; }
.preview .p-body { flex: 1; min-width: 0; }
.preview .p-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.preview .p-title { font-weight: 700; font-size: 14.5px; }
.preview .p-text { font-size: 14px; color: var(--ink-2); overflow-wrap: anywhere; }

.warn-box { background: #fff6e0; color: #4a3200; border-radius: 12px; padding: 10px 12px; font-size: 14px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); font-size: 15px; }
.kv:last-child { border-bottom: 0; }
.kv span:first-child { color: var(--ink-2); }
.kv span:last-child { font-weight: 600; text-align: right; }

.health { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.health strong { font-size: 17px; }
.health small { display: block; color: var(--muted); font-size: 13.5px; }

.port-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.port-dot.ok { background: var(--green); }
.port-dot.bad { background: var(--red); }

.msg {
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-soft);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.msg:last-child { border-bottom: 0; }
.msg-top { display: flex; align-items: center; gap: 8px; }
.msg-top strong { flex: 1; font-size: 15.5px; }
.msg p { margin: 0; font-size: 14px; color: var(--ink-2); }
.msg small { font-size: 12.5px; color: var(--muted); }

.event { padding: 9px 16px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; }
.event:last-child { border-bottom: 0; }
.event time { display: block; font-size: 12px; color: var(--muted); }

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

.test-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.test-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.test-row select { min-height: 44px; border: 1px solid #cfd4da; border-radius: 10px; padding: 0 8px; background: var(--white); font-size: 15px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(80px + var(--safe-bottom));
    transform: translateX(-50%);
    z-index: 950;
    max-width: calc(100% - 32px);
    padding: 12px 16px;
    border-radius: 14px;
    background: var(--ink);
    color: var(--white);
    font-size: 14.5px;
    font-weight: 600;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
}

/* ---------- Login ---------- */

.link {
    border: 0;
    background: none;
    padding: 0;
    font-size: inherit;
    color: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.login {
    height: 100%;
    padding: calc(var(--safe-top) + 48px) 20px 32px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    max-width: 440px;
    margin: 0 auto;
    overflow-y: auto;
}

.login img { width: 170px; height: auto; }
.login h1 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.login p { margin: 0; color: var(--ink-2); }
.login .error { color: var(--red-text); font-weight: 600; min-height: 1.4em; }
.login a { color: var(--ink-2); }

/* Wider screens: keep the pages a readable width. */
@media (min-width: 720px) {
    .page > * { max-width: 640px; margin-left: auto; margin-right: auto; }
    .map-card { right: auto; width: 400px; }
}
