/* Custom form controls. Loaded by both the website and the back office, so it only uses the design
   tokens they share. The native element behind each control is kept for its value and validation,
   parked out of sight but still focusable so the browser can still report an invalid field. */

.ui-native,
.ui-select > select {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.ui-field-wrap { position: relative; width: 100%; min-width: 0; }

/* The face of a control. Each app already styles `input`, so matching that is all this needs. */
.ui-field {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ui-field:disabled { cursor: default; opacity: 0.6; }
.ui-field .ui-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-field .ui-ph { color: var(--muted); }
.ui-field .ui-i { width: 17px; height: 17px; flex: none; opacity: 0.6; }
.ui-select-btn .ui-i { transition: transform 0.18s var(--ease); }
.ui-select-btn[aria-expanded='true'] .ui-i { transform: rotate(180deg); }
.ui-date-btn .ui-i { order: -1; opacity: 0.55; }

/* --------------------------------------------------------------------- popover */

.ui-pop {
  position: fixed;
  z-index: 300;
  max-width: min(94vw, 340px);
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--card);
  box-shadow: var(--shadow-lg);
  animation: uiPop 0.14s var(--ease);
}
@keyframes uiPop { from { opacity: 0; transform: translateY(-4px); } }

.ui-list { max-height: min(46vh, 320px); overflow: auto; overscroll-behavior: contain; }
.ui-list-box { display: grid; gap: 6px; }
.ui-search { height: 34px; }

.ui-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 0.94rem;
  cursor: pointer;
}
.ui-opt > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-opt .ui-i { width: 16px; height: 16px; flex: none; color: var(--gold-deep); }
.ui-opt:hover, .ui-opt:focus-visible { background: color-mix(in srgb, var(--gold) 16%, transparent); outline: none; }
.ui-opt.on { font-weight: 600; }
.ui-opt.off { opacity: 0.45; cursor: default; }
.ui-opt.off:hover { background: none; }

/* -------------------------------------------------------------------- calendar */

.ui-cal { width: 274px; padding: 4px; }
.ui-cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 2px 2px 8px; }
.ui-cal-head b { font-size: 0.92rem; font-family: var(--font-d); }
.ui-icon-btn {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border: 1px solid var(--line); border-radius: 8px; background: transparent; color: inherit; cursor: pointer;
}
.ui-icon-btn:hover { background: color-mix(in srgb, var(--gold) 14%, transparent); }
.ui-icon-btn .ui-i { width: 15px; height: 15px; }

.ui-cal-dow, .ui-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.ui-cal-dow span { padding: 4px 0; text-align: center; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.ui-day {
  height: 34px; border: 0; border-radius: 9px; background: transparent; color: inherit;
  font: 500 0.88rem/1 var(--font-b, inherit); cursor: pointer; font-variant-numeric: tabular-nums;
}
.ui-day:hover:not([disabled]) { background: color-mix(in srgb, var(--gold) 20%, transparent); }
.ui-day.today { box-shadow: inset 0 0 0 1px var(--line); font-weight: 700; }
.ui-day.on { background: var(--gold); color: var(--on-gold, var(--ink)); font-weight: 700; box-shadow: none; }
.ui-day[disabled] { opacity: 0.28; cursor: default; }

.ui-cal-time { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.ui-cal-time .ui-i { width: 16px; height: 16px; flex: none; opacity: 0.55; }
.ui-cal-time .ui-time { height: 34px; }
.ui-cal-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.ui-link {
  padding: 5px 8px; border: 0; border-radius: 7px; background: transparent;
  color: var(--gold-deep); font: 600 0.82rem var(--font-b, inherit); cursor: pointer;
}
.ui-link:hover { background: color-mix(in srgb, var(--gold) 16%, transparent); }

/* ---------------------------------------------------------------------- number */

.ui-num { position: relative; display: flex; align-items: center; width: 100%; }
.ui-num > input { text-align: center; padding-inline: 34px; }
.ui-num > input::-webkit-outer-spin-button,
.ui-num > input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ui-num > input[type='number'] { -moz-appearance: textfield; appearance: textfield; }
.ui-step {
  position: absolute; display: grid; place-items: center; width: 26px; height: 26px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: inherit; cursor: pointer;
}
.ui-step:first-child { left: 5px; }
.ui-step:last-child { right: 5px; }
.ui-step:hover { background: color-mix(in srgb, var(--gold) 18%, transparent); }
.ui-step .ui-i { width: 14px; height: 14px; }

/* ---------------------------------------------------------------------- colour */

.ui-chip { width: 20px; height: 20px; flex: none; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.35); }
.ui-colours { display: grid; gap: 10px; padding: 6px; width: 212px; }
.ui-sw { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.ui-sw-b { height: 28px; border: 0; border-radius: 8px; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.3); }
.ui-sw-b.on, .ui-sw-b:hover { box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.3), 0 0 0 2px var(--gold); }
.ui-hex { display: flex; align-items: center; gap: 8px; font-size: 0.76rem; font-weight: 600; color: var(--muted); }
.ui-hex input { height: 32px; font-family: ui-monospace, monospace; }

/* ------------------------------------------------------------ checkbox & radio */

input[type='checkbox'], input[type='radio'] {
  -webkit-appearance: none;
  appearance: none;
  width: 19px;
  height: 19px;
  flex: none;
  margin: 0;
  padding: 0;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  background: var(--input-bg);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  transition: background 0.15s, border-color 0.15s;
}
input[type='radio'] { border-radius: 50%; }
input[type='checkbox']::before {
  content: '';
  width: 11px;
  height: 11px;
  transform: scale(0);
  transition: transform 0.15s var(--ease);
  background: var(--on-gold, var(--ink));
  clip-path: polygon(14% 49%, 6% 60%, 39% 89%, 94% 21%, 84% 12%, 38% 69%);
}
input[type='radio']::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.15s var(--ease);
  background: var(--on-gold, var(--ink));
}
input[type='checkbox']:checked, input[type='radio']:checked { background: var(--gold); border-color: var(--gold); }
input[type='checkbox']:checked::before, input[type='radio']:checked::before { transform: scale(1); }
input[type='checkbox']:focus-visible, input[type='radio']:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 2px; }
input[type='checkbox']:disabled, input[type='radio']:disabled { opacity: 0.5; cursor: default; }

/* ----------------------------------------------------------------------- range */

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--gold) var(--pct, 50%), var(--line) var(--pct, 50%));
}
input[type='range']::-moz-range-track { height: 6px; border-radius: 99px; background: var(--line); }
input[type='range']::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--gold); }
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border: 3px solid var(--gold);
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform 0.12s var(--ease);
}
input[type='range']::-moz-range-thumb {
  width: 14px; height: 14px; border: 3px solid var(--gold); border-radius: 50%; background: var(--card);
}
input[type='range']:active::-webkit-slider-thumb { transform: scale(1.12); }

/* ------------------------------------------------------------------ file input */

input[type='file']::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: inherit;
  font: 600 0.84rem var(--font-b, inherit);
  cursor: pointer;
}
input[type='file']::file-selector-button:hover { background: color-mix(in srgb, var(--gold) 16%, transparent); }

/* -------------------------------------------------------- dialogs, not the browser's */

.ui-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 12, 16, 0.55);
  backdrop-filter: blur(3px);
  animation: uiFade 0.16s var(--ease);
}
@keyframes uiFade { from { opacity: 0; } }
.ui-modal-box {
  width: min(400px, 100%);
  display: grid;
  gap: 10px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--card);
  box-shadow: var(--shadow-lg);
  animation: uiRise 0.18s var(--ease);
}
@keyframes uiRise { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
.ui-modal-box h2 { margin: 0; font: 700 1.14rem/1.25 var(--font-d); letter-spacing: -0.02em; }
.ui-modal-box p { margin: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.55; }
.ui-modal-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.ui-btn {
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: 600 0.9rem var(--font-b, inherit);
  cursor: pointer;
}
.ui-btn:hover { background: color-mix(in srgb, var(--gold) 14%, transparent); }
.ui-btn-go { border-color: transparent; background: var(--gold); color: var(--on-gold, var(--ink)); }
.ui-btn-go:hover { background: var(--gold-deep); color: #fff; }
.ui-btn-danger { background: #b3261e; color: #fff; }
.ui-btn-danger:hover { background: #8f1d17; color: #fff; }

@media (prefers-reduced-motion: reduce) {
  .ui-pop, .ui-modal, .ui-modal-box { animation: none; }
  .ui-field .ui-i, input[type='checkbox']::before, input[type='radio']::before { transition: none; }
}

/* ---------------------------------------------------------------- on a phone
   The stepper buttons are 26px tall, stacked two to a field — a coin toss for a thumb. On a
   touch device they also duplicate the numeric keypad that opens the moment the field is
   focused, so they are removed rather than enlarged, and the field gets its width back. */
@media (max-width: 620px) and (pointer: coarse) {
  .ui-num .ui-step { display: none; }
  .ui-num > input { text-align: left; padding-inline: 13px; }
}
