body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ------------------------------------------------------------------ barra */
.app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: var(--header-h);
    padding: 0 18px;
    background: linear-gradient(180deg, #0d0d16, var(--bg));
    border-bottom: 1px solid var(--line);
    flex: 0 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-logo {
    height: 28px;
    width: auto;
    display: block;
}

.brand-divider {
    width: 1px;
    height: 20px;
    background: var(--line-strong);
}

.brand-product {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.02em;
    font-size: 15px;
    color: var(--text);
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
}

.badge-demo {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--line-strong);
    color: var(--muted);
}

.app-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-button {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--muted);
    transition: color 140ms var(--ease), border-color 140ms var(--ease);
}

.icon-button:hover {
    color: var(--text);
    border-color: var(--line-strong);
}

.live-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border: 1px solid rgba(74, 222, 128, 0.25);
    background: rgba(74, 222, 128, 0.08);
    color: var(--green);
}

.live-pill[data-state="connecting"] {
    border-color: rgba(251, 191, 36, 0.25);
    background: rgba(251, 191, 36, 0.08);
    color: var(--amber);
}

.live-pill[data-state="offline"] {
    border-color: rgba(248, 113, 113, 0.28);
    background: rgba(248, 113, 113, 0.08);
    color: var(--red);
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.16);
}

.live-pill[data-state="live"] .live-dot {
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.16); }
    50% { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0.04); }
}

/* ----------------------------------------------------------------- layout */
.layout {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--aside-w);
    gap: 12px;
    padding: 12px;
}

.map-panel {
    position: relative;
    min-height: 0;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--map-bg);
    box-shadow: var(--shadow-lg);
}

#map {
    position: absolute;
    inset: 0;
}

/* Créditos de tiles legibles sobre mapa claro */
.maplibregl-ctrl-attrib {
    font-size: 10px;
    background: rgba(255, 255, 255, 0.82) !important;
}

.maplibregl-ctrl-attrib a {
    color: #334155 !important;
}

.maplibregl-ctrl-group {
    background: rgba(16, 16, 25, 0.92) !important;
    border: 1px solid var(--line) !important;
    box-shadow: var(--shadow-sm) !important;
}

.maplibregl-ctrl-group button + button {
    border-top: 1px solid var(--line) !important;
}

.maplibregl-ctrl-group button span {
    filter: invert(1) opacity(0.8);
}

/* -------------------------------------------------------- overlays del mapa */
.map-chip {
    position: absolute;
    left: 14px;
    bottom: 14px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(16, 16, 25, 0.92);
    border: 1px solid var(--line-strong);
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    backdrop-filter: blur(8px);
}

.map-chip:hover {
    border-color: var(--violet-soft);
}

.map-chip-icon {
    color: var(--violet-soft);
}

.map-fallback {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: grid;
    place-items: center;
    padding: 24px;
    margin: 0;
    text-align: center;
    color: #334155;
    font-size: 13px;
    background: var(--map-bg);
}

.ghost-card {
    position: absolute;
    right: 14px;
    bottom: 14px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 240px;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    background: rgba(16, 16, 25, 0.94);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}

.ghost-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(242, 102, 31, 0.12);
    border: 1px solid rgba(242, 102, 31, 0.3);
    font-size: 15px;
}

.ghost-title {
    font-family: var(--font-display);
    font-size: 12.5px;
    font-weight: 600;
}

.ghost-text {
    font-size: 11px;
    color: var(--muted);
}

.toast-stack {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(320px, calc(100% - 28px));
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    background: rgba(16, 16, 25, 0.96);
    border: 1px solid var(--line-strong);
    box-shadow: var(--shadow-sm);
    animation: toast-in 220ms var(--ease);
}

.toast[data-tone="alert"] {
    border-color: rgba(248, 113, 113, 0.35);
}

.toast-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    border-radius: 9px;
    background: rgba(139, 92, 246, 0.14);
    border: 1px solid rgba(139, 92, 246, 0.3);
    color: var(--violet-soft);
    font-size: 14px;
}

.toast[data-tone="alert"] .toast-icon {
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.32);
    color: var(--red);
}

.toast-title {
    font-size: 12.5px;
    font-weight: 600;
}

.toast-text {
    font-size: 11.5px;
    color: var(--muted);
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* -------------------------------------------------------------- panel lateral */
.side-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 6px;
    border-bottom: 1px solid var(--line);
    flex: 0 0 auto;
}

.tab {
    padding: 8px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
}

.tab:hover {
    color: var(--text);
}

.tab[aria-selected="true"] {
    background: var(--surface-3);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--line-strong);
}

.tab-panel {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    overflow: hidden;
}

.search input {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 12.5px;
}

.search input::placeholder {
    color: var(--muted-2);
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.filter {
    padding: 5px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 11.5px;
}

.filter:hover {
    color: var(--text);
}

.filter.is-active {
    background: rgba(139, 92, 246, 0.16);
    border-color: rgba(139, 92, 246, 0.42);
    color: var(--violet-soft);
}

.filter-count {
    margin-left: 4px;
    font-variant-numeric: tabular-nums;
    opacity: 0.75;
}

.device-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
}

.device-row {
    display: grid;
    grid-template-columns: 10px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--surface-2);
    text-align: left;
    transition: border-color 140ms var(--ease), background 140ms var(--ease);
}

.device-row:hover {
    border-color: var(--line-strong);
}

.device-row[aria-selected="true"] {
    border-color: rgba(139, 92, 246, 0.55);
    background: rgba(139, 92, 246, 0.1);
}

.device-row[data-status="offline"] {
    opacity: 0.68;
}

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

.device-row[data-status="moving"] .status-dot {
    background: var(--status-moving);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

.device-row[data-status="stopped"] .status-dot {
    background: var(--status-stopped);
}

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

.device-name {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-meta {
    display: block;
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.device-speed {
    font-family: var(--font-display);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    text-align: right;
    white-space: nowrap;
}

.device-speed small {
    display: block;
    font-family: var(--font-body);
    font-size: 9.5px;
    font-weight: 500;
    color: var(--muted-2);
}

.list-empty {
    padding: 16px 4px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
}

/* ------------------------------------------------------------------ resumen */
.summary-head {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.eyebrow {
    font-size: 10px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted-2);
}

.summary-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.summary-title h2 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 600;
}

.pill-ok {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--green);
    background: rgba(74, 222, 128, 0.08);
    border: 1px solid rgba(74, 222, 128, 0.22);
}

.kpis {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.kpi {
    padding: 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--line);
}

.kpi-label {
    margin-bottom: 6px;
    font-size: 9.5px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted-2);
}

.kpi-value {
    font-family: var(--font-display);
    font-variant-numeric: tabular-nums;
    font-size: 20px;
    line-height: 1.1;
}

.kpi-unit {
    font-size: 10.5px;
    color: var(--muted);
}

.kpi-delta,
.kpi-note {
    margin-top: 5px;
    font-size: 10px;
    color: var(--muted);
}

.kpi-delta[data-trend="up"] { color: var(--green); }
.kpi-delta[data-trend="down"] { color: var(--red); }

.chart-card {
    padding: 14px 12px 10px;
    border-radius: 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
}

.chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 150px;
}

.bar {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    height: 100%;
}

.bar-fill {
    width: 100%;
    min-height: 6px;
    border-radius: 8px 8px 4px 4px;
    background: linear-gradient(180deg, #8b5cf6, #5b21b6);
}

.bar[data-highlight="true"] .bar-fill {
    background: linear-gradient(180deg, #fb923c, #ea580c);
}

.bar-label {
    font-size: 10px;
    color: var(--muted);
}

.chart-axis {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 10px;
    color: var(--muted-2);
}

.summary-foot {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
    padding-top: 10px;
    font-size: 11px;
    color: var(--muted);
}

/* ------------------------------------------------------------- barra inferior */
.status-bar {
    flex: 0 0 auto;
    height: var(--status-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 18px;
    border-top: 1px solid var(--line);
    background: var(--bg-2);
    font-size: 11.5px;
    color: var(--muted);
}

.status-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.status-alerts {
    color: var(--amber);
}

.noscript {
    padding: 20px;
    color: var(--text);
}

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
    :root { --aside-w: 344px; }
}

@media (max-width: 860px) {
    body {
        height: auto;
        min-height: 100dvh;
        overflow: auto;
    }

    .layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(320px, 52dvh) minmax(0, 1fr);
        gap: 10px;
        padding: 10px;
    }

    .ghost-card {
        display: none;
    }

    .side-panel {
        min-height: 320px;
    }

    .status-bar {
        height: auto;
        padding: 8px 14px;
    }
}

@media (max-width: 520px) {
    .brand-logo {
        height: 24px;
    }

    .brand-divider,
    .brand-product {
        display: none;
    }

    .kpis {
        grid-template-columns: 1fr;
    }

    .kpi {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 10px;
    }

    .kpi-label {
        margin: 0;
    }

    .kpi-delta,
    .kpi-note {
        margin: 0;
    }
}



