/* Load after app.css. These are native controls: browser keyboard handling,
   labels, validation, form values and change events remain unchanged. */
select {
  --control-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%233f7c61' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  appearance: none;
  padding-inline-end: 34px;
  background-image: var(--control-chevron);
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  line-height: 1.45;
  cursor: pointer;
}

select[multiple],
select[size]:not([size="1"]) {
  appearance: auto;
  background-image: none;
  padding-inline-end: 11px;
}

/* Only the enhanced native renderer uses the explicit selected-value button. */
select > button:first-child {
  display: none;
}

select option,
select optgroup {
  color: var(--ink);
  background-color: var(--surface);
}

.filterbar select,
.locale-select {
  padding-inline-end: 29px;
  background-image: var(--control-chevron);
  background-position: right 7px center;
}

.table-toolbar select {
  padding-inline-end:34px;
}

.project-switch select {
  --control-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%23d4edaf' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  border: 1px solid #817a7466;
  border-radius: 7px;
  padding: 7px 29px 7px 9px;
  min-height: 34px;
  color: #f6f3f1;
  background-color: #ffffff08;
  background-image: var(--control-chevron);
  background-position: right 7px center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

:is(input, select, textarea):not(:disabled):hover {
  border-color: #afa9a3;
}

:is(input, select, textarea):focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-color: var(--green);
}

.project-switch select:not(:disabled):hover {
  border-color: #c1b7ad80;
  background-color: #ffffff0d;
}

.project-switch select:focus-visible {
  outline-color: var(--lime);
  border-color: var(--lime);
}

:is(input, select, textarea):disabled {
  color: #83807e;
  background-color: #f2f0ef;
  border-color: var(--line);
  cursor: not-allowed;
}

/* Read-only values stay focusable and selectable, with a quieter surface. */
:is(input, textarea)[readonly]:not(:disabled) {
  background-color: var(--canvas);
  color: var(--ink);
  cursor: text;
}

.project-switch select:disabled {
  color: #9f9a94;
  background-color: transparent;
  border-color: #817a7444;
}

/* Checkbox/radio state and indeterminate rendering stay native. */
input:is([type="checkbox"], [type="radio"]) {
  appearance: auto;
  accent-color: var(--forest);
  inline-size: 16px;
  block-size: 16px;
  min-height: 16px;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

input:is([type="checkbox"], [type="radio"]):disabled {
  cursor: not-allowed;
}

input:is([type="date"], [type="time"], [type="datetime-local"]) {
  color-scheme: light;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

input::-webkit-calendar-picker-indicator {
  opacity: 0.65;
  cursor: pointer;
}

input:not(:disabled):hover::-webkit-calendar-picker-indicator {
  opacity: 1;
}

input[type="file"]::file-selector-button {
  border: 1px solid #dad6d2;
  border-radius: 6px;
  background: #f6ede7;
  color: var(--forest);
  padding: 6px 10px;
  margin-inline-end: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

input[type="file"]:not(:disabled):hover::file-selector-button {
  background: var(--lime);
  border-color: #bfb4a9;
}

input[type="file"]:disabled::file-selector-button {
  background: var(--canvas);
  color: var(--muted);
  cursor: not-allowed;
}

/* Progressive enhancement for single-select pickers. Unsupported browsers
   keep the styled closed control above and their operating-system popup.
   No rich option markup or replacement JavaScript widget is required. */
@supports (appearance: base-select) and selector(select::picker(select)) {
  select:where(:not([multiple]):not([size]), :not([multiple])[size="1"]),
  select:where(:not([multiple]):not([size]), :not([multiple])[size="1"])::picker(select) {
    appearance: base-select;
  }

  select:where(:not([multiple]):not([size]), :not([multiple])[size="1"]) {
    align-items: center;
    gap: 9px;
  }

  /* Keep the native arrow outside the clipped selected label. The button
     stays inert and delegates its layout to the selected content. */
  select > button:first-child {
    display: contents;
  }

  select > button:first-child > selectedcontent {
    display: block;
    flex: 1 1 auto;
    min-inline-size: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Match the specificity of compact/dark surface rules in app.css. */
  select,
  .filterbar select,
  .table-toolbar select,
  .locale-select,
  .project-switch select {
    background-image: none;
    padding-inline-end: 11px;
  }

  select::picker-icon {
    color: var(--green);
    margin-inline-start: auto;
    flex-shrink: 0;
  }

  .project-switch select::picker-icon {
    color: var(--lime);
  }

  select:open {
    border-color: var(--green);
    box-shadow: 0 0 0 3px #96462c14;
  }

  .project-switch select:open {
    border-color: #c1b7ad;
    background-color: #ffffff0d;
  }

  select::picker(select) {
    box-sizing: border-box;
    color-scheme: light;
    border: 1px solid #dad6d2;
    border-radius: 10px;
    padding: 5px;
    margin-block: 5px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 12px 32px #1e1b191f, 0 2px 6px #1e1b190a;
    max-inline-size: calc(100vw - 24px);
    max-block-size: min(360px, 60vh);
    overflow-y: auto;
    overscroll-behavior: contain;
    font: inherit;
    font-size: 12px;
    line-height: 1.5;
    scrollbar-width: thin;
    scrollbar-color: #c5beb8 transparent;
  }

  @supports (min-inline-size: anchor-size(self-inline)) {
    select::picker(select) {
      min-inline-size: min(anchor-size(self-inline), calc(100vw - 24px));
    }
  }

  select option,
  .project-switch select option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-block-size: 36px;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    color: var(--ink);
    background: var(--surface);
    white-space: normal;
    overflow-wrap: anywhere;
    cursor: pointer;
  }

  select option:checked,
  .project-switch select option:checked {
    color: var(--forest-dark);
    background: var(--lime);
    font-weight: 600;
  }

  select option:not(:disabled):hover,
  .project-switch select option:not(:disabled):hover {
    background: #f6ede7;
  }

  select option:focus-visible,
  .project-switch select option:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: -2px;
    background: #f6ede7;
  }

  select option::checkmark {
    color: var(--forest);
    flex-shrink: 0;
  }

  select option:disabled,
  .project-switch select option:disabled {
    color: #95928f;
    background: var(--canvas);
    cursor: not-allowed;
  }

  select optgroup {
    padding-block: 4px;
    font-weight: 600;
  }
}

/* Honor the operating system's contrast palette and control rendering. */
@media (forced-colors: active) {
  select,
  .filterbar select,
  .locale-select,
  .project-switch select,
  .project-switch select:open {
    appearance: auto;
    background-image: none;
    background-color: Canvas;
    color: CanvasText;
    border-color: ButtonText;
    box-shadow: none;
  }

  :is(input, select, textarea):focus-visible,
  .project-switch select:focus-visible {
    outline-color: Highlight;
  }

  input:is([type="checkbox"], [type="radio"]) {
    accent-color: auto;
  }
}
