/* ==========================================================================
   Tag Overview page — css/tags-overview.css
   Batch B: lists every distinct tag across all 4 asset types (Images/
   Documents/Videos/Testimonials), grouped by type, each with a usage
   count. Read-only reference page — see js/tags-overview.js for the
   aggregation logic. Reuses the shared .products-search-input /
   .products-index-action-btn look from css/shared-features.css where it
   already fits, plus its own small set of tag-pill/group rules below.
   ========================================================================== */

.tags-overview-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 20px 60px;
}

.tags-overview-intro {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: space-between;
  margin-bottom: 24px;
}

.tags-overview-intro p {
  color: var(--hpi-gray-600);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0;
  flex: 1 1 420px;
}

/* Wrapper for all 4 asset-type group sections; each stacks vertically. */
.tags-overview-groups {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.tags-overview-group {
  background: var(--hpi-white);
  border: 1px solid var(--hpi-gray-200);
  border-radius: 8px;
  padding: 16px 18px 18px;
  box-shadow: var(--shadow-card);
}

.tags-overview-group.is-empty-type { display: none; } /* hide a type entirely once its tags are filtered out to zero */

/* Header row: the collapsible header button (icon/title/count, click
   anywhere on it to expand/collapse) plus the "+ Add Tag" button, which
   sits visually inside the same row but is its own independent control
   (stopPropagation'd in JS so it never also toggles collapse). */
.tags-overview-group-head-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tags-overview-group-head {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
}

.tags-overview-group-chevron {
  flex: 0 0 auto;
  color: var(--hpi-gray-600);
  font-size: 0.85rem;
  transition: transform 0.15s;
}

.tags-overview-group.is-collapsed .tags-overview-group-chevron {
  transform: rotate(-90deg);
}

.tags-overview-group-body {
  margin-top: 12px;
}

.tags-overview-group.is-collapsed .tags-overview-group-body {
  display: none;
}

.tags-overview-group-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--hpi-gray-100);
  color: var(--hpi-red);
  font-size: 0.95rem;
  flex: 0 0 auto;
}

.tags-overview-group-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--hpi-black);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tags-overview-group-count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--hpi-gray-600);
  margin-left: 4px;
  flex: 0 0 auto;
}

/* "+ Add Tag" button in each group's header — pushed to the far right. */
.tags-overview-add-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--hpi-gray-800);
  color: var(--hpi-white);
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex: 0 0 auto;
  transition: background 0.15s;
}

.tags-overview-add-btn:hover { background: var(--hpi-red); }

/* Individual tag "pills" — same rounded/dashed visual language as the
   card-tag-chip / card-tag-browse-btn controls on the tool pages, so this
   page's tags read as clearly related to the ones seen there. Now
   interactive: a checkbox to multi-select several tags at once (see
   .tags-overview-selection-bar below), the tag name itself is a button
   (opens just that one tag's matching items), plus small merge/delete
   action icons.

   Legibility pass: taller pill with a touch-friendly checkbox column that
   has its own subtle background/divider so it reads as a distinct control
   rather than blending into the tag text, a bolder/larger tag name, and a
   clearer selected state (red-tinted background AND a red checkmark) so a
   checked pill is unmistakable at a glance.

   Column pass: laid out as a grid (same pattern as the Merge Tags modal's
   .tag-merge-list) instead of a wrapping flex row, so a group with many
   tags reads as an organized, scannable block of columns instead of a
   ragged multi-line wrap where tag boundaries are hard to follow. */
.tags-overview-pill-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

/* Two-row pill: top row is checkbox + name + count (full width, so a long
   tag name isn't squeezed next to the action icons and truncated); the
   rename/merge/delete icons sit on their own row underneath, right-aligned
   — see buildPill() in js/tags-overview.js. */
.tags-overview-pill {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--hpi-gray-100);
  border: 1.5px solid var(--hpi-gray-200);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  color: var(--hpi-black);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.tags-overview-pill-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.tags-overview-pill-top .tags-overview-pill-checkbox {
  margin-top: 2px; /* nudge to align with the first line of a wrapped tag name */
}

.tags-overview-pill-top .tags-overview-pill-count {
  margin-top: 1px;
}

.tags-overview-pill-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  border-top: 1px solid var(--hpi-gray-400);
  padding-top: 5px;
}

.tags-overview-pill.is-unused .tags-overview-pill-actions {
  border-top-style: dashed;
}

.tags-overview-pill:hover {
  border-color: var(--hpi-gray-400);
}

.tags-overview-pill.is-selected {
  background: #fdeceb;
  border-color: var(--hpi-red);
  box-shadow: 0 0 0 1px rgba(200, 30, 30, 0.15);
}

/* Approved-but-unused tag (created via "+ Add Tag" with no items checked,
   backed by tag_registry): distinct dashed treatment so it clearly reads
   as "part of the approved vocabulary, not yet applied to anything" —
   never mistaken for an actively-used tag. Its name isn't clickable (there
   is nothing to open yet), so it also drops the pointer/hover-underline
   styling below. */
.tags-overview-pill.is-unused {
  background: var(--hpi-white);
  border-style: dashed;
  border-color: var(--hpi-gray-400);
}

.tags-overview-pill.is-unused .tags-overview-pill-label {
  cursor: default;
  color: var(--hpi-gray-600);
  font-style: italic;
}

.tags-overview-pill.is-unused .tags-overview-pill-label:hover {
  color: var(--hpi-gray-600);
  text-decoration: none;
}

.tags-overview-pill-count-unused {
  background: var(--hpi-gray-100);
  border-style: dashed;
  color: var(--hpi-gray-600);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-size: 0.62rem;
}

.tags-overview-pill-checkbox {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--hpi-red);
}

.tags-overview-pill-label {
  flex: 1 1 auto;
  min-width: 0;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--hpi-black);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
  /* The name now has its own full-width top row (see .tags-overview-pill-top
     above), so let a long tag name wrap onto a second line instead of being
     ellipsis-truncated \u2014 the whole point of this two-row layout is that
     the name is never cut off/hard to read. */
  overflow: visible;
  white-space: normal;
  word-break: break-word;
  text-align: left;
}

.tags-overview-pill-label:hover {
  color: var(--hpi-red);
  text-decoration: underline;
}

.tags-overview-pill-count {
  background: var(--hpi-white);
  border: 1px solid var(--hpi-gray-400);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--hpi-gray-600);
  flex: 0 0 auto;
}

.tags-overview-pill-action {
  background: none;
  border: 1px solid transparent;
  color: var(--hpi-gray-600);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  flex: 0 0 auto;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tags-overview-pill-action:focus-visible {
  outline: 2px solid var(--hpi-red);
  outline-offset: 1px;
}

.tags-overview-pill-rename:hover { background: var(--hpi-gray-600); color: var(--hpi-white); }
.tags-overview-pill-merge:hover { background: var(--hpi-gray-800); color: var(--hpi-white); }
.tags-overview-pill-delete:hover { background: var(--hpi-red); color: var(--hpi-white); }

.tags-overview-group-empty {
  color: var(--hpi-gray-600);
  font-size: 0.82rem;
  font-style: italic;
  margin: 0;
}

/* Selection bar: appears at the bottom of a group once 1+ of its tags are
   checked via the pill checkboxes above. Lets the visitor open a single
   combined view of every item carrying the checked tags — either ANY of
   them (union) or ALL of them (intersection), via the Any/All toggle
   below — instead of following one tag's link at a time. */
.tags-overview-selection-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--hpi-gray-100);
  border: 1px solid var(--hpi-gray-200);
  border-radius: 8px;
}

.tags-overview-selection-bar.hidden { display: none; }

.tags-overview-selection-count {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--hpi-black);
  flex: 0 0 auto;
}

/* Any/All match-mode toggle — two pill-shaped buttons acting as a single
   choice group (radiogroup semantics via aria-pressed), so "match any" and
   "match all" are both always visible/available at once, per the user's
   explicit "we need both functions" requirement, rather than a dropdown
   that hides the option not currently selected. */
.tags-overview-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.tags-overview-mode-toggle-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--hpi-gray-600);
  margin-right: 2px;
}

.tags-overview-mode-btn {
  background: var(--hpi-white);
  border: 1px solid var(--hpi-gray-400);
  color: var(--hpi-gray-600);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tags-overview-mode-btn:hover { border-color: var(--hpi-gray-600); color: var(--hpi-black); }

.tags-overview-mode-btn.is-active {
  background: var(--hpi-gray-800);
  border-color: var(--hpi-gray-800);
  color: var(--hpi-white);
}

.tags-overview-mode-btn.is-active:hover { background: var(--hpi-black); }

.tags-overview-selection-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--hpi-red);
  color: var(--hpi-white);
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transition: background 0.15s;
  flex: 0 0 auto;
  margin-left: auto;
}

.tags-overview-selection-view-btn:hover { background: var(--hpi-red-dark); }

.tags-overview-selection-clear-btn {
  background: none;
  border: none;
  color: var(--hpi-gray-600);
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: underline;
  padding: 0;
  flex: 0 0 auto;
}

.tags-overview-selection-clear-btn:hover { color: var(--hpi-black); }

/* ---------------- Add Tag modal item picker ---------------- */
#tag-add-dialog #tag-add-type,
#tag-add-dialog #tag-add-name,
#tag-add-dialog #tag-add-search {
  border: 1px solid var(--hpi-gray-200);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85rem;
  background: var(--hpi-white);
  color: var(--hpi-black);
  width: 100%;
}

#tag-add-dialog #tag-add-type:focus,
#tag-add-dialog #tag-add-name:focus,
#tag-add-dialog #tag-add-search:focus {
  outline: none;
  border-color: var(--hpi-red);
}

.tag-add-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--hpi-gray-200);
  border-radius: 6px;
  margin-top: 10px;
  background: var(--hpi-white);
}

/* Legibility pass: bigger accent-colored checkbox in its own visually
   separated column, more vertical breathing room per row, a clear
   checked-row highlight (not just a generic hover tint), and a bolder
   item name so scanning a long list of items/tags is easier. */
.tag-add-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--hpi-gray-200);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s;
}

.tag-add-item:last-child { border-bottom: none; }
.tag-add-item:hover { background: var(--hpi-gray-100); }
.tag-add-item:has(input[type="checkbox"]:checked) { background: #fdeceb; }

.tag-add-item input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--hpi-red);
  cursor: pointer;
}

.tag-add-item-name {
  flex: 1 1 auto;
  color: var(--hpi-black);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-add-item-tags {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--hpi-gray-600);
  font-style: italic;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------------- Merge Tags modal ----------------
   Multi-select checkbox list (replaces the earlier single-target-tag
   dropdown/datalist): check any number of this asset type's other tags
   to fold into the typed "final tag name" field above the list. */
#tag-merge-target {
  border: 1px solid var(--hpi-gray-200);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85rem;
  background: var(--hpi-white);
  color: var(--hpi-black);
  width: 100%;
}

#tag-merge-target:focus {
  outline: none;
  border-color: var(--hpi-red);
}

/* ---------------- Rename Tag modal ---------------- */
#tag-rename-current,
#tag-rename-new {
  border: 1px solid var(--hpi-gray-200);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.85rem;
  background: var(--hpi-white);
  color: var(--hpi-black);
  width: 100%;
}

#tag-rename-current:disabled {
  background: var(--hpi-gray-100);
  color: var(--hpi-gray-600);
  cursor: not-allowed;
}

#tag-rename-new:focus {
  outline: none;
  border-color: var(--hpi-red);
}

/* Grid, not a single tall vertical scroll list — tags flow into as many
   columns as fit the dialog width, so 20+ tags read as a short, wide
   block instead of an unwieldy long scroll. Each tag is its own bordered
   card rather than a full-width row with a bottom divider (dividers don't
   make sense once rows wrap into columns). */
.tag-merge-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--hpi-gray-200);
  border-radius: 6px;
  margin-top: 8px;
  padding: 10px;
  background: var(--hpi-white);
}

.tag-merge-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--hpi-gray-200);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.tag-merge-item:hover { background: var(--hpi-gray-100); border-color: var(--hpi-gray-400); }
.tag-merge-item:has(input[type="checkbox"]:checked):not(.is-locked-source) { background: #fdeceb; border-color: var(--hpi-red); }

.tag-merge-item input[type="checkbox"] {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--hpi-red);
  cursor: pointer;
}

/* The tag whose merge icon was clicked is always included (checkbox
   disabled/locked-on) — clearly distinct gray treatment (not the red
   "checked" tint used for tags the visitor actively chose) plus a small
   "Source" badge, so it unmistakably reads as "already included, can't
   be removed" rather than just another selectable row. */
.tag-merge-item.is-locked-source {
  background: var(--hpi-gray-100);
  cursor: default;
}

.tag-merge-item.is-locked-source input[type="checkbox"] {
  accent-color: var(--hpi-gray-600);
  cursor: default;
}

.tag-merge-item-name {
  flex: 1 1 auto;
  color: var(--hpi-black);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-merge-item-source-badge {
  flex: 0 0 auto;
  background: var(--hpi-gray-400);
  color: var(--hpi-white);
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-radius: 10px;
  padding: 2px 8px;
}

.tag-merge-item-count {
  flex: 0 0 auto;
  font-size: 0.72rem;
  color: var(--hpi-gray-600);
  min-width: 52px;
  text-align: right;
}

@media (max-width: 768px) {
  .tags-overview-main { padding: 16px 14px 50px; }
  .tags-overview-intro { flex-direction: column; align-items: stretch; }
  .products-search-input { width: 100%; min-width: 0; }
  .tags-overview-group-head-row { flex-wrap: wrap; }
  .tags-overview-add-btn { margin-left: 0; }
  .tag-add-item-tags { display: none; }
  .tags-overview-selection-bar { flex-direction: column; align-items: stretch; }
  .tags-overview-selection-view-btn { margin-left: 0; justify-content: center; }
  .tags-overview-mode-toggle { justify-content: center; }
  .tag-merge-list { grid-template-columns: 1fr; }
  .tags-overview-pill-list { grid-template-columns: 1fr; }
}
