/* ── dv-datepicker ─────────────────────────────────────────────────────────
   Custom design-system date picker. Vanilla-JS calendar replacing the
   daterangepicker (jQuery) vendor lib for `fields--date` fields. Progressive
   enhancement: the gem's `.date-input` markup stays (hidden field = submit
   source of truth + display field), and this UI is layered on the display
   field's wrapper. Token-only.

   Ported from tmp/form-elements-preview.html (.cal / .cals / .cal__*). The
   .dv-field / .dv-pop trigger + popover shells are shared with dv_select.css;
   only datepicker-specific rules live here.
   ──────────────────────────────────────────────────────────────────────── */

/* Wrapper turns relative so the popover can anchor to the trigger. */
.dv-datepicker { position: relative; }

/* The native gem inputs (display + hidden) stay in the DOM but are visually
   hidden. The display input remains the value source the controller writes to;
   we mirror its value into .dv-field__val. */
.dv-datepicker__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Trigger — reuses .dv-field look from dv_select.css. The calendar icon sits
   on the LEFT of the value (matches approved preview row). */
.dv-datepicker .dv-field { justify-content: flex-start; }
.dv-datepicker .dv-field__val.is-placeholder { color: var(--text-muted); }

/* ── Calendar popover body ── */
.dv-pop--cal { padding: 12px; width: max-content; min-width: auto; }
/* Scoped to the popover — `.cal` / `.cals` are generic enough to collide with
   unrelated markup (e.g. the booking ticketband's `<span class="cal">`), so they
   must never leak as bare global selectors. */
.dv-pop--cal .cals { display: flex; gap: 20px; flex-wrap: wrap; }
.dv-pop--cal .cal { width: 260px; padding: 6px; }
.cal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 10px;
}
.cal__title { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); }
.cal__nav {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: transparent;
}
.cal__nav:hover { background: var(--surface-alt); color: var(--text-primary); }
.cal__nav:disabled,
.cal__nav.is-hidden { visibility: hidden; }

.cal__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal__dow {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 0;
}
.cal__day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-primary);
  user-select: none;
}
.cal__day.is-empty { cursor: default; }
.cal__day:not(.is-empty):hover { background: var(--surface-alt); }
.cal__day.is-muted { color: var(--border-strong); }
/* before today — lighter, but STILL selectable (not disabled) */
.cal__day.is-past { color: #9CA3AF; }
.cal__day.is-today { font-weight: 700; color: var(--accent); }
.cal__day.is-sel { background: var(--accent); color: #fff; font-weight: 600; }
.cal__day.is-range { background: var(--accent-light); color: var(--accent-strong); border-radius: 0; }
.cal__day.is-range.r-start { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.cal__day.is-range.r-end { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
/* keyboard focus cursor */
.cal__day.is-focus { box-shadow: inset 0 0 0 2px var(--accent); }

/* keyboard focus cursor on the selected day shouldn't double up the ring */
.cal__day.is-sel.is-focus { box-shadow: inset 0 0 0 2px #fff; }

/* ── Time row (only for include-time fields) ──
   Ported from tmp/form-elements-preview.html (.dv-time / .dv-seg / .dv-ampm).
   Reused standalone by fields--time (dv_timepicker via @import of this file). */
.cal__time {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px 2px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}
.cal__time-label { font-size: var(--text-xs); font-weight: 600; color: var(--text-muted); }

/* ── .dv-time component (HH:MM segment + AM/PM toggle) ── */
.dv-time { display: inline-flex; align-items: center; gap: 10px; width: max-content; }
.dv-seg {
  flex: 0 0 auto;        /* don't stretch/shrink inside a form flex/grid cell */
  display: inline-flex;
  align-items: center;
  width: max-content;
  height: 38px;
  padding: 0 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
}
.dv-seg:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.dv-seg input {
  flex: 0 0 auto;        /* never collapse below content width */
  width: 32px;
  min-width: 32px;
  box-sizing: content-box;
  padding: 0;
  text-align: center;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: var(--text-md);
  height: 100%;
  color: var(--text-primary);
  background: transparent;
  -moz-appearance: textfield;
}
.dv-seg input::-webkit-outer-spin-button,
.dv-seg input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.dv-seg__c { color: var(--text-muted); font-size: var(--text-md); }
.dv-ampm {
  display: inline-flex;
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.dv-ampm button {
  border: none;
  background: var(--surface);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 0 16px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .12s, color .12s;
}
.dv-ampm button + button { border-left: 1px solid var(--border-strong); }
.dv-ampm button.on { background: var(--accent); color: #fff; }
.dv-ampm button:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

/* Hidden native time input — stays the submission source of truth. */
.dv-time__native {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Footer (clear) ── */
.cal__foot {
  display: flex;
  justify-content: flex-end;
  padding: 8px 6px 2px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}
.cal__clear {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
}
.cal__clear:hover { background: var(--surface-alt); color: var(--text-primary); }
