/**
 * Coachloket — Tom Select + Tagify theming (warme klei) + site-wide scrollbars.
 * Loaded AFTER vendor/libs/tom-select/tom-select.bootstrap5.min.css (and, on
 * backend pages, after vendor/libs/tagify/tagify.css) so it overrides the
 * vendor look. Goal: a Tom Select single-select visually indistinguishable
 * from Bootstrap's `.form-select` in this template, a dropdown panel in the
 * warm-clay house style, and Tagify tags in the same palette. Works in both
 * light and dark mode (in dark mode the template renders form inputs as a
 * light "paper" surface, so the controls mirror that; only the focus ring and
 * the selected/primary accents follow the theme primary — gold in dark).
 *
 * Colour reference (matches rl-theme.css form rendering):
 *   paper bg      #FFFFFF  (var --bs-paper-bg, identical in light & dark)
 *   text/heading  #2E241D
 *   body text     #5C4F43
 *   border        #E6D8C6
 *   mint / hover  #F7E8E1
 *   primary       var(--bs-primary)  (#C4593A light / #F5C98A dark)
 */

/* ---------------------------------------------------------------------------
 * 1. The closed control — mirror `.form-select`
 * The wrapper carries the select's `form-select` class, so core.css already
 * gives it the right height, padding and Bootstrap chevron. We pin the
 * warm-clay colours and the focus/hover states (a div never gets `:focus`,
 * Tom Select toggles `.focus`/`.dropdown-active` instead).
 * ------------------------------------------------------------------------- */
.ts-wrapper.form-select {
  color: #2e241d;
  background-color: #ffffff;
  border-color: #e6d8c6;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.ts-wrapper.form-select .ts-control {
  color: #2e241d;
  padding: 0.426rem 2.625rem 0.426rem 0.9375rem;
  font-size: 0.9375rem;
  line-height: 1.625;
}

.ts-wrapper.form-select .ts-control .item {
  color: #2e241d;
}

/* Placeholder text */
.ts-wrapper.form-select .ts-control input::placeholder {
  color: #a08d78;
}

/* Hover — same subtle primary-ish accent as `.form-select:hover` */
.ts-wrapper.form-select:hover:not(.disabled):not(.focus) {
  border-color: color-mix(in srgb, var(--bs-primary, #c4593a) 45%, #e6d8c6);
}

/* Focus / open — primary ring, matching `.form-select:focus` */
.ts-wrapper.form-select.focus,
.ts-wrapper.form-select.dropdown-active {
  border-color: var(--bs-primary, #c4593a) !important;
  box-shadow: 0 0 0 0.15rem rgba(var(--bs-primary-rgb, 196, 89, 58), 0.2);
  outline: 0;
}

/* Disabled */
.ts-wrapper.form-select.disabled,
.ts-wrapper.form-select.locked {
  background-color: color-mix(in srgb, #e6d8c6 30%, #ffffff);
  color: #a08d78;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
 * 2. The open dropdown panel + options — warm-clay
 * ------------------------------------------------------------------------- */
.ts-dropdown,
.ts-dropdown.form-control,
.ts-dropdown.form-select {
  background: #ffffff;
  border: 1px solid #e6d8c6;
  border-radius: var(--bs-border-radius, 0.375rem);
  box-shadow: 0 0.25rem 1rem rgba(46, 36, 29, 0.12);
  overflow: hidden;
}

.ts-dropdown .option {
  padding: 0.5rem 0.9375rem;
  font-size: 0.9375rem;
  color: #5c4f43;
}

/* Hover / keyboard-highlighted option — warm mint tint */
.ts-dropdown .active,
.ts-dropdown .option.active {
  background-color: #f7e8e1;
  color: #a54d34;
}

/* Currently selected option */
.ts-dropdown .option.selected,
.ts-dropdown .option[aria-selected='true'] {
  background-color: var(--bs-primary, #c4593a);
  color: var(--bs-primary-contrast, #ffffff);
}
.ts-dropdown .option.selected.active,
.ts-dropdown .option[aria-selected='true'].active {
  background-color: color-mix(in srgb, var(--bs-primary, #c4593a) 88%, #2e241d);
  color: var(--bs-primary-contrast, #ffffff);
}

/* Typed-match highlight inside option labels */
.ts-dropdown [data-selectable] .highlight {
  background: rgba(var(--bs-primary-rgb, 196, 89, 58), 0.18);
  border-radius: 2px;
}

/* Grouped option headers */
.ts-dropdown .optgroup-header {
  background: #ffffff;
  color: #8a7861;
  font-weight: 600;
  padding: 0.5rem 0.9375rem;
}

/* "No results" text */
.ts-dropdown .no-results {
  padding: 0.5rem 0.9375rem;
  color: #8a7861;
}

/* Perfect Scrollbar hooks onto the scrollable option list */
.ts-dropdown-content {
  position: relative;
}

/* ---------------------------------------------------------------------------
 * 3. Search field inside the panel (dropdown_input plugin, >= 8 options)
 * ------------------------------------------------------------------------- */
.plugin-dropdown_input .dropdown-input-wrap {
  padding: 0.5rem;
}
.plugin-dropdown_input .dropdown-input {
  padding: 0.4rem 0.75rem;
  font-size: 0.9375rem;
  color: #2e241d;
  background-color: #ffffff;
  border: 1px solid #e6d8c6;
  border-radius: var(--bs-border-radius-sm, 0.325rem);
  outline: 0;
}
.plugin-dropdown_input.focus .ts-dropdown .dropdown-input {
  border-color: var(--bs-primary, #c4593a);
  box-shadow: 0 0 0 0.15rem rgba(var(--bs-primary-rgb, 196, 89, 58), 0.2);
}

/* ---------------------------------------------------------------------------
 * 4. Dark-mode nuances
 * Form inputs stay a light paper surface in dark mode (see rl-theme.css), so
 * the paper colours above already fit. Only the primary accents follow the
 * dark primary (gold), which needs dark text for contrast.
 * ------------------------------------------------------------------------- */
html[data-bs-theme='dark'] .ts-wrapper.form-select {
  background-color: #ffffff;
  color: #2e241d;
}
html[data-bs-theme='dark'] .ts-dropdown {
  background: #ffffff;
  box-shadow: 0 0.25rem 1rem rgba(20, 8, 4, 0.35);
}
html[data-bs-theme='dark'] .ts-dropdown .option.selected,
html[data-bs-theme='dark'] .ts-dropdown .option[aria-selected='true'] {
  background-color: var(--bs-primary, #f5c98a);
  color: var(--bs-primary-contrast, #93402a);
}
html[data-bs-theme='dark'] .ts-dropdown .active,
html[data-bs-theme='dark'] .ts-dropdown .option.active {
  background-color: #f7e8e1;
  color: #a54d34;
}

/* ---------------------------------------------------------------------------
 * 5. Tagify (multi-value selects, backend/staff forms) — warm-clay
 * The <tags> element inherits `form-control`, so sizing/border come from the
 * template; here we pin the palette via Tagify's CSS variables.
 * ------------------------------------------------------------------------- */
.tagify.form-control {
  --tags-border-color: #e6d8c6;
  --tags-hover-border-color: color-mix(in srgb, var(--bs-primary, #c4593a) 45%, #e6d8c6);
  --tags-focus-border-color: var(--bs-primary, #c4593a);
  --tag-bg: #f7e8e1;
  --tag-hover: #f0d8cd;
  --tag-text-color: #a54d34;
  --tag-text-color--edit: #2e241d;
  --tag-remove-btn-color: #a54d34;
  --tag-remove-bg: #f0d8cd;
  --tag-remove-btn-bg--hover: #c4593a;
  --tag-pad: 0.25em 0.5em;
  --tag-border-radius: 4px;
  --placeholder-color: #a08d78;
  --placeholder-color-focus: #8a7861;
  --input-color: #2e241d;
  background-color: #ffffff;
  min-height: calc(1.625em + 0.852rem + 2px);
  padding: 0.15rem 0.35rem;
}

.tagify.form-control.tagify--focus {
  border-color: var(--bs-primary, #c4593a);
  box-shadow: 0 0 0 0.15rem rgba(var(--bs-primary-rgb, 196, 89, 58), 0.2);
}

/* Suggestions dropdown — same warm paper panel as Tom Select */
.tagify__dropdown {
  border: 1px solid #e6d8c6;
  border-radius: var(--bs-border-radius, 0.375rem);
  box-shadow: 0 0.25rem 1rem rgba(46, 36, 29, 0.12);
  overflow: hidden;
}
.tagify__dropdown__wrapper {
  background: #ffffff;
  border: none;
}
.tagify__dropdown__item {
  padding: 0.5rem 0.9375rem;
  font-size: 0.9375rem;
  color: #5c4f43;
  border-radius: 0;
  margin: 0;
}
.tagify__dropdown__item--active {
  background: #f7e8e1;
  color: #a54d34;
}

/* Dark mode: paper stays light, focus/selection follows dark primary (gold) */
html[data-bs-theme='dark'] .tagify.form-control {
  background-color: #ffffff;
}
html[data-bs-theme='dark'] .tagify__dropdown__wrapper {
  background: #ffffff;
}

/* ---------------------------------------------------------------------------
 * 6. Site-wide scrollbars — warm-clay
 * Perfect Scrollbar cannot run on the body, so the page scrollbar gets a
 * subtle custom look: thin, rounded, terracotta thumb on a paper track.
 * ------------------------------------------------------------------------- */
html {
  scrollbar-width: thin;
  scrollbar-color: rgba(196, 89, 58, 0.45) rgba(230, 216, 198, 0.35);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: rgba(230, 216, 198, 0.35);
}
*::-webkit-scrollbar-thumb {
  background-color: rgba(196, 89, 58, 0.45);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: rgba(196, 89, 58, 0.7);
}

html[data-bs-theme='dark'] {
  scrollbar-color: rgba(245, 201, 138, 0.4) rgba(46, 36, 29, 0.4);
}
html[data-bs-theme='dark'] *::-webkit-scrollbar-track {
  background: rgba(46, 36, 29, 0.4);
}
html[data-bs-theme='dark'] *::-webkit-scrollbar-thumb {
  background-color: rgba(245, 201, 138, 0.4);
}
html[data-bs-theme='dark'] *::-webkit-scrollbar-thumb:hover {
  background-color: rgba(245, 201, 138, 0.65);
}

/* Perfect Scrollbar rails in the same palette */
.ps__thumb-y,
.ps__thumb-x {
  background-color: rgba(196, 89, 58, 0.45);
}
.ps__rail-y:hover > .ps__thumb-y,
.ps__rail-y:focus > .ps__thumb-y,
.ps__rail-y.ps--clicking .ps__thumb-y,
.ps__rail-x:hover > .ps__thumb-x,
.ps__rail-x:focus > .ps__thumb-x,
.ps__rail-x.ps--clicking .ps__thumb-x {
  background-color: rgba(196, 89, 58, 0.7);
}
.ps .ps__rail-x:hover,
.ps .ps__rail-y:hover,
.ps .ps__rail-x:focus,
.ps .ps__rail-y:focus,
.ps .ps__rail-x.ps--clicking,
.ps .ps__rail-y.ps--clicking {
  background-color: rgba(230, 216, 198, 0.35);
}
