:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #ede9fe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #0284c7;
  --info-light: #e0f2fe;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --sidebar-width: 230px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--surface-alt);
  color: var(--text);
  display: flex;
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Sidebar ──────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.nav-brand-icon {
  width: 36px; height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; flex-shrink: 0;
}

.nav-brand-title { font-weight: 700; font-size: 14px; line-height: 1.2; }
.nav-brand-sub { font-size: 11px; color: var(--text-muted); }

#sidebar ul { list-style: none; padding: 10px 8px; flex: 1; }
#sidebar ul li a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px; font-weight: 500;
  transition: all 0.12s;
}
#sidebar ul li a:hover { background: var(--surface-alt); color: var(--text); }
#sidebar ul li a.active { background: var(--primary-light); color: var(--primary); }
#sidebar ul li a .icon { font-size: 15px; width: 18px; text-align: center; }

#sidebar .nav-sub { padding: 0 0 4px 0 !important; }
#sidebar .nav-sub li a {
  padding: 4px 12px 4px 40px !important;
  font-size: 12px !important;
  font-weight: 400 !important;
  color: var(--text-muted);
  justify-content: space-between;
  border-radius: 6px;
}
#sidebar .nav-sub li a:hover { background: var(--surface-alt); color: var(--text); }
.nav-sub-count { font-size: 11px; color: var(--text-light); white-space: nowrap; }
.nav-sub-count.has-pending { color: var(--warning); font-weight: 600; }

/* ─── Store Modal Tabs ───────────────────────────── */
.store-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: -1px;
}
.store-tab:hover { color: var(--text); }
.store-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── SEO Score Chips ────────────────────────────── */
.seo-grade-chip {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  border: 1px solid;
  vertical-align: middle;
  letter-spacing: .02em;
}

/* ─── Mapping Wizard ─────────────────────────────── */
.wizard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  max-width: 780px;
}
.wizard-step-list {
  display: flex;
  align-items: center;
  margin-bottom: 28px;
  gap: 0;
}
.wizard-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.wizard-step.active { color: var(--primary); font-weight: 600; }
.wizard-step.done   { color: var(--success); }
.wizard-step-dot {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid currentColor;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.wizard-step.active .wizard-step-dot { background: var(--primary); color: #fff; border-color: var(--primary); }
.wizard-step.done   .wizard-step-dot { background: var(--success); color: #fff; border-color: var(--success); }
.wizard-step-line {
  flex: 1; height: 2px;
  background: var(--border);
  min-width: 24px; max-width: 60px;
  margin: 0 6px;
}
/* Compat list */
.compat-list { margin-bottom: 8px; }
.compat-group { margin-bottom: 12px; }
.compat-group-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  margin-bottom: 4px;
}
.compat-field {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 6px;
  margin-bottom: 3px; font-size: 13px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.compat-field-name { font-weight: 600; min-width: 130px; }
.compat-arrow { flex: 1; color: var(--text-muted); font-size: 12px; }
.compat-arrow code { background: var(--surface-hover); border-radius: 4px; padding: 1px 5px; font-size: 11px; }
.compat-status.ok { color: var(--success); font-size: 12px; white-space: nowrap; }
/* Gap cards */
.gap-card {
  border: 1px solid var(--warning);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  background: var(--warning-light);
}
.gap-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.gap-description { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.gap-resolutions { display: flex; flex-direction: column; gap: 6px; }
.resolution-option {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: var(--radius);
  background: var(--surface); border: 2px solid var(--border);
  cursor: pointer; font-size: 13px; transition: border-color .15s;
}
.resolution-option:hover { border-color: var(--primary); }
.resolution-option.selected { border-color: var(--primary); background: var(--primary-light); }
.resolution-option input[type=radio] { accent-color: var(--primary); }
.resolution-label { flex: 1; }

/* ─── Main ──────────────────────────────────────── */
#app {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 28px 32px;
  min-height: 100vh;
  max-width: calc(100vw - var(--sidebar-width));
}

/* ─── Page header ───────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 20px; font-weight: 700; }
.page-header-actions { display: flex; gap: 8px; align-items: center; }

.breadcrumb {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 6px;
}
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb span { color: var(--text-light); }

/* ─── Buttons ───────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all 0.12s;
  white-space: nowrap;
  text-decoration: none;
  font-family: inherit;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }

/* ─── Cards ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ─── Stats grid ────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }
.stat-card.danger .stat-value { color: var(--danger); }

/* ─── Table ─────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 11px 16px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--text-muted);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-alt); }
td .actions { display: flex; gap: 6px; }

/* ─── Forms ─────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text); }
.form-group .label-note { font-size: 11px; color: var(--text-muted); font-weight: 400; }

.form-group input,
.form-group textarea,
.form-group select {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.12s;
  font-family: inherit;
  width: 100%;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group input[type="checkbox"],
.form-group input[type="radio"] { width: auto; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ─── Toolbar / filters ─────────────────────────── */
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  margin-bottom: 16px;
}
.search-input {
  flex: 1; min-width: 180px;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.search-input:focus { border-color: var(--primary); }
.filter-select {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
}

/* ─── Badge / status ────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.badge-pending { background: var(--warning-light); color: #92400e; }
.badge-running { background: var(--info-light); color: #0369a1; }
.badge-awaiting_review { background: var(--primary-light); color: var(--primary); }
.badge-completed { background: var(--success-light); color: #166534; }
.badge-pushed { background: var(--success-light); color: #166534; }
.badge-failed { background: var(--danger-light); color: #991b1b; }
.badge-approved { background: var(--success-light); color: #166534; }
.badge-rejected { background: var(--danger-light); color: #991b1b; }
.badge-held_quality { background: #fed7aa; color: #9a3412; }

/* ─── Modal / Dialog ────────────────────────────── */
dialog {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  width: 100%;
  max-width: 560px;
}
dialog::backdrop { background: rgba(0,0,0,0.5); }
@keyframes slideIn {
  from { transform: translateY(-16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
dialog[open] { animation: slideIn 0.18s ease; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 20px;
  cursor: pointer; color: var(--text-muted);
  padding: 2px 6px; border-radius: 4px; line-height: 1;
}
.modal-close:hover { background: var(--surface-alt); color: var(--text); }
.modal-body { padding: 24px; overflow-y: auto; max-height: 70vh; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ─── Empty state ───────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ─── Loading ───────────────────────────────────── */
.loading {
  text-align: center; padding: 48px 20px;
  color: var(--text-muted); font-size: 14px;
}
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast ─────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  padding: 11px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; color: #fff;
  box-shadow: var(--shadow-md); z-index: 9999;
  max-width: 360px;
}
@keyframes toastIn {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.toast { animation: toastIn 0.18s ease; }
.toast-success { background: #16a34a; }
.toast-error { background: var(--danger); }
.toast-info { background: var(--info); }

/* ─── Review UI ─────────────────────────────────── */
.review-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.review-item-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.review-item-header:hover { background: var(--surface-hover); }
.review-item-title { font-weight: 700; font-size: 14px; }
.review-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.review-item-toggle { font-size: 12px; color: var(--text-muted); }

.review-item-body { padding: 0; }

.field-row {
  border-bottom: 1px solid var(--border);
  padding: 16px 18px;
}
.field-row:last-child { border-bottom: none; }
.field-row-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.field-name { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); }
.field-actions { display: flex; gap: 6px; align-items: center; }
.field-dep-note { font-size: 11px; color: var(--text-muted); font-style: italic; }

.field-compare {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.field-col { display: flex; flex-direction: column; gap: 4px; }
.field-col-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.field-col-label.before { color: var(--text-muted); }
.field-col-label.after { color: var(--primary); }

.field-value {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px; line-height: 1.5;
  border: 1px solid var(--border);
  min-height: 60px;
  background: var(--surface-alt);
}
.field-value.editable {
  background: var(--surface);
  cursor: text;
  outline: none;
}
.field-value.editable:focus { border-color: var(--primary); background: var(--surface); }
.field-value.approved { border-color: #86efac; background: #f0fdf4; }
.field-value.rejected { border-color: #fca5a5; background: #fef2f2; opacity: 0.6; }
.field-value.html-preview { font-size: 13px; }
.field-value.html-preview p { margin-bottom: 6px; }
.field-value.html-preview ul { padding-left: 18px; }

/* Images comparison */
.images-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.image-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.image-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.image-info { padding: 8px; font-size: 11px; }
.image-info .filename { font-weight: 600; word-break: break-all; }
.image-info .alt { color: var(--text-muted); margin-top: 3px; }
.image-info .size { color: var(--text-light); margin-top: 2px; }

/* Progress bar */
.progress-bar-wrap {
  background: var(--surface-alt);
  border-radius: 99px; height: 6px; overflow: hidden;
}
.progress-bar {
  height: 100%; background: var(--primary);
  border-radius: 99px; transition: width 0.4s ease;
}

/* Job card */
.job-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
  transition: box-shadow 0.12s;
}
.job-card:hover { box-shadow: var(--shadow-md); }
.job-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.job-card-title { font-size: 15px; font-weight: 700; }
.job-card-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.job-card-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.job-card-stats { font-size: 12px; color: var(--text-muted); display: flex; gap: 12px; }

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

/* Section title */
.section-title { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 14px; margin-top: 24px; }
.section-title:first-child { margin-top: 0; }

/* Fields builder */
.fields-builder { display: flex; flex-direction: column; gap: 10px; }
.field-config-row {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  overflow: hidden;
}
.field-config-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
.field-config-header:hover { background: var(--surface-hover); }
.field-config-header input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; }
.field-config-label { font-weight: 600; font-size: 13px; flex: 1; }
.field-config-dep { font-size: 11px; color: var(--text-muted); }
.field-config-body {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: none;
}
.field-config-body.visible { display: block; }

/* Prompt textarea inside field rows */
.field-config-body textarea { font-size: 12px; min-height: 70px; }

/* Cron wizard ──────────────────────────────────────────────────────────── */
.cron-field-row {
  display: flex; align-items: center; gap: 8px;
}
.cron-field-row input[type="text"] {
  flex: 1;
  width: auto !important;   /* override .form-group input { width:100% } */
  min-width: 0;
}
.cron-wizard-btn {
  padding: 7px 12px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-alt); color: var(--text-muted);
  cursor: pointer; white-space: nowrap; transition: background .12s, color .12s;
}
.cron-wizard-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.cron-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.cron-preset {
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  border: 1.5px solid var(--border); border-radius: 99px;
  background: var(--surface); cursor: pointer; color: var(--text-muted);
  transition: all .12s;
}
.cron-preset:hover, .cron-preset.active {
  border-color: var(--primary); background: var(--primary-light); color: var(--primary);
}
.cron-builder { display: flex; flex-direction: column; gap: 14px; }
.cron-builder .form-row {
  display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 10px;
}
.cron-builder .form-row label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.cron-day-grid {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.cron-day {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 11px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); transition: all .12s; user-select: none;
}
.cron-day:hover { border-color: var(--primary); color: var(--primary); }
.cron-day.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.cron-preview {
  margin-top: 16px; padding: 12px 16px;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.cron-preview-expr {
  font-family: monospace; font-size: 15px; font-weight: 700;
  color: var(--primary); letter-spacing: .04em;
}
.cron-preview-desc { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
#cronWizard { max-width: 520px; }

/* Run status row */
.run-row { display: flex; align-items: center; gap: 10px; }
.run-progress { flex: 1; }
