/* ==========================================================================================
   Controls shared by the Signal and Tessera designs (components/signal-controls.js): the searchable select, the
   advanced multi-select and the search field with suggestions. Linked before css/design/signal.css and tessera.css (seo.py);
   each design sets the tokens it reads: --sg-fast, --sg-slow, --sg-glow, --sg-soft, --sg-soft-2, --sg-soft-text,
   --sg-pill, --hit (plus the theme tokens).
   ========================================================================================== */

/* the designs without a controls palette (Classic, Nexus, Atelier) read these: the administration uses the controls there */
:root:not([data-design="signal"]):not([data-design="tessera"]) {
  --sg-fast: 120ms;
  --sg-slow: 220ms;
  --sg-soft: color-mix(in srgb, var(--accent) 16%, transparent);
  --sg-soft-2: color-mix(in srgb, var(--accent) 26%, transparent);
  --sg-soft-text: color-mix(in srgb, var(--accent) 55%, var(--text));
  --sg-glow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
  --sg-pill: 999px;
}

:root:not([data-design="signal"]):not([data-design="tessera"]) :is(.sg-select-btn, .sg-multi-field, .sg-layer, .sg-ac-input) {
  border-radius: var(--radius);
}

/* searchable select: the trigger looks like a field, the list floats above everything */
.sg-select {
  position: relative;
  min-width: 0;
}

.sg-select-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--hit);
  padding: 0 12px 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: calc(14px * var(--font-scale));
  text-align: left;
  cursor: pointer;
  transition: border-color var(--sg-fast) var(--ease), box-shadow var(--sg-fast) var(--ease);
}

.sg-select-btn:hover {
  border-color: var(--border-strong);
}

.sg-select.is-open .sg-select-btn,
.sg-select-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--sg-glow);
}

.sg-select.is-disabled .sg-select-btn {
  opacity: 0.55;
  cursor: not-allowed;
}

.sg-select-btn > .icon:last-child {
  margin-left: auto;
  color: var(--text-faint);
  transition: transform var(--sg-slow) var(--ease);
}

.sg-select.is-open .sg-select-btn > .icon:last-child {
  transform: rotate(180deg);
}

/* the floating layer shared by all three controls */
.sg-layer {
  display: flex;
  flex-direction: column;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  animation: sg-pop var(--sg-fast, 120ms) var(--ease);
}

.sg-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text-faint);
}

.sg-search:focus-within {
  border-color: var(--accent);
  color: var(--accent-text);
}

.sg-search-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: calc(14px * var(--font-scale));
}

.sg-options {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
  overscroll-behavior: contain;
}

.sg-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: 9px;
  color: var(--text);
  font-size: calc(14px * var(--font-scale));
  cursor: pointer;
  user-select: none;
}

.sg-option.is-active,
.sg-option:hover {
  background: var(--surface-2);
}

.sg-option.is-selected {
  color: var(--accent-text);
  font-weight: 600;
}

.sg-check {
  display: grid;
  place-items: center;
  flex: none;
  width: 16px;
  color: var(--accent-text);
}

.sg-hint {
  margin-left: auto;
  color: var(--text-faint);
  font-size: calc(12px * var(--font-scale));
  white-space: nowrap;
}

.sg-hint-inline {
  color: var(--text-faint);
  font-weight: 400;
}

.sg-note {
  margin: 0;
  padding: 14px 10px;
  color: var(--text-muted);
  font-size: calc(13px * var(--font-scale));
  text-align: center;
}

.sg-link {
  padding: 2px 4px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--accent-text);
  font: inherit;
  font-size: calc(12.5px * var(--font-scale));
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

.sg-link:hover:not(:disabled) {
  text-decoration: underline;
}

.sg-link:disabled {
  color: var(--text-faint);
  cursor: default;
}

/* advanced multi-select: chips inside the field, facets and a counter in the layer */
.sg-multi {
  position: relative;
  min-width: 0;
}

.sg-multi-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: var(--hit);
  padding: 5px 8px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color var(--sg-fast) var(--ease), box-shadow var(--sg-fast) var(--ease);
}

.sg-multi-field:hover {
  border-color: var(--border-strong);
}

.sg-multi.is-open .sg-multi-field,
.sg-multi-field:focus-within {
  border-color: var(--accent);
  box-shadow: var(--sg-glow);
}

.sg-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 180px;
  height: 30px;
  padding: 0 4px 0 10px;
  border-radius: 8px;
  background: var(--sg-soft);
  color: var(--sg-soft-text);
  font-size: calc(13px * var(--font-scale));
  font-weight: 600;
}

.sg-chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sg-chip-x {
  display: grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: inherit;
  cursor: pointer;
}

.sg-chip-x:hover {
  background: var(--sg-soft-2);
}

.sg-multi-btn {
  display: flex;
  align-items: center;
  flex: 1 1 80px;
  gap: 6px;
  min-width: 0;
  min-height: 32px;
  padding: 0 4px 0 8px;
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: calc(14px * var(--font-scale));
  text-align: left;
  cursor: pointer;
}

.sg-multi-btn > .icon:last-child {
  margin-left: auto;
  color: var(--text-faint);
}

.sg-multi-btn:focus-visible {
  border-radius: 8px;
}

.sg-more {
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: calc(12.5px * var(--font-scale));
  font-weight: 600;
}

.sg-facets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
  padding: 0 2px;
}

.sg-facet {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: calc(12.5px * var(--font-scale));
  font-weight: 500;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms, color 120ms;
}

.sg-facet:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.sg-facet.is-on {
  border-color: transparent;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: color-mix(in srgb, var(--accent) 55%, var(--text));
  font-weight: 600;
}

.sg-multi-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px 6px;
  color: var(--text-faint);
  font-size: calc(12px * var(--font-scale));
}

.sg-option-check input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.sg-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--text-faint);
}

.sg-dot.is-ok { background: var(--ok); }
.sg-dot.is-warn { background: var(--warn); }
.sg-dot.is-err { background: var(--err); }

.sg-badge {
  flex: none;
  padding: 2px 7px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent-2, #f5b454) 16%, transparent);
  color: var(--accent-2, #f5b454);
  font-size: calc(11px * var(--font-scale));
  font-weight: 700;
}

.sg-multi-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sg-multi-foot .btn {
  min-height: 36px;
}

.sg-multi-foot .btn-primary {
  margin-left: auto;
}

/* search field with suggestions */
.sg-ac {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
}

.sg-ac > input {
  width: 100%;
}

.sg-ac > input::-webkit-search-cancel-button {
  display: none;
}

.sg-ac-clear {
  position: absolute;
  right: 6px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
}

.sg-ac-clear:hover {
  color: var(--text);
}

.searchbox .sg-ac > input {
  padding-right: 36px;
}

.sg-layer-ac {
  padding: 6px 6px 0;
}

.sg-group + .sg-group {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.sg-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 4px;
}

.sg-option-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.sg-option-ac.is-active .sg-option-icon {
  background: var(--accent);
  color: var(--accent-contrast);
}

.sg-option mark {
  background: none;
  color: var(--accent-text);
  font-weight: 700;
}

.sg-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px -6px 0;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-faint);
  font-size: calc(12px * var(--font-scale));
}

.sg-foot kbd {
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-muted);
  font: 600 calc(11px * var(--font-scale)) / 1.5 var(--font);
}

.sg-foot kbd:not(:first-child) {
  margin-left: 8px;
}

/* touch: no keyboard hints */
@media (hover: none) {
  .sg-foot {
    display: none;
  }

  .sg-option {
    min-height: 44px;
  }
}
