/*
 * ── One note before the rules ──
 *
 * select-upgrade.js replaces the native popup on most dropdowns and marks the
 * original `select.xs-native`. Every caret rule below excludes that class.
 *
 * Not for tidiness: `select:not([multiple]):not([size])` weighs (0,2,1),
 * because :not() carries its argument's specificity, and it was beating the
 * rules meant to hide the upgraded select — so the hidden element kept its
 * caret image and its padding and painted them over the button that replaced
 * it. That is the mark on the closed control that the open list never had.
 *
 * Two stylesheets fighting over one element is a bug waiting to come back.
 * This one stops claiming the ones the other owns.
 */

/* Selects that look like selects.
 *
 * `.a-select` sets `appearance: none` and nothing puts an arrow back. Every
 * dropdown in the admin panel and the customer portal has therefore rendered
 * as a plain box with text in it — indistinguishable from a read-only field,
 * which is why the coupon "who can use it" control read as broken rather than
 * as a menu nobody had opened.
 *
 * It looked worse in Arabic for two reasons. Longer option text fills the box,
 * so there is no empty space on the right where an arrow would be expected;
 * and any arrow added with `right:` would have sat on the wrong side anyway.
 *
 * Everything below uses logical properties, so the caret follows the writing
 * direction rather than the viewport.
 */

.a-select,
.p-select,
/*
 * …and every other select on the page.
 *
 * :not([multiple]):not([size]) because a list box has no dropdown to point at
 * — an arrow on one is a caret floating beside a scrolling list, which is how
 * you can tell a stylesheet was written for one case and applied to all of
 * them.
 */
select:not([multiple]):not([size]):not(.xs-native),
select.a-input,
select.form-input {
  /* The caret, inline. No file to fetch, no request to fail, and it inherits
     nothing — which is why the colour is repeated per theme below rather than
     using currentColor, which SVG in a background-image cannot see. */
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%235A6472' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 16px 16px;

  /* logical, so RTL puts it on the left without a second rule */
  background-position: right 0.85rem center;
  padding-inline-end: 2.4rem;

  cursor: pointer;
}

[dir="rtl"] select:not([multiple]):not([size]):not(.xs-native),
[dir="rtl"] .a-select,
[dir="rtl"] .p-select,
[dir="rtl"] select.a-input,
[dir="rtl"] select.form-input {
  /* The caret moves to the left edge, where the line ends in Arabic. Without
     this it sits on the right, on top of the first word. */
  background-position: left 0.85rem center;
}

/* Dark: the same caret, lighter, because a #5A6472 stroke disappears on a
   dark field. */
[data-theme="dark"] select:not([multiple]):not([size]):not(.xs-native),
[data-admin-theme="dark"] select:not([multiple]):not([size]):not(.xs-native),
[data-theme="dark"] .a-select,
[data-admin-theme="dark"] .a-select,
[data-theme="dark"] .p-select,
[data-admin-theme="dark"] .p-select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23A7B0BC' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
}

.a-select:hover,
.p-select:hover { border-color: var(--a-border); }

/* Open, or focused. The caret turns accent so the control reads as live. */
.a-select:focus,
.p-select:focus {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23B07D18' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
}

/* A select nobody can change should not invite a click. */
.a-select:disabled,
.p-select:disabled {
  opacity: .55;
  cursor: not-allowed;
  background-image: none;
}

/*
 * The option list itself.
 *
 * A browser draws this with the operating system, and most of it cannot be
 * styled — but background and colour are honoured on every current engine, and
 * without them a dark admin panel opens a white menu. Padding is respected on
 * Firefox and ignored elsewhere; harmless where it is.
 */
/*
 * ── The fix that actually matters ──
 *
 * color-scheme tells the browser which palette to draw NATIVE controls with.
 * Without it Chrome renders a <select> popup, a date picker and a scrollbar in
 * the light scheme no matter what CSS says about them — because that popup is
 * an OS-drawn window, not part of the page.
 *
 * That is the white menu: the panel is dark, the option rules below are
 * correct, and the browser draws its own light popup over the top of them.
 *
 * It is set on :root so it reaches every control, including the ones no
 * selector below names.
 */
:root { color-scheme: light }
[data-theme="dark"],
[data-admin-theme="dark"] { color-scheme: dark }

/*
 * Every select, not just the two classes.
 *
 * The rules named .a-select and .p-select. A count across the views found
 * 25 selects with neither — 22 with no class at all and 3 using a-input —
 * and each of those opened an unstyled white list on a dark page.
 *
 * A bare `select` selector cannot miss one.
 */
select option {
  background: var(--a-bg-card, #fff);
  color: var(--a-fg, #12161B);
  padding: .5rem .75rem;

  /* start, not left: in Arabic the text has to sit against the right edge,
     and the one browser that honours this on an option is the one where it
     otherwise looks wrong. */
  text-align: start;
}

[data-theme="dark"] select option,
[data-admin-theme="dark"] select option {
  background: #12161B;
  color: #E8EBEF;
}

/*
 * The select itself inherits the page direction.
 *
 * A select with no direction of its own takes the document's, which is what
 * we want — but a parent that set `direction: ltr` for a number field or a
 * code block would otherwise leak into a select inside it, putting Arabic
 * option text against the wrong edge inside an otherwise correct form.
 */
[dir="rtl"] select,
[dir="rtl"] select option,
[dir="rtl"] select optgroup { direction: rtl; text-align: right }

/* A grouped list needs its headings to read as headings. */
select optgroup {
  font-weight: 700;
  font-style: normal;
  color: var(--a-fg-3, #5A6472);
}

/*
 * A multiple select is a list, not a one-line box.
 *
 * Left at the default it shows four rows in a field the height of a text
 * input, and people do not realise it scrolls.
 */
.a-select[multiple],
.p-select[multiple] {
  background-image: none;
  padding-inline-end: .9rem;
  min-height: 9rem;
}
.a-select[multiple] option,
.p-select[multiple] option { padding: .45rem .6rem; border-radius: 5px; }
.a-select[multiple] option:checked {
  background: var(--a-accent, #B07D18);
  color: #fff;
}

/* A native date input carries its own picker icon, which in RTL sits over the
   text. Same logical treatment. */
input[type="date"].a-input,
input[type="time"].a-input,
input[type="datetime-local"].a-input { padding-inline-end: 2.2rem; }

[dir="rtl"] input[type="date"].a-input::-webkit-calendar-picker-indicator,
[dir="rtl"] input[type="time"].a-input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset-inline-start: .6rem;
}
[dir="rtl"] .a-field { position: relative; }
/* drop 1079: a date or time box written left to right (dir="ltr") keeps its icon on its own end, after the text — not over it */
[dir="rtl"] input[dir="ltr"][type="date"].a-input::-webkit-calendar-picker-indicator,
[dir="rtl"] input[dir="ltr"][type="time"].a-input::-webkit-calendar-picker-indicator { position: static; }
/* drop 1073: and on a date field outside an .a-field (list filters, panels), the icon stays inside its own box */
[dir="rtl"] input[type="date"].a-input, [dir="rtl"] input[type="time"].a-input { position: relative; }

/* Drop 614: a reason from a list, with "Other" opening a text box beneath it (ReasonField). */
.rf { display: grid; gap: .35rem; min-width: 0; }
.rf:not(:has(.rf-select option[value="__other__"]:checked)) .rf-other { display: none; }

/* Drop 614: the client's escalation list — target date, shared updates, rating. */
.esc-c-meta { font-size: .8rem; color: var(--fg-muted, #5A6472); margin: .7rem 0 0; }
.esc-c-update { font-size: .82rem; margin-top: .5rem; padding: .5rem .7rem; border-radius: 8px; background: var(--bg-2, rgba(0,0,0,.03)); }
.esc-c-update span { font-size: .72rem; color: var(--fg-muted, #5A6472); margin-inline-end: .4rem; }
.esc-c-done { margin-top: .85rem; padding-top: .75rem; border-top: 1px solid var(--border-2, #E2E5EA); }
.esc-c-done p { font-size: .84rem; margin: 0; }
.esc-c-label { font-size: .72rem; color: var(--fg-muted, #5A6472); margin-bottom: .3rem; }
.esc-c-rate { margin-top: .9rem; padding-top: .75rem; border-top: 1px solid var(--border-2, #E2E5EA); display: grid; gap: .5rem; }
.esc-c-stars { display: flex; gap: .35rem; }
.esc-c-stars input { position: absolute; opacity: 0; pointer-events: none; }
.esc-c-stars i { font-style: normal; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--border-2, #D5D9E0); font-weight: 700; cursor: pointer; }
.esc-c-stars input:checked + i { background: var(--accent, #C98E1F); border-color: var(--accent, #C98E1F); color: #fff; }
.esc-c-stars input:focus-visible + i { outline: 2px solid var(--accent, #C98E1F); outline-offset: 2px; }

/* Drop 617: a partner's assigned work in the portal. */
.pw-head h1 { font-size: 1.35rem; font-weight: 800; margin: 0 0 .3rem; }
.pw-head p, .pw-meta, .pw-empty { font-size: .82rem; color: var(--fg-muted, #5A6472); margin: 0; }
.pw-head { margin-bottom: 1.2rem; }
.pw-back { margin: 0 0 .6rem; font-size: .82rem; }
.pw-list { display: grid; gap: .75rem; }
.pw-item { text-decoration: none; color: inherit; display: block; }
.pw-item:hover { border-color: var(--accent, #C98E1F); }
.pw-top { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; margin-bottom: .35rem; }
.pw-kind { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-muted, #5A6472); }
.pw-state { font-size: .7rem; font-weight: 700; padding: .1rem .5rem; border-radius: 100px; background: var(--bg-2, rgba(0,0,0,.05)); }
.pw-state.is-ok { background: rgba(22,163,74,.12); color: #15803d; } .pw-state.is-bad { background: rgba(220,38,38,.12); color: #b91c1c; }
.pw-state.is-warn { background: rgba(201,142,31,.15); color: #a8741a; }
.pw-title { font-weight: 700; font-size: .95rem; margin-bottom: .2rem; }
.pw-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .pw-grid { grid-template-columns: minmax(0, 1fr); } }
.pw-col { display: grid; gap: 1rem; }
.pw-dates { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .6rem; }
.pw-dates > div { display: grid; gap: .15rem; padding: .7rem; border: 1px solid var(--border-2, #E2E5EA); border-radius: 10px; }
.pw-dates span { font-size: .72rem; color: var(--fg-muted, #5A6472); } .pw-dates b { font-size: .88rem; }
.pw-dates .is-bad { border-color: rgba(220,38,38,.45); } .pw-dates .is-bad b { color: #b91c1c; }
.pw-desc { font-size: .85rem; margin: .9rem 0 0; line-height: 1.7; }
.pw-h2 { font-size: .95rem; font-weight: 800; margin: 0 0 .7rem; }
.pw-log { padding: .6rem 0; border-top: 1px solid var(--border-2, #E2E5EA); display: grid; gap: .2rem; }
.pw-log:first-of-type { border-top: 0; }
.pw-log-h { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; font-size: .82rem; }
.pw-log-h span[dir] { color: var(--fg-muted, #5A6472); font-size: .74rem; }
.pw-note { font-size: .84rem; line-height: 1.6; }
.pw-file { font-size: .8rem; }
.pw-form { display: grid; gap: .45rem; }
