:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #12161f;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #1f5fd6;
  --brand-ink: #0b3c96;
  --danger: #b91c1c;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

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

.wrap { width: min(1200px, 94vw); margin: 0 auto; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .wrap {
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 62px;
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 18px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; }
.nav a { color: var(--muted); }
.nav a:hover { color: var(--brand); }

main.wrap { padding: 28px 0 60px; }

h1 { font-size: 26px; margin: 0 0 14px; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.hero { padding: 18px 0 10px; }
.hero h1 { font-size: 32px; margin-bottom: 6px; }
.hero p { color: var(--muted); margin: 0 0 14px; }
.count { font-size: 13px; color: var(--muted); }

.search { display: flex; gap: 8px; max-width: 520px; }
.search input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
}
.search button, .btn {
  padding: 11px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-block;
}
.search button:hover, .btn:hover { background: var(--brand-ink); text-decoration: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s ease, transform .15s ease;
}
.card:hover { box-shadow: 0 10px 30px rgba(15, 23, 42, .09); transform: translateY(-2px); }
.thumb { display: block; aspect-ratio: 4 / 3; background: #eef1f5; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.noimg {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; color: var(--muted); font-size: 13px;
}
.noimg.big { aspect-ratio: 4 / 3; border-radius: var(--radius); background: #eef1f5; }
.cardbody { padding: 12px 14px 16px; }
.cardbody h3 { margin: 0 0 8px; font-size: 15px; line-height: 1.35; }
.cardbody h3 a { color: var(--ink); }
.cardbody h3 a:hover { color: var(--brand); text-decoration: none; }
.price { margin: 0; font-weight: 700; color: var(--brand-ink); }
.price.big { font-size: 24px; }
.unit, .cat { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.detail { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 28px; }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: start; }
.gallery img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); object-fit: cover; aspect-ratio: 1 / 1; }
.gallery img:first-child { grid-column: 1 / -1; aspect-ratio: 4 / 3; }
.info h1 { font-size: 26px; }
.desc { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); color: #374151; }
.meta { color: var(--muted); font-size: 13px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 0 0 18px;
}
.panel.narrow { max-width: 520px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; color: var(--muted); font-size: 13px;
}
.stat span { display: block; font-size: 26px; font-weight: 700; color: var(--ink); }

label { display: block; margin: 0 0 12px; font-size: 14px; color: #374151; }
input[type=text], input[type=search], input[type=password], input[type=number], textarea {
  width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; font: inherit; background: #fff;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.form-grid .wide { grid-column: 1 / -1; }

.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { background: #f9fafb; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.tbl tr:last-child td { border-bottom: 0; }
.link { background: none; border: 0; padding: 0; color: var(--brand); cursor: pointer; font: inherit; }
.link.danger { color: var(--danger); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: #eef1f5; color: #374151; }
.pill.queued { background: #fef3c7; color: #92400e; }
.pill.picked { background: #dbeafe; color: #1e40af; }
.pill.done, .pill.ok { background: #dcfce7; color: #166534; }
.pill.failed, .pill.err, .pill.error { background: #fee2e2; color: #991b1b; }
.pill.partial, .pill.warn { background: #ffedd5; color: #9a3412; }

.rowform { display: inline; }
.inline-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.formgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.formgrid .wide { grid-column: 1 / -1; }
.formgrid label { display: block; font-size: 13px; color: var(--muted); }
.formgrid input, .formgrid select, .formgrid textarea {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-size: 14px;
}
.formgrid textarea { min-height: 130px; resize: vertical; }
.formgrid .hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.errbox { background: #fee2e2; color: #991b1b; border-radius: 10px; padding: 12px 16px; margin: 0 0 16px; font-size: 14px; }
.errbox ul { margin: 6px 0 0; padding-left: 18px; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; background: #dcfce7; color: #166534; }
.flash.err { background: #fee2e2; color: #991b1b; }

.code, .token {
  display: block; background: #0f172a; color: #e2e8f0; padding: 12px 14px;
  border-radius: 10px; font-size: 12.5px; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}
.token { background: #f1f5f9; color: #0f172a; }

.pager { display: flex; gap: 6px; margin: 26px 0 0; flex-wrap: wrap; }
.pager a { padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-size: 14px; }
.pager a.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager .gap { padding: 7px 4px; color: var(--muted); }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px 24px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--ink); }

.foot { border-top: 1px solid var(--line); padding: 20px 0; color: var(--muted); font-size: 13px; background: var(--surface); }

@media (max-width: 820px) {
  .detail { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

/* description toolbar + media picker on the product form */
.mdbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 8px 0 4px; }
.mdbar button {
  padding: 5px 10px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 7px; font-size: 13px; line-height: 1.2; cursor: pointer;
}
.mdbar button:hover { border-color: var(--brand); color: var(--brand); }
.mdbar-hint { font-size: 12px; color: var(--muted); }
.mdbar-hint code { background: #eef1f5; padding: 1px 4px; border-radius: 4px; }
.desc-input { min-height: 200px; }
.media-box { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: #fbfcfd; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.thumbs figure { margin: 0; width: 112px; }
.thumbs img { width: 100%; height: 112px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.thumbs figcaption { font-size: 11px; color: var(--muted); text-align: center; margin-top: 4px; }
.desc p { margin: 8px 0; }
.desc ul, .desc ol { margin: 8px 0 8px 20px; padding: 0; }
.desc li { margin: 4px 0; }
.desc b, .desc strong { font-weight: 700; color: var(--ink); }

/* rich-text description editor */
.rte { border: 1px solid var(--line); border-radius: 10px; background: #fff; overflow: hidden; }
.rte:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 95, 214, .12); }
.rte-toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fbfcfd; }
.rte-toolbar button {
  min-width: 32px; padding: 5px 9px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 7px; font-size: 13px; line-height: 1.2; cursor: pointer;
}
.rte-toolbar button:hover { border-color: var(--brand); color: var(--brand); }
.rte-toolbar button.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }
.rte-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.rte-body { min-height: 220px; max-height: 520px; overflow-y: auto; padding: 12px 14px; font-size: 15px; line-height: 1.55; outline: none; }
.rte-body.is-empty::before { content: attr(data-placeholder); color: var(--muted); pointer-events: none; }
.rte-body p { margin: 0 0 10px; }
.rte-body ul, .rte-body ol { margin: 0 0 10px 22px; padding: 0; }
.rte-body li { margin: 4px 0; }
.rte-body h3 { margin: 4px 0 10px; font-size: 17px; }
.rte-body a { color: var(--brand); text-decoration: underline; }
.rte-src { display: none; }
.rte-error { margin: 6px 0 0; color: var(--danger); font-size: 13px; }
.rte-field > label { display: block; margin-bottom: 6px; font-weight: 600; }
@media (max-width: 640px) {
  .rte-toolbar { gap: 4px; }
  .rte-toolbar button { padding: 6px 8px; }
}


/* product list only: id chip + row thumbnails (scoped so other admin tables keep their widths) */
.tbl-products code.pid {
  display: inline-block; padding: 2px 6px; border-radius: 6px;
  background: #f3f4f6; border: 1px solid var(--line);
  font-size: 12px; color: #374151; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tbl-products th:nth-child(1), .tbl-products td:nth-child(1) { width: 64px; }
.tbl-products th:nth-child(2), .tbl-products td:nth-child(2) { width: 120px; }
.thumb-stack { position: relative; display: inline-flex; gap: 6px; align-items: center; }
.thumb-link { position: relative; display: inline-block; line-height: 0; }
.tbl-products img.thumb-sm {
  width: 52px; height: 52px; object-fit: cover; display: block;
  border: 1px solid var(--line); border-radius: 8px; background: #eef1f5;
}
.thumb-link:hover img.thumb-sm { border-color: #9ca3af; box-shadow: 0 0 0 2px #eef1f5; }
.tbl-products span.thumb-sm-empty {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 8px;
  border: 1px dashed var(--line); background: #fbfcfd;
  color: var(--muted); font-size: 15px;
}
.thumb-stack .thumb-count {
  position: absolute; right: -6px; bottom: -6px; min-width: 16px; text-align: center;
  background: #111827; color: #fff; font-size: 10px; font-weight: 600; line-height: 1;
  padding: 3px 5px; border-radius: 999px; box-shadow: 0 0 0 2px var(--surface);
}
.thumb-link.is-broken::after {
  content: '—'; display: flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 8px;
  border: 1px dashed var(--line); background: #fbfcfd; color: var(--muted); font-size: 15px;
}
