/*
 * THE SYSTEM'S DROPDOWN — one look for every <select> on every page.
 *
 * Linked from every page (dashboard, sign-in, the platform panel). The pages
 * keep using a plain <select>: its value, its events and its keyboard
 * behaviour stay the browser's own, so no screen's logic changes. What this
 * file changes is how it LOOKS.
 *
 * 1. The closed field: no native arrow, our own chevron at the END of the
 *    field (the left in Arabic), with room around it. Inline styles on the
 *    selects set `background:` and `padding:`, which would wipe these, so
 *    the properties that must survive are !important.
 *
 * 2. The open list, where the browser supports customizable selects
 *    (`appearance: base-select`, Chromium 135+): a rounded card in the
 *    system's colours and font, the chosen option marked in the brand red,
 *    a soft open/close. Where it is not supported (older Safari, Firefox),
 *    the browser's own list is shown — which on a phone is the better picker
 *    anyway. Nothing breaks either way.
 */

select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%238A7F7A' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-size: 12px 12px !important;
  background-position: right 13px center !important;
  padding-inline-end: 36px !important;
}
[dir="rtl"] select { background-position: left 13px center !important; }
select::-ms-expand { display: none; }
select:disabled { opacity: .6; cursor: not-allowed !important; }

@supports (appearance: base-select) {
  select,
  ::picker(select) {
    appearance: base-select;
  }

  /* The closed field keeps the page's own inline look (height, border,
     radius, font). base-select would otherwise draw its own arrow. */
  select { align-items: center; }
  select::picker-icon { display: none; }
  select:open {
    border-color: var(--red) !important;
    box-shadow: 0 0 0 3px var(--red-tint);
  }

  /* The open list. */
  ::picker(select) {
    box-sizing: border-box;
    min-width: anchor-size(width);
    max-height: min(340px, 60dvh);
    overflow-y: auto;
    margin-block: 6px;
    padding: 6px;
    border: 1px solid var(--line2);
    border-radius: 12px;
    background: var(--card);
    color: var(--ink);
    box-shadow: var(--sh-lg);
    font-family: var(--fam);
    scrollbar-width: thin;
    opacity: 0;
    translate: 0 -4px;
    transition: opacity .14s ease, translate .14s ease, overlay .14s allow-discrete, display .14s allow-discrete;
  }
  select:open::picker(select) {
    opacity: 1;
    translate: 0 0;
  }
  @starting-style {
    select:open::picker(select) {
      opacity: 0;
      translate: 0 -4px;
    }
  }

  select option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 38px;
    padding: 8px 12px;
    border-radius: 8px;
    font-family: var(--fam);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink);
    background: transparent;
    cursor: pointer;
    white-space: normal;
    line-height: 1.35;
    transition: background .1s ease;
  }
  select option:hover,
  select option:focus-visible {
    background: var(--sunken);
    outline: none;
  }
  select option:checked {
    background: var(--red-wash);
    color: var(--red-txt);
    font-weight: 700;
  }
  /* The tick sits at the end of the row, in the brand red. */
  select option::checkmark {
    order: 1;
    margin-inline-start: auto;
    color: var(--red);
    font-weight: 700;
  }
  /* "— Choose a plan —" style placeholders (an empty value) read as a hint. */
  select option[value=""] { color: var(--faint); }
  select option[value=""]:checked { color: var(--mut); background: var(--sunken); }

  select option:disabled { opacity: .45; cursor: not-allowed; }
}

@media (prefers-reduced-motion: reduce) {
  ::picker(select) { transition: none; }
}

/*
 * EVERY FIELD FOLLOWS THE PAGE'S LANGUAGE.
 *
 * In Arabic a label sits on the right, so its value must too: a number,
 * a phone, a card number or a date was drawn from the left (they are
 * left-to-right text), on the other side of the field from its own label.
 * The characters keep their own order; only the alignment follows the page.
 * A field that sets its own alignment inline (the code boxes) keeps it.
 */
html[dir="rtl"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html[dir="rtl"] textarea { text-align: right; }
html[dir="rtl"] input[type="date"],
html[dir="rtl"] input[type="datetime-local"],
html[dir="rtl"] input[type="time"] { direction: rtl; }
html[dir="rtl"] input::-webkit-datetime-edit { text-align: right; }
