/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f0f12;
  color: #e0e0e8;
  min-height: 100vh;
  padding: 0 0 60px;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  background: #18181f;
  border-bottom: 1px solid #2a2a38;
  padding: 16px 20px;
}
header h1 { font-size: 1.3rem; font-weight: 600; letter-spacing: -0.3px; }
.subtitle { font-size: 0.78rem; color: #6b6b80; margin-top: 3px; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 24px; }

.card {
  background: #18181f;
  border: 1px solid #2a2a38;
  border-radius: 10px;
  padding: 20px;
}

h2 { font-size: 0.9rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: #9090a8; margin-bottom: 18px; }

/* ── Control Grid ──────────────────────────────────────────────────────────── */
.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 20px;
  align-items: start;
}

/* ── Upload Zones ──────────────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed #3a3a50;
  border-radius: 8px;
  min-height: 180px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s;
  cursor: pointer;
}
.upload-zone.drag-over { border-color: #6e6ef0; background: #1e1e30; }
.upload-zone.has-image { border-style: solid; border-color: #3d3d5c; }

.upload-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 180px;
  color: #5a5a72;
  user-select: none;
}
.upload-inner p { font-size: 0.88rem; }
.upload-icon { font-size: 2rem; }
.hint { font-size: 0.72rem !important; color: #45455a; }

.preview {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}
.preview.hidden { display: none; }

/* ── Options ───────────────────────────────────────────────────────────────── */
.options { display: flex; flex-direction: column; gap: 14px; }

.fashn-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.04);
  border-left: 3px solid #4a90d9;
  border-radius: 4px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.78rem;
  color: #8080a0;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select, input[type="text"] {
  background: #0f0f12;
  border: 1px solid #2a2a38;
  border-radius: 6px;
  color: #e0e0e8;
  font-size: 0.9rem;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.2s;
}
select:focus, input:focus { border-color: #5a5ae0; }

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.85rem;
  color: #a0a0c0;
  cursor: pointer;
}
.checkbox-label input { width: 16px; height: 16px; cursor: pointer; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  background: #5a5ae0;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  margin-top: 4px;
}
.btn-primary:hover:not(:disabled) { background: #4a4acd; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: #8080a0;
  border: 1px solid #2a2a38;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-secondary:hover { border-color: #5a5ae0; color: #e0e0e8; }

/* ── Status ────────────────────────────────────────────────────────────────── */
.status {
  background: #18181f;
  border: 1px solid #2a2a38;
  border-radius: 8px;
  padding: 14px 20px;
  font-size: 0.88rem;
  color: #c0c0e0;
}
.status.loading { border-color: #4a4ab0; color: #9090e0; }
.status.error   { border-color: #b04a4a; color: #e09090; }
.status.success { border-color: #4ab08a; color: #90e0c0; }
.status.hidden  { display: none; }

/* ── Results Grid ──────────────────────────────────────────────────────────── */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  margin-top: 16px;
}

.result-card {
  background: #18181f;
  border: 1px solid #2a2a38;
  border-radius: 10px;
  overflow: hidden;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2a38;
}
.result-api { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: #6e6ef0; }
.result-latency { font-size: 0.78rem; color: #6b6b80; }
.result-cost { font-size: 0.72rem; color: #506040; }

.result-images {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  align-items: start;
}
.result-img-wrap {
  position: relative;
}
.result-img-wrap img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}
.result-img-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.65);
  font-size: 0.68rem;
  color: #b0b0c8;
  text-align: center;
  padding: 3px 0;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Scoring ───────────────────────────────────────────────────────────────── */
.scoring-section { padding: 14px 16px; }
.scoring-section h4 { font-size: 0.75rem; color: #6b6b80; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; }

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.score-label { font-size: 0.8rem; color: #a0a0b8; flex: 1; }
.score-buttons { display: flex; gap: 4px; }
.score-btn {
  background: #0f0f12;
  border: 1px solid #2a2a38;
  color: #6b6b80;
  border-radius: 4px;
  width: 26px;
  height: 26px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.score-btn:hover  { border-color: #5a5ae0; color: #e0e0e8; }
.score-btn.active { background: #5a5ae0; border-color: #5a5ae0; color: #fff; }

.save-scores-btn {
  width: 100%;
  margin-top: 10px;
  background: #1e2a1e;
  color: #6adb8a;
  border: 1px solid #2a402a;
  border-radius: 6px;
  padding: 8px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.2s;
}
.save-scores-btn:hover { background: #243024; }

/* Enhancement result label */
.enhanced-badge {
  display: inline-block;
  background: #2a3a2a;
  color: #6adb8a;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ── Log Table ─────────────────────────────────────────────────────────────── */
.log-section {}
.log-header { display: flex; justify-content: space-between; align-items: center; }

.log-table-wrap { overflow-x: auto; margin-top: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #2a2a38;
  color: #6b6b80;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 500;
  white-space: nowrap;
}
td {
  padding: 7px 10px;
  border-bottom: 1px solid #1e1e28;
  color: #c0c0d8;
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #1a1a24; }

.score-pill {
  display: inline-block;
  background: #1e2030;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.72rem;
}
.score-hi { color: #6adb8a; }
.score-mid { color: #e0c060; }
.score-lo { color: #e06060; }

/* ── Download button on result image ────────────────────────────────────────── */
.result-img-clickable { cursor: zoom-in; }

.download-btn {
  position: absolute;
  bottom: 30px;
  right: 8px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 4px;
  text-decoration: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}
.result-img-wrap:hover .download-btn { opacity: 1; }

/* ── Lightbox ────────────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.88);
}
.lightbox-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 90vw;
  max-height: 90vh;
}
.lightbox-inner img {
  max-width: 90vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.lightbox-actions {
  display: flex;
  gap: 12px;
}

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Responsive — Tablet (≤ 860px) ─────────────────────────────────────────── */
@media (max-width: 860px) {
  .control-grid {
    grid-template-columns: 1fr 1fr;
  }

  /* Options column spans full width below the two upload zones */
  .control-grid .options {
    grid-column: 1 / -1;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }
}

/* ── Responsive — Mobile (≤ 560px) ─────────────────────────────────────────── */
@media (max-width: 560px) {
  header { padding: 14px 16px; }
  header h1 { font-size: 1.1rem; }

  main { padding: 16px 12px; gap: 16px; }
  .card { padding: 16px 14px; }

  /* Stack uploads vertically on mobile */
  .control-grid {
    grid-template-columns: 1fr;
  }

  /* Shorter upload zones on mobile — enough to tap, not dominating the screen */
  .upload-zone { min-height: 140px; }
  .upload-inner { height: 140px; }
  .preview { height: 140px; }

  /* Generate button full-width */
  .btn-primary {
    width: 100%;
    padding: 14px 20px;
    font-size: 1rem;
  }

  /* Result images: stack person/garment/result vertically */
  .result-images {
    grid-template-columns: 1fr !important;
  }

  /* Extra samples no longer span 3 cols since we're single col */
  .result-img-wrap[style*="grid-column"] {
    grid-column: 1 !important;
  }

  /* Always show the download button on mobile (no hover) */
  .download-btn {
    opacity: 1;
    bottom: 28px;
  }

  /* Scoring rows: wrap label + buttons vertically */
  .score-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  /* Bigger tap targets for score buttons */
  .score-btn {
    width: 32px;
    height: 32px;
    font-size: 0.82rem;
  }

  /* Log table stays horizontally scrollable — already handled by overflow-x: auto */
  .log-table-wrap { font-size: 0.72rem; }

  /* Lightbox — full screen on mobile */
  .lightbox-inner {
    max-width: 100vw;
    max-height: 100dvh;
    padding: 16px;
  }
  .lightbox-inner img {
    max-width: 100vw;
    max-height: 72dvh;
    border-radius: 6px;
  }
  .lightbox-actions {
    width: 100%;
    justify-content: center;
  }
  .lightbox-actions .btn-primary,
  .lightbox-actions .btn-secondary {
    flex: 1;
    text-align: center;
  }
}
