/* ----------------------------------------------------------------------- *
   Pit Wall — die-cast parts inventory
   Palette: garage charcoal chrome + cardboard blister cards + flame accent
 * ----------------------------------------------------------------------- */
:root {
  --ink:        #16181d;
  --ink-2:      #1d212a;
  --panel:      #1f242e;
  --line:       rgba(255, 255, 255, 0.09);
  --line-soft:  rgba(255, 255, 255, 0.05);

  --card:       #f5f1e7;
  --card-edge:  #e7e0d0;
  --card-ink:   #1b1a16;
  --card-muted: #756f63;

  --text:       #ecebe6;
  --text-dim:   #9a9eaa;

  --flame-red:    #e5230f;
  --flame-orange: #ff6a00;
  --flame-yellow: #ffc31f;
  --flame: linear-gradient(100deg, var(--flame-red) 0%, var(--flame-orange) 55%, var(--flame-yellow) 100%);

  --amber:  #f2a33c;
  --danger: #e5230f;
  --good:   #4caf6a;

  --r-card: 14px;
  --r-sm: 9px;
  --shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 10px 24px rgba(0,0,0,.28);

  --font-disp: "Saira Condensed", "Arial Narrow", sans-serif;
  --font-head: "Saira", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 85% -10%, #232838 0%, transparent 60%),
    var(--ink);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
::selection { background: var(--flame-orange); color: #fff; }

/* ----------------------------------- top bar ----------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 26px;
  background: rgba(22, 24, 29, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

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

.flame-mark {
  width: 20px; height: 26px;
  background: var(--flame);
  align-self: center;
  -webkit-clip-path: polygon(50% 0, 70% 35%, 92% 18%, 78% 52%, 100% 60%, 60% 70%, 66% 100%, 42% 74%, 16% 92%, 30% 60%, 0 50%, 28% 40%, 18% 12%, 46% 30%);
  clip-path: polygon(50% 0, 70% 35%, 92% 18%, 78% 52%, 100% 60%, 60% 70%, 66% 100%, 42% 74%, 16% 92%, 30% 60%, 0 50%, 28% 40%, 18% 12%, 46% 30%);
  filter: drop-shadow(0 2px 5px rgba(229, 35, 15, .5));
}
.flame-mark.big { width: 46px; height: 58px; margin-bottom: 8px; }

.wordmark {
  font-family: var(--font-disp);
  font-weight: 800;
  font-style: italic;
  font-size: 30px;
  letter-spacing: 0.5px;
  line-height: 1;
  color: #fff;
}
.brand-sub {
  font-family: var(--font-disp);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2.5px;
  font-size: 11px;
  color: var(--text-dim);
}

.summary { display: flex; gap: 10px; }
.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 4px 16px;
  border-left: 1px solid var(--line);
  min-width: 74px;
}
.stat:first-child { border-left: none; }
.stat-num {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 26px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-dim);
  margin-top: 3px;
}
.stat-low .stat-num { color: var(--amber); }

/* ----------------------------------- toolbar ----------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px 26px;
  max-width: 1400px;
  margin: 0 auto;
}

.search-wrap { position: relative; flex: 1 1 280px; }
.search-icon {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px; fill: var(--text-dim);
  pointer-events: none;
}
#search {
  width: 100%;
  padding: 11px 14px 11px 38px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 14px;
}
#search:focus { outline: none; border-color: var(--flame-orange); }
#search::placeholder { color: var(--text-dim); }

.filters { display: flex; align-items: center; gap: 12px; }
.select { display: flex; align-items: center; gap: 8px; }
.select > span {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-dim);
}
.select select {
  appearance: none;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px 30px 9px 12px;
  font-size: 13px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%239a9eaa'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 18px;
}
.select select:focus { outline: none; border-color: var(--flame-orange); }

.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 15px;
  font-size: 13px;
  font-weight: 600;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn.is-active { background: var(--flame); color: #fff; }

.tool-actions { display: flex; gap: 10px; margin-left: auto; }

/* ----------------------------------- buttons ----------------------------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  transition: transform .08s ease, filter .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.small { padding: 7px 12px; font-size: 12px; }
.btn-flame {
  background: var(--flame);
  color: #fff;
  box-shadow: 0 4px 14px rgba(229, 35, 15, .35);
}
.btn-flame:hover { filter: brightness(1.06); }
.btn-ghost {
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
}
.btn-ghost:hover { border-color: var(--text-dim); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.icon-btn {
  border: none; background: transparent; color: var(--card-muted);
  font-size: 26px; line-height: 1; width: 36px; height: 36px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(0,0,0,.06); color: var(--card-ink); }

/* ------------------------------------ grid ------------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 20px;
  padding: 8px 26px 60px;
  max-width: 1400px;
  margin: 0 auto;
}

/* grouped view: store-style grid of square type tiles */
.grid.tiles {
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
}
.type-tile {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: var(--card-ink);
  transition: transform .14s ease, box-shadow .14s ease;
  animation: pop-in .25s ease both;
}
.type-tile:hover {
  transform: translateY(-3px);
  box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 14px 30px rgba(0,0,0,.34);
}
.type-tile:focus-visible { outline: 2px solid var(--flame-orange); outline-offset: 2px; }
.tile-photo {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.tile-photo img { width: 100%; height: 100%; object-fit: cover; }
.tile-noimg {
  font-family: var(--font-disp);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 12px;
  color: #b9b2a2;
}
.tile-count {
  position: absolute;
  bottom: 8px; right: 8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  background: rgba(20,22,26,.82);
  border-radius: 999px;
}
.tile-low {
  position: absolute;
  top: 8px; left: 8px;
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: .4px;
  color: #fff;
  background: var(--amber);
  padding: 2px 8px;
  border-radius: 999px;
}
.tile-info { padding: 10px 12px 12px; }
.tile-name {
  display: block;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-sub {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  color: var(--card-muted);
}

/* drilled-in single type */
.grid.opened { display: block; }
.type-open { max-width: 1400px; margin: 0 auto; }
.open-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 18px;
}
.back-link {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.back-link:hover { background: var(--ink-2); color: var(--text); }
.open-title {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 22px;
  color: var(--text);
  margin: 0;
}
.open-sub { font-family: var(--font-disp); font-size: 13px; color: var(--text-dim); }
.open-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(218px, 1fr));
  gap: 18px;
}
.open-empty { color: var(--text-dim); font-size: 14px; }

@media (max-width: 560px) {
  .grid.tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
  .open-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}

/* blister-pack card */
.card {
  position: relative;
  background: var(--card);
  color: var(--card-ink);
  border-radius: var(--r-card);
  border: 1px solid var(--card-edge);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pop-in .25s ease both;
}
/* the punched hang-hole at the top of a blister pack */
.card::before {
  content: "";
  position: absolute;
  top: 9px; left: 50%; transform: translateX(-50%);
  width: 34px; height: 9px; border-radius: 9px;
  background: var(--ink);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.6);
  z-index: 2;
}
.card-photo {
  position: relative;
  margin: 24px 12px 0;
  aspect-ratio: 4 / 3;
  border-radius: 9px;
  background: #fff center/cover no-repeat;
  border: 1px solid var(--card-edge);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.card-photo .no-photo {
  font-family: var(--font-disp);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-size: 12px;
  color: #b9b2a2;
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 11px 14px 4px; flex: 1; }
.card-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
  margin: 0;
}
.card-meta {
  display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap;
}
.color-tag {
  font-family: var(--font-disp);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .5px;
  text-transform: lowercase;
  background: #ece5d6;
  color: #5d5747;
  padding: 2px 7px;
  border-radius: 5px;
}
.price { font-weight: 700; font-size: 13px; color: #3a3a36; }
.card-add {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--card-muted);
}
.card-desc {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--card-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* quantity stepper */
.stepper {
  display: flex;
  align-items: center;
  margin: 10px 12px 12px;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid var(--card-edge);
}
.step-btn {
  border: none;
  width: 46px; height: 52px;
  font-family: var(--font-disp);
  font-size: 26px; font-weight: 700;
  color: #fff;
  background: var(--card-ink);
  display: flex; align-items: center; justify-content: center;
}
.step-btn.plus { background: var(--flame); }
.step-btn.minus { background: #2a2924; }
.step-btn:hover { filter: brightness(1.1); }
.step-btn:disabled { opacity: .35; cursor: not-allowed; filter: none; }

.qty {
  flex: 1;
  text-align: center;
  background: #fff;
  height: 52px;
}
.qty-input {
  width: 100%; height: 100%;
  border: none; background: transparent; text-align: center;
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: 30px;
  color: var(--card-ink);
  font-variant-numeric: tabular-nums;
}
.qty-input:focus { outline: none; background: #fffaf0; }
.qty.flash { animation: qty-flash .4s ease; }
.qty.low .qty-input { color: var(--amber); }
.qty.out .qty-input { color: var(--danger); }

/* status ribbon */
.ribbon {
  position: absolute;
  top: 26px; right: -34px;
  transform: rotate(38deg);
  width: 130px; text-align: center;
  font-family: var(--font-disp);
  font-weight: 700; font-size: 11px; letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #fff; padding: 4px 0;
  z-index: 3;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.ribbon.low { background: var(--amber); }
.ribbon.out { background: var(--danger); }

/* card hover tools */
.card-tools {
  position: absolute;
  top: 26px; left: 10px;
  display: flex; gap: 6px;
  opacity: 0;
  transition: opacity .15s ease;
  z-index: 3;
}
.card:hover .card-tools, .card:focus-within .card-tools { opacity: 1; }
.tool {
  border: none;
  width: 30px; height: 30px;
  border-radius: 7px;
  background: rgba(27,26,22,.82);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.tool svg { width: 15px; height: 15px; fill: currentColor; }
.tool:hover { background: var(--card-ink); }
.tool.del:hover { background: var(--danger); }

/* ----------------------------------- empties ----------------------------- */
.empty {
  text-align: center;
  max-width: 460px;
  margin: 70px auto;
  color: var(--text-dim);
}
.empty h2 { font-family: var(--font-head); color: var(--text); margin: 8px 0 6px; }
.empty p { margin: 0 0 18px; }
.hidden { display: none !important; }

/* ----------------------------------- dialogs ----------------------------- */
.dialog {
  border: none;
  padding: 0;
  border-radius: 16px;
  background: var(--ink-2);
  color: var(--text);
  width: min(560px, 92vw);
  box-shadow: 0 30px 70px rgba(0,0,0,.55);
}
.dialog::backdrop { background: rgba(8, 9, 12, 0.66); backdrop-filter: blur(3px); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 0; font-family: var(--font-head); font-size: 20px; }
.dialog-head .icon-btn { color: var(--text-dim); }
.dialog-head .icon-btn:hover { color: #fff; background: rgba(255,255,255,.08); }

.form-body { display: flex; gap: 18px; padding: 20px; }
@media (max-width: 540px) { .form-body { flex-direction: column; } }

.photo-field { flex: 0 0 150px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.photo-preview {
  width: 150px; height: 150px;
  border-radius: 12px;
  border: 2px dashed var(--line);
  background: var(--panel) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  overflow: hidden;
  text-align: center;
}
.photo-preview:hover { border-color: var(--flame-orange); }
.photo-hint { font-size: 12px; color: var(--text-dim); padding: 0 10px; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }

.fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-dim);
}
.field > span em { color: var(--flame-orange); font-style: normal; }
.field input, .field textarea {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--flame-orange); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.dialog-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}
.confirm { padding: 24px; }
.confirm h2 { margin: 0 0 6px; font-family: var(--font-head); }
.confirm p { margin: 0 0 8px; color: var(--text-dim); }
.confirm .dialog-foot { border: none; padding: 18px 0 0; }

/* ----------------------------------- toast ------------------------------- */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card-ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* ---------------------------------- motion ------------------------------- */
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes qty-flash { 0% { background: #fff; } 35% { background: #ffe7c2; } 100% { background: #fff; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* focus ring for keyboard users */
:focus-visible { outline: 2px solid var(--flame-orange); outline-offset: 2px; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; }
  .summary { width: 100%; justify-content: space-between; }
  .stat { align-items: center; flex: 1; }
  .tool-actions { width: 100%; }
  .tool-actions .btn { flex: 1; }
}
