:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #1f232c;
  --line: #2a2f3a;
  --ink: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #f58025;       /* Cheetos orange */
  --accent-2: #ffb347;
  --good: #3fb950;
  --bad: #f0562e;
  --radius: 14px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 70% -10%, #20160a 0%, var(--bg) 55%);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar { padding: 28px clamp(16px, 4vw, 56px) 12px; }
.brand { display: flex; gap: 16px; align-items: center; }
.brand .dot {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 24px -6px var(--accent);
}
h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

main { padding: 8px clamp(16px, 4vw, 56px) 64px; max-width: 1280px; margin: 0 auto; }

.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 820px) { .steps { grid-template-columns: 1fr; } }

.card {
  position: relative;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
}
.card.drop.over { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(245,128,37,.18); }
.step-no {
  position: absolute; top: -12px; left: 18px;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
  background: var(--accent); color: #1a1206;
}
.card h2 { margin: 4px 0 4px; font-size: 17px; }
.muted { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

.filebtn {
  display: inline-block; cursor: pointer;
  padding: 9px 16px; border-radius: 9px; font-weight: 600; font-size: 14px;
  background: #262b35; border: 1px solid var(--line); color: var(--ink);
  transition: background .15s, border-color .15s;
}
.filebtn:hover { background: #2e3441; border-color: #3a4150; }

.status { margin-top: 12px; font-size: 13px; min-height: 18px; }
.status.ok { color: var(--good); }
.status.err { color: var(--bad); }
.status.busy { color: var(--accent-2); }

.thumb { margin-top: 14px; }
.thumb img {
  max-height: 160px; max-width: 100%;
  border-radius: 8px; border: 1px solid var(--line); background: #fff; padding: 6px;
}

.parts { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: #20242d;
}
.tag.header { color: #ffd9a8; border-color: #4a3a22; }
.tag.footer { color: #a8d8ff; border-color: #22384a; }
.tag.shelf, .tag.shelf_logo { color: #c4f5b0; border-color: #2a4a22; }
.tag.frame, .tag.side { color: #f5b0c4; border-color: #4a2230; }
.tag.logo { color: #e0c4ff; border-color: #3a224a; }

.parts { margin-top: 14px; display: block; }
.parts-hd { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.partrow { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.partrow .tag { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.partrow select {
  font-size: 12px; padding: 3px 6px; border-radius: 6px;
  background: #20242d; color: #e7e9ee; border: 1px solid var(--line);
}

.rows { margin-top: 14px; max-height: 220px; overflow: auto; border-radius: 8px; }
.rows table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rows th, .rows td { text-align: left; padding: 6px 9px; border-bottom: 1px solid var(--line); }
.rows th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel-2); }

.run-bar { display: flex; align-items: center; gap: 16px; margin: 26px 0 10px; }
.primary {
  border: 0; cursor: pointer; font-weight: 700; font-size: 15px;
  padding: 12px 26px; border-radius: 11px; color: #1a1206;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 26px -8px var(--accent);
  transition: transform .1s, filter .15s, opacity .15s;
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary:active:not(:disabled) { transform: translateY(1px); }
.primary:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.run-hint { color: var(--muted); font-size: 13px; }
.ctl { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.ctl select { font-size: 13px; padding: 5px 8px; border-radius: 6px; background: #20242d; color: #e7e9ee; border: 1px solid var(--line); }
.ctl input[type=checkbox] { width: 15px; height: 15px; }

/* full-width data table + manual entry grid */
.data-table { margin: 0 0 22px; }
.tablescroll { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.tablescroll table { width: 100%; border-collapse: collapse; font-size: 12.5px; white-space: nowrap; }
.tablescroll th, .tablescroll td { text-align: left; padding: 7px 11px; border-bottom: 1px solid var(--line); }
.tablescroll th { color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
.srcToggle { display: flex; gap: 18px; margin: 4px 0 12px; font-size: 13px; color: var(--muted); }
.srcToggle label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.rmrow { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0 4px; }
.rmrow:hover { color: #ff6b6b; }

/* manual entry — per-store cards */
.mstores { display: flex; flex-direction: column; gap: 12px; }
.mcard { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--panel-2); }
.mcard-hd { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.mfields { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 10px; }
.mf { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.mf input { width: 84px; padding: 5px 7px; background: #20242d; color: #e7e9ee; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; }
.mcard-hd .mf { flex: 1; }
.mcard-hd .mf input { width: 100%; max-width: 280px; }
.mgaps-hd { margin: 13px 0 7px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 10px; }
.mgaps { display: flex; flex-wrap: wrap; gap: 8px 10px; }
.mg { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: var(--muted); }
.mg input { width: 72px; padding: 5px 7px; background: #20242d; color: #e7e9ee; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; text-align: center; }
.mg input.capped { border-color: #ff6b6b; background: #3a2326; }
.budget { font-size: 12px; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.budget.ok   { color: #ffd9a8; border-color: #4a3a22; }
.budget.good { color: #c4f5b0; border-color: #2a4a22; }
.budget.bad  { color: #ff9c9c; border-color: #5a2330; background: #3a2326; }

.gallery {
  margin-top: 18px; display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.saved-wrap { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 16px; }
.saved-hd { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 700; }
.saved-hd .muted { font-weight: 400; }
.saved-hd #clearSavedBtn { margin-left: auto; }
#saveBtn:not(:disabled) { color: var(--accent-2); border-color: #4a3a22; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  overflow: hidden; display: flex; flex-direction: column;
}
.tile .canvas {
  background: #fff; display: grid; place-items: center; padding: 14px; min-height: 240px;
}
.tile .canvas img { max-height: 320px; max-width: 100%; }
.tile.err .canvas { background: #2a1714; color: var(--bad); font-size: 13px; text-align: center; padding: 20px; }
.tile .meta { padding: 11px 13px; border-top: 1px solid var(--line); }
.tile .meta .name { font-weight: 700; font-size: 14px; margin-bottom: 3px; word-break: break-word; }
.tile .meta .loc { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.tile .meta .dims { color: var(--muted); font-size: 12.5px; }
.tile .meta .badges { margin-top: 7px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tile .pill { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #20242d; border: 1px solid var(--line); color: var(--muted); }
.tile .pill.scheme { color: var(--accent-2); border-color: #4a3a22; }
.tile .pill.scale { color: #a8d8ff; border-color: #22384a; }
.tile a.dl { margin-left: auto; font-size: 12px; color: var(--accent-2); text-decoration: none; font-weight: 600; }
.tile a.dl:hover { text-decoration: underline; }

.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- mobile / PWA ---- */
@media (max-width: 640px) {
  .run-bar { flex-wrap: wrap; }
  .run-hint { width: 100%; order: 5; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  /* 16px inputs stop iOS Safari from zooming in on focus */
  .mf input, .mg input, table.manual input, .ctl select, #templateSel { font-size: 16px; }
  .topbar { padding: 18px 16px 10px; }
  .topbar h1 { font-size: 19px; }
}
