/* ==========================================================================
   tag-set — Token Field: Interactive Pills & Integrated Text Input
   ========================================================================== */

tag-set {
  --tf-border: var(--border-subtle, #edebe6);
  --tf-border-focus: var(--accent, #4f46e5);
  --tf-pill-bg: rgba(79, 70, 229, 0.08);         /* Soft brand tint */
  --tf-pill-text: var(--accent, #4f46e5);       /* Brand indigo */
  --tf-pill-border: rgba(79, 70, 229, 0.2);
  --tf-radius: 10px;

  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 42px;
  padding: 6px 10px;
  border: 1px solid var(--tf-border);
  border-radius: var(--tf-radius);
  background: #fbfbfa;                          /* Warm subtle tray base */
  cursor: text;
  transition: all 0.15s ease;
}

tag-set *,
tag-set *::before,
tag-set *::after {
  box-sizing: border-box;
}

tag-set:hover {
  background: #ffffff;
  border-color: #ded9cf;
}

tag-set:focus-within {
  background: #ffffff;
  border-color: var(--tf-border-focus);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

/* Invalid State */
tag-set[data-invalid] {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

/* ==========================================================================
   Text Input
   ========================================================================== */

.tag-input {
  flex: 1 1 9ch;
  min-width: 9ch;
  margin: 0;
  padding: 4px 6px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-main, #16181b);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
}

.tag-input::placeholder {
  color: var(--text-muted, #8e98a0);
}

tag-set[data-full] .tag-input {
  display: none;
}

/* ==========================================================================
   Add Button (Appears conditionally via [data-has-text])
   ========================================================================== */

.tag-add {
  display: none;
  flex: 0 0 auto;
  min-height: 28px;
  padding: 3px 12px;
  border: 1px solid var(--tf-border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text-main, #16181b);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: all 0.15s ease;
}

tag-set[data-has-text] .tag-add {
  display: inline-flex;
  align-items: center;
}

.tag-add:hover {
  background: var(--tf-pill-bg);
  color: var(--tf-pill-text);
  border-color: var(--tf-pill-border);
}

.tag-add:active {
  transform: scale(0.97);
}

.tag-add:focus-visible {
  outline: 2px solid var(--tf-border-focus);
  outline-offset: 1px;
}

tag-set[data-full] .tag-add {
  display: none;
}

/* ==========================================================================
   Tag Pills
   ========================================================================== */

tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 3px 6px 3px 10px;
  border-radius: 8px;                           /* Modern subtle chip */
  background: var(--tf-pill-bg);
  border: 1px solid var(--tf-pill-border);
  color: var(--tf-pill-text);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  letter-spacing: -0.01em;
  transition: all 0.15s ease;
}

.tag-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Duplicate Shake Animation */
tag-pill[data-dupe] {
  animation: tf-shake 220ms ease-in-out;
  border-color: #ef4444;
  color: #ef4444;
}

@keyframes tf-shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* ==========================================================================
   Remove Control (×)
   ========================================================================== */

.tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: all 0.12s ease;
}

.tag-remove:hover {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.tag-remove:focus-visible {
  outline: 2px solid var(--tf-border-focus);
  outline-offset: 1px;
}

@media (hover: hover) and (pointer: fine) {
  .tag-remove {
    opacity: 0.6;
    transition: opacity 120ms ease, background-color 120ms ease;
  }
  tag-pill:hover .tag-remove,
  tag-pill:focus-within .tag-remove {
    opacity: 1;
  }
}

/* Screen reader helper */
.tag-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .tag-remove { transition: none; }
  tag-pill[data-dupe] { animation: none; }
  .tag-add:active { transform: none; }
}

/* Dark Scheme Override */
@media (prefers-color-scheme: dark) {
  tag-set {
    --tf-border: #30363d;
    --tf-pill-bg: rgba(79, 70, 229, 0.2);
    --tf-pill-border: rgba(79, 70, 229, 0.35);
    --tf-pill-text: #a5b4fc;
    background: #161b22;
  }
  tag-set:hover {
    background: #1c2128;
    border-color: #484f58;
  }
  .tag-add {
    background: #21262d;
    border-color: #30363d;
    color: #f0f6fc;
  }
  .tag-add:hover {
    background: rgba(79, 70, 229, 0.25);
  }
  .tag-input::placeholder {
    color: #6e7681;
  }
}