:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e3e6ea;
    --text: #1f2933;
    --muted: #6b7682;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --warning: #b45309;
    --warning-bg: #fef3c7;
    --late: #b91c1c;
    --late-bg: #fee2e2;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: #111827;
    color: #fff;
}
.topbar .inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 24px;
    min-height: 56px;
    flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; font-size: 17px; color: #fff; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a {
    color: #cbd5e1;
    padding: 6px 12px;
    border-radius: 6px;
}
.topbar nav a:hover, .topbar nav a.active { background: #1f2937; color: #fff; text-decoration: none; }
.topbar form button { background: none; border: 0; color: #cbd5e1; cursor: pointer; font: inherit; }

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.page-header h1 { margin: 0; font-size: 24px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.card h2 { margin: 0 0 16px; font-size: 17px; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-2 > .card { margin-bottom: 0; }

.site-card { border-top: 4px solid var(--site-color, var(--primary)); margin-bottom: 0; }
.site-card .head { display: flex; justify-content: space-between; align-items: start; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.site-card h3 { margin: 0; font-size: 16px; }
.site-card .url { color: var(--muted); font-size: 13px; word-break: break-all; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.kpi { background: var(--bg); border-radius: 8px; padding: 8px; text-align: center; }
.kpi strong { display: block; font-size: 20px; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpis.wide { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }

.meta { font-size: 13px; color: var(--muted); margin: 4px 0; }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.late { background: var(--late-bg); color: var(--late); }
.badge.status { background: #eef2f7; color: #374151; }
.badge.status-future { background: #e0e7ff; color: #3730a3; }
.badge.status-draft, .badge.status-pending { background: #f3f4f6; color: #6b7280; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: #f0f2f5; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--late); }
.btn.small { padding: 4px 10px; font-size: 13px; }
form.inline { display: inline; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; }
.alert.success { background: var(--ok-bg); color: var(--ok); }
.alert.error { background: var(--late-bg); color: var(--late); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* Carte de chaleur : articles par semaine et par site */
.heatmap td, .heatmap th { text-align: center; padding: 4px; border: 0; }
.heatmap th.site-name, .heatmap td.site-name { text-align: left; white-space: nowrap; padding-right: 12px; }
.heatmap .cell {
    display: block;
    min-width: 34px;
    height: 30px;
    line-height: 30px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    background: #eef1f4;
    color: var(--muted);
}

/* Histogramme global */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bars .bar div { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar span { font-size: 11px; color: var(--muted); margin-top: 4px; }
.bars .bar b { font-size: 11px; margin-bottom: 2px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 12px; }
.list li:last-child { border-bottom: 0; }
.list .when { color: var(--muted); font-size: 13px; white-space: nowrap; }

label { display: block; font-weight: 600; margin-bottom: 4px; }
.field { margin-bottom: 16px; }
.help { font-size: 13px; color: var(--muted); margin-top: 4px; font-weight: normal; }
input[type=text], input[type=url], input[type=email], input[type=password], input[type=number], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    background: #fff;
}
textarea { min-height: 260px; font-family: ui-monospace, monospace; font-size: 14px; }
input[type=color] { width: 60px; height: 38px; border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.error-text { color: var(--late); font-size: 13px; margin-top: 4px; }
.checks label { font-weight: normal; display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.filters > * { flex: 1; min-width: 160px; }
.filters .btn { flex: 0; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

.pagination { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 16px; list-style: none; padding: 0; }
.pagination a, .pagination span { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; display: inline-block; }
.pagination .active span { background: var(--primary); color: #fff; border-color: var(--primary); }

.login { max-width: 380px; margin: 80px auto; }

@media (max-width: 640px) {
    .topbar .inner { gap: 8px 16px; padding-top: 8px; }
    .topbar nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; }
    .topbar nav a { white-space: nowrap; }
    .topbar form { margin-left: auto; }
    .page-header h1 { font-size: 21px; }
}

/* Planning tourné vers l'avenir */
.coverage { font-weight: 600; margin: 0 0 8px; }
.coverage.ok { color: var(--ok); }
.coverage.warning { color: var(--warning); }
.coverage.late { color: var(--late); }
.gap-line { color: var(--warning); }
.attention { border-left: 4px solid var(--warning); }
.attention .list li { align-items: center; }

.heatmap th.now, .heatmap td.now { background: #eef4ff; }
.heatmap th.now { color: var(--primary); }
.heatmap .cell.future { outline: 1px dashed #c7cdd4; outline-offset: -1px; }
.heatmap .cell.gap, .legend-gap {
    background: repeating-linear-gradient(135deg, var(--late-bg) 0 5px, #fff 5px 10px);
    color: var(--late);
    outline: 1px solid #fca5a5;
}
.legend-gap { display: inline-block; width: 16px; height: 12px; border-radius: 3px; vertical-align: middle; margin-left: 6px; }
.heatmap td.site-name .help { margin: 0 0 0 16px; font-size: 11px; }

/* Calendrier */
.filters-sites { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; padding: 12px 20px; }
.filters-sites label { font-weight: normal; margin: 0; display: flex; align-items: center; gap: 4px; cursor: pointer; }
.calendar-card { padding: 12px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar .dow { font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; padding: 4px 0; }
.calendar .day { min-height: 110px; background: var(--bg); border-radius: 6px; padding: 4px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.calendar .day.other { opacity: .45; }
.calendar .day.past .num { color: var(--muted); }
.calendar .day.today { outline: 2px solid var(--primary); background: #eef4ff; }
.calendar .num { font-size: 12px; font-weight: 600; }
.event, .deadline {
    display: block;
    font-size: 12px;
    line-height: 1.3;
    padding: 2px 5px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}
.event { border-left: 3px solid var(--site-color, var(--primary)); background: #fff; }
.event.future { background: color-mix(in srgb, var(--site-color, var(--primary)) 16%, white); }
.event:hover { text-decoration: none; filter: brightness(.95); }
.deadline { background: var(--late-bg); color: var(--late); font-weight: 600; border-left: 3px solid var(--site-color, var(--late)); }
.legend { display: inline-block; margin-right: 8px; }

@media (max-width: 640px) {
    .calendar .day { min-height: 64px; }
    .event, .deadline { font-size: 10px; padding: 1px 3px; }
}

/* Dossiers et créneaux */
.badge.slot-idee { background: #f3f4f6; color: #6b7280; }
.badge.slot-reserve { background: var(--warning-bg); color: var(--warning); }
.badge.slot-redige { background: #eef2f7; color: #374151; }
.badge.slot-programme { background: #e0e7ff; color: #3730a3; }
.badge.slot-publie { background: var(--ok-bg); color: var(--ok); }
.dossier-card { display: block; color: inherit; }
.dossier-card:hover { text-decoration: none; border-color: #c7cdd4; }
.dossier-card .head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.dossier-card h2 { margin-bottom: 10px; }
.progress { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: #eef1f4; margin-bottom: 8px; }
.progress .seg.slot-publie { background: var(--ok); }
.progress .seg.slot-programme { background: #6366f1; }
.progress .seg.slot-redige { background: #94a3b8; }
.progress .seg.slot-reserve { background: #f59e0b; }
.progress .seg.slot-idee { background: #d1d5db; }
.coverage-hints { margin-top: 8px; display: grid; gap: 2px; }
.event.reserved { background: #fff; border: 1px dashed var(--site-color, var(--primary)); border-left-width: 3px; border-left-style: solid; color: var(--muted); font-style: italic; }
.heatmap .cell.reserved, .legend-reserved { box-shadow: inset 0 0 0 2px #f59e0b; }
.legend-reserved { display: inline-block; width: 14px; height: 12px; border-radius: 3px; vertical-align: middle; }
