:root,
[data-theme="claro"] {
    --bg: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-elevated: #eef1f6;
    --text: #1c2530;
    --text-muted: #5b6675;
    --border: #dde3ec;
    --accent: #2563eb;
    --accent-contrast: #ffffff;
    --success: #16a34a;
    --danger: #dc2626;
    --heatmap-0: #e9edf3;
    --heatmap-1: #bcdcff;
    --heatmap-2: #7cb8f5;
    --heatmap-3: #3d8ce0;
    --heatmap-4: #1a5bb8;
}

[data-theme="oscuro"] {
    --bg: #12151c;
    --bg-panel: #1b2029;
    --bg-elevated: #232935;
    --text: #e7ebf2;
    --text-muted: #98a2b3;
    --border: #2c3342;
    --accent: #5b8cff;
    --accent-contrast: #0b0f16;
    --success: #34d399;
    --danger: #f87171;
    --heatmap-0: #232935;
    --heatmap-1: #1f3a5f;
    --heatmap-2: #23517f;
    --heatmap-3: #2c72ab;
    --heatmap-4: #4d9fe0;
}

[data-theme="oceano"] {
    --bg: #eaf6f8;
    --bg-panel: #ffffff;
    --bg-elevated: #dcf0f3;
    --text: #0b3b45;
    --text-muted: #4a7d87;
    --border: #bfe3e8;
    --accent: #0891b2;
    --accent-contrast: #ffffff;
    --success: #059669;
    --danger: #e11d48;
    --heatmap-0: #e2f4f6;
    --heatmap-1: #a9e0e8;
    --heatmap-2: #63c4d3;
    --heatmap-3: #22a1b8;
    --heatmap-4: #0b7285;
}

[data-theme="bosque"] {
    --bg: #f2f7f0;
    --bg-panel: #ffffff;
    --bg-elevated: #e5efe1;
    --text: #1f3320;
    --text-muted: #5a7358;
    --border: #d3e3cd;
    --accent: #2f8f46;
    --accent-contrast: #ffffff;
    --success: #2f8f46;
    --danger: #c2410c;
    --heatmap-0: #e7f1e3;
    --heatmap-1: #bfe0b3;
    --heatmap-2: #8fca7c;
    --heatmap-3: #5cb047;
    --heatmap-4: #34822a;
}

[data-theme="violeta"] {
    --bg: #f5f2fb;
    --bg-panel: #ffffff;
    --bg-elevated: #ece5f8;
    --text: #2c1f45;
    --text-muted: #6b5b8a;
    --border: #ded0f2;
    --accent: #7c3aed;
    --accent-contrast: #ffffff;
    --success: #16a34a;
    --danger: #db2777;
    --heatmap-0: #ece4f8;
    --heatmap-1: #d3bdf0;
    --heatmap-2: #b78ce8;
    --heatmap-3: #9a5de0;
    --heatmap-4: #7c3aed;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background-color .2s, color .2s;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-wrap: wrap;
    gap: .75rem;
}

.app-header h1 {
    font-size: 1.2rem;
    margin: 0;
}

.theme-switcher {
    display: flex;
    gap: .4rem;
}

.theme-switcher button {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    padding: 0;
}

.theme-switcher button.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.theme-swatch-claro { background: linear-gradient(135deg, #fff 50%, #2563eb 50%); }
.theme-swatch-oscuro { background: linear-gradient(135deg, #1b2029 50%, #5b8cff 50%); }
.theme-swatch-oceano { background: linear-gradient(135deg, #eaf6f8 50%, #0891b2 50%); }
.theme-swatch-bosque { background: linear-gradient(135deg, #f2f7f0 50%, #2f8f46 50%); }
.theme-swatch-violeta { background: linear-gradient(135deg, #f5f2fb 50%, #7c3aed 50%); }

.tabs {
    display: flex;
    gap: .25rem;
    padding: 0 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab-button {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: .75rem 1rem;
    font-size: .95rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.tab-button:hover {
    color: var(--text);
}

.tab-button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

main {
    padding: 1.5rem;
    max-width: 1200px;
    margin: 0 auto;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fade-in .15s ease-in;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.panel-toolbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

select, .btn {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .4rem .6rem;
    font-size: .9rem;
}

.card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
}

.stat-card .label {
    color: var(--text-muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.stat-card .value {
    font-size: 1.6rem;
    font-weight: 700;
    margin-top: .25rem;
}

.stat-card .delta.up { color: var(--success); }
.stat-card .delta.down { color: var(--danger); }

.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: .6rem;
    height: 220px;
    padding-top: 1rem;
    border-bottom: 1px solid var(--border);
}

.bar-group {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: .2rem;
    height: 100%;
    position: relative;
}

.bar {
    width: 40%;
    border-radius: 4px 4px 0 0;
    background: var(--accent);
    min-height: 2px;
    transition: height .25s ease;
    position: relative;
}

.bar.previous {
    background: var(--text-muted);
    opacity: .5;
}

.bar-labels {
    display: flex;
    gap: .6rem;
    margin-top: .5rem;
}

.bar-labels span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    font-size: .75rem;
    color: var(--text-muted);
}

@media (max-width: 480px) {
    .bar-chart, .bar-labels {
        gap: .2rem;
    }

    .bar-labels span {
        font-size: .62rem;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: .55rem .6rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
    font-size: .9rem;
}

th:first-child, td:first-child {
    text-align: left;
}

thead th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: .8rem;
    text-transform: uppercase;
}

.pct-cell {
    border-radius: 6px;
    font-weight: 600;
}

.pct-up { color: var(--success); }
.pct-down { color: var(--danger); }

.heatmap-wrap {
    overflow-x: auto;
}

.heatmap-grid {
    display: grid;
    grid-auto-flow: column;
    grid-template-rows: repeat(7, 14px);
    gap: 3px;
}

.heatmap-cell {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    background: var(--heatmap-0);
    position: relative;
    cursor: default;
}

.heatmap-cell[data-level="1"] { background: var(--heatmap-1); }
.heatmap-cell[data-level="2"] { background: var(--heatmap-2); }
.heatmap-cell[data-level="3"] { background: var(--heatmap-3); }
.heatmap-cell[data-level="4"] { background: var(--heatmap-4); }

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 0%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: .25rem .5rem;
    border-radius: 4px;
    font-size: .7rem;
    white-space: nowrap;
    z-index: 20;
    pointer-events: none;
}

/* Cellules du bord de la heatmap : le popup s'ouvre vers l'interieur de la
   grille au lieu de deborder du conteneur (overflow-x:auto), sinon il est
   coupe et invisible. */
.heatmap-cell:nth-child(-n+7):hover::after {
    left: 0;
    transform: none;
}

.heatmap-cell:nth-last-child(-n+7):hover::after {
    left: auto;
    right: 0;
    transform: none;
}

.heatmap-cell:nth-child(7n+1):hover::after {
    bottom: auto;
    top: 130%;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: .3rem;
    margin-top: .75rem;
    font-size: .75rem;
    color: var(--text-muted);
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: .8rem;
}
