/* Date pickers (DatePicker, DateRangePicker, DateTimePicker) and their calendar. The demo has no calendar of its own: the field is the
   demo's (app.css .field, kit.css .with-action and .field-btn) and the dialog its floating popover (app.css .popover); the grid keeps
   the console's density (34px columns, 30px days on the 8px control radius) and its marks: the action colour fills the chosen day,
   an accent dot marks today, accent-soft carries a period's band, weekends sit on a Sunken tint. */

/* ---------- Fields ---------- */

.date-pick { position: relative; display: block; flex: none; width: calc(10ch + 52px); font-variant-numeric: tabular-nums; }
.date-pick.with-time { width: calc(16ch + 52px); }
.date-pick .field { width: 100%; }
.date-field { display: inline-grid; gap: 6px; justify-items: start; vertical-align: top; }
.date-field > .ferr { max-width: 36ch; }
.spec-row:has(> .date-field) { align-items: flex-start; }

/* The rest of the mask while typing, over the field with the typed part transparent (1px border + 10px padding). */
.date-ghost {
  position: absolute; top: 0; bottom: 0; left: 11px; display: flex; align-items: center;
  pointer-events: none; white-space: pre; color: var(--ink-3);
}
.date-ghost > span { color: transparent; }

/* A period: two typed days in one field, an arrow between them. */
.date-range {
  position: relative; display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 32.5px; padding: 0 38px 0 10px; border-radius: var(--r-sm);
  border: 1px solid var(--line-strong); background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.date-range:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.date-range.invalid { border-color: var(--crit-mark); box-shadow: 0 0 0 3px color-mix(in oklab, var(--crit-mark) 14%, transparent); }
.date-range.disabled { background: var(--sunken); color: var(--ink-3); cursor: not-allowed; }
.date-slot { position: relative; display: block; }
.date-slot input { display: block; width: 10.5ch; height: 30px; padding: 0; border: 0; outline: none; background: transparent; }
.date-slot input::placeholder { color: var(--ink-3); }
.date-slot input:disabled { cursor: not-allowed; }
.date-slot .date-ghost { left: 0; }
.date-range-to { display: grid; place-items: center; color: var(--ink-3); }
.fgroup > .date-range { justify-self: start; }

/* ---------- Dialog ---------- */

.popover.date-pop { min-width: 0; max-width: calc(100vw - 16px); padding: 8px; }
.date-quick { display: flex; flex-wrap: wrap; gap: 5px; padding: 1px 1px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.date-quick .chip { height: 25px; padding: 0 10px; font-size: 12px; }
.date-quick .chip:disabled { opacity: 0.45; cursor: not-allowed; }
.date-foot { display: flex; align-items: center; gap: 6px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.date-gap { flex: 1; }
.date-sum { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* At phone width the line wraps instead of cutting the period being picked or its limit. */
.date-pop.narrow .date-sum { white-space: normal; }
.date-time-label { font-size: 12.5px; font-weight: 600; }
.date-time-row .time-field { gap: 0; }
.date-time-row .time-pick { width: calc(5ch + 60px); }

.date-range-body { display: flex; gap: 12px; }
.date-presets { display: grid; align-content: start; gap: 1px; width: 150px; flex: none; padding-right: 10px; border-right: 1px solid var(--line); }
.date-preset {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 30px; padding: 0 8px;
  border-radius: 7px; font-size: 13px; color: var(--ink-2); text-align: left; white-space: nowrap;
}
.date-preset:hover { background: var(--sunken); color: var(--ink); }
.date-preset[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.date-preset .icon { flex: none; color: var(--accent); }
.date-preset:disabled { opacity: 0.45; cursor: not-allowed; background: none; }
/* Phone width: one month under a scrolling row of preset chips. */
.date-pop.narrow .date-range-body { flex-direction: column; gap: 6px; }
.date-pop.narrow .date-presets {
  display: flex; width: auto; gap: 5px; overflow-x: auto; scrollbar-width: none;
  padding: 1px 1px 8px; border-right: 0; border-bottom: 1px solid var(--line);
}
.date-pop.narrow .date-preset { flex: none; height: 25px; padding: 0 10px; border: 1px solid var(--line-strong); border-radius: 99px; font-size: 12px; }
.date-pop.narrow .date-preset[aria-pressed="true"] { border-color: var(--accent-line); }
.date-pop.narrow .date-preset .icon { display: none; }

/* ---------- Calendar ---------- */

.cal { --cal-cell: 34px; --band: var(--accent-soft); display: grid; gap: 2px; min-width: calc(7 * var(--cal-cell)); font-variant-numeric: tabular-nums; }
.cal.wk { min-width: calc(7 * var(--cal-cell) + 26px); }
/* The month and year grids keep the size of the days they replace. */
.cal:not([data-view="day"]) { width: calc(7 * var(--cal-cell)); }
.cal.wk:not([data-view="day"]) { width: calc(7 * var(--cal-cell) + 26px); }
.cal.two:not([data-view="day"]) { width: calc(14 * var(--cal-cell) + 17px); }
.cal.two.wk:not([data-view="day"]) { width: calc(14 * var(--cal-cell) + 69px); }
.cal-months { display: flex; gap: 17px; }
.cal-month { display: grid; gap: 2px; align-content: start; }
.cal-head { display: flex; align-items: center; gap: 4px; height: 30px; }
.cal-nav, .cal-nav-gap { flex: none; width: 28px; height: 28px; }
.cal-nav { display: grid; place-items: center; border-radius: var(--r-sm); color: var(--ink-2); transition: background 0.15s, color 0.15s; }
.cal-nav:hover:not(:disabled) { background: var(--sunken); color: var(--ink); }
.cal-nav:disabled { opacity: 0.35; cursor: default; }
.cal-title { flex: 1; display: flex; justify-content: center; align-items: center; gap: 1px; min-width: 0; }
.cal-pick {
  display: inline-flex; align-items: center; gap: 3px; height: 28px; padding: 0 6px 0 8px; border-radius: var(--r-sm);
  font-size: 13.5px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); text-transform: capitalize; transition: background 0.15s;
}
.cal-pick .icon { color: var(--ink-3); }
.cal-pick:hover { background: var(--sunken); }
.cal-label { display: inline-block; font-size: 13.5px; font-weight: 700; letter-spacing: -0.01em; }
.cal-label::first-letter { text-transform: uppercase; }

/* Clipped so a new month can slide in, with room for the focus outline. */
.cal-clip { overflow: clip; overflow-clip-margin: 4px; min-height: 216px; }
.cal-grid { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.cal-grid th { width: var(--cal-cell); height: 24px; padding: 0; font-size: 11px; font-weight: 600; color: var(--ink-3); text-align: center; }
.cal-grid .cal-wk { width: 26px; font-size: 10.5px; font-weight: 500; color: var(--ink-3); text-align: center; }
.cal-grid tbody .cal-wk { border-right: 1px solid var(--line); }
.cal-day { height: 32px; padding: 1px 0; text-align: center; }

/* Weekend columns on a Sunken tint, rounded at their outer corners. */
.cal-grid .we { background: color-mix(in oklab, var(--sunken) 62%, transparent); }
.cal-grid th.we.wl { border-top-left-radius: 8px; }
.cal-grid th.we.wr { border-top-right-radius: 8px; }
.cal-grid td.we.lr.wl { border-bottom-left-radius: 8px; }
.cal-grid td.we.lr.wr { border-bottom-right-radius: 8px; }

.cal-cell {
  position: relative; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: var(--r-sm);
  font-size: 13px; color: var(--ink); transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}
.cal-cell:hover { background: var(--sunken); }
.cal-day.out .cal-cell { color: var(--ink-3); }
.cal-cell.today { color: var(--accent); font-weight: 700; }
.cal-cell.today::after {
  content: ""; position: absolute; left: 50%; bottom: 3.5px; width: 4px; height: 4px; margin-left: -2px;
  border-radius: 50%; background: currentColor;
}
.cal-cell.off, .cal-cell.off:hover { color: var(--ink-3); opacity: 0.4; background: none; cursor: not-allowed; }
.cal-day.sel .cal-cell, .cal-cells .cal-cell.sel {
  background: var(--btn); color: #FFFFFF; font-weight: 700; box-shadow: 0 5px 12px -7px var(--btn);
}
.cal-day.sel .cal-cell:hover, .cal-cells .cal-cell.sel:hover { background: color-mix(in oklab, var(--btn) 88%, #000000); }

/* A period: a continuous band, half-cells at its ends, rounded where a row or the month breaks it. */
.cal-day.band { background: var(--band); }
.cal-day.band.b-start { background: linear-gradient(90deg, transparent 50%, var(--band) 50%); }
.cal-day.band.b-end { background: linear-gradient(90deg, var(--band) 50%, transparent 50%); }
.cal-day.band.b-start.b-end, .cal-day.band.b-start.b-r, .cal-day.band.b-end.b-l { background: none; }
.cal-day.band.b-l:not(.b-start) { border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.cal-day.band.b-r:not(.b-end) { border-top-right-radius: 8px; border-bottom-right-radius: 8px; }
.cal-day.band:not(.sel) .cal-cell:hover { background: color-mix(in oklab, var(--accent) 16%, var(--surface)); }
/* Still picking: a lighter band to the pointer, whose end is only outlined until it is clicked. */
.cal-day.preview { --band: color-mix(in oklab, var(--accent-soft) 60%, var(--surface)); }
.cal-day.preview.sel:not(.anchor) .cal-cell { background: var(--surface); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* Months and years. */
.cal-cells { width: 100%; height: 216px; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.cal-cells td { padding: 0; }
.cal-cells .cal-cell { width: 100%; height: 100%; min-height: 30px; font-size: 13px; text-transform: capitalize; }
.cal-cells .cal-cell.today::after { bottom: 5px; }

/* A new month slides in from its side; the month and year grids zoom in. */
.cal-body.cal-in-next { animation: cal-next 0.26s var(--ease-out); }
.cal-body.cal-in-prev { animation: cal-prev 0.26s var(--ease-out); }
.cal-body.cal-in-zoom { animation: cal-zoom 0.2s var(--ease-out); }
@keyframes cal-next { from { opacity: 0; transform: translateX(22px); } }
@keyframes cal-prev { from { opacity: 0; transform: translateX(-22px); } }
@keyframes cal-zoom { from { opacity: 0; transform: scale(0.95); } }
@media (prefers-reduced-motion: reduce) {
  .cal-body.cal-in-next, .cal-body.cal-in-prev, .cal-body.cal-in-zoom { animation: none; }
  .cal-cell, .cal-nav, .cal-pick { transition: none; }
}
html.reduce-motion .cal-body { animation: none !important; }
html.reduce-motion .cal-cell { transition: none; }

/* The date filter of a data table column: presets, the calendar and the period it makes. */
.dt-pop:has(> .dt-date-pop) { width: auto; }
.dt-date-pop .date-quick { margin-bottom: 0; }
.dt-date-pop .date-sum { min-height: 18px; }
