:root {
  --surface: #f7f8fb;
  --surface-strong: #ffffff;
  --ink: #1f2933;
  --muted: #657486;
  --soft: #eef2f6;
  --line: #d9e1ea;
  --brand: #356c8f;
  --brand-dark: #204d6a;
  --accent: #c54965;
  --success: #26795f;
  --danger: #b4233b;
  --warning: #a86808;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Montserrat', Arial, sans-serif;
  color: var(--ink);
  background: var(--surface);
}

button,
input,
textarea,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.top-stripe {
  height: 6px;
  background: linear-gradient(90deg, #356c8f, #67a0a7, #c54965);
}

.admin-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 32px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-family: 'Playfair Display', Georgia, serif;
  color: var(--ink);
}

h1 {
  font-size: 34px;
  line-height: 1;
}

.header-copy {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.save-state {
  min-width: 120px;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.save-state.dirty {
  color: var(--warning);
}

.save-state.saved {
  color: var(--success);
}

.save-state.error {
  color: var(--danger);
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.2s;
}

.primary-btn {
  background: var(--brand);
  color: #ffffff;
}

.primary-btn:hover:not(:disabled) {
  background: var(--brand-dark);
  transform: translateY(-1px);
}

.primary-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.save-btn {
  box-shadow: 0 10px 24px rgba(53, 108, 143, 0.25);
}

.secondary-btn {
  background: var(--ink);
  color: #ffffff;
}

.secondary-btn:hover {
  background: #111820;
}

.ghost-btn {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.danger-btn {
  background: #ffffff;
  color: var(--danger);
  border-color: rgba(180, 35, 59, 0.28);
}

.danger-btn:hover {
  background: #fff1f3;
  border-color: var(--danger);
}

.admin-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px 32px 48px;
}

.admin-tools {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) minmax(160px, 0.7fr) minmax(170px, 0.7fr) auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
}

.tool-group,
.card-fields label,
.token-dialog label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: #ffffff;
  outline: none;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(53, 108, 143, 0.12);
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 42px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 14px;
}

.summary-row strong {
  margin-right: 10px;
  color: var(--ink);
}

.draft-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #f2c46d;
  border-radius: 8px;
  background: #fff8e8;
  color: #674100;
}

.draft-notice button {
  border: none;
  background: transparent;
  color: var(--brand);
  font-weight: 700;
}

.products-loading,
.products-error,
.empty-state {
  display: grid;
  place-items: center;
  gap: 12px;
  min-height: 280px;
  text-align: center;
  color: var(--muted);
}

.products-error[hidden],
.empty-state[hidden],
.draft-notice[hidden] {
  display: none;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.admin-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.admin-card {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 10px 28px rgba(31, 41, 51, 0.07);
}

.admin-card.changed {
  border-color: rgba(53, 108, 143, 0.7);
  box-shadow: 0 12px 32px rgba(53, 108, 143, 0.14);
}

.card-preview {
  background: #ffffff;
}

.product-img {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--soft);
  cursor: pointer;
}

.img-upload-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 41, 51, 0.48);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.3px;
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
}

.product-img:hover .img-upload-overlay {
  opacity: 1;
}

.product-img.drag-over-img .img-upload-overlay {
  opacity: 1;
  background: rgba(53, 108, 143, 0.6);
}

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

.product-img.uploading::after {
  content: 'Lista para subir';
  position: absolute;
  right: 12px;
  bottom: 12px;
  border-radius: 8px;
  padding: 5px 9px;
  color: #ffffff;
  background: rgba(31, 41, 51, 0.78);
  font-size: 11px;
  font-weight: 700;
}

.product-img img[src=""],
.product-img img:not([src]) {
  display: none;
}

.placeholder-icon {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.badge {
  position: absolute;
  top: 12px;
  left: 12px;
  display: none;
  max-width: calc(100% - 24px);
  overflow: hidden;
  border-radius: 8px;
  padding: 5px 10px;
  color: #ffffff;
  background: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge.visible {
  display: block;
}

.product-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  text-align: center;
}

.wysiwyg-input,
.wysiwyg-textarea {
  border: 1px dashed var(--line);
  background: rgba(238, 242, 246, 0.45);
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.wysiwyg-input:hover,
.wysiwyg-textarea:hover {
  border-color: var(--muted);
  background: #ffffff;
}

.preview-name {
  min-height: 38px;
  padding: 6px 8px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
}

.preview-description {
  min-height: 64px;
  padding: 6px 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.price-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preview-price,
.preview-offer {
  min-height: 36px;
  color: var(--brand);
  font-size: 16px;
  font-weight: 800;
}

.preview-offer {
  color: var(--accent);
}

.chip-preview {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  min-height: 18px;
}

.color-dot {
  width: 14px;
  height: 14px;
  border: 1px solid rgba(31, 41, 51, 0.18);
  border-radius: 50%;
  flex: 0 0 auto;
}

.sizes {
  min-height: 17px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.card-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #fbfcfe;
}

.upload-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.image-dropzone {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 138px;
  padding: 18px;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.image-dropzone.compact {
  min-height: 52px;
  padding: 10px 18px;
}

.image-dropzone strong {
  color: var(--ink);
  font-size: 14px;
}

.image-dropzone span {
  font-size: 12px;
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.plus-btn {
  color: var(--brand);
}

.image-dropzone.drag-over {
  border-color: var(--brand);
  background: #f0f7fb;
  color: var(--brand);
}

.image-url-input {
  font-size: 12px;
}

.extra-images-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.extra-thumb {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

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

.extra-thumb.pending::after {
  content: 'Subir';
  position: absolute;
  left: 6px;
  bottom: 6px;
  border-radius: 8px;
  padding: 3px 6px;
  color: #ffffff;
  background: rgba(31, 41, 51, 0.76);
  font-size: 10px;
  font-weight: 700;
}

.remove-image {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  min-height: 24px;
  padding: 0;
  border: none;
  border-radius: 8px;
  color: #ffffff;
  background: rgba(31, 41, 51, 0.75);
  font-size: 16px;
  line-height: 1;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.color-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.selected-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
}

.selected-color-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 7px 5px 9px;
  background: #ffffff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.remove-color {
  width: 22px;
  min-height: 22px;
  padding: 0;
  border: none;
  border-radius: 8px;
  color: var(--muted);
  background: var(--soft);
  font-size: 14px;
  line-height: 1;
}

.remove-color:hover {
  color: #ffffff;
  background: var(--danger);
}

.color-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.custom-color-row {
  grid-template-columns: minmax(0, 1fr) 52px auto;
}

.custom-color-hex {
  min-width: 52px;
  padding: 6px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.check-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  color: var(--ink) !important;
  font-size: 13px !important;
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.token-dialog,
.app-dialog {
  width: min(420px, calc(100vw - 32px));
  border: none;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.token-dialog::backdrop,
.app-dialog::backdrop {
  background: rgba(31, 41, 51, 0.45);
}

.token-dialog form,
.app-dialog form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
}

.token-dialog p,
.app-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

@media (max-width: 1180px) {
  .admin-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .admin-header {
    align-items: flex-start;
    padding: 16px;
  }

  h1 {
    font-size: 28px;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .save-state {
    width: 100%;
    min-width: 0;
    text-align: left;
  }

  .admin-shell {
    padding: 18px 16px 40px;
  }

  .admin-tools,
  .admin-grid,
  .field-grid,
  .color-row,
  .custom-color-row {
    grid-template-columns: 1fr;
  }

  .summary-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .draft-notice {
    align-items: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 520px) {
  .admin-header {
    position: static;
  }

  .primary-btn,
  .secondary-btn,
  .ghost-btn,
  .danger-btn {
    width: 100%;
  }

  .card-footer,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .extra-images-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ── Card top bar ── */
.card-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 0;
  min-height: 32px;
}

.card-checkbox-wrap {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.card-checkbox {
  width: 16px;
  min-height: 16px;
  cursor: pointer;
}

.completeness-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(197, 73, 101, 0.1);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drag-handle {
  color: var(--line);
  font-size: 18px;
  line-height: 1;
  cursor: grab;
  padding: 2px 4px;
  border-radius: 4px;
  user-select: none;
  transition: color 0.15s;
}

.drag-handle:hover {
  color: var(--muted);
}

.drag-handle:active {
  cursor: grabbing;
}

/* ── Drag states ── */
.admin-card.dragging {
  opacity: 0.45;
  outline: 2px dashed var(--brand);
  outline-offset: -2px;
}

.admin-card.drop-target {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
  box-shadow: 0 0 0 4px rgba(53, 108, 143, 0.15);
}

@keyframes highlight-flash {
  0%   { box-shadow: 0 0 0 4px rgba(53, 108, 143, 0.55); }
  100% { box-shadow: 0 10px 28px rgba(31, 41, 51, 0.07); }
}

.admin-card.highlight-flash {
  animation: highlight-flash 1.2s ease-out forwards;
}

/* ── Card footer actions ── */
.card-footer-actions {
  display: flex;
  gap: 8px;
}

/* ── Bulk toolbar ── */
.bulk-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: #f0f7fb;
}

.bulk-toolbar[hidden] {
  display: none;
}

.bulk-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
  white-space: nowrap;
}

.bulk-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bulk-actions select {
  min-height: 36px;
  font-size: 13px;
  width: auto;
}

.bulk-actions .ghost-btn,
.bulk-actions .danger-btn {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13px;
  white-space: nowrap;
}

/* ── Publish dialog ── */
.publish-dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  border: none;
  border-radius: 12px;
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.publish-dialog::backdrop {
  background: rgba(31, 41, 51, 0.5);
}

.publish-dialog-inner {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
}

.publish-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.publish-summary-lead {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  flex: 0 0 auto;
  transition: border-color 0.15s, color 0.15s;
}

.icon-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.publish-sections {
  overflow-y: auto;
  flex: 1 1 auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.publish-dialog .dialog-actions {
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
  margin-top: 0;
}

.publish-section-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
}

.publish-section-added .publish-section-title { color: var(--success); }
.publish-section-deleted .publish-section-title { color: var(--danger); }
.publish-section-modified .publish-section-title { color: var(--warning); }

.publish-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.publish-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.publish-item-img-wrap {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--soft);
  flex: 0 0 52px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.publish-item-no-img {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.publish-item-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.publish-item-info strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.publish-item-detail {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.publish-item-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.publish-item-actions .ghost-btn,
.publish-item-actions .danger-btn {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 12px;
  white-space: nowrap;
}

/* ── Toast ── */
.toast-stack {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  min-width: 220px;
  max-width: 340px;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background: var(--ink);
  box-shadow: 0 8px 24px rgba(31, 41, 51, 0.22);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-warning { background: var(--warning); }

/* ── Image hover popover ── */
.image-popover {
  position: fixed;
  z-index: 8888;
  width: 220px;
  height: 220px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(31, 41, 51, 0.22);
  pointer-events: none;
  border: 1px solid var(--line);
  background: var(--soft);
}

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

@media (max-width: 760px) {
  .bulk-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .publish-dialog-header {
    padding: 16px 16px 12px;
  }

  .publish-sections {
    padding: 12px 16px;
  }

  .publish-dialog .dialog-actions {
    padding: 12px 16px;
  }

  .card-footer-actions {
    flex-direction: column;
  }
}
