/* M-BUS 2026 — the date picker.
   Partner to assets/js/datepicker.js.

   Everything is prefixed .mbd- so it cannot collide with the theme or with the
   booking wizard, and every colour, radius and space comes from tokens.css.

   Two literal lengths appear below and nowhere else:
     --mbd-cell  the smallest a day cell may be (40px). It is smaller than
                 --mb-tap because seven 44px columns do not fit a 320px
                 screen; in the sheet, where there is room, the cells are
                 raised to --mb-tap.
     --mbd-w     the popover's natural width, chosen so that seven columns
                 land just above --mbd-cell.

   The closed field is deliberately indistinguishable from `.mb-field input`
   and `.mb-quick input`: same height, border, radius, type size and focus
   behaviour. It is a <button> only because the client asked that the date
   cannot be typed. */

/* On both, not inherited: the script parents the calendar to <body>, so it is
   not a descendant of .mbd and would not see these. */
.mbd,
.mbd-pop {
  --mbd-cell: 2.5rem;
  --mbd-w: 21rem;
}

.mbd {
  display: block;
  width: 100%;
}

/* ====================================================================== *
 * The closed field
 * ====================================================================== */

.mbd-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--mb-sp-3);
  width: 100%;
  min-height: var(--mb-tap);
  padding: var(--mb-sp-3) var(--mb-sp-4);
  border: 1px solid var(--mb-border-strong);
  border-radius: var(--mb-radius-sm);
  background: var(--mb-bg);
  color: var(--mb-text);
  font: inherit;
  font-size: var(--mb-fs-base);
  text-align: left;
  cursor: pointer;
  transition: border-color .18s var(--mb-ease);
}

.mbd-field:hover { border-color: var(--mb-primary); }
.mbd-field:focus { border-color: var(--mb-primary); }
.mbd-field[aria-expanded="true"] { border-color: var(--mb-primary); }

/* The date itself. Tabular figures so that 11.11 and 19.11 are the same
   width — the same reason the timetables use them. */
.mbd-field__v {
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--mb-track-wide);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mbd-field__v.is-empty { color: var(--mb-text-muted); }

.mbd-field__icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--mb-primary);
}

/* Label text for an input that had no <label for>. Not display:none: a screen
   reader has to be able to read it. */
.mbd-sr {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ====================================================================== *
 * The open calendar
 *
 * Fixed, and parented to <body> by the script: the hero search panel animates
 * a transform, and a transformed ancestor would become the containing block
 * for anything fixed inside it.
 *
 * Above the sticky header (100) and the mobile nav (110), below the skip link
 * and the lightbox (200) — the picker is never open at the same time as those.
 * ====================================================================== */

.mbd-backdrop {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: var(--mb-board);
  opacity: 0;
  transition: opacity .18s var(--mb-ease);
}
.mbd-backdrop:not([hidden]) { opacity: .55; }
.mbd-backdrop[hidden] { display: none; }

/* No background scrolling behind the sheet. */
body.mbd-lock { overflow: hidden; }

.mbd-pop {
  position: fixed;
  top: 0; left: 0;
  z-index: 151;
  width: min(var(--mbd-w), calc(100vw - 2 * var(--mb-sp-4)));
  /* A last resort for a very short window: the script clamps the popover into
     the viewport first, and only an exceptionally small one scrolls. */
  max-height: calc(100vh - 2 * var(--mb-sp-2));
  overflow-y: auto;
  padding: var(--mb-sp-3);
  background: var(--mb-bg);
  color: var(--mb-text);
  border: 1px solid var(--mb-border);
  border-top: 4px solid var(--mb-accent);   /* the same amber lip as .mb-quick */
  border-radius: var(--mb-radius);
  box-shadow: var(--mb-shadow-lg);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .16s var(--mb-ease), transform .16s var(--mb-ease);
}
.mbd-pop[hidden] { display: none; }
.mbd-pop.is-open { opacity: 1; transform: none; }

/* ---- head ------------------------------------------------------------- */

.mbd-head {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: var(--mb-sp-1);
  margin-bottom: var(--mb-sp-2);
}

.mbd-title {
  min-width: 0;
  text-align: center;
  /* One line, always: wrapped onto two it pushes the day grid down and the
     head stops looking like a row of controls. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--mb-fs-md);
  font-weight: 800;
  letter-spacing: var(--mb-track-tight);
  font-variant-numeric: tabular-nums;
}
/* Bulgarian does not capitalise month names, but the heading of a panel reads
   better with a capital. The text itself stays "ноември 2026". */
.mbd-title::first-letter { text-transform: uppercase; }

.mbd-nav,
.mbd-x {
  display: grid;
  place-items: center;
  width: var(--mb-tap);
  height: var(--mb-tap);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--mb-radius-sm);
  background: transparent;
  color: var(--mb-primary);
  cursor: pointer;
  transition: background-color .18s var(--mb-ease), border-color .18s var(--mb-ease);
}
.mbd-nav:hover,
.mbd-x:hover { background: var(--mb-bg-alt); border-color: var(--mb-border); }
.mbd-nav svg,
.mbd-x svg { width: 1.25rem; height: 1.25rem; }
.mbd-nav[disabled] { color: var(--mb-text-muted); opacity: .4; cursor: default; }
.mbd-nav[disabled]:hover { background: transparent; border-color: transparent; }

/* The close button belongs to the sheet: a popover is dismissed by clicking
   away from it, and an extra × there is one more thing to tab past. */
.mbd-x { display: none; }

/* ---- the grid --------------------------------------------------------- */

.mbd-dows {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--mb-sp-1);
  margin-bottom: var(--mb-sp-1);
  padding-bottom: var(--mb-sp-1);
  border-bottom: 1px solid var(--mb-border);
}

.mbd-dow {
  text-align: center;
  font-size: var(--mb-fs-xs);
  font-weight: 700;
  letter-spacing: var(--mb-track-wide);
  text-transform: uppercase;
  color: var(--mb-text-muted);
}

.mbd-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--mb-sp-1);
}
.mbd-week + .mbd-week { margin-top: var(--mb-sp-1); }

.mbd-day {
  display: grid;
  place-items: center;
  min-width: var(--mbd-cell);
  min-height: var(--mbd-cell);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--mb-radius-sm);
  background: transparent;
  color: var(--mb-text);
  font: inherit;
  font-size: var(--mb-fs-sm);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color .14s var(--mb-ease), color .14s var(--mb-ease), border-color .14s var(--mb-ease);
}

.mbd-day:hover { background: var(--mb-bg-alt); border-color: var(--mb-border); }

/* Inside the grid the ring goes inside the cell, or it would sit on top of
   the neighbouring day. */
.mbd-day:focus-visible { outline: 3px solid var(--mb-accent); outline-offset: -3px; }

/* Today: the amber of the departure board, the thing about to happen. An
   underline rather than a ring, because the keyboard focus ring is also
   amber and the two must never be mistaken for each other. */
.mbd-day.is-today { font-weight: 800; }
.mbd-day.is-today .mbd-day__n {
  padding-bottom: 1px;
  box-shadow: 0 2px 0 var(--mb-accent);
}

.mbd-day.is-selected,
.mbd-day.is-selected:hover {
  background: var(--mb-primary);
  border-color: var(--mb-primary);
  color: var(--mb-text-invert);
  font-weight: 800;
}

/* Out of the allowed range: still shown, so the shape of the month is intact,
   plainly not available. */
.mbd-day.is-disabled,
.mbd-day[disabled] {
  color: var(--mb-text-muted);
  opacity: .6;
  cursor: not-allowed;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

/* The neighbouring months: fainter again, so that a greyed day of *this*
   month (sold out of range) never reads as a day of another month. */
.mbd-day--out {
  color: var(--mb-text-muted);
  opacity: .28;
  cursor: default;
  font-weight: 400;
}

/* ---- foot ------------------------------------------------------------- */

.mbd-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--mb-sp-2);
  margin-top: var(--mb-sp-2);
  padding-top: var(--mb-sp-2);
  border-top: 1px solid var(--mb-border);
}
.mbd-foot[hidden] { display: none; }

.mbd-act {
  display: inline-flex;
  align-items: center;
  min-height: var(--mb-tap);
  padding: var(--mb-sp-2) var(--mb-sp-3);
  border: 1px solid transparent;
  border-radius: var(--mb-radius-sm);
  background: transparent;
  color: var(--mb-primary);
  font: inherit;
  font-size: var(--mb-fs-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background-color .18s var(--mb-ease), border-color .18s var(--mb-ease);
}
.mbd-act:hover { background: var(--mb-bg-alt); border-color: var(--mb-border); }
.mbd-act[hidden] { display: none; }
.mbd-act--clear { margin-left: auto; color: var(--mb-text-muted); }
.mbd-act--clear:hover { color: var(--mb-text); }

/* ====================================================================== *
 * The sheet — phones, and any viewport too short for a popover
 *
 * The script adds this class, so the stylesheet and the script can never
 * disagree about which of the two is on screen.
 * ====================================================================== */

.mbd-pop--sheet {
  top: auto;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  max-width: none;
  padding: var(--mb-sp-4);
  padding-bottom: calc(var(--mb-sp-4) + env(safe-area-inset-bottom, 0px));
  border-radius: var(--mb-radius) var(--mb-radius) 0 0;
  border-bottom: 0;
  transform: translateY(100%);
}
.mbd-pop--sheet.is-open { transform: none; }

.mbd-pop--sheet .mbd-head {
  gap: var(--mb-sp-2);
  margin-bottom: var(--mb-sp-3);
}
.mbd-pop--sheet .mbd-title { font-size: var(--mb-fs-md); }
/* Held away from the next-month arrow: next to it, a × reads as a third
   stepper. */
.mbd-pop--sheet .mbd-x { display: grid; margin-left: var(--mb-sp-2); }

/* There is room here, so the cells grow to a full tap target. */
.mbd-pop--sheet .mbd-day { min-height: var(--mb-tap); font-size: var(--mb-fs-base); }
.mbd-pop--sheet .mbd-dows { margin-bottom: var(--mb-sp-2); padding-bottom: var(--mb-sp-2); }
.mbd-pop--sheet .mbd-dow { font-size: var(--mb-fs-sm); }
.mbd-pop--sheet .mbd-foot { margin-top: var(--mb-sp-3); padding-top: var(--mb-sp-3); }
.mbd-pop--sheet .mbd-act { font-size: var(--mb-fs-base); padding-inline: var(--mb-sp-4); }

/* ====================================================================== *
 * Reduced motion: it appears, it does not arrive.
 * ====================================================================== */

@media (prefers-reduced-motion: reduce) {
  .mbd-pop,
  .mbd-pop--sheet,
  .mbd-backdrop,
  .mbd-field,
  .mbd-day,
  .mbd-nav,
  .mbd-x,
  .mbd-act { transition: none; }
  .mbd-pop { transform: none; opacity: 1; }
  .mbd-pop--sheet { transform: none; }
}
