:root {
    --primary: #1a1f36;
    --primary-soft: #2d3250;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --green: #10b981;
    --green-bg: #d1fae5;
    --red: #ef4444;
    --red-bg: #fee2e2;
    --bg: #f1f5f9;
    --card: #fff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --midi: #f97316;
    --midi-bg: #fff7ed;
    --midi-light: #fed7aa;
    --soir: #8b5cf6;
    --soir-bg: #f5f3ff;
    --soir-light: #ddd6fe;
    --n1-bg: #f0f9ff;
    --n1-text: #0369a1;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --radius: 12px;
    --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg); color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ═══ NAV ═══ */
#main-nav {
    display: flex; align-items: center; gap: 16px;
    background: var(--primary); color: #fff;
    padding: 0 24px; height: 52px;
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.nav-brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-icon {
    background: var(--accent); color: #fff; font-weight: 800; font-size: .75em;
    width: 32px; height: 32px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; letter-spacing: -.5px;
}
.brand-text { font-size: 1.3em; font-weight: 700; letter-spacing: -.3px; }
.nav-links { display: flex; gap: 2px; }
.nav-link {
    color: rgba(255,255,255,.55); text-decoration: none; padding: 8px 14px;
    border-radius: var(--radius-sm); font-size: .82em; font-weight: 500;
    transition: all .2s; display: flex; align-items: center; gap: 6px;
}
.nav-link:hover { color: rgba(255,255,255,.85); background: rgba(255,255,255,.08); }
.nav-link.active { color: #fff; background: rgba(255,255,255,.12); }
.nav-actions { display: flex; gap: 8px; margin-left: 12px; }
.btn {
    padding: 8px 16px; border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-size: .8em; font-weight: 600; transition: all .15s;
    font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-light); transform: translateY(-1px); }
.btn-ghost { background: transparent; color: rgba(255,255,255,.6); border: 1px solid rgba(255,255,255,.2); }
.btn-ghost:hover { color: #fff; border-color: rgba(255,255,255,.4); }
.btn-full { width: 100%; padding: 12px; font-size: .95em; margin-top: 8px; }

/* ═══ LAYOUT ═══ */
main { padding: 14px 20px; max-width: 1600px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ═══ MONTH NAV ═══ */
.month-nav {
    display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}
.month-nav h2 {
    font-size: 1.2em; font-weight: 800; color: var(--primary);
    min-width: 180px; text-align: center; letter-spacing: -.5px;
}
.btn-nav {
    background: var(--card); border: 1px solid var(--border); color: var(--text);
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    font-size: 1.1em; display: flex; align-items: center; justify-content: center;
    transition: all .15s; box-shadow: var(--shadow-sm);
}
.btn-nav:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ═══ KPI CARDS ═══ */
.kpi-row {
    display: flex; gap: 12px; margin-bottom: 12px;
}
.kpi-card {
    background: var(--card); border-radius: 8px; padding: 16px 10px;
    box-shadow: var(--shadow); position: relative; overflow: hidden;
    border-left: 4px solid transparent; border-top: none; flex: 1; min-width: 0;
}
.kpi-card.ca { border-left-color: var(--accent); flex: 1.3; }
.kpi-card.midi { border-left-color: var(--midi); }
.kpi-card.soir { border-left-color: var(--soir); }
.kpi-card.couv { border-left-color: var(--green); }
.kpi-card.tm { border-left-color: #f59e0b; }
.kpi-card.camoy { border-left-color: #ec4899; }
.kpi-card.solde { border-left-color: #0ea5e9; }
.kpi-top {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1px;
}
.kpi-label {
    font-size: .65em; font-weight: 700; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .3px;
}
.kpi-value { font-size: 1.4em; font-weight: 800; letter-spacing: -.5px; line-height: 1.2; margin: 4px 0; }
.kpi-sub { font-size: .65em; color: var(--text-secondary); line-height: 1.3; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-delta {
    display: inline-flex; align-items: center; gap: 2px;
    font-size: .65em; font-weight: 700; padding: 1px 6px;
    border-radius: 20px;
}
.kpi-delta.pos { background: var(--green-bg); color: var(--green); }
.kpi-delta.neg { background: var(--red-bg); color: var(--red); }
.kpi-card.podium { border-left-color: #f59e0b; }
.podium-row { display: flex; align-items: center; gap: 4px; font-size: .72em; line-height: 1.6; }
.podium-day { font-weight: 600; color: var(--primary); }
.podium-val { margin-left: auto; font-weight: 700; color: var(--text); }
.kpi-sparkline {
    position: absolute; bottom: 0; right: 0; width: 80px; height: 40px; opacity: .15;
}

/* ═══ CHART SECTION ═══ */
.chart-section {
    background: var(--card); border-radius: var(--radius); padding: 18px 20px;
    box-shadow: var(--shadow); margin-bottom: 16px;
    max-height: 350px; position: relative;
}
.chart-section canvas {
    max-height: 280px !important;
}
.chart-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px;
}
.chart-header h3 { font-size: .95em; font-weight: 700; color: var(--primary); }
.chart-legend { display: flex; gap: 16px; font-size: .75em; color: var(--text-secondary); }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot {
    width: 10px; height: 10px; border-radius: 3px;
}
.legend-dot.midi { background: var(--midi); }
.legend-dot.soir { background: var(--soir); }
.legend-line {
    width: 16px; height: 2px; border-top: 2px dashed;
}
.legend-line.n1 { border-color: var(--n1-text); }

/* ═══ TABLE ═══ */
.table-section {
    background: var(--card); border-radius: 6px;
    box-shadow: var(--shadow-sm); overflow-x: auto; overflow-y: visible;
}
table { width: 100%; border-collapse: collapse; font-size: .68em; }

/* Header groups */
thead th {
    padding: 0; font-weight: 700; text-align: center;
    white-space: nowrap; font-size: .7em; letter-spacing: .3px;
    /* no sticky - was hiding first rows */
}
tr.th-group th {
    background: var(--primary); color: #fff; padding: 4px 3px;
    text-transform: uppercase; letter-spacing: .5px;
}
tr.th-group th.grp-ca { background: var(--accent); }
tr.th-group th.grp-couv { background: var(--green); }
tr.th-group th.grp-perf { background: #f59e0b; }
tr.th-group th.grp-solde { background: #0ea5e9; }
tr.th-sub th {
    background: #f8fafc; color: var(--text-secondary); padding: 3px 3px;
    border-bottom: 2px solid var(--border); font-weight: 600;
}

/* Data cells */
td {
    padding: 4px 4px; text-align: right; border-bottom: 1px solid #f1f5f9;
    white-space: nowrap; font-variant-numeric: tabular-nums;
}
td.date-cell {
    text-align: left; font-weight: 600; color: var(--primary);
    padding-left: 4px; cursor: pointer; width: 50px; max-width: 50px;
}
td.date-cell:hover { color: var(--accent); }
td.n1-date {
    text-align: center; font-size: .75em; color: var(--text-muted);
    width: 30px; max-width: 30px;
}
td.val-midi { color: var(--midi); font-weight: 500; }
td.val-soir { color: var(--soir); font-weight: 500; }
td.val-n1 { color: var(--n1-text); background: var(--n1-bg); }
td.val-bold { font-weight: 700; }
td.meteo-cell { text-align: center; font-size: .9em; width: 30px; max-width: 36px; padding: 0 2px; }
td.meteo-cell .temp { font-size: .7em; color: var(--text-muted); margin-left: 1px; }
td.val-solde { color: #0ea5e9; font-weight: 600; }

/* Rest days */
tr.repos { background: #f4f4f5; }
tr.repos td { padding: 2px 6px; color: #8891a0; font-style: italic; font-size: .78em; line-height: 1.3; }
.val-cumul { color: #0d9488; font-weight: 500; font-size: .72em; }
.kpi-card.cumul { border-left-color: #0d9488; }
.grp-cumul { background: #0d9488; }
tr.conge-row td { padding: 2px 6px; font-size: .78em; line-height: 1.3; }

/* Week separator */
tr.week-sep td { border-bottom: none; height: 1px; background: var(--bg); padding: 0; }

/* Week summary */
tr.week-summary {
    background: #f8fafc; font-weight: 600; color: var(--primary-soft);
}
tr.week-summary td { padding: 2px 4px; border-bottom: 2px solid var(--border); font-size: .75em; }

/* Month footer - sticky at bottom */
tr.bilan {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-soft) 100%);
    color: #fff; font-weight: 700;
}
tr.bilan td { padding: 4px 4px; border: none; font-size: .78em; }
tr.bilan-n1 { background: var(--n1-bg); color: var(--n1-text); font-weight: 600; }
tr.bilan-n1 td { padding: 4px; border: none; font-size: .75em; }
tr.bilan-delta td { padding: 4px; border: none; font-weight: 700; font-size: .75em; }

/* Hover */
tr.data-row:hover { background: #f0f4ff; }

/* Deltas inline */
.delta { font-weight: 600; font-size: .85em; }
.delta.pos { color: var(--green); }
.delta.neg { color: var(--red); }
.pct { font-size: .8em; color: var(--text-muted); }

/* ═══ MODAL ═══ */
/* Forecast */
.forecast-section { background: var(--card); border-radius: 8px; box-shadow: var(--shadow); padding: 10px 14px; margin-bottom: 12px; }
.forecast-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.forecast-header h3 { font-size: .75em; font-weight: 700; color: var(--primary); margin: 0; }
.forecast-subtitle { font-size: .62em; color: var(--text-muted); }
.forecast-cards { display: flex; gap: 4px; overflow-x: auto; }
.forecast-card {
    flex: 1; min-width: 65px; background: #f8fafc; border-radius: 6px; padding: 4px;
    text-align: center; border: 1px solid #e2e8f0; cursor: pointer; transition: all .15s;
}
.forecast-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(99,102,241,.15); }
.forecast-card.today { border-color: var(--accent); background: #eef2ff; }
.forecast-card.repos { opacity: .4; cursor: default; }
.fc-day { font-size: .62em; font-weight: 600; color: var(--primary); margin-bottom: 1px; }
.fc-today { background: var(--accent); color: white; padding: 0 4px; border-radius: 6px; font-size: .75em; }
.fc-meteo { font-size: .68em; margin-bottom: 1px; }
.fc-prediction { font-size: 1.15em; font-weight: 800; color: var(--accent); line-height: 1.1; }
.fc-label { font-size: .5em; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.fc-real { font-size: .58em; color: var(--green); margin-top: 1px; }
.fc-repos { font-size: .62em; color: var(--text-muted); font-style: italic; }
.fc-confidence { font-size: .5em; padding: 0 4px; border-radius: 6px; margin-top: 1px; display: inline-block; }
.fc-confidence.high { background: #dcfce7; color: #166534; }
.fc-confidence.mid { background: #fef3c7; color: #92400e; }
.fc-confidence.low { background: #fee2e2; color: #991b1b; }
.fc-conf-bar { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.fc-conf-fill { height: 100%; background: linear-gradient(90deg, #ef4444, #f59e0b, #22c55e); border-radius: 3px; }

.modal {
    position: fixed; inset: 0; background: rgba(15,23,42,.6);
    display: flex; align-items: center; justify-content: center; z-index: 200;
    backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-content {
    background: #fff; border-radius: var(--radius); padding: 0;
    min-width: 380px; max-width: 500px; max-height: 90vh; overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0,0,0,.25);
}
.modal-large { min-width: 650px; max-width: 850px; }
.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1em; font-weight: 700; color: var(--primary); }
.modal-close {
    background: none; border: none; font-size: 1.5em; cursor: pointer;
    color: var(--text-muted); transition: .15s;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group label {
    display: block; font-size: .78em; font-weight: 600;
    color: var(--text-secondary); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px;
}
.form-group input {
    width: 100%; padding: 10px 14px; border: 2px solid var(--border);
    border-radius: var(--radius-sm); font-size: 1em; transition: .15s; font-family: inherit;
}
.form-group input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(99,102,241,.15); }

/* Detail modal */
.detail-section { margin-bottom: 24px; }
.detail-section h4 {
    font-size: .85em; font-weight: 700; color: var(--primary);
    text-transform: uppercase; letter-spacing: .5px;
    margin-bottom: 10px; padding-bottom: 6px; border-bottom: 2px solid var(--border);
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.detail-item {
    display: flex; justify-content: space-between; padding: 6px 8px;
    border-radius: 6px; font-size: .88em;
}
.detail-item:nth-child(odd) { background: #f8fafc; }
.detail-item .label { color: var(--text-secondary); }
.detail-item .value { font-weight: 600; }

/* ═══ TRENDS / CATEGORIES ═══ */
.trends-controls, .cat-controls { display: flex; gap: 12px; margin-bottom: 16px; }
select {
    padding: 8px 14px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    font-size: .85em; background: var(--card); font-family: inherit; font-weight: 500;
    cursor: pointer;
}
select:focus { border-color: var(--accent); outline: none; }
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 1400px) {
    .kpi-row { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 768px) {
    #main-nav { flex-wrap: wrap; height: auto; padding: 10px 16px; }
    .nav-actions { width: 100%; justify-content: stretch; }
    .nav-actions .btn { flex: 1; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .charts-grid { grid-template-columns: 1fr; }
    .modal-large { min-width: 90vw; }
    main { padding: 12px; }
}
