:root {
  color-scheme: dark;
  --bg: #2a1b14;
  --bg-card: #3a2620;
  --bg-cell: #33211b;
  --fg: #f5e6d5;
  --muted: #b8a491;
  --border: #4a332a;
  --accent: #e07840;
  --best: #f2b632;
  --ok: #7ec88a;
  --danger: #e0674a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: radial-gradient(circle at 20% 0%, #4a2a1d 0%, var(--bg) 60%);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

main { max-width: 960px; margin: 0 auto; padding: 2rem 1rem 4rem; }
a { color: var(--accent); }

h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 0 0 0.35rem; letter-spacing: -0.01em; overflow-wrap: anywhere; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
.tagline, .desc { color: var(--muted); line-height: 1.5; margin: 0 0 0.5rem; overflow-wrap: anywhere; }
.brand { color: var(--muted); text-decoration: none; font-size: 0.9rem; display: inline-block; margin-bottom: 1.25rem; }
.brand:hover { color: var(--fg); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card-admin { border-color: var(--accent); }

.field { margin-bottom: 1rem; }
.field label, .field-label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }
.field input, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-family: inherit;
  font-size: 1rem;
}
.field textarea { resize: vertical; min-height: 4rem; }
.field-hint { font-size: 0.8rem; color: var(--muted); margin: 0.3rem 0 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  font-weight: 600;
  font-size: 0.9rem;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #1a1a1a; }
.btn-primary:hover:not(:disabled) { opacity: 0.9; }
.btn-secondary { background: transparent; border: 1px solid var(--border); color: var(--fg); }
.btn-secondary:hover:not(:disabled) { border-color: var(--muted); }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(224, 103, 74, 0.12); }
.btn-small { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
a.btn-primary, a.btn-secondary { display: inline-block; border-radius: 8px; font-weight: 600; text-decoration: none; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 500; text-decoration: underline; }

.row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.error-banner, .info-banner {
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.error-banner { background: rgba(224, 103, 74, 0.12); border: 1px solid var(--danger); color: #f5c9bd; }
.info-banner { background: rgba(126, 200, 138, 0.1); border: 1px solid var(--ok); color: #cdeed3; }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  border: 1px solid;
}
.badge-open { color: var(--ok); border-color: var(--ok); }
.badge-closed { color: var(--best); border-color: var(--best); }

/* --- Sélecteur d'avatar --- */
.avatar-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr)); gap: 0.35rem; }
.avatar-option {
  font-size: 1.5rem;
  line-height: 1;
  padding: 0.35rem 0;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 10px;
}
.avatar-option:hover { border-color: var(--border); }
.avatar-option.selected { border-color: var(--accent); background: rgba(224, 120, 64, 0.18); }
.avatar-option.taken { opacity: 0.35; }

/* --- Lien de partage --- */
.share-box { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.share-box input {
  flex: 1 1 14rem;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
}

/* --- Calendrier --- */
.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.75rem; }
.cal-nav h2 { margin: 0; text-align: center; flex: 1; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-weekday { text-align: center; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding-bottom: 0.2rem; }
.cal-cell {
  position: relative;
  min-height: 5.2rem;
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem;
  display: flex;
  flex-direction: column;
  text-align: left;
  color: var(--fg);
  font-weight: 400;
}
button.cal-cell:hover:not(:disabled) { border-color: var(--muted); }
.cal-cell:disabled { cursor: default; opacity: 1; }
.cal-cell.empty { background: transparent; border: none; }
.cal-cell.out { opacity: 0.3; }
.cal-cell.today .cal-day { color: var(--accent); font-weight: 700; }
.cal-cell.mine { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-cell.best { border-color: var(--best); box-shadow: 0 0 0 2px var(--best) inset; }
.cal-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.78rem; }
.cal-day { color: var(--muted); }
.cal-count {
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0 0.4rem;
  background: rgba(224, 120, 64, 0.25);
}
.cal-cell.best .cal-count { background: var(--best); color: #2a1b14; }
.cal-avatars { display: flex; flex-wrap: wrap; gap: 1px; margin-top: 0.2rem; align-content: flex-start; }
.avatar {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  position: relative;
  font-size: 1.15rem;
  line-height: 1.2;
  cursor: pointer;
}
.hover-only { display: inline; }
.touch-only { display: none; }
@media (hover: none) {
  .hover-only { display: none; }
  .touch-only { display: inline; }
}
.day-person { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.day-person:last-child { border-bottom: none; }
.day-person .popup-label { display: block; margin: 0.5rem 0 0.2rem; color: var(--muted); font-size: 0.78rem; }
.day-person textarea { width: 100%; box-sizing: border-box; min-height: 3.2rem; resize: vertical; }
.more {
  background: rgba(224, 120, 64, 0.25);
  border-radius: 999px;
  padding: 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  align-self: center;
  padding: 0 0.15rem;
  cursor: help;
}
.cal-legend { font-size: 0.8rem; color: var(--muted); margin-top: 0.75rem; display: flex; gap: 1rem; flex-wrap: wrap; }
.legend-swatch { display: inline-block; width: 0.9rem; height: 0.9rem; border-radius: 4px; vertical-align: -0.15rem; margin-right: 0.3rem; }

/* --- Meilleurs jours / participant·es --- */
.best-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.best-list button { background: none; border: none; color: var(--fg); padding: 0; text-align: left; font-weight: 400; font-size: 0.95rem; }
.best-list button:hover strong { text-decoration: underline; }
.people { list-style: none; margin: 0; padding: 0; }
.people li { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.people li:last-child { border-bottom: none; }
.person { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.person-avatar { font-size: 1.4rem; }
.avatar-badge {
  position: absolute;
  top: -2px;
  right: -4px;
  min-width: 0.8rem;
  height: 0.8rem;
  border-radius: 999px;
  background: var(--accent);
  color: #1a1a1a;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 0.8rem;
  text-align: center;
  pointer-events: none;
}
.day-popup {
  position: fixed;
  z-index: 50;
  width: min(19rem, calc(100vw - 1rem));
  background: var(--bg-card);
  color: var(--fg);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  font-size: 0.85rem;
}
.day-popup h4 { margin: 0 0 0.5rem; font-size: 0.9rem; }
.day-popup .field-hint { margin: 0.25rem 0; }
.day-popup input, .day-popup textarea { width: 100%; box-sizing: border-box; }
.day-popup textarea { min-height: 3.2rem; resize: vertical; }
.day-popup .popup-label { display: block; margin: 0.6rem 0 0.2rem; color: var(--muted); font-size: 0.78rem; }

.slot-day { padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.slot-day:last-child { border-bottom: none; }
.slot-row { display: flex; align-items: center; gap: 0.4rem; margin: 0.35rem 0; flex-wrap: wrap; }
.slot-row select { width: auto; }
.person-slots { font-size: 0.8rem; color: var(--muted); }
.person-slots summary { cursor: pointer; }
.person-meta { color: var(--muted); font-size: 0.8rem; overflow-wrap: anywhere; }
.people li.editing-target { background: rgba(224, 120, 64, 0.1); border-radius: 8px; padding-left: 0.5rem; padding-right: 0.5rem; }

.me-line { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.me-avatar { font-size: 2rem; }

.empty-state { color: var(--muted); text-align: center; padding: 1.5rem 1rem; }

table.admin-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.table-scroll { overflow-x: auto; }

footer { border-top: 1px solid var(--border); padding-top: 1.5rem; margin-top: 2rem; text-align: center; color: var(--muted); font-size: 0.85rem; }
footer a { color: var(--fg); text-decoration: none; border-bottom: 1px dashed var(--muted); }

@media (max-width: 600px) {
  main { padding: 1.25rem 0.75rem 3rem; }
  .card { padding: 1rem; }
  .cal-grid { gap: 2px; }
  .cal-cell { min-height: 4.4rem; padding: 0.15rem; border-radius: 6px; }
  .avatar { font-size: 0.95rem; }
  .cal-count { font-size: 0.65rem; padding: 0 0.3rem; }
}
