/* Shared chrome for editable controls, including forms mounted after page load.
   In a named layer, these important surface declarations take precedence over
   legacy page-specific important colours. Size, display and positioning stay local. */
@layer ls-field-surface {
  @media screen {
    :where(
      input:not([type]), input[type=""], input[type="text"], input[type="search"],
      input[type="email"], input[type="url"], input[type="tel"], input[type="password"],
      input[type="number"], input[type="date"], input[type="time"], input[type="month"],
      input[type="week"], input[type="datetime-local"], select, textarea,
      [contenteditable="true"][role="textbox"]
    ) {
      --ls-field-ink: #26374a;
      --ls-field-rim: linear-gradient(155deg, #72695f 0%, #e1d6c7 21%, #9d9386 49%, #70665b 73%, #d9cfc0 100%);
      --ls-field-well: linear-gradient(#fffdfa, #faf8f5);
      --ls-field-shadow: inset 0 0 0 1px #8c8175, inset 0 2px 4px #49372429, 0 1px 1px #523c2815;
      --ls-field-accent: #193c57;

      box-sizing: border-box !important;
      color-scheme: light !important;
      min-inline-size: 0;
      border: 3px solid transparent !important;
      border-radius: 7px !important;
      background: var(--ls-field-well) padding-box, var(--ls-field-rim) border-box !important;
      box-shadow: var(--ls-field-shadow) !important;
      color: var(--ls-field-ink) !important;

      &:focus {
        box-shadow: inset 0 0 0 2px var(--ls-field-accent), inset 0 2px 4px #49372420 !important;
        outline: 2px solid var(--ls-field-accent) !important;
        outline-offset: 1px !important;
      }
      &:is([aria-invalid="true"], .is-invalid, .error, :user-invalid) {
        --ls-field-accent: #9d3830;
        border-color: var(--ls-field-accent) !important;
      }
      &:is([readonly], :disabled, [aria-disabled="true"]) {
        --ls-field-ink: #675e55;
        --ls-field-well: linear-gradient(#f0ede8, #f3f0eb);
        --ls-field-rim: linear-gradient(135deg, #aba399, #d7d0c7);
        --ls-field-shadow: inset 0 0 0 1px #c4bdb3;
      }

      @media (forced-colors: active) {
        border: 2px solid ButtonText !important;
        background: Field !important;
        color: FieldText !important;
        box-shadow: none !important;
        &:focus { outline-color: Highlight !important; box-shadow: none !important; }
        &:disabled { border-color: GrayText !important; color: GrayText !important; }
      }
    }

    select:not([multiple]):is(:not([size]), [size="0"], [size="1"]) {
      /* Keep the native picker and options. Only its closed appearance changes. */
      appearance: none !important;
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      white-space: nowrap !important;
      padding-inline-end: 1.75em !important;
      --ls-field-arrow: url("/ls-theme-assets/field-chevron.svg?v=20fe245bec6a452d");
      background: var(--ls-field-arrow) right .4em center / .75em no-repeat padding-box,
        linear-gradient(to left, transparent 1.3em, #b9aea0 1.3em calc(1.3em + 1px), transparent calc(1.3em + 1px)) padding-box,
        var(--ls-field-well) padding-box, var(--ls-field-rim) border-box !important;
      @media (forced-colors: active) { appearance: auto !important; background: Field !important; }
    }

    /* This old decorative SVG would otherwise double the shared select arrow. */
    .admin-select-wrap > select + .admin-icon[aria-hidden="true"] { display: none !important; }

    /* Long lunar year/month names need room for the same picker chrome. Only
       this compact input group wraps; the calendar and its navigation stay local. */
    @media (max-width: 600px) {
      body #calendar-panel #ls-month-calendar .mc-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
      }
      body #calendar-panel #ls-month-calendar .mc-controls > .mc-mode {
        grid-column: 1 / -1 !important;
      }
    }

    input:is([type="date"], [type="time"], [type="datetime-local"], [type="month"], [type="week"])::-webkit-calendar-picker-indicator {
      border-inline-start: 1px solid #b9aea0;
      padding-inline-start: .55em;
      cursor: pointer;
    }
  }
}
