:root {
  --ink: #15100e;
  --paper: #241c19;
  --paper-2: #2c2320;
  --line: #423531;
  --text: #f3ece4;
  --muted: #a89686;
  --rope: #bd7f3f;
  --rope-dark: #96632f;
  --bamboo: #7f9a6c;
  --bamboo-dark: #5f7a4f;
  --danger: #8c4234;
  --ok: #7f9a6c;
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Noto Serif", serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 1.2rem;
  background: var(--ink);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--rope-dark); color: var(--text); }

/* Dark-themed scrollbar so it doesn't clash with the ink background */
* { scrollbar-color: var(--line) var(--ink); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--ink); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--rope-dark); }

/* Faint bamboo grove silhouette, bottom-right, purely decorative */
body::before {
  content: "";
  position: fixed;
  right: -4vw;
  bottom: -4vh;
  width: min(70vw, 620px);
  height: min(70vw, 620px);
  pointer-events: none;
  z-index: -1;
  opacity: 0.09;
  background-repeat: no-repeat;
  background-position: bottom right;
  background-size: contain;
  background-image: url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'>\
<g fill='none' stroke='%237f9a6c' stroke-width='6' stroke-linecap='round'>\
  <line x1='60' y1='400' x2='60' y2='40'/>\
  <line x1='60' y1='120' x2='34' y2='96'/>\
  <line x1='60' y1='200' x2='88' y2='176'/>\
  <line x1='60' y1='280' x2='34' y2='256'/>\
  <line x1='140' y1='400' x2='140' y2='90'/>\
  <line x1='140' y1='170' x2='112' y2='146'/>\
  <line x1='140' y1='250' x2='168' y2='226'/>\
  <line x1='140' y1='330' x2='112' y2='306'/>\
  <line x1='230' y1='400' x2='230' y2='10'/>\
  <line x1='230' y1='90' x2='202' y2='66'/>\
  <line x1='230' y1='170' x2='258' y2='146'/>\
  <line x1='230' y1='250' x2='202' y2='226'/>\
  <line x1='230' y1='330' x2='258' y2='306'/>\
  <line x1='320' y1='400' x2='320' y2='130'/>\
  <line x1='320' y1='210' x2='292' y2='186'/>\
  <line x1='320' y1='290' x2='348' y2='266'/>\
</g>\
<g stroke='%237f9a6c' stroke-width='6'>\
  <line x1='44' y1='120' x2='76' y2='120'/>\
  <line x1='44' y1='200' x2='76' y2='200'/>\
  <line x1='44' y1='280' x2='76' y2='280'/>\
  <line x1='124' y1='170' x2='156' y2='170'/>\
  <line x1='124' y1='250' x2='156' y2='250'/>\
  <line x1='124' y1='330' x2='156' y2='330'/>\
  <line x1='214' y1='90' x2='246' y2='90'/>\
  <line x1='214' y1='170' x2='246' y2='170'/>\
  <line x1='214' y1='250' x2='246' y2='250'/>\
  <line x1='214' y1='330' x2='246' y2='330'/>\
  <line x1='304' y1='210' x2='336' y2='210'/>\
  <line x1='304' y1='290' x2='336' y2='290'/>\
</g>\
</svg>");
}

.wrap { max-width: 640px; margin: 0 auto; position: relative; }

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin: 0.3rem 0 1.6rem;
}
.brand svg { flex: none; opacity: 0.9; }
h1 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Noto Serif", serif;
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: 0.015em;
  line-height: 1.2;
  margin: 0;
  color: var(--text);
}

h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Noto Serif", serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  margin: 1.8rem 0 0.7rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
h2::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, var(--line), transparent);
}

/* Booking-modal heading: the date/time being booked, so it needs to read
   as the headline of the sheet, not a muted section label like other h2s. */
h2.modal-date {
  color: var(--rope);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.3;
}
h2.modal-date::after { content: none; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 3px solid var(--bamboo-dark);
  border-radius: 4px 10px 10px 4px;
  padding: 1rem;
  margin-bottom: 0.8rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: border-left-color 0.15s ease, box-shadow 0.15s ease;
}
.card:hover {
  border-left-color: var(--rope);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
}

.slot-date {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: var(--rope);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 1.6rem 0 0.5rem;
}
.slot-date::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--rope);
  flex: none;
}

.slot-row { display: flex; justify-content: space-between; align-items: center; gap: 0.8rem; }
@media (max-width: 420px) {
  /* Stack time/note above the button instead of squeezing them side by side,
     so "Réserver" always gets a full-width, easy-to-hit tap target. */
  .slot-row { flex-direction: column; align-items: stretch; }
  .slot-row button { width: 100%; }
}
.slot-time { font-size: 1.15rem; font-weight: 600; font-family: "Iowan Old Style", Georgia, serif; letter-spacing: 0.01em; }
.slot-note { color: var(--muted); font-size: 0.85rem; margin-top: 0.3rem; line-height: 1.45; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

button, input, textarea {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  color: inherit;
}

button {
  background: var(--rope);
  border: none;
  color: #1c140c;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
button:hover { background: var(--rope-dark); color: var(--text); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3); }
button:active { transform: translateY(0); box-shadow: none; }
button:disabled { opacity: 0.6; cursor: default; transform: none; box-shadow: none; }
button.secondary { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.secondary:hover { background: var(--paper-2); }
button.danger { background: var(--danger); color: var(--text); }
button.danger:hover { background: #6f3327; }

button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--bamboo);
  outline-offset: 2px;
}

input, textarea {
  width: 100%;
  /* Without this, the native date/time picker widget can render at its own
     comfortable minimum width and spill past the card's edge on a phone —
     block-level width:100% alone doesn't stop that on some mobile browsers. */
  min-width: 0;
  max-width: 100%;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  margin-top: 0.3rem;
  transition: border-color 0.15s ease;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--bamboo);
}
input[type="date"], input[type="time"] {
  padding-left: 0.5rem;
  padding-right: 0.4rem;
  /* A date/time value is a handful of characters — no reason for the box to
     stretch across the whole card the way the free-text note field should.
     Caps the width instead of setting it outright, so it still shrinks
     safely on narrow phones (via the inherited width:100%) rather than
     ever overflowing. */
}
input[type="date"] { max-width: 10rem; }
input[type="time"] { max-width: 7rem; }

label { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 0.7rem; letter-spacing: 0.01em; }

.weekday-picker { display: flex; gap: 0.4rem; margin-top: 0.4rem; }
.weekday-picker label {
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0.4rem 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.weekday-picker input { width: auto; margin: 0; accent-color: var(--rope); }
.weekday-picker label:has(input:checked) { border-color: var(--rope); color: var(--rope); }

.empty {
  color: var(--muted);
  text-align: center;
  padding: 3rem 1rem;
  font-family: "Iowan Old Style", Georgia, serif;
  font-style: italic;
}

.gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  max-width: 320px;
  margin: 3.5rem auto;
  text-align: center;
  animation: fadeUp 0.35s ease both;
}
.gate svg { opacity: 0.85; margin-bottom: 0.3rem; }
.gate p { font-family: "Iowan Old Style", Georgia, serif; color: var(--muted); line-height: 1.5; }
.gate input {
  text-align: center;
  letter-spacing: 0.08em;
  font-size: 1.05rem;
}
.gate button { width: 100%; padding: 0.65rem 1.1rem; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 7, 6, 0.7);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 10;
  animation: fadeIn 0.2s ease both;
}
.modal {
  background: var(--paper); border: 1px solid var(--line); border-top: 3px solid var(--rope);
  border-radius: 14px 14px 0 0; padding: 1.2rem; width: 100%; max-width: 640px;
  /* Cap height and scroll internally so the confirm/cancel buttons stay reachable
     even when the on-screen keyboard shrinks the visible viewport on a phone.
     dvh (dynamic viewport height) tracks the keyboard on modern mobile browsers;
     vh is the fallback for older ones that don't parse dvh. */
  max-height: 88vh;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(1.2rem + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35);
  animation: slideUp 0.25s ease both;
}
@media (min-width: 480px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); animation: fadeUp 0.25s ease both; }
}

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--bamboo); color: #10160c; padding: 0.6rem 1.1rem; border-radius: 8px;
  font-weight: 600; z-index: 20; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  animation: toastInOut 3s ease both;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastInOut {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, 8px); }
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}
.badge.open { background: #2b3b26; color: #a9c797; }
.badge.booked { background: #3a2620; color: #d19a86; }

.cal { margin-bottom: 0.6rem; }
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.9rem;
}
.cal-header button.secondary {
  padding: 0.3rem 0.75rem;
  line-height: 1;
  font-size: 1.15rem;
}
.cal-title {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Noto Serif", serif;
  font-weight: 600;
  text-transform: capitalize;
  letter-spacing: 0.02em;
  color: var(--text);
}
.cal-weekdays {
  display: grid;
  /* minmax(0, 1fr), not bare 1fr: a bare 1fr track has an implicit min-width
     of "auto" (its content's min-content size), so it refuses to shrink below
     that and can push the grid wider than the screen. minmax(0, 1fr) lets
     columns actually shrink to fit narrow phone widths. */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  text-align: center;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 0.3rem; }
.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: manipulation;
  min-width: 0;
}
.cal-day.empty { visibility: hidden; }
.cal-day .num {
  width: 78%;
  height: 78%;
  max-width: 2.2rem;
  max-height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 360px) {
  body { padding: 0.8rem; }
  .cal-grid, .cal-weekdays { gap: 0.15rem; }
  .cal-day .num { font-size: 0.8rem; }
  .weekday-picker { gap: 0.25rem; }
  .weekday-picker label { font-size: 0.75rem; }
  input[type="date"], input[type="time"] { font-size: 0.9rem; }
}
.cal-day.today .num { box-shadow: inset 0 0 0 2px var(--bamboo); }
.cal-day.has-slots {
  cursor: pointer;
}
.cal-day.has-slots .num {
  background: var(--rope);
  color: #1c140c;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(189, 127, 63, 0.45);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}
.cal-day.has-slots:hover .num { background: var(--rope-dark); color: var(--text); transform: scale(1.08); }
.cal-day.has-slots.today .num { box-shadow: 0 2px 8px rgba(189, 127, 63, 0.45), inset 0 0 0 2px var(--bamboo); }
.cal-day.has-slots.selected .num {
  background: var(--text);
  color: var(--ink);
  box-shadow: 0 0 0 3px var(--rope);
}

/* Admin calendar: every day is clickable (empty day pre-fills the add form),
   and open/booked days get distinct colors so occupancy is visible at a glance. */
.cal-admin .cal-day:not(.empty) { cursor: pointer; }
.cal-admin .cal-day:not(.has-slots):hover .num { background: var(--paper-2); color: var(--text); }
.cal-admin .cal-day:not(.has-slots).selected .num { background: var(--paper-2); color: var(--text); box-shadow: inset 0 0 0 2px var(--line); }

.cal-admin .cal-day.day-open .num { background: var(--bamboo); color: #10160c; box-shadow: 0 2px 8px rgba(127, 154, 108, 0.45); }
.cal-admin .cal-day.day-open:hover .num { background: var(--bamboo-dark); color: var(--text); }
.cal-admin .cal-day.day-open.today .num { box-shadow: 0 2px 8px rgba(127, 154, 108, 0.45), inset 0 0 0 2px var(--rope); }
.cal-admin .cal-day.day-open.selected .num { background: var(--text); color: var(--ink); box-shadow: 0 0 0 3px var(--bamboo); }

.cal-admin .cal-day.day-booked .num { background: var(--danger); color: var(--text); box-shadow: 0 2px 8px rgba(140, 66, 52, 0.45); }
.cal-admin .cal-day.day-booked:hover .num { background: #6f3327; }
.cal-admin .cal-day.day-booked.today .num { box-shadow: 0 2px 8px rgba(140, 66, 52, 0.45), inset 0 0 0 2px var(--bamboo); }
.cal-admin .cal-day.day-booked.selected .num { background: var(--text); color: var(--ink); box-shadow: 0 0 0 3px var(--danger); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
