/**
 * PIJ Ultrasonido - Dashboard Styles
 * Version: 2.0.0 (Modernized)
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    /* Primary Brand Colors - PIJ Blue */
    --primary: #0274be;
    --primary-light: #e6f0f8;
    --primary-dark: #005691;

    /* Semantic Colors */
    --success: #0f9d58;
    --success-light: #e6f4ea;
    --warning: #f4b400;
    --warning-light: #fef7e0;
    --danger: #DA291C;
    /* PIJ Red */
    --danger-light: #fce8e6;
    --info: #0274be;
    --info-light: #e6f0f8;

    /* Backgrounds */
    --bg-primary: #f1f1f1;
    /* PIJ Light Gray */
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;

    /* Text */
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --text-muted: #80868b;

    /* Borders & Shadows */
    --border-color: #e0e0e0;
    --shadow-sm: 0 1px 2px 0 rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    /* Dimensions */
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --header-height: 70px;
    --nav-height: 60px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

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

.logo {
    height: 40px;
    width: auto;
    object-fit: contain;
}

/* Task #148 ronda 2: botones icon-only en la sección Acceso del Local.
   Tamaño uniforme 32x32, estilo igual al refresh-btn de la maqueta.
   Iconos SVG 16x16 centrados. Hover sutil. */
.btn-icon-action {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid #e6e8ec;
    border-radius: 8px;
    color: #3a3f47;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.btn-icon-action:hover {
    background: rgba(13, 146, 224, 0.08);
    color: #0274be;
    border-color: rgba(13, 146, 224, 0.3);
}
.btn-icon-action:active {
    transform: scale(0.95);
}

/* Task #145: el logo Bruma es horizontal (un poco más alto y ancho).
   Lo separamos del PIJ con un divisor vertical sutil para indicar que
   son dos marcas distintas (PIJ = corporativa, Bruma = comercial). */
.logo-bruma {
    height: 32px;
    padding-left: 14px;
    margin-left: 4px;
    border-left: 1px solid rgba(0,0,0,0.12);
}
@media (max-width: 600px) {
    /* En mobile el header se aprieta — escondemos el logo Bruma para no
       romper el layout. El título "PIJ Ultrasonido" + el logo PIJ quedan. */
    .logo-bruma { display: none; }
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

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

.time {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.refresh-countdown {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 4px 8px;
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
    min-width: 35px;
    text-align: center;
}

/* Tabs */
.nav-tabs {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    padding: 0 30px;
    gap: 12px;
    z-index: 99;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: all 0.3s ease;
}

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

.tab.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.tab svg {
    flex-shrink: 0;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 0.2s;
}

.badge-success {
    background: var(--success-light);
    color: var(--success);
}

.badge-danger {
    background: var(--danger-light);
    color: var(--danger);
}

.badge-warning {
    background: var(--warning-light);
    color: #b06d00;
}

.badge-info {
    background: #e3f2fd;
    color: #1565c0;
}

/* Main Content */
.main-content {
    margin-top: calc(var(--header-height) + var(--nav-height));
    padding: 32px;
    min-height: calc(100vh - var(--header-height) - var(--nav-height));
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Sub-pestañas por categoría de dispositivo (Ultrasonidos / Equipos Especiales) */
.device-category-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    padding: 6px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    width: fit-content;
    max-width: 100%;
}

.cat-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.cat-tab:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.cat-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(2, 116, 190, 0.25);
}

.cat-tab.active .cat-count {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

.cat-count {
    display: inline-block;
    min-width: 22px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 700;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    text-align: center;
}

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 32px;
    flex-wrap: wrap;
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.search-box input {
    padding: 12px 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 14px;
    width: 320px;
    max-width: 100%;
    background: var(--bg-primary);
    transition: all 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px var(--primary-light);
}

.filter-buttons {
    display: flex;
    gap: 8px;
    background: var(--bg-primary);
    padding: 4px;
    border-radius: var(--radius-full);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active {
    transform: scale(0.98);
}

.btn-sm {
    padding: 6px 16px;
    font-size: 13px;
    border-radius: var(--radius-full);
}

.btn-icon {
    padding: 10px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
}

.btn-icon:hover {
    background: var(--bg-primary);
    color: var(--primary);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 2px 6px rgba(26, 115, 232, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(26, 115, 232, 0.4);
}

.btn-success {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 6px rgba(15, 157, 88, 0.3);
}

.btn-danger {
    background: var(--danger);
    color: white;
    box-shadow: 0 2px 6px rgba(217, 48, 37, 0.3);
}

.btn-warning {
    background: var(--warning);
    color: #202124;
}

.btn-sync {
    background: linear-gradient(135deg, #00bcd4, #0097a7);
    color: white;
}

.btn-sync:hover {
    background: linear-gradient(135deg, #0097a7, #00838f);
}

.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger-outline:hover {
    background: var(--danger);
    color: white;
}

.btn-warning-outline {
    background: transparent;
    color: var(--warning);
    border: 1px solid var(--warning);
}

.btn-warning-outline:hover {
    background: var(--warning);
    color: #202124;
}

/* Dropdown menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-toggle {
    cursor: pointer;
}

.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    min-width: 180px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 1000;
    padding: 8px 0;
    margin-top: 4px;
}

.dropdown:hover .dropdown-menu,
.dropdown:focus-within .dropdown-menu {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-primary);
    text-align: left;
    transition: background 0.15s;
}

.dropdown-item:hover {
    background: var(--hover);
}

.dropdown-item svg {
    flex-shrink: 0;
}

.dropdown-item-danger {
    color: var(--danger);
}

.dropdown-item-danger:hover {
    background: rgba(217, 48, 37, 0.1);
}

/* Botón de guardar configuración con detección de cambios */
#btn-save-config {
    transition: all 0.3s ease;
}

#btn-save-config:not(.has-changes) {
    background: var(--success);
    cursor: default;
    opacity: 0.85;
}

#btn-save-config.has-changes {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    animation: pulse-save 2s infinite;
}

@keyframes pulse-save {
    0%, 100% {
        box-shadow: 0 2px 6px rgba(26, 115, 232, 0.3);
    }
    50% {
        box-shadow: 0 4px 15px rgba(26, 115, 232, 0.5);
    }
}

/* Estados de botones para comandos pendientes/confirmados */
.btn.pending {
    background: linear-gradient(135deg, #ff9800, #f57c00) !important;
    color: white !important;
    animation: pulse-pending 1.5s infinite;
    position: relative;
}

.btn.pending::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes pulse-pending {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.4);
    }

    50% {
        opacity: 0.9;
        box-shadow: 0 0 10px 4px rgba(255, 152, 0, 0.3);
    }
}

@keyframes dots {

    0%,
    20% {
        content: '.';
    }

    40% {
        content: '..';
    }

    60%,
    100% {
        content: '...';
    }
}

.btn.confirmed {
    background: linear-gradient(135deg, #4caf50, #388e3c) !important;
    color: white !important;
    animation: flash-confirmed 0.5s ease;
}

@keyframes flash-confirmed {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 15px rgba(76, 175, 80, 0.6);
    }
}

.btn-secondary {
    background: #e0e0e0;
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #d0d0d0;
}

.btn-emergency {
    background: linear-gradient(135deg, #ff0000, #cc0000);
    color: white;
    font-weight: 700;
    text-transform: uppercase;
    box-shadow: 0 4px 12px rgba(255, 0, 0, 0.4);
    border: 2px solid #990000;
    animation: pulse-emergency 2s infinite;
}

.btn-emergency:hover {
    background: linear-gradient(135deg, #cc0000, #990000);
    box-shadow: 0 6px 16px rgba(255, 0, 0, 0.5);
    transform: translateY(-2px);
}

@keyframes pulse-emergency {

    0%,
    100% {
        box-shadow: 0 4px 12px rgba(255, 0, 0, 0.4);
    }

    50% {
        box-shadow: 0 4px 20px rgba(255, 0, 0, 0.6);
    }
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-outline:hover {
    background: var(--primary-light);
}

.filter-buttons .btn {
    background: transparent;
    color: var(--text-secondary);
    border: none;
    padding: 6px 20px;
    box-shadow: none;
    font-weight: 500;
}

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

.filter-buttons .btn.active {
    background: #fff;
    color: var(--primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-weight: 600;
}

/* Devices Grid */
.devices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 24px;
}

.device-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.device-card:hover {
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px);
    border-color: var(--primary-light);
}

.device-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--border-color);
    transition: background 0.3s;
}

.device-card.online::before {
    background: var(--success);
}

.device-card.offline::before {
    background: var(--text-muted);
}

.device-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-left: 12px;
}

.device-title {
    display: flex;
    flex-direction: column;
}

.device-id {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

/* Subtítulo en la tarjeta: ID del dispositivo bajo el nombre */
.device-id-sub {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    margin-top: 1px;
    opacity: 0.85;
}

.device-name {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Wrapper del título en el modal: nombre grande + ID pequeño */
.modal-device-title-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.modal-device-title-wrap h2 {
    margin: 0;
    line-height: 1.15;
}

.modal-device-id-sub {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.4px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    margin-top: 2px;
    opacity: 0.85;
}

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

.device-system-state {
    font-size: 13px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.device-system-state.system-on {
    background: var(--success);
    color: white;
    box-shadow: 0 2px 8px rgba(15, 157, 88, 0.4);
}

.device-system-state.system-off {
    background: var(--text-muted);
    color: white;
}

.device-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-full);
}

.status-online {
    background: var(--success-light);
    color: var(--success);
}

.status-offline {
    background: #f1f3f4;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-online .status-dot {
    background: var(--success);
    box-shadow: 0 0 0 2px var(--success-light);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(15, 157, 88, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(15, 157, 88, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(15, 157, 88, 0);
    }
}

.status-offline .status-dot {
    background: var(--text-muted);
}

.device-card-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-left: 12px;
}

.device-info-row-main {
    display: flex;
    gap: 12px;
}

.device-info-row-main .main-item {
    flex: 1;
}

.device-info-grid {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1fr;
    gap: 8px;
}

.schedule-value {
    font-family: 'Roboto Mono', monospace;
    font-size: 12px !important;
}

.device-info-item {
    background: var(--bg-primary);
    padding: 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.device-info-item:hover {
    background: #e8f0fe;
}

.device-info-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
}

.device-info-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.device-info-value.on {
    color: var(--success);
}

.device-info-value.off {
    color: var(--text-muted);
}

.device-info-value.alert {
    color: var(--danger);
}

/* v2.1.1-EV: badge "pending" (sin agua pero dentro del deadband 20min) */
.device-info-value.warn {
    color: #d48806;          /* ámbar */
    font-size: 0.85em;
    font-weight: 600;
}
.status-value.warn {
    color: #d48806;
    font-weight: 600;
}
.alert-item.warn {
    background: #fff7e6;
    border-left: 4px solid #d48806;
}
.alert-item.warn .alert-icon { color: #d48806; }
.alert-item.warn .alert-status { color: #d48806; font-weight: 600; }

/* Estado esperado (simulador) */
.device-expected-state {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 12px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    border: 1px dashed #dee2e6;
}

.expected-state-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 500;
}

.expected-state-value {
    font-size: 13px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
}

.expected-state-value.expected-on {
    background: rgba(76, 175, 80, 0.15);
    color: #2e7d32;
}

.expected-state-value.expected-off {
    background: rgba(158, 158, 158, 0.15);
    color: #616161;
}

.expected-state-reason {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
    flex: 1;
}

.expected-state-verify {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: help;
}

.expected-state-verify.verify-ok {
    background: #4caf50;
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.5);
}

.expected-state-verify.verify-mismatch {
    background: #f44336;
    box-shadow: 0 0 6px rgba(244, 67, 54, 0.5);
    animation: pulse-red 1.5s infinite;
}

.expected-state-verify.verify-unknown {
    background: #9e9e9e;
    opacity: 0.5;
}

@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.device-card-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-left: 12px;
}

.device-location {
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.device-last-seen {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* Emergency Button on Card */
.btn-card-emergency {
    width: 100%;
    margin-top: 12px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(220, 38, 38, 0.3);
}

.btn-card-emergency:hover:not(:disabled) {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(220, 38, 38, 0.4);
}

.btn-card-emergency:active:not(:disabled) {
    transform: translateY(0);
}

.btn-card-emergency:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
    box-shadow: none;
}

.btn-card-emergency svg {
    flex-shrink: 0;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 20px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: all 0.3s;
}

.stat-card:hover .stat-icon {
    transform: rotate(10deg) scale(1.1);
}

.stat-icon.success {
    background: var(--success-light);
    color: var(--success);
}

.stat-icon.warning {
    background: var(--warning-light);
    color: #b06d00;
}

.stat-icon.info {
    background: var(--info-light);
    color: var(--info);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

/* Alerts List */
.alerts-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.alert-item {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 20px;
    border-left: 4px solid transparent;
    transition: transform 0.2s;
}

.alert-item:hover {
    transform: translateX(4px);
}

.alert-icon.water {
    background: var(--info-light);
    color: var(--info);
    border-left-color: var(--info);
}

.alert-icon.emergency {
    background: var(--danger-light);
    color: var(--danger);
    border-left-color: var(--danger);
}

.alert-icon.manual {
    background: var(--warning-light);
    color: #b06d00;
    border-left-color: #b06d00;
}

.alert-item:has(.alert-icon.water) {
    border-left-color: var(--info);
}

.alert-item:has(.alert-icon.emergency) {
    border-left-color: var(--danger);
}

.alert-item:has(.alert-icon.manual) {
    border-left-color: #b06d00;
}

.alert-icon.sync {
    background: #d1fae5;
    color: #059669;
    border-left-color: #059669;
}

.alert-item:has(.alert-icon.sync) {
    border-left-color: #059669;
}

.alert-icon.warning {
    background: #fef3c7;
    color: #d97706;
    border-left-color: #d97706;
}

.alert-item:has(.alert-icon.warning) {
    border-left-color: #d97706;
}

.alert-icon.offline {
    background: #e5e7eb;
    color: #6b7280;
    border-left-color: #6b7280;
}

.alert-item:has(.alert-icon.offline) {
    border-left-color: #6b7280;
}

.alert-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 4px;
}

.alert-device {
    font-size: 13px;
    color: var(--text-secondary);
}

.alert-time {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    transition: opacity 0.3s;
}

.modal.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 20px;
    width: 100%;
    max-width: 900px;
    max-height: calc(100vh - 48px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-content.modal-lg {
    max-width: 1100px;
}

.modal-content.modal-xl {
    max-width: 1400px;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 24px 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8f9fa;
}

.modal-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
}

.btn-close {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    box-shadow: var(--shadow-sm);
    color: var(--text-secondary);
    font-size: 28px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    background: var(--danger-light);
    color: var(--danger);
    transform: rotate(90deg);
}

/* Sync status badge */
.sync-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: var(--warning-light);
    color: #b36b00;
    border: 1px solid #f4b400;
    margin-left: 12px;
    animation: pulse-sync 2s ease-in-out infinite;
}

.sync-badge.hidden {
    display: none;
}

.sync-badge.synced {
    background: var(--success-light);
    color: var(--success);
    border-color: var(--success);
    animation: none;
}

.sync-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #f4b400;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.sync-badge.synced .sync-spinner {
    display: none;
}

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

@keyframes pulse-sync {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Modal header actions (delete button + close) */
.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Danger outline button */
.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
}

.btn-danger-outline:hover {
    background: var(--danger);
    color: white;
    box-shadow: 0 2px 8px rgba(234, 67, 53, 0.3);
}

.btn-danger-outline svg {
    width: 16px;
    height: 16px;
}

.modal-body {
    padding: 32px;
    overflow-y: auto;
}

.detail-section {
    background: var(--bg-primary);
    border-radius: 16px;
    padding: 24px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

.detail-section h3 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
    display: inline-block;
}

/* Form Styles */
.form-group label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 13px;
    margin-bottom: 8px;
}

.form-group input,
.form-group textarea,
.select {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    transition: all 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Modal Wide */
.modal-wide {
    max-width: 1100px;
}

/* Control + Monitor Row */
.control-monitor-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.control-section {
    display: flex;
    flex-direction: column;
}

/* Main Power Control */
.main-power-control {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.btn-power {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 4px solid #ddd;
    background: linear-gradient(180deg, #f5f5f5, #e0e0e0);
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), inset 0 2px 4px rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
}

.btn-power:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.btn-power.active {
    background: linear-gradient(180deg, #4ade80, #22c55e);
    border-color: #16a34a;
    color: white;
    box-shadow: 0 4px 20px rgba(34, 197, 94, 0.4), inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.btn-power.active:hover {
    box-shadow: 0 6px 25px rgba(34, 197, 94, 0.5);
}

.power-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.power-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #9ca3af;
}

.power-status-dot.active {
    background: #22c55e;
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
    animation: pulse 2s infinite;
}

/* Control Actions */
.control-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.btn-emergency-modal {
    flex: 1;
    padding: 12px 16px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-emergency-modal:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-1px);
}

.btn-reset-emergency {
    flex: 1;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
    animation: pulse-warning 2s infinite;
}

.btn-reset-emergency:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    transform: translateY(-1px);
}

@keyframes pulse-warning {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.5);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(245, 158, 11, 0);
    }
}

.btn-outline-sm {
    padding: 10px 16px;
    background: transparent;
    color: var(--warning);
    border: 2px solid var(--warning);
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-outline-sm:hover {
    background: var(--warning-light);
}

/* Control Buttons Grid */
.control-buttons-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.control-buttons-grid .btn {
    padding: 10px 12px;
    font-size: 11px;
}

.btn-info {
    background: var(--info);
    color: white;
}

/* API Monitor Section */
.api-monitor-section {
    display: flex;
    flex-direction: column;
}

.api-monitor-section h3 {
    display: flex;
    align-items: center;
    gap: 12px;
}

.api-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #f3f4f6;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: none;
    letter-spacing: 0;
}

.api-status-badge.online {
    background: var(--success-light);
    color: var(--success);
}

.api-status-badge.offline {
    background: var(--danger-light);
    color: var(--danger);
}

.api-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9ca3af;
}

.api-status-badge.online .api-dot {
    background: var(--success);
    animation: pulse 2s infinite;
}

.api-status-badge.offline .api-dot {
    background: var(--danger);
}

/* API Console */
.api-console {
    flex: 1;
    min-height: 200px;
    max-height: 280px;
    background: #1e1e1e;
    border-radius: var(--radius-sm);
    padding: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 11px;
    line-height: 1.6;
    overflow-y: auto;
    color: #d4d4d4;
}

.console-line {
    padding: 2px 0;
    border-bottom: 1px solid #2d2d2d;
}

.console-line:last-child {
    border-bottom: none;
}

.console-line.info {
    color: #9cdcfe;
}

.console-line.success {
    color: #4ec9b0;
}

.console-line.error {
    color: #f14c4c;
}

.console-line.warning {
    color: #dcdcaa;
}

.console-line .time {
    color: #6a9955;
    margin-right: 8px;
}

.console-line .direction {
    font-weight: bold;
    margin-right: 4px;
}

.console-line .direction.incoming {
    color: #4ec9b0;
}

.console-line .direction.outgoing {
    color: #ce9178;
}

/* Estados de comandos */
.console-line.pending {
    color: #ffb74d;
    font-style: italic;
    background-color: rgba(255, 183, 77, 0.1);
    padding-left: 8px;
    border-left: 3px solid #ffb74d;
}

.console-line.pending::before {
    content: '⏳ ';
}

.console-line.sent {
    color: #64b5f6;
    background-color: rgba(100, 181, 246, 0.1);
    padding-left: 8px;
    border-left: 3px solid #64b5f6;
}

.console-line.sent::before {
    content: '📤 ';
}

.console-line.confirmed {
    color: #81c784;
    font-weight: 600;
    background-color: rgba(129, 199, 132, 0.15);
    padding-left: 8px;
    border-left: 3px solid #4caf50;
}

.console-line.confirmed::before {
    content: '✓ ';
    color: #4caf50;
}

/* Origen de instrucciones */
.console-line.local-instruction {
    color: #ba68c8;
    background-color: rgba(186, 104, 200, 0.1);
    padding-left: 8px;
    border-left: 3px solid #ba68c8;
}

.console-line.local-instruction::before {
    content: '🎛️ ';
}

.console-line.web-instruction {
    color: #4dd0e1;
    background-color: rgba(77, 208, 225, 0.1);
    padding-left: 8px;
    border-left: 3px solid #4dd0e1;
}

.console-line.web-instruction::before {
    content: '🌐 ';
}

/* Respuesta del ESP32 */
.console-line.esp-response {
    color: #aed581;
    background-color: rgba(174, 213, 129, 0.1);
    padding-left: 8px;
    border-left: 3px solid #aed581;
}

.console-line.esp-response::before {
    content: '📡 ';
}

/* Buffer offline sincronizado */
.console-line.sync,
.console-line.bufferRecovery {
    color: #ff9800;
    background-color: rgba(255, 152, 0, 0.15);
    padding-left: 8px;
    border-left: 3px solid #ff9800;
}

.console-line.sync::before,
.console-line.bufferRecovery::before {
    content: '📥 ';
}

/* Grupos de keepalives colapsables */
.console-line.keepalive-group {
    cursor: pointer;
    user-select: none;
}

.console-line.keepalive-group:hover {
    background-color: rgba(174, 213, 129, 0.2);
}

.console-line.keepalive-group .ka-toggle {
    display: inline-block;
    width: 16px;
    font-size: 10px;
    color: #888;
    margin-right: 4px;
}

.console-line.keepalive-group .ka-count {
    display: inline-block;
    background: #4caf50;
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    padding: 1px 6px;
    border-radius: 10px;
    margin-right: 6px;
    min-width: 18px;
    text-align: center;
}

.keepalive-details {
    margin-left: 20px;
    border-left: 2px solid #4caf50;
    padding-left: 8px;
    margin-bottom: 4px;
}

.keepalive-details .ka-detail {
    font-size: 11px;
    opacity: 0.85;
    padding: 2px 4px;
}

.keepalive-details .ka-detail::before {
    content: '└ ';
    color: #4caf50;
}

/* Eventos de Timezone Sync */
.console-line.timezone-sync {
    color: #64b5f6;
    border-left: 3px solid #2196f3;
}

.console-line.timezone-sync::before {
    content: '⏰ ';
}

.console-line.timezone-update {
    color: #81c784;
    border-left: 3px solid #4caf50;
    background-color: rgba(76, 175, 80, 0.1);
}

.console-line.timezone-update::before {
    content: '🔄 ';
}

/* Separador de fechas en historial */
.console-date-separator {
    background: linear-gradient(90deg, #333 0%, #444 50%, #333 100%);
    color: #9cdcfe;
    text-align: center;
    padding: 4px 8px;
    margin: 8px 0;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Botones del historial */
.console-history-buttons {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

/* Botón Pendientes en la fila de history-buttons (Task #82, ronda 2) */
.btn-pending-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-pending-toggle.has-pending {
    background: #ffa726;
    color: #1a1408;
    border-color: #f57c00;
    font-weight: 600;
}
.btn-pending-toggle.has-pending:hover {
    background: #ffb74d;
}
.btn-pending-badge {
    background: rgba(255, 255, 255, 0.25);
    color: inherit;
    border-radius: 10px;
    padding: 0 6px;
    font-size: 10.5px;
    font-weight: 700;
    min-width: 16px;
    text-align: center;
    line-height: 14px;
}
.btn-pending-toggle.has-pending .btn-pending-badge {
    background: #1a1408;
    color: #ffa726;
}
.btn-pending-toggle:not(.has-pending) .btn-pending-badge {
    background: #555;
    color: #ccc;
}

/* Panel de cambios pendientes en cola (Task #82) */
.pending-config-panel {
    background: linear-gradient(180deg, #2d2410 0%, #3a3018 100%);
    border: 1px solid #ffa726;
    border-radius: 6px;
    padding: 8px 10px;
    margin: 8px 0;
    font-size: 12px;
    color: #ffe0b2;
    transition: opacity 0.3s ease, max-height 0.3s ease;
}
.pending-config-panel.is-empty {
    /* Cuando está vacío, atenuamos el borde y el fondo para que no compita
       visualmente con el resto del Monitor API. */
    background: linear-gradient(180deg, #1f1f1f 0%, #262626 100%);
    border-color: #444;
    color: #888;
}
.pending-config-panel.is-empty .pending-config-title {
    color: #888;
}
.pending-config-panel.is-empty .pending-config-count {
    background: #555;
    color: #ccc;
}
.pending-config-panel.is-empty .pending-config-icon {
    opacity: 0.5;
}
.pending-config-panel.is-collapsed {
    /* Plegado por click en el botón Pendientes */
    display: none;
}
.pending-config-empty {
    padding: 8px 4px;
    font-size: 11.5px;
    font-style: italic;
    color: #888;
    text-align: center;
    line-height: 1.4;
}
.pending-config-panel.is-empty .pending-config-empty { display: block; }
.pending-config-panel:not(.is-empty) .pending-config-empty { display: none; }
.pending-config-panel.is-empty .pending-config-list { display: none; }
.pending-config-panel.is-empty #pending-config-clear-btn { display: none; }
.pending-config-panel.is-empty #pending-config-footer { display: none; }

/* Animaciones cuando aparece un item nuevo o desaparece uno aplicado */
@keyframes pending-item-in {
    from { opacity: 0; transform: translateX(-6px); background: rgba(255, 167, 38, 0.35); }
    to   { opacity: 1; transform: translateX(0);     background: transparent; }
}
@keyframes pending-item-out {
    from { opacity: 1; max-height: 60px; padding-top: 4px; padding-bottom: 4px; }
    to   { opacity: 0; max-height: 0;    padding-top: 0;    padding-bottom: 0;    border: 0; }
}
.pending-config-list li.is-new {
    animation: pending-item-in 0.6s ease-out;
}
.pending-config-list li.is-removing {
    animation: pending-item-out 0.5s ease-in forwards;
    overflow: hidden;
}
.pending-config-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    flex-wrap: wrap;
    gap: 6px;
}
.pending-config-title {
    font-weight: 600;
    color: #ffb74d;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.pending-config-icon {
    font-size: 14px;
}
.pending-config-count {
    background: #ffa726;
    color: #1a1408;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 700;
    min-width: 18px;
    display: inline-block;
    text-align: center;
}
.pending-config-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
}
.pending-config-list li {
    padding: 4px 6px;
    border-bottom: 1px dashed rgba(255, 167, 38, 0.18);
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    line-height: 1.4;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: baseline;
}
.pending-config-list li:last-child {
    border-bottom: none;
}
.pending-config-key {
    color: #9cdcfe;
    font-weight: 600;
}
.pending-config-arrow {
    color: #888;
}
.pending-config-value {
    color: #ce9178;
    word-break: break-all;
}
.pending-config-value.bool-true  { color: #4ec9b0; }
.pending-config-value.bool-false { color: #f48771; }
.pending-config-footer {
    margin-top: 6px;
    font-size: 10.5px;
    color: #b3a06a;
    font-style: italic;
}
.btn-danger {
    background: #c62828;
    color: white;
    border: 1px solid #b71c1c;
}
.btn-danger:hover { background: #b71c1c; }

.console-history-buttons .btn {
    padding: 4px 8px;
    font-size: 11px;
}

/* Stats de conexión */
.connection-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
    font-size: 11px;
    color: #888;
}

.connection-stats .stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.connection-stats .stat.good {
    color: #4caf50;
}

.connection-stats .stat.warning {
    color: #ff9800;
}

.connection-stats .stat.bad {
    color: #f44336;
}

/* Info Row */
.info-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 24px;
}

.detail-section.compact {
    padding: 16px;
}

.detail-section.compact h3 {
    margin-bottom: 12px;
    font-size: 12px;
}

/* Status Grid (dentro del modal) */
.status-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.status-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 10px;
    background: white;
    border-radius: 6px;
    font-size: 12px;
}

.status-item .status-label {
    color: var(--text-secondary);
}

.status-item .status-value {
    font-weight: 600;
}

.status-item .status-value.on,
.indicator-value.on {
    color: var(--success);
}

.status-item .status-value.off,
.indicator-value.off {
    color: var(--text-muted);
}

.status-item .status-value.alert,
.indicator-value.alert {
    color: var(--danger);
}

/* Stats Compact */
.stats-compact {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.stats-compact .stat-item {
    text-align: center;
    padding: 10px;
    background: white;
    border-radius: 6px;
}

.stats-compact .stat-item .stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    display: block;
}

.stats-compact .stat-item .stat-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
}

/* Device Info Compact */
.device-info-compact {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.info-row-item {
    display: flex;
    justify-content: space-between;
    padding: 6px 10px;
    background: white;
    border-radius: 6px;
    font-size: 11px;
}

.info-row-item span:first-child {
    color: var(--text-secondary);
}

.info-row-item span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

/* Config Row */
.config-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 24px;
}

.config-row.full-width {
    grid-template-columns: 1fr;
}

/* Config Grid */
.config-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 16px;
}

.config-group {
    background: white;
    padding: 12px;
    border-radius: 8px;
}

.config-group h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.config-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.config-inline label {
    font-size: 12px;
    color: var(--text-secondary);
}

.config-inline input[type="time"],
.config-inline input[type="number"],
.config-inline select {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
}

.config-inline input[type="range"] {
    flex: 1;
    min-width: 100px;
}

/* Modo Inteligente Config */
.smart-mode-config {
    margin-top: 8px;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 8px;
    border-left: 3px solid var(--info);
}

.smart-config-section {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

/* Múltiples horarios */
.config-group-schedules {
    min-width: 280px;
}

#schedule-times-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.schedule-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--bg-primary);
    border-radius: 6px;
    border-left: 3px solid var(--primary);
}

.schedule-num {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    width: 18px;
}

.schedule-sep {
    color: var(--text-muted);
    font-size: 12px;
}

.schedule-row input[type="time"] {
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
    width: 90px;
}

/* Modo 24/7 */
.schedule-247 {
    background: transparent !important;
    border-left: none !important;
    padding: 4px 0 !important;
    margin-bottom: 8px;
}

.schedule-247-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.schedule-247-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.schedule-247-label {
    font-size: 12px;
    color: var(--text-secondary);
}

#schedules-list.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* Botón eliminar horario */
.btn-remove-schedule {
    width: 22px;
    height: 22px;
    border: none;
    background: #ffebee;
    color: #c62828;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-left: auto;
}

.btn-remove-schedule:hover {
    background: #ffcdd2;
    color: #b71c1c;
}

/* Acciones de horarios */
.schedule-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border-color);
}

.btn-add-schedule {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: #e3f2fd;
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-add-schedule:hover {
    background: var(--primary);
    color: white;
}

.btn-add-schedule:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.schedule-overlap-warning {
    font-size: 11px;
    color: #e65100;
    background: #fff3e0;
    padding: 4px 8px;
    border-radius: 4px;
    animation: pulse-warning 1.5s infinite;
}

@keyframes pulse-warning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.smart-config-section:last-child {
    margin-bottom: 0;
}

.smart-label {
    font-weight: 500;
    color: var(--text-primary);
    min-width: 80px;
}

.smart-hint {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.smart-config-section input[type="number"] {
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
}

.smart-config-section select {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
}

/* Device IDs Row */
.device-ids-row {
    display: flex;
    gap: 16px;
    align-items: stretch;
    margin-bottom: 12px;
}

.device-ids-row .device-id-display {
    margin-bottom: 0;
    flex: 1;
}

.box-id-group {
    flex: 1;
    margin: 0 !important;
}

.box-id-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.box-id-input {
    font-family: 'SF Mono', Monaco, monospace;
    font-weight: 600;
    letter-spacing: 0.5px;
}

@media (max-width: 500px) {
    .device-ids-row {
        flex-direction: column;
    }
}

/* Device ID Display */
.device-id-display {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #f0f7ff 0%, #e6f0f8 100%);
    border: 1px solid var(--primary-light);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.device-id-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.device-id-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    font-family: 'SF Mono', Monaco, monospace;
    letter-spacing: 0.5px;
}

.btn-copy {
    margin-left: auto;
    padding: 6px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-copy:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-copy.copied {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

/* Client Form */
.client-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.client-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.client-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.client-form label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.client-form input,
.client-form textarea,
.client-form select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}

.client-form textarea {
    resize: vertical;
    min-height: 60px;
}

/* Timezone y Address fields con botón */
.timezone-field,
.address-field {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

/* Badge del offset de timezone */
.timezone-offset-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--primary-light);
    color: var(--primary);
    margin-left: 6px;
    vertical-align: middle;
}

.timezone-offset-badge:empty {
    display: none;
}

.timezone-field select,
.address-field input {
    flex: 1;
}

.timezone-field .btn,
.address-field .btn {
    flex-shrink: 0;
    padding: 6px 8px;
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-hint.success {
    color: var(--success);
}

.form-hint.error {
    color: var(--danger);
}

/* Resultados de geocodificación */
.form-hint.geo-results {
    margin-top: 8px;
}

.geo-results-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.geo-results-title {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.geo-result-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 10px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.geo-result-item:hover {
    background: #e3f2fd;
    border-color: var(--primary);
}

.geo-result-icon {
    flex-shrink: 0;
    font-size: 12px;
}

.geo-result-text {
    font-size: 12px;
    color: var(--text-primary);
    line-height: 1.3;
}

.form-hint .searching {
    color: var(--primary);
}

/* Pages checkboxes */
.pages-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0;
}
.pages-checkboxes label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    background: #f1f3f4;
    cursor: pointer;
    font-size: 13px;
    font-weight: 400;
    transition: all 0.15s;
    border: 1px solid transparent;
}
.pages-checkboxes label:hover {
    background: #e8eaed;
}
.pages-checkboxes input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
}
.pages-checkboxes input[type="checkbox"]:checked + span {
    color: var(--primary);
    font-weight: 500;
}
.pages-checkboxes label.checked {
    background: #e8f0fe;
    border-color: var(--primary);
}
.pages-checkboxes .no-pages {
    color: var(--text-secondary);
    font-size: 12px;
    font-style: italic;
}

/* WiFi Networks */
.wifi-networks-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    max-height: 120px;
    overflow-y: auto;
}

.wifi-network-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: white;
    border-radius: 6px;
    font-size: 12px;
}

.wifi-network-item.hardcoded {
    background: #f3f4f6;
}

.wifi-network-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wifi-icon {
    color: var(--text-secondary);
}

.wifi-badge {
    font-size: 9px;
    padding: 2px 6px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 4px;
    font-weight: 600;
}

/* WiFi Password inline display */
.wifi-password {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding: 2px 6px;
    background: #f0f0f0;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.wifi-password .pass-hidden,
.wifi-password .pass-visible {
    font-family: 'SF Mono', Monaco, monospace;
    letter-spacing: 1px;
}

.wifi-password .pass-visible {
    color: var(--text-primary);
}

.toggle-password-inline {
    padding: 2px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
    transition: all 0.2s;
}

.toggle-password-inline:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--primary);
}

.wifi-actions {
    display: flex;
    gap: 4px;
}

.wifi-actions button {
    padding: 4px 6px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: 4px;
    transition: all 0.2s;
}

.wifi-actions button:hover {
    background: var(--bg-primary);
    color: var(--primary);
}

.wifi-actions button.delete:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* WiFi Edit Form */
.wifi-network-item.editing {
    flex-direction: column;
    align-items: stretch;
    padding: 12px;
}

.wifi-edit-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.wifi-edit-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wifi-edit-row label {
    min-width: 60px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
}

.wifi-edit-row input,
.wifi-edit-row select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
}

.wifi-edit-row select {
    cursor: pointer;
    background: white;
}

.wifi-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    justify-content: flex-end;
}

.wifi-add-inline {
    display: flex;
    gap: 8px;
}

.wifi-add-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wifi-add-row {
    display: flex;
    gap: 8px;
}

.wifi-type-select {
    width: 130px;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 11px;
    background: white;
    cursor: pointer;
}

.wifi-user-input {
    width: 100%;
}

.wifi-input-sm {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
}

/* Password input wrapper with toggle button */
.wifi-pass-wrapper {
    display: flex;
    flex: 1;
    position: relative;
}

.wifi-pass-wrapper .wifi-input-sm {
    padding-right: 32px;
}

.btn-toggle-pass {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-toggle-pass:hover {
    opacity: 1;
}

/* Badge for Enterprise networks */
.wifi-badge-enterprise {
    font-size: 8px;
    padding: 2px 5px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 4px;
    font-weight: 600;
    margin-left: 4px;
}

.wifi-user-display {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 4px;
}

/* Device Client Info en tarjeta */
.device-client-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-left: 12px;
}

.client-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.client-location {
    font-size: 12px;
    color: var(--text-secondary);
}

/* API Console Actions */
.api-console-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.btn-xs {
    padding: 4px 8px;
    font-size: 10px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* API Countdown */
.api-countdown {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
    font-weight: normal;
}

/* Spin animation */
.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.hidden {
    display: none !important;
}

/* Alerts Panel */
.alerts-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alert-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid var(--border-color);
}

.alert-item.ok {
    border-left-color: var(--success);
}

.alert-item.warning {
    border-left-color: var(--warning);
    background: var(--warning-light);
}

.alert-item.error {
    border-left-color: var(--danger);
    background: var(--danger-light);
}

.alert-item.disabled {
    opacity: 0.5;
    border-left-color: var(--text-muted);
}

.alert-icon {
    color: var(--text-secondary);
    display: flex;
}

.alert-item.ok .alert-icon {
    color: var(--success);
}

.alert-item.warning .alert-icon {
    color: var(--warning);
}

.alert-item.error .alert-icon {
    color: var(--danger);
}

.alert-label {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
}

.alert-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg-primary);
}

.alert-item.ok .alert-status {
    background: var(--success-light);
    color: var(--success);
}

.alert-item.warning .alert-status {
    background: var(--warning);
    color: white;
}

.alert-item.error .alert-status {
    background: var(--danger);
    color: white;
}

/* Accessories Checkboxes */
.accessories-checkboxes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    cursor: pointer;
    padding: 6px 10px;
    background: white;
    border-radius: 6px;
    transition: all 0.2s;
}

.checkbox-label:hover {
    background: var(--bg-primary);
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* Install Config */
.install-config {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Consumption Stats */
.section-subtitle {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 12px 0 8px 0;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.consumption-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.consumption-item {
    background: var(--primary-light);
    padding: 8px;
    border-radius: 6px;
    text-align: center;
}

.consumption-value {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
}

.consumption-label {
    font-size: 10px;
    color: var(--text-secondary);
}

/* History Log (improved tech log) */
.history-log-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-log-list {
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 8px;
}

.history-log-form {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.history-log-form textarea {
    flex: 1;
    min-width: 200px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    min-height: 60px;
}

.history-log-form textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.log-type-select {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    background: white;
    min-width: 180px;
}

/* Tech Log */
.tech-log-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tech-log-list {
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 8px;
}

/* ════════════════════════════════════════════════════════════════
   Sistema de notificaciones por email/webhook (Task #103)
   ════════════════════════════════════════════════════════════════ */
.alerts-notif-section {
    margin-top: 24px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px 20px;
}
.alerts-notif-section summary {
    cursor: pointer;
    user-select: none;
    margin-bottom: 14px;
}
.alerts-notif-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.alerts-notif-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
    gap: 12px;
}
.alert-sub-card {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.alert-sub-card.disabled {
    opacity: 0.6;
    background: #f5f5f5;
}
.alert-sub-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid #eee;
}
.alert-sub-card-header h4 {
    margin: 0;
    font-size: 14px;
}
.alert-sub-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}
.alert-sub-status.on  { background: #c8e6c9; color: #1b5e20; }
.alert-sub-status.off { background: #eee; color: #666; }
.alert-sub-card-body {
    font-size: 12px;
    color: #444;
    line-height: 1.6;
}
.alert-sub-card-body div { margin-bottom: 4px; }
.alert-sub-thresholds {
    font-size: 11px;
    color: #777;
    padding: 4px 8px;
    background: #f9f9f9;
    border-radius: 4px;
    margin-top: 6px;
}
.alert-sub-note {
    font-style: italic;
    color: #555;
    background: #fff8e1;
    padding: 4px 8px;
    border-radius: 4px;
    border-left: 3px solid #ffb300;
}
.event-tag {
    display: inline-block;
    background: #e3f2fd;
    color: #1565c0;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10.5px;
    margin: 1px 2px;
    font-family: 'Monaco', monospace;
}
.event-tag.muted { background: #eee; color: #777; }
.alert-sub-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed #eee;
}
.alerts-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: #888;
}
.alerts-empty p { margin: 6px 0; }

/* Modal CRUD suscripciones — usa el patrón .modal/.modal.show del dashboard
   (display:none → display:flex + opacity:1 al agregar .show). Solo
   sobreescribimos z-index y el contenido para que se vea bien. */
.alert-sub-modal {
    z-index: 1100;
}
.alert-sub-content {
    max-width: 700px !important;
    width: 92% !important;
    border-radius: 12px !important;
    background: var(--bg-primary, #fff) !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    display: block !important;     /* override del flex del .modal-content base */
}
.alert-sub-content .modal-body {
    padding: 16px 20px;
}
.alert-sub-content .form-row {
    margin-bottom: 12px;
}
.alert-sub-content .form-row label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 12px;
    color: #333;
}
.alert-sub-content .form-row input[type="text"],
.alert-sub-content .form-row input[type="email"],
.alert-sub-content .form-row input[type="url"],
.alert-sub-content .form-row input[type="number"],
.alert-sub-content .form-row select,
.alert-sub-content .form-row textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 13px;
}
.alert-sub-content .form-row small {
    display: block;
    color: #777;
    font-size: 10.5px;
    margin-top: 2px;
}
.alert-sub-content .form-row-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}
.alert-sub-content .checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}
.alert-event-checks {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 10px;
    background: #fafafa;
    border-radius: 5px;
    border: 1px solid #eee;
}
.event-check {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 4px;
}
.event-check:hover { background: #fff; }
.event-applies {
    margin-left: auto;
    font-size: 9.5px;
    background: #e0f2f1;
    color: #00695c;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 600;
}

/* Modal de progreso del test (Task #107) */
.alert-test-modal { z-index: 1200; }
.alert-test-content {
    max-width: 560px !important;
    width: 92% !important;
    border-radius: 12px !important;
    background: var(--bg-primary, #fff) !important;
    display: block !important;
}
.alert-test-content .modal-body {
    padding: 20px 24px;
}
.test-progress {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.test-step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f8f9fa;
    border-left: 3px solid #ddd;
    transition: background 0.3s ease, border-color 0.3s ease;
    animation: step-in 0.4s ease-out;
}
@keyframes step-in {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}
.test-step.active {
    background: #e3f2fd;
    border-left-color: #1976d2;
}
.test-step.done {
    background: #e8f5e9;
    border-left-color: #2e7d32;
}
.test-step.fail {
    background: #ffebee;
    border-left-color: #c62828;
}
.test-step.pending { opacity: 0.6; }
.test-step-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.step-spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(25, 118, 210, 0.25);
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: step-spin 0.7s linear infinite;
}
@keyframes step-spin {
    to { transform: rotate(360deg); }
}
.step-check {
    color: #2e7d32;
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
}
.step-x {
    color: #c62828;
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
}
.test-step-text {
    flex: 1;
    font-size: 13px;
    line-height: 1.4;
}
.test-step-text strong { display: block; color: #333; }
.test-step-text small {
    display: block;
    color: #666;
    margin-top: 2px;
    font-size: 11.5px;
}
.test-step.fail .test-step-text small { color: #c62828; }

.test-final-result {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    animation: step-in 0.4s ease-out;
}
.test-final-result.success {
    background: #e8f5e9;
    border-left: 4px solid #2e7d32;
    color: #1b5e20;
}
.test-final-result.fail {
    background: #ffebee;
    border-left: 4px solid #c62828;
    color: #b71c1c;
}
.test-final-result strong { font-size: 15px; }
.test-final-result p { margin: 8px 0 4px; font-size: 13px; line-height: 1.5; }
.test-final-result small { font-size: 11px; opacity: 0.75; display: block; margin-top: 8px; }

/* Panel de estado del test de suscripción (Task #106) */
.alert-test-status {
    margin: 12px 20px 0;
    padding: 14px 16px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    display: none;
    animation: test-status-in 0.3s ease-out;
}
@keyframes test-status-in {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.alert-test-status[data-state="sending"] {
    background: #e3f2fd;
    border-left: 4px solid #1976d2;
    color: #0d47a1;
}
.alert-test-status[data-state="success"] {
    background: #e8f5e9;
    border-left: 4px solid #2e7d32;
    color: #1b5e20;
}
.alert-test-status[data-state="error"] {
    background: #ffebee;
    border-left: 4px solid #c62828;
    color: #b71c1c;
}
.alert-test-status[data-state="warning"] {
    background: #fff3e0;
    border-left: 4px solid #f57c00;
    color: #e65100;
}
.test-spinner-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.test-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(25, 118, 210, 0.2);
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: test-spin 0.7s linear infinite;
    flex-shrink: 0;
}
@keyframes test-spin {
    to { transform: rotate(360deg); }
}
.test-results {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.test-line {
    background: rgba(255, 255, 255, 0.55);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 12.5px;
}
.test-line.test-ok   { color: #1b5e20; }
.test-line.test-fail { color: #b71c1c; }
.test-line small { display: block; margin-top: 2px; opacity: 0.85; }
.test-timestamp {
    margin-top: 8px;
    text-align: right;
    color: #777;
}

/* Tabla de historial de envíos */
.alerts-history-table-wrap {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
}
.alerts-history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.alerts-history-table th,
.alerts-history-table td {
    padding: 6px 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}
.alerts-history-table th {
    background: #f5f5f5;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}
.alerts-history-table code {
    font-size: 11px;
    background: #f0f0f0;
    padding: 1px 5px;
    border-radius: 3px;
}
.alert-history-ok   { color: #2e7d32; font-weight: 600; }
.alert-history-fail { color: #c62828; font-weight: 600; }

/* Fotos en notas del historial (Task #102) */
.tech-log-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.tech-log-photo {
    display: inline-block;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    background: #f0f0f0;
    border: 1px solid #ddd;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tech-log-photo:hover {
    transform: scale(1.04);
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
}
.tech-log-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.history-log-photo-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.tech-log-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 20px;
}

.tech-log-entry {
    background: white;
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    border-left: 3px solid var(--primary);
}

.tech-log-entry:last-child {
    margin-bottom: 0;
}

/* Log entry types */
.tech-log-entry[data-type="maintenance"] {
    border-left-color: var(--warning);
}

.tech-log-entry[data-type="repair"] {
    border-left-color: var(--danger);
}

.tech-log-entry[data-type="replacement"] {
    border-left-color: #9c27b0;
}

.tech-log-entry[data-type="config_change"] {
    border-left-color: var(--info);
}

.tech-log-entry[data-type="id_change"] {
    border-left-color: #ff5722;
}

.tech-log-entry[data-type="installation"] {
    border-left-color: var(--success);
}

.tech-log-entry[data-type="api_log"] {
    border-left-color: #607d8b;
}

.tech-log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.tech-log-type {
    font-size: 11px;
    font-weight: 500;
    margin-right: 8px;
}

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

.tech-log-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
}

.tech-log-delete:hover {
    color: var(--danger);
}

.tech-log-text {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    white-space: pre-wrap;
}

.tech-log-form textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    min-height: 60px;
}

.tech-log-form textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.tech-log-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tech-log-count {
    font-size: 11px;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 8px;
}

/* Local Change Alert */
.local-change-alert {
    margin-bottom: 12px;
}

.local-change-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    animation: pulse 2s infinite;
}

.local-change-banner.warning {
    background: var(--warning-light);
    border: 1px solid var(--warning);
}

.local-change-banner svg {
    color: var(--warning);
    flex-shrink: 0;
}

.local-change-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.local-change-content strong {
    font-size: 13px;
    color: var(--text-primary);
}

.local-change-content span {
    font-size: 11px;
    color: var(--text-secondary);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.local-changes-history {
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 8px;
    max-height: 150px;
    overflow-y: auto;
}

.local-change-item {
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.local-change-item:last-child {
    margin-bottom: 0;
}

.local-change-item .change-desc {
    color: var(--text-primary);
}

.local-change-item .change-time {
    color: var(--text-muted);
    font-size: 11px;
}

/* Responsive */
@media (max-width: 1024px) {
    .control-monitor-row {
        grid-template-columns: 1fr;
    }

    .info-row {
        grid-template-columns: 1fr;
    }

    .config-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 0 16px;
        height: 60px;
    }

    .header h1 {
        display: none;
    }

    .main-content {
        padding: 16px;
        margin-top: 110px;
    }

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

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

    .search-box input {
        width: 100%;
    }

    .modal-content {
        height: 100%;
        border-radius: 0;
    }

    .control-buttons-grid {
        grid-template-columns: 1fr;
    }

    .client-form .form-row {
        grid-template-columns: 1fr;
    }

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

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

/* ============================================================
   HISTORY MODAL - Charts & Stats
   ============================================================ */

/* Device ID badge in header */
.device-id-badge {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-secondary);
    background: #e9ecef;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    margin-left: 8px;
}

/* Stats buttons (clickeable) */
.history-stats-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-btn {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.stat-btn:hover {
    border-color: var(--primary);
    background: linear-gradient(135deg, #e8f4fd 0%, #d0e8f9 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-btn.active {
    border-color: var(--primary);
    background: linear-gradient(135deg, var(--primary-light) 0%, #b8d4e8 100%);
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}

.stat-btn .stat-icon {
    font-size: 28px;
    line-height: 1;
}

.stat-btn .stat-info {
    display: flex;
    flex-direction: column;
}

.stat-btn .stat-number {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-btn .stat-title {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Chart title in toolbar */
.chart-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

/* Chart panels */
.chart-container {
    position: relative;
}

.chart-panel {
    display: none;
}

.chart-panel.active {
    display: block;
}

/* Sub stats below chart */
.chart-sub-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: var(--radius);
    margin-top: 12px;
}

.sub-stat {
    font-size: 13px;
}

.sub-stat .label {
    color: var(--text-secondary);
}

.sub-stat span:not(.label) {
    font-weight: 600;
    color: var(--text-primary);
}

/* Pie chart specific */
.chart-wrapper.chart-medium-pie {
    height: 280px;
    display: flex;
    justify-content: center;
}

.chart-wrapper.chart-small-pie {
    height: 160px;
    width: 160px;
    flex-shrink: 0;
}

/* Records chart improved - Keepalive summary */
.records-keepalive-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #1a73e8 0%, #0d5ab9 100%);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    color: white;
}

.keepalive-main-stat {
    display: flex;
    align-items: center;
    gap: 12px;
}

.keepalive-icon {
    font-size: 28px;
}

.keepalive-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
}

.keepalive-label {
    font-size: 14px;
    opacity: 0.9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.keepalive-meta {
    font-size: 12px;
    opacity: 0.8;
}

/* Records events section */
.records-events-section {
    margin-bottom: 16px;
}

.records-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 12px 0;
}

.records-chart-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* Records bars container */
.records-bars-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.records-bar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}

.records-bar-tooltip {
    display: none;
    position: absolute;
    left: 110px;
    top: 100%;
    margin-top: 5px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    min-width: 200px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-primary);
}

.records-bar-item:hover .records-bar-tooltip {
    display: block;
}

.records-bar-label {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 100px;
}

.records-bar-track {
    flex: 1;
    height: 24px;
    background: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.records-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
    min-width: 2px;
}

.records-bar-value {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
}

.records-bar-value.inside {
    color: white;
    right: auto;
    left: 8px;
}

/* Records legend improved */
#chart-records .chart-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

#chart-records .legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 6px 10px;
    background: #fafafa;
    border-radius: 4px;
}

#chart-records .legend-count {
    margin-left: auto;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: var(--radius);
    margin-top: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.legend-count {
    font-weight: 600;
    color: var(--text-primary);
}

/* Emergency list */
.emergency-list {
    background: #fff5f5;
    border: 1px solid #ffcccc;
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 12px;
}

.emergency-list h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--danger);
}

.emergency-items {
    max-height: 200px;
    overflow-y: auto;
}

.emergency-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: white;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 13px;
}

.emergency-item .time {
    font-weight: 600;
    color: var(--danger);
}

.emergency-item .desc {
    color: var(--text-secondary);
}

.no-emergencies {
    text-align: center;
    padding: 20px;
    color: var(--success);
    font-size: 14px;
}

/* Emergency Summary Grid */
.emergency-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.emergency-type-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: #fafafa;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.emergency-type-card:hover {
    background: white;
    box-shadow: var(--shadow-sm);
}

.emergency-type-card .type-icon {
    font-size: 24px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(234, 67, 53, 0.1);
    border-radius: 8px;
}

.emergency-type-card.button .type-icon { background: rgba(234, 67, 53, 0.15); }
.emergency-type-card.water .type-icon { background: rgba(251, 188, 4, 0.15); }
.emergency-type-card.power .type-icon { background: rgba(99, 102, 241, 0.15); }
.emergency-type-card.network .type-icon { background: rgba(16, 185, 129, 0.15); }

.emergency-type-card .type-info {
    flex: 1;
}

.emergency-type-card .type-count {
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    color: var(--text-primary);
}

.emergency-type-card .type-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Service Interruptions */
.service-interruptions {
    margin: 16px 0;
}

.section-subtitle {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 12px 0;
}

.interruptions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.interruption-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid;
}

.interruption-card.power {
    background: linear-gradient(135deg, #fef3c7 0%, #fff 100%);
    border-color: #fcd34d;
}

.interruption-card.network {
    background: linear-gradient(135deg, #dbeafe 0%, #fff 100%);
    border-color: #93c5fd;
}

.interruption-icon {
    font-size: 28px;
}

.interruption-info {
    flex: 1;
}

.interruption-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.interruption-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.interruption-detail {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Emergency list header */
.emergency-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.emergency-list-header .section-subtitle {
    margin: 0;
}

.emergency-count {
    font-size: 12px;
    color: var(--text-muted);
    background: white;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

/* Emergency item improved */
.emergency-items .emergency-item {
    display: grid;
    grid-template-columns: 24px 130px 1fr auto;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 6px;
    align-items: center;
}

.emergency-item .type-indicator {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.emergency-item .type-indicator.button { background: rgba(234, 67, 53, 0.15); }
.emergency-item .type-indicator.water { background: rgba(251, 188, 4, 0.15); }
.emergency-item .type-indicator.power { background: rgba(99, 102, 241, 0.15); }
.emergency-item .type-indicator.network { background: rgba(16, 185, 129, 0.15); }

.emergency-item .duration {
    font-size: 11px;
    color: var(--text-muted);
    background: #f5f5f5;
    padding: 3px 8px;
    border-radius: 4px;
}

/* ========================================
   PANEL DE BLACKOUTS
   ======================================== */

.blackout-summary {
    margin-bottom: 20px;
}

.blackout-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

@media (max-width: 800px) {
    .blackout-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.blackout-stat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.blackout-stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.blackout-stat-card .stat-icon.power {
    background: rgba(99, 102, 241, 0.15);
}

.blackout-stat-card .stat-icon.network {
    background: rgba(16, 185, 129, 0.15);
}

.blackout-stat-card .stat-icon.total {
    background: rgba(251, 188, 4, 0.15);
}

.blackout-stat-card .stat-icon.uptime {
    background: rgba(52, 168, 83, 0.15);
}

.blackout-stat-card .stat-content {
    flex: 1;
}

.blackout-stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.blackout-stat-card .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.blackout-stat-card .stat-detail {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.blackout-list {
    margin-top: 20px;
}

.blackout-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

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

.blackout-items {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.blackout-item {
    display: grid;
    grid-template-columns: 32px 1fr 100px 80px;
    gap: 12px;
    padding: 12px 16px;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.blackout-item:last-child {
    border-bottom: none;
}

.blackout-item:hover {
    background: #f8f9fa;
}

.blackout-item .type-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.blackout-item .type-icon.power {
    background: rgba(99, 102, 241, 0.15);
}

.blackout-item .type-icon.network {
    background: rgba(16, 185, 129, 0.15);
}

.blackout-item .time-range {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.blackout-item .time-range .start-time {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.blackout-item .time-range .end-time {
    font-size: 11px;
    color: var(--text-muted);
}

.blackout-item .duration {
    font-size: 14px;
    font-weight: 600;
    color: var(--danger);
    text-align: right;
}

.blackout-item .type-label {
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    text-align: center;
}

.blackout-item .type-label.power {
    background: rgba(99, 102, 241, 0.15);
    color: #6366f1;
}

.blackout-item .type-label.network {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.history-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: #f8f9fa;
    border-radius: var(--radius);
    gap: 16px;
}

.history-toolbar .toolbar-left,
.history-toolbar .toolbar-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chart-wrapper {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    padding: 16px;
    margin-bottom: 16px;
}

.chart-wrapper.chart-large {
    height: 350px;
}

.chart-wrapper.chart-medium {
    height: 200px;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

.history-days-list {
    background: #f8f9fa;
    border-radius: var(--radius);
    padding: 16px;
}

.history-days-list h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.days-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.day-chip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.day-chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
}

.day-chip.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.day-chip .day-size {
    color: var(--text-muted);
    font-size: 10px;
    margin-left: 4px;
}

/* Timeline Chart Styles */
.chart-wrapper.chart-timeline {
    height: 150px;
    margin: 12px 0;
}

.timeline-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.timeline-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.timeline-legend .legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: inline-block;
}

.timeline-zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: var(--radius-sm);
}

.timeline-zoom-controls .zoom-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.timeline-zoom-controls .btn {
    padding: 4px 10px;
}

.timeline-zoom-controls .btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.timeline-events-list {
    margin-top: 16px;
    max-height: 200px;
    overflow-y: auto;
}

.timeline-event-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-left: 3px solid var(--border-color);
    margin-bottom: 8px;
    background: #fafafa;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    transition: all 0.2s;
}

.timeline-event-item:hover {
    background: var(--primary-light);
}

.timeline-event-item.event-on {
    border-left-color: #34a853;
}

.timeline-event-item.event-off {
    border-left-color: #9e9e9e;
}

.timeline-event-item.event-config-local {
    border-left-color: #1a73e8;
}

.timeline-event-item.event-config-web {
    border-left-color: #673ab7;
}

.timeline-event-item.event-emergency {
    border-left-color: #ea4335;
}

.timeline-event-item.event-water {
    border-left-color: #fbbc04;
}

.timeline-event-time {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 120px;
}

.timeline-event-type {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

.timeline-event-detail {
    font-size: 11px;
    color: var(--text-secondary);
    flex: 1;
}

/* Timeline Stats Container - Tabla de estadísticas */
.timeline-stats-container {
    margin-bottom: 16px;
}

.timeline-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.timeline-stat-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
}

.timeline-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.timeline-stat-card .stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.timeline-stat-card .stat-icon.on { background: rgba(52, 168, 83, 0.15); color: #34a853; }
.timeline-stat-card .stat-icon.off { background: rgba(158, 158, 158, 0.15); color: #9e9e9e; }
.timeline-stat-card .stat-icon.config { background: rgba(26, 115, 232, 0.15); color: #1a73e8; }
.timeline-stat-card .stat-icon.emergency { background: rgba(234, 67, 53, 0.15); color: #ea4335; }
.timeline-stat-card .stat-icon.water { background: rgba(251, 188, 4, 0.15); color: #fbbc04; }
.timeline-stat-card .stat-icon.total { background: rgba(2, 116, 190, 0.15); color: var(--primary); }

.timeline-stat-card .stat-info {
    flex: 1;
}

.timeline-stat-card .stat-value {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.timeline-stat-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timeline-stat-card .stat-sublabel {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Timeline Filters */
.timeline-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #f8f9fa;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}

.timeline-filters .filter-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}

.timeline-filters .filter-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.timeline-filters .filter-checkbox:hover {
    background: rgba(0, 0, 0, 0.05);
}

.timeline-filters .filter-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.timeline-filters .legend-color {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

/* Activity Heatmap por hora */
.activity-heatmap-container {
    margin-top: 16px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.activity-heatmap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.activity-heatmap-header h5 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.heatmap-legend {
    display: flex;
    gap: 12px;
    font-size: 11px;
    color: var(--text-secondary);
}

.heatmap-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.heat-box {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.heat-none { background: #ebedf0; }
.heat-low { background: #9be9a8; }
.heat-med { background: #40c463; }
.heat-high { background: #216e39; }

.activity-heatmap {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    gap: 3px;
}

.heat-cell {
    aspect-ratio: 1;
    min-height: 24px;
    border-radius: 3px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    position: relative;
}

.heat-cell:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    z-index: 1;
}

.heat-cell::after {
    content: attr(data-hour);
    position: absolute;
    bottom: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Solo mostrar etiqueta cada 4 horas */
.heat-cell:not(:nth-child(4n+1))::after {
    display: none;
}

/* Timeline Table Container */
.timeline-table-container {
    margin-top: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.timeline-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--border-color);
}

.timeline-table-header h5 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.timeline-table-header .events-count {
    font-size: 12px;
    color: var(--text-muted);
    background: white;
    padding: 4px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.timeline-events-table {
    max-height: 300px;
    overflow-y: auto;
}

/* Tabla de eventos mejorada */
.timeline-events-table .event-row {
    display: grid;
    grid-template-columns: 140px 100px 1fr auto;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid #f0f0f0;
    align-items: center;
    transition: background 0.15s;
}

.timeline-events-table .event-row:hover {
    background: var(--primary-light);
}

.timeline-events-table .event-row:last-child {
    border-bottom: none;
}

.timeline-events-table .event-time {
    font-size: 12px;
    color: var(--text-muted);
    font-family: 'SF Mono', Monaco, monospace;
}

.timeline-events-table .event-type {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
}

.timeline-events-table .event-type .type-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.timeline-events-table .event-detail {
    font-size: 12px;
    color: var(--text-secondary);
}

.timeline-events-table .event-duration {
    font-size: 11px;
    color: var(--text-muted);
    background: #f5f5f5;
    padding: 3px 8px;
    border-radius: 4px;
}

/* Session bars - para mostrar períodos ON/OFF */
.session-bars-container {
    margin: 16px 0;
    padding: 12px;
    background: #fafafa;
    border-radius: var(--radius-sm);
}

.session-bars-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.session-bars-header h6 {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.session-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.session-bar-date {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 60px;
}

.session-bar-track {
    flex: 1;
    height: 20px;
    background: #e0e0e0;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.session-bar-segment {
    position: absolute;
    height: 100%;
    top: 0;
}

.session-bar-segment.on {
    background: #34a853;
}

.session-bar-segment.off {
    background: #9e9e9e;
}

.session-bar-segment.emergency {
    background: #ea4335;
}

@media (max-width: 1200px) {
    .history-stats-buttons {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .history-stats-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-btn {
        padding: 12px;
    }

    .stat-btn .stat-icon {
        font-size: 22px;
    }

    .stat-btn .stat-number {
        font-size: 16px;
    }

    .history-toolbar {
        flex-direction: column;
        gap: 12px;
    }

    .history-toolbar .toolbar-left,
    .history-toolbar .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .chart-wrapper.chart-large {
        height: 250px;
    }

    .chart-sub-stats {
        flex-wrap: wrap;
        gap: 12px;
    }
}

/* ============================================================
   RELAY CYCLES INFO
   ============================================================ */

.relay-cycles-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px 12px;
    background: #f0f4f8;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.relay-cycles-info .cycles-label {
    color: var(--text-secondary);
}

.relay-cycles-info .cycles-value {
    font-weight: 600;
    color: var(--text-primary);
}

.relay-cycles-info.warning {
    background: var(--warning-light);
}

.relay-cycles-info.warning .cycles-value {
    color: var(--warning);
}

.relay-cycles-info.danger {
    background: var(--danger-light);
}

.relay-cycles-info.danger .cycles-value {
    color: var(--danger);
}

.relay-cycles-info .btn-xs {
    margin-left: auto;
    padding: 2px 8px;
    font-size: 11px;
}

/* Config help text */
.config-help {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    line-height: 1.4;
}

/* Device ID info */
.device-id-info {
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: 10px;
}
/* Pending Devices Alert */
.pending-alert {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeeba 100%);
    border: 1px solid #ffc107;
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.2);
}

.pending-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    font-size: 14px;
}

.pending-icon {
    font-size: 20px;
}

.pending-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pending-device-item {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    background: white;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid #e0e0e0;
}

.pending-id {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: var(--primary);
    min-width: 90px;
}

.pending-info {
    flex: 1;
    font-size: 11px;
    color: var(--text-secondary);
    min-width: 150px;
}

.pending-device-item .badge {
    font-size: 10px;
    padding: 3px 8px;
    text-transform: none;
}

.pending-device-item .btn {
    flex-shrink: 0;
    margin-left: auto;
}

/* Replace Device Modal */
.replace-options-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

.replace-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.replace-option:last-child {
    border-bottom: none;
}

.replace-option:hover {
    background: var(--bg-tertiary);
}

.replace-option-id {
    font-family: 'Roboto Mono', monospace;
    font-weight: 600;
    color: var(--primary);
}

.replace-option-info {
    display: flex;
    gap: 12px;
    align-items: center;
}

.replace-location {
    color: var(--text-secondary);
    font-size: 13px;
}

.replace-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}

.replace-status.online {
    background: var(--success-light);
    color: var(--success);
}

.replace-status.offline {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* RTC Battery Warning */
.rtc-warning {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--warning-light);
    color: #856404;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    margin-top: 8px;
}

.rtc-warning svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ============================================================
   Device Card Alert Icons
   ============================================================ */

.device-alert-icon {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    animation: pulse-alert 1.5s infinite;
}

.device-alert-icon.warning {
    color: var(--warning);
}

.device-alert-icon.critical {
    color: var(--danger);
}

.device-card.has-alert {
    border-left: 4px solid var(--warning);
}

.device-card.has-critical-alert {
    border-left: 4px solid var(--danger);
    animation: shake-subtle 0.5s ease-in-out;
}

@keyframes pulse-alert {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes shake-subtle {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* ============================================================
   ESP32 Device Info Section
   ============================================================ */

.device-esp-info {
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 10px;
    margin-top: 8px;
    font-size: 12px;
}

.esp-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    gap: 10px;
    border-bottom: 1px solid var(--border-color);
}

.esp-info-row .btn {
    padding: 3px 8px;
    font-size: 11px;
    flex-shrink: 0;
}

.esp-info-row .btn svg {
    vertical-align: middle;
    margin-right: 3px;
}

.esp-info-row:last-child {
    border-bottom: none;
}

.esp-label {
    color: var(--text-secondary);
}

.esp-value {
    font-family: monospace;
    color: var(--text-primary);
}

/* ============================================================
   Display Mode Help Button
   ============================================================ */

.btn-help {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    font-weight: bold;
    font-size: 12px;
    cursor: pointer;
    margin-left: 8px;
    transition: all 0.2s;
}

.btn-help:hover {
    background: var(--primary);
    color: white;
}

/* Config Info Box */
.config-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(66, 133, 244, 0.1);
    border: 1px solid rgba(66, 133, 244, 0.3);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--primary);
}

.config-info .info-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
}

/* Display Modes Help Modal */
.modal-xlarge {
    max-width: 1100px;
    width: 95%;
}

/* Mode Selector Tabs */
.mode-selector-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.mode-tab {
    padding: 10px 20px;
    border: 2px solid var(--border-color);
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.mode-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Mode Content Sections */
.mode-content {
    display: none;
}

.mode-content.active {
    display: block;
}

.mode-description {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.mode-description h3 {
    margin: 0;
    font-size: 20px;
    color: var(--text-primary);
}

.mode-description p {
    flex: 1;
    margin: 0;
    color: var(--text-secondary);
    min-width: 200px;
}

/* Navigation Flow */
.navigation-flow {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

.nav-section {
    text-align: center;
}

.nav-section h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--text-secondary);
}

.nav-arrow {
    font-size: 24px;
    color: var(--primary);
    align-self: center;
    margin-top: 20px;
}

.nav-hint {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
}

/* OLED Frame */
.oled-frame {
    background: #1a1a1a;
    border-radius: 8px;
    padding: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: inline-block;
}

.oled-frame.small {
    transform: scale(0.9);
    transform-origin: top center;
}

.oled-frame.emergency {
    box-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
}

.oled-frame.warning {
    box-shadow: 0 0 20px rgba(244, 180, 0, 0.5);
}

.oled-screen {
    background: #000;
    border-radius: 4px;
    padding: 8px 10px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.5;
    width: 200px;
    min-height: 90px;
    color: #fff;
}

.oled-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
}

.oled-divider {
    height: 1px;
    background: #fff;
    margin: 4px 0;
}

.oled-row.oled-big {
    font-size: 14px;
    font-weight: bold;
    justify-content: center;
    padding: 4px 0;
}

.oled-row.oled-small {
    font-size: 10px;
    justify-content: center;
    color: #888;
}

.oled-row.oled-selected {
    background: #fff;
    color: #000;
    margin: 0 -10px;
    padding: 2px 10px;
}

.oled-row.oled-center {
    justify-content: center;
}

.oled-row.oled-hint {
    font-size: 9px;
    color: #666;
    justify-content: center;
    margin-top: 4px;
}

.oled-row.oled-disabled {
    color: #444;
}

.oled-row.oled-bar {
    background: #000;
    height: 12px;
    border: 1px solid #fff;
    margin: 4px 0;
    padding: 0;
}

.oled-row.oled-bar .bar-fill {
    display: block;
    height: 100%;
    background: #fff;
}

.wifi-icon {
    font-family: Arial, sans-serif;
    font-size: 10px;
}

/* Submenu Grid */
.submenu-title {
    margin: 24px 0 16px 0;
    font-size: 16px;
    color: var(--text-primary);
}

.submenu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.submenu-item {
    text-align: center;
}

.submenu-item h5 {
    margin: 0 0 8px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.submenu-item .screen-desc {
    margin: 8px 0 0 0;
    font-size: 11px;
    color: var(--text-muted);
    max-width: 200px;
    line-height: 1.4;
}

/* Features Summary */
.mode-features-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-top: 16px;
}

.feature {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
}

.feature-yes {
    background: var(--success-light);
    color: var(--success);
}

.feature-no {
    background: #f0f0f0;
    color: #999;
    text-decoration: line-through;
}

/* Special Screens */
.special-screens {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.special-screens h4 {
    margin: 0 0 16px 0;
    font-size: 16px;
    color: var(--text-primary);
}

/* Mode Notes */
.mode-note {
    margin-top: 20px;
    padding: 12px 16px;
    background: var(--info-light);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.mode-note strong {
    color: var(--primary);
}

.mode-note-warning {
    background: var(--warning-light);
}

.mode-note-warning strong {
    color: var(--warning);
}

@media (max-width: 700px) {
    .navigation-flow {
        flex-direction: column;
        align-items: center;
    }
    .nav-arrow {
        transform: rotate(90deg);
        margin: 0;
    }
    .mode-description {
        flex-direction: column;
        text-align: center;
    }
}

/* ============================================================
   RTC Battery Status
   ============================================================ */

.rtc-battery-status {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    font-size: 13px;
}

.battery-age {
    color: var(--text-secondary);
}

.battery-warning {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--warning);
    font-weight: 500;
}

.battery-warning svg {
    fill: currentColor;
}

/* ============================================================
   History Date Navigation
   ============================================================ */

.history-date-nav {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: var(--radius);
}

.history-date-nav h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--text-primary);
}

.date-range-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.date-range-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-range-inputs label {
    font-size: 13px;
    color: var(--text-secondary);
}

.date-range-inputs input[type="date"] {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.date-quick-buttons {
    display: flex;
    gap: 6px;
}

.available-months {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.month-chip {
    padding: 6px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.month-chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Modal Medium Size */
.modal-content.modal-medium {
    max-width: 600px;
}

/* ============================================================
   Alert Tooltip Styles
   ============================================================ */

.device-alert-icon {
    position: relative;
}

.alert-tooltip {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 100;
    box-shadow: var(--shadow-md);
    margin-top: 8px;
}

.alert-tooltip::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: #333;
    border-top: none;
}

.device-alert-icon:hover .alert-tooltip {
    display: block;
}

.alert-line {
    padding: 2px 0;
}

.alert-line:not(:last-child) {
    border-bottom: 1px solid rgba(255,255,255,0.2);
}

/* ============================================================
   Config Hint Style
   ============================================================ */

.config-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 8px;
}

.esp-id {
    font-weight: 600;
    color: var(--primary);
}

/* ============================================================
   Timeline Chart Improvements
   ============================================================ */

.chart-timeline {
    min-height: 150px;
    cursor: grab;
}

.chart-timeline:active {
    cursor: grabbing;
}

.timeline-nav-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 8px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-top: 8px;
}

.timeline-nav-controls button {
    padding: 6px 16px;
}

.timeline-zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding: 8px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.zoom-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-right: 4px;
}

.timeline-help-text {
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 8px;
}


/* ============================================================
   Reboots Tooltip
   ============================================================ */

.stat-reboots {
    position: relative;
    cursor: pointer;
}

.stat-reboots:hover .stat-tooltip {
    display: block !important;
}

.stat-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 12px;
    min-width: 200px;
    z-index: 1000;
    margin-bottom: 8px;
}

.stat-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--bg-secondary);
}

.tooltip-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    gap: 12px;
}

.tooltip-row span:first-child {
    color: var(--text-secondary);
}

.tooltip-row span:last-child {
    font-weight: 500;
    color: var(--text-primary);
}


/* Device Reboot Info */
.device-reboot-info {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin: 0 12px 8px;
    background: var(--warning-light);
    border-radius: var(--radius-sm);
    font-size: 11px;
    color: var(--text-secondary);
}

.device-reboot-info svg {
    flex-shrink: 0;
    color: var(--warning);
}

/* Device Last Event */
.device-last-event {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin: 0 12px 8px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
    font-size: 11px;
    color: var(--text-secondary);
    border-left: 3px solid rgb(99, 102, 241);
}

.device-last-event svg {
    flex-shrink: 0;
    color: rgb(99, 102, 241);
}

/* Status item wide (para reinicios con info adicional) */
.status-item-wide {
    grid-column: span 2;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
}

.status-subtext {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
}

/* Tooltip para status items */
.status-item.has-tooltip {
    position: relative;
    cursor: pointer;
}

.status-item.has-tooltip:hover .status-tooltip {
    display: block !important;
}

.status-tooltip {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
    min-width: 280px;
    margin-top: 8px;
}

.status-tooltip::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 20px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid var(--border-color);
}

.status-tooltip::after {
    content: '';
    position: absolute;
    top: -6px;
    left: 21px;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 7px solid var(--bg-card);
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
}

.tooltip-label {
    color: var(--text-secondary);
}

.tooltip-value {
    font-weight: 600;
    color: var(--text-primary);
}

.tooltip-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

.tooltip-section-title {
    font-weight: 600;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Gap Legend for Temperature Chart */
.gap-legend {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
}

.gap-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.gap-legend-item .gap-color {
    width: 16px;
    height: 12px;
    border-radius: 2px;
}

/* ========================================
   TIMELINE ACCORDION - Eventos agrupados por día
   ======================================== */

.timeline-day-group {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    margin-bottom: 8px;
    overflow: hidden;
    background: var(--bg-card);
}

.timeline-day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
}

.timeline-day-header:hover {
    background: var(--bg-hover);
}

.timeline-day-header .day-date {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.timeline-day-header .day-summary {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.timeline-day-header .chevron {
    transition: transform 0.2s ease;
    color: var(--text-secondary);
    font-size: 12px;
}

.timeline-day-group.expanded .timeline-day-header .chevron {
    transform: rotate(180deg);
}

.timeline-day-events {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.timeline-day-group.expanded .timeline-day-events {
    max-height: 2000px;
}

.timeline-event-row {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    gap: 12px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    align-items: center;
    font-size: 13px;
}

.timeline-event-row:hover {
    background: var(--bg-hover);
}

.timeline-event-time {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 12px;
}

.timeline-event-type {
    display: flex;
    align-items: center;
    gap: 8px;
}

.timeline-event-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.timeline-event-icon.power-on {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.timeline-event-icon.power-off {
    background: rgba(107, 114, 128, 0.15);
    color: var(--text-secondary);
}

.timeline-event-icon.emergency {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.timeline-event-icon.config {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.timeline-event-icon.keepalive {
    background: rgba(156, 163, 175, 0.1);
    color: var(--text-tertiary);
}

.timeline-event-label {
    font-weight: 500;
    color: var(--text-primary);
}

.timeline-event-detail {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
}

.timeline-empty {
    padding: 40px;
    text-align: center;
    color: var(--text-secondary);
}

/* Badges para summary */
.timeline-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.timeline-badge.on {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.timeline-badge.off {
    background: rgba(107, 114, 128, 0.15);
    color: var(--text-secondary);
}

.timeline-badge.emergency {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.timeline-badge.config {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

/* ========================================
   PÁGINA DE ALERTAS - MEJORADA
   ======================================== */

/* Resumen de alertas */
.alerts-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 900px) {
    .alerts-summary {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 500px) {
    .alerts-summary {
        grid-template-columns: 1fr;
    }
}

.alert-summary-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid transparent;
}

.alert-summary-card.emergency {
    border-left-color: var(--danger);
}

.alert-summary-card.water {
    border-left-color: #3b82f6;
}

.alert-summary-card.manual {
    border-left-color: #f59e0b;
}

.alert-summary-card.offline {
    border-left-color: #6b7280;
}

.alert-summary-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
}

.alert-summary-card.emergency .alert-summary-icon {
    background: var(--danger-light);
    color: var(--danger);
}

.alert-summary-card.water .alert-summary-icon {
    background: #dbeafe;
    color: #3b82f6;
}

.alert-summary-card.manual .alert-summary-icon {
    background: #fef3c7;
    color: #f59e0b;
}

.alert-summary-card.offline .alert-summary-icon {
    background: #f3f4f6;
    color: #6b7280;
}

.alert-summary-info {
    display: flex;
    flex-direction: column;
}

.alert-summary-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.alert-summary-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Gráfico de alertas */
.alerts-chart-container {
    margin-bottom: 24px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    height: 340px;
    display: flex;
    flex-direction: column;
}

.alerts-chart-container h3 {
    margin: 0 0 12px 0;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
}

.alerts-chart-container canvas {
    flex: 1;
    min-height: 0;
    width: 100% !important;
    max-height: 100% !important;
}

/* Toolbar de alertas */
.alerts-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 16px;
}

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

.filter-checkbox {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.filter-checkbox input {
    display: none;
}

.filter-tag {
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
    border: 2px solid transparent;
    opacity: 0.5;
    transition: all 0.2s;
}

.filter-checkbox input:checked + .filter-tag {
    opacity: 1;
}

.filter-tag.emergency {
    background: var(--danger-light);
    color: var(--danger);
    border-color: var(--danger);
}

.filter-tag.water {
    background: #dbeafe;
    color: #3b82f6;
    border-color: #3b82f6;
}

.filter-tag.manual {
    background: #fef3c7;
    color: #f59e0b;
    border-color: #f59e0b;
}

.filter-tag.offline {
    background: #f3f4f6;
    color: #6b7280;
    border-color: #6b7280;
}

/* Lista de alertas mejorada */
.alerts-list-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.alerts-list-container h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.count-label {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-muted);
}

/* ========================================
   PÁGINA DE ESTADÍSTICAS - MEJORADA
   ======================================== */

/* Grid de 6 tarjetas */
.stats-grid-6 {
    grid-template-columns: repeat(6, 1fr);
}

@media (max-width: 1200px) {
    .stats-grid-6 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 700px) {
    .stats-grid-6 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.stat-icon.primary {
    color: var(--primary);
    background: var(--primary-light);
}

/* Grid de gráficos de estadísticas */
.stats-charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.stats-charts-grid .chart-container {
    min-height: 300px;
}

.stats-charts-grid .chart-container canvas {
    max-height: 280px;
}

@media (max-width: 900px) {
    .stats-charts-grid {
        grid-template-columns: 1fr;
    }
}

/* Ranking de dispositivos */
.stats-ranking-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 24px;
}

.stats-ranking-container h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
}

.ranking-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.ranking-tab {
    padding: 8px 16px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.ranking-tab:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.ranking-tab.active {
    background: var(--primary-light);
    color: var(--primary);
}

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.ranking-position {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-muted);
}

.ranking-item:nth-child(1) .ranking-position {
    background: #ffd700;
    color: #fff;
}

.ranking-item:nth-child(2) .ranking-position {
    background: #c0c0c0;
    color: #fff;
}

.ranking-item:nth-child(3) .ranking-position {
    background: #cd7f32;
    color: #fff;
}

.ranking-device {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ranking-device-name {
    font-weight: 500;
    color: var(--text-primary);
}

.ranking-device-location {
    font-size: 12px;
    color: var(--text-muted);
}

.ranking-value {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
}

.ranking-bar {
    width: 100px;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.ranking-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
}

/* Botón Guardar Todo */
.btn-save-all {
    transition: background 0.2s ease, color 0.2s ease;
}
/* Task #139: estados visuales del botón Guardar.
   - btn-save-active = hay cambios sin guardar (azul, animado, llamativo)
   - btn-save-clean = todo guardado (verde tenue, sin animación)
   El botón ahora SIEMPRE se ve, incluso sin cambios — al hacer click igual
   ejecuta saveAllChanges() forzando el guardado de TODO. Esto evita que
   un detector de cambios roto haga que la data se pierda silenciosamente. */
.btn-save-all.btn-save-active,
.btn-save-fab.btn-save-active {
    animation: pulse-save 2s infinite;
    background: #0274be;
    color: #fff;
}
.btn-save-all.btn-save-clean {
    background: rgba(76, 175, 80, 0.12);
    color: #4caf50;
    border: 1px solid rgba(76, 175, 80, 0.3);
}
.btn-save-all.btn-save-clean:hover {
    background: rgba(76, 175, 80, 0.22);
    color: #2e7d32;
}
.btn-save-fab.btn-save-clean {
    background: #4caf50 !important;
    box-shadow: 0 4px 14px rgba(76, 175, 80, 0.45),
                0 2px 6px rgba(0, 0, 0, 0.18) !important;
    animation: none;
}
.btn-save-fab.btn-save-clean:hover {
    background: #43a047 !important;
}

@keyframes pulse-save {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(2, 116, 190, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(2, 116, 190, 0);
    }
}

.btn-save-all svg {
    margin-right: 4px;
}

/* ========================================================================
   Secciones colapsables — Task #134, items 3 y 10
   ========================================================================
   Patrón: <div class="detail-section collapsible-section [collapsed]" id="...">
              <h3 class="collapsible-h3" onclick="toggleSection(id)">
                  <span class="collapse-caret">▸</span>  texto
              </h3>
              <div>...contenido...</div>  <-- cualquier sibling del h3
           </div>
   El JS toggleSection() agrega/quita .collapsed al section. El CSS oculta
   todos los siblings del h3 cuando .collapsed está presente. El caret rota.
   ======================================================================== */
.collapsible-h3 {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease, color 0.15s ease;
    border-radius: 6px;
    padding: 4px 8px;
    margin-left: -8px;
    margin-right: -8px;
}
.collapsible-h3:hover {
    color: var(--accent, #0d92e0);
    background: rgba(13, 146, 224, 0.08);
}
/* Caret visualmente prominente: chip pequeño con flecha. Apunta a la
   derecha (▶) cuando colapsado, a abajo (▼) cuando expandido. Más obvio
   visualmente que el ▸ chiquito anterior. — Task #136 (7-mayo-2026). */
.collapse-caret {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin-right: 8px;
    border-radius: 4px;
    background: rgba(13, 146, 224, 0.18);
    color: #0d92e0;
    font-size: 12px;
    font-weight: 700;
    transition: transform 0.22s ease, background 0.15s ease;
    line-height: 1;
    vertical-align: middle;
}
.collapsible-h3:hover .collapse-caret {
    background: rgba(13, 146, 224, 0.32);
}
.collapsible-section:not(.collapsed) .collapse-caret {
    transform: rotate(90deg);
}
/* Ocultar todos los hijos directos excepto el h3 cuando está colapsado */
.collapsible-section.collapsed > *:not(h3):not(.collapsible-h3) {
    display: none !important;
}
/* Indicador "Click para abrir/cerrar" cuando colapsada (texto pequeño
   al final del h3). Solo visible en colapsada para no estorbar abierta. */
.collapsible-section.collapsed .collapsible-h3::after {
    content: "click para abrir";
    font-size: 11px;
    font-weight: 400;
    color: #888;
    margin-left: 10px;
    font-style: italic;
}
.collapsible-section:not(.collapsed) .collapsible-h3::after {
    content: "click para cerrar";
    font-size: 11px;
    font-weight: 400;
    color: #aaa;
    margin-left: 10px;
    font-style: italic;
}

/* ========================================================================
   FAB Guardar (flotante, móvil) — Task #134, item B
   ========================================================================
   En móvil el botón "Guardar configuración" del header queda fuera de
   pantalla mientras el usuario scrollea las secciones del modal. Este FAB
   se muestra cuando hay cambios pendientes (display lo activa via JS) y
   dispara la misma función. En desktop (>=900px) queda oculto para no
   duplicar la UI con el botón del header.
   ======================================================================== */
.btn-save-fab {
    position: fixed;
    bottom: 22px;
    right: 22px;
    z-index: 9999;
    background: linear-gradient(135deg, #0274be 0%, #0d92e0 100%);
    color: #fff;
    border: none;
    border-radius: 30px;
    padding: 14px 22px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(2, 116, 190, 0.45),
                0 2px 6px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    display: none;
    align-items: center;
    gap: 8px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    animation: fab-pulse 2.4s infinite;
}
.btn-save-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(2, 116, 190, 0.55),
                0 3px 9px rgba(0, 0, 0, 0.22);
}
.btn-save-fab:active {
    transform: translateY(0);
}
.btn-save-fab.visible {
    display: inline-flex;
}
.btn-save-fab svg {
    flex-shrink: 0;
}
.btn-save-fab .fab-label {
    line-height: 1;
}
@keyframes fab-pulse {
    0%, 100% {
        box-shadow: 0 4px 14px rgba(2, 116, 190, 0.45),
                    0 2px 6px rgba(0, 0, 0, 0.18),
                    0 0 0 0 rgba(13, 146, 224, 0.45);
    }
    50% {
        box-shadow: 0 4px 14px rgba(2, 116, 190, 0.45),
                    0 2px 6px rgba(0, 0, 0, 0.18),
                    0 0 0 12px rgba(13, 146, 224, 0);
    }
}
/* Desktop: ocultar el FAB porque el botón del header ya está visible. */
@media (min-width: 900px) {
    .btn-save-fab,
    .btn-save-fab.visible {
        display: none !important;
    }
}
@media (max-width: 480px) {
    .btn-save-fab {
        bottom: 16px;
        right: 16px;
        padding: 12px 18px;
        font-size: 14px;
    }
}

/* Empty state pequeño */
.empty-state-small {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ============================================================
   PAGES ADMIN
   ============================================================ */
.pages-admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.pages-admin-header h2 {
    margin: 0;
    font-size: 20px;
}
.pages-description {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
}
.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.page-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    transition: box-shadow 0.2s;
}
.page-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.page-card.page-inactive {
    opacity: 0.6;
}
.page-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.page-card-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.page-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
}
.page-status.status-active {
    background: #e8f5e9;
    color: #2e7d32;
}
.page-status.status-inactive {
    background: #fbe9e7;
    color: #c62828;
}
.page-card-url {
    margin-bottom: 6px;
}
.page-card-url a {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
    font-family: monospace;
}
.page-card-url a:hover {
    text-decoration: underline;
}
.page-card-desc {
    color: var(--text-secondary);
    font-size: 12px;
    margin: 4px 0 8px;
}
.page-card-stats {
    margin-bottom: 10px;
}
.page-device-count {
    font-size: 13px;
    color: var(--text-secondary);
    background: #f1f3f4;
    padding: 2px 8px;
    border-radius: 8px;
}
.page-card-actions {
    display: flex;
    gap: 8px;
}
.page-device-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    font-size: 13px;
    cursor: pointer;
}
.page-device-checkbox:hover {
    background: #f1f3f4;
    border-radius: 6px;
}
.sensor-status-row {
    display: flex;
    align-items: center;
    padding: 6px 0;
    font-size: 13px;
}
.empty-state, .error-state {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ============================================================
   TANK VIEW STYLES
   ============================================================ */

#tank-view {
    display: none;
}

.tank-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 0 0 30px 0;
    padding: 20px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 12px;
}

.tank-stat-card {
    background: white;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.tank-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.tank-stat-value {
    font-size: 36px;
    font-weight: bold;
    color: #2196F3;
    margin-bottom: 8px;
}

.tank-stat-label {
    font-size: 13px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.tank-sensor-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f5f5f5;
    border-radius: 6px;
    margin-top: 8px;
}

.tank-sensor-indicator .sensor-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #999;
    flex-shrink: 0;
}

.tank-sensor-indicator .sensor-status {
    font-size: 13px;
    font-weight: 600;
    color: #666;
}

.tank-config-row {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid #eee;
}

.tank-config-row:last-child {
    border-bottom: none;
}

.tank-config-row label {
    flex: 0 0 auto;
    font-weight: 500;
    color: #333;
}

.tank-history-table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #ddd;
}

.tank-history-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 13px;
}

.tank-history-table thead {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-bottom: 2px solid #2196F3;
}

.tank-history-table th {
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

.tank-history-table td {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    color: #666;
}

.tank-history-table tbody tr:hover {
    background: #f9f9f9;
}

.tank-history-table tbody tr:last-child td {
    border-bottom: none;
}

/* ============================================================
   MOBILE RESPONSIVE - Task #67 (22-abril-2026)
   Corrige ancho excesivo en celular y adapta layout completo
   ============================================================ */

/* Prevenir overflow horizontal global */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Tablet (≤ 900px): ajustes intermedios */
@media (max-width: 900px) {
    .alerts-chart-container {
        height: 300px;
        padding: 16px;
    }

    .device-category-tabs {
        width: 100%;
        justify-content: stretch;
    }

    .device-category-tabs .cat-tab {
        flex: 1;
        justify-content: center;
    }

    .toolbar {
        padding: 14px;
        gap: 12px;
    }

    .devices-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 16px;
    }
}

/* Mobile (≤ 768px): layout apilado compacto */
@media (max-width: 768px) {
    :root {
        --header-height: 56px;
        --nav-height: 56px;
    }

    /* Header: logo + badge + refresh button compactos */
    .header {
        padding: 0 12px !important;
        height: 56px !important;
        gap: 8px;
    }

    .header-left {
        gap: 8px;
        min-width: 0;
        flex-shrink: 1;
    }

    .header h1 {
        display: none;
    }

    .logo {
        height: 32px;
    }

    .header-right {
        gap: 8px;
        flex-shrink: 0;
    }

    .time {
        display: none;
    }

    .refresh-countdown {
        font-size: 11px;
        padding: 3px 6px;
        min-width: 30px;
    }

    #online-count {
        font-size: 10px;
        padding: 3px 8px;
    }

    /* Tabs: scroll horizontal suave, sin saltar líneas */
    .nav-tabs {
        padding: 0 8px !important;
        gap: 4px;
        height: 56px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        padding: 8px 12px;
        font-size: 13px;
        flex-shrink: 0;
        white-space: nowrap;
    }

    .tab svg {
        width: 16px;
        height: 16px;
    }

    /* Main content compacto */
    .main-content {
        padding: 12px !important;
        margin-top: 112px !important;
    }

    /* Sub-tabs ultrasonido / especiales: ocupan ancho completo */
    .device-category-tabs {
        width: 100%;
        padding: 4px;
    }

    .cat-tab {
        padding: 8px 10px;
        font-size: 13px;
    }

    /* Toolbar: stack vertical */
    .toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
        margin-bottom: 16px;
        gap: 10px;
    }

    .search-box,
    .search-box input {
        width: 100%;
    }

    .filter-buttons {
        justify-content: center;
        flex-wrap: wrap;
    }

    #btn-add-device {
        width: 100%;
        justify-content: center;
    }

    /* Devices grid: 1 columna */
    .devices-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .device-card {
        padding: 16px;
    }

    .device-card-header {
        padding-left: 8px;
        margin-bottom: 14px;
    }

    .device-id {
        font-size: 16px;
    }

    /* Modal: pantalla completa */
    .modal {
        padding: 0 !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    .modal-header {
        padding: 12px 16px !important;
        position: sticky;
        top: 0;
        background: var(--bg-secondary);
        z-index: 10;
    }

    .modal-header h2 {
        font-size: 18px;
    }

    .modal-body {
        padding: 16px !important;
    }

    /* Alertas: chart más corto en móvil */
    .alerts-chart-container {
        height: 260px;
        padding: 12px;
        margin-bottom: 16px;
    }

    .alerts-chart-container h3 {
        font-size: 14px;
    }

    .alerts-summary {
        gap: 10px;
        margin-bottom: 16px;
    }

    .alert-summary-card {
        padding: 14px;
        gap: 12px;
    }

    .alert-summary-icon {
        width: 40px;
        height: 40px;
    }

    .alert-summary-value {
        font-size: 22px;
    }

    .alerts-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
    }

    .alerts-filters {
        gap: 8px;
        justify-content: center;
    }

    .filter-tag {
        padding: 5px 10px;
        font-size: 11px;
    }

    /* Stats tab */
    .stats-grid-6 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
        gap: 10px;
    }

    .stat-value {
        font-size: 22px;
    }

    .stat-icon svg {
        width: 24px;
        height: 24px;
    }

    .stats-charts-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .stats-charts-grid .chart-container {
        min-height: 260px;
        padding: 12px;
    }

    /* Chart containers genéricos */
    .chart-container {
        max-width: 100%;
        overflow: hidden;
    }

    .chart-container canvas {
        max-width: 100% !important;
    }

    /* Tablas con scroll horizontal seguro */
    .tank-history-table-wrapper,
    .history-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -12px;
        padding: 0 12px;
    }

    /* Alert pending devices */
    .pending-alert {
        padding: 12px !important;
        font-size: 13px;
    }

    /* History modal stats buttons */
    .history-stats-buttons {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    .stat-btn {
        padding: 12px;
        gap: 8px;
    }

    /* Config/form rows: todo apilado */
    .form-row,
    .config-row,
    .info-row,
    .control-monitor-row,
    .status-grid,
    .stats-compact,
    .control-buttons-grid,
    .client-form .form-row {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    /* Botones toolbar wifi/logs */
    .tank-config-row {
        flex-wrap: wrap;
        gap: 10px;
    }

    /* Evitar texto cortado en badges/selects */
    .select, select {
        max-width: 100%;
    }
}

/* Mobile pequeño (≤ 480px): ajustes extremos */
@media (max-width: 480px) {
    .main-content {
        padding: 10px !important;
    }

    .tab {
        padding: 7px 10px;
        font-size: 12px;
    }

    .tab svg {
        width: 14px;
        height: 14px;
    }

    .cat-tab {
        padding: 7px 8px;
        font-size: 12px;
    }

    .cat-count {
        min-width: 18px;
        padding: 1px 6px;
        font-size: 10px;
    }

    .device-card {
        padding: 14px;
    }

    .alerts-chart-container {
        height: 220px;
    }

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

    .alert-summary-card {
        padding: 12px;
        gap: 10px;
    }

    .alert-summary-value {
        font-size: 20px;
    }

    .alert-summary-label {
        font-size: 11px;
    }

    .alert-summary-icon {
        width: 36px;
        height: 36px;
    }

    .alert-summary-icon svg {
        width: 20px;
        height: 20px;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-label {
        font-size: 11px;
    }

    /* Modal más compacto */
    .modal-header h2 {
        font-size: 16px;
    }

    .modal-body {
        padding: 12px !important;
    }

    /* Botones más pequeños */
    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }

    .btn-sm {
        padding: 5px 12px;
        font-size: 12px;
    }
}

/* Landscape móvil: el chart no debe ser tan alto */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .alerts-chart-container {
        height: 220px;
    }

    .main-content {
        margin-top: 100px !important;
    }
}

/* ════════════════════════════════════════════════════════════════
   Check de monitoreo por equipo (pedido de JP, 2026-08-03)
   Marcado  = si el equipo se cae, avisa por Telegram cada 15 min.
   Sin marcar = no avisa, y el correo diario lo muestra con su motivo.
   ════════════════════════════════════════════════════════════════ */
.device-monitor {
    display: flex; align-items: center; gap: 7px;
    margin: 0 14px 12px; padding: 7px 10px;
    border-radius: 8px; font-size: 12px; cursor: pointer;
    border: 1px solid transparent; user-select: none;
    transition: background .15s ease, border-color .15s ease;
}
.device-monitor input { margin: 0; cursor: pointer; width: 15px; height: 15px; accent-color: #1E8449; }
.device-monitor.on  { background: #eaf6ef; color: #186b3c; border-color: #cfe8da; }
.device-monitor.off { background: #fdf3e3; color: #8a6116; border-color: #f0dfc0; }
.device-monitor.off input { accent-color: #B9770E; }
.device-monitor:hover { filter: brightness(.97); }
