:root {
  color-scheme: light dark;
  --border: #d0d5dd;
  --bg-subtle: #f6f7f9;
  --accent: #2f6feb;
  --danger: #d1453b;
  --ok: #1a8a4c;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.topbar h1 { font-size: 1.1rem; margin: 0; }

.tabs { display: flex; gap: 0.5rem; }

.tab-btn {
  padding: 0.4rem 0.9rem;
  border: 1px solid transparent;
  background: none;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.95rem;
}

.tab-btn.active { border-color: var(--border); background: var(--bg-subtle); font-weight: 600; }

main { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar, .review-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }

.pagination { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }

.status-pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
}
.status-pill.empty { color: var(--danger); }
.status-pill.filled { color: var(--ok); }
.status-pill.pending { color: var(--accent); }

button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.65; }

tr.row-generating { background: var(--bg-subtle); opacity: 0.6; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #24292f;
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 100;
  max-width: 80vw;
  transition: opacity 0.15s ease;
}
.toast.error { background: var(--danger); }
.toast.hidden { opacity: 0; pointer-events: none; }

fieldset { margin-bottom: 1.25rem; border: 1px solid var(--border); border-radius: 8px; }
fieldset label { display: block; margin: 0.4rem 0; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.2rem 0.5rem; margin: 0.3rem 0 0.6rem; }
.checkbox-grid label { margin: 0.2rem 0; }
textarea, input[type="text"], input[type="number"], select { font: inherit; }
textarea { width: 100%; }
.hint { font-size: 0.85rem; opacity: 0.75; margin: 0.25rem 0; }
.saved-msg { color: var(--ok); margin-left: 0.75rem; }

.draft-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; }

.product-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.product-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.product-group-header h3 { margin: 0; font-size: 1.05rem; }
.group-count { font-size: 0.8rem; font-weight: normal; opacity: 0.6; }
.group-collapse-btn {
  border: 1px solid var(--border);
  background: none;
  border-radius: 4px;
  width: 1.6rem;
  height: 1.6rem;
  line-height: 1;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.group-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.product-group-body.collapsed { display: none; }
.product-group-section { margin-bottom: 0.75rem; }
.product-group-section:last-child { margin-bottom: 0; }
.product-group-section > .section-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.6;
  margin-bottom: 0.4rem;
}

.draft-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}
.draft-card:last-child { margin-bottom: 0; }
.draft-card h4 { margin: 0 0 0.4rem 0; font-size: 0.9rem; opacity: 0.8; }
.draft-card .content-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; margin: 0.5rem 0; }
.draft-card .content-compare > div { display: flex; flex-direction: column; }
.draft-card label.small { font-size: 0.75rem; opacity: 0.7; margin-bottom: 0.2rem; }
.draft-card textarea, .draft-card input[type="text"] { width: 100%; }
.draft-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

.row-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; display: block; }
.row-thumb-placeholder { width: 36px; height: 36px; border-radius: 4px; background: var(--bg-subtle); border: 1px solid var(--border); }

.product-group-header .group-thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; vertical-align: middle; }
.product-group-header .group-title { display: flex; align-items: center; gap: 0.5rem; }

#pending-bulk-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.editor-toolbar { display: flex; gap: 0.25rem; margin-bottom: 0.3rem; }
.editor-toolbar button {
  border: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.85rem;
  line-height: 1.6;
}
.editor-toolbar button:hover { background: var(--border); }

.html-preview[contenteditable] {
  cursor: text;
  min-height: 140px;
}
.html-preview[contenteditable]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-picker {
  position: absolute;
  z-index: 200;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  min-width: 180px;
}
.field-picker label { display: block; font-size: 0.85rem; margin: 0.2rem 0; font-weight: normal; }
.field-picker-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; padding-top: 0.4rem; border-top: 1px solid var(--border); }

.alt-card-body { display: flex; gap: 0.75rem; align-items: flex-start; }
.alt-thumb { width: 60px; height: 60px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.alt-thumb-placeholder { background: var(--bg-subtle); border: 1px solid var(--border); }
.alt-fields { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }
.alt-fields input[type="text"] { width: 100%; }

.html-preview {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  background: var(--bg-subtle);
  font-size: 0.9rem;
  line-height: 1.5;
  max-height: 260px;
  overflow-y: auto;
}
.html-preview p { margin: 0 0 0.75em; }
.html-preview p:last-child { margin-bottom: 0; }
.html-preview h4 { margin: 1em 0 0.4em; font-size: 0.95rem; }
.html-preview h4:first-child { margin-top: 0; }
.html-preview ul { margin: 0 0 0.75em; padding-left: 1.25em; }
.html-preview li { margin-bottom: 0.25em; }
.html-preview table { width: 100%; }

.research-warning {
  background: #fdf6e3;
  border: 1px solid #e8d9a0;
  color: #412402;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.82rem;
  margin: 0.4rem 0;
}
.research-warning ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }
.research-warning-cache { background: #e6f1fb; border-color: #b5d4f4; color: #0c447c; }
.research-warning-miss { background: #f0f0f0; border-color: #d6d6d6; color: #444; }
.research-warning a { color: inherit; }

.format-existing-panel { max-width: 640px; }
.format-existing-actions { display: flex; gap: 0.5rem; margin: 1rem 0; }
.format-existing-progress { margin-top: 1.5rem; }
.format-existing-progress.hidden { display: none; }
.progress-bar {
  width: 100%;
  height: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.3s ease;
}
