:root {
  --bg: #e6e6e2;          /* page around the agenda */
  --panel: #f1f1ed;       /* agenda background, shows between month days */
  --surface: #ffffff;     /* month days, buttons, boxes */
  --line: #e0e0db;
  --line-strong: #cfcfca;
  --text: #1f1f1d;
  --muted: #66665f;
  --busy: #b4b4ae;
  --free-bar: #ececE8;
  --accent: #2f6fb3;
  --today: #e6effa;
  --now: #d93a2b;
  --avail: #3d9b5c;      /* free mode: bookable slots */
  --feast: #d97706;      /* special dates (birthdays...) in the year view */
  --off: rgba(0, 0, 0, .04);
  --hours-w: 3.2em;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --panel: #262624;
    --surface: #32322f;
    --line: #3a3a37;
    --line-strong: #4b4b47;
    --text: #ececE8;
    --muted: #ababa3;
    --busy: #7a7a74;
    --free-bar: #41413d;
    --accent: #5b9be0;
    --today: #233243;
    --now: #ff6b5b;
    --avail: #48ad6b;
    --feast: #f59e0b;
    --off: rgba(255, 255, 255, .04);
    color-scheme: dark;
  }
}

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

html, body {
  height: 100%;
  margin: 0;
}
body {
  padding: 10px;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .05);
}

/* ---------- Toolbar ---------- */

.bar, .legend, .msg { flex-shrink: 0; }
.app:not(.ready) .bar { visibility: hidden; }   /* until the link is accepted */
.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.bar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  text-align: center;
  text-transform: capitalize;
}
.nav, .opts { display: flex; gap: 6px; }
.links { max-width: 14em; padding-right: .4em; }   /* admin link switcher */

.btn {
  padding: .35em .75em;
  font: inherit;
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .35; cursor: default; }
#prev, #next { font-size: 1.1rem; line-height: 1; padding: .3em .7em; }

/* Rounded by the group, since any of its buttons may be hidden */
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.seg .btn { border-radius: 0; }
.seg .btn + .btn { margin-left: -1px; }
.seg .btn { display: flex; align-items: center; padding: 0 .3em; }
.seg .btn[aria-pressed="true"] { position: relative; z-index: 1; background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
.vicon { display: block; width: 1.6em; }

#view {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ---------- Week ---------- */

.week {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.week-head, .week-body {
  display: grid;
  grid-template-columns: var(--hours-w) repeat(7, minmax(0, 1fr));
}
.week-body {
  flex: 1;
  min-height: 0;
  padding-top: .5em;
}
.day-head {
  padding: 4px 0 6px;
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}
.day-head .num {
  display: inline-block;
  min-width: 1.9em;
  margin-left: .25em;
  padding: .15em .3em;
  font-size: .95rem;
  color: var(--text);
  border-radius: 1em;
}
.day-head.today { color: var(--accent); font-weight: 600; }
.day-head.today .num { color: #fff; background: var(--accent); }
.day-head.off { opacity: .45; }
.wd-short { display: none; }

/* Special dates: icons right-aligned next to the day number */
.feasts { display: inline-flex; gap: 1px; font-size: .9rem; font-weight: 400; line-height: 1; }
.feast { cursor: help; padding-right: 0.2em; }
.cell-top .feasts { font-size: .8rem; }

.hours { display: grid; }
.hour {
  padding-right: 6px;
  font-size: .7rem;
  color: var(--muted);
  text-align: right;
  transform: translateY(-.55em);
}

.day {
  position: relative;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background-image: linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% calc(100% / var(--rows));
}
.day.today { background-color: var(--today); }
.day.off { background-color: var(--off); }

.blk {
  position: absolute;
  left: 2px;
  right: 2px;
  border-radius: 5px;
}
.busy, .period.p2 { background: var(--busy); }
.avail { background: color-mix(in srgb, var(--avail) 88%, transparent); }
/* .period.p1 { background: repeating-linear-gradient(135deg, var(--busy) 0 5px, transparent 5px 10px); opacity: .8; } */
.period.p1 { background: var(--busy); opacity: .6; }

.item {
  --c: var(--busy);
  --pb: 0%;
  --pa: 0%;
  right: auto;
  margin-left: 2px;
  padding: 0 4px;
  overflow: hidden;
  font-size: .72rem;
  line-height: 1.25;
  border-radius: 4px;
  background: linear-gradient(to bottom,
    color-mix(in srgb, var(--c) 35%, transparent) 0 var(--pb),
    var(--c) var(--pb) calc(100% - var(--pa)),
    color-mix(in srgb, var(--c) 35%, transparent) calc(100% - var(--pa)));
  box-shadow: 0 0 0 1px var(--panel);
}

.now {
  position: absolute;
  left: -1px;
  right: 0;
  z-index: 2;
  height: 2px;
  background: var(--now);
  pointer-events: none;
}
.now::before {
  content: "";
  position: absolute;
  left: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  background: var(--now);
  border-radius: 50%;
}

/* ---------- Month ---------- */

.month {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}
.month-head, .month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
}
.month-head div {
  padding-bottom: 6px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}
.month-grid { flex: 1; min-height: 0; }

.cell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 3px;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
button.cell { cursor: pointer; }
button.cell:hover { border-color: var(--muted); }
.cell-top {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 2px;
}
.cell .num {
  margin-left: 2px;
  font-size: .75rem;
}
.cell.mark .num::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 4px;
  vertical-align: middle;
  background: var(--mark, var(--accent));
  border-radius: 50%;
}
.cell.today { border: 2px solid var(--accent); }
.cell.today .num { color: var(--accent); font-weight: 700; }
.cell.other { opacity: .45; }
.cell.off { background: var(--off); }
.cell.off .bars, .cell.weekend .bars { visibility: hidden; }

.bars {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}
.pbar { flex-basis: 0; min-height: 2px; background: var(--free-bar); border-radius: 2px; }
/* .pbar.p1 { background: repeating-linear-gradient(135deg, var(--busy) 0 4px, var(--free-bar) 4px 8px); } */
.pbar.p1 { background: var(--busy); opacity: .6; }
.pbar.p2 { background: var(--busy); }
.pbar.avail { background: var(--avail); }
/* Free slots already gone (only visible with weeks before): same lighter look as the days of another month */
.avail.past { opacity: .45; }

/* ---------- Year ---------- */

.year {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 10px 14px;
  min-width: 0;
  min-height: 0;
}
.mini {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 6px 8px 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.mini-name {
  margin-bottom: 4px;
  font-size: .8rem;
  font-weight: 600;
  text-transform: capitalize;
}
.mini-grid {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  gap: 2px;
  min-height: 0;
}
.mini-wd {
  align-self: center;
  font-size: .6rem;
  color: var(--muted);
  text-align: center;
}
.yd {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0;
  font: inherit;
  font-size: .68rem;
  color: var(--text);
  background: none;
  border: 0;
  border-radius: 4px;
}
button.yd { cursor: pointer; }
button.yd:hover { background: var(--free-bar); }
.yd.mark, button.yd.mark:hover { font-weight: 600; color: #fff; background: var(--mark, var(--accent)); }
button.yd.mark:hover { filter: brightness(.9); }
.yd.today { box-shadow: inset 0 0 0 1.5px var(--accent); }
.yd.feast { font-weight: 700; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--feast); }
.yd.feast.today { box-shadow: inset 0 0 0 1.5px var(--feast), 0 0 0 1.5px var(--accent); }
.yd.off { opacity: .35; }

@media (max-width: 900px) {
  .year { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(4, minmax(0, 1fr)); }
}

/* ---------- Booking form (availability mode) ---------- */

.booking .week .avail:not(.past) { cursor: pointer; }
.booking .week .avail:not(.past):hover { filter: brightness(1.08); }
.legend .hint { color: var(--avail); font-weight: 600; }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn.primary:disabled { opacity: .5; }

.book {
  width: calc(100% - 32px);
  max-width: 27em;
  padding: 18px 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.book::backdrop { background: rgba(0, 0, 0, .35); }
.book h2 { margin: 0 0 2px; font-size: 1.1rem; }
.book .when { margin: 0 0 14px; color: var(--muted); }
.book .when::first-letter { text-transform: uppercase; }
.book form { display: grid; gap: 10px; }
.book label { display: grid; gap: 3px; font-size: .82rem; color: var(--muted); }
.book .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.book input, .book select, .book textarea {
  width: 100%;
  padding: .45em .55em;
  font: inherit;
  font-size: .95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}
.book textarea { resize: vertical; }
.book .hp { position: absolute; left: -9999px; width: 1px; height: 1px; }
.book .out { margin: 0; min-height: 1.2em; font-size: .9rem; }
.book .out.ok { color: var(--avail); font-weight: 600; }
.book .out.err { color: var(--now); }
.book .actions { display: flex; justify-content: flex-end; gap: 8px; }
/* Once sent: only the message and the close button remain */
.book form.sent > :not(.out):not(.actions), .book form.sent #bk-send { display: none; }

/* ---------- Legend & messages ---------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 8px;
  font-size: .75rem;
  color: var(--muted);
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
}
.sw.busy { background: var(--busy); border-color: var(--busy); }
/* .sw.p1 { background: repeating-linear-gradient(135deg, var(--busy) 0 3px, var(--free-bar) 3px 6px); } */
.sw.p1 { background: var(--busy); opacity: .6; }
.sw.free { background: var(--free-bar); }
.sw.avail { background: var(--avail); border-color: var(--avail); }
.sw.mark { background: var(--mark, var(--accent)); border-color: var(--mark, var(--accent)); }
.sw.dot { width: 8px; height: 8px; margin: 0 2px; border-radius: 50%; }

#view { position: relative; }
.week .blk[title] { cursor: pointer; }
.bubble {
  position: absolute;
  z-index: 5;
  max-width: min(18em, calc(100% - 8px));
  padding: 6px 10px;
  font-size: .8rem;
  line-height: 1.4;
  white-space: pre-line;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
  pointer-events: none;
}
/* Loading: shown over the view while data is fetched, fading in after 250 ms so quick loads do not flicker */
.spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  width: 38px;
  height: 38px;
  margin: -19px 0 0 -19px;
  border: 3px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  animation: ag-spin .8s linear infinite, ag-appear .2s ease .25s forwards;
}
@keyframes ag-spin { to { transform: rotate(360deg); } }
@keyframes ag-appear { to { opacity: 1; } }

.notice {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  width: min(26em, calc(100% - 32px));
  margin: 0;
  padding: 18px 22px;
  font-size: 1.05rem;
  line-height: 1.45;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .12);
  transform: translate(-50%, -50%);
}

.msg {
  margin-top: 6px;
  font-size: .8rem;
  color: var(--now);
}

/* ---------- Phone ---------- */

@media (max-width: 640px) {
  :root { --hours-w: 1.9em; }
  body { padding: 0; }
  .app { padding: 8px; border-radius: 0; box-shadow: none; }
  .bar { gap: 6px; }
  .bar h1 { flex-basis: 100%; order: -1; font-size: 1rem; }
  .nav { flex: 1; }
  .links { order: -2; flex-basis: 100%; max-width: none; }
  .wd-long { display: none; }
  .wd-short { display: inline; }
  .day-head { font-size: .72rem; }
  .day-head .feasts { font-size: .7rem; }
  .cell-top { overflow: hidden; }
  .cell-top .feasts { gap: 0; font-size: .62rem; }
  .day-head .num { display: block; margin: 2px auto 0; width: 1.9em; font-size: .85rem; }
  .hour .mm { display: none; }
  .hour { padding-right: 3px; }
  .blk { left: 1px; right: 1px; }
  .item { margin-left: 1px; padding: 0 2px; font-size: .65rem; }
  .month-head, .month-grid { gap: 2px; }
  .cell { padding: 2px; border-radius: 4px; }
  .year { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: none; grid-auto-rows: 11.5em; gap: 8px; overflow-y: auto; }
}
