/*
 * Booking Core — calendar grid + range chip styles.
 * Modern minimal: clean lines, subtle shadows, no decoration.
 * All colours are CSS custom properties so the host page can theme.
 */

.acw-calendar {
  --acw-bg: #ffffff;
  --acw-fg: #1f2937;
  --acw-muted: #9ca3af;
  --acw-border: #e5e7eb;
  --acw-accent: #2563eb;
  --acw-accent-soft: #dbeafe;
  --acw-disabled-bg: #f3f4f6;
  --acw-disabled-fg: #cbd5e1;
  --acw-hover: #f3f4f6;
  --acw-radius: 8px;
  --acw-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--acw-fg);
  background: var(--acw-bg);
  border: 1px solid var(--acw-border);
  border-radius: var(--acw-radius);
  padding: 0.75rem;
  box-shadow: var(--acw-shadow);
  user-select: none;
}

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

.acw-cal-title {
  font-weight: 600;
  font-size: 1rem;
}

.acw-nav {
  background: transparent;
  border: 1px solid var(--acw-border);
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--acw-fg);
}
.acw-nav:hover { background: var(--acw-hover); }
.acw-nav:focus-visible {
  outline: 2px solid var(--acw-accent);
  outline-offset: 2px;
}

.acw-weekdays,
.acw-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.acw-weekdays { margin-bottom: 4px; }

.acw-weekday {
  text-align: center;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--acw-muted);
  padding: 4px 0;
}

.acw-day {
  position: relative;
  aspect-ratio: 1 / 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--acw-fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background-color 80ms ease, border-color 80ms ease;
}

.acw-day:hover:not([aria-disabled="true"]) {
  background: var(--acw-hover);
}

.acw-day:focus-visible {
  outline: 2px solid var(--acw-accent);
  outline-offset: 2px;
}

.acw-day.acw-outside {
  color: var(--acw-muted);
  opacity: 0.5;
}

.acw-day[aria-disabled="true"] {
  background: var(--acw-disabled-bg);
  color: var(--acw-disabled-fg);
  cursor: not-allowed;
  text-decoration: line-through;
}

.acw-day.acw-selected {
  background: var(--acw-accent-soft);
  color: var(--acw-fg);
}

.acw-day.acw-range-start,
.acw-day.acw-range-end {
  background: var(--acw-accent);
  color: #ffffff;
  font-weight: 600;
}

.acw-day-num {
  position: relative;
  z-index: 1;
}

.acw-day-badge {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.6rem;
  background: var(--acw-accent);
  color: #ffffff;
  border-radius: 999px;
  padding: 1px 5px;
  line-height: 1.2;
  z-index: 1;
}

.acw-day[aria-disabled="true"] .acw-day-badge {
  background: var(--acw-muted);
}

/* ---------- Range chip ---------- */

.acw-chip-host {
  display: block;
}

.acw-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 0.85rem;
  color: #1f2937;
}

.acw-chip-label {
  white-space: nowrap;
}

.acw-chip-btn {
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  color: #1f2937;
  line-height: 1;
}

.acw-chip-edit:hover {
  background: #2563eb;
  color: #ffffff;
}

.acw-chip-clear {
  font-size: 1rem;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.acw-chip-clear:hover {
  background: #e5e7eb;
}

.acw-chip-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

/* ---------- Design-mode preview ---------- */
/* Static placeholder shown inside the SurveyJS form builder. Not interactive. */

.acw-design-preview {
  border: 1px dashed var(--acw-border, #d1d5db);
  border-radius: 8px;
  padding: 1rem;
  background: #fafafa;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1f2937;
}
.acw-design-preview-header {
  font-weight: 600;
  margin-bottom: 0.5rem;
}
.acw-design-preview-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 0.85em;
  color: #666;
  margin-bottom: 0.25rem;
}
.acw-design-preview-weekdays span {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75em;
}
.acw-design-preview-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.acw-design-preview-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 4px;
  color: #999;
  font-size: 0.9em;
}
.acw-design-preview-cell-empty {
  background: transparent;
  border-color: transparent;
}
.acw-design-preview-note {
  margin-top: 0.75rem;
  font-size: 0.85em;
  color: #666;
}
.acw-design-preview-note code {
  background: #f1f5f9;
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95em;
}

/* ---------- Lane mode (selectionMode: 'lane') ---------- */
/* Gantt-style horizontal strip. One row per selected resource, day columns
   shared across rows via a top header. Used when the form opts in to lane
   mode for multi-resource bookings where each resource needs its own date
   range. See docs/AVAILABILITY_CALENDAR_AMR_UNIFIED_HANDOFF.md §1. */

.acw-lane-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-x: auto;
  font-size: 0.85rem;
  width: 100%;
}

.acw-lane-month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
  /* Sticky to the left edge of the scrolling viewport so the nav stays
     visible even when the day strip overflows horizontally. */
  position: sticky;
  left: 0;
  background: transparent;
  z-index: 1;
}
.acw-lane-nav-prev,
.acw-lane-nav-next {
  appearance: none;
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  width: 28px;
  height: 28px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: #374151;
}
.acw-lane-nav-prev:hover,
.acw-lane-nav-next:hover {
  background: #e5e7eb;
}
.acw-lane-nav-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #1f2937;
  min-width: 9em;
  text-align: center;
}

/* Recurrence ↻ toggle — sits inside the row label, opens the inline panel. */
.acw-lane-row-label {
  /* Override the default `display: flex` from above so the label-text and
     ↻ button align nicely with room for both. */
  gap: 6px;
}
.acw-lane-row-label-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.acw-lane-recurrence-toggle {
  appearance: none;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border: 1px solid #d1d5db;
  border-radius: 50%;
  background: #ffffff;
  color: #4b5563;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.acw-lane-recurrence-toggle:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1e40af;
}

/* Inline recurrence-config panel — sits between two lane rows. Spans the
   full row width and is sticky-positioned at left so it stays in the
   visible viewport even if the horizontal day strip is scrolled. */
.acw-lane-recurrence-panel {
  position: sticky;
  left: 0;
  background: #f9fafb;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  margin: 4px 0;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}
.acw-recur-heading {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: #1f2937;
}
.acw-recur-hint {
  font-size: 0.85rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  /* Inside a flex layout where children default to min-width: max-content,
     long hint text would push the panel wider than its container. Force a
     soft wrap. */
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  box-sizing: border-box;
}
.acw-recur-hint-ok {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}
.acw-recur-hint-warn {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}
.acw-recur-dow {
  display: flex;
  gap: 6px;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.acw-recur-dow-chip {
  appearance: none;
  width: 32px;
  height: 32px;
  border: 1px solid #d1d5db;
  border-radius: 50%;
  background: #ffffff;
  color: #374151;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  line-height: 1;
}
.acw-recur-dow-chip:hover {
  background: #eff6ff;
  border-color: #93c5fd;
}
.acw-recur-dow-chip.acw-recur-dow-chip-active {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}
.acw-recur-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0.4rem 0;
  font-size: 0.875rem;
}
.acw-recur-row label {
  font-weight: 500;
  color: #4b5563;
  min-width: 7em;
}
.acw-recur-every-input,
.acw-recur-end-date {
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.875rem;
  color: #1f2937;
}
.acw-recur-every-input {
  width: 60px;
}
.acw-recur-actions {
  display: flex;
  gap: 8px;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.acw-recur-apply,
.acw-recur-cancel,
.acw-recur-clear {
  appearance: none;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #d1d5db;
}
.acw-recur-apply {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}
.acw-recur-apply:hover {
  background: #1d4ed8;
}
.acw-recur-apply.acw-recur-apply-disabled,
.acw-recur-apply:disabled {
  background: #9ca3af;
  border-color: #9ca3af;
  cursor: not-allowed;
  opacity: 0.6;
}
.acw-recur-apply.acw-recur-apply-disabled:hover,
.acw-recur-apply:disabled:hover {
  background: #9ca3af;
}
.acw-recur-cancel {
  background: #ffffff;
  color: #4b5563;
}
.acw-recur-cancel:hover {
  background: #f3f4f6;
}
.acw-recur-clear {
  background: #ffffff;
  color: #b91c1c;
  border-color: #fecaca;
  margin-left: auto;
}
.acw-recur-clear:hover {
  background: #fef2f2;
}

.acw-lane-day-header,
.acw-lane-row {
  display: flex;
  align-items: stretch;
  min-width: max-content;
}

.acw-lane-row-label {
  flex: 0 0 180px;
  padding: 6px 8px;
  font-weight: 500;
  display: flex;
  align-items: center;
  border-right: 1px solid #e5e7eb;
  background: #f9fafb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Pin to the left edge of the scrolling lane grid so the row label
     (location name + ↻ recurrence toggle) stays visible no matter how
     far the user scrolls horizontally through day cells. */
  position: sticky;
  left: 0;
  z-index: 2;
  /* Opaque background so day cells don't bleed through behind the label. */
}

.acw-lane-row-label-spacer {
  /* Header-row spacer — also sticky to align with body-row labels below. */
  background: #ffffff;
  border-right: 1px solid #e5e7eb;
  position: sticky;
  left: 0;
  z-index: 2;
}

.acw-lane-day-cell {
  flex: 0 0 26px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid #f3f4f6;
  border-bottom: 1px solid transparent;
  font-size: 0.75rem;
  color: #374151;
  cursor: pointer;
  user-select: none;
  background: #ffffff;
  box-sizing: border-box;
}

.acw-lane-day-cell-header {
  font-weight: 600;
  color: #6b7280;
  background: #f9fafb;
  cursor: default;
  border-bottom: 1px solid #e5e7eb;
  height: 28px;
}

.acw-lane-row {
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  /* NOTE: do NOT add overflow: hidden here — it creates a new sticky
     containing block, which breaks position:sticky on .acw-lane-row-label
     (the labels would stick to the row's left edge inside the scrolled
     content instead of the grid viewport). See FIX-20. */
}

.acw-lane-row .acw-lane-day-cell:hover {
  background: #eff6ff;
}

/* Capacity exhausted on this row for this date — × glyph in muted red. */
.acw-lane-day-cell.acw-lane-day-cell-unavailable {
  color: #b91c1c;
  background: #fef2f2;
  cursor: not-allowed;
  font-weight: 600;
}
.acw-lane-day-cell.acw-lane-day-cell-unavailable:hover {
  background: #fef2f2;
}

/* Globally blocked (lockdown / past / weekday filter) — greyed across the
   whole column. Header cells also get the muted tint so the user can scan
   blocked dates at a glance. */
.acw-lane-day-cell.acw-lane-day-cell-blocked {
  background: repeating-linear-gradient(
    -45deg,
    #f3f4f6,
    #f3f4f6 4px,
    #e5e7eb 4px,
    #e5e7eb 8px
  );
  color: #9ca3af;
  cursor: not-allowed;
}
.acw-lane-day-cell.acw-lane-day-cell-blocked:hover {
  background: repeating-linear-gradient(
    -45deg,
    #f3f4f6,
    #f3f4f6 4px,
    #e5e7eb 4px,
    #e5e7eb 8px
  );
}

/* Recurrence pattern wanted this cell but it's unavailable for booking
   (capacity exhausted OR globally blocked). Overlay a ⚠ glyph on top of
   the existing × / hatch styling so the user can see both: "the pattern
   tried to land here AND this date isn't bookable". */
.acw-lane-day-cell.acw-lane-recurrence-warn {
  position: relative;
  background: #fef3c7;
  color: #92400e;
  cursor: not-allowed;
}
.acw-lane-day-cell.acw-lane-recurrence-warn::after {
  content: '⚠';
  font-size: 10px;
  position: absolute;
  top: 1px;
  right: 2px;
  line-height: 1;
}

/* Fee summary panel — UI-only (never enters question.value). One row per
   selected location showing range + days × rate subtotal, plus a total.
   Sits inside `host` next to the lane grid; the grid has its own horizontal
   overflow (intrinsic width = sum of day cells), so the summary explicitly
   pins to the host's content width with box-sizing: border-box. Without
   that, the summary would inherit the grid's intrinsic width and extend
   past the form card's right edge. */
.acw-lane-fee-summary {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  /* Long location names can push entries wide; min-width:0 lets flex
     children shrink past their content's intrinsic width. */
  min-width: 0;
}
.acw-lane-fee-heading {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  color: #1f2937;
}
.acw-lane-fee-entry,
.acw-lane-fee-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.25rem 0;
  font-size: 0.875rem;
  color: #374151;
  /* Allow children to shrink + wrap on very narrow viewports so the
     amount drops to a new line under the label rather than overflowing. */
  flex-wrap: wrap;
  min-width: 0;
}
.acw-lane-fee-entry .acw-lane-fee-label {
  min-width: 0;
  flex: 1 1 auto;
  /* Long date lists like "recurring on 2026-06-05, 2026-07-05, ..." would
     overflow the panel on a wide selection. Break aggressively on chars
     (not just words) so a long unbreakable string still wraps cleanly. */
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  max-width: 100%;
}
.acw-lane-fee-entry .acw-lane-fee-amount {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  flex: 0 0 auto;
}
.acw-lane-fee-total {
  border-top: 1px solid #d1d5db;
  margin-top: 0.4rem;
  padding-top: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
  color: #111827;
}

/* ---------- Mobile ---------- */

@media (max-width: 600px) {
  .acw-calendar {
    padding: 0.5rem;
    width: 100%;
    box-sizing: border-box;
  }
  .acw-day {
    /* On mobile, cells are ~50px wide. With aspect-ratio 1/1 they'd be
       50px tall, which doesn't leave enough room between the top-left dots
       and the centred day number — content visually clusters in the upper
       half. Drop the square enforcement and let min-height drive. Cells
       end up slightly taller than wide; dots and number get breathing room. */
    aspect-ratio: auto;
    min-height: 56px;
    font-size: 1rem;
    padding-top: 14px;     /* push day number below the dot row */
    padding-bottom: 4px;
    align-items: flex-start;
  }
  /* Subtle background on bookable cells so the cell bounds are visible on
     narrow viewports. */
  .acw-day:not([aria-disabled="true"]):not(.acw-selected) {
    background: rgba(0, 0, 0, 0.025);
  }
  /* Slightly larger dots so they're easier to read on small screens —
     applied via CSS so it overrides the inline 7px set by the decorator. */
  .acw-cell-dots > span {
    width: 8px !important;
    height: 8px !important;
  }
  .acw-nav {
    width: 40px;
    height: 40px;
  }
  .acw-day-badge {
    font-size: 0.55rem;
    padding: 1px 4px;
  }
  .acw-host-summary {
    font-size: 0.85rem;
  }
  .acw-host-legend {
    gap: 0.5rem 0.75rem !important;
  }
}

/* ===== T8: Mobile-stack fallback for the lane grid =====
   At <=640px viewport (and via the JS-applied .acw-mobile-stack class for
   container-driven responsiveness + testability), each lane row stacks its
   label as a full-width heading ABOVE the day-cell strip, instead of sitting
   beside it.

   Strategy: switch the row from `display: flex` to `display: block` so the
   label (block) naturally sits above the cells, then make cells `inline-flex`
   so they keep their content-centering and lay out left-to-right on a single
   inline line with `white-space: nowrap`. The grid's outer overflow-x: auto
   still drives a single shared horizontal scroll across all rows + header.
   The label is `position: sticky; left: 0` so it stays pinned to the viewport
   while the cells scroll. */
.acw-lane-grid.acw-mobile-stack .acw-lane-row,
.acw-lane-grid.acw-mobile-stack .acw-lane-day-header {
  display: block;
  white-space: nowrap;
}
.acw-lane-grid.acw-mobile-stack .acw-lane-row > .acw-lane-row-label {
  display: block;
  width: 100vw;
  max-width: 100vw;
  box-sizing: border-box;
  position: sticky;
  left: 0;
  z-index: 2;
  border-right: none;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}
.acw-lane-grid.acw-mobile-stack .acw-lane-row > .acw-lane-day-cell,
.acw-lane-grid.acw-mobile-stack .acw-lane-day-header > .acw-lane-day-cell {
  display: inline-flex;
  vertical-align: top;
  /* In a block-level row the flex shorthand on the cell is ignored, so we
     restate the dimensions explicitly. */
  width: 26px;
  min-width: 26px;
  height: 32px;
}
.acw-lane-grid.acw-mobile-stack .acw-lane-row-label-spacer {
  display: none;
}

/* Same rules via media query for plain-CSS robustness (works even if the JS
   hook hasn't fired yet — e.g. during initial mount frame). */
@media (max-width: 640px) {
  .acw-lane-grid .acw-lane-row,
  .acw-lane-grid .acw-lane-day-header {
    display: block;
    white-space: nowrap;
  }
  .acw-lane-grid .acw-lane-row > .acw-lane-row-label {
    display: block;
    width: 100vw;
    max-width: 100vw;
    box-sizing: border-box;
    position: sticky;
    left: 0;
    z-index: 2;
    border-right: none;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
  }
  .acw-lane-grid .acw-lane-row > .acw-lane-day-cell,
  .acw-lane-grid .acw-lane-day-header > .acw-lane-day-cell {
    display: inline-flex;
    vertical-align: top;
    width: 26px;
    min-width: 26px;
    height: 32px;
  }
  .acw-lane-grid .acw-lane-row-label-spacer {
    display: none;
  }
}
