/* Tag chip rendering — used by the option editor preview and (Phase 4)
 * contact-side display + picker. Inline `style` carries per-option
 * color_bg / color_fg; this file owns shape, spacing, and the optional
 * expiry indicator.
 */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.625rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
}

.chip--tag {
  /* Background + color come from inline `style`. The 1px border in matching
   * background prevents jitter when an outline state appears (Phase 4).
   */
}

.chip__expires {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Segmented control (used for tag-field Mode toggle).
 * Two-button radio group rendered as a single-row pill.
 */
.segmented-control {
  display: inline-flex;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small, 4px);
  overflow: hidden;
}

.segmented-control__item {
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  background: transparent;
  border-right: 1px solid var(--md-sys-color-outline-variant);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.segmented-control__item:last-child {
  border-right: none;
}

.segmented-control__item.is-selected {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.segmented-control__item input[type="radio"] {
  /* Hide native radio — the label wrapper handles the click target. */
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.option-editor {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.option-row {
  background: var(--md-sys-color-surface-container-low, transparent);
}

/* Tag cell — read-only chip strip inside a lens-sections cell. */
.tag-cell__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

/* Tag cell anchor — host for the chip strip + floating popover slot. */
.tag-cell-anchor {
  position: relative;
}

.tag-popover-slot {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 50;
}

.tag-popover-slot:empty {
  display: none;
}

/* Tag picker — floats over the cell. Width capped so it stays readable
 * regardless of how narrow the cell is. */
.tag-picker {
  min-width: 240px;
  max-width: 360px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small, 4px);
  box-shadow: var(--md-sys-elevation-level2);
  padding: 0.5rem;
  margin-top: 0.25rem;
}

.tag-picker__done {
  background: transparent;
  border: none;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.25rem 0.5rem;
}

.tag-picker__done:hover {
  text-decoration: underline;
}

.tag-picker__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.tag-picker__hint {
  font-size: 0.75rem;
  margin-left: auto;
}

.tag-picker__list {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  max-height: 280px;
  overflow-y: auto;
}

.tag-picker__form {
  display: block;
  margin: 0;
}

.tag-picker__row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.375rem 0.5rem;
  background: transparent;
  border: none;
  border-radius: var(--md-sys-shape-corner-small, 4px);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--md-sys-color-on-surface);
}

.tag-picker__row:hover {
  background: var(--md-sys-color-surface-container-highest);
}

.tag-picker__row.is-selected {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.tag-picker__check {
  font-size: 18px;
  color: var(--md-sys-color-primary);
}

.tag-picker__check-placeholder {
  display: inline-block;
  width: 18px;
  height: 18px;
}

.tag-picker__expires {
  margin-left: auto;
  font-size: 0.85rem;
}

/* Sidebar tag options block. The outer container is NOT a flex row because
 * the builder-props__row default would lay the header + pill list
 * side-by-side and squish everything. Stack vertically instead. */
.builder-props__block {
  display: block;
  margin-top: 0.75rem;
}

.bp-tag-block {
  font-size: var(--md-sys-typescale-label-medium-size);
}

.bp-tag-options-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.bp-tag-options-title {
  color: var(--md-sys-color-on-surface-variant);
}

.bp-tag-add-link {
  background: none;
  border: none;
  color: var(--md-sys-color-primary);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}

.bp-tag-add-link:hover {
  text-decoration: underline;
}

.bp-tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.bp-tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  color: #FFF;
  background: var(--md-sys-color-primary);
}

.bp-tag-pill--ghost {
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  border: 1px dashed var(--md-sys-color-outline-variant);
}

.bp-tag-pill__edit {
  font-size: 14px;
  opacity: 0.7;
}

.bp-tag-pill:hover .bp-tag-pill__edit {
  opacity: 1;
}

.bp-tag-mode-block {
  margin-top: 0.75rem;
}

.bp-tag-mode-label {
  font-size: var(--md-sys-typescale-label-medium-size);
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 0.35rem;
}

.bp-tag-mode {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small, 4px);
  overflow: hidden;
  background: var(--md-sys-color-surface-container-low, transparent);
}

.bp-tag-mode label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
}

.bp-tag-mode label:last-child {
  border-bottom: none;
}

.bp-tag-mode label:has(input:checked) {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.bp-tag-mode input[type="radio"] {
  margin: 0;
  accent-color: var(--md-sys-color-primary);
}

/* Single-option editor modal — calm one-option-at-a-time surface.
 * Override .modal-panel's fixed 640px height — this modal sizes to content. */
.tag-option-modal {
  width: min(480px, 92vw);
  height: auto;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tagopt-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.25rem 0;
}

.tagopt-label-input {
  width: 100%;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small, 4px);
  font-size: 0.9rem;
  font-family: inherit;
}

.tagopt-preview-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tagopt-color-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.tagopt-color-row:last-child {
  margin-bottom: 0;
}

.tagopt-color-label {
  font-size: 0.85rem;
  width: 24px;
  color: var(--md-sys-color-on-surface-variant);
}

.tagopt-swatches {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.tagopt-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--md-sys-color-outline-variant);
  cursor: pointer;
  padding: 0;
}

.tagopt-swatch.is-selected {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

.tagopt-expire-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tagopt-expire-row input[type="number"],
.tagopt-expire-row select {
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small, 4px);
  font-size: 0.875rem;
}

.tagopt-expire-row input:disabled,
.tagopt-expire-row select:disabled {
  opacity: 0.5;
}

.tagopt-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--md-sys-color-outline-variant);
  margin-top: 0.5rem;
}

.tagopt-footer__primary {
  display: inline-flex;
  gap: 0.5rem;
}

.tagopt-delete {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: transparent;
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-error);
  padding: 0.45rem 0.7rem;
  border-radius: var(--md-sys-shape-corner-small, 4px);
  font-size: 0.85rem;
  cursor: pointer;
}

.tagopt-delete:hover {
  background: var(--md-sys-color-error-container);
}

/* Bulk new-contact form tag dropdown. Selected chips render inline; an
 * "Add tag" trigger opens a menu of unselected options. */
.tag-dropdown {
  position: relative;
}

.tag-dropdown__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  min-height: 2rem;
}

.tag-dropdown__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.tag-dropdown__remove {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 0.1rem;
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.7;
}

.tag-dropdown__remove:hover {
  opacity: 1;
}

.tag-dropdown__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.625rem;
  border: 1px dashed var(--md-sys-color-outline);
  border-radius: 999px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.8125rem;
  cursor: pointer;
}

.tag-dropdown__trigger:hover {
  background: var(--md-sys-color-surface-container);
  border-style: solid;
}

.tag-dropdown__menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: 50;
  min-width: 200px;
  max-width: 320px;
  max-height: 280px;
  overflow-y: auto;
  padding: 0.4rem;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small, 4px);
  box-shadow: var(--md-sys-elevation-level2);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tag-dropdown__item {
  background: transparent;
  border: none;
  padding: 0.25rem;
  text-align: left;
  cursor: pointer;
  border-radius: var(--md-sys-shape-corner-small, 4px);
}

.tag-dropdown__item:hover {
  background: var(--md-sys-color-surface-container-highest);
}

[x-cloak] { display: none !important; }

/* Filter panel tag picker — single-row layout: chip preview, dropdown,
 * optional date range. Wraps to a second row on narrow viewports. */
.tag-filter {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag-filter__selected {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.tag-filter__remove {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 0.1rem;
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.7;
}

.tag-filter__remove:hover {
  opacity: 1;
}

/* Higher specificity to beat .field-input__date's width: 100% rule
 * which would otherwise stretch the date inputs across the value cell. */
.tag-filter .tag-filter__date {
  width: 140px;
  min-width: 0;
  flex: 0 0 auto;
}

/* Tag select — custom popover trigger styled as the selected chip. */
.tag-select {
  position: relative;
  flex: 0 0 auto;
}

.tag-select__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  min-width: 140px;
}

.tag-select__trigger.is-empty {
  border-style: dashed;
  color: var(--md-sys-color-on-surface-variant);
}

.tag-select__trigger:not(.is-empty) {
  border-color: transparent;
  font-weight: 500;
}

.tag-select__menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: 60;
  min-width: 200px;
  max-height: 280px;
  overflow-y: auto;
  padding: 0.35rem;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small, 4px);
  box-shadow: var(--md-sys-elevation-level2);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.tag-select__item {
  background: transparent;
  border: none;
  padding: 0.3rem;
  text-align: left;
  cursor: pointer;
  border-radius: var(--md-sys-shape-corner-small, 4px);
}

.tag-select__item:hover {
  background: var(--md-sys-color-surface-container-highest);
}

.tag-select__item--clear {
  font-size: 0.8125rem;
  padding: 0.4rem 0.5rem;
}

