*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #d8dce3;
  --text: #1a1d23;
  --text-muted: #5c6573;
  --accent: #2f5d8a;
  --accent-hover: #264d73;
  --error: #b42318;
  --error-bg: #fef3f2;
  --success: #027a48;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --warn-border: #fedf89;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
}

.header {
  margin-bottom: 1.5rem;
}

.header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--text-muted);
  cursor: pointer;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel[hidden] {
  display: none;
}

.panel-hint {
  margin: -0.5rem 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field-label {
  display: block;
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.product-type-select {
  width: 100%;
  max-width: 280px;
  margin-bottom: 1rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.results-subheading {
  margin: 1rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.group-section {
  margin-bottom: 0.75rem;
}

.group-grid {
  margin-bottom: 0.25rem;
}

.candidate-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0.2rem 0;
}

.candidate-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #e8eef5;
  color: var(--accent);
}

.mode-option--secondary {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.video-meta {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.collage-section {
  margin: 1.25rem 0 1.5rem;
}

.collage-frame {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 0.5rem;
  overflow: auto;
  max-width: 100%;
}

.collage-frame img {
  display: block;
  max-width: 100%;
  height: auto;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}

.thumb-frame {
  position: relative;
  aspect-ratio: 1;
}

.candidate-index-badge {
  position: absolute;
  top: 0.35rem;
  left: 0.35rem;
  z-index: 1;
  min-width: 1.5rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  pointer-events: none;
}

.candidate-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  background: #fafbfc;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.candidate-card:hover,
.candidate-card:focus-visible {
  border-color: var(--accent);
  outline: none;
  box-shadow: var(--shadow);
}

.candidate-score {
  margin: 0.4rem 0 0.1rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.candidate-time,
.candidate-rec,
.candidate-warn {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.candidate-card.rec-excellent_candidate {
  border-color: #abefc6;
}

.candidate-card.rec-retake_recommended {
  border-color: var(--warn-border);
}

.checks-list {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.check-item.check-fail {
  color: var(--warn);
}

.check-item.check-skip {
  color: var(--text-muted);
  font-style: italic;
}

.frame-modal-preview {
  margin-bottom: 0.75rem;
  max-height: 420px;
}

.frame-enhancement-results {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.frame-results-title {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.frame-output-section {
  margin-top: 1rem;
}

.frame-results-subtitle {
  margin: -0.4rem 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.frame-output-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.frame-output-warning {
  margin: 0.4rem 0 0;
  font-size: 0.72rem;
  color: var(--warn);
}

.frame-output-meta {
  margin: 0.4rem 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.frame-output-steps {
  margin-top: 0.45rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.frame-output-steps summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.frame-output-steps ol {
  margin: 0.35rem 0 0;
  padding-left: 1.15rem;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
}

.checkbox-label input {
  margin-top: 0.2rem;
}

.ai-premium-panel {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

.ai-premium-result {
  margin-top: 1rem;
}

#enhance-frame-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1rem;
  font-weight: 600;
}

.mode-selector {
  margin: 0 0 1rem;
  padding: 0;
  border: none;
}

.mode-selector legend {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.mode-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  cursor: pointer;
}

.mode-option input {
  accent-color: var(--accent);
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 140px;
  padding: 1.25rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: #f0f6fc;
}

.dropzone-text {
  font-weight: 500;
}

.dropzone-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.selected-file {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  word-break: break-all;
}

.selected-file.has-file {
  color: var(--text);
  font-weight: 500;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn {
  padding: 0.55rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #f0f2f5;
}

.status-message {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  min-height: 1.35em;
}

.status-message.error {
  color: var(--error);
  background: var(--error-bg);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: 1px solid #fecdca;
}

.status-message.success {
  color: var(--success);
}

.status-message.loading {
  color: var(--text-muted);
}

.comparison-filename {
  margin: -0.5rem 0 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
}

.comparison-meta {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.preflight-panel {
  margin: 0 0 0.5rem;
  padding: 0.55rem 0.75rem;
  background: #f8f9fb;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
}

.preflight-score {
  margin: 0 0 0.2rem;
  font-weight: 600;
  color: var(--text);
}

.preflight-recommendation {
  margin: 0;
  color: var(--text-muted);
}

.preflight-recommendation.premium_bg_removal {
  color: var(--success);
}

.preflight-recommendation.retake_recommended {
  color: var(--warn);
}

.comparison-status.warn {
  color: var(--warn);
}

.comparison-status {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
}

.comparison-status.success {
  color: var(--success);
}

.comparison-status.muted {
  color: var(--text-muted);
}

.transparent-link-wrap {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
}

.transparent-link-wrap a {
  color: var(--accent);
  text-decoration: none;
}

.transparent-link-wrap a:hover {
  text-decoration: underline;
}

.warnings-list {
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem 0.65rem 1.75rem;
  list-style: disc;
  font-size: 0.85rem;
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
}

.warnings-list li + li {
  margin-top: 0.35rem;
}

.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.comparison-card {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.comparison-card figcaption {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.image-frame {
  aspect-ratio: 1;
  background: #f0f2f5;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-frame img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.file-list {
  margin: 0.5rem 0 0;
  padding-left: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  max-height: 120px;
  overflow-y: auto;
}

.file-list li + li {
  margin-top: 0.2rem;
}

.batch-summary {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
}

.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
  background: #fafbfc;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.result-card:hover,
.result-card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  outline: none;
}

.result-card--error {
  cursor: default;
  background: var(--error-bg);
  border-color: #fecdca;
}

.result-card--error:hover {
  border-color: #fecdca;
  box-shadow: none;
}

.result-thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.thumb-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.thumb-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.result-card-title {
  margin: 0 0 0.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  word-break: break-all;
}

.result-card-meta,
.result-card-rec,
.result-card-status,
.result-card-warnings {
  margin: 0 0 0.15rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.result-card-error {
  margin: 0;
  font-size: 0.8rem;
  color: var(--error);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, 0.55);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: min(960px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(16, 24, 40, 0.18);
  padding: 1rem 1.25rem 1.25rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-filename {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  word-break: break-all;
}

.modal-meta,
.modal-status {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
}

.modal-status.success {
  color: var(--success);
}

.modal-status.warn {
  color: var(--warn);
}

.modal-status.muted {
  color: var(--text-muted);
}

body.modal-open {
  overflow: hidden;
}

@media (max-width: 720px) {
  .comparison-grid {
    grid-template-columns: 1fr;
  }

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