:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #17212b;
  --muted: #6b7785;
  --line: #e2e7eb;
  --brand: #a91924;
  --brand-dark: #76131a;
  --green: #11845b;
  --green-soft: #e7f7f0;
  --red: #c33b45;
  --red-soft: #fff0f1;
  --amber: #a86908;
  --amber-soft: #fff7df;
  --shadow: 0 18px 45px rgba(23, 33, 43, .07);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: inherit; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 240px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 32px 22px 24px;
  background: #151b22; color: #fff; display: flex; flex-direction: column;
}
.brand { text-decoration: none; padding: 0 10px 30px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-name { display: block; font-size: 20px; font-weight: 800; }
.brand-subtitle { display: block; margin-top: 5px; color: #96a0ab; font-size: 12px; letter-spacing: .08em; }
.sidebar nav { display: grid; gap: 8px; margin-top: 28px; }
.nav-section { color: #a8b1bb; font-size: 12px; font-weight: 700; margin: 8px 10px 3px; }
.nav-section.muted { margin-top: 28px; }
.nav-link { min-height: 46px; padding: 0 13px; border-radius: 10px; display: flex; align-items: center; gap: 11px; text-decoration: none; color: #dbe1e6; }
.nav-link.active { color: #fff; background: linear-gradient(135deg, #a91924, #7b171d); font-weight: 700; box-shadow: 0 9px 24px rgba(169,25,36,.25); }
.nav-link.disabled { opacity: .45; }
.nav-icon { width: 25px; height: 25px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.45); border-radius: 7px; font-size: 12px; }
.logout { margin-top: auto; }
.button-link { width: 100%; border: 0; background: transparent; cursor: pointer; }
.button-link:hover { background: rgba(255,255,255,.06); }

.main-content { min-width: 0; padding: 36px clamp(22px, 4vw, 58px) 70px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 28px; }
.topbar h1 { margin: 5px 0 0; font-size: clamp(26px, 3vw, 36px); letter-spacing: -.03em; }
.eyebrow { color: var(--brand); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.primary-button, .secondary-button {
  display: inline-flex; min-height: 44px; align-items: center; justify-content: center;
  padding: 0 18px; border-radius: 10px; border: 0; text-decoration: none; cursor: pointer; font-weight: 750;
}
.primary-button { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; box-shadow: 0 10px 22px rgba(169,25,36,.18); }
.primary-button:hover { filter: brightness(.96); }
.secondary-button { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.full { width: 100%; }

.flash-stack { display: grid; gap: 10px; margin: -10px 0 20px; }
.flash { padding: 13px 16px; border-radius: 10px; border: 1px solid; font-weight: 650; }
.flash.success { background: var(--green-soft); color: #0e6c4b; border-color: #b8ead7; }
.flash.error { background: var(--red-soft); color: #a12b34; border-color: #f2c9cd; }

.status-banner {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 13px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 17px 20px; box-shadow: var(--shadow);
}
.status-banner p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 0 0 5px var(--green-soft); background: var(--green); }
.status-banner.pending .status-dot { background: var(--amber); box-shadow: 0 0 0 5px var(--amber-soft); }
.last-generated { color: var(--muted); font-size: 12px; white-space: nowrap; }

.summary-grid { display: grid; grid-template-columns: repeat(6, minmax(120px, 1fr)); gap: 13px; margin: 18px 0 34px; }
.summary-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: 0 8px 28px rgba(23,33,43,.045); }
.summary-card span { display: block; color: var(--muted); font-size: 13px; }
.summary-card strong { display: block; margin-top: 9px; font-size: 28px; }
.summary-card.available strong { color: var(--green); }
.summary-card.unavailable strong { color: var(--red); }
.summary-card.not-listed strong { color: #596572; }
.summary-card.unknown strong { color: var(--amber); }
.summary-card.alert { background: linear-gradient(135deg, #fff8eb, #fff); }

.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; font-size: 21px; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.text-link, .product-links a { color: var(--brand); text-decoration: none; font-weight: 700; }

.product-list { display: grid; gap: 18px; }
.product-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.product-header { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.product-header h3 { margin: 0; font-size: 17px; }
.product-links { display: flex; gap: 16px; margin-top: 8px; font-size: 12px; }
.variant-count { padding: 6px 11px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 12px; white-space: nowrap; }
.variant-table-wrap { overflow-x: auto; }
.variant-table { width: 100%; border-collapse: collapse; min-width: 790px; }
.variant-table th { text-align: right; padding: 12px 18px; color: var(--muted); background: var(--surface-soft); font-size: 11px; }
.variant-table td { padding: 16px 18px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
.variant-table tbody tr:first-child td { border-top: 0; }
.paused-row { opacity: .56; background: #fafbfc; }
.mapping-note { display: block; width: fit-content; margin-top: 5px; color: var(--amber); font-size: 11px; }
.status-chip { display: inline-flex; padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-chip.in_stock { color: #0d714d; background: var(--green-soft); }
.status-chip.out_of_stock { color: #a72d36; background: var(--red-soft); }
.status-chip.not_listed { color: #4f5d69; background: #edf1f4; }
.status-chip.mapping_required, .status-chip.unknown { color: #90600b; background: var(--amber-soft); }
.health-text { color: var(--muted); }
.toggle-button { min-width: 72px; padding: 6px 10px; border: 1px solid #cfd6dc; border-radius: 999px; background: #f0f2f4; color: var(--muted); cursor: pointer; }
.toggle-button.on { border-color: #abe1cd; background: var(--green-soft); color: var(--green); }
.restock-alert { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.restock-alert span { padding: 4px 8px; background: var(--amber-soft); color: #8f5b00; border-radius: 6px; font-size: 11px; font-weight: 800; }
.restock-alert button { border: 0; background: transparent; color: var(--brand); font-size: 11px; text-decoration: underline; cursor: pointer; }

.empty-state { padding: 64px 24px; text-align: center; background: var(--surface); border: 1px dashed #cbd3da; border-radius: 16px; }
.empty-state h2 { margin: 14px 0 5px; }
.empty-state p { margin: 0 auto 22px; max-width: 560px; color: var(--muted); }
.empty-icon { width: 54px; height: 54px; margin: auto; display: grid; place-items: center; color: var(--brand); background: #fbeaec; border-radius: 16px; font-size: 28px; }

.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: clamp(22px, 4vw, 34px); box-shadow: var(--shadow); margin-bottom: 18px; }
.step-title { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 26px; }
.step-title > span { flex: 0 0 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--brand); color: #fff; font-weight: 800; }
.step-title h2 { margin: 1px 0 4px; font-size: 20px; }
.step-title p { margin: 0; color: var(--muted); font-size: 13px; }
.stack-form { display: grid; gap: 18px; }
.stack-form label { display: grid; gap: 8px; color: #3c4855; font-size: 13px; font-weight: 700; }
input, select { width: 100%; min-height: 45px; border: 1px solid #ccd4db; border-radius: 9px; padding: 0 13px; background: #fff; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(169,25,36,.09); }
.url-form .primary-button { width: fit-content; }
.matched-products { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
.matched-products div { padding: 15px; border-radius: 10px; background: var(--surface-soft); }
.matched-products small { display: block; color: var(--muted); margin-bottom: 6px; }
.mapping-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.mapping-row { display: grid; grid-template-columns: minmax(180px, .8fr) auto minmax(260px, 1.2fr); align-items: center; gap: 16px; padding: 16px; border-top: 1px solid var(--line); }
.mapping-row:first-child { border-top: 0; }
.variant-choice { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.variant-choice input { width: 18px; min-height: 18px; accent-color: var(--brand); }
.variant-choice small { display: block; margin-top: 3px; color: var(--muted); }
.mapping-arrow { color: var(--muted); }
.form-footer { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-top: 22px; }
.form-footer p { max-width: 570px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.form-footer .primary-button { white-space: nowrap; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 85% 10%, #f3d8dc, transparent 28%), #f4f6f8; }
.auth-card { width: min(430px, 100%); padding: 38px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 28px 80px rgba(23,33,43,.13); }
.auth-brand { margin-bottom: 27px; }
.auth-brand h1, .auth-card h1 { margin: 7px 0 6px; font-size: 30px; }
.auth-brand p, .auth-card p { color: var(--muted); line-height: 1.7; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1050px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 16px 18px; flex-direction: row; align-items: center; gap: 12px; }
  .brand { padding: 0; border: 0; margin-left: auto; }
  .brand-name { font-size: 16px; }
  .brand-subtitle, .nav-section, .nav-link.disabled { display: none; }
  .sidebar nav { margin: 0; display: block; }
  .nav-link { min-height: 40px; }
  .nav-link .nav-icon { display: none; }
  .logout { margin: 0; }
  .logout .nav-link { padding: 0 9px; font-size: 12px; }
  .main-content { padding: 24px 16px 50px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar .primary-button, .topbar .secondary-button { width: 100%; }
  .status-banner { grid-template-columns: auto 1fr; }
  .last-generated { grid-column: 2; white-space: normal; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .product-header, .section-heading, .form-footer { align-items: flex-start; flex-direction: column; }
  .matched-products { grid-template-columns: 1fr; }
  .mapping-row { grid-template-columns: 1fr; gap: 10px; }
  .mapping-arrow { display: none; }
  .form-footer .primary-button, .url-form .primary-button { width: 100%; }
}
