:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --dark-color: #34495e;
    --light-color: #ecf0f1;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
}

.header {
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 20px;
    margin-bottom: 25px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.header h1 {
    color: var(--primary-color);
    margin-bottom: 10px;
    font-size: 2.8em;
    font-weight: 700;
    text-align: center;
}

.header p {
    color: #7f8c8d;
    font-size: 1.3em;
    text-align: center;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255,255,255,0.9);
    padding: 15px 25px;
    border-radius: 15px;
    margin-bottom: 25px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.online { background: var(--success-color); }
.offline { background: var(--danger-color); }

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 25px;
    margin-bottom: 25px;
}

.card {
    background: rgba(255, 255, 255, 0.95);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--danger-color), var(--warning-color), var(--success-color));
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

.fase-card {
    border-left: 6px solid;
}

.fase1 { border-left-color: var(--danger-color); }
.fase2 { border-left-color: var(--success-color); }
.fase3 { border-left-color: var(--warning-color); }
.total-card { border-left-color: var(--secondary-color); background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); }

.card h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
    font-size: 1.5em;
    display: flex;
    align-items: center;
    gap: 10px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.metric {
    text-align: center;
    padding: 15px;
    background: rgba(255,255,255,0.7);
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.05);
}

.metric-value {
    font-size: 1.8em;
    font-weight: bold;
    color: var(--primary-color);
    margin: 5px 0;
}

.metric-label {
    font-size: 0.9em;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-unit {
    font-size: 0.7em;
    color: #95a5a6;
}

.estado {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 0.9em;
    font-weight: bold;
    margin-top: 15px;
}

.activo { background: var(--success-color); color: white; }
.inactivo { background: #bdc3c7; color: #2c3e50; }
.carga-activa { background: var(--warning-color); color: white; animation: glow 2s infinite; }

@keyframes glow {
    0% { box-shadow: 0 0 5px var(--warning-color); }
    50% { box-shadow: 0 0 20px var(--warning-color); }
    100% { box-shadow: 0 0 5px var(--warning-color); }
}

.chart-container {
    background: rgba(255, 255, 255, 0.95);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    backdrop-filter: blur(10px);
    margin-bottom: 25px;
    height: 400px;
}

.chart-title {
    text-align: center;
    margin-bottom: 25px;
    color: var(--primary-color);
    font-size: 1.6em;
    font-weight: 600;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    background: var(--secondary-color);
    color: white;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(52, 152, 219, 0.4);
}

.btn.active {
    background: var(--primary-color);
    box-shadow: 0 5px 15px rgba(44, 62, 80, 0.3);
}

.btn-danger { background: var(--danger-color); box-shadow: 0 5px 15px rgba(231, 76, 60, 0.3); }
.btn-success { background: var(--success-color); box-shadow: 0 5px 15px rgba(39, 174, 96, 0.3); }
.btn-warning { background: var(--warning-color); box-shadow: 0 5px 15px rgba(243, 156, 18, 0.3); }

.vista {
    display: none;
}

.vista.active {
    display: block;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.last-update {
    text-align: center;
    color: white;
    margin-top: 30px;
    font-size: 0.95em;
    background: rgba(255,255,255,0.1);
    padding: 15px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.stat-card {
    background: rgba(255,255,255,0.9);
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.stat-value {
    font-size: 2.5em;
    font-weight: bold;
    color: var(--primary-color);
    margin: 10px 0;
}

.stat-label {
    color: #7f8c8d;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Estilos para la tabla histórica */
.table-container {
    overflow-x: auto;
    margin: 20px 0;
    border-radius: 10px;
    border: 1px solid rgba(0,0,0,0.1);
}

#tabla-historica {
    width: 100%;
    border-collapse: collapse;
    min-width: 1200px;
}

#tabla-historica th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 15px;
    text-align: center;
    font-weight: 600;
    font-size: 0.9em;
    position: sticky;
    top: 0;
    cursor: pointer;
    user-select: none;
}

#tabla-historica th:hover {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
}

#tabla-historica th i {
    margin-left: 5px;
    font-size: 0.8em;
}

#tabla-historica td {
    padding: 12px 15px;
    text-align: center;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    font-size: 0.9em;
}

#tabla-historica tbody tr:nth-child(even) {
    background-color: rgba(0,0,0,0.02);
}

#tabla-historica tbody tr:hover {
    background-color: rgba(52, 152, 219, 0.1);
    transition: background-color 0.3s ease;
}

#tabla-historica tbody tr.highlight {
    background-color: rgba(243, 156, 18, 0.1);
    border-left: 3px solid var(--warning-color);
}

.table-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.search-box {
    position: relative;
    flex-grow: 1;
    max-width: 400px;
}

.search-box input {
    width: 100%;
    padding: 12px 40px 12px 15px;
    border: 2px solid rgba(52, 152, 219, 0.3);
    border-radius: 8px;
    font-size: 0.95em;
    transition: all 0.3s ease;
}

.search-box input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.search-box i {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #95a5a6;
}

.table-info {
    font-size: 0.9em;
    color: #7f8c8d;
    font-weight: 500;
}

.table-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(0,0,0,0.1);
    flex-wrap: wrap;
    gap: 15px;
}

.pagination {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-pagination {
    padding: 10px 20px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.3s ease;
}

.btn-pagination:hover:not(:disabled) {
    background: #2980b9;
    transform: translateY(-2px);
}

.btn-pagination:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    opacity: 0.6;
}

#pagina-actual {
    font-weight: 600;
    color: var(--primary-color);
}

.items-per-page {
    display: flex;
    align-items: center;
    gap: 10px;
}

.items-per-page label {
    font-size: 0.9em;
    color: #7f8c8d;
}

.items-per-page select {
    padding: 8px 15px;
    border: 2px solid rgba(52, 152, 219, 0.3);
    border-radius: 6px;
    background: white;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
}

.items-per-page select:focus {
    outline: none;
    border-color: var(--secondary-color);
}

/* Estilos para valores específicos en la tabla */
.valor-bajo { color: #27ae60; }
.valor-medio { color: #f39c12; }
.valor-alto { color: #e74c3c; }
.valor-costo { 
    font-weight: 600; 
    color: #9b59b6;
    background: rgba(155, 89, 182, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Responsive */
@media (max-width: 768px) {
    .grid {
        grid-template-columns: 1fr;
    }
    
    .metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .header h1 {
        font-size: 2em;
    }
    
    .chart-container {
        height: 300px;
        padding: 20px;
    }
    
    .status-bar {
        flex-direction: column;
        gap: 10px;
    }
    
    .table-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-box {
        max-width: 100%;
    }
    
    .table-footer {
        flex-direction: column;
        align-items: stretch;
    }
    
    .items-per-page {
        justify-content: center;
    }
}

.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    font-size: 1.2em;
    color: #7f8c8d;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--secondary-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin-right: 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error-message {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 200px;
    font-size: 1.2em;
    color: var(--danger-color);
    text-align: center;
}

/* Estilo específico para moneda boliviana */
.metric-value.moneda {
    color: #9b59b6;
    font-size: 1.6em;
}

/* Estilo para indicadores industriales */
.industrial-tag {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: bold;
    margin-left: 10px;
}

/* Ajustes para unidades más grandes */
.metric-unit.mwh {
    font-size: 0.65em;
    color: #3498db;
}

/* Destacar costos */
.costo-destacado {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 2px solid #9b59b6;
    position: relative;
}

.costo-destacado::after {
    content: '💲';
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 1.2em;
    opacity: 0.3;
}