*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0b10;
  --surface: #13131c;
  --surface2: #1c1c2a;
  --surface3: #242436;
  --border: #2a2a3d;
  --border-hi: #3a3a55;
  --text: #eaeaf4;
  --text-muted: #7878a0;
  --accent: #7c6af7;
  --accent2: #a78bfa;
  --accent-dim: #7c6af718;
  --accent-glow: #7c6af733;
  --amazon: #ff9900;
  --lazada: #3b82f6;
  --aliexpress: #ff4747;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px #00000055;
  --shadow-lg: 0 8px 40px #00000077;
  --card-glow: 0 0 0 1px var(--accent), 0 4px 24px var(--accent-glow);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface2: #f1f5f9;
  --surface3: #e2e8f0;
  --border: #cbd5e1;
  --border-hi: #94a3b8;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent2: #8b5cf6;
  --accent-dim: #6366f118;
  --accent-glow: #6366f133;
  --shadow: 0 4px 12px #00000015;
  --shadow-lg: 0 8px 24px #00000022;
}

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: 52px;
  overflow-x: hidden;
}

/* ── Topbar ── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  z-index: 200;
}

#topbar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), transparent);
  pointer-events: none;
}

#bom-picker-btn {
  flex: 1;
  min-width: 0;
  max-width: 240px;
  text-align: left;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  transition: border-color 0.15s;
  overflow: hidden;
}

#bom-picker-btn:hover { border-color: var(--accent); }

#topbar-bom-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-caret {
  color: var(--text-muted);
  font-size: 0.7rem;
  flex-shrink: 0;
}

.topbar-icon-btn {
  width: 34px; height: 34px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
  font-family: inherit;
  flex-shrink: 0;
  font-weight: 600;
}

.topbar-icon-btn:hover { border-color: var(--border-hi); color: var(--text); }
.topbar-icon-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

#currency-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.72rem;
  font-family: inherit;
  max-width: 80px;
}

#rates-status {
  font-size: 0.6rem;
  color: var(--text-muted);
  white-space: nowrap;
  display: none;
}

/* BOM picker modal entries */
.bom-entry {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 4px;
  transition: all 0.15s;
  position: relative;
}

.bom-entry:hover { background: var(--surface2); border-color: var(--border); }

.bom-entry.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.bom-entry.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.bom-entry-name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bom-entry-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ── Main ── */
#main {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 52px);
}

#bom-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  flex-wrap: wrap;
  position: sticky;
  top: 52px;
  z-index: 100;
}

#bom-title-wrap { flex: 1; min-width: 0; }

#bom-name-display {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

#bom-desc-display {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

#bom-stats {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.stat-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.78rem;
  white-space: nowrap;
  font-weight: 500;
}

.stat-chip span { color: var(--accent2); font-weight: 700; }

.header-btn {
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
  font-weight: 500;
}

.header-btn:hover { border-color: var(--border-hi); color: var(--text); background: var(--surface3); }

.header-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.header-btn.primary:hover { opacity: 0.88; box-shadow: 0 2px 12px var(--accent-glow); }

.header-btn.danger:hover { border-color: var(--red); color: var(--red); }

/* ── Items toolbar (search + sort) ── */
#items-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px 0;
  flex-wrap: wrap;
}

#toolbar-total {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green);
  white-space: nowrap;
  padding: 4px 0;
}

#item-search {
  flex: 1;
  min-width: 160px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px 7px 32px;
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
  transition: border-color 0.15s;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237878a0' stroke-width='2.5'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

#item-search:focus { border-color: var(--accent); }

#sort-select {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.78rem;
  font-family: inherit;
  cursor: pointer;
  width: auto;
}

#items-area {
  padding: 12px 20px 20px;
}

/* ── Filter bar ── */
#filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

#filter-bar select, #filter-bar input {
  width: auto;
  padding: 6px 10px;
  font-size: 0.78rem;
}

/* ── Empty state ── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 12px;
  padding: 40px;
}

#empty-state .icon { font-size: 3rem; opacity: 0.6; }
#empty-state h2 { font-size: 1.05rem; color: var(--text); font-weight: 600; }
#empty-state p { font-size: 0.82rem; text-align: center; }

/* ── Item cards ── */
@keyframes card-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 10px;
  display: flex;
  gap: 0;
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
  animation: card-in 0.18s ease both;
  position: relative;
}

.item-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--item-accent, var(--border));
  border-radius: 0;
}

.item-card:hover {
  border-color: var(--accent);
  box-shadow: var(--card-glow);
}

.item-card.status-received { --item-accent: var(--green); }
.item-card.status-ordered  { --item-accent: var(--amber); }
.item-card.status-needed   { --item-accent: var(--border); }

.item-card.status-received { opacity: 0.85; }

.item-img {
  width: 90px;
  min-width: 90px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.6rem;
  flex-shrink: 0;
  overflow: hidden;
}

.item-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-body {
  flex: 1;
  padding: 12px 14px;
  min-width: 0;
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.item-name {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.item-top-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.item-qty {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
  font-weight: 500;
}

.status-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.status-badge.status-needed   { background: var(--surface3); color: var(--text-muted); border: 1px solid var(--border); }
.status-badge.status-ordered  { background: #f59e0b1a; color: var(--amber); border: 1px solid #f59e0b44; }
.status-badge.status-received { background: #22c55e1a; color: var(--green); border: 1px solid #22c55e44; }

.item-specs {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.item-links {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 4px;
}

.platform-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  font-family: inherit;
}

.platform-btn:hover { opacity: 0.8; transform: translateY(-1px); }

.platform-btn.amazon     { background: #ff990018; color: var(--amazon);   border: 1px solid #ff990033; }
.platform-btn.lazada     { background: #3b82f618; color: #60a5fa;         border: 1px solid #3b82f633; }
.platform-btn.aliexpress { background: #ef444418; color: #f87171;         border: 1px solid #ef444433; }

.platform-btn.cheapest::after {
  content: '★';
  font-size: 0.6rem;
  color: var(--green);
}

/* ── Item actions (right column) ── */
.item-actions {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 12px;
  border-left: 1px solid var(--border);
  min-width: 78px;
  align-items: center;
  gap: 6px;
}

.item-best-price {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--green);
  text-align: center;
  line-height: 1.2;
}

.item-best-price-label {
  font-size: 0.58rem;
  color: var(--text-muted);
  text-align: center;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 3px;
}

.qty-btn {
  width: 22px; height: 22px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
  font-family: inherit;
  line-height: 1;
  padding: 0;
}

.qty-btn:hover { border-color: var(--accent); color: var(--accent); }

.qty-val {
  font-size: 0.78rem;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
}

.item-edit-btn, .item-del-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.72rem;
  transition: all 0.15s;
  font-family: inherit;
  width: 100%;
}

.item-edit-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.item-del-btn:hover  { border-color: var(--red);    color: var(--red); }

/* ── Compat row ── */
.compat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.compat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  border: 1px solid;
  font-size: 0.7rem;
  background: #00000020;
  cursor: default;
}

/* ── Spec chips ── */
.spec-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.spec-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 9px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.spec-chip strong { color: var(--accent2); }

/* ── Tile view ── */
#items-area.tile-view {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 10px;
  padding: 12px;
  align-content: start;
}

.item-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: card-in 0.18s ease both;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.item-tile:hover { border-color: var(--accent); box-shadow: var(--card-glow); }

.item-tile.status-received { --item-accent: var(--green); opacity: 0.85; }
.item-tile.status-ordered  { --item-accent: var(--amber); }
.item-tile.status-needed   { --item-accent: var(--border); }

/* The rectangle: image + action strip + qty strip */
.item-tile-rect {
  display: flex;
  flex-direction: column;
  border-bottom: 3px solid var(--item-accent, var(--border));
}

.item-tile-top-row {
  display: flex;
}

.item-tile-img {
  flex: 1;
  aspect-ratio: 1;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; color: var(--text-muted);
  overflow: hidden;
  min-height: 0;
}

.item-tile-img img { width: 100%; height: 100%; object-fit: cover; }

.item-tile-actions {
  width: 36px;
  background: var(--surface2);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 5px; padding: 8px 0;
}

.item-tile-btn {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s; font-family: inherit;
  padding: 0; line-height: 1;
}

.item-tile-btn:hover { color: var(--text); border-color: var(--border-hi); }
.item-tile-btn.edit:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.item-tile-btn.copy:hover { color: var(--accent2); border-color: var(--accent2); }
.item-tile-btn.del:hover  { color: var(--red); border-color: var(--red); }

.item-tile-qty-strip {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 5px 4px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
}

.item-tile-qty-strip .qty-btn { width: 24px; height: 24px; }
.item-tile-qty-strip .qty-val { font-size: 0.78rem; min-width: 18px; }

/* Info below the rectangle */
.item-tile-info {
  padding: 8px 10px 10px;
}

.item-tile-name {
  font-size: 0.8rem; font-weight: 700; line-height: 1.3;
  margin-bottom: 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-tile-meta {
  display: flex; flex-wrap: wrap; gap: 3px; align-items: center;
  font-size: 0.65rem;
}

.item-tile-price { color: var(--green); font-weight: 700; }

/* View toggle button in toolbar */
#view-toggle-btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

#view-toggle-btn:hover { border-color: var(--border-hi); color: var(--text); }
#view-toggle-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── Modals ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: #000000aa;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-header h2 { font-size: 1.05rem; font-weight: 700; }

.modal-close {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 4px 9px;
  border-radius: 6px;
  transition: all 0.15s;
  font-family: inherit;
}

.modal-close:hover { color: var(--text); border-color: var(--border-hi); }

.modal-body { padding: 18px 22px; }

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

/* ── Auto-fill ── */
.autofill-section {
  background: linear-gradient(135deg, #1e1830, var(--surface2));
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 18px;
}

.autofill-row {
  display: flex;
  gap: 8px;
}

.autofill-row input {
  flex: 1;
  background: var(--surface);
  border-color: var(--border-hi);
  font-size: 0.82rem;
  padding: 8px 12px;
}

.autofill-btn {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
  white-space: nowrap;
}

.autofill-btn:hover   { opacity: 0.85; }
.autofill-btn:disabled { opacity: 0.5; cursor: default; }

.autofill-status {
  font-size: 0.72rem;
  margin-top: 6px;
  color: var(--text-muted);
  min-height: 16px;
}

.autofill-status.loading { color: var(--accent2); }
.autofill-status.success { color: var(--green); }
.autofill-status.error   { color: #f87171; }

/* ── Form ── */
.form-group { margin-bottom: 14px; }

label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"], input[type="number"], input[type="url"], textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea { resize: vertical; min-height: 70px; }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.platform-section {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

.platform-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.platform-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-amazon { background: var(--amazon); }
.dot-lazada { background: #60a5fa; }
.dot-aliexpress { background: #f87171; }

.img-preview {
  margin-top: 8px;
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: none;
}

/* ── Spec fields in item modal ── */
.modal-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 18px 0 8px;
}

.spec-field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  min-height: 34px;
}

.spec-field-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  min-width: 130px;
  flex-shrink: 0;
}

.spec-unit { font-size: 0.7rem; color: var(--accent2); margin-left: 3px; }

.spec-range-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.spec-range-inputs input, .spec-field-row > input {
  width: 90px;
  padding: 6px 8px;
  font-size: 0.8rem;
}

.range-dash { color: var(--text-muted); font-size: 0.85rem; }

/* ── Spec manager modal ── */
.spec-mgr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.spec-mgr-name { font-size: 0.875rem; font-weight: 600; }
.spec-mgr-meta { font-size: 0.75rem; color: var(--text-muted); }

/* ── Linked parts checkboxes ── */
.linked-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.linked-checkbox input { width: auto; cursor: pointer; accent-color: var(--accent); }

/* ── No BOM selected ── */
#no-bom {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: calc(100vh - 120px);
  padding: 40px 24px;
  gap: 16px;
}

#no-bom .no-bom-icon {
  font-size: 4rem;
  opacity: 0.4;
  line-height: 1;
}

#no-bom h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

#no-bom p {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 300px;
  line-height: 1.6;
}

#no-bom-create-btn {
  padding: 11px 28px !important;
  font-size: 0.9rem !important;
  border-radius: 10px !important;
}

/* ── Swipe to delete ── */
.item-card {
  touch-action: pan-y;
}

.item-card.swiping {
  transition: none !important;
}

.item-card.swipe-delete {
  background: #ef444418;
  border-color: var(--red) !important;
}

/* ── Compact header buttons on mobile ── */
.btn-text { /* visible by default */ }

@media (max-width: 640px) {
  .btn-text { display: none; }
  #bom-header .header-btn { padding: 7px 9px; min-width: 34px; justify-content: center; }
  #bom-header { gap: 6px; padding: 10px 12px; }
  #bom-stats { display: none; }
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--surface3);
  border: 1px solid var(--border-hi);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 999;
  pointer-events: none;
  box-shadow: var(--shadow);
}

.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Component type badge ── */
.type-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 1px 7px;
  border-radius: 4px;
  background: var(--surface3);
  border: 1px solid var(--border-hi);
  color: var(--text-muted);
  margin-bottom: 3px;
}

/* ── Copy button ── */
.item-copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
  font-family: inherit;
  width: 100%;
}
.item-copy-btn:hover { border-color: var(--accent2); color: var(--accent2); }

/* ── Proposal item sources ── */
.prop-source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.prop-source-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prop-source-bundle { font-size: 0.72rem; color: var(--accent2); font-weight: 600; white-space: nowrap; }
.prop-source-select { width: auto; font-size: 0.75rem; padding: 4px 8px; flex-shrink: 0; }

/* ── Compare table extras ── */
.cmp-type-col { width: 90px; }
.cmp-excluded { font-size: 0.72rem; color: var(--text-muted); font-style: italic; }

/* ── Bundles ── */
.bundle-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: #a78bfa18;
  border: 1px solid #a78bfa44;
  color: var(--accent2);
}

.bundle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.bundle-row-name { font-size: 0.875rem; font-weight: 600; }
.bundle-row-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* ── Comparison table ── */
.cmp-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.cmp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 500px;
}

.cmp-table th, .cmp-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.cmp-table thead th {
  background: var(--surface2);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

.cmp-table thead th:first-child { color: var(--text); }

.cmp-table tbody tr:hover td { background: var(--surface2); }

.cmp-table tfoot td {
  font-weight: 700;
  font-size: 0.9rem;
  background: var(--surface2);
  border-top: 2px solid var(--border-hi);
  border-bottom: none;
}

.cmp-item-col  { min-width: 140px; }
.cmp-qty-col   { width: 40px; }
.cmp-proposal-col { min-width: 160px; }
.cmp-data-col  { min-width: 140px; }

.cmp-total-cell { color: var(--text); }
.cmp-best { color: var(--green) !important; }
.cmp-best::after { content: ' ★'; font-size: 0.7rem; }

.compare-bundle-cell {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent2);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ── Input / Output spec columns in item modal ── */
.spec-io-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
  margin-bottom: 4px;
}

@media (max-width: 560px) {
  .spec-io-grid { grid-template-columns: 1fr; }
}

.spec-io-col { min-width: 0; }

.spec-in-title  { color: #60a5fa; }
.spec-out-title { color: var(--green); }

.spec-io-hint {
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-left: 4px;
}

/* ── Spec direction labels on chips ── */
.spec-dir-label {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.65;
}
.spec-chip-in  .spec-dir-label { color: #60a5fa; }
.spec-chip-out .spec-dir-label { color: var(--green); }

/* ── Supply badge ── */
.supply-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.6rem; font-weight: 700; padding: 2px 7px; border-radius: 10px;
  background: #facc151a; border: 1px solid #facc1544; color: #facc15;
  text-transform: uppercase; letter-spacing: 0.04em;
}

.supply-checkbox-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.82rem; font-weight: 600; color: #facc15;
  cursor: pointer; padding: 8px 0; white-space: nowrap;
}
.supply-checkbox-label input { width: auto; cursor: pointer; accent-color: #facc15; }

/* ── Status group headers ── */
.status-group-header {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  padding: 12px 0 4px; display: flex; align-items: center; gap: 8px;
}
.status-group-header::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.status-group-header.group-received { color: var(--green); }
.status-group-header.group-ordered  { color: var(--amber); }

/* ── Unpriced badge ── */
.unpriced-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.6rem; font-weight: 700; padding: 2px 7px; border-radius: 10px;
  background: #f59e0b1a; border: 1px solid #f59e0b44; color: var(--amber);
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* ── Stock badge ── */
.stock-badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 0.6rem; font-weight: 700; padding: 2px 7px; border-radius: 10px;
  background: #22c55e1a; border: 1px solid #22c55e44; color: var(--green);
}

/* ── Price spread warning ── */
.price-spread-warn { font-size: 0.62rem; color: var(--amber); font-weight: 600; }

/* ── Drag handle / reorder ── */
.drag-handle {
  cursor: grab; color: var(--border-hi); font-size: 0.9rem; padding: 0 2px;
  user-select: none; align-self: stretch; display: flex; align-items: center;
}
.drag-handle:active { cursor: grabbing; }
.item-card.dragging { opacity: 0.45; }
.item-card.drag-over { border-color: var(--accent); box-shadow: var(--card-glow); }

/* ── Duplicate button ── */
.item-dup-btn {
  background: none; border: 1px solid var(--border); border-radius: 6px;
  color: var(--text-muted); padding: 4px 8px; cursor: pointer;
  font-size: 0.72rem; transition: all 0.15s; font-family: inherit; width: 100%;
}
.item-dup-btn:hover { border-color: var(--green); color: var(--green); }

/* ── eBay / Shopee platform colours ── */
.platform-btn.ebay   { background: #0064d218; color: #4da6ff; border: 1px solid #0064d233; }
.platform-btn.shopee { background: #ee450018; color: #ff8c42; border: 1px solid #ee450033; }
.dot-ebay   { background: #4da6ff; }
.dot-shopee { background: #ff8c42; }

/* ── Undo toast ── */
.toast.toast-undo { pointer-events: all; }
.toast-undo-btn {
  margin-left: 12px; padding: 2px 10px; background: var(--accent);
  border: none; border-radius: 10px; color: #fff; font-size: 0.78rem;
  font-weight: 700; cursor: pointer; font-family: inherit;
}

/* ── QR modal ── */
.qr-modal-img {
  display: block; margin: 12px auto; border-radius: 8px;
  border: 6px solid #fff; image-rendering: pixelated;
}

/* ── Print styles ── */
/* ── Graph View ── */
#graph-view {
  width: 100%;
  height: calc(100svh - 260px);
  min-height: 480px;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  background-image: radial-gradient(circle, var(--border) 1px, transparent 1px);
  background-size: 28px 28px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
#graph-view:active { cursor: grabbing; }

#graph-world {
  position: absolute;
  top: 0; left: 0;
  will-change: transform;
}

.graph-node {
  position: absolute;
  width: 110px;
  height: 110px;
  background: var(--bg-card);
  border: 2px solid var(--border-hi);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  cursor: grab;
  touch-action: none;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.graph-node:active { cursor: grabbing; }

.graph-node.graph-selected {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-dim), 0 4px 16px rgba(0,0,0,0.35);
}

/* Status border accent — thin coloured stripe at bottom */
.graph-node.graph-status-needed  { border-bottom-color: #f87171; border-bottom-width: 3px; }
.graph-node.graph-status-ordered { border-bottom-color: #facc15; border-bottom-width: 3px; }
.graph-node.graph-status-received{ border-bottom-color: #4ade80; border-bottom-width: 3px; }

.graph-node-img {
  width: 100%;
  height: 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 10px 10px 0 0;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.graph-node-img img {
  width: 100%; height: 100%; object-fit: cover;
}
.graph-node-emoji { font-size: 1.8rem; line-height: 1; }

.graph-node-name {
  font-size: 0.58rem;
  font-weight: 600;
  text-align: center;
  padding: 3px 5px 2px;
  line-height: 1.25;
  width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: var(--text);
}

.graph-node-badge {
  position: absolute;
  top: 3px; right: 4px;
  font-size: 0.65rem;
  line-height: 1;
}

@media print {
  #topbar, #bom-header, #filter-bar, #items-toolbar,
  .item-actions, .item-tile-actions, .item-tile-qty-strip,
  .toast, .modal-overlay { display: none !important; }
  body { padding-top: 0 !important; background: #fff; color: #000; }
  .item-card {
    border: 1px solid #ccc !important; break-inside: avoid;
    margin-bottom: 8px; box-shadow: none !important;
    background: #fff !important; color: #000 !important;
  }
  .item-name, .item-body { color: #000 !important; }
  .platform-btn { border: 1px solid #ccc !important; color: #333 !important; background: #f5f5f5 !important; }
  .spec-chip { border: 1px solid #ccc !important; background: #f5f5f5 !important; color: #333 !important; }
  .status-badge { border: 1px solid #999 !important; color: #333 !important; background: #eee !important; }
  #items-area { display: block !important; }
}

/* ── Progress Bar ── */
.bom-progress {
  width: 100%;
  height: 6px;
  background: var(--surface2);
  border-radius: 4px;
  margin-top: 10px;
  display: flex;
  overflow: hidden;
}
.bom-progress-received { background: var(--green); }
.bom-progress-ordered { background: var(--amber); }

/* ── Responsive Action Header ── */
.more-actions-menu { display: none; }

@media (max-width: 768px) {
  .secondary-action { display: none; }
  .more-actions-btn { display: inline-flex; }
  
  .more-actions-menu.active {
    display: flex;
    flex-direction: column;
    position: absolute;
    right: 20px;
    top: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
  }
  .more-actions-menu.active .header-btn {
    display: flex;
    width: 100%;
    text-align: left;
    margin-bottom: 4px;
  }
}
