/* CMTS&S Control - Estilos Personalizados */

/* Variables CSS */
:root {
    --cmtss-primary: #2185d0;
    --cmtss-primary-dark: #1a6fb3;
    --cmtss-success: #21ba45;
    --cmtss-warning: #fbbd08;
    --cmtss-danger: #db2828;
    --cmtss-info: #31ccec;
    --cmtss-dark: #1b1c1d;
    --cmtss-light: #f9fafb;
    --cmtss-border: #e0e0e0;
}

/* Base font size - scales all rem values on mobile */
html {
    font-size: 16px;
}

@media (max-width: 768px) {
    html {
        font-size: 18px;
    }
}

/* Dashboard Layout */
.cmtss-dashboard {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 100vh;
}

.cmtss-dashboard.sidebar-visible {
    grid-template-columns: 250px 1fr;
}

.cmtss-sidebar {
    background: var(--cmtss-dark);
    color: white;
    padding: 0;
    position: relative;
    transition: width 0.3s ease;
    overflow-y: auto;
    display: none;
}

.cmtss-sidebar.open {
    display: block;
}

.cmtss-sidebar .ui.inverted.menu {
    width: 100%;
}

.cmtss-sidebar .item {
    padding: 0.85rem 1.5rem !important;
    border-radius: 0 !important;
    margin: 0 !important;
    transition: all 0.3s ease;
    border-left: 3px solid transparent !important;
    position: relative;
}

.cmtss-sidebar .item .icon {
    transition: all 0.3s ease;
}

.cmtss-sidebar .item:hover {
    background: rgba(255,255,255,0.08) !important;
    padding-left: 1.8rem !important;
}

/* Item activo base */
.cmtss-sidebar .item.active {
    color: #fff !important;
    font-weight: 600;
}

/* ===== Color SOLO en item activo (nth-child) ===== */
/* El item clickeado cambia de color para indicar dónde está el usuario */

/* Dashboard - Azul */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(1).active {
    background: rgba(33,133,208,0.3) !important;
    border-left: 4px solid #2185d0 !important;
    color: #5bb7ff !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(1).active > i.icon {
    color: #5bb7ff !important;
}

/* Control Remoto - Verde */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(2).active {
    background: rgba(33,186,69,0.3) !important;
    border-left: 4px solid #21ba45 !important;
    color: #5dff7e !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(2).active > i.icon {
    color: #5dff7e !important;
}

/* Protocolos - Cian */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(3).active {
    background: rgba(0,181,204,0.3) !important;
    border-left: 4px solid #00b5cc !important;
    color: #4de8ff !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(3).active > i.icon {
    color: #4de8ff !important;
}

/* Alarmas - Rojo */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(4).active {
    background: rgba(219,40,40,0.3) !important;
    border-left: 4px solid #db2828 !important;
    color: #ff6b6b !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(4).active > i.icon {
    color: #ff6b6b !important;
}

/* Sensores - Naranja */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(5).active {
    background: rgba(242,113,28,0.3) !important;
    border-left: 4px solid #f2711c !important;
    color: #ffab5e !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(5).active > i.icon {
    color: #ffab5e !important;
}

/* Asistencia - Violeta */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(6).active {
    background: rgba(100,53,201,0.3) !important;
    border-left: 4px solid #6435c9 !important;
    color: #a78bfa !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(6).active > i.icon {
    color: #a78bfa !important;
}

/* Reportes - Teal */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(7).active {
    background: rgba(0,135,126,0.3) !important;
    border-left: 4px solid #00877e !important;
    color: #4dd9cd !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(7).active > i.icon {
    color: #4dd9cd !important;
}

/* Administracion - Gris azulado */
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(8).active {
    background: rgba(118,142,161,0.3) !important;
    border-left: 4px solid #768ea1 !important;
    color: #b0c4d4 !important;
}
.cmtss-sidebar .ui.inverted.menu > a.item:nth-child(8).active > i.icon {
    color: #b0c4d4 !important;
}

.cmtss-main {
    padding: 0;
    background: var(--cmtss-light);
    overflow-y: auto;
    max-height: 100vh;
}

/* Header */
.cmtss-header {
    background: white;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--cmtss-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Tarjetas de Sensores */
.sensor-card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.sensor-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.sensor-card.alarm-active {
    border-left: 4px solid var(--cmtss-danger);
    animation: pulse-alarm 2s infinite;
}

@keyframes pulse-alarm {
    0%, 100% { background-color: white; }
    50% { background-color: rgba(219, 40, 40, 0.05); }
}

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

.sensor-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--cmtss-dark);
}

.sensor-value.critical {
    color: var(--cmtss-danger);
}

.sensor-value.warning {
    color: var(--cmtss-warning);
}

.sensor-value.normal {
    color: var(--cmtss-success);
}

.sensor-unit {
    font-size: 1.2rem;
    color: #666;
    margin-left: 0.25rem;
}

/* Panel de Alarmas */
.alarm-panel {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.alarm-item {
    padding: 1rem;
    border-bottom: 1px solid var(--cmtss-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: background 0.2s;
}

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

.alarm-item:hover {
    background: rgba(0,0,0,0.02);
}

.alarm-item.critical {
    background: linear-gradient(90deg, rgba(219, 40, 40, 0.1) 0%, transparent 100%);
}

.alarm-item.warning {
    background: linear-gradient(90deg, rgba(251, 189, 8, 0.1) 0%, transparent 100%);
}

.alarm-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.alarm-icon.critical {
    background: var(--cmtss-danger);
    color: white;
}

.alarm-icon.warning {
    background: var(--cmtss-warning);
    color: white;
}

/* Graficas */
.chart-container {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--cmtss-border);
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Status Indicators */
.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-indicator.online,
.status-indicator.normal {
    background: var(--cmtss-success);
    box-shadow: 0 0 8px var(--cmtss-success);
}

.status-indicator.offline,
.status-indicator.disabled {
    background: #999;
}

.status-indicator.alarm,
.status-indicator.critical {
    background: var(--cmtss-danger);
    animation: blink 1s infinite;
}

.status-indicator.warning {
    background: var(--cmtss-warning);
    animation: blink 2s infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Grid de Sensores */
.sensors-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* Facility View */
.facility-header {
    background: linear-gradient(135deg, var(--cmtss-primary) 0%, var(--cmtss-primary-dark) 100%);
    color: white;
    padding: 2rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.facility-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}

.facility-stat {
    text-align: center;
}

.facility-stat-value {
    font-size: 1.8rem;
    font-weight: bold;
}

.facility-stat-label {
    font-size: 0.85rem;
    opacity: 0.8;
}

/* Login */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1b1c1d 0%, #2185d0 100%);
}

.login-box {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo h1 {
    color: var(--cmtss-primary);
    margin: 0;
    font-size: 2.5rem;
}

.login-logo p {
    color: #666;
    margin: 0.5rem 0 0;
}

/* Reports */
.report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.report-filters {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Cards UI */
.ui.card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.ui.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
}

/* Toast notification animation */
.toast-enter {
    opacity: 0;
    transform: translateX(100%);
}

.toast-active {
    opacity: 1;
    transform: translateX(0);
    transition: opacity 0.3s, transform 0.3s;
}

/* WebSocket connection indicator */
.ws-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.ws-indicator.connected {
    background: rgba(33, 186, 69, 0.1);
    color: var(--cmtss-success);
}

.ws-indicator.disconnected {
    background: rgba(219, 40, 40, 0.1);
    color: var(--cmtss-danger);
}

/* Scrollbar personalizada */
.cmtss-main::-webkit-scrollbar,
.alarm-panel::-webkit-scrollbar {
    width: 6px;
}

.cmtss-main::-webkit-scrollbar-track,
.alarm-panel::-webkit-scrollbar-track {
    background: transparent;
}

.cmtss-main::-webkit-scrollbar-thumb,
.alarm-panel::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.cmtss-main::-webkit-scrollbar-thumb:hover,
.alarm-panel::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* Tablas con scroll horizontal en mobile */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Admin tabs */
.admin-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--cmtss-border);
    margin-bottom: 1.5rem;
}

.admin-tab {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    border: none;
    background: transparent;
    color: #666;
    font-size: 1rem;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.admin-tab:hover {
    color: var(--cmtss-primary);
}

.admin-tab.active {
    color: var(--cmtss-primary);
    border-bottom-color: var(--cmtss-primary);
    font-weight: bold;
}

/* ============================================================ */
/* Responsive */
/* ============================================================ */

@media (max-width: 1024px) {
    .cmtss-dashboard {
        grid-template-columns: 220px 1fr;
    }
}

/* Overlay oculto por defecto en desktop */
.sidebar-overlay {
    display: none;
}

@media (max-width: 768px) {
    .cmtss-dashboard {
        grid-template-columns: 1fr !important;
    }

    .cmtss-sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        width: 250px;
        z-index: 1000;
        transition: left 0.3s ease;
        display: block !important;
    }

    .cmtss-sidebar.open {
        left: 0;
    }

    /* Overlay para sidebar mobile */
    .sidebar-overlay.visible {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }

    .cmtss-main {
        grid-column: 1 !important;
    }

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

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

    .facility-header {
        padding: 1.5rem;
    }

    /* Dashboard grid responsive */
    div[style*="gridTemplateColumns: \"2fr 1fr\""],
    div[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    div[style*="gridTemplateColumns: \"1fr 1fr\""],
    div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Filtros en columna en mobile */
    .ui.form .fields {
        flex-direction: column;
    }

    .ui.form .fields .field {
        width: 100% !important;
        margin-bottom: 0.5rem !important;
    }

    /* Estadisticas responsivas */
    .ui.three.statistics {
        flex-wrap: wrap;
    }

    .ui.three.statistics .statistic {
        width: 33% !important;
        margin-bottom: 1rem;
    }

    /* Tablas responsivas */
    .ui.table:not(.unstackable) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Ocultar thead en tablas stackable en mobile */
    .ui.stackable.table thead {
        display: none !important;
    }

    /* Cards de equipos en stackable table */
    .ui.stackable.table tbody tr {
        border: 1px solid #e0e0e0 !important;
        border-radius: 8px !important;
        margin-bottom: 0.75rem !important;
        padding: 0.75rem !important;
        display: block !important;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    }

    .ui.stackable.table tbody td {
        display: block !important;
        border: none !important;
        padding: 0.2rem 0 !important;
        text-align: left !important;
    }

    .ui.stackable.table tbody td:last-child {
        text-align: center !important;
        padding-top: 0.5rem !important;
        border-top: 1px solid #f0f0f0 !important;
        margin-top: 0.25rem;
    }

    /* Header responsive */
    .cmtss-header {
        padding: 0.5rem 1rem;
    }

    .cmtss-header h3 {
        font-size: 1rem;
    }

    /* Modal responsive */
    div[style*="maxWidth: \"600px\""] {
        max-width: 95vw !important;
    }
}

@media (max-width: 480px) {
    .ui.three.statistics .statistic {
        width: 100% !important;
    }

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

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

    .login-box {
        margin: 1rem;
        padding: 1.5rem;
    }
}

/* ============================================================ */
/* Print - Life Sheet                                           */
/* ============================================================ */

@media screen {
    .print-life-sheet {
        display: none !important;
    }
}

@media print {
    body > * {
        display: none !important;
    }
    .print-life-sheet {
        display: block !important;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        background: #fff;
        color: #000;
        font-size: 12pt;
        padding: 1cm;
        z-index: 99999;
    }
    .print-life-sheet table {
        page-break-inside: auto;
    }
    .print-life-sheet tr {
        page-break-inside: avoid;
    }
}
