:root {
    --primary: #0f172a; --accent: #3b82f6; --solar: #eab308;
    --grid: #ef4444; --bat: #22c55e; --surplus: #94a3b8;
    --bg: #f8fafc; --card: #ffffff; --border: #cbd5e1;
}
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); margin: 0; height: 100vh; overflow: hidden; }

.app-container { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }

/* SIDEBAR & RANKING */
.sidebar { background: var(--card); border-right: 1px solid var(--border); padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.sidebar h2 { color: var(--primary); margin: 0 0 5px 0; border-bottom: 2px solid var(--accent); padding-bottom: 5px; font-size: 1.2rem; }
.section-title { font-size: 0.8rem; font-weight: bold; color: #64748b; text-transform: uppercase; margin-top: 5px; margin-bottom: 5px; }

.input-row { display: flex; justify-content: space-between; align-items: center; background: #f1f5f9; padding: 8px; border-radius: 6px; border: 1px solid var(--border); }
.input-row label { font-size: 0.75rem; font-weight: bold; color: #334155; }
.input-row input, .input-row select { width: 90px; padding: 4px; border: 1px solid #cbd5e1; border-radius: 4px; text-align: right; font-size: 0.75rem; }

.tariff-card { background: #f1f5f9; border: 1px solid var(--border); padding: 10px; border-radius: 8px; cursor: pointer; transition: 0.2s; position: relative; }
.tariff-card:hover { border-color: var(--accent); }
.tariff-card.selected { background: #eff6ff; border: 2px solid var(--accent); }
.tariff-card.winner::before { content: '🏆 MEJOR'; position: absolute; top: -8px; right: 10px; background: #eab308; color: #000; font-size: 0.6rem; font-weight: bold; padding: 2px 6px; border-radius: 10px; }
.t-name { font-weight: bold; font-size: 0.85rem; color: #1e293b; }
.t-price { font-size: 1.1rem; font-weight: bold; color: #0f172a; margin-top: 2px; }
.t-details { margin-top: 6px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.t-badge { background: #e2e8f0; padding: 3px 5px; border-radius: 4px; font-size: 0.65rem; color: #475569; display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.chart-container-side { height: 120px; width: 100%; margin-top: 5px; }

/* MAIN CONTENT */
.main-content { padding: 12px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }

/* CINTA DE MÉTRICAS */
.kpi-ribbon { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.kpi-card { background: white; padding: 6px 4px; border-radius: 6px; border: 1px solid var(--border); text-align: center; box-shadow: 0 1px 2px rgba(0,0,0,0.05); display: flex; flex-direction: column; justify-content: center; }
.pv-card { background: #fefce8; border-color: #fef08a; }
.kpi-title { font-size: 0.6rem; color: #64748b; font-weight: bold; text-transform: uppercase; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.pv-card .kpi-title { color: #854d0e; }
.kpi-value { font-size: 0.95rem; font-weight: bold; color: var(--primary); }
.pv-card .kpi-value { color: #a16207; }
.kpi-sub { font-size: 0.55rem; color: #94a3b8; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.pv-card .kpi-sub { color: #ca8a04; }

/* TABLA DESGLOSE */
.dashboard-table { width: 100%; border-collapse: collapse; background: white; border-radius: 6px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.dashboard-table th { background: #1e293b; color: white; padding: 4px 8px; font-size: 0.7rem; text-align: right; }
.dashboard-table th:first-child { text-align: left; }
.dashboard-table td { padding: 4px 8px; border-bottom: 1px solid #e2e8f0; font-size: 0.75rem; text-align: right; }
.dashboard-table td:first-child { text-align: left; font-weight: bold; color: #475569; }
.dashboard-table tr.total-row { background: #f8fafc; font-weight: bold; font-size: 0.85rem; color: #0f172a; }
.text-green { color: #16a34a !important; }
.text-red { color: #dc2626 !important; }

/* TABS Y GRÁFICOS */
.tabs { display: flex; gap: 5px; overflow-x: auto; padding-bottom: 2px; }
.tab-btn { background: white; border: 1px solid #cbd5e1; padding: 4px 12px; border-radius: 4px; cursor: pointer; transition: 0.2s; font-size: 0.8rem; flex-shrink: 0; white-space: nowrap;}
.tab-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.charts-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.card { background: var(--card); padding: 10px; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid var(--border); display: flex; flex-direction: column;}
.chart-container { position: relative; height: 200px; width: 100%; }

/* PLANNER Y MATRIZ */
.planner-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.planner-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-opt { background: #16a34a; color: white; border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 0.75rem; }
.toggle-label { font-size: 0.75rem; display: flex; align-items: center; gap: 4px; background: #fff7ed; padding: 4px 8px; border-radius: 4px; border: 1px solid #ffedd5; cursor: pointer; }
.select-ev { font-size: 0.7rem; padding: 3px; border-radius: 4px; border: 1px solid #cbd5e1; outline: none; }

.matrix-container { flex-grow: 1; min-height: 150px; overflow-y: auto; border: 1px solid #e2e8f0; border-radius: 6px; }
table.matrix { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.65rem; table-layout: fixed; }
table.matrix th { background: #f1f5f9; padding: 4px 2px; vertical-align: bottom; text-align: center; position: sticky; top: 0; z-index: 10; border-bottom: 2px solid #cbd5e1; box-shadow: 0 2px 2px -1px rgba(0,0,0,0.1); }
table.matrix td { border-bottom: 1px solid #e2e8f0; border-right: 1px solid #f1f5f9; padding: 1px; text-align: center; }

.check-btn { width: 100%; height: 18px; border: 1px solid #cbd5e1; border-radius: 2px; cursor: pointer; position: relative; transition: 0.1s; }
.check-btn:active { transform: scale(0.9); }
.is-on { background: var(--bat); border-color: #15803d; }
.is-off { background: white; }

.recommend { border: 2px solid #22c55e !important; background-color: #f0fdf4; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); } 70% { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }

.warning-box { padding: 6px; border-radius: 4px; margin-bottom: 6px; font-weight: bold; display: none; font-size: 0.7rem; }
.warn-yellow { background: #fef08a; color: #854d0e; border: 1px solid #fde047; }
.warn-red { background: #fee2e2; color: #b91c1c; border: 1px solid #fca5a5; animation: shake 0.5s; }
@keyframes shake { 0%,100%{transform:translateX(0);} 25%{transform:translateX(-5px);} 75%{transform:translateX(5px);} }

#loader { position: fixed; inset: 0; background: rgba(255,255,255,0.95); z-index: 999; display: flex; justify-content: center; align-items: center; }
.spinner { width: 40px; height: 40px; border: 4px solid #e2e8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }

.kpi-ribbon, .dashboard-table, .tabs, .charts-grid, .planner-header { flex-shrink: 0; }

tr.row-overload { background-color: rgba(239, 68, 68, 0.1) !important; }
tr.row-overload td:first-child { color: var(--grid); font-weight: bold; border-left: 4px solid var(--grid); }

.planner-section, .dashboard-table, .tabs, .charts-grid { flex-shrink: 0; }
.matrix-container { flex-grow: 1; min-height: 200px; overflow-y: auto; }
.sidebar, .kpi-ribbon, .dashboard-table, .tabs, .charts-grid, .planner-header { flex-shrink: 0; }

/* --- NUEVAS CLASES PARA EL MODO ESTIMACIÓN --- */
.matrix-disabled {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(100%);
    transition: 0.3s ease;
}

.estimacion-info {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    margin-bottom: 8px;
    display: none;
}