:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --ink: #1f2733;
    --muted: #6b7785;
    --line: #e3e7ec;
    --primary: #2f6df0;
    --primary-dark: #1f55c8;
    --yes: #1f9d57;
    --yes-bg: #e7f6ed;
    --maybe: #c98a00;
    --maybe-bg: #fcf3dc;
    --no: #c0392b;
    --no-bg: #fbe9e7;
    --best-bg: #eaf2ff;
    --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    /* La page ne défile jamais horizontalement : les contenus larges
       (calendrier, tableaux) défilent dans leur propre conteneur. */
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
}

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    padding: 14px 20px;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-logo { height: 30px; width: auto; display: block; }
.brand-app { font-weight: 600; font-size: .95rem; color: var(--muted);
    border-left: 1px solid var(--line); padding-left: 12px; }
@media (max-width: 520px) { .brand-app { display: none; } }

.container { max-width: 860px; margin: 0 auto; padding: 28px 20px 60px; }

h1 { font-size: 1.7rem; margin: 0 0 6px; }
h2 { font-size: 1.25rem; margin: 28px 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; color: var(--muted); }
.lede { color: var(--muted); margin: 0 0 20px; }
.meta { color: var(--muted); margin: 0 0 8px; }
.muted { color: var(--muted); }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 24px;
}

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 14px; }
input[type=text], input[type=email], input[type=datetime-local], textarea {
    width: 100%;
    margin-top: 5px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    font-weight: 400;
    background: #fff;
}
textarea { resize: vertical; }

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 220px; }

fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin: 8px 0 18px; }
legend { font-weight: 700; padding: 0 6px; }

.slot-row { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.slot-field { flex: 1; margin-bottom: 0; }
.btn-remove {
    border: 1px solid var(--line); background: #fff; color: var(--no);
    border-radius: 8px; padding: 9px 12px; cursor: pointer; font-size: 0.9rem;
}

button { font: inherit; }
.btn-primary {
    background: var(--primary); color: #fff; border: 0; border-radius: 9px;
    padding: 11px 20px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-secondary {
    background: #eef1f5; color: var(--ink); border: 1px solid var(--line);
    border-radius: 9px; padding: 9px 16px; font-weight: 600; cursor: pointer;
}
.btn-link { background: none; border: 0; color: var(--primary); cursor: pointer; text-decoration: underline; padding: 0; }
.inline-form { display: inline; margin: 0; }

.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 20px; }
.alert.success { background: var(--yes-bg); color: #14653a; }
.alert.error { background: var(--no-bg); color: #8c2a1d; }

/* Liens copiables */
.links { display: grid; gap: 18px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { background: #f9fafb; }
.copy-btn { white-space: nowrap; }

/* Tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 0.82rem; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.slot-cell { font-weight: 600; }
.num { text-align: center; font-variant-numeric: tabular-nums; }
.name-cell { font-weight: 600; }

.vote-table .choice-cell { text-align: center; }
.vote-table .choice-cell label { display: inline-flex; flex-direction: column; align-items: center; gap: 4px; font-weight: 500; margin: 0; cursor: pointer; }
.choice-yes span { color: var(--yes); }
.choice-maybe span { color: var(--maybe); }
.choice-no span { color: var(--no); }

.cell-yes { color: var(--yes); background: var(--yes-bg); text-align: center; font-weight: 700; }
.cell-maybe { color: var(--maybe); background: var(--maybe-bg); text-align: center; font-weight: 700; }
.cell-no { color: var(--no); background: var(--no-bg); text-align: center; font-weight: 700; }
.cell-empty { color: var(--muted); text-align: center; }

tr.best, th.best, td.best { background: var(--best-bg); }
.maybe-count { color: var(--maybe); font-size: 0.8rem; }

.badge { display: inline-block; background: var(--primary); color: #fff; font-size: 0.72rem; padding: 2px 8px; border-radius: 20px; margin-left: 8px; vertical-align: middle; }
.badge-final { background: var(--yes); }
.totals td { border-top: 2px solid var(--line); }

.footer { text-align: center; color: var(--muted); padding: 30px 20px; font-size: 0.85rem; }
.footer p { margin: 4px 0; }
.footer-credit a { color: var(--primary-dark); text-decoration: none; }
.footer-credit a:hover { text-decoration: underline; }

/* Page légale (conditions) */
.legal { max-width: 720px; }
.legal h2 { font-size: 1.05rem; margin: 24px 0 8px; color: var(--ink); }
.legal ul { margin: 6px 0 6px; padding-left: 22px; }
.legal li { margin: 4px 0; }
.legal a { color: var(--primary-dark); }

/* ============================ Calendrier ============================ */
/* min-width:0 : un <fieldset> a par défaut min-width:min-content et
   s'élargirait pour contenir la grille — ce qui pousserait toute la page. */
.cal-fieldset { padding: 16px; min-width: 0; }
.calendar, #cal-body { min-width: 0; }
.calendar { margin-top: 6px; }

.cal-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-label { font-weight: 700; font-size: .9rem; }
.cal-durations { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cal-durations button {
    border: 1px solid var(--line); background: #fff; color: var(--ink);
    border-radius: 8px; padding: 7px 12px; font-weight: 600; cursor: pointer; font-size: .88rem;
}
.cal-durations button:hover { border-color: var(--primary); }
.cal-durations button.active { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
#cal-custom { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }

.cal-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.cal-tabs button {
    background: none; border: 0; border-bottom: 2px solid transparent;
    padding: 8px 14px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.cal-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.cal-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.cal-nav button {
    border: 1px solid var(--line); background: #fff; border-radius: 8px;
    padding: 6px 12px; font-weight: 600; cursor: pointer;
}
.cal-nav button:hover { border-color: var(--primary); }
.cal-period { font-weight: 700; }
.cal-tz { margin-left: auto; color: var(--muted); font-size: .85rem; }

/* --- Vue semaine --- */
.wk-hscroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.wk { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.wk-head { display: flex; background: #fafbfc; border-bottom: 1px solid var(--line); }
.wk-gutter { width: 52px; flex: none; }
.wk-col-head { flex: 1; text-align: center; padding: 8px 2px; border-left: 1px solid var(--line); }
.wk-col-head.today { background: var(--best-bg); }
.wk-dow { font-size: .72rem; color: var(--muted); letter-spacing: .03em; }
.wk-dom { font-size: 1.15rem; font-weight: 700; }

.wk-scroll { max-height: 420px; overflow-y: auto; overflow-x: hidden; }
.wk-grid { display: flex; position: relative; }
.wk-gutter-col { width: 52px; flex: none; }
.wk-hour { font-size: .72rem; color: var(--muted); text-align: right; padding-right: 6px;
    box-sizing: border-box; border-top: 1px solid var(--line); }
.wk-col { flex: 1; position: relative; border-left: 1px solid var(--line); }
.wk-cell { border-top: 1px solid #eef1f5; cursor: pointer; }
.wk-cell:nth-child(even) { border-top-color: var(--line); }
.wk-cell:hover { background: var(--best-bg); }

.wk-block {
    position: absolute; left: 2px; right: 2px; background: var(--primary);
    color: #fff; border-radius: 6px; padding: 1px 5px; font-size: .68rem;
    line-height: 1.25; cursor: pointer; overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
    display: flex; align-items: center; justify-content: space-between; gap: 4px; z-index: 2;
}
.wk-block:hover { background: var(--primary-dark); }
.wk-block-t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk-block-x { opacity: .85; flex: none; }

/* --- Vue mois --- */
.mo-head, .mo-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.mo-head { background: #fafbfc; border: 1px solid var(--line); border-bottom: 0;
    border-radius: 10px 10px 0 0; }
.mo-head div { text-align: center; padding: 8px 2px; font-size: .72rem; color: var(--muted); }
.mo-grid { border: 1px solid var(--line); border-radius: 0 0 10px 10px; overflow: hidden; }
.mo-day {
    background: #fff; border: 0; border-top: 1px solid var(--line); border-left: 1px solid var(--line);
    min-height: 64px; padding: 6px 8px; text-align: left; font-weight: 600; cursor: pointer;
    font-size: .9rem; color: var(--ink);
}
.mo-day:nth-child(7n+1) { border-left: 0; }
.mo-day:hover { background: var(--best-bg); }
.mo-day.out { color: #c2c9d2; background: #fcfcfd; }
.mo-day.today { box-shadow: inset 0 0 0 2px var(--primary); }
.mo-day.sel { background: var(--primary); color: #fff; }
.mo-hint { font-size: .82rem; color: var(--muted); margin: 10px 2px 0; }

/* --- Compteur --- */
.slot-counter { margin-top: 12px; font-weight: 600; color: var(--yes); }
.slot-counter.empty { color: var(--muted); }
.slot-counter.error { color: var(--no); }

@media (max-width: 640px) {
    /* La grille garde une largeur minimale confortable et défile
       horizontalement DANS son cadre (.wk-hscroll), sans pousser la page. */
    .wk { min-width: 540px; }
    .cal-tz { margin-left: 0; width: 100%; }
    .cal-durations button { padding: 8px 11px; font-size: .85rem; }
}

/* Case à cocher (options de sondage / finalisation) */
label.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 600; }
label.check input { margin-top: 3px; width: auto; }
.hint { font-weight: 400; color: var(--muted); font-size: .85rem; }
.winners { margin: 6px 0; padding-left: 20px; }
.finalize-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }

/* Titre éditable (page organisateur) */
.editable-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.title-edit-toggle { font-size: .85rem; }
.rename-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 6px; }
.rename-form input { font-size: 1.2rem; font-weight: 600; padding: 8px 10px;
    border: 1px solid var(--line); border-radius: 8px; min-width: 260px; flex: 1; }

/* Suppression d'un sondage */
.danger-zone {
    margin-top: 32px; padding: 16px; border: 1px solid #f0c2c2;
    border-radius: 10px; background: #fdf5f5;
}
.danger-zone h3 { margin: 0 0 4px; color: var(--no); }
.btn-danger {
    background: var(--no); color: #fff; border: 0; border-radius: 8px;
    padding: 10px 16px; font-weight: 700; cursor: pointer;
}
.btn-danger:hover { filter: brightness(0.93); }

/* Alerte info + suppression d'une réponse (admin) */
.alert.info { background: #eaf4ff; border: 1px solid #b9dcff; color: #0b4a8f; }
.name-cell { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.name-cell .inline-form { display: inline; margin: 0; }
.btn-x {
    border: 0; background: transparent; color: var(--no); cursor: pointer;
    font-size: .95rem; line-height: 1; padding: 2px 4px; border-radius: 4px;
}
.btn-x:hover { background: #fdecec; }

/* Console d'administration globale */
.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px; margin: 18px 0 8px;
}
.stat-card {
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    padding: 16px; text-align: center;
}
.stat-num { font-size: 1.8rem; font-weight: 800; color: var(--primary-dark); line-height: 1; }
.stat-lbl { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.console-table td { vertical-align: top; }
