/* Copyright (c) 2026 William Chesher */
/* SPDX-License-Identifier: MIT */
/* teeny-dropdown - sectioned, icon-aware, single/multi-select popover */

.teeny-dd {
  position: relative;
  display: inline-block;
  font: inherit;
  --teeny-dd-radius: 10px;
  --teeny-dd-radius-sm: 8px;
  --teeny-dd-row-h: 34px;
  --teeny-dd-pad-x: 12px;
  --teeny-dd-gap: 10px;
  --teeny-dd-fg: var(--text-primary, #e8ecf3);
  --teeny-dd-fg-muted: var(--text-secondary, #9aa4b8);
  --teeny-dd-bg: var(--bg-secondary, #1f2940);
  --teeny-dd-bg-hover: var(--bg-hover, rgba(255, 255, 255, 0.05));
  --teeny-dd-border: var(--border-light, rgba(255, 255, 255, 0.08));
  --teeny-dd-accent: var(--accent, #00d4ff);
  --teeny-dd-accent-bg: var(--accent-bg, rgba(0, 212, 255, 0.12));
  --teeny-dd-unity: var(--teeny-dd-accent);
  --teeny-dd-solo: var(--peach, #ff9f6b);
}

/* Trigger button -- mirrors a native <select> but rounded + iconic.
 * Element+class selector raises specificity above .toolbar button rules. */
button.teeny-dd__trigger,
.teeny-dd__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--teeny-dd-gap);
  width: auto;
  min-width: 220px;
  max-width: 320px;
  height: 32px;
  min-height: 32px;
  padding: 0 var(--teeny-dd-pad-x);
  background: var(--teeny-dd-bg);
  color: var(--teeny-dd-fg);
  border: 1px solid var(--teeny-dd-border);
  border-radius: var(--teeny-dd-radius-sm);
  cursor: pointer;
  font: inherit;
  font-size: 0.85rem;
  line-height: 1;
  text-align: left;
  box-shadow: none;
  transform: none;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

/* Scope overrides for the automate toolbar -- defeats the .toolbar button
 * forced circular-2rem-gradient rule and the .toolbar select pill style. */
.toolbar button.teeny-dd__trigger,
.toolbar .teeny-dd button.teeny-dd__trigger {
  width: auto;
  min-width: 220px;
  max-width: 320px;
  height: 32px;
  min-height: 32px;
  padding: 0 var(--teeny-dd-pad-x);
  border-radius: var(--teeny-dd-radius-sm);
  border: 1px solid var(--teeny-dd-border);
  background: var(--teeny-dd-bg);
  color: var(--teeny-dd-fg);
  box-shadow: none;
  flex-shrink: 1;
}
.toolbar button.teeny-dd__trigger:hover {
  transform: none;
  border-color: var(--teeny-dd-accent);
  background: var(--teeny-dd-bg-hover);
  box-shadow: none;
}
.toolbar button.teeny-dd__trigger svg {
  width: 14px;
  height: 14px;
}
.teeny-dd__trigger:hover {
  border-color: var(--teeny-dd-accent);
  background: var(--teeny-dd-bg-hover);
}
.teeny-dd__trigger:focus-visible {
  outline: none;
  border-color: var(--teeny-dd-accent);
  box-shadow: 0 0 0 3px var(--teeny-dd-accent-bg);
}
.teeny-dd[data-open="true"] .teeny-dd__trigger {
  border-color: var(--teeny-dd-accent);
  box-shadow: 0 0 0 3px var(--teeny-dd-accent-bg);
}

.teeny-dd__trigger-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  font-size: 14px;
  color: var(--teeny-dd-fg-muted);
  flex: 0 0 auto;
}
.teeny-dd__trigger-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.teeny-dd__trigger-label.is-placeholder {
  color: var(--teeny-dd-fg-muted);
}
.teeny-dd__trigger-caret {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  margin-left: 2px;
  color: var(--teeny-dd-fg-muted);
  transition: transform 160ms ease;
}
.teeny-dd[data-open="true"] .teeny-dd__trigger-caret {
  transform: rotate(180deg);
  color: var(--teeny-dd-accent);
}
.teeny-dd__trigger-count {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--teeny-dd-accent-bg);
  color: var(--teeny-dd-accent);
  font-size: 11px;
  font-weight: 600;
}

/* Popover */
.teeny-dd__pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  max-width: 360px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--teeny-dd-bg);
  border: 1px solid var(--teeny-dd-border);
  border-radius: var(--teeny-dd-radius);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.2),
    0 12px 32px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  z-index: 1000;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-4px) scale(0.99);
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
}
.teeny-dd[data-open="true"] .teeny-dd__pop {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Search */
.teeny-dd__search {
  flex: 0 0 auto;
  padding: 8px 8px 4px;
  border-bottom: 1px solid var(--teeny-dd-border);
}
.teeny-dd__search input {
  width: 100%;
  height: 28px;
  padding: 0 10px;
  background: var(--bg-tertiary, rgba(255, 255, 255, 0.04));
  color: var(--teeny-dd-fg);
  border: 1px solid var(--teeny-dd-border);
  border-radius: 6px;
  font: inherit;
  outline: none;
  transition: border-color 120ms ease;
}
.teeny-dd__search input::placeholder { color: var(--teeny-dd-fg-muted); }
.teeny-dd__search input:focus { border-color: var(--teeny-dd-accent); }

/* Scrollable list */
.teeny-dd__list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 6px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--teeny-dd-border) transparent;
}
.teeny-dd__list::-webkit-scrollbar { width: 8px; }
.teeny-dd__list::-webkit-scrollbar-thumb {
  background: var(--teeny-dd-border);
  border-radius: 4px;
}

/* Sections */
.teeny-dd__section + .teeny-dd__section {
  margin-top: 4px;
  border-top: 1px solid var(--teeny-dd-border);
  padding-top: 4px;
}
.teeny-dd__section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px var(--teeny-dd-pad-x) 4px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teeny-dd-fg-muted);
  user-select: none;
}
.teeny-dd__section-header::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--section-accent, var(--teeny-dd-fg-muted));
  box-shadow: 0 0 8px var(--section-accent, transparent);
}
.teeny-dd__section-header-count {
  margin-left: auto;
  font-weight: 500;
  color: var(--teeny-dd-fg-muted);
  opacity: 0.7;
}

/* Section visual variants -- distinct treatment, same shape */
.teeny-dd__section[data-variant="unity"] {
  --section-accent: var(--teeny-dd-unity);
}
.teeny-dd__section[data-variant="solo"] {
  --section-accent: var(--teeny-dd-solo);
  background: linear-gradient(
    180deg,
    rgba(255, 159, 107, 0.025) 0%,
    transparent 100%
  );
}

/* Row */
.teeny-dd__row {
  display: flex;
  align-items: center;
  gap: var(--teeny-dd-gap);
  min-height: var(--teeny-dd-row-h);
  padding: 0 var(--teeny-dd-pad-x);
  cursor: pointer;
  color: var(--teeny-dd-fg);
  position: relative;
  user-select: none;
  transition: background 100ms ease, color 100ms ease;
}
.teeny-dd__row::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 2px;
  border-radius: 0 2px 2px 0;
  background: var(--section-accent, transparent);
  opacity: 0;
  transition: opacity 120ms ease;
}
.teeny-dd__row:hover,
.teeny-dd__row.is-focus {
  background: var(--teeny-dd-bg-hover);
}
.teeny-dd__row:hover::before,
.teeny-dd__row.is-focus::before {
  opacity: 0.5;
}
.teeny-dd__row.is-selected {
  background: var(--accent-bg, rgba(0, 212, 255, 0.08));
  color: var(--section-accent, var(--teeny-dd-accent));
}
.teeny-dd__row.is-selected::before { opacity: 1; }
.teeny-dd__row.is-hidden { display: none; }

.teeny-dd__row-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  font-size: 14px;
  color: var(--teeny-dd-fg-muted);
  flex: 0 0 auto;
}
.teeny-dd__row.is-selected .teeny-dd__row-icon {
  color: var(--section-accent, var(--teeny-dd-accent));
}
.teeny-dd__row-label {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.teeny-dd__row-meta {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--teeny-dd-fg-muted);
  opacity: 0.7;
}
.teeny-dd__row-check {
  flex: 0 0 auto;
  width: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--section-accent, var(--teeny-dd-accent));
  opacity: 0;
  transition: opacity 120ms ease;
}
.teeny-dd__row.is-selected .teeny-dd__row-check { opacity: 1; }

/* Multi-select checkbox */
.teeny-dd__row-checkbox {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1.5px solid var(--teeny-dd-border);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 120ms ease, background 120ms ease;
}
.teeny-dd__row.is-selected .teeny-dd__row-checkbox {
  border-color: var(--section-accent, var(--teeny-dd-accent));
  background: var(--section-accent, var(--teeny-dd-accent));
}
.teeny-dd__row-checkbox::after {
  content: "";
  width: 8px;
  height: 4px;
  border-left: 2px solid var(--teeny-dd-bg);
  border-bottom: 2px solid var(--teeny-dd-bg);
  transform: rotate(-45deg) translateY(-1px);
  opacity: 0;
  transition: opacity 100ms ease;
}
.teeny-dd__row.is-selected .teeny-dd__row-checkbox::after { opacity: 1; }

/* Empty state */
.teeny-dd__empty {
  padding: 18px var(--teeny-dd-pad-x);
  text-align: center;
  color: var(--teeny-dd-fg-muted);
  font-size: 12.5px;
}

/* Footer (multi-select actions) */
.teeny-dd__footer {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  border-top: 1px solid var(--teeny-dd-border);
  background: var(--bg-tertiary, rgba(0, 0, 0, 0.15));
}
.teeny-dd__footer button {
  flex: 1;
  height: 26px;
  border: 1px solid var(--teeny-dd-border);
  border-radius: 6px;
  background: transparent;
  color: var(--teeny-dd-fg);
  cursor: pointer;
  font: inherit;
  font-size: 11.5px;
  transition: border-color 120ms ease, background 120ms ease;
}
.teeny-dd__footer button:hover {
  border-color: var(--teeny-dd-accent);
  background: var(--teeny-dd-bg-hover);
}

/* Light-theme adaptation -- the tokens already invert via shell.css. */
