:root {
    --bg: #f4efe6;
    --panel: rgba(255, 250, 244, 0.88);
    --panel-strong: #fff8f0;
    --line: rgba(108, 73, 34, 0.14);
    --text: #26160a;
    --muted: #7d6144;
    --accent: #cc4b1d;
    --accent-soft: #ffe0d2;
    --ok: #2d7a53;
    --warn: #d58d11;
    --danger: #b42318;
    --offline: #6b7280;
    --shadow: 0 20px 45px rgba(79, 45, 12, 0.12);
    --radius-xl: 28px;
    --radius-lg: 22px;
    --radius-md: 16px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at top left, rgba(204, 75, 29, 0.18), transparent 28%),
        radial-gradient(circle at bottom right, rgba(45, 122, 83, 0.14), transparent 22%),
        linear-gradient(180deg, #f6f0e6 0%, #f1e8dd 100%);
    color: var(--text);
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
}

body {
    padding: 18px;
}

.shell {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 18px;
    min-height: calc(100vh - 36px);
}

.panel,
.sidebar {
    backdrop-filter: blur(12px);
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.sidebar {
    padding: 24px;
    border-radius: var(--radius-xl);
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.panel-lite {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.58);
    padding: 14px;
}

.brand-block h1,
.panel-head h2 {
    margin: 0;
    font-size: 1.45rem;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.subline,
.muted {
    color: var(--muted);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.summary-card {
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 14px;
}

.summary-card strong {
    display: block;
    font-size: 1.6rem;
    margin-top: 6px;
}

.summary-card-alert {
    background: linear-gradient(135deg, #ffe1d9, #fff1ed);
}

.summary-label {
    color: var(--muted);
    font-size: 0.85rem;
}

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

.filter-chip,
.ghost-button {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.72);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 14px;
    font: inherit;
    cursor: pointer;
}

.filter-chip.is-active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.ghost-button.is-active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.tracker-section,
.main-panel,
.bottom-grid {
    min-height: 0;
}

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

.refresh-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #eef6f1;
    color: var(--ok);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
}

.refresh-badge.is-stale {
    background: #fff2dd;
    color: var(--warn);
}

.tracker-list,
.event-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: auto;
}

.tracker-list {
    padding-right: 4px;
}

.tracker-card {
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.7);
    cursor: pointer;
}

.tracker-card.is-selected {
    border-color: rgba(204, 75, 29, 0.45);
    box-shadow: 0 10px 24px rgba(204, 75, 29, 0.16);
}

.tracker-card-top,
.tracker-card-meta,
.detail-grid {
    display: grid;
    gap: 8px;
}

.tracker-card-top {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
}

.tracker-name {
    font-weight: 800;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 999px;
    padding: 8px 10px;
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.status-active { background: #e7f6ee; color: var(--ok); }
.status-gps-missing { background: #fff2dd; color: var(--warn); }
.status-stale { background: #fff1e7; color: #b45309; }
.status-battery-low { background: #fff3f1; color: #c2410c; }
.status-offline { background: #eef2f7; color: var(--offline); }
.status-alarm { background: #fde8e8; color: var(--danger); }

.tracker-card-meta {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    color: var(--muted);
    font-size: 0.88rem;
}

.tracker-card-coords {
    font-size: 0.84rem;
    color: var(--muted);
}

.main-panel {
    display: grid;
    grid-template-rows: minmax(420px, 1fr) 320px;
    gap: 18px;
}

.map-panel,
.detail-panel,
.events-panel {
    border-radius: var(--radius-xl);
    padding: 20px;
}

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

.map {
    min-height: 440px;
    border-radius: 24px;
    overflow: hidden;
    border: 1px solid var(--line);
    margin-top: 14px;
}

.bottom-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 18px;
}

.tracker-detail {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.command-unit-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.detail-box {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.68);
}

.detail-box span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    margin-bottom: 4px;
}

.detail-box strong {
    font-size: 1rem;
}

.event-item {
    display: grid;
    grid-template-columns: 12px minmax(0, 1fr);
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.event-item:last-child {
    border-bottom: 0;
}

.event-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-top: 6px;
}

.event-dot-critical { background: var(--danger); }
.event-dot-warning { background: var(--warn); }
.event-dot-info { background: var(--ok); }

.event-meta {
    color: var(--muted);
    font-size: 0.84rem;
    margin-bottom: 4px;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 160px;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.45);
}

.map-marker {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
}

.tracker-label {
    background: rgba(255, 248, 240, 0.96);
    border: 1px solid rgba(31, 111, 178, 0.22);
    border-radius: 999px;
    box-shadow: 0 8px 20px rgba(38, 22, 10, 0.12);
    color: var(--text);
    font-family: 'Plus Jakarta Sans', 'Segoe UI', sans-serif;
    font-size: 0.78rem;
    font-weight: 800;
    padding: 6px 10px;
}

.tracker-label::before {
    display: none;
}

.command-label {
    border-color: rgba(31, 111, 178, 0.36);
    color: #1f6fb2;
}

.marker-active { background: var(--ok); }
.marker-gps-missing { background: var(--warn); }
.marker-stale { background: #ea580c; }
.marker-battery-low { background: #f97316; }
.marker-offline { background: var(--offline); }
.marker-alarm { background: var(--danger); animation: pulse 1.1s infinite; }

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    70% { transform: scale(1.45); opacity: 0.25; }
    100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 1180px) {
    .shell,
    .bottom-grid {
        grid-template-columns: 1fr;
    }

    .main-panel {
        grid-template-rows: auto auto;
    }
}

@media (max-width: 720px) {
    body {
        padding: 10px;
    }

    .sidebar,
    .map-panel,
    .detail-panel,
    .events-panel {
        padding: 16px;
        border-radius: 22px;
    }

    .summary-grid,
    .detail-grid,
    .tracker-card-meta {
        grid-template-columns: 1fr;
    }

    .map {
        min-height: 360px;
    }
}

.top-nav {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.top-nav-inline {
    justify-content: flex-end;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--line);
    font-weight: 700;
}

.nav-link-active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.layout-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.layout-button {
    flex: 1 1 160px;
}

.layout-arrow-button {
    flex: 0 0 56px;
    font-size: 1.3rem;
    font-weight: 800;
    padding-inline: 0;
}

.ghost-select {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.72);
    color: var(--text);
    border-radius: 999px;
    padding: 10px 14px;
    font: inherit;
}

.tracker-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mini-command-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #e8f3ff;
    border: 2px solid #1f6fb2;
    color: #1f6fb2;
    font-size: 0.72rem;
    font-weight: 800;
}

.command-marker {
    position: relative;
    width: 72px;
    height: 58px;
}

.command-marker-top,
.command-marker-post,
.command-marker-box {
    position: absolute;
    display: block;
    background: #fff;
    border: 4px solid #1f6fb2;
}

.command-marker-top {
    top: 0;
    left: 28px;
    width: 32px;
    height: 24px;
}

.command-marker-post {
    top: 22px;
    left: 26px;
    width: 10px;
    height: 30px;
}

.command-marker-box {
    left: 0;
    bottom: 0;
    width: 72px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1f6fb2;
    font-size: 0.82rem;
    font-weight: 800;
}

.shell.sidebar-collapsed {
    grid-template-columns: 88px minmax(0, 1fr);
}

.shell.sidebar-collapsed .brand-block,
.shell.sidebar-collapsed .summary-grid,
.shell.sidebar-collapsed .filter-row,
.shell.sidebar-collapsed .tracker-section,
.shell.sidebar-collapsed .mobile-only,
.shell.sidebar-collapsed .top-nav {
    display: none;
}

.shell.sidebar-collapsed .sidebar {
    align-items: center;
    justify-content: flex-start;
}

.mobile-only {
    display: none;
}

.mobile-sidebar-toggle {
    position: fixed;
    left: 14px;
    top: 14px;
    z-index: 1900;
    box-shadow: var(--shadow);
}

.stats-shell {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.stats-header,
.stats-panel {
    padding: 20px;
    border-radius: var(--radius-xl);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 18px;
}

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

.table-wrap {
    margin-top: 12px;
    overflow: auto;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
}

.stats-table th,
.stats-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.table-empty {
    text-align: center;
    color: var(--muted);
}

.stats-reset-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 12px;
}

.danger-button {
    border: 0;
    border-radius: 14px;
    padding: 14px 16px;
    background: var(--danger);
    color: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.map-panel:fullscreen {
    padding: 14px;
    background: #f5eee5;
}

.map-panel:fullscreen .map {
    min-height: calc(100vh - 96px);
}

@media (max-width: 1180px) {
    .mobile-only {
        display: inline-flex;
    }

    .shell {
        position: relative;
    }

    .sidebar {
        position: fixed;
        inset: 10px auto 10px 10px;
        width: min(360px, calc(100vw - 20px));
        z-index: 2000;
        transform: translateX(-110%);
        transition: transform 0.22s ease;
        overflow: auto;
    }

    .shell.sidebar-mobile-open .sidebar {
        transform: translateX(0);
    }

    .shell.sidebar-collapsed {
        grid-template-columns: 1fr;
    }

    .stats-grid,
    .stats-summary {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .panel-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .ghost-select,
    .ghost-button,
    .danger-button,
    .nav-link {
        width: 100%;
    }
}
