:root {
  --bg: #FBF9F3;
  --ink: #1C2B33;
  --ink-soft: #7C8A83;
  --line: #ECE9DE;
  --card-bg: #FFFFFF;
  --field-bg: #FFFFFF;
  --field-border: #E4E1D5;
  --chip-bg: #F0EEE4;
  --accent: #23577A;
  --accent-ink: #FFFFFF;
  --danger: #A24B3B;
  --ok: #4F7A5A;
  --ok-bg: #E4F0E6;

  --p-morel: #8FBBE0;
  --p-petit: #EE9992;
  --p-lt: #F0D077;
  --p-roussel: #8FCBA2;
  --p-camille: #BFA6DE;
  --p-nadia: #82CFC7;
  --p-6: #E8AACB;
  --p-7: #ABB9C7;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12191B;
    --ink: #E9EDEA;
    --ink-soft: #93A19C;
    --line: #263133;
    --card-bg: #182124;
    --field-bg: #182124;
    --field-border: #2C383B;
    --chip-bg: #1E2A2D;
    --accent: #7FB2CC;
    --accent-ink: #10181A;
    --ok-bg: #1B2C21;
  }
}

.p-morel { background: var(--p-morel); }
.p-petit { background: var(--p-petit); }
.p-lt { background: var(--p-lt); }
.p-roussel { background: var(--p-roussel); }
.p-camille { background: var(--p-camille); }
.p-nadia { background: var(--p-nadia); }
.p-6 { background: var(--p-6); }
.p-7 { background: var(--p-7); }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
}
input, textarea {
  font-family: inherit;
  color: inherit;
}

.field-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 7px;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 16px;
  padding: 16px;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
}
.btn-primary:active { opacity: 0.85; }

.icon-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--chip-bg); color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  flex: none;
}

.form-error {
  font-size: 12.5px; font-weight: 600; color: var(--danger);
  margin: 0 0 12px;
}

/* ---------- access gate ---------- */
.gate {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.gate-card {
  width: 100%; max-width: 360px;
  text-align: center;
}
.eyebrow {
  font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-soft); font-weight: 700; margin: 0 0 10px;
}
.gate-title {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 34px; font-weight: 600; margin: 0 0 28px;
}
.gate-input-row {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--field-border); border-radius: 14px;
  padding: 4px 6px 4px 16px; background: var(--field-bg);
  margin-bottom: 14px;
}
#gate-code {
  flex: 1; border: none; background: none; outline: none;
  font-size: 15px; padding: 10px 0; color: var(--ink);
  min-width: 0;
}
.gate-card form { text-align: left; }

/* ---------- app shell ---------- */
.app { max-width: 480px; margin: 0 auto; padding: 0 0 100px; position: relative; min-height: 100vh; }

.app-header { padding: 20px 20px 14px; text-align: center; }
.app-eyebrow {
  font-size: 10.5px; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--ink-soft); font-weight: 700; margin: 0 0 4px;
}
.app-title {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 26px; font-weight: 600; margin: 0;
}

.view-toggle {
  display: flex; gap: 4px; width: fit-content; margin: 0 auto 6px;
  background: var(--chip-bg); border-radius: 12px; padding: 3px;
}
.view-btn {
  padding: 7px 16px; border-radius: 9px; font-size: 12.5px; font-weight: 700;
  color: var(--ink-soft);
}
.view-btn.is-active { background: var(--card-bg); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.month-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 22px 14px;
}
.month-label { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; text-transform: capitalize; }
.nav-btn {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--chip-bg); color: var(--ink);
}

.weekday-row {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 0 14px; margin-bottom: 4px;
}
.weekday-row span {
  text-align: center; font-size: 10.5px; font-weight: 700;
  color: var(--ink-soft); letter-spacing: 0.03em;
}

.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 0 14px; row-gap: 4px;
}
.cell {
  position: relative;
  height: 50px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.cell.muted { color: var(--ink-soft); opacity: 0.5; font-weight: 500; }
.cell.clickable { cursor: pointer; }
.cell.clickable:active { opacity: 0.8; }
.cell .num { position: relative; z-index: 2; }
.cell .tag {
  position: relative; z-index: 2;
  font-size: 7px; font-weight: 800; letter-spacing: 0.04em;
  text-transform: uppercase; color: rgba(28, 43, 51, 0.75);
  margin-top: 1px; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cell .fill { position: absolute; inset: 2px 0; z-index: 1; }
.cell.start .fill { left: 2px; border-radius: 11px 0 0 11px; }
.cell.end .fill { right: 2px; border-radius: 0 11px 11px 0; }
.cell.solo .fill { left: 2px; right: 2px; border-radius: 11px; }
.cell.start .num, .cell.end .num, .cell.mid .num, .cell.solo .num { color: var(--ink); }

.cell.today .num::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--ink);
}

.cell.multi .num {
  position: absolute; top: 3px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--ink); z-index: 3;
}
.cell.multi .lane { position: absolute; height: 6px; z-index: 1; }
.lane.multi-start { left: 2px; right: 0; border-radius: 4px 0 0 4px; }
.lane.multi-end { left: 0; right: 2px; border-radius: 0 4px 4px 0; }
.lane.multi-mid { left: 0; right: 0; }
.count-badge {
  position: absolute; top: -5px; right: -3px; z-index: 4;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); color: var(--bg); font-size: 8px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--bg);
}

.year-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px;
  padding: 4px 16px 8px;
}
.mini-month {
  background: var(--card-bg); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px; cursor: pointer;
}
.mini-month:active { opacity: 0.85; }
.mini-month-label {
  font-size: 11.5px; font-weight: 700; text-transform: capitalize;
  text-align: center; margin: 0 0 8px;
}
.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini-cell { aspect-ratio: 1; border-radius: 2px; background: var(--chip-bg); }
.mini-cell.out { background: transparent; }
.mini-cell.today { outline: 1.5px solid var(--ink); outline-offset: -1.5px; }

.legend-block { border-top: 1px solid var(--line); margin-top: 12px; }
.legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 14px 20px 4px;
}
.legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; color: var(--ink-soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.section-label {
  padding: 18px 20px 8px; font-size: 11px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft);
}
.empty-note { padding: 4px 20px 8px; font-size: 13px; color: var(--ink-soft); }

.stay-list { padding: 0 16px; display: flex; flex-direction: column; gap: 8px; }
.stay-card {
  display: flex; align-items: center; gap: 11px;
  background: var(--card-bg); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px; cursor: pointer;
}
.stay-card:active { opacity: 0.85; }
.stay-note {
  font-size: 11.5px; color: var(--ink-soft); margin-top: 3px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px;
}
.stay-bar { width: 4px; align-self: stretch; border-radius: 3px; flex: none; }
.stay-body { flex: 1; min-width: 0; }
.stay-name { font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.now-pill {
  font-size: 8.5px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase;
  background: var(--ink); color: var(--bg); padding: 2px 6px; border-radius: 20px;
}
.stay-dates { font-size: 11.5px; color: var(--ink-soft); margin-top: 1px; font-variant-numeric: tabular-nums; }
.stay-meta { font-size: 11px; color: var(--ink-soft); flex: none; }
.stay-delete {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-soft);
}
.stay-delete:active { background: var(--chip-bg); }

.fab {
  position: fixed; right: max(20px, calc(50% - 240px + 20px)); bottom: 22px; z-index: 10;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 22px -6px rgba(35,87,122,0.5);
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 27, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 20; padding: 0;
}
.modal {
  width: 100%; max-width: 480px; max-height: 92vh;
  background: var(--bg); border-radius: 24px 24px 0 0;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px 10px;
}
.modal-header h2 {
  font-family: Georgia, "Iowan Old Style", serif; font-size: 20px; font-weight: 600; margin: 0;
}
.modal-body { padding: 4px 20px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.modal-body input[type="text"],
.modal-body input[type="date"] {
  width: 100%; border: 1px solid var(--field-border); border-radius: 14px;
  padding: 12px 14px; font-size: 15px; background: var(--field-bg); color: var(--ink);
  outline: none;
}
.date-row { display: flex; gap: 10px; }
.date-row > div { flex: 1; }

.avail-note { display: flex; align-items: flex-start; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ok); margin: -6px 0 0; }
.avail-note.busy { color: var(--ink-soft); }
.avail-dot {
  width: 16px; height: 16px; border-radius: 50%; background: var(--ok-bg);
  display: flex; align-items: center; justify-content: center; flex: none; margin-top: 1px;
}
.avail-note.busy .avail-dot { background: var(--chip-bg); }

.stepper {
  display: flex; align-items: center; gap: 16px;
  border: 1px solid var(--field-border); border-radius: 14px;
  padding: 10px 16px; background: var(--field-bg); width: fit-content;
}
.step-btn {
  width: 28px; height: 28px; border-radius: 50%; background: var(--chip-bg);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px;
}
.step-val { font-size: 15px; font-weight: 700; min-width: 18px; text-align: center; font-variant-numeric: tabular-nums; }

.modal-body textarea {
  width: 100%; border: 1px solid var(--field-border); border-radius: 14px;
  padding: 12px 14px; font-size: 13px; font-family: inherit; color: var(--ink);
  resize: none; height: 64px; background: var(--field-bg); outline: none;
}
.modal-body textarea::placeholder { color: var(--ink-soft); opacity: 0.7; }

.btn-danger-text {
  width: 100%; text-align: center; padding: 6px 0 4px;
  color: var(--danger); font-size: 13px; font-weight: 600;
}

.day-modal .modal-body,
.day-modal .day-modal-list { padding: 4px 20px 24px; }

@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 24px; max-height: 86vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
