/* The date picker (public/js/datepicker.js): a text field in the agency's format, a
 * calendar button, and a month grid in a dialog. Tokens only, square corners. The grid
 * reads like Today's strip: weekday initials small and quiet, day numbers in the display
 * face; the selected day in the section's hue, today ringed, weekends and closures muted
 * (closures hatched, as on Today). Placed by the script with CSSOM (top/left).
 * Sizes come from app.css's tokens (--control-h, --control-h-sm, --fs-*), as the themed
 * dropdown's do (select.css): the field is as tall as a select, the dialog opens with
 * the same 140ms fade and 4px slide and sits at the dropdown list's layer. */

.datefield { display: flex; align-items: stretch; width: 100%; min-width: 0; position: relative; }
/* A small basis, so a narrow grid cell (the audit filters on a phone) can hold it; it
 * grows to the field's width. */
.datefield .datefield-text { flex: 1 1 8em; min-width: 0; width: 8em; }
.datefield-btn {
  flex: none; display: grid; place-items: center; width: var(--control-h); min-height: var(--control-h); margin-left: -1px;
  background: var(--surface); color: var(--text-2); border: 1px solid var(--border-control); border-radius: 0;
  cursor: pointer; padding: 0;
}
.datefield-btn:hover { border-color: var(--text-2); color: var(--text); }
.datefield-btn[aria-expanded="true"] { border-color: var(--ink, var(--focus)); background: var(--tint, var(--raised)); color: var(--text); }
.datefield-btn svg { width: 16px; height: 16px; }
.datefield-btn:focus-visible { position: relative; z-index: 1; }
.datefield-btn:disabled { opacity: .6; cursor: not-allowed; }
.datefield-text:invalid:not(:placeholder-shown):not(:focus) { border-color: var(--danger); }
.datefield-error { display: block; margin-top: var(--space-1); color: var(--danger); font-size: var(--fs-small); font-weight: 600; }
.datefield-error[hidden] { display: none; }
.field .hint.date-result:empty { display: none; }

.datepop {
  position: fixed; z-index: 60; top: 0; left: 0;
  width: calc(var(--control-h-sm) * 8.5); max-width: calc(100vw - 16px);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-top: 3px solid var(--hue, var(--accent));
  box-shadow: var(--shadow);
  font: var(--fs-body)/1.4 var(--font);
  opacity: 0; transform: translateY(-4px);
  transition: opacity 140ms ease-out, transform 140ms ease-out;
}
.datepop.up { transform: translateY(4px); border-top: 1px solid var(--line-strong); border-bottom: 3px solid var(--hue, var(--accent)); }
.datepop.in { opacity: 1; transform: none; }
.datepop[hidden] { display: none; }

.datepop-head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-1); }
.datepop-title { flex: 1; margin: 0; text-align: center; font: 650 var(--fs-h2)/1.2 var(--font-display); }
.datepop-nav {
  width: var(--control-h-sm); height: var(--control-h-sm); display: grid; place-items: center; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 0; color: var(--text-2);
  font-size: var(--fs-h2); line-height: 1; cursor: pointer;
}
.datepop-nav:hover { background: var(--raised); border-color: var(--line); color: var(--text); }

.datepop-grid { width: 100%; border-collapse: collapse; table-layout: fixed; margin: 0; }
.datepop-grid th {
  padding: var(--space-1) 0 var(--space-2); font-size: var(--fs-meta); font-weight: 600; color: var(--text-2); text-align: center;
  border-bottom: 1px solid var(--line);
}
.datepop-grid th.off { color: var(--text-3); }
.datepop-grid td { padding: 0; height: var(--control-h-sm); text-align: center; }
.datepop-grid td.cal-day {
  font: 600 var(--fs-body)/1 var(--font-display); font-variant-numeric: tabular-nums; color: var(--text);
  cursor: pointer; position: relative;
}
.datepop-grid td.cal-day:hover { background: var(--tint, var(--raised)); }
.datepop-grid td.cal-weekend { color: var(--text-3); font-weight: 500; }
.datepop-grid td.cal-closed {
  color: var(--text-3); font-weight: 500;
  background: repeating-linear-gradient(135deg, transparent 0 5px, var(--hatch) 5px 6px);
}
.datepop-grid td.cal-today { box-shadow: inset 0 0 0 2px var(--ink, var(--focus)); }
.datepop-grid td[aria-selected="true"] { background: var(--hue, var(--accent)); color: var(--on-hue); font-weight: 700; }
.datepop-grid td.cal-today[aria-selected="true"] { box-shadow: inset 0 0 0 2px var(--hue, var(--accent)), inset 0 0 0 4px var(--surface); }
.datepop-grid td.cal-disabled { color: var(--text-3); opacity: .4; cursor: not-allowed; }
.datepop-grid td.cal-disabled:hover { background: transparent; }
.datepop-grid td:focus-visible { outline: 2px solid var(--ink, var(--focus)); outline-offset: -2px; }

.datepop-foot {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-2); border-top: 1px solid var(--line); margin-top: var(--space-1);
}
.datepop-note { margin: 0; min-height: 1.4em; font-size: var(--fs-meta); color: var(--text-2); line-height: 1.4; }
.datepop-today {
  flex: none; min-height: var(--control-h-sm); padding: 0 var(--space-3); border: 1px solid var(--line-strong); border-radius: 0;
  background: transparent; font-weight: 600; font-size: var(--fs-small); cursor: pointer;
}
.datepop-today:hover { background: var(--raised); }

@media (prefers-reduced-motion: reduce) {
  .datepop, .datepop.up { transition: none; transform: none; }
}

@media (max-width: 599px) {
  .datepop { width: min(calc(var(--control-h) * 8.5), calc(100vw - 16px)); }
  .datepop-grid td { height: var(--control-h); }
}
