:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e3e5ea;
    --text: #1f2330;
    --muted: #6b7180;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #dc2626;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
a { color: var(--primary); }
.muted { color: var(--muted); font-weight: normal; }
[hidden] { display: none !important; }

/* ---------- Boutons & formulaires ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    padding: .5rem .9rem; border: 1px solid transparent; border-radius: var(--radius);
    font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: auto; }
.btn-primary:disabled:hover { background: var(--primary); }
.btn.active { background: #eef0ff; color: var(--primary); border-color: #c7ccff; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 1rem; }

.icon-btn {
    border: 0; background: transparent; cursor: pointer; padding: .25rem .35rem;
    border-radius: 6px; font-size: .95rem; line-height: 1;
}
.icon-btn:hover { background: var(--bg); }

.link {
    border: 0; background: none; padding: 0; font: inherit; color: inherit;
    text-align: left; cursor: pointer; font-weight: 600;
}
.link:hover { color: var(--primary); text-decoration: underline; }

label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; font-size: .9rem; }
input, select, textarea {
    font: inherit; padding: .5rem .6rem; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, .link:focus-visible, .chip:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 1px;
}
textarea { resize: vertical; }
input[type="color"] { height: 2.6rem; padding: .2rem; cursor: pointer; width: 100%; }
.error { color: var(--danger); font-weight: normal; min-height: 0; }
.error:empty { display: none; }

/* ---------- Layout ---------- */

.topbar {
    display: flex; align-items: center; gap: 1.5rem; padding: .75rem 1.5rem;
    background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; font-size: 1.2rem; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: .25rem; }
.nav a { padding: .4rem .75rem; border-radius: var(--radius); color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--bg); color: var(--text); }
.nav a.active { background: #eef0ff; color: var(--primary); }
.topbar-actions { margin-left: auto; display: flex; gap: .5rem; align-items: center; }
.logout { margin: 0; }

.page { padding: 1.5rem; max-width: 1600px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; }
.notice { background: #eef0ff; border: 1px solid #c7ccff; padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.empty { color: var(--muted); padding: 1rem 0; }

.dashboard { display: grid; grid-template-columns: 7fr 3fr; gap: 1.5rem; align-items: start; }

/* ---------- Calendrier ---------- */

.calendar, .upcoming {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem; box-shadow: var(--shadow); min-width: 0;
}
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; }
.calendar-nav { display: flex; gap: .35rem; }
.calendar-grid {
    display: grid; grid-template-columns: repeat(7, minmax(0, 1fr));
    border-top: 1px solid var(--border); border-left: 1px solid var(--border);
}
.calendar-weekday {
    padding: .4rem; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase;
    border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); text-align: center;
}
.calendar-day {
    min-height: 110px; padding: .3rem; display: flex; flex-direction: column; gap: 3px;
    border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); min-width: 0;
}
.calendar-day.is-outside { background: #fafbfc; }
.calendar-day.is-outside .calendar-day-num { color: #b5bac5; }
.calendar-day-head { display: flex; align-items: center; justify-content: space-between; min-height: 1.6rem; }
.calendar-day-num { font-size: .85rem; font-weight: 600; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; border-radius: 50%; }
.calendar-day.is-today .calendar-day-num { background: var(--primary); color: #fff; }
.calendar-day-long { display: none; }
.add-btn {
    border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1rem;
    width: 1.5rem; height: 1.5rem; border-radius: 50%; opacity: 0; transition: opacity .15s;
}
.calendar-day:hover .add-btn, .add-btn:focus-visible { opacity: 1; }
.add-btn:hover { background: var(--bg); color: var(--primary); }

.chip {
    display: flex; align-items: center; gap: .35rem; width: 100%; border: 0; border-radius: 5px;
    padding: .2rem .4rem; font: inherit; font-size: .8rem; font-weight: 500; cursor: pointer; text-align: left;
}
.chip:hover { filter: brightness(.92); }
.chip[draggable="true"] { cursor: grab; }
.chip.is-dragging { opacity: .35; }
.calendar-day.is-drop-target { background: #eef0ff; box-shadow: inset 0 0 0 2px var(--primary); }
.chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: none; width: .6rem; height: .6rem; border-radius: 50%; box-shadow: 0 0 0 2px #fff; display: inline-block; }

.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin: .75rem 0 0; font-size: .85rem; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: .4rem; }

/* ---------- Liste d'articles ---------- */

.upcoming h2 { margin-bottom: .75rem; }
.article-list { list-style: none; margin: 0; padding: 0; }
.article-item { padding: .7rem 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: .4rem; }
.article-item:last-child { border-bottom: 0; }
.article-main { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; }
.article-date { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.article-meta { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.article-actions { margin-left: auto; display: flex; }

.pill {
    display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
    max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.status-select {
    font-size: .8rem; padding: .15rem 1.6rem .15rem .5rem; border-radius: 999px;
    border: 1px solid var(--status); color: var(--status); font-weight: 600; cursor: pointer;
}

/* Tooltip de description */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after {
    content: attr(data-tooltip); position: absolute; left: 0; top: calc(100% + 6px); z-index: 20;
    width: max-content; max-width: 280px; padding: .5rem .65rem; border-radius: 6px;
    background: #1f2330; color: #fff; font-size: .8rem; font-weight: normal; line-height: 1.4;
    white-space: pre-wrap; box-shadow: var(--shadow); pointer-events: none;
}

.wide-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0 1rem; box-shadow: var(--shadow); }
.wide-list .empty { padding: 1rem 0; }
@media (min-width: 768px) {
    .wide-list .article-item { flex-direction: row; align-items: center; }
    .wide-list .article-main { flex: 1; justify-content: flex-start; }
    .wide-list .article-date { order: -1; width: 9rem; }
    .wide-list .article-meta { flex: none; width: 26rem; }
}

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.filters input[type="search"] { flex: 1 1 200px; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; }

/* ---------- Blogs ---------- */

.blog-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.blog-card {
    display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; background: var(--surface);
    border: 1px solid var(--border); border-left: 5px solid var(--blog); border-radius: var(--radius); box-shadow: var(--shadow);
}
.swatch { width: 1.4rem; height: 1.4rem; border-radius: 50%; background: var(--blog); flex: none; }
.blog-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.blog-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blog-info a { font-size: .85rem; text-decoration: none; }

/* ---------- Tableau (Options) ---------- */

.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: .8rem; text-transform: uppercase; color: var(--muted); font-weight: 600; background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .col-actions { text-align: right; width: 1%; }
.badge { display: inline-block; margin-left: .5rem; padding: .05rem .5rem; border-radius: 999px; background: #eef0ff; color: var(--primary); font-size: .75rem; font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Dialogs ---------- */

.dialog {
    border: 0; border-radius: 12px; padding: 0; width: min(560px, calc(100vw - 2rem));
    box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.dialog-sm { width: min(400px, calc(100vw - 2rem)); }
.dialog::backdrop { background: rgba(17, 20, 30, .45); }
.dialog form { padding: 1.25rem; display: flex; flex-direction: column; gap: .9rem; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; }
.dialog-footer { display: flex; gap: .5rem; align-items: center; margin-top: .25rem; }
.spacer { flex: 1; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }

/* ---------- Toasts ---------- */

.toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; }
.toast {
    padding: .7rem 1rem; border-radius: var(--radius); color: #fff; background: #16a34a;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .2); max-width: 340px; animation: toast-in .2s ease-out;
    transition: opacity .4s, transform .4s;
}
.toast-error { background: var(--danger); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Connexion ---------- */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card {
    width: min(380px, 100%); background: var(--surface); padding: 2rem; border-radius: 12px;
    box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1rem;
}
.login-card h1 { font-size: 1.6rem; }
.login-card p { margin: -.75rem 0 0; }
.alert { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; padding: .6rem .8rem; border-radius: var(--radius); margin: 0 !important; }

/* ---------- Responsive ---------- */

@media (max-width: 992px) {
    .dashboard { grid-template-columns: 1fr; }
    .calendar-day { min-height: 90px; }
}

@media (max-width: 768px) {
    .topbar { flex-wrap: wrap; gap: .5rem 1rem; padding: .6rem 1rem; }
    .nav { order: 3; width: 100%; }
    .page { padding: 1rem; }
    .form-row { grid-template-columns: 1fr; }

    /* Calendrier en vue agenda : un jour par ligne, jours vides masqués. */
    .calendar-grid { grid-template-columns: 1fr; border: 0; }
    .calendar-weekday, .calendar-day.is-outside, .calendar-day.is-empty { display: none; }
    .calendar-day { min-height: 0; border: 0; border-bottom: 1px solid var(--border); padding: .6rem 0; }
    .calendar-day-num { display: none; }
    .calendar-day-long { display: block; font-weight: 600; text-transform: capitalize; }
    .calendar-day.is-today .calendar-day-long { color: var(--primary); }
    .add-btn { opacity: 1; }
    .chip { font-size: .9rem; padding: .4rem .6rem; }
    .calendar-grid:not(:has(.calendar-day:not(.is-empty):not(.is-outside)))::after {
        content: "Aucun article ce mois-ci."; color: var(--muted); padding: 1rem 0;
    }
}
