/* Panda — So sánh ảnh sản phẩm */

:root {
  --bg: #f3f6f6;
  --surface: #ffffff;
  --surface-2: #eaf0f0;
  --border: #d7e0e0;
  --text: #172225;
  --text-muted: #5b6c6e;
  --accent-before: #2e6b80;
  --accent-before-soft: #dcebf0;
  --accent-after: #c97328;
  --accent-after-soft: #f8e7d3;
  --danger: #b8433a;
  --danger-soft: #f6dedc;
  --focus: #2e6b80;
  --shadow: 0 1px 2px rgba(23, 34, 37, 0.06), 0 6px 20px rgba(23, 34, 37, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10171a;
    --surface: #182226;
    --surface-2: #1f2b2f;
    --border: #2c3a3e;
    --text: #e6eeee;
    --text-muted: #93a7aa;
    --accent-before: #5fb0c7;
    --accent-before-soft: #1d3540;
    --accent-after: #e8a25a;
    --accent-after-soft: #3d2c18;
    --danger: #e37167;
    --danger-soft: #3a201d;
    --focus: #5fb0c7;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --bg: #10171a;
  --surface: #182226;
  --surface-2: #1f2b2f;
  --border: #2c3a3e;
  --text: #e6eeee;
  --text-muted: #93a7aa;
  --accent-before: #5fb0c7;
  --accent-before-soft: #1d3540;
  --accent-after: #e8a25a;
  --accent-after-soft: #3d2c18;
  --danger: #e37167;
  --danger-soft: #3a201d;
  --focus: #5fb0c7;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body {
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; }

h1, h2, h3 {
  font-family: "Archivo", system-ui, sans-serif;
  font-weight: 700;
  text-wrap: balance;
  margin: 0;
}

.mono {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
}

a { color: var(--accent-before); }
a:focus-visible, button:focus-visible, textarea:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.eyebrow {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 4px;
}

.topbar h1 { font-size: 22px; }

.back-link {
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 13px;
  text-decoration: none;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.back-link:hover { color: var(--accent-before); }

button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
button:hover { border-color: var(--accent-before); }

button.primary {
  background: var(--accent-before);
  border-color: var(--accent-before);
  color: #fff;
}
button.primary:hover { opacity: 0.92; }

button.danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 6px 8px;
}
button.danger-ghost:hover { color: var(--danger); border-color: var(--danger); }

/* ---- index.html: paste panel ---- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 24px;
}

.panel h2 {
  font-size: 15px;
  margin-bottom: 4px;
}

.panel .hint {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0 0 14px;
}

.panel .hint code {
  font-family: "IBM Plex Mono", monospace;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  line-height: 1.55;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.paste-warning {
  font-size: 12.5px;
  color: var(--danger);
  margin: 10px 0 0;
  white-space: pre-wrap;
}

/* ---- product table ---- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

thead th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

.product-name { font-weight: 600; }

.product-url {
  display: inline-block;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  font-size: 12.5px;
}

.code-chip {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  color: var(--text-muted);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-muted);
}
.empty-state p { margin: 6px 0 0; font-size: 13.5px; }

footer.note {
  margin-top: 28px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ---- product.html: compare stage ---- */

.product-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.product-meta .ext-link {
  font-size: 12.5px;
  color: var(--text-muted);
  text-decoration: none;
}
.product-meta .ext-link:hover { color: var(--accent-before); }

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.mode-toggle button {
  border: none;
  border-radius: 0;
  background: var(--surface);
}
.mode-toggle button[aria-pressed="true"] {
  background: var(--accent-before-soft);
  color: var(--accent-before);
}
.mode-toggle button + button { border-left: 1px solid var(--border); }

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 12px;
  flex-wrap: wrap;
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: var(--stage-ratio, 4 / 3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  user-select: none;
  touch-action: none;
}

.stage img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

.stage .layer-after {
  clip-path: inset(0 calc(100% - var(--pos, 50%)) 0 0);
}

.stage .chip {
  position: absolute;
  top: 12px;
  z-index: 3;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  pointer-events: none;
}
.chip-before { left: 12px; background: var(--accent-before); }
.chip-after { right: 12px; background: var(--accent-after); }

.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos, 50%);
  width: 2px;
  background: #fff;
  transform: translateX(-1px);
  z-index: 4;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.handle {
  position: absolute;
  top: 50%;
  left: var(--pos, 50%);
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 5;
  cursor: ew-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.handle:active { cursor: grabbing; }
.handle svg { width: 18px; height: 18px; }

.side-by-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.side-by-side .pane {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--shadow);
  aspect-ratio: var(--stage-ratio, 4 / 3);
  background: var(--surface-2);
}
.side-by-side .pane img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.side-by-side .chip { position: absolute; top: 12px; }

.hidden { display: none !important; }

.missing-state {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-muted);
}
.missing-state .path {
  display: inline-block;
  margin-top: 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);
}

/* ---- photo pool ---- */

.pool-dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 22px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  background: var(--surface-2);
}
.pool-dropzone.drag-over {
  border-color: var(--accent-before);
  color: var(--accent-before);
  background: var(--accent-before-soft);
}
.pool-dropzone input { display: none; }

.pool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-top: 14px;
}
.pool-grid:empty { margin-top: 0; }

.pool-thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  border: 2px solid transparent;
  cursor: grab;
  background: var(--surface-2);
}
.pool-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  -webkit-user-drag: element;
}
.pool-thumb.selected {
  border-color: var(--accent-before);
  box-shadow: 0 0 0 2px var(--accent-before-soft);
}
.pool-thumb .used-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: center;
  background: rgba(23, 34, 37, 0.68);
  color: #fff;
  border-radius: 4px;
  padding: 2px 4px;
}
.pool-thumb .thumb-del {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  background: rgba(23, 34, 37, 0.68);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.pool-thumb:hover .thumb-del,
.pool-thumb:focus-within .thumb-del { opacity: 1; }

/* ---- pair tabs ---- */

.pair-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.pair-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-size: 13px;
  font-weight: 500;
  background: var(--surface);
  cursor: pointer;
}
.pair-tab.active {
  border-color: var(--accent-before);
  background: var(--accent-before-soft);
  color: var(--accent-before);
  font-weight: 600;
}
.pair-tab .pair-del {
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.55;
  padding: 2px 4px;
  font-size: 12px;
  border-radius: 999px;
}
.pair-tab .pair-del:hover { opacity: 1; color: var(--danger); }

.pair-add {
  border: 1px dashed var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 16px;
  font-size: 13px;
}
.pair-add:hover { color: var(--accent-before); border-color: var(--accent-before); }

/* ---- upload tiles ---- */

.uploader-row {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 20px;
  margin-top: 14px;
  align-items: start;
}
@media (max-width: 620px) {
  .uploader-row { grid-template-columns: 1fr; }
}

.slot-heading {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin: 0 0 6px;
}
.slot-heading.before { color: var(--accent-before); }
.slot-heading.after { color: var(--accent-after); }
.slot-count { color: var(--text-muted); font-weight: 400; }

.upload-tile {
  position: relative;
  border: 1px dashed var(--border);
  border-radius: 12px;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 12.5px;
  overflow: hidden;
}
.upload-tile.drag-over {
  border-color: var(--accent-before);
  color: var(--accent-before);
  background: var(--accent-before-soft);
}
.upload-tile.has-image {
  border-style: solid;
  padding: 0;
}
.upload-tile.has-image img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
}
.upload-tile .tile-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(23, 34, 37, 0.55);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.upload-tile.has-image:hover .tile-overlay { opacity: 1; }
.upload-tile.has-image .tile-hint { display: none; }

/* ---- after gallery (nhiều ảnh Sau trong 1 hàng) ---- */

.after-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.after-thumb {
  position: relative;
  width: 140px;
  height: 160px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
}
.after-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.after-thumb.active {
  border-color: var(--accent-after);
  box-shadow: 0 0 0 2px var(--accent-after-soft);
}
.after-thumb .thumb-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(23, 34, 37, 0.68);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.after-add-tile {
  width: 140px;
  height: 160px;
  flex-shrink: 0;
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}
.after-add-tile.drag-over {
  border-color: var(--accent-after);
  color: var(--accent-after);
  background: var(--accent-after-soft);
}

.upload-status {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 10px 0 0;
  min-height: 16px;
}
.upload-status.error { color: var(--danger); }
.upload-status.busy { color: var(--accent-before); }

.pair-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

@media (max-width: 620px) {
  .side-by-side { grid-template-columns: 1fr; }
  .product-url { max-width: 140px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- xem tất cả ảnh (báo cáo) ---- */

.view-actions { display: flex; gap: 8px; }

.after-picker.hidden { display: none; }

#viewAllArea {
  max-width: none;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  padding: 0 24px;
  box-sizing: border-box;
}

.va-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.va-table thead th {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  padding: 12px 20px;
}
.va-table thead th.before { color: var(--accent-before); background: var(--accent-before-soft); }
.va-table thead th.after { color: var(--accent-after); background: var(--accent-after-soft); }
.va-table tr.va-group-header th {
  text-align: left;
  padding: 18px 20px 4px;
  background: var(--surface);
  border-top: 3px solid var(--border);
}
.va-table tbody tr.va-group-header:first-child th { border-top: none; }
.va-group-title { font-size: 14px; font-weight: 600; margin: 0; }
.va-group-count { font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--text-muted); margin: 3px 0 0; font-weight: 400; }
.va-table tbody td { padding: 10px 20px 18px; vertical-align: top; width: 50%; }
.va-table a.va-cell { text-decoration: none; color: inherit; display: block; }
.va-table a.va-cell img { display: block; width: 100%; height: auto; border-radius: 8px; border: 1px solid var(--border); }
.va-empty-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 80px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12.5px;
  text-align: center;
  padding: 16px;
}
