* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: #0f1117;
    color: #e2e8f0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2px 24px;
    background: #1a1d2e;
    border-bottom: 1px solid #2d3148;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-logo-img {
    height: 68px;
    width: auto;
}

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

.header-update {
    font-size: 0.78rem;
    color: #64748b;
}

.btn-satellite {
    background: #2d3148;
    color: #94a3b8;
    border: 1px solid #3d4268;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-satellite:hover,
.btn-satellite.active {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

/* LAYOUT */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - 57px);
}

/* MAPA */
.map-section {
    flex: 1;
    position: relative;
}

#map {
    height: 100%;
    width: 100%;
}

/* SIDEBAR */
.sidebar {
    width: 300px;
    flex-shrink: 0;
    background: #1a1d2e;
    border-left: 1px solid #2d3148;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #2d3148;
    flex-shrink: 0;
}

.sidebar-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: #f1f5f9;
}

.sidebar-count {
    font-size: 0.72rem;
    color: #4ade80;
    background: #14532d;
    padding: 2px 8px;
    border-radius: 20px;
}

/* SEARCH */
.sidebar-search {
    padding: 8px 10px;
    border-bottom: 1px solid #2d3148;
    flex-shrink: 0;
}

.sidebar-search input {
    width: 100%;
    background: #0f1117;
    border: 1px solid #2d3148;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.78rem;
    color: #e2e8f0;
    outline: none;
    transition: border-color 0.2s;
}

.sidebar-search input:focus {
    border-color: #6366f1;
}

.sidebar-search input::placeholder {
    color: #64748b;
}

.sensor-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sensor-empty {
    font-size: 0.82rem;
    color: #64748b;
    text-align: center;
    margin-top: 24px;
}

/* SENSOR ROW */
.sensor-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #2d3148;
    background: #0f1117;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}

.sensor-row:hover {
    border-color: #6366f1;
    background: #13162a;
}

.sensor-row.active-row {
    border-color: #6366f1;
    background: #13162a;
}

.sensor-row-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 5px #4ade80;
    flex-shrink: 0;
}

.sensor-row-dot.offline {
    background: #64748b;
    box-shadow: none;
}

.sensor-row-name {
    font-size: 0.78rem;
    font-weight: 700;
    color: #f1f5f9;
    width: 80px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sensor-row-metrics {
    display: flex;
    gap: 8px;
    flex: 1;
    flex-wrap: nowrap;
    overflow: hidden;
}

.sensor-row-metric {
    font-size: 0.75rem;
    color: #e2e8f0;
    font-weight: 600;
    white-space: nowrap;
}

.sensor-row-metric small {
    font-size: 0.62rem;
    color: #64748b;
    margin-left: 1px;
}

.sensor-row-metric.alert {
    color: #f87171;
}

.sensor-row-time {
    font-size: 0.62rem;
    color: #64748b;
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-historial-row {
    background: transparent;
    border: 1px solid #2d3148;
    color: #6366f1;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 5px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-historial-row:hover {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

/* SIGNAL BARS */
.signal-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 14px;
    flex-shrink: 0;
}

.signal-bar {
    width: 4px;
    border-radius: 1px;
    background: #2d3148;
}

.signal-bar.active {
    background: #4ade80;
}

.signal-bar.active.medium {
    background: #f59e0b;
}

.signal-bar.active.weak {
    background: #f87171;
}

/* BADGES */
.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
}

.badge-ok {
    background: #14532d;
    color: #4ade80;
}

.badge-err {
    background: #7f1d1d;
    color: #f87171;
}

/* POPUP LEAFLET */
.naviotic-popup .leaflet-popup-content-wrapper {
    background: #1a1d2e;
    border: 1px solid #2d3148;
    border-radius: 10px;
    color: #e2e8f0;
    padding: 0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.naviotic-popup .leaflet-popup-tip {
    background: #1a1d2e;
}

.naviotic-popup .leaflet-popup-content {
    margin: 0;
    width: 240px !important;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid #2d3148;
}

.popup-device {
    font-size: 0.85rem;
    font-weight: 700;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.popup-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
}

.popup-ok {
    background: #14532d;
    color: #4ade80;
}

.popup-err {
    background: #7f1d1d;
    color: #f87171;
}

.popup-grid {
    padding: 8px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
}

.popup-row span {
    color: #64748b;
}

.popup-row strong {
    color: #f1f5f9;
    font-weight: 600;
}

.popup-btn {
    display: block;
    width: calc(100% - 28px);
    margin: 8px 14px 12px;
    padding: 8px;
    background: #6366f1;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.popup-btn:hover {
    background: #4f46e5;
}

/* MODAL */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 2000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px 16px;
}

.modal {
    background: #1a1d2e;
    border: 1px solid #2d3148;
    border-radius: 14px;
    width: 90vw;
    height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    resize: both;
    min-width: 400px;
    min-height: 300px;
    max-width: 98vw;
    max-height: 98vh;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #2d3148;
    flex-shrink: 0;
}

.modal-title {
    font-size: 1rem;
    font-weight: 700;
    color: #f1f5f9;
}

.modal-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-select {
    background: #0f1117;
    color: #e2e8f0;
    border: 1px solid #2d3148;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.82rem;
    cursor: pointer;
    outline: none;
}

.modal-select:focus {
    border-color: #6366f1;
}

.btn-export-csv {
    background: #14532d;
    color: #4ade80;
    border: 1px solid #166534;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-export-csv:hover {
    background: #166534;
}

.modal-close {
    background: #2d3148;
    color: #94a3b8;
    border: none;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #7f1d1d;
    color: #f87171;
}

.modal-body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
}

.modal-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 20px 0;
    border-bottom: 1px solid #2d3148;
    flex-shrink: 0;
}

.modal-tab {
    background: transparent;
    color: #64748b;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: -1px;
}

.modal-tab:hover {
    color: #cbd5e1;
}

.modal-tab.active {
    color: #6366f1;
    border-bottom-color: #6366f1;
}

.modal-panel {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-chart-container {
    height: 280px;
    padding: 16px 20px 8px;
    flex-shrink: 0;
}

.modal-table-wrap {
    overflow-y: auto;
    flex: 1;
    padding: 0 20px 16px;
}

.modal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.modal-table th {
    text-align: left;
    padding: 8px 10px;
    color: #64748b;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.4px;
    border-bottom: 1px solid #2d3148;
    position: sticky;
    top: 0;
    background: #1a1d2e;
}

.modal-table td {
    padding: 7px 10px;
    color: #cbd5e1;
    border-bottom: 1px solid #1e2235;
}

.modal-table tr:hover td {
    background: #1e2235;
}

/* MAPA HISTORIAL */
#historial-map {
    flex: 1;
    width: 100%;
    min-height: 200px;
}

/* LEAFLET LABEL */
.sensor-label {
    background: #1a1d2e;
    border: 1px solid #6366f1;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* TOASTS */
#toast-container {
    position: fixed;
    top: 70px;
    right: 16px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: #1a1d2e;
    border: 1px solid #2d3148;
    border-left: 4px solid #6366f1;
    border-radius: 8px;
    padding: 10px 14px;
    min-width: 260px;
    max-width: 320px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    pointer-events: all;
    animation: toastIn 0.3s ease;
}

.toast.toast-warn {
    border-left-color: #f59e0b;
}

.toast.toast-error {
    border-left-color: #f87171;
}

.toast.toast-ok {
    border-left-color: #4ade80;
}

.toast-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: #f1f5f9;
    margin-bottom: 2px;
}

.toast-msg {
    font-size: 0.72rem;
    color: #94a3b8;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* RESPONSIVE */
@media (max-width: 768px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 280px;
        border-left: none;
        border-top: 1px solid #2d3148;
    }

    #map {
        height: calc(100vh - 57px - 280px);
    }
}