/* ---------------------------------------------------------------------------
   Calendars, and the guide portal's shell.
   Loaded by the five booking pages and by myguide/.

   Kept out of main.css on purpose: main.css is referenced by 90 pages, so
   every edit to it means bumping ?v= on all 90. This file is referenced by
   six, and the booking calendar is the part most likely to be tweaked.

   Colour comes from main.css's own custom properties where there is one, with
   a literal fallback so the portal still looks right if it is ever served
   without main.css. The two state colours are new: red for a day that cannot
   be booked, amber for one that can be but needs a substitute guide. They are
   darkened from the obvious red/orange so that white text on them clears
   WCAG AA, and neither state is signalled by colour alone — every day also
   carries a word in its label and its aria-label.
   --------------------------------------------------------------------------- */

:root {
  --cal-closed: #b3261e;
  --cal-closed-bg: #fdecea;
  --cal-cover: #a15c00;
  --cal-cover-bg: #fdf0dc;
  --cal-open-bg: #ffffff;
  --cal-booked: #1b5e20;
  --cal-booked-bg: #e8f5e9;
  /* Hovering a day answers "can this be booked?": green when a guide on the
     tour is free, amber when none is. Both are darkened from the obvious
     green/orange so the day number on them clears WCAG AA. */
  --cal-free: #176b2c;
  --cal-free-bg: #ecf8ee;
  --cal-line: #e2ddd5;
  --cal-muted: #8a8278;
}

/* ---------- The grid ---------- */

/* One month, full width of whatever holds it. There is deliberately no
   multi-column rule here: a media query measures the viewport, while the grid
   is sized by its container, so "two months on a wide screen" put two month
   tables inside a 330px half of a form row. */
.cal-months {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: 1fr;
}

table.cal {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.cal-caption {
  font-weight: 600;
  text-align: left;
  padding: 0 0 0.6rem;
  font-size: 1.05rem;
}

table.cal th {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cal-muted);
  padding-bottom: 0.35rem;
}

table.cal th abbr { text-decoration: none; border: 0; }

.cal-cell { padding: 1px; }

.cal-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  /* Tall enough to be a comfortable phone target (44px) with room for the
     note line underneath. */
  min-height: 3rem;
  padding: 0.25rem 0.1rem;
  border: 1px solid var(--cal-line);
  border-radius: 6px;
  background: var(--cal-open-bg);
  color: inherit;
  text-decoration: none;
  font-size: 0.95rem;
  line-height: 1.1;
  /* The booking calendar renders a selectable day as a <button>, which
     defaults to the arrow cursor and to the browser's own font. */
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease,
              color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

/* Hover and keyboard focus, for both markups: the booking calendar builds a
   <button> per day, the guide portal an <a>. The old rule named only `a`, so
   the booking calendar had no hover state at all.

   A day that cannot be chosen is rendered as a <span>, so it is excluded here
   by element rather than by a class — nothing can get a hover it should not
   have by picking up the wrong modifier. */
/* A day a guide is free for: green. This is the default hover because the
   feed only marks the exceptions — a day with no `is-cover` class is one
   somebody can take. */
button.cal-day:hover,
a.cal-day:hover {
  border-color: var(--cal-free);
  background: var(--cal-free-bg);
  color: var(--cal-free);
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(23, 107, 44, 0.18);
}

button.cal-day:focus-visible,
a.cal-day:focus-visible {
  outline: none;
  border-color: var(--cal-free);
  background: var(--cal-free-bg);
  box-shadow: 0 0 0 3px rgba(23, 107, 44, 0.3);
}

button.cal-day:active { transform: translateY(0); box-shadow: none; }

/* A day no guide on the tour is free for: amber, never green. It is still
   bookable — a colleague takes the tour and the customer confirms a notice —
   so it keeps its hover, it just answers the question differently. */
.is-cover button.cal-day:hover,
.is-cover a.cal-day:hover,
.is-part-off a.cal-day:hover {
  background: #fbe4c0;
  border-color: var(--cal-cover);
  color: var(--cal-cover);
  box-shadow: 0 3px 10px rgba(161, 92, 0, 0.2);
}

.is-cover button.cal-day:focus-visible,
.is-cover a.cal-day:focus-visible {
  border-color: var(--cal-cover);
  background: #fbe4c0;
  box-shadow: 0 0 0 3px rgba(161, 92, 0, 0.3);
}

/* The portal's own "blocked all day" state. */
.is-off a.cal-day:hover {
  background: #fbd9d5;
  border-color: var(--cal-closed);
  color: var(--cal-closed);
}

.is-selected button.cal-day:hover,
.is-selected a.cal-day:hover { transform: none; }

/* Someone who has asked for less movement gets the colour change only. */
@media (prefers-reduced-motion: reduce) {
  .cal-day { transition: background-color 0.12s ease, border-color 0.12s ease; }
  button.cal-day:hover,
  a.cal-day:hover { transform: none; }
}

.cal-num { font-variant-numeric: tabular-nums; }

.cal-note {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-top: 0.15rem;
  text-align: center;
  color: var(--cal-muted);
}

.cal-pad { padding: 1px; }

/* ---------- Day states ---------- */

.is-today .cal-day { border-width: 2px; font-weight: 700; }
.is-selected .cal-day { box-shadow: 0 0 0 2px currentColor; }

.is-past .cal-day,
.cal-cell.is-past .cal-day {
  color: var(--cal-muted);
  background: #f6f4f1;
  border-style: dashed;
}

/* A day we don't run tours at all: Sunday today (CLOSED_WEEKDAYS in
   inc/policy.php), and anything outside the booking window. */
.is-closed .cal-day {
  background: var(--cal-closed-bg);
  border-color: var(--cal-closed);
  color: var(--cal-closed);
  text-decoration: line-through;
}

.is-closed .cal-note { color: var(--cal-closed); }

/* Bookable, but no guide on the tour is free — a substitute will take it and
   the customer has to acknowledge that before booking. */
.is-cover .cal-day {
  background: var(--cal-cover-bg);
  border-color: var(--cal-cover);
  color: var(--cal-cover);
  font-weight: 600;
}

.is-cover .cal-note { color: var(--cal-cover); }

/* The portal's own two states. */
.is-off .cal-day {
  background: var(--cal-closed-bg);
  border-color: var(--cal-closed);
  color: var(--cal-closed);
}

.is-part-off .cal-day {
  background: var(--cal-cover-bg);
  border-color: var(--cal-cover);
  color: var(--cal-cover);
}

.is-booked .cal-day { border-left: 4px solid var(--cal-booked); }

/* Not selectable — a past day, a closed day, one outside the booking window.
   Rendered as a <span>, so it gets none of the hover rules above; this just
   undoes the pointer cursor inherited from .cal-day. */
span.cal-day { cursor: default; }

/* ---------- Legend and month navigation ---------- */

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 1rem;
  font-size: 0.8rem;
  color: var(--cal-muted);
  margin: 0.5rem 0 1rem;
}

.cal-key {
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  border: 1px solid var(--cal-line);
  vertical-align: -0.1em;
  margin-right: 0.3rem;
}

.cal-key--off,
.cal-key--closed { background: var(--cal-closed-bg); border-color: var(--cal-closed); }
.cal-key--part,
.cal-key--cover { background: var(--cal-cover-bg); border-color: var(--cal-cover); }
.cal-key--booked { background: var(--cal-booked-bg); border-color: var(--cal-booked); }

.cal-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.cal-nav .is-disabled { opacity: 0.4; }

/* ---------- The booking form's calendar ---------- */

.booking-calendar { margin-top: 0.35rem; }

/* The field that opens the calendar. Deliberately identical to .form-group
   input in main.css — same padding, border, radius, background and focus ring
   — so it reads as one of the form's fields and not as a button. Full width
   and 3rem tall, because the thing it replaces was a native date input whose
   picker only opened from a ~16px glyph. */
.date-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border, #e2ddd5);
  border-radius: var(--radius, 8px);
  background: var(--bg, #fff);
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--fg, inherit);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.date-trigger:hover { border-color: var(--primary, #c9973a); }

.date-trigger:focus-visible,
.date-trigger[aria-expanded="true"] {
  outline: none;
  border-color: var(--primary, #c9973a);
  box-shadow: 0 0 0 3px rgba(201, 151, 58, 0.15);
}

.date-trigger-value { flex: 1; min-width: 0; }
.date-trigger-value.is-placeholder { color: var(--cal-muted); }

.date-trigger-icon {
  flex: 0 0 auto;
  display: inline-flex;
  opacity: 0.55;
}

/* The grid itself, folded away until the field is clicked. */
.booking-calendar-panel {
  margin-top: 0.5rem;
  padding: 0.85rem 0.9rem 0.6rem;
  border: 1px solid var(--cal-line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 6px 24px rgba(20, 18, 15, 0.08);
}

.booking-calendar-panel[hidden] { display: none; }

.booking-calendar-selected {
  font-size: 0.9rem;
  margin: 0.6rem 0 0;
}

.booking-calendar-selected .is-cover-note {
  display: block;
  color: var(--cal-cover);
  font-size: 0.8rem;
  margin-top: 0.2rem;
}

/* Shown only when the calendar could not be drawn, in which case the plain
   date input it replaces is put back. */
.booking-calendar-fallback { margin-top: 0.35rem; }

/* ---------- The guide-cover dialog ---------- */

.cover-dialog {
  border: 1px solid var(--cal-line);
  border-radius: 10px;
  padding: 1.5rem;
  max-width: 32rem;
  width: calc(100% - 2rem);
  color: inherit;
  background: #fff;
}

.cover-dialog::backdrop { background: rgba(20, 18, 15, 0.55); }

.cover-dialog h2 {
  font-size: 1.15rem;
  margin: 0 0 0.75rem;
  color: var(--cal-cover);
}

.cover-dialog p { margin: 0 0 1rem; font-size: 0.95rem; line-height: 1.5; }

.cover-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.cover-dialog-actions .btn { flex: 1 1 12rem; }

/* ---------- Portal shell ---------- */

.portal-body { background: #faf8f5; }

.portal-shell {
  max-width: 48rem;
  margin: 0 auto;
  padding: 0 1rem;
}

.portal-header {
  border-bottom: 1px solid var(--cal-line);
  padding: 0.9rem 0;
  background: #fff;
}

.portal-header .portal-shell {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

.portal-brand { font-weight: 700; margin: 0; letter-spacing: 0.01em; }
.portal-who { margin: 0; color: var(--cal-muted); font-size: 0.9rem; }

.portal-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  max-width: 48rem;
  margin: 0 auto 1.25rem;
  padding: 0.5rem 1rem 0;
  flex-wrap: wrap;
}

.portal-nav-link {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.95rem;
  color: inherit;
}

.portal-nav-link.is-active { background: #ece7df; font-weight: 600; }
.portal-nav-logout { margin-left: auto; }

.portal-nav-signout {
  background: none;
  border: 0;
  cursor: pointer;
  font: inherit;
  color: var(--cal-muted);
  text-decoration: underline;
}

.portal-shell h1 { font-size: 1.5rem; margin: 0.5rem 0 0.75rem; }
.portal-shell h2 { font-size: 1.1rem; margin: 1.5rem 0 0.75rem; }

.portal-section { margin-bottom: 1.5rem; }
.portal-muted { color: var(--cal-muted); font-size: 0.9rem; }

.portal-ok,
.portal-error {
  padding: 0.7rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.portal-ok { background: var(--cal-booked-bg); color: var(--cal-booked); }
.portal-error { background: var(--cal-closed-bg); color: var(--cal-closed); }

.portal-card {
  background: #fff;
  border: 1px solid var(--cal-line);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
}

.portal-card--offer { border-left: 4px solid var(--cal-cover); }

.portal-card p { margin: 0 0 0.3rem; }
.portal-card-when { font-weight: 700; }
.portal-card-where,
.portal-card-who { font-size: 0.9rem; }
.portal-card-notes { font-size: 0.9rem; background: #faf8f5; padding: 0.5rem; border-radius: 4px; }

.portal-ref {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  color: var(--cal-muted);
  margin: 0.4rem 0 0 !important;
}

.portal-list { margin: 0 0 0.75rem; padding-left: 1.2rem; font-size: 0.9rem; }
.portal-form { max-width: 24rem; }
.portal-cta { margin-top: 2rem; }

.portal-day {
  background: #fff;
  border: 1px solid var(--cal-line);
  border-radius: 8px;
  padding: 1rem;
}

.portal-actions { display: flex; flex-direction: column; gap: 0.5rem; }

.portal-slot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--cal-line);
  font-size: 0.95rem;
  margin: 0;
}

.portal-slot-row--off { color: var(--cal-closed); }
.portal-slot-row--booked { color: var(--cal-booked); font-weight: 600; }

.portal-inline-form { display: inline; }

.portal-state {
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

.portal-state--off { background: var(--cal-closed-bg); color: var(--cal-closed); }
.portal-booked-note { margin-bottom: 0.3rem; }

/* ---------- Two button variants the portal needs ----------
   main.css defines .btn, .btn-primary, .btn-lg and .btn-full only. These two
   live here rather than there because adding them to main.css would mean
   bumping ?v= on all 90 pages that reference it, for styling that six use. */

.btn-secondary {
  background: #fff;
  color: inherit;
  border: 1px solid var(--cal-line);
}

.btn-secondary:hover { background: #f6f4f1; }

.btn-link {
  background: none;
  border: 0;
  padding: 0.35rem 0.5rem;
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
}

.btn-link:hover { text-decoration: none; }

.date-trigger:disabled {
  cursor: default;
  background: #f6f4f1;
  border-color: var(--cal-line);
}
