/* ═══════════════════════════════════════════════════════════════════════════
   ORDERLY SELECT

   A <select> is the one control a browser will not let you style. `appearance:
   none` reaches the closed box and nothing else: the list that drops out of it
   is drawn by the operating system, in the OS's own grey, with the OS's own
   tick and row height. On macOS that is a light-grey panel that lands on top
   of a dark till screen, which is what this replaces.

   So the control is rebuilt rather than restyled. orderly-select.js puts a
   real <button> in front of every select and draws the list itself; the
   <select> stays in the DOM as the value, so forms submit, `sel.value` reads
   and writes, and `onchange` fires exactly as before.

   Themes come free: the trigger inherits the select's own classes, and both
   the caret and the tick are drawn in `currentColor`, so a dropdown on a
   Linen QR menu and one on the dark waiter screen are the same component
   wearing the surrounding ink. The menu itself resolves QR tokens first and
   falls back to the app tokens, because on a QR page `--qr-*` is set on <html>
   and the menu is a child of <body>.
   ═══════════════════════════════════════════════════════════════════════════ */

/* The real control. Kept in the DOM — it is still the value — but taken out
   of sight and out of the tab order. Geometry is forced because the element
   carries field padding classes that would otherwise give it a size. */
select[data-osel-native] {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: -1px !important;
  border: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
  overflow: hidden !important;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── Trigger ───────────────────────────────────────────────────────────────
   Carries the select's own class list, so it keeps whatever the screen dressed
   its fields in. Only layout is added here — the label left, the caret right,
   the label truncating rather than pushing the caret out of the box. */
/* `:not(.hidden):not([hidden])` matters: the trigger copies the select's class
   list, so a field the screen hides with Tailwind's `hidden` arrives here
   carrying it. Both rules are one class deep, and which one wins would come
   down to whether the Tailwind CDN injected its <style> before or after this
   file — a coin toss that would leave hidden fields on screen. Declining to
   match at all when `hidden` is present settles it. */
.osel-trigger:not(.hidden):not([hidden]) {
  display: flex;
}
.osel-trigger {
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  text-align: left;
  cursor: pointer;
  font: inherit;
  line-height: 1.25;
}
.osel-trigger:disabled { cursor: not-allowed; opacity: .68; }

.osel-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* An empty-valued option is a prompt ("Select a time…"), not an answer, and
   should read like placeholder text rather than a chosen value.

   Coloured rather than faded. `opacity: .55` on the trigger's own ink put
   "All Menus" at 2.6:1 on a light page, and opacity cannot be aimed: it
   dilutes whatever colour it finds toward whatever is behind it. `--text-4` is
   the floor base.html sets for every other placeholder in the app, so the
   prompt now recedes by exactly as much as the ones beside it. */
.osel-trigger.osel-empty .osel-label { color: var(--text-4); }

.osel-caret {
  flex: 0 0 auto;
  width: 12px;
  height: 8px;
  opacity: .6;
  transition: transform .15s ease;
}
.osel-trigger[aria-expanded="true"] .osel-caret { transform: rotate(180deg); }

/* ── Menu ──────────────────────────────────────────────────────────────────
   Positioned by script and appended to <body>, not to the field's own parent.
   A dropdown that renders next to its select gets clipped by the first
   `overflow-hidden` card above it and trapped by the first `backdrop-filter`
   modal — both of which this app has. Living on <body> at a fixed position
   sidesteps every ancestor.

   A menu is opaque, always. It is the one surface in the app that covers
   working content — a bill, a table grid, a booking list — and anything
   showing through it is noise sitting behind the thing being read. The colour
   is stated literally here rather than pulled from `--surface-3` because that
   token also feeds panels that are allowed to be tinted; a dropdown may not
   inherit a translucency decision made somewhere else.

   The edge does the rest of the work. A wide, soft, spread-in shadow with a
   faint border reads as haze on a near-black page, which is what made this
   look see-through even though it never was. A hairline, a dark contact ring
   and a tighter shadow give it a definite edge instead of a glow. */
.osel-menu {
  position: fixed;
  z-index: 100000;
  box-sizing: border-box;
  padding: .25rem;
  border-radius: .75rem;
  /* A clear step above both the page (#06080C) and a card (#0C111A), so the
     panel reads as sitting on top of the screen rather than dissolving into
     it. `--surface-3` is only a shade off this; the separation people read as
     "solid" comes from the gap to what is behind, not from the value itself. */
  background-color: #1E2736;
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: 0 0 0 1px rgba(0,0,0,.55), 0 14px 34px -10px rgba(0,0,0,.85);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  animation: osel-in .1s ease-out;
}
[data-theme="light"] .osel-menu {
  background-color: #FFFFFF;
  border-color: rgba(15,23,42,.12);
  box-shadow: 0 0 0 1px rgba(15,23,42,.05), 0 14px 34px -10px rgba(15,23,42,.28);
}
/* QR pages set --qr-theme on <html>, so the body-level menu still resolves
   them. Every QR surface token is a solid hex, which is the requirement. */
[data-qr-theme] .osel-menu {
  background-color: var(--qr-surface);
  border-color: var(--qr-border);
}

/* Fade only. The old slide made the panel look as though it were moving
   through the page rather than sitting on top of it. */
@keyframes osel-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .osel-menu { animation: none; }
  .osel-caret { transition: none; }
}

/* No scrollbar at all. Was a thin themed bar; even that reads as a grey rail
   down a dark panel, and the menu is scrolled by touch or wheel in every
   place it is used. The list still scrolls — only the rail is gone, and the
   clipped last row is the affordance that says so. */
.osel-menu { scrollbar-width: none; -ms-overflow-style: none; }
.osel-menu::-webkit-scrollbar { display: none; width: 0; height: 0; }

/* 44px rows, for the same reason every other control in the app is 44px: this
   is tapped with a thumb, mid-service, one-handed.

   The tick keeps its 16px gutter whether or not it is showing, so every label
   in the list starts on the same vertical line. A tick that takes its space
   only when visible shunts one row's text sideways, and a column of text with
   one line out of true is most of why a list looks untidy. */
.osel-opt {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  min-height: 44px;
  padding: .5rem .625rem;
  border-radius: .5rem;
  font-size: .875rem;
  line-height: 1.35;
  color: var(--qr-text, var(--text-1, #F5F8FC));
  cursor: pointer;
  user-select: none;
}
.osel-opt + .osel-opt { margin-top: 1px; }
.osel-opt-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Keyboard cursor and pointer hover are the same state deliberately: two
   different highlights in one list reads as two different selections. */
.osel-opt.osel-active { background: var(--qr-surface-hover, var(--surface-4, #2C3646)); }

/* Selected is a filled chip rather than coloured text alone — at a glance
   down a list of twenty booking times, weight and colour on their own are not
   enough to find the current one. */
.osel-opt[aria-selected="true"] {
  background: var(--accent-soft, rgba(24,111,242,.16));
  color: var(--qr-accent, var(--accent-ink, #6BA9FF));
  font-weight: 700;
}
.osel-opt[aria-selected="true"].osel-active {
  background: var(--qr-surface-hover, var(--surface-4, #2C3646));
}
.osel-opt[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }

/* Colour is never the only signal — the tick says "selected" on its own. */
.osel-tick {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  opacity: 0;
}
.osel-opt[aria-selected="true"] .osel-tick { opacity: 1; }

.osel-group {
  padding: .625rem .625rem .25rem;
  font-size: .625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--qr-text-faint, var(--text-3, #8A97A8));
}
/* A rule above every group but the first — the divider belongs between
   groups, not above the top of the list. */
.osel-opt + .osel-group {
  margin-top: .25rem;
  border-top: 1px solid var(--qr-border, var(--border-1, rgba(255,255,255,.09)));
  padding-top: .625rem;
}
.osel-empty-msg {
  padding: .75rem .625rem;
  font-size: .8125rem;
  color: var(--qr-text-faint, var(--text-3, #8A97A8));
}
