/* Date / month / time pickers (assets/js/modules/custom-pickers.js), drawn with the
   design-system tokens so they follow light and dark themes.

   The panel is a POPOVER anchored under the field that opened it (the script sets
   top/left); .custom-picker-overlay is a transparent full-screen catcher so a click
   anywhere outside closes it.

   EVERY PANEL RULE IS SCOPED `body .custom-picker-overlay ...` ON PURPOSE: dashboard.css
   carries an older copy of these rules AND an unrelated `.calendar-day` widget, and
   style.css has `body.dark-mode .calendar-day` (0,2,1). The `body` prefix lifts these to
   (0,2,1)+ so they tie-or-beat both and win on load order, while the unrelated calendar
   widget is left alone. */

.input-wrapper { position: relative; }

.date-picker-icon, .time-picker-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--sz-text-muted);
  cursor: pointer;
  font-size: 0.95rem;
}
html[dir="rtl"] .date-picker-icon, html[dir="rtl"] .time-picker-icon { right: auto; left: 12px; }

/* Fields converted from <input type="date"> by hand — the wrapper lays out like the plain
   input it replaced, and the text clears the calendar icon. */
span.input-wrapper { display: block; }
span.input-wrapper > .custom-date-input,
span.input-wrapper > .custom-time-input,
span.input-wrapper > .custom-month-input { width: 100%; cursor: pointer; padding-inline-end: 2.1rem; }
.custom-date-input, .custom-month-input, .custom-time-input { cursor: pointer; caret-color: transparent; }

/* Fields the script upgrades from a native date / month / date-time input carry their
   calendar glyph as a background, so the page's markup and layout are untouched. */
input.sz-date-auto {
  padding-inline-end: 34px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23646d80' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2.5'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 11px center !important;
  background-size: 15px !important;
}
html[dir="rtl"] input.sz-date-auto { background-position: left 11px center !important; }
html.dark-mode input.sz-date-auto {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239aa3b5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='5' width='18' height='16' rx='2.5'/%3E%3Cpath d='M3 10h18M8 3v4M16 3v4'/%3E%3C/svg%3E") !important;
}
.custom-date-input[aria-expanded="true"], .custom-month-input[aria-expanded="true"], .custom-time-input[aria-expanded="true"] {
  border-color: var(--sz-accent) !important;
  box-shadow: 0 0 0 3px var(--sz-accent-ring) !important;
}

/* ---------- transparent click-catcher ---------- */
body .custom-picker-overlay {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  background: transparent;
  display: block;
  z-index: 10070;
}
body .custom-picker-overlay.hidden { display: none; }

/* ---------- the panel ---------- */
body .custom-picker-overlay .custom-picker-content {
  position: fixed;
  top: 0; left: 0;                    /* the script overwrites both on open */
  box-sizing: border-box;
  width: 304px;
  max-width: calc(100vw - 16px);
  padding: 14px 14px 10px;
  background: var(--sz-surface);
  color: var(--sz-text);
  border: 1px solid var(--sz-border);
  border-radius: var(--sz-r-pop, 12px);
  box-shadow: var(--sz-shadow-pop);
  font-family: var(--sz-font);
  font-size: 14px;
  line-height: 1.3;
  transform-origin: top center;
}
html.dark-mode body .custom-picker-overlay .custom-picker-content { border-color: var(--sz-border-strong); }
body .custom-picker-overlay .custom-picker-content.is-up { transform-origin: bottom center; }
@media (prefers-reduced-motion: no-preference) {
  body .custom-picker-overlay .custom-picker-content { opacity: 0; transform: translateY(-4px) scale(.985); transition: opacity 140ms var(--sz-ease), transform 160ms var(--sz-ease); }
  body .custom-picker-overlay .custom-picker-content.is-up { transform: translateY(4px) scale(.985); }
  body .custom-picker-overlay .custom-picker-content.is-in { opacity: 1; transform: none; }
}
/* fallback when there is no field to anchor to */
body .custom-picker-overlay .custom-picker-content.is-centered,
body .custom-picker-overlay .custom-picker-content.is-centered.is-in {
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}

/* ---------- header: < [ month ] [ year ] > ---------- */
body .custom-picker-overlay .picker-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  font-weight: 650;
  color: var(--sz-text-strong);
}
body .custom-picker-overlay .picker-header > span { flex: 1; text-align: center; }
body .custom-picker-overlay .picker-selects { display: flex; gap: 6px; flex: 1 1 auto; min-width: 0; }

/* the month / year selects become the shared Select (dropdown_enhance.js); this is the
   look of the native fallback before the script runs */
body .custom-picker-overlay .picker-select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  box-sizing: border-box;
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
  height: 34px;
  padding: 0 26px 0 10px;
  background: var(--sz-surface-2) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23909aa8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5 11 1.5'/%3E%3C/svg%3E") no-repeat right 9px center / 10px 7px;
  color: inherit;
  border: 1px solid var(--sz-border);
  border-radius: var(--sz-r-ctl);
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
}
body .custom-picker-overlay .picker-select-year { flex: 0 0 84px; width: 84px; }
body .custom-picker-overlay .picker-selects .sz-dd { flex: 1 1 auto; min-width: 0; }
body .custom-picker-overlay .picker-selects .sz-dd:has(> .picker-select-year) { flex: 0 0 84px; }
body .custom-picker-overlay .picker-selects .sz-dd .dropdown-button,
body .custom-picker-overlay .picker-time .sz-dd .dropdown-button {
  min-height: 34px;
  padding: 0 9px;
  font-size: 13.5px;
  font-weight: 650;
  color: var(--sz-text-strong);
  background: var(--sz-surface);
  box-shadow: none;
}
html.dark-mode body .custom-picker-overlay .picker-selects .sz-dd .dropdown-button,
html.dark-mode body .custom-picker-overlay .picker-time .sz-dd .dropdown-button { background: var(--sz-surface-2); }
body .custom-picker-overlay .sz-dd .dropdown-button .caret { font-size: 10px; margin-inline-start: 6px; }

body .custom-picker-overlay .picker-nav-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none;
  border: 1px solid transparent;
  color: var(--sz-text-muted);
  cursor: pointer;
  border-radius: var(--sz-r-ctl);
  padding: 0;
  font-size: 12px;
}
body .custom-picker-overlay .picker-nav-btn:hover:not(:disabled) { background: var(--sz-surface-3); color: var(--sz-text-strong); }
body .custom-picker-overlay .picker-nav-btn:disabled { opacity: .35; cursor: not-allowed; }
body .custom-picker-overlay :is(.picker-nav-btn, .calendar-day, .month-cell, .time-option, .picker-link):focus-visible {
  outline: 2px solid var(--sz-accent);
  outline-offset: 1px;
}

/* ---------- calendar grid ---------- */
:root body .custom-picker-overlay .calendar-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px;
  margin-bottom: 2px;
  text-align: center;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--sz-text-muted);
  font-weight: 700;
  line-height: 26px;
}
:root body .custom-picker-overlay .calendar-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }

:root body .custom-picker-overlay .calendar-day {
  width: 100%; height: auto; min-height: 0;
  aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center;
  margin: 0;
  border: 0;
  padding: 0;
  background: none;
  color: var(--sz-text);
  cursor: pointer;
  border-radius: var(--sz-r-ctl);
  font: inherit;
  font-size: 13.5px;
  font-weight: 560;
  font-variant-numeric: proportional-nums;
  user-select: none;
  box-shadow: none;
  transform: none;
}
@media (hover: hover) and (pointer: fine) {
  :root body .custom-picker-overlay .calendar-day:hover:not(:disabled):not(.selected) { background: var(--sz-surface-3); color: var(--sz-text-strong); }
}
:root body .custom-picker-overlay .calendar-day.other-month { color: var(--sz-text-faint); background: none; }
/* today is a ring, never a fill: a selection must stay unmistakable */
:root body .custom-picker-overlay .calendar-day.today {
  color: var(--sz-accent-text);
  font-weight: 760;
  box-shadow: inset 0 0 0 1.5px var(--sz-accent);
  background: none;
}
:root body .custom-picker-overlay .calendar-day.selected,
:root body .custom-picker-overlay .calendar-day.selected:hover {
  background: var(--sz-accent);
  color: var(--sz-on-accent);
  font-weight: 760;
  box-shadow: none;
}
:root body .custom-picker-overlay .calendar-day:disabled,
:root body .custom-picker-overlay .calendar-day.is-disabled {
  color: var(--sz-text-faint);
  opacity: .45;
  cursor: not-allowed;
  background: none;
  text-decoration: line-through;
}

/* ---------- date + time ---------- */
body .custom-picker-overlay .picker-time {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--sz-border);
}
body .custom-picker-overlay .picker-time[hidden] { display: none; }
body .custom-picker-overlay .picker-time-label { flex: 1; color: var(--sz-text-muted); font-size: 12.5px; font-weight: 650; }
body .custom-picker-overlay .picker-time .sz-dd { width: 74px; }
body .custom-picker-overlay .picker-time-sep { font-weight: 760; color: var(--sz-text-muted); }

/* ---------- actions ---------- */
body .custom-picker-overlay .picker-actions {
  display: flex; justify-content: space-between; align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--sz-border);
}
body .custom-picker-overlay .picker-actions-end { display: inline-flex; align-items: center; gap: 6px; margin-inline-start: auto; }
body .custom-picker-overlay .picker-actions .btn {
  margin: 0;
  min-height: 32px;
  padding: 0 12px;
  font-size: 13px;
}
body .custom-picker-overlay .picker-link {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--sz-r-ctl);
  background: none;
  color: var(--sz-accent-text);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
body .custom-picker-overlay .picker-link.picker-clear-btn { color: var(--sz-text-muted); }
body .custom-picker-overlay .picker-link:hover:not(:disabled) { background: var(--sz-surface-3); }
body .custom-picker-overlay .picker-link:disabled { opacity: .4; cursor: not-allowed; }
body .custom-picker-overlay [hidden] { display: none !important; }

/* ---------- time picker (hh:mm AM) ---------- */
body .custom-picker-overlay .custom-picker-content.time-picker { width: 272px; }
body .custom-picker-overlay .time-selector { display: flex; align-items: flex-end; justify-content: center; gap: 8px; margin: 4px 0 6px; }
body .custom-picker-overlay .time-column { text-align: center; }
body .custom-picker-overlay .time-column label { display: block; margin-bottom: 6px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--sz-text-muted); }
body .custom-picker-overlay .time-scroll {
  display: flex; flex-direction: column; gap: 2px;
  height: 168px; overflow-y: auto; width: 64px; padding: 3px;
  border: 1px solid var(--sz-border);
  border-radius: var(--sz-r-ctl);
  scrollbar-width: thin;
  overscroll-behavior: contain;
}
body .custom-picker-overlay .time-option {
  flex: 0 0 auto; min-height: 32px; padding: 0; border: 0; border-radius: 6px;
  background: none; color: var(--sz-text); font: inherit; font-size: 13.5px; font-variant-numeric: proportional-nums; cursor: pointer;
}
body .custom-picker-overlay .time-option:hover { background: var(--sz-surface-3); }
body .custom-picker-overlay .time-option.selected { background: var(--sz-accent); color: var(--sz-on-accent); font-weight: 700; }
body .custom-picker-overlay .time-separator { padding-bottom: 72px; font-size: 1.2rem; font-weight: 760; color: var(--sz-text-muted); }

/* ---------- month picker ---------- */
body .custom-picker-overlay .custom-picker-content.month-picker { width: 272px; }
body .custom-picker-overlay .month-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
body .custom-picker-overlay .month-cell {
  min-height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--sz-r-ctl);
  background: none;
  color: var(--sz-text);
  font: inherit;
  font-size: 13.5px;
  font-weight: 620;
  cursor: pointer;
  text-align: center;
}
body .custom-picker-overlay .month-cell:hover { background: var(--sz-surface-3); }
body .custom-picker-overlay .month-cell.today { color: var(--sz-accent-text); box-shadow: inset 0 0 0 1.5px var(--sz-accent); background: none; }
body .custom-picker-overlay .month-cell.selected,
body .custom-picker-overlay .month-cell.selected:hover { background: var(--sz-accent); color: var(--sz-on-accent); box-shadow: none; }

/* touch: style.css asks for 44px icon buttons below 768px; the picker honours it */
@media (max-width: 767px) {
  body .custom-picker-overlay .picker-header .picker-nav-btn { width: 44px; height: 44px; }
}
/* phones: thumb-sized cells; the panel never runs off-screen */
@media (max-width: 480px) {
  body .custom-picker-overlay .custom-picker-content { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); overflow-y: auto; }
  :root body .custom-picker-overlay .calendar-day { font-size: 15px; }
  body .custom-picker-overlay .month-cell { min-height: 48px; font-size: 15px; }
  body .custom-picker-overlay .picker-link, body .custom-picker-overlay .picker-actions .btn { min-height: 44px; }
}
