/* Katalisa Life OS — Listbox (kls-*)
 *
 * Custom select/listbox que substitui visualmente o <select> nativo
 * (a lista aberta do select nativo renderiza com chrome do SO — magenta no
 * macOS — e não segue o DS). Progressive enhancement: o <select> nativo
 * continua no DOM como fonte da verdade (form submit, HTMX, validação).
 *
 * Enhancement só no desktop (pointer fino). Em touch o JS pula e o nativo
 * segue (picker mobile otimizado). Ver static/js/listbox.js.
 *
 * Tokens DS: --bento-bg-card, --bento-border, --bento-shadow-slide,
 * --ds-text, --ds-text-muted, brand #912CEE, --ds-violet-ink (#A855F7).
 */

/* sr-only — esconde o <select> nativo SEM display:none (mantém validação
   nativa + autofill + acessível ao label `for=`). */
.kls-native {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.kls-wrap { position: relative; width: 100%; }

/* Botão — espelha o visual do <select> fechado do shell.css */
.kls-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  border-radius: var(--bento-radius, 0);
  border: 1px solid rgb(203 213 225);
  background: #fff;
  padding: 0.625rem 0.875rem;
  padding-right: 2.25rem;
  font-size: 0.9375rem;
  line-height: 1.4;
  color: inherit;
  cursor: pointer;
  position: relative;
  transition: border-color .15s, box-shadow .15s;
}
html.dark .kls-button {
  border-color: rgba(145, 44, 238, 0.25);
  background: #0F172A;
  color: rgba(238, 233, 191, 0.85);
}
.kls-button:hover { border-color: rgba(145, 44, 238, 0.55); }
.kls-button:focus-visible,
.kls-button[aria-expanded="true"] {
  outline: none;
  border-color: rgb(145 44 238);
  box-shadow: 0 0 0 3px rgb(145 44 238 / .18);
}
.kls-button[disabled],
.kls-button[aria-disabled="true"] {
  opacity: .55;
  cursor: not-allowed;
}
.kls-button.kls-invalid {
  border-color: #e11d48;
  box-shadow: 0 0 0 3px rgb(225 29 72 / .18);
}

.kls-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kls-value.kls-is-placeholder { color: var(--ds-text-muted); }

/* Seta — mesma do shell.css (chevron SVG), rotaciona ao abrir */
.kls-caret {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.125rem; height: 1.125rem;
  pointer-events: none;
  color: #64748b;
  transition: transform .15s;
}
html.dark .kls-caret { color: #94a3b8; }
.kls-button[aria-expanded="true"] .kls-caret { transform: translateY(-50%) rotate(180deg); }

/* Painel dropdown */
.kls-panel {
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 60;
  width: 100%;
  min-width: max-content;
  max-width: min(28rem, 92vw);
  max-height: 18rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bento-bg-card);
  border: 1px solid var(--bento-border);
  border-radius: var(--bento-radius, 0);
  box-shadow: var(--bento-shadow-slide);
}
.kls-panel--up {
  top: auto;
  bottom: calc(100% + 4px);
}
.kls-panel[hidden] { display: none; }

/* Busca (selects grandes) */
.kls-search-wrap {
  flex: 0 0 auto;
  padding: 0.5rem;
  border-bottom: 1px solid var(--bento-border);
  background: rgba(145, 44, 238, 0.04);
}
.kls-search {
  width: 100%;
  border-radius: var(--bento-radius, 0);
  border: 1px solid var(--bento-border);
  background: var(--bento-bg-card);
  color: var(--ds-text);
  padding: 0.375rem 0.625rem;
  font-size: 0.875rem;
  outline: none;
}
.kls-search:focus { border-color: rgb(145 44 238); }

.kls-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.25rem;
  list-style: none;
  margin: 0;
}

.kls-group-label {
  padding: 0.5rem 0.625rem 0.25rem;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ds-text-muted);
}

.kls-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.625rem;
  font-size: 0.9rem;
  color: var(--ds-text);
  border-radius: var(--bento-radius, 0);
  cursor: pointer;
  user-select: none;
}
.kls-option[hidden] { display: none; }
.kls-option:hover,
.kls-option.kls-active {
  background: rgba(145, 44, 238, 0.10);
}
html.light .kls-option:hover,
html.light .kls-option.kls-active {
  background: rgb(241 245 249);
}
.kls-option[aria-selected="true"] {
  background: rgba(145, 44, 238, 0.14);
  color: var(--ds-violet-ink);
  font-weight: 600;
}
.kls-option[aria-disabled="true"] {
  opacity: .45;
  cursor: not-allowed;
}
.kls-option .kls-check {
  flex: 0 0 auto;
  width: 1rem;
  font-size: 0.95rem;
  color: var(--ds-violet-ink);
  visibility: hidden;
}
.kls-option[aria-selected="true"] .kls-check { visibility: visible; }
.kls-option-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kls-empty {
  padding: 0.75rem 0.625rem;
  font-size: 0.85rem;
  color: var(--ds-text-muted);
  text-align: center;
}
