/* Calendar screen (DESIGN.md screen 3) and shared booking-screen styles: the timeline
   grid, phone day list, booking bars (the signature element - see
   docs/DESIGN_DIRECTION.md), availability box, and small utilities used across
   `templates/bookings/*.html`. Uses the tokens from app.css. */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- Legend
   Deliberately neutral (not one of the six party hues): the legend's job is to teach
   "colour = person, shape = status", so its three swatches share one neutral tone and
   differ only in fill/outline/badge - never colour. (Fixes the old bug where the
   standalone "Konflikt" swatch fell back to the same green fill as "Bestätigt".) */

.calendar-legend__hint {
  color: var(--muted);
  margin: 0 0 var(--space-1);
  font-size: 0.9rem;
}

.calendar-legend {
  list-style: none;
  margin: 0 0 var(--space-3);
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
}

.legend-swatch {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 0.9rem;
  font-weight: 700;
}

.legend-swatch__box {
  position: relative;
  width: 30px;
  height: 20px;
  border-radius: 6px;
  background: var(--muted);
  border: 2px solid var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.legend-swatch__box--tint {
  background: #E4E9EA;
  border-style: dashed;
}

.legend-swatch__box--conflict::after {
  content: "\26A0";
  position: absolute;
  top: -7px;
  right: -7px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--danger);
  color: #FFFFFF;
  font-size: 9px;
  line-height: 15px;
  text-align: center;
}

/* ---------------------------------------------------------------- Desktop grid */

.calendar-scroll {
  overflow-x: auto;
  border-top: 2px solid var(--ink);
  border-bottom: 1px solid var(--hairline);
  margin-bottom: var(--space-3);
  scrollbar-width: thin;
  scrollbar-color: var(--muted) var(--sky);
}

.calendar-scroll::-webkit-scrollbar {
  height: 10px;
}

.calendar-scroll::-webkit-scrollbar-track {
  background: var(--sky);
}

.calendar-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}

.calendar-scroll::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

@media (max-width: 719px) {
  .calendar-scroll {
    display: none;
  }
}

@media (min-width: 720px) {
  .calendar-daylist {
    display: none;
  }
}

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

.calendar-table__roomcol {
  width: 11rem;
}

.calendar-table__nightcol {
  width: 4.5rem;
}

.calendar-table th,
.calendar-table td {
  border: none;
  border-bottom: 1px solid var(--hairline);
  padding: 6px 6px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.calendar-table__roomcol,
.calendar-table th[scope="row"] {
  padding-left: 4px;
}

.calendar-table thead th {
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  border-bottom: 2px solid var(--ink);
  position: sticky;
  top: 0;
  z-index: 1;
}

.calendar-table th.calendar-table__night {
  white-space: normal;
  text-align: center;
  overflow: visible;
}

.calendar-table__weekday {
  display: block;
}

.calendar-table__daynum {
  display: block;
  font-weight: 400;
}

.calendar-table th[scope="row"] {
  background: var(--surface);
  position: sticky;
  left: 0;
  z-index: 1;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  line-height: 1.25;
  font-weight: 700;
}

.calendar-table thead th[scope="col"]:first-child,
.calendar-table th[scope="row"] {
  z-index: 2;
}

.calendar-table__beds {
  color: var(--muted);
  font-weight: 400;
}

.calendar-table__night.is-monday {
  border-left: 2px solid var(--ink);
}

.calendar-table__night.is-today,
.calendar-table td.is-over {
  position: relative;
}

.calendar-table__night.is-today {
  background: var(--accent-bg);
}

.calendar-table td.is-over {
  color: var(--danger);
  font-weight: 700;
}

.calendar-table__row--summary th,
.calendar-table__row--summary td {
  font-weight: 700;
  border-top: 2px solid var(--ink);
  border-bottom: none;
}

/* Fix for the known truncation bug: the summary row's occupancy values (e.g. "⚠ 9/8")
   were clipped to "⚠ …" by the shared ellipsis rule above in a narrow night column.
   This row gets its own rule - wrapping allowed, icon and count stacked instead of
   forced onto one clipped line. */
.calendar-table__row--summary td {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  text-align: center;
}

/* Occupancy heat strip: each night's cell tinted by its guests/beds ratio, in a few
   buckets of the slate-water hue (borrowed from direction B's desktop calendar). The
   used/total number stays plain text at every bucket - the tint is a supporting
   at-a-glance signal, never the only one - and an over-capacity night keeps its own
   danger colour plus the ⚠ icon and visually-hidden text, never just "the darkest
   heat step". */
.calendar-table__row--summary td.heat-1 { background: var(--heat-1); }
.calendar-table__row--summary td.heat-2 { background: var(--heat-2); }
.calendar-table__row--summary td.heat-3 { background: var(--heat-3); }
.calendar-table__row--summary td.heat-4 { background: var(--heat-4); }

.calendar-table__row--summary td.is-over {
  background: var(--danger-bg);
}

.calendar-table__occupancy {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.calendar-table__occupancy-flag {
  color: var(--danger);
  font-size: 0.85rem;
}

.calendar-table .bar {
  width: 100%;
  box-sizing: border-box;
}

.calendar-table .bar__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------------- Booking bars
   The signature element (docs/DESIGN_DIRECTION.md): colour identifies the PARTY
   (booking_id % 6 -> one of six hues, same colour in every room row and in the phone
   day list), never the status. Status is carried by form: approved = solid fill,
   tentative = light tint of the same hue + dashed outline + small diamond marker,
   conflict = a ⚠ badge in the danger colour layered on top of whichever fill/tint the
   party already has. */

.bar {
  --bar-hue: var(--muted);
  --bar-tint: #E4E9EA;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  border: 2px solid var(--bar-hue);
  background: var(--bar-hue);
  color: #FFFFFF;
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  text-decoration: none;
}

.bar:hover {
  text-decoration: underline;
}

.bar--hue-0 { --bar-hue: var(--hue-0); --bar-tint: var(--hue-0-tint); }
.bar--hue-1 { --bar-hue: var(--hue-1); --bar-tint: var(--hue-1-tint); }
.bar--hue-2 { --bar-hue: var(--hue-2); --bar-tint: var(--hue-2-tint); }
.bar--hue-3 { --bar-hue: var(--hue-3); --bar-tint: var(--hue-3-tint); }
.bar--hue-4 { --bar-hue: var(--hue-4); --bar-tint: var(--hue-4-tint); }
.bar--hue-5 { --bar-hue: var(--hue-5); --bar-tint: var(--hue-5-tint); }

.bar--approved {
  background: var(--bar-hue);
  border-color: var(--bar-hue);
  color: #FFFFFF;
}

.bar--tentative {
  background: var(--bar-tint);
  border: 2px dashed var(--bar-hue);
  color: var(--ink);
}

.bar__marker {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border: 2px solid currentColor;
  border-radius: 2px;
  transform: rotate(45deg);
}

.bar__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar--conflict {
  padding-right: 24px;
}

.bar--conflict::after {
  content: "\26A0";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--danger);
  color: #FFFFFF;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* ---------------------------------------------------------------- Phone day list
   "A lively guest list": each night shows the date, small dots for the parties
   staying (same hue as the calendar bars) and a mini occupancy bar + count, not just
   a bare fraction. Opens via <details> into the full guest list for that night. */

.calendar-daylist__day {
  border-bottom: 1px solid var(--hairline);
  border-left: 3px solid transparent;
  padding: 0 0 0 var(--space-2);
}

.calendar-daylist__day.is-today {
  border-left-color: var(--accent);
  background: var(--accent-bg);
}

.calendar-daylist__day summary {
  cursor: pointer;
  min-height: calc(var(--touch) + 6px);
  padding: 6px 0;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
  list-style: none;
}

.calendar-daylist__day summary::-webkit-details-marker {
  display: none;
}

.calendar-daylist__date {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
  min-width: 4.5rem;
}

.calendar-daylist__dots {
  display: flex;
  align-items: center;
  gap: 3px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.calendar-daylist__dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bar-hue, var(--muted));
  border: 2px solid var(--bar-hue, var(--muted));
}

.calendar-daylist__dot--hue-0 { --bar-hue: var(--hue-0); }
.calendar-daylist__dot--hue-1 { --bar-hue: var(--hue-1); }
.calendar-daylist__dot--hue-2 { --bar-hue: var(--hue-2); }
.calendar-daylist__dot--hue-3 { --bar-hue: var(--hue-3); }
.calendar-daylist__dot--hue-4 { --bar-hue: var(--hue-4); }
.calendar-daylist__dot--hue-5 { --bar-hue: var(--hue-5); }

.calendar-daylist__dot--tentative {
  background: var(--surface);
}

.calendar-daylist__dot--conflict {
  border-color: var(--danger);
  border-style: solid;
  box-shadow: 0 0 0 2px var(--danger-bg);
}

.calendar-daylist__more {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 700;
}

.calendar-daylist__meter {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
}

.calendar-daylist__meter-track {
  width: 40px;
  height: 8px;
  border-radius: 4px;
  background: var(--hairline);
  overflow: hidden;
  flex-shrink: 0;
}

.calendar-daylist__meter-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 4px 0 0 4px;
}

.calendar-daylist__meter-fill.is-over {
  background: var(--danger);
  border-radius: 4px;
}

.calendar-daylist__meter-count {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 2.6rem;
  text-align: right;
}

.calendar-daylist__meter-count.is-over {
  color: var(--danger);
}

/* Bucketed meter widths (10% steps) so no inline `style` attribute is needed (kept
   CSP-clean: style-src 'self' only). Values over 100% (over-capacity nights) are
   capped visually at full width; the danger colour and the ⚠ in the count carry the
   rest of the meaning. */
.calendar-daylist__meter-fill--w0 { width: 0%; }
.calendar-daylist__meter-fill--w10 { width: 10%; }
.calendar-daylist__meter-fill--w20 { width: 20%; }
.calendar-daylist__meter-fill--w30 { width: 30%; }
.calendar-daylist__meter-fill--w40 { width: 40%; }
.calendar-daylist__meter-fill--w50 { width: 50%; }
.calendar-daylist__meter-fill--w60 { width: 60%; }
.calendar-daylist__meter-fill--w70 { width: 70%; }
.calendar-daylist__meter-fill--w80 { width: 80%; }
.calendar-daylist__meter-fill--w90 { width: 90%; }
.calendar-daylist__meter-fill--w100 { width: 100%; }

.calendar-daylist__marker {
  color: var(--muted);
  font-size: 0.85rem;
}

.calendar-daylist__list {
  list-style: none;
  margin: 0;
  padding: 0 0 var(--space-2);
}

.calendar-daylist__list li {
  padding: var(--space-1) 0;
  border-top: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex-wrap: wrap;
}

.calendar-daylist__list-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--bar-hue, var(--muted));
  border: 2px solid var(--bar-hue, var(--muted));
}

/* ---------------------------------------------------------------- Room tiles
   Visitor room picker: tappable tiles instead of a plain checkbox list. The whole
   tile is the <label>; the checkbox is a real input (visually hidden, not
   display:none, so it stays in the tab order and keyboard-operable) and the checked
   state is drawn on `.room-tile__check` via `:has()`, always paired with a heavier
   border on the tile itself - never colour alone. */
/* One column on a phone-width screen (a room name like "Blaues Zimmer" needs more
   room than a narrow two-up column gives it - full width keeps every name on one
   line), two columns from tablet width up, including the desktop booking form. */
.room-tiles {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-1);
  max-width: 560px;
}

@media (min-width: 480px) {
  .room-tiles {
    grid-template-columns: repeat(2, 1fr);
  }
}

.room-tile {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--touch);
  padding: var(--space-1) var(--space-2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.room-tile:has(.room-tile__input:checked) {
  border-color: var(--accent);
  background: var(--accent-bg);
}

.room-tile:has(.room-tile__input:focus-visible) {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.room-tile__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.room-tile__check {
  position: relative;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.room-tile:has(.room-tile__input:checked) .room-tile__check {
  background: var(--accent);
  border-color: var(--accent);
}

.room-tile:has(.room-tile__input:checked) .room-tile__check::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 11px;
  border: solid #FFFFFF;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.room-tile__body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.room-tile__name {
  font-weight: 700;
}

.room-tile__beds {
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------- Booking detail / form */

.booking-summary {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-1) var(--space-2);
  margin: var(--space-2) 0;
}

.booking-summary dt {
  color: var(--muted);
}

.booking-summary dd {
  margin: 0;
}

.booking-summary__comment {
  white-space: pre-wrap;
}

.booking-summary__rooms {
  list-style: none;
  margin: 0;
  padding: 0;
}

.booking-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

/* Manager's edit form: one row per room, name/beds on the left and a fixed-width
   guests input on the right, with a header row labelling the guests column and a
   hairline between rows so the grid reads cleanly at a glance. */
.room-alloc {
  max-width: 560px;
}

.room-alloc__row {
  display: grid;
  grid-template-columns: 1fr 5rem;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) 0;
}

.room-alloc__row + .room-alloc__row {
  border-top: 1px solid var(--hairline);
}

.room-alloc__row--head {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  border-bottom: 2px solid var(--ink);
  border-top: none !important;
  padding-bottom: var(--space-1);
  margin-bottom: 4px;
}

.room-alloc__row--head span:last-child {
  text-align: right;
}

.room-alloc__row label {
  font-weight: 400;
}

.room-alloc__row input[type="number"] {
  width: 5rem;
  min-height: var(--touch);
  padding: 0 var(--space-1);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.room-alloc__row input[type="number"]:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* ---------------------------------------------------------------- Availability panel
   Rendered inline on load and refreshed via htmx on every `change` (DESIGN.md "Where
   htmx Is Used" #1). Reads as a quiet summary panel: a heading, the headline numbers,
   then per-room fit and any warnings - not a wall of prose. */
.availability-box {
  max-width: 560px;
}

.availability-box__title {
  margin: 0 0 var(--space-1);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--muted);
}

/* The placeholder ("choose your dates") and error ("fix the dates above") states,
   shown under the same always-visible title instead of as bare floating text. */
.availability-box__note {
  margin: 0;
  color: var(--muted);
}

.availability-box__headline {
  margin: 0 0 var(--space-1);
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.availability-box__rooms {
  list-style: none;
  margin: var(--space-1) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.availability-box__rooms li {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.availability-box__fit {
  color: var(--accent-strong);
  font-weight: 700;
  flex-shrink: 0;
}

.availability-box__fit::before {
  content: "\2713";
}

.availability-box__nofit {
  color: var(--danger);
  font-weight: 700;
  flex-shrink: 0;
}

.availability-box__nofit::before {
  content: "\26A0";
}

.availability-box__preview {
  margin: var(--space-1) 0 0;
  color: var(--muted);
}

/* Aside layout: the availability panel sits beside the booking form on desktop, under
   it on a phone. The `#availability` div itself is a plain sibling of the <form> (an
   htmx target can live anywhere - it doesn't need to be a form descendant), which is
   what lets it move into its own column without any change to the hx-* attributes. */
.booking-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}

@media (min-width: 900px) {
  .booking-layout {
    grid-template-columns: minmax(0, 40rem) minmax(16rem, 20rem);
  }
}

.booking-layout__aside {
  padding-top: var(--space-1);
  min-width: 0;
}

@media (min-width: 900px) {
  .booking-layout__aside {
    border-top: none;
    padding-top: calc(var(--space-1) + 2.6rem);
    /* Stays in view while the (potentially long) form scrolls past it, clearing the
       fixed topbar. */
    position: sticky;
    top: 5rem;
  }
}

.delete-widget {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.delete-widget__form {
  margin: 0;
  display: inline;
}
