:root {
  /* Fairtrade palette */
  --lime: #d4ff47;
  --lime-tint: #f0ffc2;
  --cyan: #0fc0fc;
  --cyan-deep: #0eade3;
  --cyan-tint: #d9f4fe;
  --teal: #035e7c;
  --teal-dark: #02455c;
  --navy: #001b6e;
  --green: #aacc39;
  --green-dark: #4d6600;
  --green-tint: #eef7d4;
  --pink: #ff4571;
  --pink-hover: #e6335f;
  --pink-tint: #ffe4ec;
  --ink: #1e1e1e;

  /* Semantic mapping */
  --bg: #ffffff;
  --surface: #ffffff;
  --inset: #f4f4f4;
  --text-main: var(--ink);
  --text-head: var(--ink);
  --text-muted: #6b6b6b;
  --warn-text: #92400e;
  --pink-border: #ffb8ca;
  --overlay: rgba(30, 30, 30, 0.5);
  --primary: var(--teal);
  --primary-hover: var(--teal-dark);
  --accent: var(--lime);
  --interactive: var(--cyan);
  --interactive-hover: var(--cyan-deep);
  --secondary: #ffffff;
  --secondary-hover: #ebebeb;
  --danger: var(--pink);
  --danger-hover: var(--pink-hover);
  --border: #dadada;
  --border-strong: #c4c4c4;
  --success: var(--green);
  --warn: #f59e0b;
  --warn-bg: #fffbeb;
  --warn-border: #fcd9b6;
  --radius: 12px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 3px rgba(30, 30, 30, 0.08);
  --shadow-md: 0 6px 20px rgba(30, 30, 30, 0.14);
  --font-head: "Exo 2", "Alegreya Sans", sans-serif;
  --font-main:
    "Alegreya Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
}

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

body {
  font-family: var(--font-main);
  font-size: 15px;
  background: var(--bg);
  color: var(--text-main);
  min-height: 100vh;
}

h1,
h2,
h3,
.cat-group-title {
  font-family: var(--font-head);
  font-weight: 800;
  color: var(--text-head);
  letter-spacing: -0.01em;
}

/* The topbar stays lime in both themes — all its text stays ink. */
.topbar {
  color: var(--ink);
}
.topbar h1,
.topbar .count {
  color: var(--ink);
}
.topbar .count {
  color: rgba(30, 30, 30, 0.65);
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

/* ---------- Top bar (signature lime block) ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background: var(--lime);
  border-radius: var(--radius);
  padding: 22px 24px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-title .logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  background: #fff;
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
  color: var(--teal);
  flex-shrink: 0;
}
.topbar h1 {
  font-size: 26px;
  font-weight: 900;
}
.count {
  font-size: 14px;
  color: rgba(30, 30, 30, 0.65);
  margin-top: 2px;
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* Account controls sit top-right, next to the title — same spot where guests
   see the login button. The action buttons flow on their own row below. */
.topbar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  align-self: flex-start;
}
.topbar .topbar-actions {
  flex-basis: 100%;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.topbar-user .username {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
}

.role-chip {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.role-admin {
  background: var(--teal);
  color: #fff;
}
.role-editor {
  background: #fff;
  color: var(--teal);
}

/* ---------- Buttons (pill) ---------- */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-pill);
  font-family: var(--font-head);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.05s,
    box-shadow 0.15s,
    border-color 0.15s;
  white-space: nowrap;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--secondary);
  color: var(--ink);
  border: 1.5px solid var(--border);
  padding: 8.5px 16.5px;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-hover);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}
.btn-accent {
  background: var(--ink);
  color: var(--lime);
}
.btn-accent:hover:not(:disabled) {
  background: #000;
}

/* Secondary buttons sitting on the lime topbar keep their white fill but drop
   the gray border, which would muddy the lime. */
.topbar .btn-secondary {
  border-color: transparent;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  position: sticky;
  top: 12px;
  z-index: 20;
}

.search-box {
  position: relative;
  flex: 1 1 280px;
  min-width: 200px;
}
.search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.6;
}
.search-box input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-main);
  outline: none;
}
.search-box input:focus {
  border-color: var(--interactive);
  box-shadow: 0 0 0 3px rgba(15, 192, 252, 0.22);
}

.segmented {
  display: inline-flex;
  background: var(--inset);
  border-radius: var(--radius-pill);
  padding: 3px;
}
.segmented .seg {
  border: none;
  background: transparent;
  padding: 7px 14px;
  font-size: 13px;
  font-family: var(--font-head);
  font-weight: 700;
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  cursor: pointer;
}
.segmented .seg.active {
  background: var(--surface);
  color: var(--teal);
  box-shadow: var(--shadow-sm);
}

.select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-main);
  background: var(--surface);
  color: var(--text-main);
  cursor: pointer;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.toggle input {
  accent-color: var(--teal);
}

/* ---------- State blocks ---------- */
.state-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 64px 16px;
  color: var(--text-muted);
  font-size: 16px;
}
.state-emoji {
  font-size: 42px;
}

/* ---------- Product grid ---------- */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

#product-count {
    font-family: var(--font-head);
}

.product-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition:
    box-shadow 0.15s,
    transform 0.15s,
    border-color 0.15s;
}
/* No translate on hover — a moving hover target flickers at the card edges. */
.product-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.product-card.low-stock {
  border-color: var(--warn-border);
}
.product-card.is-purged {
  opacity: 0.55;
}

.product-card.flash {
  animation: flash 1.6s ease;
}
@keyframes flash {
  0% {
    box-shadow: 0 0 0 3px var(--cyan);
  }
  100% {
    box-shadow: none;
  }
}

.ribbon {
  position: absolute;
  top: 10px;
  right: -6px;
  background: var(--ink);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
}

.card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.source-badge {
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.source-elpuente {
  background: var(--cyan-tint);
  color: var(--teal);
}
.source-gepa {
  background: var(--lime-tint);
  color: var(--green-dark);
}
.source-manual {
  background: var(--inset);
  color: var(--text-muted);
}

.chip {
  background: var(--inset);
  color: var(--text-muted);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
}

.card-name {
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.3;
}
.card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: -4px;
}

.card-price {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.price-main {
  font-family: var(--font-head);
  font-size: 22px;
  font-weight: 800;
  color: var(--text-head);
}
.price-reg {
  font-size: 13px;
  color: var(--text-muted);
}

.card-stock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; /* narrow cards: stepper drops below the label instead of overflowing */
  gap: 6px 8px;
  background: var(--inset);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-top: auto;
}
.card-stock .stepper {
  margin-left: auto;
}
.card-stock.is-low {
  background: var(--warn-bg);
}
.stock-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}
.card-stock.is-low .stock-label {
  color: var(--warn);
}

/* ---------- Stepper (circular, cyan — like the site's carousel arrows) ---------- */
.stepper {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.step-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--interactive);
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  color: #fff;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.step-btn:hover {
  background: var(--interactive-hover);
}
.stepper input,
.stock-input {
  width: 52px;
  height: 30px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-main);
  background: var(--surface);
  color: var(--text-main);
  -moz-appearance: textfield;
  appearance: textfield;
}
/* The circular +/- buttons replace the native number spinner. */
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button,
.stock-input::-webkit-outer-spin-button,
.stock-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.card-stock.is-low .stock-input {
  color: var(--warn);
  border-color: var(--warn-border);
}

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 520px;
  max-width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 48px rgba(30, 30, 30, 0.25);
  transform: translateY(12px);
  transition: transform 0.18s;
}
.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 20px;
  font-weight: 800;
}
.modal-close {
  border: none;
  background: transparent;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-close:hover {
  color: var(--text-main);
  background: var(--inset);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}
.modal-footer .spacer {
  flex: 1;
}

/* ---------- Wizard panels ---------- */
.wizard-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Wizard steps ---------- */
.wizard-steps {
  display: flex;
  gap: 6px;
  padding: 14px 24px 0;
}
.wstep {
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-family: var(--font-head);
  font-weight: 700;
  color: var(--text-muted);
  padding: 8px 4px;
  border-bottom: 2px solid var(--border);
}
.wstep.active {
  color: var(--teal);
  border-color: var(--teal);
}
.wstep.done {
  color: var(--green-dark);
  border-color: var(--green);
}

/* ---------- Forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}
.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.field textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-main);
  outline: none;
  resize: vertical;
}
.field input:focus,
.field textarea:focus {
  border-color: var(--interactive);
  box-shadow: 0 0 0 3px rgba(15, 192, 252, 0.22);
}

.hint {
  font-size: 13px;
  color: var(--text-muted);
}
.hint code {
  background: var(--inset);
  padding: 1px 5px;
  border-radius: 4px;
}

.advanced summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
}
.advanced[open] summary {
  margin-bottom: 12px;
}

.inline-error {
  background: var(--pink-tint);
  color: var(--danger-hover);
  border: 1px solid var(--pink-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.banner {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Preview card (wizard confirm + editor header) ---------- */
.preview-card {
  background: var(--inset);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  gap: 14px;
}
.pc-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.pc-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.pc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pc-sku {
  font-size: 13px;
  color: var(--text-muted);
}
.pc-name {
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 700;
}
.pc-price {
  font-size: 15px;
}
.pc-calc {
  color: var(--teal);
  font-weight: 700;
  margin-left: 6px;
}
.pc-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pc-link {
  font-size: 14px;
  color: var(--teal);
  text-decoration: none;
  font-weight: 600;
}
.pc-link:hover {
  text-decoration: underline;
}

/* ---------- Category tabs (pills) ---------- */
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding-bottom: 4px;
}
.tab {
  border: none;
  background: transparent;
  padding: 9px 18px;
  font-size: 14px;
  font-family: var(--font-head);
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-radius: var(--radius-pill);
  transition:
    background 0.15s,
    color 0.15s;
}
.tab:hover {
  color: var(--text-main);
  background: var(--inset);
}
.tab.active {
  background: var(--ink);
  color: var(--lime);
}

/* ---------- Category group sections (Alle view) ---------- */
.cat-group {
  margin-bottom: 28px;
}
.cat-group-title {
  font-size: 19px;
  font-weight: 800;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.cat-group-count {
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--inset);
  border-radius: var(--radius-pill);
  padding: 2px 9px;
}

/* ---------- Card image ---------- */
.card-img {
  width: 100%;
  height: 130px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.img-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--inset);
  border: 1px dashed var(--border);
  color: var(--text-muted);
}
.img-fallback i {
  font-size: 30px;
  opacity: 0.4;
}

/* ---------- Categories manager ---------- */
.cat-manage-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.cat-row.dragging {
  opacity: 0.5;
}
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 16px;
  user-select: none;
}
.cat-name-input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-main);
  background: transparent;
}
.cat-name-input:focus {
  border-color: var(--interactive);
  background: var(--surface);
  outline: none;
}
.cat-row-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-main); /* buttons don't inherit text color */
  cursor: pointer;
  font-size: 15px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--secondary-hover);
}
.cat-empty {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 12px;
}
.cat-add-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.cat-add-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-main);
}

/* ---------- Category select + inline new input ---------- */
.cat-new {
  margin-top: 8px;
}

/* ---------- Large / tall modals ---------- */
.modal-large {
  width: 900px;
  max-width: 100%;
} /* height follows content */
.modal-tall {
  height: 88vh;
} /* preview needs a tall iframe */
.preview-body {
  padding: 0;
  flex: 1;
  overflow: hidden;
}
#preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--inset);
}

/* ---------- Update check ---------- */
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--inset);
  border-top-color: var(--interactive);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.upd-summary {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* Live progress (during the check) */
.upd-progress {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.upd-progress-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}
.upd-bar {
  height: 8px;
  background: var(--inset);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.upd-bar-fill {
  height: 100%;
  width: 0;
  background: var(--interactive);
  border-radius: var(--radius-pill);
  transition: width 0.2s ease;
}
.upd-live {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
}
.upd-live li {
  padding: 4px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.upd-live li:nth-child(odd) {
  background: var(--inset);
}
.li-ok {
  color: var(--green-dark);
}
.li-chg {
  color: var(--cyan-deep);
}
.li-err {
  color: var(--danger);
}

.upd-product {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.upd-product-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.upd-change {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.upd-change input {
  accent-color: var(--teal);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}
.upd-field {
  font-size: 13px;
  font-weight: 600;
  width: 110px;
  flex-shrink: 0;
}
.upd-values {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  min-width: 0;
}
.upd-old {
  color: var(--danger);
  text-decoration: line-through;
  opacity: 0.8;
}
.upd-new {
  color: var(--green-dark);
  font-weight: 600;
}
.upd-arrow {
  color: var(--text-muted);
}
.upd-thumb {
  height: 34px;
  width: 34px;
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 5px;
  vertical-align: middle;
}
.muted {
  color: var(--text-muted);
}

.upd-errors {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.upd-errors summary {
  cursor: pointer;
  font-weight: 600;
}
.upd-errors ul {
  margin: 8px 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---------- Icon alignment + sort control ---------- */
.btn i,
.toggle i,
.avail-chip i,
.tab i,
.pc-link i {
  vertical-align: -0.08em;
}
.avail-chip i {
  font-size: 10px;
}
.upd-live i,
.cat-del i,
.drag-handle i {
  vertical-align: -0.1em;
}

.sort-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sort-dir {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ---------- Availability chip + check ---------- */
.avail-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.avail-in {
  background: var(--green-tint);
  color: var(--green-dark);
}
.avail-out {
  background: var(--pink-tint);
  color: var(--danger-hover);
}
.avl-soldrow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

/* ---------- VPE formula proposals ---------- */
.fml-row {
  align-items: center;
}
.fml-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
}

/* ---------- Toasts ---------- */
#toast-host {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-md);
  font-size: 14px;
  max-width: 380px;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast i {
  font-size: 16px;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toast-success i {
  background: var(--green-tint);
  color: var(--green-dark);
}
.toast-error i {
  background: var(--pink-tint);
  color: var(--danger-hover);
}
.toast-info i {
  background: var(--cyan-tint);
  color: var(--cyan-deep);
}

/* ---------- Confirm dialog ---------- */
.modal-confirm {
  width: 420px;
}
.modal-confirm .modal-body p {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-main);
}

/* ---------- Editor image upload ---------- */
.img-edit {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.img-edit-preview {
  width: 96px;
  height: 96px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.img-edit-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.img-edit-preview.is-empty {
  background: var(--inset);
  border-style: dashed;
}
.img-edit-preview i {
  font-size: 32px;
  color: var(--text-muted);
  opacity: 0.5;
}
.img-edit-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.img-edit-actions .btn {
  padding: 8px 12px;
  font-size: 13px;
}

/* ---------- Users manager ---------- */
.user-row-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
}
.user-add-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.user-add-row input {
  flex: 1 1 130px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font-main);
}
.user-add-row .select {
  flex: 0 0 auto;
}

/* ---------- Guest mode (belt-and-suspenders: editor nodes are also removed
   from the DOM by script.js; guests do get .guest-price — the selling price) */
body.guest .card-stock,
body.guest .card-edit,
body.guest .card-price,
body.guest .source-badge,
body.guest .ribbon {
  display: none !important;
}

.guest-price {
  margin-top: auto;
}

/* Guest hero: the catalog is the public storefront — bigger, friendlier,
   login demoted to a quiet pill. */
body.guest .topbar {
  padding: 34px 32px;
}
body.guest .topbar h1 {
  font-size: 34px;
}
body.guest .topbar .count {
  font-size: 15px;
}
body.guest .topbar-title .logo {
  width: 60px;
  height: 60px;
  font-size: 32px;
}
body.guest #btn-login {
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  font-size: 13px;
  padding: 8px 14px;
}
body.guest #btn-login:hover:not(:disabled) {
  background: #fff;
}
body.guest .product-card {
  cursor: pointer;
}

/* Clickable card areas for editors */
body:not(.guest) .card-img,
body:not(.guest) .card-name {
  cursor: pointer;
}

/* ---------- Product detail page ---------- */
.detail-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 90;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(14px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
  pointer-events: none;
}
.detail-overlay.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.detail-overlay[hidden] {
  display: none;
}
body.detail-open {
  overflow: hidden;
}

.detail-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}
.detail-back {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--lime);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  transition:
    transform 0.15s ease,
    background 0.15s;
}
.detail-back:hover {
  transform: translateX(-3px);
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}

/* Carousel */
.carousel {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}
.carousel-track {
  display: flex;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.carousel-track .car-slide {
  flex: 0 0 100%;
  min-width: 0;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.carousel-track .car-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.car-slide.img-fallback i {
  font-size: 56px;
  color: var(--text-muted);
  opacity: 0.4;
}

.car-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--cyan);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    transform 0.15s;
  box-shadow: var(--shadow-sm);
}
.car-btn:hover {
  background: var(--cyan-deep);
}
.car-prev {
  left: 12px;
}
.car-next {
  right: 12px;
}
.car-prev:hover {
  transform: translateY(-50%) translateX(-2px);
}
.car-next:hover {
  transform: translateY(-50%) translateX(2px);
}
.carousel.single .car-btn,
.carousel.single .car-dots {
  display: none;
}

.car-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  display: flex;
  justify-content: center;
  gap: 7px;
}
.car-dot {
  width: 9px;
  height: 9px;
  border: none;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  padding: 0;
  transition:
    background 0.15s,
    transform 0.15s;
}
.car-dot.active {
  background: var(--cyan);
  transform: scale(1.25);
}

/* Detail info column */
.detail-info {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}
.detail-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.detail-info h2 {
  font-size: 34px;
  font-weight: 900;
  line-height: 1.1;
  margin: 0;
}
.detail-sub {
  color: var(--text-muted);
  font-size: 15px;
  margin-top: -6px;
}
.detail-price {
  font-family: var(--font-head);
  font-size: 32px;
  font-weight: 800;
  color: var(--ink);
  background: var(--lime);
  align-self: flex-start;
  padding: 6px 18px;
  border-radius: var(--radius-pill);
}
.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.detail-badge {
  background: var(--inset);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
}
.detail-summary {
  font-size: 16px;
  line-height: 1.55;
  color: var(--text-main);
}
.detail-summary p {
  margin: 0 0 8px;
}
.detail-meta {
  background: var(--inset);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}
.detail-meta .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.detail-meta .row span:first-child {
  color: var(--text-muted);
}
.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

@media (max-width: 760px) {
  .detail-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  .detail-info h2 {
    font-size: 26px;
  }
}

/* ---------- Gallery editing (editor dialog) ---------- */
.gallery-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.gallery-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}
.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.gallery-thumb .g-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(30, 30, 30, 0.65);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.gallery-thumb .g-del:hover {
  background: var(--pink);
}
.gallery-empty {
  font-size: 13px;
  color: var(--text-muted);
}

/* ---------- Hover-zoom on the detail carousel (pointer devices only) ----------
   transform-origin transitions too, so the magnified area glides with the
   cursor instead of jumping (jitter near the corners otherwise). */
@media (hover: hover) and (pointer: fine) {
  .car-slide img {
    transition:
      transform 0.18s ease,
      transform-origin 0.18s ease;
    cursor: zoom-in;
  }
  .car-slide:hover img {
    transform: scale(1.8);
  }
}
.car-slide img {
  cursor: zoom-in;
}

/* ---------- Lightbox (fullscreen image, pinch/wheel zoom) ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 20, 0.94);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.lightbox.active {
  opacity: 1;
  pointer-events: auto;
}
.lightbox[hidden] {
  display: none;
}

.lb-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none; /* we handle pinch/pan ourselves */
}
#lb-img {
  max-width: 92vw;
  max-height: 88vh;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: center center;
  cursor: grab;
}
#lb-img.dragging {
  cursor: grabbing;
}

.lb-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 19px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: background 0.15s;
}
.lb-close:hover {
  background: rgba(255, 255, 255, 0.28);
}
.lb-prev,
.lb-next {
  z-index: 2;
}
.lb-prev {
  left: 16px;
}
.lb-next {
  right: 16px;
}
.lightbox.single .lb-prev,
.lightbox.single .lb-next {
  display: none;
}

.lb-hint {
  position: absolute;
  bottom: 16px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  pointer-events: none;
  transition: opacity 0.4s;
}
/* ---------- Animations ---------- */
.product-card {
  animation: card-in 0.4s ease backwards;
}
@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}
.card-img {
  transition: transform 0.25s ease;
}
.product-card:hover .card-img,
.product-card:hover.product-card > img.card-img {
  transform: scale(1.04);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.15s,
    transform 0.2s;
}
.theme-toggle:hover {
  background: #fff;
  transform: rotate(15deg);
}

/* ---------- Badge images ---------- */
.detail-badge-img {
  height: 46px;
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
}
.detail-badge-img img {
  height: 100%;
  width: auto;
  max-width: 110px;
  object-fit: contain;
}

/* ---------- Dark theme ---------- */
:root[data-theme="dark"] {
  --bg: #161616;
  --surface: #222222;
  --inset: #2c2c2c;
  --text-main: #ececec;
  --text-head: #f5f5f5;
  --text-muted: #a0a0a0;
  --border: #3d3d3d;
  --border-strong: #575757;
  --secondary: #2a2a2a;
  --secondary-hover: #383838;
  --overlay: rgba(0, 0, 0, 0.65);
  --primary: #0b7396;
  --primary-hover: #0d86ae;
  --lime-tint: #37420f;
  --cyan-tint: #10333f;
  --green-tint: #26350e;
  --green-dark: #bcdb56;
  --pink-tint: #45202b;
  --pink-border: #6e2b3d;
  --danger-hover: #ff6b8e;
  --warn-bg: #3a2e10;
  --warn-text: #eab308;
  --warn-border: #5c471a;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.55);
}
/* Secondary buttons keep dark text only on the lime topbar */
:root[data-theme="dark"] .btn-secondary {
  color: var(--text-main);
}
:root[data-theme="dark"] .topbar .btn-secondary {
  background: #fff;
  color: var(--ink);
}
/* The active pill needs a step up from the inset track, not surface-on-inset */
:root[data-theme="dark"] .segmented .seg.active {
  background: #3f3f3f;
  color: var(--cyan);
}
/* Solid cyan circles glare on dark surfaces — mute to tint + cyan glyph */
:root[data-theme="dark"] .step-btn {
  background: #1b4354;
  color: var(--cyan);
}
:root[data-theme="dark"] .step-btn:hover {
  background: #235568;
}
/* Teal is a light-theme text color — swap for cyan on dark surfaces */
:root[data-theme="dark"] .source-elpuente,
:root[data-theme="dark"] .pc-calc,
:root[data-theme="dark"] .pc-link,
:root[data-theme="dark"] .wstep.active {
  color: var(--cyan);
}
:root[data-theme="dark"] .wstep.active {
  border-color: var(--cyan);
}
/* Ink pill would vanish on a dark page — invert to lime */
:root[data-theme="dark"] .tab.active {
  background: var(--lime);
  color: var(--ink);
}
:root[data-theme="dark"] .btn-accent {
  background: var(--lime);
  color: var(--ink);
}
:root[data-theme="dark"] .btn-accent:hover:not(:disabled) {
  background: #e2ff75;
}
/* Product photos keep a white plate so they read correctly */
:root[data-theme="dark"] .card-img,
:root[data-theme="dark"] .pc-img,
:root[data-theme="dark"] .upd-thumb,
:root[data-theme="dark"] .img-edit-preview,
:root[data-theme="dark"] .gallery-thumb,
:root[data-theme="dark"] .carousel,
:root[data-theme="dark"] .detail-badge-img {
  background: #fff;
}
:root[data-theme="dark"] .img-fallback,
:root[data-theme="dark"] .img-edit-preview.is-empty {
  background: var(--inset);
}
:root[data-theme="dark"] .car-dot {
  background: #555;
}
:root[data-theme="dark"] .car-dot.active {
  background: var(--cyan);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .app {
    padding: 14px;
  }
  .topbar {
    padding: 16px;
  }
  /* Account controls become their own tidy row under the title */
  .topbar-account {
    flex-basis: 100%;
    margin-left: 0;
    align-self: auto;
    flex-wrap: wrap;
  }
  .topbar-actions {
    width: 100%;
  }
  .topbar-actions .btn {
    flex: 1;
  }
  .toolbar {
    position: static;
  }
  .stepper input,
  .stock-input {
    width: 44px;
  }
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }
  .modal {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
  }
  .modal-overlay {
    padding: 0;
  }
}

/* ---------- Small text in the heading font (numbers render crisper in
   Exo 2 than in Alegreya Sans) ---------- */
.count,
.price-reg,
.card-sub,
.stock-label,
.cat-group-count,
.cat-row-count,
.chip,
.avail-chip,
.source-badge,
.role-chip,
.pc-sku,
.pc-price,
.stepper input,
.stock-input,
.detail-meta,
.detail-badge,
.hint,
.toggle {
  font-family: var(--font-head);
}

/* ---------- Inputs follow the theme (no UA-default white in dark mode) ---------- */
.field input[type="text"],
.field input[type="number"],
.field input[type="password"],
.field textarea,
.search-box input,
.cat-add-row input,
.user-add-row input {
  background: var(--surface);
  color: var(--text-main);
}
