/* Form controls shared by the shop and admin.
   Native elements stay in the DOM so every form works without JS; their look is drawn here.
   controls.js upgrades <select> into a listbox, <input type=date> into chips/calendar,
   and [data-filedrop] into a file list with previews. */

/* ---------- Text field, textarea, select shell ---------- */
.input, .textarea, select.input, .select {
  -webkit-appearance: none; appearance: none;
  width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid var(--line-strong); border-radius: var(--rounded-sm);
  background-color: var(--white); color: var(--charcoal);
  font: inherit; font-size: 16px; line-height: 1.4; text-align: left;
  caret-color: var(--forest-green);
  transition: border-color 150ms ease-out, box-shadow 150ms ease-out, background-color 150ms ease-out;
}
.textarea { min-height: 112px; resize: vertical; display: block; }
.input::placeholder, .textarea::placeholder { color: var(--taupe); opacity: 1; }
.input:hover, .textarea:hover, .select:hover { border-color: var(--charcoal); }
.input:focus, .textarea:focus, .select:focus-visible, .input:focus-visible {
  outline: none; border-color: var(--forest-green); box-shadow: inset 0 0 0 1px var(--forest-green);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--berry-red); }
.input[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus { box-shadow: inset 0 0 0 1px var(--berry-red); }
.input:disabled, .textarea:disabled, .select:disabled { background-color: var(--ivory-cream); color: var(--taupe); border-color: var(--linen); cursor: not-allowed; }
.input:-webkit-autofill, .input:-webkit-autofill:hover, .input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--charcoal); -webkit-box-shadow: 0 0 0 40px var(--white) inset; caret-color: var(--forest-green);
}

/* Native <select> fallback (no JS): drawn chevron instead of the OS arrow. */
select.input, select.select {
  padding-right: 44px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23302D2B' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}

/* Number, search, date, time: remove OS spinners and glyphs, keep our own. */
.input[type="number"] { -moz-appearance: textfield; }
.input[type="number"]::-webkit-inner-spin-button, .input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.input[type="search"]::-webkit-search-cancel-button, .input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; }
.input[type="date"], .input[type="time"] { font-variant-numeric: tabular-nums; }
.input::-webkit-datetime-edit { padding: 0; }
.input::-webkit-date-and-time-value { text-align: left; }
.input::-webkit-calendar-picker-indicator {
  cursor: pointer; opacity: 1; width: 20px; height: 20px; padding: 0; margin: 0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B635D' stroke-width='1.5' stroke-linecap='round'%3E%3Crect x='4' y='5.5' width='16' height='14.5' rx='2'/%3E%3Cpath d='M4 10h16M8.5 3.5v4M15.5 3.5v4'/%3E%3C/svg%3E") center / 20px no-repeat;
}
.input[type="time"]::-webkit-calendar-picker-indicator {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236B635D' stroke-width='1.5' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='8.5'/%3E%3Cpath d='M12 7.5V12l3 2'/%3E%3C/svg%3E");
}

/* ---------- Checkbox & radio (drawn, keyboard + screen reader stay native) ---------- */
:where(input[type="checkbox"], input[type="radio"]) {
  -webkit-appearance: none; appearance: none; flex: none; margin: 0;
  width: 22px; height: 22px; display: inline-grid; place-content: center; vertical-align: middle;
  border: 1.5px solid var(--line-strong); background: var(--white); color: var(--ivory-cream);
  cursor: pointer; transition: background-color 150ms ease-out, border-color 150ms ease-out;
}
:where(input[type="checkbox"]) { border-radius: var(--rounded-sm); }
:where(input[type="radio"]) { border-radius: 50%; }
:where(input[type="checkbox"])::before {
  content: ""; width: 14px; height: 14px; background: currentColor; transform: scale(0); transition: transform 160ms var(--ease);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / contain no-repeat;
}
:where(input[type="radio"])::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--forest-green); transform: scale(0); transition: transform 160ms var(--ease); }
:where(input[type="checkbox"], input[type="radio"]):hover { border-color: var(--charcoal); }
:where(input[type="checkbox"]):checked { background: var(--forest-green); border-color: var(--forest-green); }
:where(input[type="radio"]):checked { border-color: var(--forest-green); }
:where(input[type="checkbox"], input[type="radio"]):checked::before { transform: scale(1); }
:where(input[type="checkbox"], input[type="radio"]):focus-visible { outline: 2px solid var(--forest-green); outline-offset: 2px; }
:where(input[type="checkbox"], input[type="radio"])[aria-invalid="true"] { border-color: var(--berry-red); }
:where(input[type="checkbox"], input[type="radio"]):disabled { background: var(--ivory-cream); border-color: var(--linen); cursor: not-allowed; }

.check { display: flex; gap: var(--space-3); align-items: flex-start; min-height: 44px; padding-block: 10px; cursor: pointer; line-height: 1.5; }
.check > input { margin-top: 1px; }

/* Selectable card (delivery type, payment method). */
.choice-list { display: grid; gap: var(--space-3); }
@media (min-width: 640px) { .choice-list { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); } }
.choice {
  display: grid; grid-template-columns: auto 1fr; column-gap: var(--space-3); align-items: start;
  min-height: 64px; padding: var(--space-4); border: 1px solid var(--line-strong); border-radius: var(--rounded-md);
  background: var(--white); cursor: pointer; line-height: 1.4; font-weight: 500;
  transition: border-color 150ms ease-out, background-color 150ms ease-out, box-shadow 150ms ease-out;
}
.choice:has(.icon) { grid-template-columns: auto 1fr auto; }
.choice > input { margin-top: 0; grid-row: span 2; }
.choice > .icon { order: 3; width: 22px; height: 22px; color: var(--taupe); }
.choice small { display: block; margin-top: 2px; color: var(--taupe); font-size: var(--fs-small); font-weight: 400; }
.choice:hover { border-color: var(--charcoal); }
.choice:has(input:checked) { border-color: var(--forest-green); box-shadow: inset 0 0 0 1px var(--forest-green); background: var(--forest-4); }
.choice:has(input:checked) > .icon { color: var(--forest-green); }
.choice:has(input:focus-visible) { outline: 2px solid var(--forest-green); outline-offset: 2px; }
.choice > input:focus-visible { outline: none; }

/* ---------- Enhanced select (controls.js) ---------- */
.ctl { position: relative; }
.ctl-native { position: absolute !important; left: 50%; bottom: 0; width: 1px !important; height: 1px !important; min-height: 0 !important; padding: 0 !important; border: 0 !important; opacity: 0; pointer-events: none; }
.select-trigger { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.select-trigger .select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-trigger .icon { width: 18px; height: 18px; flex: none; color: var(--charcoal); transform: rotate(90deg); transition: transform 200ms var(--ease); }
.select-trigger[aria-expanded="true"] .icon { transform: rotate(-90deg); }
.select-trigger.is-placeholder .select-value { color: var(--taupe); }
select.input + .select-trigger, .select-trigger.input { padding-right: 14px; }

/* Filter pill variant (catalog). Smaller type, active state when a filter is applied. */
.select { min-height: 44px; padding: 8px 10px 8px 12px; border-radius: var(--rounded-pill); border-color: var(--linen); font-size: var(--fs-small); font-weight: 500; }
select.select { padding-right: 40px; font-size: 16px; }
.select:hover { border-color: var(--taupe); }
.select-trigger.select { gap: var(--space-1); }
.select-trigger.select .icon { width: 14px; height: 14px; }
@media (min-width: 640px) { .select-trigger.select { gap: var(--space-2); padding-inline: 16px 12px; } .select-trigger.select .icon { width: 16px; height: 16px; } }
.select-trigger.select.is-active { border-color: var(--forest-green); background: var(--forest-4); color: var(--forest-green); }
.select-trigger.select.is-active .icon { color: var(--forest-green); }

/* Popover (desktop) / bottom sheet (mobile), shared by select and calendar. */
.pop {
  position: absolute; z-index: 45; top: calc(100% + 6px); left: 0; min-width: max(100%, 232px); max-width: min(360px, calc(100vw - 2 * var(--gutter)));
  background: var(--white); border-radius: var(--rounded-md); box-shadow: var(--shadow-pop);
  padding: var(--space-2); transform-origin: top left; animation: pop-in 180ms var(--ease);
}
.pop.is-up { top: auto; bottom: calc(100% + 6px); transform-origin: bottom left; }
.pop.is-right { left: auto; right: 0; transform-origin: top right; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
.sheet-head { display: none; }
.sheet-backdrop { display: none; }
@media (max-width: 639px) {
  .pop, .pop.is-up, .pop.is-right {
    position: fixed; z-index: 61; left: 0; right: 0; top: auto; bottom: 0; max-width: none; min-width: 0;
    max-height: min(78dvh, 560px); overflow: auto; overscroll-behavior: contain;
    border-radius: var(--rounded-lg) var(--rounded-lg) 0 0; padding: 0 var(--gutter) calc(var(--space-4) + env(safe-area-inset-bottom));
    animation: sheet-in 260ms var(--ease);
  }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); position: sticky; top: 0; z-index: 1; background: var(--white); padding: var(--space-3) 0 var(--space-2); }
  .sheet-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--linen); }
  .sheet-title { font-weight: 600; padding-top: var(--space-2); }
  .sheet-backdrop.is-open { display: block; position: fixed; inset: 0; z-index: 60; background: rgba(48, 45, 43, .4); animation: ctl-fade 200ms ease-out; }
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
html.is-locked { overflow: hidden; }

.listbox { display: grid; gap: 2px; max-height: 320px; overflow: auto; outline: none; }
@media (max-width: 639px) { .listbox { max-height: none; } }
.opt {
  display: flex; align-items: center; gap: var(--space-3); min-height: 44px; padding: 10px 12px; border-radius: var(--rounded-sm);
  cursor: pointer; font-size: var(--fs-body); line-height: 1.35; color: var(--charcoal); user-select: none;
}
.opt .opt-text { flex: 1; min-width: 0; }
.opt .opt-meta { color: var(--taupe); font-size: var(--fs-small); font-variant-numeric: tabular-nums; white-space: nowrap; }
.opt .icon { width: 18px; height: 18px; flex: none; color: var(--forest-green); visibility: hidden; }
.opt.is-active { background: var(--ivory-cream); }
.opt[aria-selected="true"] { font-weight: 600; color: var(--forest-green); }
.opt[aria-selected="true"] .icon { visibility: visible; }
.opt[aria-disabled="true"] { color: var(--taupe); cursor: not-allowed; }

/* ---------- Date: chip row + calendar (controls.js) ---------- */
.date-chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
@media (min-width: 640px) { .date-chips { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.date-chip {
  display: grid; justify-items: center; align-content: center; gap: 2px; min-height: 64px; padding: 8px 4px;
  border: 1px solid var(--line-strong); border-radius: var(--rounded-md); background: var(--white); color: var(--charcoal);
  cursor: pointer; font: inherit; line-height: 1.2; text-align: center;
  transition: border-color 150ms ease-out, background-color 150ms ease-out, color 150ms ease-out;
}
.date-chip .dc-top { font-size: var(--fs-small); color: var(--taupe); }
.date-chip .dc-main { font-weight: 600; font-variant-numeric: tabular-nums; font-size: var(--fs-body); }
.date-chip .icon { width: 20px; height: 20px; color: var(--forest-green); }
.date-chip:hover { border-color: var(--charcoal); }
.date-chip[aria-checked="true"] { background: var(--forest-green); border-color: var(--forest-green); color: var(--ivory-cream); }
.date-chip[aria-checked="true"] .dc-top, .date-chip[aria-checked="true"] .icon { color: var(--ivory-cream); }
.date-chip.is-other .dc-main { font-size: var(--fs-small); font-weight: 600; }
.date-chips.is-invalid .date-chip:not([aria-checked="true"]) { border-color: var(--berry-red); }

.date-trigger { display: flex; align-items: center; gap: var(--space-3); cursor: pointer; padding-right: 48px; }
.date-trigger .icon { width: 20px; height: 20px; color: var(--taupe); flex: none; }
.date-trigger .date-value { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.date-trigger.is-placeholder .date-value { color: var(--taupe); }
.date-trigger[aria-expanded="true"] { border-color: var(--forest-green); box-shadow: inset 0 0 0 1px var(--forest-green); }
.date-clear { position: absolute; right: 2px; top: 2px; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; border-radius: var(--rounded-sm); color: var(--taupe); cursor: pointer; }
.date-clear:hover { color: var(--charcoal); }
.date-clear .icon { width: 18px; height: 18px; }

.cal { width: 100%; min-width: 300px; padding: var(--space-2); }
@media (max-width: 639px) { .cal { min-width: 0; padding: 0; } }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); }
.cal-title { font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-nav { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--charcoal); cursor: pointer; }
.cal-nav:hover:not(:disabled) { background: var(--ivory-cream); }
.cal-nav:disabled { color: var(--linen); cursor: not-allowed; }
.cal-nav .icon { width: 20px; height: 20px; }
.cal-nav.prev .icon { transform: scaleX(-1); }
.cal-grid { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal-grid th { font-size: var(--fs-label); font-weight: 600; letter-spacing: .04em; color: var(--taupe); padding: 4px 0 8px; text-align: center; }
.cal-grid td { padding: 1px; text-align: center; }
.cal-day {
  width: 100%; max-width: 44px; aspect-ratio: 1; min-height: 40px; margin: 0 auto; display: grid; place-items: center; position: relative;
  border: 0; border-radius: 50%; background: none; color: var(--charcoal); font: inherit; font-variant-numeric: tabular-nums; cursor: pointer;
}
.cal-day:hover:not(:disabled) { background: var(--ivory-cream); }
.cal-day.is-today::after { content: ""; position: absolute; bottom: 5px; width: 4px; height: 4px; border-radius: 50%; background: var(--champagne-gold); }
.cal-day[aria-pressed="true"] { background: var(--forest-green); color: var(--ivory-cream); font-weight: 600; }
.cal-day[aria-pressed="true"].is-today::after { background: var(--ivory-cream); }
.cal-day:disabled { color: var(--linen); cursor: not-allowed; text-decoration: line-through; text-decoration-color: transparent; }
.cal-day.is-outside { visibility: hidden; }
.cal-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); margin-top: var(--space-2); padding-top: var(--space-2); border-top: 1px solid var(--linen); font-size: var(--fs-small); color: var(--taupe); }
.cal-foot button { min-height: 44px; padding: 0 var(--space-3); border: 0; background: none; color: var(--forest-green); font: inherit; font-weight: 500; cursor: pointer; border-radius: var(--rounded-sm); }
.cal-foot button:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- File drop ---------- */
.filedrop {
  position: relative; display: grid; justify-items: center; gap: var(--space-1); text-align: center;
  padding: var(--space-6) var(--space-4); border: 1px dashed var(--line-strong); border-radius: var(--rounded-md);
  background: var(--white); transition: border-color 150ms ease-out, background-color 150ms ease-out;
}
.filedrop-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }
.filedrop-input::file-selector-button { cursor: pointer; }
.filedrop .icon { width: 28px; height: 28px; color: var(--rose-deep); stroke-width: 1.25; margin-bottom: var(--space-1); }
.filedrop-title { font-weight: 600; color: var(--forest-green); }
.filedrop-hint { font-size: var(--fs-small); color: var(--taupe); }
.filedrop:hover, .filedrop.is-over { border-color: var(--forest-green); background: var(--forest-4); }
.filedrop:has(.filedrop-input:focus-visible) { outline: 2px solid var(--forest-green); outline-offset: 2px; }
.filedrop:has(.filedrop-input[aria-invalid="true"]) { border-color: var(--berry-red); }
.file-list { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.file-item { display: grid; grid-template-columns: 48px 1fr; gap: var(--space-3); align-items: center; padding: var(--space-2); border: 1px solid var(--linen); border-radius: var(--rounded-sm); background: var(--white); font-size: var(--fs-small); }
.file-item img { width: 48px; height: 60px; object-fit: cover; border-radius: 4px; background: var(--blush-pink); }
.file-item .file-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .file-size { color: var(--taupe); font-variant-numeric: tabular-nums; }
.file-warn { color: var(--berry-red); font-size: var(--fs-small); margin-top: var(--space-2); }

@media (prefers-reduced-motion: reduce) { .pop, .sheet-backdrop.is-open { animation: none; } }
@keyframes ctl-fade { from { opacity: 0; } to { opacity: 1; } }
.filedrop-face { display: grid; justify-items: center; gap: var(--space-1); }
.sheet-head .icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; margin-right: -10px; border: 0; border-radius: 50%; background: none; color: var(--charcoal); cursor: pointer; }
.sheet-head .icon-btn:hover { background: var(--ivory-cream); }
.sheet-head .icon { width: 22px; height: 22px; }
