/**
 * Healthwise Allergen Widget Styles
 * 
 * Minimal, accessible styling that works well in any context.
 * Uses CSS custom properties for easy customization.
 */

:root {
  --cw-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --cw-font-size: 14px;
  --cw-border-radius: 8px;
  
  --cw-color-ok: #22c55e;
  --cw-color-ok-bg: #f0fdf4;
  --cw-color-warn: #f59e0b;
  --cw-color-warn-bg: #fffbeb;
  --cw-color-bad: #ef4444;
  --cw-color-bad-bg: #fef2f2;
  --cw-color-free: #0ea5e9;
  --cw-color-free-bg: #f0f9ff;
  --cw-color-neutral: #6b7280;
  --cw-color-neutral-bg: #f9fafb;
  
  --cw-color-text: #1f2937;
  --cw-color-text-muted: #6b7280;
  --cw-color-border: #e5e7eb;
  --cw-color-bg: #ffffff;
}

/* Base widget container */
.cw-widget {
  font-family: var(--cw-font-family);
  font-size: var(--cw-font-size);
  color: var(--cw-color-text);
  background: var(--cw-color-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: var(--cw-border-radius);
  overflow: hidden;
  max-width: 400px;
}

/* Summary bar */
.cw-summary {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s;
}

.cw-summary:hover {
  background-color: rgba(0, 0, 0, 0.02);
}

/* Inline mode: summary is informational, not interactive */
.cw-inline .cw-summary {
  cursor: default;
}

.cw-inline .cw-summary:hover {
  background-color: transparent;
}

.cw-icon {
  font-size: 18px;
  margin-right: 10px;
  line-height: 1;
}

.cw-text {
  flex: 1;
  font-weight: 500;
}

.cw-toggle {
  font-size: 12px;
  color: var(--cw-color-text-muted);
  transition: transform 0.2s;
}

.cw-expanded .cw-toggle {
  transform: rotate(180deg);
}

/* Status-specific colors */
.cw-status-ok .cw-summary {
  background-color: var(--cw-color-ok-bg);
  border-bottom: 1px solid var(--cw-color-ok);
}

.cw-status-ok .cw-icon,
.cw-status-ok .cw-text {
  color: var(--cw-color-ok);
}

.cw-status-warn .cw-summary {
  background-color: var(--cw-color-warn-bg);
  border-bottom: 1px solid var(--cw-color-warn);
}

.cw-status-warn .cw-icon,
.cw-status-warn .cw-text {
  color: var(--cw-color-warn);
}

.cw-status-bad .cw-summary {
  background-color: var(--cw-color-bad-bg);
  border-bottom: 1px solid var(--cw-color-bad);
}

.cw-status-bad .cw-icon,
.cw-status-bad .cw-text {
  color: var(--cw-color-bad);
}

/* Details section */
.cw-details {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.cw-expanded .cw-details {
  max-height: 500px;
  overflow-y: auto;
}

.cw-product-info {
  padding: 12px 16px;
  background: var(--cw-color-neutral-bg);
  border-bottom: 1px solid var(--cw-color-border);
}

.cw-brand {
  color: var(--cw-color-text-muted);
}

/* Sections */
.cw-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--cw-color-border);
}

.cw-section:last-of-type {
  border-bottom: none;
}

.cw-section-title {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.cw-section.cw-bad .cw-section-title { color: var(--cw-color-bad); }
.cw-section.cw-warn .cw-section-title { color: var(--cw-color-warn); }
.cw-section.cw-free .cw-section-title { color: var(--cw-color-free); }
.cw-section.cw-ok .cw-section-title { color: var(--cw-color-ok); }

/* Match list */
.cw-match-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.cw-match {
  padding: 4px 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px;
}

.cw-ingredient {
  font-weight: 500;
}

.cw-match-free .cw-ingredient {
  color: var(--cw-color-free);
}

.cw-terms {
  font-size: 12px;
  color: var(--cw-color-text-muted);
}

/* Empty state */
.cw-empty {
  padding: 16px;
  text-align: center;
  color: var(--cw-color-text-muted);
}

/* CTA section */
.cw-cta {
  padding: 12px 16px;
  background: var(--cw-color-neutral-bg);
  text-align: center;
}

.cw-profile-btn {
  display: inline-block;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: #3b82f6;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.cw-profile-btn:hover {
  background: #2563eb;
}

/* Loading state */
.cw-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 12px;
  color: var(--cw-color-text-muted);
}

.cw-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--cw-color-border);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: cw-spin 0.8s linear infinite;
}

@keyframes cw-spin {
  to { transform: rotate(360deg); }
}

/* Error state */
.cw-error {
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 10px;
  background: var(--cw-color-bad-bg);
  color: var(--cw-color-bad);
}

/* Profile Editor */
.cw-profile-editor {
  background: var(--cw-color-bg);
}

.cw-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--cw-color-neutral-bg);
  border-bottom: 1px solid var(--cw-color-border);
}

.cw-editor-title {
  font-weight: 600;
  font-size: 15px;
}

.cw-close-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--cw-color-text-muted);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.cw-close-btn:hover {
  color: var(--cw-color-text);
}

.cw-editor-body {
  padding: 16px;
}

.cw-editor-body.cw-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 150px;
  color: var(--cw-color-text-muted);
}

/* Breadcrumb navigation */
.cw-breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--cw-color-neutral-bg);
  border-radius: 6px;
  font-size: 13px;
}

.cw-breadcrumb-item {
  color: #3b82f6;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}

.cw-breadcrumb-item:hover {
  background: rgba(59, 130, 246, 0.1);
  text-decoration: underline;
}

.cw-breadcrumb-sep {
  color: var(--cw-color-text-muted);
}

/* Bulk action buttons */
.cw-bulk-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.cw-bulk-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--cw-color-text);
  background: var(--cw-color-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.cw-bulk-btn:hover {
  background: var(--cw-color-neutral-bg);
  border-color: var(--cw-color-text-muted);
}

/* Selection count */
.cw-selection-count {
  font-size: 12px;
  font-weight: normal;
  color: var(--cw-color-text-muted);
  margin-left: 8px;
}

.cw-editor-hint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--cw-color-text-muted);
}

.cw-allergen-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.cw-allergen-option {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  gap: 8px;
}

.cw-allergen-option:hover {
  background: var(--cw-color-neutral-bg);
}

.cw-allergen-option.cw-selected {
  background: var(--cw-color-bad-bg);
  border-color: var(--cw-color-bad);
}

.cw-allergen-option input {
  display: none;
}

/* ── Unified node list (tree editor) ── */
.cw-node-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cw-node-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--cw-color-border);
  border-radius: 8px;
  transition: all 0.15s;
}

.cw-node-row.cw-selected {
  background: var(--cw-color-bad-bg);
  border-color: var(--cw-color-bad);
}

/* +/− toggle button */
.cw-node-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border: 1.5px solid var(--cw-color-border);
  border-radius: 50%;
  background: #fff;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
  color: var(--cw-color-text-muted);
}

.cw-node-toggle.cw-toggle-add {
  color: var(--cw-color-ok);
  border-color: var(--cw-color-ok);
}

.cw-node-toggle.cw-toggle-add:hover {
  background: var(--cw-color-ok-bg);
}

.cw-node-toggle.cw-toggle-remove {
  color: var(--cw-color-bad);
  border-color: var(--cw-color-bad);
  background: var(--cw-color-bad-bg);
}

.cw-node-toggle.cw-toggle-remove:hover {
  background: #fca5a5;
}

/* Node name */
.cw-node-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

/* › navigation button (drill into children) */
.cw-node-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  background: var(--cw-color-neutral-bg);
  font-size: 16px;
  font-weight: bold;
  color: var(--cw-color-text-muted);
  cursor: pointer;
  transition: all 0.15s;
  padding: 0;
}

.cw-node-nav:hover {
  background: #e5e7eb;
  color: var(--cw-color-text);
}

.cw-allergen-icon {
  font-size: 16px;
  line-height: 1;
}

.cw-allergen-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.cw-has-children {
  font-size: 11px;
  color: var(--cw-color-text-muted);
  background: var(--cw-color-neutral-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.cw-editor-footer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--cw-color-neutral-bg);
  border-top: 1px solid var(--cw-color-border);
}

.cw-cancel-btn {
  flex: 1;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--cw-color-text);
  background: var(--cw-color-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.cw-cancel-btn:hover {
  background: var(--cw-color-neutral-bg);
}

.cw-save-btn {
  flex: 1;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: #3b82f6;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.cw-save-btn:hover {
  background: #2563eb;
}

.cw-save-btn:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

/* List view (current preferences) + Add allergens */
.cw-editor-list-view .cw-pref-list {
  padding: 8px 0;
  max-height: 240px;
  overflow-y: auto;
}

.cw-pref-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  gap: 8px;
  border-bottom: 1px solid var(--cw-color-border);
}

.cw-pref-list-item:last-child {
  border-bottom: none;
}

.cw-pref-name {
  flex: 1;
  font-size: 14px;
}

.cw-pref-remove {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: var(--cw-color-text-muted);
  background: var(--cw-color-neutral-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.cw-pref-remove:hover {
  color: var(--cw-color-bad);
  background: var(--cw-color-bad-bg);
}

.cw-add-allergens-btn {
  display: block;
  width: 100%;
  margin: 12px 0 0;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #3b82f6;
  background: var(--cw-color-neutral-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s;
  box-sizing: border-box;
}

.cw-add-allergens-btn:hover {
  background: #eff6ff;
}

.cw-back-btn {
  margin-right: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--cw-color-text-muted);
  background: transparent;
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s;
}

.cw-back-btn:hover {
  background: var(--cw-color-neutral-bg);
  color: var(--cw-color-text);
}

/* =========================================================================
   Trigger mode: shield button
   ========================================================================= */

.cw-trigger-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid var(--cw-color-border);
  border-radius: 50%;
  background: var(--cw-color-bg);
  cursor: pointer;
  color: var(--cw-color-text-muted);
  transition: border-color 0.2s, color 0.2s, box-shadow 0.2s;
}

.cw-trigger-btn svg {
  width: 24px;
  height: 24px;
}

.cw-trigger-btn:hover {
  box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.15);
}

/* Status-coloured ring on trigger button */
.cw-trigger-btn.cw-status-ok {
  border-color: var(--cw-color-ok);
  color: var(--cw-color-ok);
}

.cw-trigger-btn.cw-status-ok:hover {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.cw-trigger-btn.cw-status-warn {
  border-color: var(--cw-color-warn);
  color: var(--cw-color-warn);
}

.cw-trigger-btn.cw-status-warn:hover {
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.cw-trigger-btn.cw-status-bad {
  border-color: var(--cw-color-bad);
  color: var(--cw-color-bad);
}

.cw-trigger-btn.cw-status-bad:hover {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* Loading pulse animation for trigger button */
.cw-trigger-btn.cw-trigger-loading {
  animation: cw-trigger-pulse 1.2s ease-in-out infinite;
}

@keyframes cw-trigger-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* =========================================================================
   Trigger mode: modal overlay
   ========================================================================= */

.cw-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  animation: cw-overlay-fadein 0.2s ease-out;
}

@keyframes cw-overlay-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.cw-modal-panel {
  background: var(--cw-color-bg);
  border-radius: var(--cw-border-radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  animation: cw-panel-slidein 0.25s ease-out;
}

@keyframes cw-panel-slidein {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.cw-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--cw-color-border);
  flex-shrink: 0;
}

.cw-modal-title {
  font-family: var(--cw-font-family);
  font-size: 16px;
  font-weight: 600;
  color: var(--cw-color-text);
}

.cw-modal-close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--cw-color-text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.15s;
}

.cw-modal-close:hover {
  background: var(--cw-color-neutral-bg);
  color: var(--cw-color-text);
}

.cw-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Widget inside modal doesn't need max-width constraint */
.cw-modal-body .cw-widget {
  max-width: none;
}

/* ----- Recommendations section ----- */

.cw-recommendations {
  margin-top: 8px;
  border-top: 1px solid var(--cw-color-neutral-border, #e5e7eb);
  padding-top: 8px;
}

.cw-rec-list {
  list-style: none;
  margin: 4px 0 0 0;
  padding: 0;
}

.cw-rec-item {
  margin-bottom: 6px;
}

.cw-rec-link,
.cw-rec-btn {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border: 1px solid var(--cw-color-ok-border, #a7f3d0);
  border-radius: 6px;
  background: var(--cw-color-ok-bg, #ecfdf5);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.cw-rec-link:hover,
.cw-rec-btn:hover {
  border-color: var(--cw-color-ok-text, #065f46);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.cw-rec-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--cw-color-text, #1f2937);
}

.cw-rec-brand {
  font-size: 12px;
  color: var(--cw-color-text-muted, #6b7280);
}

.cw-rec-freefrom {
  font-size: 12px;
  color: var(--cw-color-ok-text, #065f46);
}

/* Responsive adjustments */
@media (max-width: 480px) {
  .cw-widget {
    max-width: 100%;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  
  .cw-allergen-grid {
    grid-template-columns: 1fr;
  }

  .cw-modal-panel {
    width: 100%;
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .cw-modal-overlay {
    align-items: flex-end;
  }
}

/* ----- Strategy Comparison section ----- */

/* Strategy override mode: tint the summary bar */
.cw-widget.cw-strategy-active .cw-summary {
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border-color: #93c5fd;
}

.cw-comparison {
  margin-top: 8px;
  border-top: 1px solid var(--cw-color-border, #e5e7eb);
}

.cw-comparison-toggle {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #6b7280;
}

.cw-comparison-toggle:hover {
  color: #374151;
}

.cw-toggle-arrow {
  font-size: 10px;
  transition: transform 0.2s;
}

.cw-comparison-summary {
  font-size: 12px;
  padding: 4px 0 8px;
  color: #6b7280;
}

.cw-comparison-error {
  color: var(--cw-color-bad, #dc2626);
  font-size: 12px;
  padding: 4px 0;
}

.cw-raw-text {
  margin-bottom: 8px;
}

.cw-raw-text summary {
  font-size: 12px;
  color: #6b7280;
  cursor: pointer;
}

.cw-raw-text pre {
  font-size: 11px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 8px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  margin-top: 4px;
}

.cw-diff-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.cw-diff-table th {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
  color: #374151;
}

.cw-diff-table td {
  padding: 3px 8px;
  border-bottom: 1px solid #f3f4f6;
}

.cw-diff-improvement td {
  background: #f0fdf4;
  color: #166534;
}

.cw-diff-regression td {
  background: #fef2f2;
  color: #991b1b;
}

.cw-diff-same td {
  color: #9ca3af;
}

/* =========================================================================
   Editor tabs (Groups / Ingredients)
   ========================================================================= */

.cw-editor-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-bottom: 2px solid var(--cw-color-border);
}

.cw-editor-tab {
  flex: 1;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--cw-color-text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  text-align: center;
}

.cw-editor-tab:hover {
  color: var(--cw-color-text);
}

.cw-editor-tab.active {
  color: #3b82f6;
  border-bottom-color: #3b82f6;
  font-weight: 600;
}

.cw-editor-description {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--cw-color-text-muted);
  line-height: 1.4;
}

/* =========================================================================
   Group selection grid
   ========================================================================= */

.cw-group-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.cw-group-option {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  gap: 8px;
}

.cw-group-option:hover {
  background: var(--cw-color-neutral-bg);
  border-color: var(--cw-color-text-muted);
}

.cw-group-option.cw-selected {
  background: var(--cw-color-bad-bg);
  border-color: var(--cw-color-bad);
}

.cw-group-option input {
  display: none;
}

.cw-group-icon {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.cw-group-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.cw-group-count {
  font-size: 11px;
  color: var(--cw-color-text-muted);
  background: var(--cw-color-neutral-bg);
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

/* =========================================================================
   Group attribution tags on match results
   ========================================================================= */

.cw-match-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.cw-match-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.cw-group-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--cw-color-text-muted);
  background: var(--cw-color-neutral-bg);
  border: 1px solid var(--cw-color-border);
  padding: 1px 6px;
  border-radius: 10px;
  white-space: nowrap;
}

/* =========================================================================
   Quick-add button and popover
   ========================================================================= */

.cw-quick-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  margin-left: auto;
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  color: var(--cw-color-text-muted);
  background: var(--cw-color-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.cw-quick-add-btn:hover {
  color: #3b82f6;
  border-color: #3b82f6;
  background: #eff6ff;
}

.cw-quick-add-btn.cw-added {
  color: var(--cw-color-ok);
  border-color: var(--cw-color-ok);
  background: var(--cw-color-ok-bg);
  cursor: default;
  font-size: 12px;
}

.cw-quick-add-btn.cw-adding {
  opacity: 0.6;
  cursor: wait;
}

/* Quick-add popover */
.cw-quick-add-popover {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 100;
  background: var(--cw-color-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 10px;
  min-width: 180px;
  animation: cw-popover-fadein 0.15s ease-out;
}

@keyframes cw-popover-fadein {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cw-popover-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--cw-color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.cw-popover-chips {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cw-target-chip {
  display: block;
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--cw-color-text);
  background: var(--cw-color-neutral-bg);
  border: 1px solid var(--cw-color-border);
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.cw-target-chip:hover {
  background: #eff6ff;
  border-color: #3b82f6;
  color: #3b82f6;
}

/* Make match list items position relative for popover positioning */
.cw-match {
  position: relative;
  flex-direction: column;
}

@media (max-width: 480px) {
  .cw-group-grid {
    grid-template-columns: 1fr;
  }
}
