/* ไปกัน! date picker (js/core/datepicker.js) — prefix .dp-
   Field buttons that replace the native date inputs, and the iOS-style Thai calendar panel:
   a glass bottom sheet on phones, a glass popover anchored to the field on >=700px. Tokens only. */

/* ======================= field: one date / date + time ======================= */
.dp-field {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-width: 0; min-height: 48px;
  padding: 10px 14px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: var(--surface-sunk); color: var(--ink);
  font-size: 16px; font-weight: 700; line-height: 1.3; text-align: left;
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur), transform 120ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.dp-f-ico { display: inline-grid; place-items: center; flex: 0 0 auto; color: var(--primary); }
.dp-f-text { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; min-width: 0; }
.dp-f-date, .dp-f-time { white-space: nowrap; }
.dp-f-dot { margin-right: 6px; color: var(--ink-3); font-weight: 400; }
.dp-f-ph { color: var(--ink-3); font-weight: 400; }
.dp-field:active { transform: scale(.985); }
.dp-field:focus-visible, .dp-field.is-open {
  background: var(--surface); border-color: var(--primary); box-shadow: var(--focus-ring); border-radius: var(--r-sm);
}
.dp-field:disabled { opacity: .5; pointer-events: none; }
@media (hover: hover) { .dp-field:not(.is-open):hover { background: color-mix(in srgb, var(--surface-sunk) 72%, var(--primary-soft)); } }

/* ======================= field: start → end pair (trip dates) ======================= */
.dp-range {
  position: relative; min-width: 0;
  border: 1px solid transparent; border-radius: var(--r-md);
  background: var(--surface-sunk);
  transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
}
.dp-range.is-open { background: var(--surface); border-color: var(--primary); box-shadow: var(--focus-ring); }
.dp-range-pair { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.dp-range-pair::before {               /* hairline between the halves */
  content: ""; position: absolute; left: 50%; top: 12px; bottom: 12px; width: 1px;
  background: var(--line-strong); pointer-events: none;
}
.dp-rh {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 3px;
  min-width: 0; min-height: 64px; padding: 10px 22px 10px 16px;
  border: 0; border-radius: var(--r-md); background: transparent; color: var(--ink); text-align: left;
  transition: background var(--dur), transform 120ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.dp-rh[data-part="end"] { padding: 10px 14px 10px 26px; }
.dp-rh-l { max-width: 100%; font-size: var(--fs-xs); font-weight: 400; color: var(--ink-3); line-height: 1.3; }
.dp-rh-v { max-width: 100%; font-size: 16px; font-weight: 700; line-height: 1.3; white-space: nowrap; }
.dp-rh.is-open .dp-rh-v { color: var(--primary); }
.dp-rh:active { transform: scale(.98); }
.dp-rh:focus-visible { box-shadow: inset 0 0 0 2px var(--primary); border-radius: var(--r-md); }
.dp-rh:disabled { opacity: .5; pointer-events: none; }
@media (hover: hover) { .dp-range:not(.is-open) .dp-rh:hover { background: color-mix(in srgb, var(--surface-sunk) 60%, var(--primary-soft)); } }
.dp-range-mid {
  position: absolute; left: 50%; top: 50%; z-index: 1;
  display: grid; place-items: center; width: 28px; height: 28px; margin: -14px 0 0 -14px;
  border-radius: 50%; background: var(--surface); color: var(--primary);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); pointer-events: none;
}
.dp-range-foot {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 12px 9px; border-top: 1px solid var(--line);
  color: var(--primary); font-size: var(--fs-sm); font-weight: 700;
}
/* very narrow phones: a little less padding so the full date always fits */
@media (max-width: 359px) {
  .dp-rh { padding-right: 18px; padding-left: 12px; }
  .dp-rh[data-part="end"] { padding-left: 20px; padding-right: 10px; }
}

/* ======================= picker layer ======================= */
.dp-layer { position: fixed; inset: 0; z-index: 120; }
.dp-scrim { position: absolute; inset: 0; background: transparent; }
.dp-layer.is-sheet .dp-scrim, .dp-layer.is-center .dp-scrim { background: color-mix(in srgb, var(--scrim) 30%, transparent); animation: dpFade var(--dur) var(--ease); }

.dp-panel {
  --dp-row: 40px;                       /* time wheel row */
  --dp-rows: 3;                         /* visible wheel rows */
  position: fixed; display: flex; flex-direction: column; min-width: 0;
  /* glass, but nearly solid: a calendar must stay readable over busy sheets (icon grids, colour dots) */
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-edge), var(--shadow-3);
  color: var(--ink);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { .dp-panel { background: var(--surface); } }
@media (pointer: coarse) { .dp-panel { --dp-row: 44px; } }   /* wheel rows are tap targets too */

/* phones: bottom sheet over the current sheet */
.dp-layer.is-sheet .dp-panel {
  left: 0; right: 0; bottom: 0; margin: 0 auto;
  width: 100%; max-width: 480px; max-height: calc(100dvh - var(--safe-top) - 16px);
  border-bottom: 0; border-radius: var(--r-xl) var(--r-xl) 0 0;
  animation: dpUp 280ms var(--ease);
}
/* >=700px: popover next to the field (left/top set in JS) */
.dp-layer.is-pop .dp-panel {
  width: min(360px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  border-radius: var(--r-lg);
  animation: dpPop 200ms var(--ease);
}
.dp-layer.is-pop .dp-panel.dp-m-datetime { --dp-rows: 5; width: min(560px, calc(100vw - 24px)); }
.dp-layer.is-pop .dp-panel.dp-m-time { width: min(300px, calc(100vw - 24px)); }
.dp-panel.dp-m-time { --dp-rows: 5; }
.dp-layer.is-out { pointer-events: none; }
.dp-layer.is-out .dp-scrim { opacity: 0; transition: opacity 160ms var(--ease); }
.dp-layer.is-out .dp-panel { opacity: 0; transform: translateY(10px); transition: opacity 160ms var(--ease), transform 160ms var(--ease); }
.dp-layer.is-sheet.is-out .dp-panel { transform: translateY(40%); }

.dp-grab { display: none; flex: 0 0 auto; width: 40px; height: 5px; margin: 10px auto 0; border-radius: 99px; background: var(--line-strong); }
.dp-layer.is-sheet .dp-grab { display: block; }
.dp-scroll {
  flex: 1 1 auto; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain;
  padding: 6px 12px 4px; scrollbar-width: thin;
}
.dp-main, .dp-cal { min-width: 0; }
.dp-eyebrow { padding: 6px 8px 0; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-3); letter-spacing: .02em; overflow-wrap: anywhere; }

/* ---- header: month + year, chevrons ---- */
.dp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; padding: 2px 0 4px; }
.dp-title {
  display: inline-flex; align-items: center; gap: 4px; min-width: 0; min-height: 44px; padding: 6px 8px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink);
  font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 700; line-height: 1.25; text-align: left;
}
.dp-title-t { min-width: 0; }
.dp-title .ico { color: var(--primary); transition: transform var(--dur) var(--ease); }
.dp-title[aria-expanded="true"] { color: var(--primary); }
.dp-title[aria-expanded="true"] .ico { transform: rotate(90deg); }
.dp-navs { display: flex; flex: 0 0 auto; gap: 2px; }
.dp-panel.is-months .dp-navs { visibility: hidden; }
.dp-nav {
  display: grid; place-items: center; width: 44px; height: 44px; flex: 0 0 auto;
  border: 0; border-radius: 50%; background: transparent; color: var(--primary);
  transition: background var(--dur), transform 120ms var(--ease);
}
.dp-nav:active { background: var(--primary-soft); transform: scale(.94); }
.dp-nav:focus-visible { border-radius: 50%; }
@media (hover: hover) { .dp-nav:hover, .dp-title:hover { background: var(--primary-soft); } }

/* ---- day grid ---- */
.dp-days { overflow: hidden; touch-action: pan-y; }
.dp-grid { display: flex; flex-direction: column; }
.dp-wd, .dp-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.dp-wdc { display: grid; place-items: center; height: 28px; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-3); }
.dp-day {
  position: relative; display: grid; place-items: center; min-width: 0; height: 44px; padding: 0;
  border: 0; background: transparent; color: var(--ink); font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
.dp-day::before {                       /* range band */
  content: ""; position: absolute; inset: 2px 0; background: var(--primary-soft); opacity: 0; pointer-events: none;
}
.dp-day.is-mid::before { opacity: 1; }
.dp-week > .dp-day:first-child::before { left: 2px; border-radius: 999px 0 0 999px; }
.dp-week > .dp-day:last-child::before { right: 2px; border-radius: 0 999px 999px 0; }
.dp-day.has-band.is-start::before { opacity: 1; left: 50%; }
.dp-day.has-band.is-end::before { opacity: 1; right: 50%; }
.dp-n {
  position: relative; z-index: 1; display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 50%; line-height: 1;
  transition: background var(--dur), color var(--dur), transform 120ms var(--ease);
}
.dp-day.is-out .dp-n { color: var(--ink-3); opacity: .55; }
.dp-day.is-out.is-mid .dp-n { color: var(--ink-2); opacity: 1; }   /* next month's day inside the band: in range, not disabled */
.dp-day.is-today .dp-n { color: var(--primary); font-weight: 700; }
.dp-day.is-today .dp-n::after {
  content: ""; position: absolute; left: 50%; bottom: 5px; width: 4px; height: 4px; margin-left: -2px;
  border-radius: 50%; background: currentColor;
}
.dp-day.is-sel .dp-n {
  background: var(--primary-strong); color: var(--primary-ink); font-weight: 700; opacity: 1;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 32%, transparent);
}
.dp-day.is-dis { cursor: default; }
.dp-day.is-dis .dp-n { color: var(--ink-3); opacity: .38; }
.dp-day:not(.is-dis):active .dp-n { transform: scale(.92); }
.dp-day:focus-visible { box-shadow: none; }
.dp-day:focus-visible .dp-n { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary); }
@media (hover: hover) {
  .dp-day:not(.is-sel):not(.is-dis):hover .dp-n { background: var(--surface-sunk); }
  .dp-day.is-mid:not(.is-dis):hover .dp-n { background: color-mix(in srgb, var(--primary) 16%, transparent); }
}
.dp-grid.dp-in-l { animation: dpInL 240ms var(--ease); }
.dp-grid.dp-in-r { animation: dpInR 240ms var(--ease); }

/* ---- 12-month grid + year stepper ---- */
.dp-months { min-height: 292px; padding: 2px 0 6px; }
.dp-ystep {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: max-content; max-width: 100%; margin: 0 auto 8px; padding: 0 4px;
  border-radius: var(--r-pill); background: var(--surface-sunk);
}
.dp-year { min-width: 6.5em; text-align: center; font-size: var(--fs-md); font-weight: 700; }
.dp-mgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.dp-mo {
  min-width: 0; min-height: 52px; padding: 6px 4px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink);
  font-size: var(--fs-sm); line-height: 1.3;
  transition: background var(--dur), color var(--dur), transform 120ms var(--ease);
}
.dp-mo-s { display: none; }
.dp-mo.is-now { color: var(--primary); font-weight: 700; }
.dp-mo.is-sel { background: var(--primary-strong); color: var(--primary-ink); font-weight: 700; }
.dp-mo[aria-disabled="true"] { opacity: .38; cursor: default; }
.dp-mo:active { transform: scale(.96); }
@media (hover: hover) { .dp-mo:not(.is-sel):not([aria-disabled="true"]):hover { background: var(--surface-sunk); } }
@media (max-width: 339px) { .dp-mo-l { display: none; } .dp-mo-s { display: inline; } }

/* ---- time wheel (date + time) ---- */
.dp-time {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 6px; padding: 8px 4px 2px 8px; border-top: 1px solid var(--line);
}
.dp-time-l { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 700; }
.dp-time-l .ico { color: var(--primary); }
.dp-wheel { position: relative; display: flex; align-items: center; gap: 2px; padding: 0 8px; }
.dp-wh-band {
  position: absolute; left: 0; right: 0; top: 50%; height: var(--dp-row); transform: translateY(-50%);
  border-radius: var(--r-sm); background: var(--primary-soft); pointer-events: none;
}
.dp-wh-col {
  position: relative; width: 60px; height: calc(var(--dp-row) * var(--dp-rows));
  padding-block: calc(var(--dp-row) * (var(--dp-rows) - 1) / 2);
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y;
  scroll-snap-type: y mandatory; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(transparent, black 34%, black 66%, transparent);
  mask-image: linear-gradient(transparent, black 34%, black 66%, transparent);
}
.dp-layer.is-pop .dp-m-datetime .dp-wh-col {
  -webkit-mask-image: linear-gradient(transparent, black 30%, black 70%, transparent);
  mask-image: linear-gradient(transparent, black 30%, black 70%, transparent);
}
.dp-wh-col::-webkit-scrollbar { display: none; }
.dp-wh-col:focus-visible { box-shadow: none; }
.dp-wh-col:focus-visible .dp-wh-i.is-sel { outline: 2px solid var(--primary); outline-offset: -2px; border-radius: var(--r-xs); }
.dp-wh-i {
  display: grid; place-items: center; height: var(--dp-row);
  scroll-snap-align: center; cursor: pointer;
  font-size: 20px; color: var(--ink-3); transition: color 120ms;
}
.dp-wh-i.is-sel { color: var(--ink); font-weight: 700; }
.dp-wh-sep { position: relative; font-size: 20px; font-weight: 700; color: var(--ink); }
.dp-wh-unit { position: relative; margin-left: 2px; font-size: var(--fs-sm); font-weight: 700; color: var(--ink-2); }
/* popover: wheel beside the calendar */
.dp-layer.is-pop .dp-m-datetime .dp-main { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
/* time only: the wheel is the whole picker */
.dp-m-time .dp-time { justify-content: center; margin: 0; padding: 6px 0 2px; border-top: 0; }
.dp-m-time .dp-time-l { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.dp-m-time .dp-wh-col { width: 72px; }
.dp-m-time .dp-wh-i, .dp-m-time .dp-wh-sep { font-size: 24px; }
.dp-layer.is-pop .dp-m-datetime .dp-time {
  flex-direction: column; justify-content: center; gap: 10px;
  margin: 0; padding: 0 0 0 10px; border-top: 0; border-left: 1px solid var(--line);
}

/* ---- quick chips, summary, footer ---- */
.dp-chips { position: relative; display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 4px 2px; }
/* many shortcuts (a trip's days): one sideways-scrolling row instead of a tall wrapped block */
.dp-chips.is-scroll {
  flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  margin-inline: -12px; padding-inline: 16px; scroll-padding-inline: 16px; scroll-snap-type: x proximity;
  -webkit-mask-image: linear-gradient(90deg, transparent, black 16px, black calc(100% - 16px), transparent);
  mask-image: linear-gradient(90deg, transparent, black 16px, black calc(100% - 16px), transparent);
}
.dp-chips.is-scroll::-webkit-scrollbar { display: none; }
.dp-chips.is-scroll .dp-chip { flex: 0 0 auto; scroll-snap-align: start; white-space: nowrap; }
.dp-chip:disabled { opacity: .45; pointer-events: none; }
.dp-sum {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 8px 4px 6px; padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--surface-sunk); color: var(--ink); font-size: var(--fs-sm); text-align: center;
}
.dp-sum > .ico { color: var(--primary); }
.dp-sum-t { display: flex; flex-wrap: wrap; justify-content: center; column-gap: 6px; min-width: 0; }
.dp-sum-t > * { white-space: nowrap; }
.dp-sum-t b { color: var(--primary); }
.dp-sum-dot { color: var(--ink-3); }
.dp-sum-hint { color: var(--ink-3); }
.dp-foot {
  flex: 0 0 auto; display: flex; gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--line);
}
.dp-foot .btn { flex: 1 1 0; }
.dp-layer.is-pop .dp-foot { padding-bottom: 10px; }
/* anchored popover: compact, right-aligned, tinted OK (the sheet underneath keeps the one gradient primary) */
.dp-layer.is-pop:not(.is-center) .dp-foot { justify-content: flex-end; padding: 8px 12px; }
.dp-layer.is-pop:not(.is-center) .dp-foot .btn { flex: 0 0 auto; min-width: 88px; }

/* ---- dark: a little more contrast for the band and the hover tint ---- */
:root[data-theme="dark"] .dp-day::before, :root[data-theme="dark"] .dp-wh-band { background: color-mix(in srgb, var(--primary) 26%, transparent); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dp-day::before, :root:not([data-theme="light"]) .dp-wh-band { background: color-mix(in srgb, var(--primary) 26%, transparent); }
}

@keyframes dpUp { from { transform: translateY(100%); } }
@keyframes dpPop { from { opacity: 0; transform: scale(.96) translateY(-4px); } }
@keyframes dpFade { from { opacity: 0; } }
@keyframes dpInL { from { opacity: .2; transform: translateX(28px); } }
@keyframes dpInR { from { opacity: .2; transform: translateX(-28px); } }
@media (prefers-reduced-motion: reduce) {
  .dp-panel, .dp-scrim, .dp-grid, .dp-n, .dp-field, .dp-rh, .dp-nav, .dp-mo, .dp-title .ico { animation: none !important; transition: none !important; }
  .dp-layer.is-out .dp-panel { transform: none; }
}
