/* Collapse by the pane's own width (not the viewport) — the dashboard's main
   column can be much narrower than the window (sidebar + padding), the same
   gap layouts.css's #layoutRoot container query already covers. Without this,
   a window just above the 900px @media breakpoint below can still leave the
   Tags panel under ~250px, too narrow for its 3-column form — the flexible
   name-field column collapses to 0 width instead of wrapping the shell first. */
#taggingRoot { container-type: inline-size; }

.tagging-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
}
@container (max-width: 760px) {
  .tagging-shell { grid-template-columns: 1fr; }
}

.tagging-panel {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.tagging-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid #e2e8f0;
}

.tagging-panel-title {
  font-size: 15px;
  font-weight: 700;
}

.tagging-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.tagging-muted {
  color: #64748b;
  font-size: 12px;
}

.tagging-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px auto;
  align-items: end;
  gap: 10px;
  padding: 16px;
}

.tagging-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.tagging-label {
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.tagging-input,
.tagging-select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
}

.tagging-search-control {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: min(280px, 34vw);
}

.tagging-search-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 38px;
  flex: 0 0 auto;
  color: #64748b;
  line-height: 1;
}

.tagging-search-icon svg {
  width: 28px;
  height: 28px;
  display: block;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.tagging-search-input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
}

.tagging-color-field {
  min-width: 96px;
}

.tagging-color-picker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 38px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 5px 7px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.tagging-color-picker:hover {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb),  0.08);
}

.tagging-color-preview {
  width: 100%;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
  flex: 0 0 auto;
}

.tagging-color-text {
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.tagging-color-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.tagging-form-actions {
  display: flex;
  align-items: end;
}

.tagging-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 12px;
  background: #fff;
  color: #334155;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.tagging-btn:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.tagging-btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

.tagging-btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.tagging-btn-danger {
  color: #b91c1c;
  border-color: #fecaca;
}

.tagging-btn-danger:hover {
  background: #fef2f2;
  border-color: #fca5a5;
}

.tagging-list {
  display: grid;
  max-height: min(56vh, 560px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.tagging-list-divider {
  height: 1px;
  margin: 0 16px;
  background: linear-gradient(90deg, transparent, #cbd5e1 14%, #cbd5e1 86%, transparent);
}

.tagging-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
}

.tagging-row:last-child {
  border-bottom: 0;
}

/* The edit-row's Save button lives inside .tagging-form, which bottom-aligns
   itself (align-items:end) to its own label+input fields. Cancel lives in the
   sibling .tagging-row-actions, so without this override the outer .tagging-row's
   align-items:center would center it against the *whole* form's height instead
   of matching Save's bottom edge — the two buttons end up visibly offset. */
.tagging-row-editing {
  align-items: end;
}

.tagging-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tagging-swatch {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.14);
  flex: 0 0 auto;
}

.tagging-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  max-width: 100%;
}

.tagging-badge-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tagging-row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.tagging-assign-body {
  padding: 14px 16px;
}

.tagging-chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  max-height: min(44vh, 420px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.tagging-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  background: #fff;
  user-select: none;
}

.tagging-chip span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.tagging-chip input {
  margin: 0;
  flex: 0 0 auto;
}

.tagging-empty {
  padding: 28px 16px;
  text-align: center;
  color: #64748b;
  font-size: 13px;
}

@media (max-width: 900px) {
  .tagging-shell {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .tagging-form {
    grid-template-columns: 1fr;
  }

  .tagging-color-field {
    min-width: 0;
  }

  .tagging-form-actions {
    align-items: stretch;
  }

  .tagging-panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .tagging-head-actions {
    width: 100%;
    justify-content: stretch;
  }

  .tagging-search-control {
    min-width: 0;
    flex: 1;
  }

  .tagging-form-actions .tagging-btn {
    width: 100%;
  }

  .tagging-row {
    grid-template-columns: 1fr;
  }

  .tagging-row-actions {
    justify-content: flex-start;
  }
}
