:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #66615b;
  --line: #ded6cc;
  --paper: #f8f5ef;
  --panel: #ffffff;
  --panel-raised: #fbfaf7;
  --brand: #b91f1f;
  --brand-dark: #8f1717;
  --amber: #b97112;
  --blue: #285c8f;
  --steel: #3f3b36;
  --shadow: 0 18px 42px rgba(52, 45, 36, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(248, 245, 239, 0.96)),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  min-height: 40px;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
  padding: 0 14px;
}

button:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand-dark);
  background: #fff7f3;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  align-items: center;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px clamp(18px, 4vw, 42px);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand-mark {
  align-items: center;
  background: var(--brand);
  border-radius: 6px;
  color: #fff;
  display: inline-flex;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.brand small,
.upload-zone small {
  color: var(--muted);
  display: block;
  margin-top: 2px;
}

.topbar nav {
  display: flex;
  gap: 18px;
  font-weight: 800;
}

.topbar nav a:hover,
.topbar nav button:hover {
  color: var(--brand-dark);
}

.topbar nav button {
  background: transparent;
  border: 0;
  color: inherit;
  font-weight: 800;
  min-height: auto;
  padding: 0;
}

.app-shell {
  padding: clamp(16px, 3vw, 34px);
}

.workspace {
  display: grid;
  gap: clamp(18px, 3vw, 30px);
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  max-width: 1500px;
  margin: 0 auto;
}

.control-panel,
.preview-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel {
  align-self: start;
  display: grid;
}

.panel-section {
  border-bottom: 1px solid var(--line);
  padding: 22px;
}

.panel-section:last-child {
  border-bottom: 0;
}

.eyebrow {
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 1.02;
  margin-bottom: 14px;
}

h2 {
  font-size: 1rem;
  margin-bottom: 0;
}

h3 {
  font-size: 0.92rem;
  margin-bottom: 10px;
}

.lede,
#nextStep {
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 0;
}

.upload-zone {
  align-items: center;
  background: #fffaf3;
  border: 2px dashed #cdbfac;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  gap: 14px;
  padding: 18px;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--brand);
  background: #fff3ea;
}

.inline-status,
.privacy-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  margin: 10px 0 0;
}

.inline-status:empty {
  display: none;
}

.inline-status[data-tone="success"] {
  color: #287549;
}

.inline-status[data-tone="warning"] {
  color: #906313;
}

.inline-status[data-tone="error"] {
  color: var(--brand-dark);
}

.upload-zone input {
  inline-size: 1px;
  opacity: 0;
  position: absolute;
}

.upload-icon {
  align-items: center;
  background: var(--brand);
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  flex: 0 0 34px;
  font-size: 1.5rem;
  font-weight: 400;
  height: 34px;
  justify-content: center;
  line-height: 1;
  width: 34px;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 900;
  margin-bottom: 8px;
}

.vehicle-picker {
  border: 0;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.vehicle-picker legend {
  display: block;
  font-size: 0.82rem;
  font-weight: 900;
  margin-bottom: 8px;
  padding: 0;
}

.vehicle-picker label {
  color: var(--muted);
  font-size: 0.72rem;
  margin-bottom: 0;
}

.vehicle-picker select {
  margin-top: 6px;
}

select,
input,
textarea {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  width: 100%;
}

select {
  background: #ffffff;
  padding: 0 12px;
}

input {
  min-height: 40px;
  padding: 0 12px;
}

textarea {
  color: var(--steel);
  line-height: 1.45;
  padding: 12px;
  resize: vertical;
}

.section-head,
.preview-toolbar {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.section-head {
  margin-bottom: 12px;
}

.section-head button {
  font-size: 0.78rem;
  min-height: 34px;
}

#selectRecommended,
#copyCaption,
#generateAiImage,
#sharePost,
#clearImages {
  background: #fffaf3;
  border-color: #d6c7b3;
}

#selectRecommended:hover:not(:disabled),
#copyCaption:hover:not(:disabled),
#generateAiImage:hover:not(:disabled),
#sharePost:hover:not(:disabled),
#clearImages:hover:not(:disabled) {
  background: #fff3ea;
  border-color: var(--brand);
}

.product-list {
  display: grid;
  gap: 10px;
}

.product-list-empty {
  background: var(--panel-raised);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
}

.product-list-empty strong {
  color: var(--ink);
  display: block;
  margin-bottom: 5px;
}

.product-list-empty p {
  margin: 0;
}

.product-card {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 12px;
}

.product-card-main {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: 92px minmax(0, 1fr);
}

.product-image {
  aspect-ratio: 1;
  background: #f1ece3;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.product-image img {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.product-image-placeholder {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  justify-content: center;
  padding: 8px;
  text-align: center;
}

.product-image-placeholder span {
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 900;
}

.product-image-placeholder small {
  font-size: 0.68rem;
  line-height: 1.2;
}

.product-card label {
  align-items: start;
  cursor: pointer;
  display: grid;
  font-size: 0.95rem;
  gap: 10px;
  grid-template-columns: 18px 1fr;
  margin: 0;
}

.product-card input {
  margin-top: 3px;
}

.product-card p {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
  margin: 0;
}

.variant-row {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 8px;
  grid-template-columns: 58px minmax(0, 1fr);
  padding: 8px;
}

.variant-row label {
  color: var(--muted);
  font-size: 0.74rem;
  margin: 0;
  text-transform: uppercase;
}

.variant-row select {
  min-height: 34px;
}

.variant-note {
  background: #fffaf3;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.product-fit {
  color: var(--amber);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.preview-panel {
  min-width: 0;
  padding: 22px;
}

.preview-toolbar {
  margin-bottom: 18px;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.segmented-control {
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-flex;
  overflow: hidden;
}

.segmented-control button {
  border: 0;
  border-radius: 0;
  min-height: 38px;
}

.segmented-control button + button {
  border-left: 1px solid var(--line);
}

.segmented-control button.active {
  background: var(--brand);
  color: #fff;
}

.export-control {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-grid;
  font-size: 0.72rem;
  gap: 4px;
  grid-template-columns: auto minmax(118px, 1fr);
  margin: 0;
  min-height: 40px;
  padding: 3px 6px 3px 10px;
  text-transform: uppercase;
}

.export-control select {
  border: 0;
  min-height: 32px;
  padding: 0 8px;
  text-transform: none;
}

#downloadImage {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

#downloadImage:hover:not(:disabled),
#submitLead:hover:not(:disabled),
.segmented-control button.active:hover:not(:disabled) {
  background: var(--brand-dark);
  color: #fff;
}

.ai-status {
  color: var(--amber);
  font-size: 0.86rem;
  font-weight: 800;
  min-height: 1.2em;
  margin: -6px 0 14px;
}

.canvas-wrap {
  background:
    linear-gradient(45deg, #eee7dc 25%, transparent 25%) 0 0 / 32px 32px,
    linear-gradient(45deg, transparent 75%, #eee7dc 75%) 0 0 / 32px 32px,
    linear-gradient(45deg, transparent 75%, #eee7dc 75%) 16px 16px / 32px 32px,
    linear-gradient(45deg, #eee7dc 25%, #f8f5ef 25%) 16px 16px / 32px 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

.canvas-wrap.drag-over {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 2px rgba(185, 31, 31, 0.18);
}

.canvas-wrap.drag-over .empty-state strong {
  color: var(--brand-dark);
}

canvas {
  aspect-ratio: 3 / 2;
  display: block;
  touch-action: none;
  width: 100%;
}

.empty-state {
  align-items: center;
  background: radial-gradient(circle, rgba(185, 31, 31, 0.08), rgba(255, 255, 255, 0.8) 58%);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 12px;
  inset: 0;
  justify-content: center;
  line-height: 1.4;
  padding: clamp(22px, 5vw, 46px);
  pointer-events: none;
  position: absolute;
  text-align: center;
}

.empty-state-card {
  background: rgba(0, 0, 0, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  box-shadow: 0 18px 42px rgba(31, 27, 24, 0.24);
  max-width: 440px;
  padding: clamp(18px, 4vw, 28px);
}

.empty-state strong {
  color: #fff;
  display: block;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  line-height: 1.2;
}

.empty-state span {
  display: block;
  margin-top: 10px;
}

.empty-state ul {
  color: rgba(255, 255, 255, 0.86);
  display: inline-block;
  font-size: 0.88rem;
  line-height: 1.45;
  margin: 14px 0 0;
  max-width: 340px;
  padding-left: 18px;
  text-align: left;
}

.empty-state li + li {
  margin-top: 6px;
}

.empty-state.hidden {
  display: none;
}

.generation-overlay {
  align-items: center;
  background: rgba(31, 27, 24, 0.52);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: clamp(18px, 5vw, 42px);
  position: absolute;
  z-index: 3;
}

.generation-overlay.hidden {
  display: none;
}

.generation-card {
  align-items: center;
  background: rgba(255, 250, 243, 0.96);
  border: 1px solid rgba(95, 80, 65, 0.22);
  border-radius: 8px;
  box-shadow: 0 22px 58px rgba(31, 27, 24, 0.2);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 360px;
  padding: 24px;
  text-align: center;
}

.generation-card strong {
  font-size: 1rem;
}

.generation-card span:not(.loader-ring) {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.loader-ring {
  animation: spin 0.85s linear infinite;
  border: 4px solid #eadccc;
  border-top-color: var(--brand);
  border-radius: 50%;
  display: inline-block;
  height: 42px;
  width: 42px;
}

.progress-track {
  background: #eadccc;
  border-radius: 999px;
  height: 7px;
  margin-top: 4px;
  overflow: hidden;
  width: 100%;
}

.progress-track span {
  animation: loadingBar 1.45s ease-in-out infinite;
  background: var(--brand);
  border-radius: inherit;
  display: block;
  height: 100%;
  width: 42%;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes loadingBar {
  0% {
    transform: translateX(-110%);
  }
  50% {
    transform: translateX(55%);
  }
  100% {
    transform: translateX(245%);
  }
}

.thumb-strip {
  display: flex;
  gap: 10px;
  margin: 14px 0 22px;
  min-height: 72px;
  overflow-x: auto;
}

.thumb-item {
  border: 2px solid transparent;
  border-radius: 6px;
  flex: 0 0 96px;
  height: 64px;
  position: relative;
}

.thumb-item.active {
  border-color: var(--brand);
}

.thumb {
  background: #f1ece3;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  height: 100%;
  overflow: hidden;
  padding: 0;
  width: 100%;
}

.thumb img {
  display: block;
  height: 100%;
  object-fit: cover;
  width: 100%;
}

.thumb-remove {
  align-items: center;
  background: rgba(23, 23, 23, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  font-size: 1rem;
  height: 24px;
  justify-content: center;
  line-height: 1;
  min-height: 24px;
  padding: 0;
  position: absolute;
  right: -8px;
  top: -8px;
  width: 24px;
}

.thumb-remove:hover {
  background: var(--brand);
  border-color: var(--brand);
}

.results-grid {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.7fr) minmax(230px, 0.7fr);
  padding-top: 20px;
}

.link-list {
  display: grid;
  gap: 8px;
}

.link-list a {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  min-height: 42px;
  padding: 9px 12px;
}

.link-list a:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.summary-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.summary-list div {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
}

.summary-list dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.summary-list dd {
  color: var(--ink);
  font-size: 0.9rem;
  line-height: 1.35;
  margin: 0;
}

.fitment-modal {
  background: transparent;
  border: 0;
  color: var(--ink);
  margin: auto;
  max-width: min(720px, calc(100vw - 28px));
  padding: 0;
  width: 100%;
}

.fitment-modal::backdrop {
  background: rgba(23, 23, 23, 0.42);
}

.modal-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: clamp(18px, 3vw, 28px);
}

.modal-head {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.icon-button {
  align-items: center;
  border-radius: 50%;
  display: inline-flex;
  flex: 0 0 36px;
  font-size: 1.35rem;
  height: 36px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 36px;
}

.fitment-modal h3 {
  font-size: 1.15rem;
  margin-bottom: 8px;
}

.fitment-modal p {
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 0;
}

.fitment-modal form {
  display: grid;
  gap: 12px;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.fitment-modal label {
  color: var(--ink);
  font-size: 0.78rem;
  margin-bottom: 0;
}

.fitment-modal label input,
.fitment-modal label textarea {
  margin-top: 7px;
}

#submitLead {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  justify-self: start;
}

.form-status {
  color: var(--amber);
  font-size: 0.86rem;
  font-weight: 800;
}

@media (max-width: 980px) {
  .workspace,
  .results-grid {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: 2;
  }

  .preview-panel {
    order: 1;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions button {
    flex: 1 1 140px;
  }

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

  .product-card-main {
    grid-template-columns: 74px minmax(0, 1fr);
  }
}
