/* ─── DESIGN TOKENS ─── */
:root {
  --primary: #5046e5;
  --primary-dark: #3730a3;
  --primary-light: #ede9fe;
  --primary-muted: #a5b4fc;
  --success: #059669;
  --success-dark: #065f46;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #2563eb;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --header-bg: #111827;
  --sidebar-bg: #1f2937;
  --sidebar-text: #d1d5db;
  --sidebar-hover: rgba(255,255,255,0.08);
  --radius: 12px;
  --radius-sm: 7px;
  --radius-xs: 4px;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.09), 0 2px 4px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.13), 0 4px 10px rgba(0,0,0,0.07);
  --header-h: 3.5rem;
  --tr: 0.18s ease;
}

/* ─── RESET ─── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  text-decoration: none;
  cursor: pointer;
  color: inherit;
}

/* ─── HEADER ─── */
body > h1 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  padding: 0 1.25rem;
  height: var(--header-h);
  background: var(--header-bg);
  color: white;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  position: sticky;
  top: 0;
  z-index: 2100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}

.burger-icon {
  cursor: pointer;
  user-select: none;
  font-size: 1.1rem;
  padding: 0.35rem 0.45rem;
  border-radius: var(--radius-xs);
  transition: background var(--tr);
  line-height: 1;
}

.burger-icon:hover { background: rgba(255,255,255,0.12); }

/* ─── LAYOUT ─── */
.main-layout {
  display: flex;
  width: 100%;
  min-height: calc(100vh - var(--header-h));
}

/* ─── SIDEBAR BACKDROP ─── */
.burger-overlay {
  display: none;
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.35);
  z-index: 2050;
  cursor: default;
}

.burger-toggle:checked ~ .burger-overlay { display: block; }

/* ─── SIDEBAR ─── */
.burger-menu {
  display: none;
  flex-direction: column;
  background: var(--sidebar-bg);
  position: fixed;
  top: var(--header-h);
  left: 0;
  height: calc(100vh - var(--header-h));
  width: 230px;
  z-index: 2075;
  padding: 0.75rem 0;
  box-shadow: 4px 0 24px rgba(0,0,0,0.3);
  overflow-y: auto;
}

.burger-toggle:checked ~ .burger-menu { display: flex; }

.burger-menu a {
  color: var(--sidebar-text);
  padding: 0.65rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: all var(--tr);
  display: flex;
  align-items: center;
}

.burger-menu a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  border-left-color: var(--primary-muted);
}

/* ─── PAGE CONTENT ─── */
#pageDiv {
  flex: 1;
  min-height: calc(100vh - var(--header-h));
  padding: 1.5rem 1.75rem;
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 800px) {
  #pageDiv { padding: 1rem; }
}

/* ─── TYPOGRAPHY ─── */
h2 {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 1rem;
}

h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--text);
}

/* Section headers with inline actions (e.g. items header) */
h2.section-header {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  text-transform: none;
  letter-spacing: normal;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

h2.section-header a,
h2.section-header label {
  font-size: 1rem;
  padding: 0.2rem 0.35rem;
  border-radius: var(--radius-xs);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--tr), color var(--tr);
  display: inline-flex;
  align-items: center;
}

h2.section-header a:hover,
h2.section-header label:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* ─── ITEMS FILTER PANEL ─── */
.filter-panel {
  margin-bottom: 1.5rem;
}

.filter-panel summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.filter-panel form {
  margin-top: 0.75rem;
}

.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.filter-row:last-of-type { border-bottom: none; }

.filter-attr-name {
  flex: 1;
  min-width: 30%;
  font-size: 0.875rem;
  font-weight: 500;
}

.filter-interval {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.filter-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.85rem;
}

.filter-checkboxes label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* ─── ITEMS MAP (Leaflet / OpenStreetMap) ─── */
.items-map-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  padding: 0.5rem;
}

#itemsMapContainer {
  height: 400px;
  width: 100%;
  border-radius: var(--radius);
}

/* ─── LOCATION ATTRIBUTE EDITOR (map + coordinates, synced) ─── */
.attr-location-field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.attr-location-map {
  height: 220px;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.attr-location-map.readonly,
.attr-location-map.readonly .leaflet-container {
  cursor: default;
}

/* ─── CARD GRID ─── */
.flexDiv {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.875rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 800px) {
  .flexDiv {
    grid-template-columns: repeat(auto-fill, minmax(6rem, 1fr));
    gap: 0.625rem;
  }
}

/* ─── PAGINATION (issue #15) ─── */
.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pagination-page-input {
  width: 3.5rem;
  padding: 0.3rem 0.4rem;
  text-align: center;
}

/* ─── CARD BASE ─── */
.itemDiv {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--tr), border-color var(--tr);
}

.itemDiv:hover {
  box-shadow: var(--shadow-md);
  border-color: #d1d5db;
}

@media (max-width: 800px) {
  .itemDiv { min-width: 6rem; height: 7.5rem; }
}

@media (min-width: 801px) {
  .itemDiv { width: 9rem; min-width: 9rem; height: 12rem; }
}

/* ─── CARD BODY (fills remaining space above the progress bar) ─── */
.itemBody {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* ─── CARD LINK WRAPPER ─── */
.itemDiv a {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding-bottom: 0.25rem;
  color: var(--text);
}

.itemDiv a br { display: none; }

/* ─── CARD NAME ─── */
.itemDiv a span {
  font-size: 0.75rem;
  font-weight: 500;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  padding: 0.3rem 0.4rem 0.15rem;
  width: 100%;
  color: var(--text);
  word-break: break-word;
}

/* ─── CARD EDIT BUTTON ─── */
.editItem {
  position: absolute;
  top: 5px;
  left: 5px;
  cursor: pointer;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
  border-radius: 50%;
  width: 1.65rem;
  height: 1.65rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  box-shadow: var(--shadow-xs);
  transition: background var(--tr), box-shadow var(--tr);
  z-index: 1;
}

.editItem:hover {
  background: rgba(255,255,255,1);
  box-shadow: var(--shadow-sm);
}

/* ─── ITEM STATUS PICKER ─── */
/* .status-picker relies on .editItem's `position: absolute` (do NOT set `position:
   relative` here, it would override .editItem and pull the badge back into normal
   flow, pushing the image/title below it). */
.status-picker .status-current {
  position: relative; /* enters the "positioned" paint layer, above the ::before bridge below */
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* Invisible bridge covering the badge-to-menu gap so the pointer never leaves
   .status-picker's hover area while moving from the badge to the menu (without
   this, .status-menu's `display:none` kicks in mid-transit and the menu never
   stays open long enough to reach). z-index:0 keeps it below .status-current and
   .status-menu (both explicitly positioned above it) so clicks still reach them —
   an unpositioned element here would otherwise paint on top regardless of DOM order. */
.status-picker::before {
  content: '';
  position: absolute;
  z-index: 0;
  top: -8px;
  left: -8px;
  width: 160px;
  height: calc(100% + 16px);
}

.status-menu {
  display: none;
  position: absolute;
  top: 0;
  left: 100%;
  flex-direction: row;
  gap: 2px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(4px);
  border-radius: 999px;
  padding: 2px 4px;
  box-shadow: var(--shadow-sm);
  z-index: 2;
}

.status-picker:hover .status-menu {
  display: flex;
}

.status-menu span {
  cursor: pointer;
  width: 1.4rem;
  height: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  border-radius: 50%;
  transition: background var(--tr);
}

.status-menu span:hover {
  background: var(--primary-light);
}

/* ─── CARD IMAGE ─── */
.itemImg {
  object-fit: contain;
  cursor: pointer;
  display: block;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
}

@media (max-width: 800px) {
  .itemImg { height: 4rem; width: 4rem; margin-top: 0.65rem; }
}

@media (min-width: 801px) {
  .itemImg { height: 8rem; width: 8rem; margin-top: 0.5rem; }
}

/* ─── PROGRESS BARS ─── */
.progress-bar {
  flex: 0 0 4px;
  display: flex;
  width: 100%;
  overflow: hidden;
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}

.progress-owned {
  background: var(--success);
  flex-shrink: 0;
  opacity: 0.85;
}

.progress-duplicate {
  background: var(--success-dark);
  flex-shrink: 0;
  opacity: 0.85;
}

.progress-ordered {
  background: var(--info);
  flex-shrink: 0;
  opacity: 0.85;
}

.progress-wished {
  background: var(--warning);
  flex-shrink: 0;
  opacity: 0.85;
}

.progress-missing {
  background: var(--danger);
  flex-shrink: 0;
  opacity: 0.7;
}

/* ─── CREATE/LINK/IMPORT TOOLBAR (above a grid) ─── */
.collection-toolbar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.875rem;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: background var(--tr), color var(--tr), border-color var(--tr);
}

.toolbar-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-muted);
  color: var(--primary-dark);
}

/* ─── BREADCRUMB ─── */
.hierarchyDiv {
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  scrollbar-width: thin;
  --bc-step: 7em;
}

@media (max-width: 800px) { .hierarchyDiv { min-height: 8rem; --bc-step: 5.4rem; } }

@media (min-width: 801px) { .hierarchyDiv { min-height: 13rem; } }

.hierarchyDiv > * {
  position: absolute;
  top: 0.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
}

.hierarchyDiv > *:nth-child(n) {
  left: calc(var(--bc-step) * (var(--item-index, calc(var(--n, 1) - 1))) + 0.5rem);
}

.hierarchyDiv > p {
  position: static;
  background: linear-gradient(135deg, var(--primary-light) 0%, #faf5ff 100%);
  border: 1px solid var(--primary-muted);
  color: var(--primary-dark);
  font-size: 0.9rem;
  line-height: 1.65;
  padding: 1rem 1.25rem;
  margin: 0.5rem;
  max-width: 520px;
  box-shadow: none;
}

/* ─── POPUP / MODAL ─── */
.popup {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(17, 24, 39, 0.55);
  justify-content: center;
  align-items: center;
  z-index: 2110;
  backdrop-filter: blur(3px);
}

.popup-inner {
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius);
  min-width: min(50vw, 90vw);
  max-width: 95vw;
  min-height: 50vh;
  max-height: 95dvh;
  position: relative;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.popup-content {
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

@media (max-width: 600px) {
  .popup-inner {
    padding: 1rem;
    min-width: 92vw;
    min-height: 0;
  }
}

.popup-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  padding: 0.2rem 0.5rem;
  line-height: 1;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--tr), color var(--tr);
  border: none;
  box-shadow: none;
}

.popup-close:hover {
  background: var(--bg);
  color: var(--text);
}

/* ─── IMPORT POPUP ─── */
#popupImportDiv {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(17, 24, 39, 0.55);
  justify-content: center;
  align-items: center;
  z-index: 2110;
  backdrop-filter: blur(3px);
}

.import-popup-inner {
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius);
  min-width: min(50vw, 90vw);
  min-height: 50vh;
  position: relative;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.import-popup-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  padding: 0.2rem 0.5rem;
  line-height: 1;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: background var(--tr), color var(--tr);
  border: none;
  box-shadow: none;
}

.import-popup-close:hover {
  background: var(--bg);
  color: var(--text);
}

/* ─── FORMS ─── */
input[type="text"],
input[type="email"],
select,
textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--tr), box-shadow var(--tr);
  outline: none;
}

input[type="text"]:focus,
input[type="email"]:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(80,70,229,0.15);
}

/* ─── BUTTONS ─── */
button,
input[type="submit"],
input[type="button"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--tr), box-shadow var(--tr);
  background: var(--primary);
  color: white;
  box-shadow: var(--shadow-xs);
  line-height: 1.4;
}

button:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

button:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled {
  background: var(--border);
  color: var(--text-light);
  cursor: not-allowed;
  box-shadow: none;
}

button:disabled:hover,
input[type="submit"]:disabled:hover,
input[type="button"]:disabled:hover {
  background: var(--border);
  box-shadow: none;
}

.btn-danger {
  background: var(--danger) !important;
  color: white !important;
}

.btn-danger:hover { background: #b91c1c !important; }

.btn-secondary {
  background: var(--bg) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-xs) !important;
}

.btn-secondary:hover { background: #e5e7eb !important; }

/* ─── ITEM / COLLECTION EDIT MODAL ─── */
#itemEditModal,
#collectionEditModal {
  display: flex;
  flex-flow: wrap;
  gap: 1.5rem;
  text-align: left;
}

.edit-form-wrap { flex: 1; min-width: 220px; }

.form-field { margin-bottom: 0.75rem; }

.form-field-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
}

.form-field-header > span {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
}

.attr-add-value, .attr-resync { font-size: 0.85rem; line-height: 1; }

.item-reference-image-resync {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.form-field input[type="text"] { width: 100%; }

.attr-multi-values { display: flex; flex-direction: column; gap: 0.4rem; }

.attr-multi-value-row { display: flex; align-items: center; gap: 0.4rem; }

.attr-multi-value-row input[type="text"] { flex: 1; width: auto; min-width: 0; }

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

/* Readonly display */
.read-field { margin-bottom: 0.75rem; }

.read-field .field-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.15rem;
}

.read-field .field-value {
  font-size: 0.9rem;
  color: var(--text);
}

/* ─── IMAGE EDITOR ─── */
.image-editor-wrap { position: relative; }

.image-editor-toolbar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.625rem;
  flex-wrap: wrap;
}

.image-editor-toolbar > * {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  overflow: hidden;
  border-radius: var(--radius-xs);
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--tr), border-color var(--tr);
  text-decoration: none;
  color: inherit;
  margin: 0;
  padding: 0;
  box-shadow: none;
  font-family: inherit;
  line-height: 1;
}

.image-editor-toolbar > *:hover {
  background: var(--primary-light);
  border-color: var(--primary-muted);
}

/* override .itemDiv a (higher specificity) so toolbar anchors match label/span sizing */
.image-editor-toolbar > a {
  display: inline-flex;
  flex-direction: row;
  height: 2rem;
  padding-bottom: 0;
  color: inherit;
}

.image-editor-area { margin: 0.75rem 0; }

/* ─── IMAGE SEARCH CANDIDATES ─── */
.image-candidates { margin: 0.75rem 0; }

.image-candidates-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.image-candidates-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.image-candidate {
  display: block;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--tr);
}

.image-candidate:hover { border-color: var(--primary-muted); }

.image-candidate img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ─── CROP ─── */
.image-crop-stage {
  position: relative;
  display: inline-block;
  max-width: 300px;
}

.image-crop-stage img {
  display: block;
  max-width: 300px;
  width: 100%;
  height: auto;
}

.image-crop-selection {
  position: absolute;
  box-sizing: border-box;
  border: 2px solid #ff7a00;
  background: rgba(255, 122, 0, 0.15);
  cursor: move;
  touch-action: none;
}

.image-crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #ff7a00;
  border: 2px solid #fff;
  border-radius: 50%;
}

.image-crop-handle[data-mode="nw"] { top: -7px; left: -7px; cursor: nwse-resize; }
.image-crop-handle[data-mode="ne"] { top: -7px; right: -7px; cursor: nesw-resize; }
.image-crop-handle[data-mode="sw"] { bottom: -7px; left: -7px; cursor: nesw-resize; }
.image-crop-handle[data-mode="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }

/* ─── ATTRIBUTE CHIPS ─── */
.attr-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  background: var(--primary-light);
  border: 1px solid var(--primary-muted);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--primary-dark);
  cursor: grab;
  user-select: none;
  transition: background var(--tr);
}

.attr-chip:hover { background: #ddd6fe; }
.attr-chip:active { cursor: grabbing; }

/* ─── GROUPING CHIPS ─── */
.grouping-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  background: var(--primary-light);
  border: 1px solid var(--primary-muted);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--primary-dark);
}

/* ─── SELECT ATTRIBUTES PANEL ─── */
.attr-panel-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.attr-panel-row:last-of-type { border-bottom: none; }

.attr-panel-name { flex: 1; min-width: 50%; font-size: 0.875rem; font-weight: 500; }

.attr-panel-type { font-size: 0.78rem; color: var(--text-muted); }

.attr-panel-delete {
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  border-radius: var(--radius-xs);
  transition: background var(--tr);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.attr-panel-delete:hover { background: #fef2f2; color: var(--danger); }

.attr-add-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.attr-add-form input[type="text"] { flex: 1; min-width: 100px; }

.attr-add-form select { min-width: 120px; }

.attr-panel-save {
  display: block;
  margin-top: 0.625rem;
  font-size: 0.8rem;
  color: var(--primary);
  cursor: pointer;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0.25rem 0;
  text-decoration: none;
}

.attr-panel-save:hover { text-decoration: underline; }

.attr-panel-values {
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  border-radius: var(--radius-xs);
  transition: background var(--tr);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.attr-panel-values:hover { background: var(--bg); color: var(--primary); }

/* ─── ATTRIBUTE POSSIBLE VALUES POPUP ─── */
.attr-values-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-width: min(420px, 90vw);
  max-width: 95vw;
  max-height: 85dvh;
  box-shadow: var(--shadow-lg);
}

.attr-values-dialog::backdrop {
  background: rgba(17, 24, 39, 0.55);
  backdrop-filter: blur(3px);
}

.attr-values-dialog h4 { margin: 0 0 0.75rem; font-size: 0.95rem; }

.attr-free-entry-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.attr-values-editor { display: flex; flex-direction: column; gap: 0.4rem; }

.attr-values-list { display: flex; flex-direction: column; gap: 0.4rem; }

.attr-value-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.attr-value-row input[type="text"] { flex: 1; }

.attr-values-dialog-close {
  display: block;
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--primary);
  cursor: pointer;
  background: none;
  border: none;
  box-shadow: none;
  padding: 0.25rem 0;
}

.attr-values-dialog-close:hover { text-decoration: underline; }

/* ─── ITEM GROUPING MEMBERS ─── */
.grouping-member-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0;
  margin: 0.4rem 0;
  list-style: none;
}

.grouping-member-row {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem;
  background: var(--primary-light);
  border: 1px solid var(--primary-muted);
  border-radius: var(--radius-xs);
  font-size: 0.75rem;
  text-align: center;
  max-width: 6rem;
}

.grouping-member-img {
  object-fit: contain;
  border-radius: var(--radius-xs);
}

@media (max-width: 800px) {
  .grouping-member-img { height: 2rem; width: 2rem; }
}

@media (min-width: 801px) {
  .grouping-member-img { height: 4rem; width: 4rem; }
}

.grouping-member-list--draggable .grouping-member-row { cursor: grab; }
.grouping-member-list--draggable .grouping-member-row:active { cursor: grabbing; }

.grouping-member-row--current { border-color: var(--danger); border-width: 2px; }

/* ─── COLLECTION LINK SELECTOR ROWS ─── */
.link-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--tr);
}

.link-row:last-child { border-bottom: none; }
.link-row:hover { background: var(--bg); }

.link-row img {
  width: 2rem;
  height: 2rem;
  object-fit: contain;
  border-radius: var(--radius-xs);
  flex-shrink: 0;
}

.link-row-name { flex: 1; font-size: 0.875rem; }

.link-row-expand {
  background: var(--bg) !important;
  color: var(--text-muted) !important;
  border: 1px solid var(--border) !important;
  padding: 0.2rem 0.45rem !important;
  font-size: 0.75rem !important;
  border-radius: var(--radius-xs) !important;
  box-shadow: none !important;
}

.link-row-expand:hover {
  background: var(--primary-light) !important;
  color: var(--primary) !important;
  border-color: var(--primary-muted) !important;
}

.link-row-confirm {
  background: #dcfce7 !important;
  color: #15803d !important;
  border: 1px solid #86efac !important;
  padding: 0.2rem 0.5rem !important;
  font-size: 0.8rem !important;
  border-radius: var(--radius-xs) !important;
  box-shadow: none !important;
}

.link-row-confirm:hover { background: #bbf7d0 !important; }

.link-children { padding-left: 1.5rem; }

.move-confirm-warning { color: #b91c1c; }

.move-bulk-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0.75rem 1rem;
  margin: 0.5rem 0;
}

/* ─── SECTIONS (Friends, Account, etc.) ─── */
section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

ul { list-style: none; margin: 0; padding: 0; }

ul li {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

ul li:last-child { border-bottom: none; }

/* ─── ACCOUNT STATS ─── */
.account-info {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.3rem 1rem;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.account-info strong {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.875rem;
  margin-top: 0.5rem;
}

.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  text-align: center;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  display: block;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-top: 0.25rem;
}

/* ─── TABLE ─── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

th {
  text-align: left;
  padding: 0.65rem 1rem;
  background: var(--bg);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

/* ─── BULK EDIT TABLE (horizontal scroll on narrow screens) ─── */
.bulk-edit-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.bulk-edit-table {
  min-width: max-content;
}

.bulk-edit-table td input[type="text"] {
  min-width: 8rem;
}
tr:hover td { background: var(--bg); }

/* ─── UTILITY ─── */
.linkCursor { cursor: pointer; }

.with-border {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-block-start: 0.75rem;
  background: var(--bg);
}

.error-message {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}

/* ─── COLLECTION EDIT FORM ─── */
.collection-edit-block { margin-bottom: 0.75rem; }

.collection-edit-block > span:first-child,
.collection-edit-block > label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.3rem;
}

.collection-edit-block input[type="text"] { width: 100%; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
