:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --ink: #15171b;
  --muted: #6a6f78;
  --line: #e4e4de;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --good: #1b7a4b;
  --good-bg: #e6f4ec;
  --warn: #9a5b00;
  --warn-bg: #fdf1dc;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1a1c1f;
    --surface-2: #23262a;
    --ink: #eceef0;
    --muted: #9aa0a8;
    --line: #2d3035;
    --good: #5cc98d;
    --good-bg: #16301f;
    --warn: #e8b152;
    --warn-bg: #33270f;
    --bad: #f08a80;
    --bad-bg: #3a1a17;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 .5em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.main { padding-top: 24px; padding-bottom: 64px; min-height: 70vh; }
.narrow { max-width: 680px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.brand small { font-weight: 500; color: var(--muted); font-size: .8rem; margin-left: 4px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: .95rem;
}
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { text-decoration: none; padding: 6px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; font-size: .92rem; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- storefront ---------- */
.hero { padding: 28px 0 20px; display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: end; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin-bottom: 6px; }
.hero p { margin: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 0; }
.toolbar input[type=search] { width: 220px; max-width: 100%; }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; display: flex; flex-direction: column;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card-img { aspect-ratio: 1 / 1; background: var(--surface-2); position: relative; }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-img .badge { position: absolute; top: 10px; left: 10px; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }
.card-title { font-weight: 600; font-size: .95rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { color: var(--muted); font-size: .8rem; }
.price-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.price { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.msrp { color: var(--muted); font-size: .85rem; text-decoration: line-through; }
.off { color: var(--good); font-weight: 600; font-size: .8rem; }
.is-held { opacity: .75; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge-good, .badge-paid, .badge-active { background: var(--good-bg); color: var(--good); }
.badge-warn, .badge-pending { background: var(--warn-bg); color: var(--warn); }
.badge-bad, .badge-expired, .badge-cancelled { background: var(--bad-bg); color: var(--bad); }
.badge-shipped, .badge-sold { background: var(--surface-2); color: var(--ink); }

.empty { text-align: center; padding: 64px 16px; color: var(--muted); }

.how { margin-top: 56px; display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.how .step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.how .step b { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: .8rem; margin-bottom: 8px; }

/* ---------- item page ---------- */
.item { display: grid; gap: 28px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .item { grid-template-columns: 1.15fr 1fr; align-items: start; } }
.gallery-main { aspect-ratio: 1 / 1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.gallery-main img { width: 100%; height: 100%; object-fit: contain; }
.thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; }
.thumbs button { flex: 0 0 68px; height: 68px; padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: var(--surface-2); cursor: pointer; }
.thumbs button.on { border-color: var(--accent); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.item-info h1 { margin-bottom: 6px; }
.big-price { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.specs { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .9rem; margin: 16px 0; }
.specs dt { color: var(--muted); }
.specs dd { margin: 0; }
.desc { white-space: pre-line; }
.issues { font-weight: 400; }
.issues p { margin: 6px 0 0; }

/* ---------- panels and forms ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.stack > * + * { margin-top: 14px; }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid3 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
label { display: block; font-weight: 500; font-size: .88rem; }
label > input, label > select, label > textarea { margin-top: 5px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-height: 40px;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.choice { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.choice label {
  display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer; background: var(--surface);
}
.choice label:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice span small { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; min-height: 32px; font-size: .85rem; }
.btn-danger { color: var(--bad); }
.btn[disabled] { opacity: .55; cursor: wait; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.totals { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.totals td { padding: 6px 0; }
.totals td:last-child { text-align: right; }
.totals .total td { border-top: 1px solid var(--line); padding-top: 10px; font-weight: 700; font-size: 1.15rem; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash-ok { background: var(--good-bg); color: var(--good); }
.flash-bad { background: var(--bad-bg); color: var(--bad); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- order / pay page ---------- */
.pay { text-align: center; }
.pay .amount { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 4px 0; }
.code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 700; letter-spacing: .08em; background: var(--surface-2); padding: 2px 8px; border-radius: 6px; }
.qr { display: inline-block; background: #fff; padding: 12px; border-radius: 12px; margin: 12px auto; }
.copy { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- admin ---------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .label { color: var(--muted); font-size: .82rem; }
.stat .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list td.r, table.list th.r { text-align: right; font-variant-numeric: tabular-nums; }
table.list tfoot td { font-weight: 700; border-bottom: 0; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }
.edit-layout { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .edit-layout { grid-template-columns: 1fr 360px; align-items: start; } .sticky { position: sticky; top: 76px; } }
.photo-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.photo-grid figure { margin: 0; position: relative; }
.photo-grid img { aspect-ratio: 1/1; object-fit: cover; width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.photo-grid figcaption { font-size: .75rem; display: flex; justify-content: space-between; gap: 4px; margin-top: 4px; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; cursor: pointer;
  background: var(--surface-2);
}
.drop:hover { border-color: var(--accent); }
.drop input { display: none; }
.ai-box { border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.rates { display: grid; gap: 6px 14px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.rates label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 400; }
.rates input { width: 80px; min-height: 32px; padding: 4px 8px; margin: 0; }

.footer { border-top: 1px solid var(--line); padding: 28px 0; }
.footer-in { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.footer p { margin: 4px 0 0; }

[hidden] { display: none !important; }
