:root {
    --ink: #ffffff;
    --muted: #9ca3af;
    --page: #0f0f0f;
    --panel: #1a1a1a;
    --line: #2b2b2b;
    --brand: #ec1d45;
    --brand-dark: #b91132;
    --green: #22c55e;
    --blue: #2563eb;
    --amber: #f59e0b;
    --shadow: 0 18px 38px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--page);
    font-family: Arial, Helvetica, sans-serif;
}

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

.hidden { display: none !important; }

.splash {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    color: #fff;
    background: var(--brand);
    transition: opacity .25s ease, visibility .25s ease;
}

.splash.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash .brand-mark {
    color: var(--brand);
    background: #101010;
}

.splash strong {
    font-size: 26px;
}

.splash span {
    opacity: .86;
    font-weight: 700;
}

.loader {
    width: 34px;
    height: 34px;
    border: 4px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

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

.app {
    width: min(100%, 460px);
    min-height: 100vh;
    margin: 0 auto;
    background: var(--page);
}

.login {
    min-height: 100vh;
    display: grid;
    align-content: center;
    gap: 24px;
    padding: 22px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--brand);
    border-radius: 8px;
    font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand span { margin-top: 3px; color: var(--muted); font-size: 13px; }

.login-card, .panel, .status-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-card {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 28px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 12px;
    color: var(--ink);
    background: #101010;
}

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

.check-option {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.check-option input {
    width: 17px;
    min-height: 17px;
}

.link-btn {
    border: 0;
    padding: 0;
    color: var(--brand);
    background: transparent;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    color: var(--ink);
    background: #fff;
}

textarea {
    min-height: 78px;
    resize: vertical;
}

.home,
.history,
.profile {
    min-height: 100vh;
    padding: 14px 14px 158px;
}

.top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 2px 16px;
}

.top span {
    color: var(--muted);
    font-size: 13px;
}

.top h1 {
    margin: 4px 0 0;
    font-size: 28px;
}

.signal-stack {
    display: grid;
    gap: 3px;
    min-width: 94px;
    text-align: right;
}

.signal-stack strong,
.signal-stack span {
    display: block;
    font-size: 12px;
}

.offline-banner {
    margin-bottom: 12px;
    border: 1px solid #60430b;
    border-radius: 8px;
    padding: 10px 12px;
    color: #ffd791;
    background: #281b05;
    font-size: 13px;
    font-weight: 800;
}

.icon-btn {
    width: auto;
    min-width: 64px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #151515;
    color: var(--ink);
    cursor: pointer;
}

.status-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 82px;
    gap: 14px;
    align-items: center;
    padding: 16px;
    margin-bottom: 12px;
    background:
        linear-gradient(135deg, rgba(236,29,69,.18), rgba(37,99,235,.08)),
        var(--panel);
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 27px;
    border-radius: 8px;
    padding: 0 9px;
    color: var(--muted);
    background: #eef2f7;
    font-size: 12px;
    font-weight: 800;
}

.pill.active {
    color: var(--green);
    background: #e4f6ee;
}

.status-card strong {
    display: block;
    margin-top: 10px;
    font-size: 32px;
}

.status-card p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.quick-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.quick-stats div,
.target-card,
.health-grid div,
.summary-grid div {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101010;
}

.quick-stats span,
.target-card span,
.health-grid span,
.summary-grid span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.quick-stats strong,
.target-card strong,
.health-grid strong,
.summary-grid strong {
    display: block;
    margin-top: 6px;
    font-size: 20px;
}

.quick-stats strong.low { color: var(--green); }
.quick-stats strong.review { color: var(--amber); }
.quick-stats strong.high { color: var(--brand-dark); }

.target-grid,
.health-grid,
.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

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

.selfie {
    width: 82px;
    height: 82px;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, var(--brand), var(--blue));
    font-size: 12px;
    font-weight: 800;
}

.selfie img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.panel {
    padding: 14px;
    margin-top: 12px;
}

.safety-panel {
    border-color: rgba(236, 29, 69, .62);
    background: #21080e;
}

.checklist {
    display: grid;
    gap: 10px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.check-row span {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--line);
    background: #101010;
}

.check-row.done {
    color: var(--green);
}

.check-row.done span {
    border-color: var(--green);
    background: var(--green);
    box-shadow: inset 0 0 0 4px #fff;
}

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

.panel-head h2 {
    margin: 0;
    font-size: 16px;
}

.panel-head span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.map {
    height: 160px;
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background:
        linear-gradient(90deg, rgba(37, 99, 235, .12) 1px, transparent 1px),
        linear-gradient(rgba(37, 99, 235, .12) 1px, transparent 1px),
        #e5ecf5;
    background-size: 34px 34px;
}

.mini-map {
    position: absolute;
    inset: 0;
    z-index: 2;
    background: #dfe7f1;
}

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

.mini-map:not(:empty) ~ .road,
.mini-map:not(:empty) ~ .pin {
    display: none;
}

.leaflet-container {
    font-family: Arial, Helvetica, sans-serif;
}

.road {
    position: absolute;
    left: -14%;
    width: 128%;
    height: 34px;
    background: rgba(255,255,255,.78);
    border: 1px solid rgba(103,114,134,.2);
}

.road.one { top: 35%; transform: rotate(14deg); }
.road.two { top: 57%; transform: rotate(-10deg); }

.pin {
    position: absolute;
    left: 48%;
    top: 43%;
    width: 19px;
    height: 19px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: var(--brand);
    box-shadow: 0 10px 20px rgba(17,24,39,.25);
}

.small {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.camera {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    background: #111827;
    object-fit: cover;
}

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

.validation-panel ul {
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
    list-style: none;
}

.validation-panel li {
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    background: #101010;
    font-size: 13px;
    font-weight: 700;
}

.validation-panel li.pass {
    color: var(--green);
    background: #e4f6ee;
    border-color: #bfe8d5;
}

.validation-panel li.fail {
    color: var(--brand-dark);
    background: #fde3e8;
    border-color: #f5b9c5;
}

.primary, .secondary, .danger {
    min-height: 48px;
    border-radius: 8px;
    border: 0;
    padding: 0 14px;
    color: #fff;
    background: var(--brand);
    font-weight: 800;
    cursor: pointer;
}

.secondary {
    color: var(--ink);
    background: #101010;
    border: 1px solid var(--line);
}

.danger { background: var(--brand-dark); }

.safety-panel .danger {
    min-height: 58px;
    font-size: 17px;
    background: #dc2626;
    box-shadow: 0 14px 28px rgba(220, 38, 38, .24);
}

.compact {
    min-height: 36px;
    padding: 0 12px;
}

.full {
    width: 100%;
}

button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

.timeline {
    display: grid;
    gap: 10px;
}

.empty {
    color: var(--muted);
    font-size: 13px;
}

.route-item {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101010;
}

.route-item time {
    color: var(--muted);
    font-size: 13px;
}

.route-item strong, .route-item span {
    display: block;
}

.route-item span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.dock {
    position: fixed;
    left: 50%;
    bottom: 62px;
    width: min(100%, 460px);
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    background: rgba(15,15,15,.94);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
}

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 0;
    z-index: 15;
    width: min(100%, 460px);
    transform: translateX(-50%);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
    background: rgba(15,15,15,.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(10px);
}

.bottom-nav button {
    min-height: 46px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--muted);
    background: transparent;
    font-weight: 800;
    cursor: pointer;
}

.bottom-nav button.active {
    color: var(--brand);
    background: #fde3e8;
    border-color: #f5b9c5;
}

.history-list {
    display: grid;
    gap: 10px;
}

.history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #101010;
}

.history-item strong,
.history-item span {
    display: block;
}

.history-item span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.history-item .pill {
    align-self: start;
}

.dock.shift-active {
    grid-template-columns: 1fr 1fr;
}

.pill.break {
    color: #8a5800;
    background: #fff1cf;
}

.battery-good { color: var(--green) !important; }
.battery-warn { color: var(--amber) !important; }
.battery-low { color: #ef4444 !important; }

@media (max-width: 380px) {
    .target-grid,
    .health-grid {
        grid-template-columns: 1fr;
    }

    .quick-stats strong,
    .target-card strong,
    .health-grid strong,
    .summary-grid strong {
        font-size: 18px;
    }
}
