:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --line: #d8dee4;
  --text: #1f2328;
  --muted: #6e7781;
  --blue: #0969da;
  --green: #1a7f37;
  --red: #cf222e;
  --amber-bg: #fff8c5;
  --amber-line: #d4a72c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, sans-serif;
  font-size: 15px;
}

a {
  color: inherit;
}

.topbar {
  height: 60px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.page {
  width: min(1180px, calc(100vw - 32px));
  margin: 28px auto 48px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.page-head h1 {
  margin: 4px 0;
  font-size: 32px;
  line-height: 1.15;
}

.page-head p {
  margin: 0;
  color: var(--muted);
}

.back-link {
  display: inline-block;
  margin-bottom: 4px;
  color: var(--blue);
  text-decoration: none;
  font-size: 14px;
}

.sync-status,
.notice {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  box-shadow: 0 4px 14px rgb(31 35 40 / 8%);
}

.notice {
  margin-bottom: 18px;
  color: var(--text);
}

.notice-warning {
  border-color: var(--amber-line);
  background: var(--amber-bg);
}

.button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.button-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
  box-shadow: 0 2px 8px rgb(31 35 40 / 8%);
}

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

.product-card {
  display: block;
  position: relative;
  min-width: 0;
  min-height: 260px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  box-shadow: 0 14px 34px rgb(31 35 40 / 16%);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.product-card:hover {
  border-color: var(--blue);
  box-shadow: 0 18px 44px rgb(31 35 40 / 22%);
  transform: translateY(-1px);
}

.product-card-unfinished {
  border-color: #86efac;
  outline: 1px solid #86efac;
  outline-offset: 0;
}

.product-card-unfinished:hover {
  border-color: #4ade80;
}

.product-card-ai-ready {
  border-color: #38bdf8;
  outline: 2px solid #7dd3fc;
  outline-offset: 0;
  box-shadow:
    0 0 0 4px rgb(125 211 252 / 24%),
    0 0 22px rgb(14 165 233 / 24%),
    0 14px 34px rgb(31 35 40 / 16%);
}

.product-card-ai-ready:hover {
  border-color: #0ea5e9;
  box-shadow:
    0 0 0 5px rgb(125 211 252 / 34%),
    0 0 30px rgb(14 165 233 / 40%),
    0 18px 44px rgb(2 132 199 / 24%);
}

.product-image {
  height: 100%;
  min-height: 260px;
  min-width: 0;
  display: grid;
  place-items: center;
  background: #fff;
}

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

.product-image span,
.image-placeholder {
  color: var(--muted);
}

.product-meta {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: grid;
  gap: 6px;
  padding: 12px;
  min-width: 0;
  background: #fff;
  border: 1px solid #8c959f;
  border-radius: 6px;
  color: var(--text);
  box-shadow: 0 10px 28px rgb(31 35 40 / 28%);
}

.product-meta strong {
  overflow-wrap: anywhere;
  font-size: 17px;
  color: var(--text);
}

.product-meta span {
  color: #424a53;
  font-size: 14px;
}

.empty-state,
.panel,
.test-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 8px 24px rgb(31 35 40 / 8%);
}

.empty-state h2,
.panel h2,
.test-head h2 {
  margin: 0;
}

.empty-state p {
  color: var(--muted);
}

.panel {
  margin-bottom: 18px;
}

.product-source-body {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.product-source-body-text-only {
  grid-template-columns: minmax(0, 1fr);
}

.product-source-image {
  width: 132px;
}

.product-source-image img {
  width: 132px;
  height: 132px;
}

.product-source-copy {
  min-width: 0;
  display: grid;
  gap: 10px;
}

.product-source-copy h2 {
  margin: 0;
}

.product-source-fields {
  display: grid;
  gap: 10px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  white-space: normal;
}

.product-source-fields div {
  min-width: 0;
}

.product-source-fields dt {
  color: var(--text);
  font-weight: 700;
}

.product-source-fields dd {
  margin: 3px 0 0;
  white-space: pre-wrap;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.ai-images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.ai-images figure {
  margin: 0;
  display: grid;
  gap: 10px;
}

.image-caption {
  color: var(--muted);
  font-size: 13px;
}

.ai-images img,
.image-frame img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.image-frame img[data-lightbox-src] {
  cursor: zoom-in;
}

.image-frame img[data-lightbox-src]:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

.ai-text,
.muted {
  color: var(--muted);
}

.ai-text strong {
  color: var(--text);
  font-weight: 700;
}

.ai-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  animation: spinner-rotate 0.75s linear infinite;
}

.ai-text,
.ai-note p {
  white-space: pre-wrap;
}

.ai-collapsible {
  display: grid;
  gap: 8px;
}

.ai-images + .ai-collapsible,
.ai-note strong + .ai-collapsible {
  margin-top: 10px;
}

.ai-generated-at {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.ai-collapsible .ai-text,
.ai-collapsible .product-source-fields {
  margin: 0;
  line-height: 1.55;
}

.product-source-expanded .product-source-fields {
  margin: 0;
  line-height: 1.55;
}

.view-only .product-source-copy .ai-toggle {
  display: none;
}

.ai-collapsible.is-collapsed .ai-text,
.ai-collapsible.is-collapsed .product-source-fields {
  max-height: calc(1.55em * 6);
  overflow: hidden;
  position: relative;
}

.ai-collapsible.is-collapsed .ai-text::after,
.ai-collapsible.is-collapsed .product-source-fields::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2.4em;
  background: linear-gradient(to bottom, rgb(255 255 255 / 0), var(--surface));
  pointer-events: none;
}

.ai-toggle {
  width: fit-content;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.ai-toggle:hover {
  text-decoration: underline;
}

.ai-prompt-debug-toggle {
  width: fit-content;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
}

.ai-prompt-debug-toggle:hover {
  color: var(--blue);
  text-decoration: underline;
}

.ai-prompt-debug {
  width: 100%;
  max-height: 360px;
  overflow: auto;
  margin-top: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f6f8fa;
}

.ai-prompt-debug[hidden] {
  display: none;
}

.ai-prompt-debug-section + .ai-prompt-debug-section {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.ai-prompt-debug h3 {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.3;
}

.ai-prompt-debug pre {
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.45 Consolas, "Courier New", monospace;
}

.ai-collapsible.is-collapsed .ai-prompt-debug-toggle,
.ai-collapsible.is-collapsed .ai-prompt-debug {
  display: none;
}

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

.tests-list {
  display: grid;
  gap: 18px;
}

.test-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

.test-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.test-status-unfinished {
  color: #0d9488;
  font-weight: 800;
}

.variant-leader-badge {
  flex: none;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--green);
  background: #dafbe1;
  font-size: 13px;
  font-weight: 700;
}

.variant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.variant-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  box-shadow: 0 4px 14px rgb(31 35 40 / 7%);
}

.variant-leader {
  border-color: var(--green);
}

.variant-leader-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  box-shadow: 0 4px 12px rgb(31 35 40 / 14%);
}

.variant-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.image-placeholder {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.image-frame {
  position: relative;
  margin: 0;
  min-width: 0;
}

.image-number-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 2;
  min-height: 28px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgb(31 35 40 / 16%);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 4px 14px rgb(31 35 40 / 14%);
}

.image-download {
  position: absolute;
  top: 8px;
  right: 8px;
  min-height: 28px;
  padding: 0 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgb(31 35 40 / 16%);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 4px 14px rgb(31 35 40 / 14%);
}

.image-download:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.image-placeholder {
  display: grid;
  place-items: center;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.metrics div {
  min-width: 0;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f6f8fa;
}

.metrics dt {
  color: var(--muted);
  font-size: 12px;
}

.metrics dd {
  margin: 4px 0 0;
  font-weight: 700;
}

.metrics .metric-good {
  border-color: #2da44e;
  background: #dafbe1;
}

.metrics .metric-good dt,
.metrics .metric-good dd {
  color: var(--green);
}

.ai-note {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.ai-note form {
  margin-top: 10px;
}

.ai-note p {
  margin-bottom: 0;
}

body.is-lightbox-open {
  overflow: hidden;
}

.image-lightbox[hidden] {
  display: none;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgb(0 0 0 / 82%);
  cursor: zoom-out;
}

.image-lightbox img {
  max-width: min(96vw, 1400px);
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgb(0 0 0 / 45%);
  cursor: default;
}

.image-lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1001;
  width: 42px;
  height: 42px;
  border: 1px solid rgb(255 255 255 / 28%);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 28px rgb(0 0 0 / 28%);
}

.image-lightbox-close:hover {
  color: var(--blue);
}

@media (max-width: 700px) {
  .topbar {
    padding: 0 16px;
  }

  .page {
    width: min(100vw - 20px, 1180px);
    margin-top: 18px;
  }

  .page-head,
  .test-head,
  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-head h1 {
    font-size: 26px;
  }

  .product-grid,
  .variant-grid {
    grid-template-columns: 1fr;
  }

  .product-source-body {
    grid-template-columns: 1fr;
  }

  .product-source-image {
    width: min(132px, 100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}
