:root {
  --green: #2f5d50;
  --green-soft: #e3ece8;
  --sand: #faf6ef;
  --card: #ffffff;
  --ink: #1f2a27;
  --muted: #6b7773;
  --line: #e4ddd1;
  --accent: #d0754a;
  --danger: #b23a3a;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--sand);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--sand); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--green); color: #fff;
}
.brand { font-weight: 700; text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.me-btn {
  background: rgba(255,255,255,.15); border: 0; color: #fff; border-radius: 999px;
  padding: 6px 12px; cursor: pointer; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.icon-btn {
  background: transparent; border: 0; cursor: pointer; font-size: 1.15rem;
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; text-decoration: none;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }
.topbar .icon-btn:hover { background: rgba(255,255,255,.15); }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

/* ---------- Écrans simples (mot de passe, identité) ---------- */
.center-card {
  max-width: 380px; margin: 12vh auto 0; background: var(--card);
  border-radius: var(--radius); padding: 24px; box-shadow: 0 2px 12px rgba(0,0,0,.06);
}
.center-card h1 { margin: 0 0 4px; font-size: 1.5rem; text-align: center; }
.center-card p { color: var(--muted); text-align: center; margin: 0 0 20px; }
.logo { font-size: 3rem; text-align: center; }

.field { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background-color: #fff; }
.field:focus { outline: 2px solid var(--green); outline-offset: -1px; }
.btn {
  border: 0; border-radius: 10px; padding: 12px 16px; cursor: pointer;
  background: var(--green); color: #fff; font-weight: 600;
}
.btn.block { width: 100%; margin-top: 10px; }
.btn.ghost { background: var(--green-soft); color: var(--green); }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--danger); text-align: center; min-height: 1.2em; margin-top: 8px; font-size: .9rem; }

.person-list { display: grid; gap: 8px; margin-bottom: 16px; }
.person-list button {
  text-align: left; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.person-list button.current { border-color: var(--green); background: var(--green-soft); }
.inline-form { display: flex; gap: 8px; }
.inline-form .field { flex: 1; min-width: 0; }

/* ---------- Calendrier ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-head h1 { font-size: 1.2rem; margin: 0; text-transform: capitalize; }
.cal-nav { display: flex; gap: 4px; align-items: center; }
.today-btn { background: var(--green-soft); color: var(--green); border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: .85rem; }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-dow { text-align: center; font-size: .75rem; color: var(--muted); font-weight: 600; padding-bottom: 2px; }
.cal-day {
  min-height: 72px; background: var(--card); border: 1px solid transparent; border-radius: 8px;
  padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 3px;
  text-align: left; min-width: 0;
}
.cal-day:hover { border-color: var(--line); }
.cal-day.other { opacity: .4; }
.cal-day.past { background: #f3efe8; }
.cal-day.today { border-color: var(--accent); }
.cal-day .num { font-size: .8rem; font-weight: 600; }
.cal-day.today .num { color: var(--accent); }
.badges { display: flex; flex-wrap: wrap; gap: 2px; }

.badge {
  width: 22px; height: 22px; border-radius: 50%; color: #fff;
  font-size: .62rem; font-weight: 700; display: inline-grid; place-items: center;
  flex-shrink: 0; letter-spacing: -.02em;
}
.badge.more { background: #9aa39f; }
.badge.lg { width: 34px; height: 34px; font-size: .85rem; }

.legend { margin-top: 12px; font-size: .8rem; color: var(--muted); text-align: center; }

@media (min-width: 640px) {
  .cal-day { min-height: 96px; padding: 6px; }
  .badge { width: 26px; height: 26px; font-size: .7rem; }
}

/* ---------- Panneau d'édition d'un jour ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(20,30,27,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--sand); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
}
@media (min-width: 640px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }

.booking { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.booking-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.booking-top .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.del-btn { color: var(--danger); }
.toggles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.toggle { position: relative; }
.toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.toggle span {
  display: block; text-align: center; padding: 9px 4px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font-size: .9rem; user-select: none;
}
.toggle input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); }
.room-row { margin-top: 8px; display: flex; align-items: center; gap: 8px; font-size: .9rem; }
.room-row select { flex: 1; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background-color: #fff; }

.empty { color: var(--muted); text-align: center; padding: 16px 0; }
.section-title {
  margin: 4px 0 8px; font-size: .78rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; display: flex; align-items: center; gap: 6px;
}
.section-title .count {
  background: var(--green-soft); color: var(--green); border-radius: 999px;
  padding: 1px 8px; font-size: .75rem; letter-spacing: 0;
}
.add-section {
  margin-top: 20px; padding: 14px 12px 12px; border: 1.5px dashed #cfc5b4;
  border-radius: var(--radius); background: rgba(255,255,255,.45);
}
.add-section .section-title { margin-top: 0; }
.add-section .muted { margin: 0; }
.add-section select { flex: 1; min-width: 0; }

/* ---------- Réglages ---------- */
.settings h1 { font-size: 1.3rem; margin: 0 0 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }
.list { list-style: none; padding: 0; margin: 0 0 12px; }
.list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list li .name { flex: 1; }
.muted { color: var(--muted); font-size: .9rem; }
.rename-form { flex: 1; display: flex; align-items: center; gap: 4px; min-width: 0; }
.rename-form .field { flex: 1; min-width: 0; padding: 8px 10px; }
.ok-btn { color: var(--green); font-weight: 700; }

/* ---------- Notification ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: .9rem;
}

/* ---------- Champ mot de passe avec bouton « voir » ---------- */
.pw-wrap { position: relative; }
.pw-wrap .field { padding-right: 48px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: 0; background: transparent; border-radius: 8px;
  cursor: pointer; font-size: 1.1rem; opacity: .45; display: grid; place-items: center;
}
.pw-toggle.on { opacity: 1; }
.pw-toggle:hover { background: var(--green-soft); }

/* ---------- Listes déroulantes : flèche personnalisée ---------- */
select {
  -webkit-appearance: none; appearance: none;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b7773' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  padding-right: 36px !important;
  line-height: 1.2;
  cursor: pointer;
}

/* ---------- Vue semaine (petits écrans) ---------- */
.week-title { font-size: 1.05rem !important; text-transform: none !important; }
.week-list { display: grid; gap: 6px; }
.week-day {
  display: flex; align-items: stretch; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid transparent; border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; min-height: 60px; min-width: 0; overflow: hidden;
}
.week-day.past { background: #f3efe8; opacity: .75; }
.week-day.today { border-color: var(--accent); }
.week-date {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 40px; flex-shrink: 0; border-right: 1px solid var(--line); padding-right: 10px;
}
.week-date .wd { font-size: .72rem; color: var(--muted); text-transform: capitalize; font-weight: 600; }
.week-date .dn { font-size: 1.25rem; font-weight: 700; }
.week-day.today .dn, .week-day.today .wd { color: var(--accent); }
.week-people { display: flex; flex-direction: column; justify-content: center; gap: 4px; min-width: 0; flex: 1; }
.wp { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: .92rem; }
.wp-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wp-icons { margin-left: auto; display: grid; grid-template-columns: repeat(3, 20px); flex-shrink: 0; font-size: .85rem; text-align: center; }
.wp-room { font-size: .75rem; color: var(--muted); margin: -2px 0 2px 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.week-list, .week-day > * { min-width: 0; }
.cal-head { gap: 8px; }

/* ---------- Journal ---------- */
.logs h1 { font-size: 1.3rem; margin: 0 0 4px; }
.logs .intro { margin: 0 0 12px; }
.log-group {
  font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .06em; margin: 18px 0 6px;
}
.log-group::first-letter { text-transform: uppercase; }
.log-item {
  display: flex; align-items: flex-start; gap: 10px; background: var(--card);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px;
}
.log-item .badge { margin-top: 1px; }
.log-body { flex: 1; min-width: 0; }
.log-text { font-size: .92rem; line-height: 1.35; }
.log-day { white-space: nowrap; }
.log-time { font-size: .78rem; color: var(--muted); flex-shrink: 0; margin-top: 2px; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chips:empty { display: none; }
.chip { font-size: .76rem; padding: 2px 8px; border-radius: 999px; background: #efeae1; color: var(--ink); }
.chip.add { background: #e1efe6; color: #23633f; }
.chip.del { background: #f6e3e1; color: var(--danger); text-decoration: line-through; text-decoration-thickness: 1px; }
.btn.block + .btn, .logs .btn.block { margin-top: 12px; }

@media (max-width: 400px) {
  .me-btn { max-width: 110px; padding: 6px 10px; }
  .topbar-right { gap: 2px; }
}
