/* ===========================================================================
   SGE'S OWN DATE FIELD — the look. Markup: src/date-field.js. Behaviour:
   public/date-field.js.

   KEITH, 18 September 2026: "Go with Option 3" — SGE's own text field reading
   and accepting DD-MM-YYYY, plus a small button that opens a calendar picker.

   IT IS ITS OWN SHEET, not an appendix to style.css, for the reason the shell
   already gives for public/list-preview.css and public/shells.css: this is one
   component with one behaviour file, and the page shell has a seam for exactly
   that. On a screen with no date field every rule below is inert.

   IT INVENTS NO TOKEN, NO COLOUR AND NO SPACING VALUE. Everything below is a
   --sp-*, --fw-*, --r-*, --tap or palette token already defined in style.css.

   THE ONE THING WORTH READING TWICE is .dfield-native. That element is a real
   <input type="date"> — it carries the form name, it posts YYYY-MM-DD, and it
   is what opens the picker. It is drawn at zero opacity exactly over the
   calendar glyph, so the glyph IS the control: the picker opens on a press with
   no JavaScript, on a desktop and on a phone alike. It is NOT display:none and
   NOT visibility:hidden — both would take the picker away from a keyboard and
   make a required empty field unfocusable, which is the bug that shape usually
   ships with.
   =========================================================================== */

.dfield {
  display: inline-flex;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: var(--space-xxs);
  max-width: 100%;
  vertical-align: top;
}

/* ON THE SCHEDULE APPOINTMENT CARD THE LABEL IS ABOVE ITS BOXES — 21 October
   2026, Keith: "Date & time" sat left of its two boxes while "Type" and "Notes"
   had theirs underneath. The pair is inline-flex, so it follows the label text
   on the same line; here it is block-level like the select and text box beside
   it. The boxes keep their own widths. */
.appointment-form > label > .dfield { display: flex; }

/* THE FIELD IS SIZED TO WHAT IT HOLDS — Keith: "A date box holds a date's worth
   of space". --fw-date is the cap style.css already gives a native date box, so
   the replacement is the width of the thing it replaced. */
.dfield > .dfield-text {
  width: var(--fw-date);
  max-width: 100%;
  margin-top: 0;
  flex: 0 1 auto;
  font-variant-numeric: tabular-nums;
}

/* THE TIME, on the two appointment boxes that hold a day AND a time. It is a
   native <input type="time">: Keith's rule governs how a DATE is written, and
   the date beside this is SGE's own control. The box is sized to what it holds
   — "A date box holds a date's worth of space" — which for HH:MM is the short
   width style.css already defines, not a date's. */
.dfield > .dfield-clock {
  width: var(--fw-short);
  max-width: 100%;
  margin-top: 0;
  flex: 0 1 auto;
  font-variant-numeric: tabular-nums;
}

/* The picker. --tap is the 44px floor of BS-001 rule V8, which Keith confirmed
   stands at every width: "understand.. then maintan it". */
.dfield-pick {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: var(--tap);
  min-height: var(--tap);
  border: 1px solid var(--field-line);
  border-radius: var(--r-sm);
  background: var(--field-bg);
  color: var(--t2);
}
.dfield-pick:hover { background: var(--panel); }

.dfield-ico {
  width: var(--sp-md);
  height: var(--sp-md);
  pointer-events: none;
}

/* The native box itself. The selector is three classes deep on purpose: the
   screens that dressed their old date boxes by hand — `.visit-filter
   input[type="date"]`, `.report-filters input[type="date"]` — are (0,2,1), and
   this has to out-weigh them or the transparent overlay picks up their width
   and margin. */
.dfield .dfield-pick .dfield-native {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: transparent;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

/* Focus is drawn on the BOX, because the control itself is invisible. Without
   this a keyboard user tabbing onto the picker sees nothing move. */
.dfield .dfield-pick .dfield-native:focus-visible { outline: none; }
.dfield-pick:focus-within {
  border-color: var(--accent-focus);
  box-shadow: 0 0 0 var(--sp-xxs) var(--accent-wash);
}

/* THE REFUSAL. It sits on its own line under the pair, so a wrong date never
   shoves the field sideways, and it is the danger colour the rest of SGE uses
   for the same thing. `role="alert"` on the span is what reads it out; this
   only makes it visible. */
.dfield-msg {
  flex: 1 0 100%;
  margin: 0;
  color: var(--danger);
  font-size: var(--fs-caption);
  line-height: 1.43;
  letter-spacing: var(--ls-caption);
}

.dfield-wrong > .dfield-text {
  border-color: var(--danger);
}

/* A date box sitting in a table cell or a tight toolbar takes the room it has
   rather than the room it would like. */
.dfield-tight > .dfield-text { width: auto; min-width: 0; flex: 1 1 auto; }

@media (max-width: 767px) {
  /* On a phone the pair stays on one line and the text box takes what is left,
     so the picker never wraps under the field it belongs to. */
  .dfield { flex-wrap: wrap; width: 100%; }
  .dfield > .dfield-text { flex: 1 1 auto; width: auto; min-width: 0; }
  /* With a time box there are three things on the line, so the date keeps the
     room it needs and the time takes what a time needs — neither is squeezed
     into an ellipsis, and the picker stays beside them. */
  .dfield-stamp > .dfield-text { flex: 1 1 var(--fw-short); }
  .dfield-stamp > .dfield-clock { flex: 0 1 auto; width: var(--fw-short); }
}
