/* Shared availability calendar (guest booking widget + admin blocking page).
   Renders a month grid with available / booked / blocked / selected / in-range
   day states, painted by calendar.js. Sits on a white surface in both places. */

.hw-cal {
  width: 100%;
  max-width: 440px;
  margin-inline: auto;
  user-select: none;
}

.hw-cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.hw-cal-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ocean-deep);
}

.hw-cal-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--ocean-mid);
  background: var(--sand-100);
  transition: background 0.15s var(--ease-out), color 0.15s var(--ease-out);
}

.hw-cal-nav:hover {
  background: var(--sand-200);
  color: var(--coral-dark);
}

.hw-cal-nav.is-disabled,
.hw-cal-nav:disabled {
  opacity: 0.35;
  cursor: default;
  background: transparent;
}

.hw-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.hw-cal-dow {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ocean-light);
  padding-bottom: var(--space-2);
}

.hw-day {
  position: relative;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--ocean-deep);
  background: var(--white);
  border: 1.5px solid var(--sand-200);
  border-radius: var(--radius-sm);
  transition: background 0.12s var(--ease-out), border-color 0.12s var(--ease-out), color 0.12s var(--ease-out);
}

.hw-day--blank {
  background: transparent;
  border-color: transparent;
  pointer-events: none;
}

/* Available */
.hw-day--open {
  cursor: pointer;
}

.hw-day--open:hover {
  border-color: var(--coral);
  background: color-mix(in oklch, var(--coral) 8%, var(--white));
}

/* Unavailable — past / booked / blocked */
.hw-day.is-disabled {
  cursor: default;
  color: var(--sand-400);
  background: var(--sand-100);
  border-color: transparent;
}

.hw-day--past span {
  opacity: 0.55;
}

.hw-day--booked {
  color: var(--ocean-light);
  background: color-mix(in oklch, var(--coral) 10%, var(--sand-100));
}

.hw-day--booked span,
.hw-day--blocked span {
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
  opacity: 0.8;
}

.hw-day--blocked {
  color: var(--ocean-light);
  background:
    repeating-linear-gradient(
      -45deg,
      var(--sand-200),
      var(--sand-200) 4px,
      var(--sand-300) 4px,
      var(--sand-300) 8px
    );
}

/* Selection */
.hw-day.is-inrange {
  background: color-mix(in oklch, var(--coral) 16%, var(--white));
  border-color: color-mix(in oklch, var(--coral) 22%, var(--white));
  color: var(--coral-dark);
}

.hw-day.is-preview {
  border-style: dashed;
}

.hw-day.is-start,
.hw-day.is-end {
  background: var(--coral);
  border-color: var(--coral);
  color: var(--white);
  font-weight: 700;
}

.hw-day.is-start span,
.hw-day.is-end span {
  text-decoration: none;
  opacity: 1;
}

/* Summary + legend */
.hw-cal-summary {
  min-height: 1.25rem;
  margin-top: var(--space-4);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ocean-mid);
}

.hw-cal-summary--warn {
  color: var(--error);
}

.hw-cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--sand-200);
}

.hw-cal-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.78rem;
  color: var(--ocean-mid);
}

.hw-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1.5px solid var(--sand-300);
  display: inline-block;
}

.hw-swatch--available {
  background: var(--white);
  border-color: var(--sand-300);
}

.hw-swatch--booked {
  background: color-mix(in oklch, var(--coral) 10%, var(--sand-100));
  border-color: transparent;
}

.hw-swatch--blocked {
  background:
    repeating-linear-gradient(
      -45deg,
      var(--sand-200),
      var(--sand-200) 3px,
      var(--sand-300) 3px,
      var(--sand-300) 6px
    );
  border-color: transparent;
}

.hw-swatch--selected {
  background: var(--coral);
  border-color: var(--coral);
}

/* ── Admin booking overview (status-coloured bars) ─────────────────────────
   Only the admin calendar carries `.hw-cal--has-bars`. Day cells grow to make
   room for stacked booking bars beneath the date number; the guest calendar is
   untouched. */

.hw-cal--has-bars {
  max-width: 620px;
}

.hw-cal--has-bars .hw-cal-grid {
  gap: 2px;
}

.hw-cal--has-bars .hw-day {
  aspect-ratio: auto;
  min-height: 66px;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 4px 0 0;
  overflow: hidden;
}

.hw-cal--has-bars .hw-day-num {
  padding-left: 5px;
  font-size: 0.82rem;
  line-height: 1.1;
  text-align: left;
}

/* In bars mode the coloured bar is the occupancy signal, so a booked day cell
   itself stays clean and readable rather than greyed + struck-through (the
   guest treatment). Admin blocks keep their distinct hatched fill. */
.hw-cal--has-bars .hw-day.hw-day--booked {
  background: var(--white);
  border-color: var(--sand-200);
  color: var(--ocean-deep);
}

.hw-cal--has-bars .hw-day--booked .hw-day-num {
  text-decoration: none;
  opacity: 1;
  color: var(--ocean-deep);
}

/* Bars sit at the bottom of the cell; slots keep lanes aligned across days. */
.hw-day-bars {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding-bottom: 3px;
}

.hw-book-slot {
  height: 15px;
}

.hw-book-seg {
  height: 15px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 3px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
  color: var(--white);
  overflow: hidden;
  cursor: pointer;
  transition: filter 0.12s var(--ease-out);
}

.hw-book-seg:hover {
  filter: brightness(1.06);
}

/* Rounded only at the true first/last night so a multi-day stay reads as one
   continuous bar across the row. */
.hw-book-seg.is-start {
  border-top-left-radius: 4px;
  border-bottom-left-radius: 4px;
}

.hw-book-seg.is-end {
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.hw-book-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hw-book-more {
  margin-left: auto;
  padding-left: 3px;
  font-size: 0.58rem;
  opacity: 0.9;
}

/* Freed statuses (denied / cancelled) no longer hold the dates — mute them. */
.hw-book-seg.is-muted {
  opacity: 0.5;
}

.hw-book-seg.is-muted .hw-book-name {
  text-decoration: line-through;
}

/* Status → colour. Shared by the bars and the legend swatches. */
.hw-book-seg--confirmed,
.cal-seg--confirmed {
  background: var(--success);
}

.hw-book-seg--pending,
.cal-seg--pending {
  background: var(--coral);
}

.hw-book-seg--denied,
.cal-seg--denied {
  background: color-mix(in oklch, var(--error) 55%, var(--sand-300));
}

.hw-book-seg--cancelled,
.cal-seg--cancelled {
  background: var(--sand-400);
}

/* Status legend */
.cal-status-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--sand-200);
}

.cal-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.78rem;
  color: var(--ocean-mid);
}

.cal-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  display: inline-block;
  flex-shrink: 0;
}

.cal-swatch--blocked {
  background:
    repeating-linear-gradient(
      -45deg,
      var(--sand-200),
      var(--sand-200) 3px,
      var(--sand-300) 3px,
      var(--sand-300) 6px
    );
}

/* ── Booking detail dialog ─────────────────────────────────────────────── */
.cal-dialog {
  /* margin:auto centres the modal; the global `* { margin: 0 }` reset would
     otherwise pin the native <dialog> to the top-left. Near-full-screen: the
     host reviews a whole conversation here, so the overlay fills the viewport
     minus a comfortable gutter that keeps the backdrop visible as a frame. */
  margin: auto;
  border: none;
  border-radius: var(--radius-md);
  padding: 0;
  width: calc(100vw - 2 * var(--cal-dialog-gutter));
  height: calc(100vh - 2 * var(--cal-dialog-gutter));
  max-width: none;
  max-height: none;
  background: var(--white);
  color: var(--ocean-deep);
  box-shadow: 0 24px 60px oklch(20% 0.06 258 / 0.28);
  --cal-dialog-gutter: var(--space-4);
}

.cal-dialog::backdrop {
  background: oklch(20% 0.06 258 / 0.45);
  backdrop-filter: blur(2px);
}

.cal-dialog-inner {
  position: relative;
  height: 100%;
  padding: var(--space-6);
  overflow: hidden;
}

@media (min-width: 900px) {
  .cal-dialog {
    --cal-dialog-gutter: var(--space-6);
  }

  .cal-dialog-inner {
    padding: var(--space-7);
  }
}

/* The revealed card owns the dialog's full height so its two columns can each
   scroll independently. [hidden] must still win over the display below, since
   calendar.js toggles the attribute to pick which booking is on screen. */
.cal-detail {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow-y: auto;
}

.cal-detail[hidden] {
  display: none;
}

.cal-detail-main {
  min-width: 0;
}

@media (min-width: 900px) {
  .cal-detail {
    display: grid;
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    gap: var(--space-7);
    align-items: start;
    overflow: hidden;
  }

  /* Each column scrolls on its own so a long thread never pushes the guest's
     details or the accept/deny actions out of view. */
  .cal-detail-main {
    height: 100%;
    overflow-y: auto;
    padding-right: var(--space-2);
  }
}

.cal-dialog-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--ocean-light);
  background: var(--sand-100);
  transition: background 0.15s, color 0.15s;
}

.cal-dialog-close:hover {
  background: var(--sand-200);
  color: var(--ocean-deep);
}

.cal-detail-head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.cal-detail-ref {
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ocean-light);
}

.cal-detail-name {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ocean-deep);
  margin-bottom: var(--space-4);
}

.cal-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}

.cal-detail-cell dt {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ocean-light);
  margin-bottom: 2px;
}

.cal-detail-cell dd {
  font-size: 0.95rem;
  color: var(--ocean-deep);
  word-break: break-word;
}

.cal-detail-cell a {
  color: var(--coral-dark);
}

.cal-detail-cell a:hover {
  text-decoration: underline;
}

.cal-detail-notes {
  padding-top: var(--space-3);
  border-top: 1px solid var(--sand-200);
  margin-bottom: var(--space-4);
}

.cal-detail-notes dt {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ocean-light);
  margin-bottom: var(--space-1);
}

.cal-detail-notes p {
  font-size: 0.92rem;
  color: var(--ocean-deep);
}

/* Staff-editable guest details (LGU report data), collapsed by default so the
   dialog stays scannable for the common case. */
.cal-guest-details {
  margin-bottom: var(--space-4);
}

.cal-guest-details summary {
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ocean-light);
}

.cal-guest-details-form {
  margin-top: var(--space-3);
}

.cal-guest-details-form .btn-ask {
  margin-top: var(--space-2);
}

.cal-detail-asked {
  margin-bottom: var(--space-4);
}

.cal-detail-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-4);
  border-top: 1px solid var(--sand-200);
}

.cal-action-row {
  display: flex;
  gap: var(--space-2);
}

.cal-action-row .btn-confirm,
.cal-action-row .btn-cancel {
  padding: var(--space-2) var(--space-4);
}

.cal-detail-hint {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--ocean-light);
}

.cal-detail-terminal {
  font-size: 0.9rem;
  color: var(--ocean-light);
  font-style: italic;
}

/* ---- Booking detail conversation thread ---- */
.cal-detail-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--sand-200);
}

@media (min-width: 900px) {
  /* As the dialog's right column the thread owns the full height: the head and
     reply box stay put while only the message list scrolls. */
  .cal-detail-thread {
    height: 100%;
    margin-bottom: 0;
    padding-top: 0;
    border-top: none;
  }
}
.cal-thread-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ocean-mid);
  margin-bottom: var(--space-3);
}
.cal-thread-head iconify-icon {
  color: var(--ocean-light);
}
.cal-thread-unread {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--white);
  background: var(--coral);
  padding: 1px var(--space-2);
  border-radius: 999px;
}
.cal-thread-empty {
  font-size: 0.88rem;
  color: var(--ocean-light);
  margin-bottom: var(--space-3);
}
.cal-thread-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}

@media (min-width: 900px) {
  /* In the full-height dialog the list is the only scrolling part of the
     thread, so let it take whatever room the head and reply box leave. */
  .cal-thread-list {
    flex: 1;
    max-height: none;
    padding-right: var(--space-2);
  }

  /* A short thread sits down by the reply box instead of floating at the top.
     An auto margin on the first bubble resolves to 0 once the list overflows,
     so this bottom-anchors without breaking scroll-up (unlike justify-content,
     which would make overflowing messages unreachable). */
  .cal-msg:first-child {
    margin-top: auto;
  }

  /* Cap the bubbles at a comfortable measure: stretched to the full width of
     the dialog's right column they would read as rows, not as a conversation. */
  .cal-msg {
    max-width: min(62ch, 78%);
  }
}

.cal-msg {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 88%;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
}
.cal-msg--host {
  align-self: flex-end;
  background: color-mix(in oklch, var(--tide-light) 40%, var(--white));
  border: 1px solid color-mix(in oklch, var(--tide) 35%, transparent);
}
.cal-msg--guest {
  align-self: flex-start;
  background: color-mix(in oklch, var(--sand-300) 45%, var(--white));
  border: 1px solid var(--sand-300);
}
.cal-msg-author {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ocean-mid);
}
.cal-msg-body {
  font-size: 0.9rem;
  color: var(--ocean-deep);
  white-space: pre-wrap;
  word-break: break-word;
}
.cal-msg-time {
  font-size: 0.68rem;
  color: var(--ocean-light);
}
.cal-thread-form {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}
.cal-thread-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--ocean-deep);
  background: var(--white);
  border: 1px solid var(--sand-300);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  resize: vertical;
  min-height: 40px;
}
.cal-thread-input:focus {
  outline: none;
  border-color: var(--tide);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--tide) 25%, transparent);
}

/* ── Mobile (≤768px) ─────────────────────────────────────────────────────
   Additive phone layout: compact month cells, a full-bleed booking dialog
   sheet, and ~44px tap targets. Desktop rendering is untouched. */
@media (max-width: 768px) {
  .hw-cal-title {
    font-size: 1.05rem;
  }

  .hw-cal-nav {
    width: 44px;
    height: 44px;
  }

  /* Bars mode: cells shrink but keep the day number + up to three status
     lanes distinguishable; blocking stays a whole-cell tap target. */
  .hw-cal--has-bars .hw-day {
    min-height: 52px;
    padding-top: 2px;
  }

  .hw-cal--has-bars .hw-day-num {
    padding-left: 3px;
    font-size: 0.72rem;
  }

  .hw-book-slot,
  .hw-book-seg {
    height: 11px;
  }

  /* The booking dialog becomes a full-bleed sheet on phones: the gutter
     frame is desktop luxury, the host needs the whole viewport here. */
  .cal-dialog {
    --cal-dialog-gutter: 0px;
    border-radius: 0;
  }

  .cal-dialog-inner {
    padding: var(--space-4);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
    padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  }

  .cal-dialog-close {
    width: 44px;
    height: 44px;
    top: calc(var(--space-2) + env(safe-area-inset-top, 0px));
    right: var(--space-2);
  }

  .cal-detail-name {
    font-size: 1.3rem;
  }

  /* Status actions stretch to full-width 44px targets. */
  .cal-action-row form {
    flex: 1;
  }

  .cal-action-row .btn-confirm,
  .cal-action-row .btn-cancel {
    width: 100%;
    min-height: 44px;
    padding: var(--space-3) var(--space-4);
    font-size: 0.85rem;
  }

  .cal-thread-form .btn-ask {
    align-self: stretch;
    display: inline-flex;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    font-size: 0.85rem;
  }

  /* ≥16px input: smaller text triggers focus auto-zoom on iOS/WKWebView. */
  .cal-thread-input {
    font-size: 16px;
  }
}

/* ── Small phones (≤480px) ───────────────────────────────────────────────
   At ~42px cell width a bar label shows 2–3 characters — noise, not
   information. Bars become pure status-colour chips (the legend explains
   the colours; the name is one tap away in the dialog and in the seg's
   title attribute). The "+N" overflow badge stays readable. */
@media (max-width: 480px) {
  .hw-book-name {
    display: none;
  }
}
