/* ===========================================================================
   Global themed date picker (calendar-theme.js enhances every
   input[type="date"] the way dropdown-theme.js enhances selects).
   Structure follows the approved date-picker reference design; colours map to
   the app design-system tokens so the picker matches the rest of the UI.
   Opt out per input with data-native-date.
   =========================================================================== */

:root {
  --cal-primary: var(--brand, #aa3232);
  --cal-primary-hover: var(--brand-strong, #842525);
  --cal-primary-tint: color-mix(in srgb, var(--brand, #aa3232) 32%, #ffffff);
  --cal-tonal: color-mix(in srgb, var(--brand, #aa3232) 10%, #ffffff);
  --cal-tonal-2: color-mix(in srgb, var(--brand, #aa3232) 5%, #ffffff);
  --cal-border: var(--control-border-color, #cbd5e1);
  --cal-hairline: #efeff4;
  --cal-ink: var(--ink, #172333);
  --cal-muted: var(--muted, #667485);
  --cal-out-month: #c9c7d4;
}

.global-datepicker {
  position: relative;
  display: inline-grid;
  width: 100%;
  min-width: 0;
  vertical-align: middle;
}

/* Keep the native input focusable (form validation) but invisible */
.global-datepicker-source {
  position: absolute !important;
  inset: 0 auto auto 0 !important;
  width: 1px !important;
  height: 1px !important;
  min-width: 1px !important;
  min-height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  border: 0 !important;
}

.global-datepicker-field {
  display: flex;
  width: 100%;
  min-height: var(--control-h, 42px);
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--cal-border);
  border-radius: var(--control-radius, 8px);
  background: #ffffff;
  color: var(--cal-ink);
  cursor: default;
  font: inherit;
  font-size: 14px;
  line-height: 1.2;
  padding: 9px 12px;
  text-align: left;
  outline: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.global-datepicker-field:hover,
.global-datepicker.open .global-datepicker-field,
.global-datepicker-field:focus-visible {
  border-color: var(--cal-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cal-primary) 16%, transparent);
}
.global-datepicker-value {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.global-datepicker-value.placeholder { color: var(--cal-muted); }
.global-datepicker-icon { color: var(--cal-muted); display: grid; place-items: center; flex: 0 0 auto; }
.global-datepicker.is-disabled .global-datepicker-field {
  background: #f8fafc;
  color: #94a3b8;
  cursor: not-allowed;
}

/* ---- Popover ---- */
.global-datepicker-popover {
  /* Positioned (fixed) by calendar-theme.js from the field's rect, exactly the
     way .global-dropdown-panel is, so a modal or any overflow:auto scroll
     container can never clip it. It used to be position:absolute anchored to
     the field with top/left, which the Sales Order dialog's own scrolling body
     cut in half - the month grid ended after the first week (owner, 22 Sep
     2026, "in sales order the full calender is not visible"). No ancestor
     stacking or overflow trick can fix an absolute box inside a scroller; only
     leaving the scroller's coordinate space does.

     JS sets top and left from the field's rect and clamps them into the
     viewport, so nothing here may set either. */
  position: fixed;
  z-index: 30050;
  width: 292px;
  max-width: calc(100vw - 24px);
  background: #ffffff;
  border: 1px solid #e7e7ec;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(20, 16, 60, 0.14);
  padding: 14px;
}

.global-datepicker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px 8px;
}
.global-datepicker-month { font-size: 13.5px; font-weight: 700; color: var(--cal-ink); }
.global-datepicker-nav {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--cal-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
}
.global-datepicker-nav:hover { background: #efeef4; }

.global-datepicker-dow,
.global-datepicker-week {
  display: grid;
  grid-template-columns: repeat(7, 36px);
  gap: 2px;
  justify-content: center;
}
.global-datepicker-dow div {
  font-size: 10.5px;
  font-weight: 700;
  color: #9c98ab;
  text-align: center;
  padding: 6px 0;
  letter-spacing: 0.04em;
}
.global-datepicker-day {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--cal-ink);
  font: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.global-datepicker-day:hover { background: var(--cal-tonal-2); }
.global-datepicker-day.out { color: var(--cal-out-month); }
.global-datepicker-day.today {
  border-color: var(--cal-primary-tint);
  color: var(--cal-primary);
  font-weight: 700;
}
.global-datepicker-day.selected {
  background: var(--cal-primary);
  color: #ffffff;
  font-weight: 700;
  border-color: transparent;
}
.global-datepicker-day.selected:hover { background: var(--cal-primary-hover); }
.global-datepicker-day:disabled {
  color: #d4d2de;
  cursor: not-allowed;
  background: transparent;
}

/* ---- Time picker ----------------------------------------------------------
   Hour / minute / AM-PM, for the same reason the date picker exists: a native
   input[type=time] takes its 12- or 24-hour shape from the BROWSER's locale
   and the page cannot choose (owner, 25 Sep 2026 - and lang="en-US" was
   measured and does not move it either). The wrapper, button, value, icon and
   popover all reuse the datepicker classes above, so only these columns are
   new and the two controls cannot drift apart.
   Opt out per input with data-native-time. */
/* THE BLUE IS DELIBERATE and is the one hard-coded colour in this file.

   Shown two mock-ups - his screenshot's blue, or the same layout in the app's
   own red - the owner picked the screenshot exactly (25 Sep 2026). So this is
   his choice, not a slip past the "never hard-code a colour" rule, and it is
   named here once rather than repeated. */
:root {
  --time-pick-accent: #1a73e8;
  --time-pick-accent-hover: #1765cc;
}

.global-timepicker-popover {
  width: 216px;
  /* Tighter than the calendar's padding: three columns of numbers, no head
     and no footer, so the panel is all list. */
  padding: 8px;
}

.global-timepicker-cols {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}

/* FLEX, not grid, because the picked value is floated to the top with the
   `order` property - see markTimeSelection. Grid would need explicit rows. */
.global-timepicker-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* One scroller per column. Every minute is offered rather than 5-minute
     steps, so a value already in the field can always be shown. */
  max-height: 196px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.global-timepicker-mer { overflow: visible; }

.global-timepicker-opt {
  flex: 0 0 auto;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--cal-ink);
  font: inherit;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.global-timepicker-opt:hover { background: var(--cal-tonal-2); }
.global-timepicker-opt.selected {
  background: var(--time-pick-accent);
  color: #ffffff;
  font-weight: 700;
  border-color: transparent;
}
.global-timepicker-opt.selected:hover { background: var(--time-pick-accent-hover); }

.global-datepicker-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--cal-hairline);
}
.global-datepicker-foot button {
  background: none;
  border: 0;
  padding: 6px 8px;
  border-radius: 8px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.global-datepicker-clear { color: var(--cal-muted); }
.global-datepicker-clear:hover { background: #efeef4; }
.global-datepicker-today { color: var(--cal-primary); }
.global-datepicker-today:hover { background: var(--cal-tonal-2); }

/* Let the popover escape clipping cards and paint above sibling tables —
   same treatment the dropdown menus get. */
.panel:has(.global-datepicker.open),
.card:has(.global-datepicker.open),
article:has(.global-datepicker.open),
.inventory-table-controls:has(.global-datepicker.open),
.dashboard-filters:has(.global-datepicker.open) {
  position: relative;
  z-index: 30;
  overflow: visible;
}
