/*
 * Site-wide dropdown (<select>) styling. Loaded from the root layout (app/layout.tsx), so it covers every
 * page: site pages, organizer/attendee dashboards, the admin panel, the registration walkthrough and the
 * React pages (Discover filters, My Tickets, ...).
 *
 * Each page keeps its own box styles (background color, border, radius, padding). This layer adds:
 *   - a themed chevron in place of the browser's grey arrow (drawn as a background image; the image
 *     properties are !important because many page rules use the `background:` shorthand, which would
 *     otherwise wipe it),
 *   - hover / focus / disabled states,
 *   - dark/light colors for the option list,
 *   - in Chromium 135+ on desktop (customizable select, `appearance: base-select`): a fully styled
 *     dropdown panel. Phones and tablets keep the native picker, which is easier to use there.
 * Multi-selects (list boxes) are left alone.
 */

/* ---------- Closed control ---------- */
select:not([multiple]) {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-inline-end: 40px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23cfff4b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 1.75 6 6.25l4.5-4.5'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 14px center !important;
  background-size: 12px 8px !important;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
select:not([multiple]):hover:not(:disabled) { border-color: #cfff4b99; }
select:not([multiple]):focus-visible { border-color: #cfff4b; box-shadow: 0 0 0 3px #cfff4b33; }
select:disabled { opacity: .55; cursor: not-allowed; }
select::-ms-expand { display: none; }

/* Option list colors for the native picker (Windows/Linux Chrome, Edge and Firefox honor these). */
select option, select optgroup { background-color: #15222b; color: #f5fafb; }
select optgroup { color: #aabbc4; font-weight: 700; }
select option:disabled { color: #6f818b; }

/* ---------- Light mode (theme.js sets data-color-mode on <html>) ---------- */
[data-color-mode=light] select:not([multiple]) {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%2338631a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 1.75 6 6.25l4.5-4.5'/%3E%3C/svg%3E") !important;
}
[data-color-mode=light] select:not([multiple]):hover:not(:disabled) { border-color: #38631a; }
[data-color-mode=light] select:not([multiple]):focus-visible { border-color: #38631a; box-shadow: 0 0 0 3px #38631a2e; }
[data-color-mode=light] select option,
[data-color-mode=light] select optgroup { background-color: #fff; color: #172720; }
[data-color-mode=light] select optgroup { color: #42574d; }
[data-color-mode=light] select option:disabled { color: #8a9a90; }

/* ---------- Styled dropdown panel (Chromium customizable select, desktop pointers only) ---------- */
@supports (appearance: base-select) {
  @media (hover: hover) and (pointer: fine) {
    select:not([multiple]),
    select:not([multiple])::picker(select) { appearance: base-select; }

    /* The chevron stays the background image above; the built-in icon would duplicate it. */
    select:not([multiple])::picker-icon { display: none; }
    select:not([multiple]):open {
      border-color: #cfff4b;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23cfff4b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 6.25 6 1.75l4.5 4.5'/%3E%3C/svg%3E") !important;
    }

    select:not([multiple])::picker(select) {
      min-width: anchor-size(width);
      max-height: min(360px, 60vh);
      margin-block: 6px;
      padding: 6px;
      overflow-y: auto;
      border: 1px solid #3c505c;
      border-radius: 12px;
      background: #15222b;
      color: #f5fafb;
      box-shadow: 0 18px 44px #00000080, 0 2px 6px #00000040;
      scrollbar-width: thin;
      scrollbar-color: #4b616d transparent;
      opacity: 1;
      transform: none;
      transition: opacity .14s ease, transform .14s ease, overlay .14s allow-discrete, display .14s allow-discrete;
    }
    @starting-style {
      select:not([multiple]):open::picker(select) { opacity: 0; transform: translateY(-4px); }
    }

    select:not([multiple]) option {
      display: flex;
      align-items: center;
      gap: 10px;
      min-height: 38px;
      padding: 8px 12px;
      border-radius: 8px;
      background: transparent;
      color: inherit;
      font-size: .95rem;
      line-height: 1.3;
      white-space: normal;
      cursor: pointer;
      outline: none;
      transition: background-color .1s, color .1s;
    }
    select:not([multiple]) option + option { margin-top: 2px; }
    select:not([multiple]) option:is(:hover, :focus-visible):not(:disabled) { background: #cfff4b1f; color: #fff; }
    select:not([multiple]) option:checked { background: #cfff4b; color: #11180d; font-weight: 700; }
    select:not([multiple]) option:checked:is(:hover, :focus-visible) { background: #dcff73; color: #11180d; }
    select:not([multiple]) option::checkmark { order: 1; margin-inline-start: auto; content: "\2713"; font-weight: 800; }
    select:not([multiple]) option:disabled { background: transparent; color: #6f818b; cursor: not-allowed; }
    select:not([multiple]) optgroup { background: transparent; padding: 4px 0; }
    select:not([multiple]) optgroup::before,
    select:not([multiple]) legend { padding: 6px 12px 4px; font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; color: #aabbc4; }

    [data-color-mode=light] select:not([multiple]):open {
      border-color: #38631a;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%2338631a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1.5 6.25 6 1.75l4.5 4.5'/%3E%3C/svg%3E") !important;
    }
    [data-color-mode=light] select:not([multiple])::picker(select) {
      border-color: #c3d2c8;
      background: #fff;
      color: #172720;
      box-shadow: 0 18px 44px #263c2526, 0 2px 6px #263c251a;
      scrollbar-color: #a9bcb0 transparent;
    }
    [data-color-mode=light] select:not([multiple]) option:is(:hover, :focus-visible):not(:disabled) { background: #eaf1e9; color: #172720; }
    [data-color-mode=light] select:not([multiple]) option:checked { background: #38631a; color: #fff; }
    [data-color-mode=light] select:not([multiple]) option:checked:is(:hover, :focus-visible) { background: #2e5315; color: #fff; }
    [data-color-mode=light] select:not([multiple]) option:disabled { background: transparent; color: #8a9a90; }
    [data-color-mode=light] select:not([multiple]) legend { color: #42574d; }
  }
}
