/* Cite · Paste-up form controls (paste/controls.js draws the popovers).
   Needs tokens.css. Fields are the outlined field from tool.css; every
   popover is a sheet with the lift shadow, a bottom sheet on a phone.
   No browser-default control is left showing on an operator page. */

/* ── The trigger: a field-styled button where the native was ── */
.cc { position: relative; display: block; width: 100%; }
.cc-native { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; margin: 0; opacity: 0 !important; pointer-events: none !important; }
.cc-trigger {
  --fl: color-mix(in srgb, var(--ink) 38%, transparent);
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 14px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink); font: inherit; font-weight: 600; font-size: 16px; text-align: left; cursor: pointer;
  box-shadow: inset 0 0 0 1.5px var(--fl); transition: box-shadow 160ms ease, background-color 160ms ease;
}
.cc-trigger .cc-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cc-trigger.is-empty .cc-value { color: var(--ink3); font-weight: 500; }
.cc-trigger .cc-ic { flex: none; width: 18px; height: 18px; color: var(--ink3); transition: transform 200ms var(--ease-out), color 160ms ease; }
@media (hover: hover) { .cc-trigger:hover { --fl: color-mix(in srgb, var(--ink) 66%, transparent); } .cc-trigger:hover .cc-ic { color: var(--ink); } }
.cc-trigger:focus-visible, .cc-trigger[aria-expanded="true"] { outline: none; box-shadow: inset 0 0 0 2px var(--ink), 0 0 0 4px color-mix(in srgb, var(--accent) 34%, transparent); }
.cc-select .cc-trigger[aria-expanded="true"] .cc-ic { transform: rotate(180deg); }
.cc-trigger.err { box-shadow: inset 0 0 0 2px var(--danger); }
.cc-trigger:disabled { --fl: color-mix(in srgb, var(--ink) 16%, transparent); color: var(--ink3); cursor: not-allowed; }
.field .cc-trigger { --fl: rgba(29,31,34,.45); color: #1D1F22; }
.field .cc-trigger .cc-ic, .field .cc-trigger.is-empty .cc-value { color: rgba(29,31,34,.7); }

/* ── The popover ── */
.cc-pop {
  position: fixed; z-index: 300; max-width: min(380px, calc(100vw - 16px)); padding: 6px; border-radius: 14px;
  background: var(--sheet); color: var(--ink); box-shadow: var(--shadow-lift), 0 0 0 1px color-mix(in srgb, var(--ink) 8%, transparent);
  font-family: var(--f); opacity: 0; transform: translateY(-4px) scale(.98); transform-origin: top center;
  transition: opacity 140ms ease, transform 200ms var(--ease-out);
}
.cc-pop.on { opacity: 1; transform: none; }
.cc-scrim { display: none; }

.cc-list { display: grid; gap: 2px; max-height: min(320px, 50vh); margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; outline: none; scrollbar-width: thin; }
.cc-list li { list-style: none; display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 0 12px 0 10px; border-radius: 9px; color: var(--ink2); font-weight: 600; font-size: 15.5px; cursor: pointer; }
.cc-list li .cc-tick { flex: none; width: 16px; height: 16px; color: var(--green-ink); opacity: 0; }
.cc-list li[aria-selected="true"] { color: var(--ink); font-weight: 750; }
.cc-list li[aria-selected="true"] .cc-tick { opacity: 1; }
.cc-list li.is-active { background: var(--well); color: var(--ink); }
.cc-list:focus-visible li.is-active { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }
.cc-list li[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.cc-pop-time .cc-list { min-width: 150px; }

/* ── The calendar ── */
.cc-cal { width: 300px; max-width: 100%; padding: 6px 6px 4px; }
.cc-cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.cc-cal-head b { font-weight: 800; font-size: 16px; letter-spacing: -.015em; }
.cc-nav { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 99px; background: var(--well); color: var(--ink2); cursor: pointer; transition: background-color 160ms ease, color 160ms ease; }
.cc-nav .cc-ic { width: 18px; height: 18px; }
@media (hover: hover) { .cc-nav:hover { color: var(--ink); background: color-mix(in srgb, var(--well) 60%, var(--rule2)); } }
.cc-cal table { width: 100%; border-collapse: separate; border-spacing: 2px; }
.cc-cal th { padding: 4px 0; color: var(--ink3); font-size: 12.5px; font-weight: 750; text-align: center; }
.cc-cal td { padding: 0; text-align: center; }
.cc-cal td button { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 99px; background: none; color: var(--ink); font: inherit; font-weight: 650; font-size: 14.5px; font-variant-numeric: tabular-nums; cursor: pointer; transition: background-color 140ms ease, color 140ms ease; }
.cc-cal td button.is-other { color: var(--faint); }
.cc-cal td button.is-today { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--ink) 40%, transparent); }
.cc-cal td button.is-chosen { background: var(--ink); color: var(--ground); font-weight: 800; box-shadow: none; }
.cc-cal td button:disabled { color: var(--faint); opacity: .45; cursor: not-allowed; }
@media (hover: hover) { .cc-cal td button:not(.is-chosen):not(:disabled):hover { background: var(--well); } }
.cc-cal td button:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 1px; }
.cc-cal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 6px 4px 2px; }
.cc-link { padding: 6px 10px; border: 0; border-radius: 8px; background: none; color: var(--ink); font: inherit; font-weight: 750; font-size: 14px; cursor: pointer; }
@media (hover: hover) { .cc-link:hover { background: var(--well); } }
.cc-dt { display: grid; grid-template-columns: auto 150px; gap: 6px; align-items: start; }
.cc-dt .cc-list { max-height: 330px; }
.cc-pop-datetime { max-width: min(480px, calc(100vw - 16px)); }

/* ── Number: the field between − and + ── */
.cc-number { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; align-items: stretch; gap: 6px; }
.cc-number input { text-align: center; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
.cc-number input::-webkit-inner-spin-button, .cc-number input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cc-step { display: grid; place-items: center; min-height: 48px; border: 0; border-radius: 10px; background: var(--well); color: var(--ink2); cursor: pointer; transition: background-color 160ms ease, color 160ms ease, transform 120ms var(--ease-out); }
.cc-step .cc-ic { width: 18px; height: 18px; }
.cc-step:active { transform: scale(.94); }
@media (hover: hover) { .cc-step:hover { color: var(--ink); background: color-mix(in srgb, var(--well) 60%, var(--rule2)); } }

/* ── Checkbox, radio, switch: drawn, not the browser's ── */
input[type="checkbox"]:not(.sr):not(.cc-native), input[type="radio"]:not(.sr):not(.cc-native) {
  -webkit-appearance: none; appearance: none; flex: none; display: inline-grid; place-items: center; width: 22px; height: 22px; margin: 0; vertical-align: -5px;
  border-radius: 7px; background: transparent; box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--ink) 45%, transparent); cursor: pointer;
  transition: background-color 160ms ease, box-shadow 160ms ease;
}
input[type="radio"]:not(.sr):not(.cc-native) { border-radius: 50%; }
input[type="checkbox"]:not(.sr):not(.cc-native)::after { content: ''; width: 12px; height: 12px; background: var(--ground); opacity: 0; transform: scale(.6); transition: opacity 140ms ease, transform 200ms var(--ease-spring);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4.5 12.5 5 5L19.5 7'/%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='black' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4.5 12.5 5 5L19.5 7'/%3E%3C/svg%3E") center / contain no-repeat; }
input[type="radio"]:not(.sr):not(.cc-native)::after { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--ground); opacity: 0; transform: scale(.5); transition: opacity 140ms ease, transform 200ms var(--ease-spring); }
input[type="checkbox"]:not(.sr):not(.cc-native):checked, input[type="radio"]:not(.sr):not(.cc-native):checked { background: var(--ink); box-shadow: none; }
input[type="checkbox"]:not(.sr):not(.cc-native):checked::after, input[type="radio"]:not(.sr):not(.cc-native):checked::after { opacity: 1; transform: none; }
input[type="checkbox"]:not(.sr):not(.cc-native):indeterminate { background: var(--ink); box-shadow: none; }
input[type="checkbox"]:not(.sr):not(.cc-native):indeterminate::after { opacity: 1; transform: none; height: 2.5px; -webkit-mask: none; mask: none; border-radius: 2px; }
input[type="checkbox"]:not(.sr):not(.cc-native):focus-visible, input[type="radio"]:not(.sr):not(.cc-native):focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
input[type="checkbox"]:not(.sr):not(.cc-native):disabled, input[type="radio"]:not(.sr):not(.cc-native):disabled { opacity: .45; cursor: not-allowed; }
@media (hover: hover) { input[type="checkbox"]:not(.sr):not(:checked):hover, input[type="radio"]:not(.sr):not(:checked):hover { box-shadow: inset 0 0 0 1.5px var(--ink); } }

/* The switch: a checkbox with class "switch" or role="switch". Green when on. */
input[type="checkbox"].switch:not(.sr), input[type="checkbox"][role="switch"]:not(.sr) { width: 44px; height: 26px; border-radius: 99px; background: color-mix(in srgb, var(--ink) 22%, transparent); box-shadow: none; place-items: center start; padding: 3px; }
input[type="checkbox"].switch:not(.sr)::after, input[type="checkbox"][role="switch"]:not(.sr)::after { width: 20px; height: 20px; border-radius: 50%; background: #FBF8F1; opacity: 1; transform: none; -webkit-mask: none; mask: none; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform 240ms var(--ease-out); }
input[type="checkbox"].switch:not(.sr):checked, input[type="checkbox"][role="switch"]:not(.sr):checked { background: var(--accent); }
input[type="checkbox"].switch:not(.sr):checked::after, input[type="checkbox"][role="switch"]:not(.sr):checked::after { transform: translateX(18px); }

/* ── Range ── */
input[type="range"]:not(.sr) { -webkit-appearance: none; appearance: none; width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer; }
input[type="range"]:not(.sr)::-webkit-slider-runnable-track { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--ink) 18%, transparent); }
input[type="range"]:not(.sr)::-moz-range-track { height: 6px; border-radius: 99px; background: color-mix(in srgb, var(--ink) 18%, transparent); }
input[type="range"]:not(.sr)::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--ink); }
input[type="range"]:not(.sr)::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 3px var(--sheet), 0 2px 6px rgba(0,0,0,.3); transition: transform 140ms var(--ease-out); }
input[type="range"]:not(.sr)::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 3px var(--sheet), 0 2px 6px rgba(0,0,0,.3); }
input[type="range"]:not(.sr):active::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"]:not(.sr):focus-visible { outline: none; }
input[type="range"]:not(.sr):focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--sheet), 0 0 0 6px color-mix(in srgb, var(--accent) 50%, transparent); }

/* ── A visible file input: its button is the quiet pill ── */
input[type="file"]:not(.sr) { max-width: 100%; color: var(--ink3); font: inherit; font-size: 14.5px; }
input[type="file"]:not(.sr)::file-selector-button { height: 40px; margin-right: 12px; padding: 0 16px; border: 0; border-radius: 99px; background: transparent; color: var(--ink); font: inherit; font-weight: 700; font-size: 14.5px; box-shadow: inset 0 0 0 1.5px var(--ink); cursor: pointer; transition: background-color 160ms ease; }
@media (hover: hover) { input[type="file"]:not(.sr)::file-selector-button:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); } }

/* ── Phones: every popover is a bottom sheet ── */
@media (max-width: 600px) {
  .cc-scrim { display: block; position: fixed; inset: 0; z-index: 299; background: rgba(20,18,15,.42); opacity: 0; transition: opacity 180ms ease; }
  .cc-scrim.on { opacity: 1; }
  .cc-pop { left: 0 !important; right: 0; top: auto !important; bottom: 0; max-width: none; min-width: 0 !important; padding: 10px 10px calc(14px + env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; transform: translateY(24px); transform-origin: bottom center; }
  .cc-pop::before { content: ''; display: block; width: 40px; height: 4px; margin: 0 auto 10px; border-radius: 4px; background: color-mix(in srgb, var(--ink) 22%, transparent); }
  .cc-list { max-height: 55vh; }
  .cc-list li { min-height: 48px; font-size: 16.5px; }
  .cc-cal { width: 100%; }
  .cc-cal td button { width: 42px; height: 42px; }
  .cc-dt { grid-template-columns: 1fr; }
  .cc-dt .cc-list { max-height: 30vh; }
}
@media (prefers-reduced-motion: reduce) { .cc-pop { transition: opacity 1ms; transform: none; } }
