:root {
    color-scheme: dark;
    --bg: #0b0f16;
    --panel: rgba(17, 23, 34, 0.96);
    --panel-2: #151d2b;
    --ink: #edf3fb;
    --muted: #9ba9ba;
    --line: rgba(144, 164, 190, 0.22);
    --blue: #4b8dff;
    --green: #20c985;
    --amber: #f0a737;
    --red: #ff5c6c;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.34);
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, Arial, Helvetica, sans-serif;
    font-size: 13px;
}

button,
input,
select {
    font: inherit;
}

button,
input,
select {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #111927;
    color: var(--ink);
}

button {
    padding: 0 12px;
    cursor: pointer;
    font-weight: 700;
}

button:hover,
.tab-button.active {
    border-color: rgba(75, 141, 255, 0.55);
    background: rgba(75, 141, 255, 0.16);
    color: #dce9ff;
}

input,
select {
    padding: 0 10px;
}

[hidden] {
    display: none !important;
}

.global-overlay {
    position: fixed;
    z-index: 3000;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(4, 8, 14, 0.82);
    backdrop-filter: blur(7px);
}

.overlay-card {
    width: min(380px, calc(100vw - 36px));
    display: grid;
    justify-items: center;
    gap: 12px;
    padding: 30px;
    background: #101722;
    border: 1px solid rgba(144, 164, 190, 0.32);
    border-radius: 10px;
    box-shadow: var(--shadow);
    text-align: center;
}

.overlay-card strong {
    font-size: 18px;
}

.overlay-card span {
    color: var(--muted);
}

.spinner {
    width: 46px;
    height: 46px;
    border: 4px solid rgba(255, 255, 255, 0.14);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.model-overlay {
    position: fixed;
    z-index: 3100;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 28px;
    background: rgba(4, 8, 14, 0.84);
    backdrop-filter: blur(7px);
}

.model-window {
    position: relative;
    width: min(1180px, calc(100vw - 56px));
    height: min(700px, calc(100vh - 56px));
    display: grid;
    grid-template-columns: minmax(560px, 1fr) 330px;
    gap: 18px;
    padding: 18px;
    background:
        radial-gradient(circle at 24% 22%, rgba(56, 139, 255, 0.18), transparent 28%),
        linear-gradient(145deg, #050b14 0%, #0a1524 48%, #07101b 100%);
    border: 1px solid rgba(95, 181, 255, 0.48);
    border-radius: 12px;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.62), inset 0 0 70px rgba(75, 141, 255, 0.1);
}

.model-close {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 34px;
    min-height: 34px;
    padding: 0;
    border-color: rgba(75, 141, 255, 0.45);
    background: rgba(8, 16, 27, 0.84);
    color: #9fc7ff;
    font-size: 24px;
    line-height: 1;
}

.model-stage {
    min-width: 0;
    min-height: 0;
    display: grid;
    place-items: center;
    border: 1px solid rgba(95, 181, 255, 0.34);
    border-radius: 10px;
    background:
        radial-gradient(circle at 50% 48%, rgba(95, 181, 255, 0.2), transparent 42%),
        linear-gradient(rgba(95, 181, 255, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(95, 181, 255, 0.07) 1px, transparent 1px),
        #040b14;
    background-size: auto, 30px 30px, 30px 30px, auto;
    overflow: hidden;
}

.model-stage canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.model-info {
    min-width: 0;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 12px;
    padding: 18px 14px;
    border: 1px solid rgba(75, 141, 255, 0.24);
    border-radius: 8px;
    background: rgba(10, 20, 34, 0.78);
}

.model-info h2 {
    margin: 0;
    color: #9fc7ff;
    font-size: 17px;
    letter-spacing: 0;
}

.model-info pre {
    margin: 0;
    overflow: auto;
    color: #65b7ff;
    font: 12px/1.55 "Courier New", monospace;
    white-space: pre-wrap;
}

.login-view {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 18% 18%, rgba(75, 141, 255, 0.18), transparent 28%),
        linear-gradient(135deg, #0b0f16 0%, #151d2b 100%);
}

.login-panel {
    width: 380px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.login-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 18px;
}

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

.login-panel h1 {
    margin: 0;
    font-size: 24px;
}

.login-panel p {
    margin: 6px 0 20px;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 12px;
}

.login-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 700;
}

.login-form button {
    margin-top: 4px;
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

.form-error {
    min-height: 18px;
    color: var(--red);
    font-weight: 700;
}

.app-shell {
    height: 100%;
    display: grid;
    grid-template-rows: 48px 1fr;
}

.topbar {
    display: grid;
    grid-template-columns: 280px 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 8px 12px;
    background: #101722;
    border-bottom: 1px solid var(--line);
}

.brand-line strong {
    display: block;
    font-size: 16px;
}

#accountLabel {
    display: block;
    color: var(--muted);
    font-size: 11px;
    margin-top: 1px;
}

.tabs,
.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.tabs {
    justify-content: center;
}

.tab-button {
    min-width: 104px;
    background: transparent;
}

.panel {
    display: none;
    min-height: 0;
}

.panel.active {
    display: block;
}

.live-panel {
    position: relative;
    height: 100%;
}

.map {
    width: 100%;
    height: 100%;
    min-height: 0;
    background: #1c2736;
}

.fleet-panel {
    position: absolute;
    z-index: 500;
    top: 14px;
    left: 14px;
    bottom: 14px;
    width: 390px;
    display: grid;
    grid-template-rows: auto auto auto auto;
    gap: 10px;
    padding: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.fleet-head {
    display: grid;
    grid-template-columns: 1fr 160px;
    gap: 10px;
    align-items: end;
}

.fleet-head h2,
.details-panel h3 {
    margin: 0;
    font-size: 15px;
}

.fleet-head p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.loader,
.history-status {
    padding: 9px 10px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
}

.device-list {
    overflow: visible;
    display: grid;
    align-content: start;
    gap: 8px;
    padding-right: 2px;
}

.device-card {
    display: grid;
    grid-template-columns: 10px 1fr auto;
    gap: 9px;
    align-items: center;
    padding: 9px;
    background: #111927;
    border: 1px solid var(--line);
    border-radius: 7px;
    cursor: pointer;
}

.device-card:hover,
.device-card.selected {
    border-color: rgba(75, 141, 255, 0.7);
    background: #162132;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--muted);
}

.online .status-dot,
.status-pill.online {
    background: var(--green);
}

.delayed .status-dot,
.status-pill.delayed {
    background: var(--amber);
}

.offline .status-dot,
.status-pill.offline {
    background: var(--red);
}

.device-title {
    min-width: 0;
}

.device-title strong,
.device-title span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.device-title span,
.device-meta {
    color: var(--muted);
    font-size: 11px;
}

.device-speed {
    color: var(--ink);
    font-weight: 800;
    text-align: right;
}

.status-pill {
    display: inline-block;
    border-radius: 99px;
    color: #071016;
    font-size: 11px;
    font-weight: 800;
    padding: 3px 7px;
}

.details-panel {
    overflow: visible;
    display: grid;
    grid-template-rows: auto auto;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.details-body {
    overflow: visible;
    display: grid;
    align-content: start;
    gap: 8px;
}

.details-main,
.tech-grid {
    display: grid;
    gap: 6px;
}

.details-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 7px 8px;
    background: #111927;
    border: 1px solid rgba(144, 164, 190, 0.14);
    border-radius: 6px;
}

.details-row span {
    color: var(--muted);
    min-width: 0;
}

.details-row strong {
    text-align: right;
    overflow-wrap: anywhere;
}

.action-row,
.popup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.mini-button,
.popup-actions a,
.popup-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    line-height: 28px;
    padding: 0 10px;
    border: 1px solid rgba(75, 141, 255, 0.38);
    border-radius: 6px;
    background: rgba(75, 141, 255, 0.13);
    color: #e8f2ff;
    font-weight: 800;
    font-size: 12px;
    text-decoration: none;
    vertical-align: middle;
}

.popup-actions button {
    cursor: pointer;
}

.mini-button:hover,
.popup-actions a:hover,
.popup-actions button:hover {
    background: rgba(75, 141, 255, 0.24);
}

.truck-marker {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.92);
    border-radius: 9px;
    background: #101722;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
    color: var(--muted);
}

.truck-marker.online {
    color: var(--green);
}

.truck-marker.delayed {
    color: var(--amber);
}

.truck-marker.offline {
    color: var(--red);
}

.truck-marker svg {
    width: 23px;
    height: 23px;
    display: block;
    stroke: currentColor;
}

.popup h3 {
    margin: 0 0 8px;
    font-size: 15px;
}

.popup p {
    margin: 4px 0;
}

.popup a {
    display: inline-block;
    margin-top: 8px;
    color: #1f65d8;
    font-weight: 800;
}

.popup .popup-actions a {
    margin-top: 0;
    color: #e8f2ff;
}

.leaflet-popup-content .popup-actions a,
.leaflet-popup-content .popup-actions button {
    height: 30px;
    line-height: 30px;
    background: #1f65d8;
    border-color: #1f65d8;
    color: #ffffff;
    text-shadow: none;
}

.leaflet-popup-content .popup-actions a:hover,
.leaflet-popup-content .popup-actions button:hover {
    background: #164da8;
}

.history-panel.active {
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 10px;
    height: 100%;
    padding: 12px;
    background: #0d121b;
}

.history-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.history-controls select {
    min-width: 260px;
}

.history-panel .map {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

@media (max-width: 900px) {
    body {
        overflow: auto;
    }

    .app-shell {
        min-height: 100%;
    }

    .topbar {
        grid-template-columns: 1fr;
        height: auto;
    }

    .fleet-panel {
        position: static;
        width: auto;
        height: 54vh;
        border-radius: 0;
    }

    .live-panel {
        display: grid !important;
        grid-template-rows: 46vh auto;
    }

    .model-window {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(280px, 1fr) 260px;
    }
}
