:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --bg-card: #1e293b;
  --bg-elev: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-d: #4f46e5;

  --available: #22c55e;
  --maybe: #f59e0b;
  --unavailable: #ef4444;
  --partial: #6366f1;
  --unset: #475569;

  --radius: 14px;
  --shadow: 0 4px 16px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow-x: hidden;     /* belt-and-braces: never scroll sideways */
  max-width: 100vw;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: rgba(15,23,42,.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.05rem; white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; }
.nav { display: flex; gap: 4px; margin-left: 8px; flex-shrink: 0; }
.nav a {
  padding: 6px 12px; border-radius: 999px; color: var(--muted); font-size: .9rem;
}
.nav a.active { background: var(--accent); color: #fff; }
.user { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0; min-width: 0; }
.chip {
  padding: 4px 12px; border-radius: 999px; font-size: .85rem; font-weight: 600;
  background: color-mix(in srgb, var(--c) 22%, transparent);
  border: 1px solid var(--c); color: var(--text);
  max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.logout { font-size: 1.2rem; color: var(--muted); padding: 0 4px; }
.logout:hover { color: var(--unavailable); }

.container { max-width: 880px; margin: 0 auto; padding: 16px; }

/* ---- login ---- */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px 28px; box-shadow: var(--shadow);
}
.login-logo { font-size: 3rem; }
.login-card h1 { margin: 8px 0; }
.login-form { display: flex; flex-direction: column; gap: 10px; margin: 22px 0 14px; text-align: left; }
.login-form label { font-size: .85rem; color: var(--muted); }
input, textarea, select {
  width: 100%; padding: 12px 14px; font-size: 1rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }
button {
  cursor: pointer; font-size: 1rem; font-weight: 600;
  background: var(--accent); color: #fff; border: none;
  padding: 12px 16px; border-radius: 10px;
}
button:hover { background: var(--accent-d); }
.alert.error { background: rgba(239,68,68,.15); border: 1px solid var(--unavailable); color: #fecaca; padding: 10px 14px; border-radius: 10px; }

/* ---- calendar head ---- */
.cal-head, .syn-head, .day-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-nav { display: flex; align-items: center; gap: 12px; }
.cal-nav h2 { font-size: 1.2rem; min-width: 160px; text-align: center; }
.btn-icon {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px;
  background: var(--bg-card); border: 1px solid var(--border); font-size: 1.3rem;
}
.btn-icon:hover { background: var(--bg-elev); }
.btn-icon.disabled { opacity: .3; pointer-events: none; }
.view-toggle { display: flex; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.view-toggle a { padding: 8px 14px; font-size: .9rem; color: var(--muted); }
.view-toggle a.active { background: var(--accent); color: #fff; }
.btn-back { color: var(--muted); font-size: .95rem; }

/* ---- legend ---- */
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--muted); margin-bottom: 14px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; flex: none; }

/* status colour mapping */
.status-available  { --sc: var(--available); }
.status-maybe      { --sc: var(--maybe); }
.status-unavailable{ --sc: var(--unavailable); }
.status-partial    { --sc: var(--partial); }
.status-unset      { --sc: var(--unset); }
.dot.status-available { background: var(--available); }
.dot.status-maybe { background: var(--maybe); }
.dot.status-unavailable { background: var(--unavailable); }
.dot.status-partial { background: var(--partial); }
.dot.status-unset { background: var(--unset); }

/* ---- month grid ---- */
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.wd { text-align: center; font-size: .75rem; color: var(--muted); padding-bottom: 4px; }
.cell {
  position: relative; aspect-ratio: 1 / 1; border-radius: 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  padding: 5px; display: flex; flex-direction: column;
  border-left: 4px solid var(--sc, var(--unset));
  transition: transform .08s;
}
.cell.day:hover { transform: translateY(-2px); border-color: var(--accent); }
.cell.empty { background: transparent; border: none; }
.cell.is-today { outline: 2px solid var(--accent); }
.daynum { font-size: .85rem; font-weight: 600; }
.cell { overflow: hidden; }
.cell-dots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
/* One dot per member, coloured by their STATUS (not by person):
   vert = dispo, rouge = pas dispo, violet = peut-être, vide = non renseigné. */
.pdot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: var(--unset);
}
.pdot.st-available   { background: var(--available); }
.pdot.st-maybe       { background: #a855f7; }
.pdot.st-partial     { background: #a855f7; }
.pdot.st-unavailable { background: var(--unavailable); }
.pdot.st-unset       { background: transparent; box-shadow: inset 0 0 0 1.5px var(--border); }
.grp-badge {
  font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 999px;
  background: var(--bg-elev); color: var(--muted); align-self: flex-start; margin-top: auto;
}
.grp-badge.full { background: var(--available); color: #04210f; }
.ev-dot { position: absolute; top: 4px; right: 6px; color: var(--accent); font-size: .7rem; }

/* ---- multi-select ---- */
.hint { margin: 0 0 12px; }
.month-grid { user-select: none; -webkit-user-select: none; }
.month-grid.picking { touch-action: none; }
.cell.day { cursor: pointer; }
.month-grid.picking .cell.day { cursor: copy; }

.select-bar-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.btn-multi {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: 999px; font-size: .9rem; font-weight: 600;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn-multi:hover { background: var(--bg-elev); border-color: var(--accent); }
.btn-multi.on { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 12px color-mix(in srgb, var(--accent) 45%, transparent); }
.bm-icon { font-size: 1.05rem; line-height: 1; }

/* selected day: framed + slightly shrunk, with a check badge */
.cell.sel-pick {
  border-color: var(--accent);
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  transform: scale(.9) !important;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 35%, transparent);
  z-index: 2;
}
.sel-check {
  position: absolute; top: 3px; right: 4px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: .72rem; font-weight: 800; line-height: 18px; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.cell.sel-pick .ev-dot { display: none; }

.sel-bar {
  position: sticky; bottom: 0; z-index: 15; margin-top: 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.sel-count { font-size: .9rem; white-space: nowrap; }
.sel-actions { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.sel-actions .sb { flex: 1; min-width: 78px; }
button:disabled { opacity: .4; cursor: not-allowed; }

/* ---- week list ---- */
.week-list { display: flex; flex-direction: column; gap: 8px; }
.week-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  border-left: 5px solid var(--sc, var(--unset));
}
.week-row.day:hover { border-color: var(--accent); }
.week-row.out { opacity: .45; }
.week-row.is-today { outline: 2px solid var(--accent); }
.wr-date { text-align: center; min-width: 46px; }
.wr-wd { display: block; font-size: .7rem; color: var(--muted); }
.wr-num { display: block; font-size: 1.4rem; font-weight: 700; line-height: 1; }
.wr-mon { display: block; font-size: .65rem; color: var(--muted); }
.wr-body { display: flex; flex-direction: column; gap: 4px; }

/* ---- day detail ---- */
.day-head { margin-bottom: 18px; }
.day-head h2 { font-size: 1.3rem; }
.slot-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.slot-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.slot-head h3 { font-size: 1.05rem; }

.status-btns { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.sb {
  background: var(--bg); border: 1px solid var(--border); color: var(--muted);
  font-size: .85rem; padding: 10px 4px; border-radius: 9px; font-weight: 600;
}
.sb.sel { background: var(--sc); border-color: var(--sc); color: #07140a; }
.sb.status-unset.sel { color: var(--text); }
.sb:hover { border-color: var(--sc); color: var(--text); }

.members { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.member {
  display: inline-flex; align-items: center; gap: 6px; font-size: .8rem;
  padding: 4px 10px; border-radius: 999px; background: var(--bg);
  border: 1px solid color-mix(in srgb, var(--sc) 50%, var(--border));
}
.member small { color: var(--muted); }

.events { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.event { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.ev-view { display: flex; justify-content: space-between; gap: 10px; }
.ev-main p { margin: 4px 0; }
.ev-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.ev-edit { display: flex; flex-direction: column; gap: 8px; }
.link { background: none; color: var(--accent); padding: 2px 4px; font-size: .82rem; font-weight: 600; }
.link:hover { background: none; text-decoration: underline; }
.link.danger { color: var(--unavailable); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; align-items: center; }
.btn-sm { padding: 8px 14px; font-size: .88rem; }

.add-event summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .9rem; padding: 4px 0; }
.add-event form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.lock { margin: 4px 0 0; }

/* ---- day popup (modal) ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(2,6,23,.7); backdrop-filter: blur(3px);
  padding: 0;
}
.modal-card {
  position: relative; width: 100%; max-width: 560px;
  max-height: 92vh; overflow-y: auto;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 20px 18px 28px;
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
  animation: sheet-up .22s ease;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg-elev); color: var(--text); border: 1px solid var(--border);
  font-size: 1rem; padding: 0; display: grid; place-items: center;
}
.modal-close:hover { background: var(--unavailable); border-color: var(--unavailable); }
.modal-loading { padding: 40px; text-align: center; color: var(--muted); }
.day-modal-head { margin: 0 40px 16px 4px; }
.day-modal-head h2 { font-size: 1.25rem; }

@media (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 20px; }
  .modal-card { border-radius: 20px; }
}

/* ---- synthesis ---- */
.filter { display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.filter select { width: auto; padding: 8px 10px; }
.best-banner { background: rgba(34,197,94,.14); border: 1px solid var(--available); color: #bbf7d0; padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; }
.syn-list { display: flex; flex-direction: column; gap: 8px; }
.syn-row { display: flex; align-items: center; gap: 14px; padding: 12px 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; }
.syn-row:hover { border-color: var(--accent); }
.syn-row.full { border-color: var(--available); background: rgba(34,197,94,.08); }
.syn-date { text-align: center; min-width: 46px; }
.sd-wd { display: block; font-size: .7rem; color: var(--muted); }
.sd-num { display: block; font-size: 1.4rem; font-weight: 700; line-height: 1; }
.sd-mon { display: block; font-size: .65rem; color: var(--muted); }
.sd-slot { display: block; font-size: .62rem; color: var(--accent); margin-top: 2px; }
.syn-bar-wrap { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.syn-bar { height: 8px; background: var(--bg-elev); border-radius: 999px; overflow: hidden; }
.syn-fill { height: 100%; background: var(--maybe); border-radius: 999px; }
.syn-fill.full { background: var(--available); }
.syn-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.missing { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; color: var(--muted); }

@media (max-width: 560px) {
  .topbar { gap: 6px; padding: 10px 12px; }
  .nav { margin-left: 2px; gap: 2px; }
  .nav a { padding: 6px 9px; font-size: .85rem; }
  .brand { font-size: .92rem; }
  .chip { max-width: 84px; padding: 4px 9px; }
  .cal-nav h2 { min-width: 110px; font-size: 1.05rem; }
  .cell { padding: 3px; border-radius: 8px; }
  .daynum { font-size: .78rem; }
  .grp-badge { font-size: .6rem; padding: 1px 4px; }
  .month-grid { gap: 4px; }
  .cell-dots { gap: 2px; margin-top: 2px; }
  .pdot { width: 7px; height: 7px; }
  .container { padding: 12px; }
  /* keep the 4 status buttons readable on narrow phones */
  .status-btns { gap: 4px; }
  .sb { padding: 9px 2px; font-size: .8rem; }
}
@media (max-width: 360px) {
  .brand span.brand-text { display: none; } /* icon only on very small screens */
  .status-btns { grid-template-columns: repeat(2, 1fr); }
}
