/* Inventory & SKU Management — one stylesheet, no framework, no build step. */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16191d;
  --muted: #656d78;
  --line: #dfe3e8;
  --accent: #1f6feb;
  --accent-soft: #e8f0fe;
  --ok: #17803d;
  --ok-soft: #e6f4ea;
  --warn: #a35a00;
  --warn-soft: #fdf0dc;
  --bad: #b3261e;
  --bad-soft: #fce8e6;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --panel: #1c2024;
    --ink: #e8eaed;
    --muted: #9aa4af;
    --line: #2c3238;
    --accent: #7aa7ff;
    --accent-soft: #1e2836;
    --ok: #6ddc95;
    --ok-soft: #14291c;
    --warn: #f0b862;
    --warn-soft: #2c2213;
    --bad: #f2938c;
    --bad-soft: #2e1a19;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- topbar -- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}
.brand { font-weight: 650; color: var(--ink); font-size: 16px; }
.brand span { letter-spacing: -0.01em; }
.mainnav { display: flex; gap: 4px; }
.mainnav a {
  padding: 6px 11px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 500;
}
.mainnav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.mainnav a.on { background: var(--accent-soft); color: var(--accent); }
.quicksearch { flex: 1 1 240px; max-width: 460px; }
.quicksearch input { width: 100%; }
.whoami { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.who { color: var(--muted); font-size: 13px; }
.who em { font-style: normal; background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 1px 8px; margin-left: 4px; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }

.foot {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 20px 30px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* ----------------------------------------------------------------- type --- */
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 26px 0 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
.sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.pagehead { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.pagehead .grow { flex: 1; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }

/* --------------------------------------------------------------- panels --- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 18px;
}
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }

/* A panel heading reads as a section header, with a hairline under it. */
.panel > h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
  padding-bottom: 10px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.panel > h2 .spec, .panel > h2 .badge { text-transform: none; letter-spacing: 0; }
.panel > h2 + .spec, .panel > h2 + .sub { margin-top: -8px; }

/* The submit row, so a form ends with a clear action rather than a stray button. */
.panel.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.panel.form-actions .spacer { flex: 1; }
.split { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- tiles --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 22px; }
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: block;
  color: var(--ink);
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 27px; font-weight: 600; margin-top: 4px; letter-spacing: -0.02em; }
.tile .note { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.tile.bad .value { color: var(--bad); }
.tile.warn .value { color: var(--warn); }
.tile.wide { grid-column: span 2; }
@media (max-width: 620px) { .tile.wide { grid-column: span 1; } }

/* --------------------------------------------------------------- tables --- */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--bg); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 26px 0; text-align: center; }

/* --------------------------------------------------------------- badges --- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 12px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.muted { color: var(--muted); }
.derived { color: var(--muted); font-size: 11.5px; display: block; }

/* --------------------------------------------------------------- forms ---- */
/* Match by exclusion, not by listing types: an <input> with no type attribute
   is still a text box, and selecting on [type=text] silently leaves it
   unstyled at the browser's default width. */
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=submit]):not([type=button]),
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 11px;
  width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:hover:not([type=checkbox]):not([type=radio]):not([type=file]),
select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }

label { display: block; font-size: 13px; font-weight: 500; color: var(--ink); margin-bottom: 6px; }
.field { margin-bottom: 18px; }
.field:last-child { margin-bottom: 0; }
.field .hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; line-height: 1.45; }

/* A single-line field stretched across a wide panel looks unfinished; cap it
   while textareas and explicit full-width fields still fill the panel. */
.field > input:not([type=checkbox]):not([type=radio]):not([type=file]),
.field > select { max-width: 560px; }
.field.wide > input, .field.wide > select, .field > textarea { max-width: none; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }
.checkline { display: flex; align-items: center; gap: 8px; }
.checkline input { width: auto; }
.checkline label { margin: 0; color: var(--ink); }

button, .btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 16px;
  cursor: pointer;
  display: inline-block;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
button:hover, .btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
.btn.primary, button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 550;
}
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.primary:disabled, button.primary:disabled { filter: none; }
.btn.danger, button.danger { color: var(--bad); border-color: var(--bad); }
.btn.small, button.small { padding: 3px 9px; font-size: 13px; }
.linkish { border: none; background: none; color: var(--accent); padding: 0; cursor: pointer; font: inherit; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }

/* --------------------------------------------------------------- flash ---- */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid transparent; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.error { background: var(--bad-soft); color: var(--bad); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }

.banner {
  padding: 11px 15px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 14px;
}

/* --------------------------------------------------------------- filters -- */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 130px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 16px; color: var(--muted); font-size: 14px; }

/* --------------------------------------------------------------- images --- */
/* The stored thumbnail is 300 px, so it stays crisp at every size below. */
.thumb {
  width: 96px;
  height: 96px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
  border: 1px solid var(--line);
  display: block;
}
.thumb:hover { border-color: var(--accent); }

/* Compact variants, so a big list thumbnail does not stretch these rows. */
.picker-item .thumb,
.components-table .thumb { width: 52px; height: 52px; }

.gallery { display: flex; gap: 14px; flex-wrap: wrap; }
.gallery figure { margin: 0; text-align: center; }
.gallery img {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
}
.gallery img:hover { border-color: var(--accent); }
.gallery figcaption { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* The photo comes first on the SKU page: a large primary image with the other
   positions beside it, and the details panel below. */
.photo-strip { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.photo-strip .gallery { flex: 1 1 200px; }

.hero-image {
  width: 360px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  display: block;
}
.hero-image:hover { border-color: var(--accent); }

@media (max-width: 560px) {
  .hero-image { width: 100%; }
}

/* -------------------------------------------------------------- helpers --- */
/* A single headline figure inside a panel. */
.stat-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 14px;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.spec { color: var(--muted); font-size: 12px; }
hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

.login {
  max-width: 340px;
  margin: 9vh auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
}
.login h1 { margin-bottom: 18px; }

/* ------------------------------------------------- combo recipe builder --- */
.picker { position: relative; display: inline-block; }

.picker-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  width: min(460px, 86vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .16);
  padding: 10px;
}
.picker-panel input[type=search] { margin-bottom: 8px; }

.picker-results { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow-y: auto; }
.picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.picker-item:hover { background: var(--accent-soft); }
.picker-item.already { opacity: .78; }
.picker-text { flex: 1; min-width: 0; font-size: 14px; line-height: 1.35; }
.picker-text .meta { display: block; color: var(--muted); font-size: 12px; }
.picker-add {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2px 10px;
  white-space: nowrap;
}
.picker-item:hover .picker-add { border-color: var(--accent); }
.picker-empty { padding: 14px 8px; color: var(--muted); font-size: 14px; text-align: center; }
.picker-foot { margin: 8px 2px 0; }

.thumb.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 30px;
  color: var(--muted);
  background: var(--bg);
  border-style: dashed;
}
.picker-item .thumb.placeholder,
.components-table .thumb.placeholder { font-size: 18px; }
.thumb.small { width: 28px; height: 28px; font-size: 12px; }

.components-table td { vertical-align: middle; }
.components-table tr.bumped { animation: bump .7s ease; }
@keyframes bump {
  0%   { background: var(--accent-soft); }
  100% { background: transparent; }
}

.qty-control { display: flex; align-items: center; }
.qty-control .qty-input { width: 68px; text-align: center; border-radius: 0; position: relative; z-index: 1; }
.qty-step { width: 32px; padding: 7px 0; font-size: 16px; line-height: 1; border-radius: 6px 0 0 6px; }
.qty-step[data-step="1"] { border-radius: 0 6px 6px 0; }

.row-remove {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  padding: 2px 8px;
  cursor: pointer;
}
.row-remove:hover { color: var(--bad); }

.builder-summary { margin: 12px 2px 0; font-size: 13.5px; color: var(--muted); }
.builder-summary.warn { color: var(--warn); }

.advanced { margin-top: 16px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; -webkit-user-select: none; user-select: none; }
.advanced summary:hover { color: var(--accent); }

/* --------------------------------------------- chosen-file previews ------- */
.file-previews { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.file-preview { margin: 0; width: 92px; }
.file-preview img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  display: block;
}
.file-preview figcaption { font-size: 11.5px; color: var(--muted); margin-top: 4px; line-height: 1.3; }
.file-preview figcaption span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: .8;
}
.file-preview.over-limit img { opacity: .35; border-style: dashed; }
.file-preview.over-limit figcaption { color: var(--warn); }
.file-preview-note { flex-basis: 100%; margin: 2px 0 0; font-size: 12.5px; color: var(--warn); }

/* ----------------------------------------------------- SKU listing rows --- */
.sku-row td { vertical-align: middle; }
.sku-row.is-inactive .sku-title,
.sku-row.is-inactive .thumb { opacity: .6; }

.col-thumb { width: 108px; }
.col-thumb a { display: inline-block; }
.col-stock { width: 130px; white-space: nowrap; }
.col-status { width: 96px; }
.col-act { width: 130px; white-space: nowrap; text-align: right; }
.col-act .btn { margin-left: 6px; }

.sku-title {
  font-weight: 550;
  font-size: 15px;
  color: var(--ink);
  display: inline-block;
  margin-bottom: 4px;
  line-height: 1.35;
}
.sku-title:hover { color: var(--accent); }

.sku-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sku-meta code { color: var(--muted); }
.sku-seller {
  color: var(--muted);
  font-size: 12px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stock-figure { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; display: block; }
.stock-figure.ok { color: var(--ok); }
.stock-figure.warn { color: var(--warn); }
.stock-figure.bad { color: var(--bad); }
.col-stock .derived { margin-top: 1px; }

/* ===========================================================================
   Small screens. The app is used on a phone as much as a desk, so everything
   below reflows rather than shrinking: the nav scrolls instead of wrapping into
   a pile, wide tables scroll inside their own box rather than pushing the page
   sideways, and every control keeps a finger-sized target.
   =========================================================================== */

@media (max-width: 880px) {
  main { padding: 16px 14px 48px; }

  .topbar {
    gap: 10px 14px;
    padding: 10px 14px;
    position: static;           /* a sticky bar eats too much of a short screen */
  }
  .brand { font-size: 15px; }
  .mainnav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .mainnav::-webkit-scrollbar { display: none; }
  .mainnav a { white-space: nowrap; }
  .quicksearch { order: 4; flex-basis: 100%; max-width: none; }
  .whoami { margin-left: auto; }

  .pagehead { gap: 10px; }
  h1 { font-size: 19px; }
  .panel { padding: 14px; }

  /* Tables keep their columns and scroll inside the panel. */
  .tablewrap { margin: 0 -14px; padding: 0 14px; }
  th, td { padding: 8px 8px; }
  table { font-size: 13.5px; }

  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

  .split { gap: 14px; }
  .filters .field { min-width: 0; flex: 1 1 140px; }

  .gallery img { width: 140px; height: 140px; }
  .thumb { width: 76px; height: 76px; }
  .file-preview, .file-preview img { width: 78px; }
  .file-preview img { height: 78px; }

  /* On a phone the product photo is the thing you look for first, so it leads
     the edit page. On a wide screen it stays below the fields, where the form
     reads top-to-bottom without a picture pushing it down. */
  .sku-form-page { display: flex; flex-direction: column; }
  .sku-form-page > .pagehead { order: -2; }
  .sku-form-page > .photos-panel { order: -1; }

  /* The row itself links to the SKU, so the buttons are redundant here. */
  .col-act { display: none; }
  .col-thumb { width: 88px; }
  .col-stock { width: 106px; }
  .sku-seller { max-width: 150px; }
  .sku-title { font-size: 14.5px; }
}

@media (max-width: 560px) {
  /* 16px stops iOS zooming the page when a field is focused. */
  input[type=text], input[type=search], input[type=password],
  input[type=number], input[type=date], select, textarea { font-size: 16px; }

  button, .btn { padding: 9px 14px; min-height: 40px; }
  button.small, .btn.small { min-height: 32px; padding: 4px 10px; }

  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .tile { padding: 12px 13px; }
  .tile .value { font-size: 23px; }

  .filters { gap: 8px; }
  .filters .field { flex: 1 1 100%; }
  .filters button, .filters .btn { flex: 1 1 auto; }

  .row > * { flex: 1 1 100%; }
  .actions { gap: 8px; }
  .actions > form, .actions > button, .actions > .btn { flex: 1 1 auto; }

  .pagehead .actions { width: 100%; }
  .foot { flex-direction: column; gap: 4px; }

  .picker-panel { width: min(420px, 92vw); }
  .gallery img { width: 116px; height: 116px; }
  .thumb { width: 64px; height: 64px; }
  .qty-control .qty-input { width: 56px; }

  /* Keep columns legible: a wide table scrolls sideways inside its panel
     rather than squeezing every cell into an unreadable sliver. */
  .tablewrap > table { min-width: 460px; }
  /* The SKU listing is down to four columns here, so it fits without scrolling. */
  .tablewrap > table.sku-table { min-width: 0; }
  .col-thumb { width: 76px; }
  .col-stock { width: 88px; }
  .col-status { width: auto; }
  .stock-figure { font-size: 17px; }
}

.suggest { position: relative; }
.suggest ul {
  position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
  margin: 2px 0 0; padding: 0; list-style: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  max-height: 260px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.suggest li { padding: 7px 10px; cursor: pointer; font-size: 14px; }
.suggest li:hover, .suggest li.active { background: var(--accent-soft); }
.suggest li .meta { color: var(--muted); font-size: 12px; }
