/* ===== RESET & BASE ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #0f172a;
    color: #e2e8f0;
    min-height: 100vh;
    line-height: 1.5;
}

.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== HEADER ===== */
h1 {
    text-align: center;
    font-size: 1.6rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #fbbf24, #f59e0b, #d97706);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    text-align: center;
    color: #94a3b8;
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.subtitle .badge {
    background: #1e3a5f;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    color: #60a5fa;
}

/* ===== SECTION HEADERS ===== */
.section-header {
    margin: 2.5rem 0 1.25rem;
    padding-bottom: 0.6rem;
    border-bottom: 2px solid #334155;
}

.section-header h2 { font-size: 1.25rem; color: #f1f5f9; }
.section-header p { color: #94a3b8; font-size: 0.8rem; margin-top: 0.2rem; }

/* ===== BILL CARD ===== */
.bill-card {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 1px solid #334155;
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 1.5rem;
    position: relative;
    overflow: hidden;
}

.bill-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, #7c3aed, #a78bfa, #7c3aed);
}

.bill-header {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid #334155;
    gap: 1rem;
}

.bill-header-left h2 { font-size: 1.15rem; color: #f1f5f9; }
.bill-header-left p { color: #94a3b8; font-size: 0.8rem; margin-top: 0.2rem; }

.bill-total { text-align: right; flex-shrink: 0; }
.bill-total .amount { font-size: 2.2rem; font-weight: 700; color: #a78bfa; }
.bill-total .label { font-size: 0.7rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em; }

.bill-stat { text-align: center; }
.bill-stat .value { font-size: 1.3rem; font-weight: 700; color: #f1f5f9; }
.bill-stat .value span { font-size: 0.75rem; color: #64748b; font-weight: 400; }
.bill-stat .label { font-size: 0.7rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 0.2rem; }

/* ===== CONSUMPTION CARDS ===== */
.consumption-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.consumption-card {
    background: #1e293b;
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    border: 1px solid #334155;
}

.consumption-card .period { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.consumption-card .kwh { font-size: 1.5rem; font-weight: 700; color: #f1f5f9; }
.consumption-card .kwh span { font-size: 0.75rem; color: #64748b; font-weight: 400; }
.consumption-card .pct { font-size: 0.75rem; margin-top: 0.2rem; }
.consumption-card .period-hours { font-size: 0.6rem; color: #64748b; margin-top: 0.3rem; line-height: 1.3; }

.period-punta { color: #f87171; }
.period-llano { color: #fbbf24; }
.period-valle { color: #34d399; }

/* ===== BAR CHART ===== */
.chart { margin-bottom: 2rem; }

.chart-row {
    display: grid;
    grid-template-columns: 160px 1fr 90px;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.chart-label { text-align: right; }
.chart-label .name { font-weight: 600; font-size: 0.85rem; }
.chart-label .tariff { font-size: 0.7rem; color: #64748b; }

.chart-bar-container {
    height: 36px;
    background: #1e293b;
    border-radius: 8px;
    overflow: hidden;
}

.chart-bar {
    height: 100%;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    font-weight: 600;
    font-size: 0.8rem;
    min-width: 70px;
}

.chart-bar.octopus { background: linear-gradient(90deg, #5b21b6, #7c3aed); }
.chart-bar.endesa { background: linear-gradient(90deg, #1d4ed8, #3b82f6); }
.chart-bar.iberdrola { background: linear-gradient(90deg, #15803d, #22c55e); }
.chart-bar.naturgy { background: linear-gradient(90deg, #b45309, #f59e0b); }
.chart-bar.totalenergies { background: linear-gradient(90deg, #dc2626, #ef4444); }
.chart-bar.repsol { background: linear-gradient(90deg, #0369a1, #0ea5e9); }
.chart-bar.highlight { box-shadow: 0 0 0 2px #fbbf24; }

.chart-diff { text-align: right; font-size: 0.8rem; font-weight: 600; }
.diff-save { color: #34d399; }
.diff-extra { color: #f87171; }
.diff-neutral { color: #a78bfa; }

/* ===== TABLES ===== */
.table-wrap {
    border-radius: 16px;
    overflow-x: auto;
    box-shadow: 0 4px 30px rgba(0,0,0,0.4);
    margin-bottom: 2rem;
    -webkit-overflow-scrolling: touch;
}

table { width: 100%; border-collapse: collapse; min-width: 600px; }

thead th {
    background: #1e293b;
    padding: 0.7rem 0.8rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #94a3b8;
    border-bottom: 2px solid #334155;
    white-space: nowrap;
}

thead th:not(:first-child) { text-align: right; }

tbody td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid #1e293b;
    font-variant-numeric: tabular-nums;
    font-size: 0.85rem;
}

tbody td:not(:first-child) { text-align: right; }
tbody tr:hover { background: #1e293b; }

.row-total td { font-weight: 700; border-top: 2px solid #334155; font-size: 0.95rem; }
.row-highlight td { background: rgba(124,58,237,0.08); }

/* Company badges in table headers */
.company-badge { display: inline-flex; align-items: center; gap: 0.4rem; }
.company-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-octopus { background: #7c3aed; }
.dot-endesa { background: #3b82f6; }
.dot-iberdrola { background: #22c55e; }
.dot-naturgy { background: #f59e0b; }
.dot-totalenergies { background: #ef4444; }
.dot-repsol { background: #0ea5e9; }

/* ===== INSIGHT CARDS ===== */
.insight-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.insight-card {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid #334155;
}

.insight-card.warning { border-left: 4px solid #f59e0b; }
.insight-card.success { border-left: 4px solid #10b981; }
.insight-card.danger { border-left: 4px solid #ef4444; }
.insight-card.info { border-left: 4px solid #3b82f6; }

.insight-card h3 { font-size: 0.9rem; margin-bottom: 0.6rem; }
.insight-card.warning h3 { color: #fbbf24; }
.insight-card.success h3 { color: #34d399; }
.insight-card.danger h3 { color: #f87171; }
.insight-card.info h3 { color: #60a5fa; }

.insight-card p { color: #94a3b8; font-size: 0.8rem; line-height: 1.6; }
.insight-card strong { color: #f1f5f9; }

.highlight-number { font-size: 1.3rem; font-weight: 700; display: block; margin: 0.4rem 0; }

.insight-card details { margin-top: 0.8rem; }
.insight-card details summary {
    cursor: pointer;
    color: #60a5fa;
    font-size: 0.8rem;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.insight-card details summary::-webkit-details-marker { display: none; }
.insight-card details summary::before { content: "\25B6"; font-size: 0.6rem; transition: transform 0.2s; }
.insight-card details[open] summary::before { transform: rotate(90deg); }
.insight-card details .detail-content {
    margin-top: 0.6rem;
    padding: 0.8rem;
    background: #0f172a;
    border-radius: 8px;
    border: 1px solid #334155;
    font-size: 0.78rem;
    color: #94a3b8;
    line-height: 1.7;
}
.insight-card details .detail-content strong { color: #f1f5f9; }
.insight-card details .detail-content .detail-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0;
    font-size: 0.75rem;
}
.insight-card details .detail-table th {
    text-align: left;
    color: #64748b;
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid #334155;
    font-weight: 500;
}
.insight-card details .detail-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid #1e293b;
}
.insight-card details .detail-table .win { color: #34d399; }
.insight-card details .detail-table .lose { color: #f87171; }

/* ===== POWER CARDS ===== */
.power-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.power-card {
    background: #1e293b;
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid #334155;
}

.power-card h4 { font-size: 0.75rem; color: #64748b; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.6rem; }

.power-row { display: flex; justify-content: space-between; padding: 0.35rem 0; font-size: 0.8rem; }
.power-row + .power-row { border-top: 1px solid #0f172a; }
.power-row .val { font-weight: 600; font-variant-numeric: tabular-nums; }
.power-row .val.good { color: #34d399; }
.power-row .val.bad { color: #f87171; }
.power-row .val.neutral { color: #e2e8f0; }
.power-row.total-row { border-top: 2px solid #334155; margin-top: 0.4rem; padding-top: 0.4rem; }

/* ===== TAGS ===== */
.tag {
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 500;
    display: inline-block;
    margin: 0.1rem;
}

.tag-green { background: #064e3b; color: #34d399; }
.tag-blue { background: #1e3a5f; color: #60a5fa; }
.tag-yellow { background: #422006; color: #fbbf24; }
.tag-red { background: #450a0a; color: #f87171; }
.tag-purple { background: #3b0764; color: #c084fc; }

/* ===== COMPANY ICONS ===== */
.company-cell { display: flex; align-items: center; gap: 0.5rem; }

.company-icon {
    width: 30px; height: 30px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.6rem; flex-shrink: 0; color: white;
}

.icon-octopus { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.icon-endesa { background: linear-gradient(135deg, #2563eb, #60a5fa); }
.icon-iberdrola { background: linear-gradient(135deg, #16a34a, #4ade80); }
.icon-naturgy { background: linear-gradient(135deg, #b45309, #fbbf24); }
.icon-totalenergies { background: linear-gradient(135deg, #dc2626, #f87171); }
.icon-repsol { background: linear-gradient(135deg, #0369a1, #38bdf8); }

.best-badge {
    background: #065f46; color: #34d399;
    padding: 0.1rem 0.35rem; border-radius: 999px;
    font-size: 0.55rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.04em;
    margin-left: 0.25rem;
}

/* ===== WINNER CARDS (index) ===== */
.winner-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.winner-card {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.25rem;
    border: 1px solid #334155;
}

.winner-card .medal { font-size: 1.3rem; margin-bottom: 0.4rem; }
.winner-card h4 { font-size: 0.9rem; color: #f1f5f9; margin-bottom: 0.2rem; }
.winner-card .winner-company { color: #fbbf24; font-weight: 600; font-size: 0.85rem; }
.winner-card p { color: #94a3b8; font-size: 0.8rem; margin-top: 0.4rem; line-height: 1.5; }

/* ===== UPLOAD ZONE ===== */
.upload-zone {
    border: 2px dashed #334155;
    border-radius: 16px;
    padding: 2.5rem 1.5rem;
    text-align: center;
    margin: 2rem 0;
    transition: border-color 0.3s, background 0.3s;
    cursor: pointer;
    position: relative;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: #fbbf24;
    background: rgba(251, 191, 36, 0.05);
}

.upload-zone h3 { font-size: 1.1rem; color: #f1f5f9; margin-bottom: 0.5rem; }
.upload-zone p { color: #64748b; font-size: 0.85rem; margin-bottom: 1rem; }

.upload-zone input[type="file"] {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    opacity: 0; cursor: pointer;
}

.upload-btn {
    display: inline-block;
    background: linear-gradient(135deg, #fbbf24, #d97706);
    color: #0f172a;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
}

.upload-btn:hover { transform: scale(1.03); }

/* Loading spinner */
.loading { display: none; text-align: center; padding: 2rem; }
.loading.active { display: block; }
.spinner {
    width: 40px; height: 40px; border: 3px solid #334155;
    border-top-color: #fbbf24; border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== INFO BOX ===== */
.info-box {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    border-left: 4px solid #f59e0b;
    margin: 2rem 0;
}

.info-box h3 { color: #fbbf24; margin-bottom: 0.5rem; font-size: 0.9rem; }
.info-box p { color: #cbd5e1; line-height: 1.6; font-size: 0.8rem; }
.info-box strong { color: #f1f5f9; }

/* ===== ERROR BOX ===== */
.error-box {
    background: #1e293b;
    border-radius: 12px;
    padding: 1.25rem 1.5rem;
    border-left: 4px solid #ef4444;
    margin: 2rem 0;
}
.error-box h3 { color: #f87171; margin-bottom: 0.5rem; font-size: 0.9rem; }
.error-box p { color: #cbd5e1; font-size: 0.8rem; }

/* ===== BACK LINK ===== */
.back-link {
    display: inline-flex; align-items: center; gap: 0.4rem;
    color: #94a3b8; font-size: 0.85rem;
    margin-bottom: 1.5rem;
    transition: color 0.2s;
}
.back-link:hover { color: #f1f5f9; text-decoration: none; }

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    color: #475569;
    font-size: 0.7rem;
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid #1e293b;
}

/* ========================================================= */
/* ===== RESPONSIVE ===== */
/* ========================================================= */

/* Tablet */
@media (max-width: 768px) {
    .container { padding: 1rem; }
    h1 { font-size: 1.3rem; }

    .bill-card { grid-template-columns: 1fr; gap: 1rem; padding: 1.25rem; }
    .bill-header { flex-direction: column; align-items: flex-start; }
    .bill-total { text-align: left; }
    .bill-total .amount { font-size: 1.8rem; }

    .consumption-grid { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
    .consumption-card .kwh { font-size: 1.2rem; }

    .chart-row { grid-template-columns: 110px 1fr 75px; gap: 0.5rem; }
    .chart-label .name { font-size: 0.75rem; }
    .chart-label .tariff { font-size: 0.65rem; }
    .chart-bar { font-size: 0.7rem; padding-right: 6px; }

    .insight-grid { grid-template-columns: 1fr; }
    .power-grid { grid-template-columns: 1fr; }
    .winner-grid { grid-template-columns: 1fr; }

    table { min-width: 500px; }
}

/* Mobile */
@media (max-width: 480px) {
    .container { padding: 0.75rem; }
    h1 { font-size: 1.1rem; }
    .subtitle { font-size: 0.8rem; }

    .bill-card { padding: 1rem; }
    .bill-total .amount { font-size: 1.5rem; }
    .bill-stat .value { font-size: 1.1rem; }

    .consumption-grid { grid-template-columns: 1fr 1fr 1fr; gap: 0.4rem; }
    .consumption-card { padding: 0.75rem; }
    .consumption-card .kwh { font-size: 1rem; }
    .consumption-card .period { font-size: 0.6rem; }

    /* Barras: layout vertical en movil */
    .chart-row {
        grid-template-columns: 1fr 60px;
        grid-template-rows: auto auto;
    }
    .chart-label {
        grid-column: 1 / -1;
        text-align: left;
        display: flex;
        gap: 0.4rem;
        align-items: baseline;
    }
    .chart-bar-container { height: 30px; }
    .chart-bar { font-size: 0.7rem; min-width: 55px; }

    .section-header h2 { font-size: 1rem; }

    .upload-zone { padding: 1.5rem 1rem; }
    .upload-zone h3 { font-size: 0.95rem; }

    .insight-card { padding: 1rem; }
    .insight-card h3 { font-size: 0.8rem; }
    .insight-card p { font-size: 0.75rem; }

    table { min-width: 450px; font-size: 0.75rem; }
    thead th { padding: 0.5rem; font-size: 0.65rem; }
    tbody td { padding: 0.4rem 0.5rem; }
}
