:root {
  --bg: #f4eee2;
  --bg-2: #ebe3d4;
  --card: #fffdf8;
  --ink: #102136;
  --muted: #5a6270;
  --line: #ddd4c6;
  --coal: #102136;
  --coal-2: #1a2e48;
  --brass: #c9b57a;
  --brass-soft: #e8d9a8;
  --rust: #c51f24;
  --ok: #2f6b4f;
  --red: #c51f24;
  --night: #102136;
  --wave: #2a5f8f;
  --cream: #f4eee2;
  --shadow: 0 1px 2px rgba(16, 33, 54, 0.07);
  --radius: 12px;
  --header: 56px;
  --bottom: 60px;
  --max: 1180px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: clip; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: calc(var(--bottom) + env(safe-area-inset-bottom));
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
.badge[hidden], [hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.skip {
  position: absolute; left: 10px; top: -48px;
  background: var(--coal); color: #fff; padding: 8px 12px; z-index: 40;
}
.skip:focus { top: 8px; }

/* Prototype banner */
.banner {
  background: var(--coal);
  color: #f4eee2;
  font-size: 0.72rem;
  letter-spacing: 0.01em;
  text-align: center;
  padding: 6px 12px;
  line-height: 1.3;
}
.banner strong { color: #f0c9c9; font-weight: 650; }

/* Header */
.header {
  position: sticky; top: 0; z-index: 30;
  background: rgba(244, 238, 226, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.header-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--header);
  padding: 8px 12px 6px;
  max-width: var(--max);
  margin: 0 auto;
}
.logo {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; flex-shrink: 0;
}
.logo img, .logo svg { width: 36px; height: 36px; display: block; }
.logo img { border-radius: 50%; object-fit: cover; background: var(--night); box-shadow: 0 0 0 1.5px var(--brass-soft); }
.logo-text { display: flex; flex-direction: column; line-height: 1.1; }
.logo-text strong {
  font-size: 0.98rem;
  font-weight: 750;
  letter-spacing: 0.01em;
}
.logo-text small {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
  margin-top: 2px;
}
.admin-only { display: none !important; }
body.is-admin .sell-btn.admin-only { display: inline-flex !important; }
body.is-admin .logout-btn.admin-only { display: inline-flex !important; }
body.is-admin .sell-nav.admin-only { display: flex !important; }
body.is-admin .owner-actions.admin-only { display: grid !important; }
body.is-admin .admin-bar.admin-only { display: block !important; }
body.is-admin .empty-cta.admin-only { display: block !important; }

.admin-bar {
  background: #1a2e48;
  color: #e8d9a8;
  font-size: 0.72rem;
  text-align: center;
  padding: 5px 12px;
}
.logout-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  padding: 8px 6px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.sell-btn {
  margin-left: auto;
  display: none;
  align-items: center; gap: 4px;
  background: var(--red);
  color: #fff !important;
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 999px;
  padding: 8px 12px;
  line-height: 1;
  white-space: nowrap;
}
.sell-btn:hover { filter: brightness(1.08); }
.header-actions {
  margin-left: auto;
  display: flex; align-items: center; gap: 2px;
}
body.is-admin .header-actions { margin-left: 2px; }
.icon-btn {
  position: relative;
  width: 42px; height: 42px;
  border: 0; background: transparent;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink);
  text-decoration: none;
}
.icon-btn:hover, .icon-btn:focus-visible { background: var(--bg-2); }
.icon-btn svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: 4px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 99px;
  background: var(--rust); color: #fff;
  font-size: 0.62rem; font-weight: 700;
  display: grid; place-items: center;
  line-height: 1;
}
.icon-btn.active { color: var(--rust); }

.search-row {
  padding: 0 12px 10px;
  max-width: var(--max);
  margin: 0 auto;
}
.search {
  display: flex; align-items: center; gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--wave); box-shadow: 0 0 0 3px rgba(42, 95, 143, 0.2); }
.search svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.search input {
  border: 0; outline: 0; background: transparent;
  width: 100%; font-size: 0.95rem;
}
.search input::placeholder { color: #8b857a; }

/* Catalog controls */
.controls { max-width: var(--max); margin: 0 auto; }
.chips {
  display: flex; gap: 8px;
  overflow-x: auto;
  padding: 12px 12px 6px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.is-on {
  background: var(--coal);
  border-color: var(--coal);
  color: #f6f1e7;
}
.sort-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  padding: 4px 12px 10px;
  font-size: 0.82rem; color: var(--muted);
}
.sort-row label { display: flex; align-items: center; gap: 6px; }
.sort-row select {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 6px 8px;
}
.count { font-weight: 600; color: var(--ink); }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 10px 16px;
  max-width: var(--max);
  margin: 0 auto;
}
.card {
  position: relative;
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
  text-decoration: none;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  border: 1px solid rgba(22,20,16,0.04);
  color: inherit;
  min-width: 0;
}
.card:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #e8e2d6;
  overflow: hidden;
}
.thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center;
}
.heart {
  position: absolute; top: 6px; right: 6px;
  width: 36px; height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 1px 3px rgba(0,0,0,0.16);
  display: grid; place-items: center;
  color: var(--ink);
  z-index: 2;
}
.heart svg { width: 18px; height: 18px; }
.heart.is-on { color: var(--rust); }
.heart.is-on svg path { fill: currentColor; }
.meta { padding: 8px 9px 10px; min-width: 0; }
.price {
  font-weight: 750;
  font-size: 0.98rem;
  letter-spacing: -0.01em;
}
.title {
  margin: 2px 0 0;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.detail {
  margin-top: 3px;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty, .notice {
  max-width: var(--max);
  margin: 16px auto;
  padding: 28px 18px;
  text-align: center;
  color: var(--muted);
}
.empty h2, .notice h2 { color: var(--ink); font-size: 1.1rem; margin: 0 0 8px; }

/* Product detail */
.detail-page { max-width: 760px; margin: 0 auto; padding-bottom: 24px; }
.back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 12px;
  text-decoration: none;
  font-weight: 600; font-size: 0.9rem;
}
.hero-img {
  background: #e8e2d6;
  aspect-ratio: 1 / 1;
  max-height: 40vh;
  overflow: hidden;
}
.hero-img img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center;
}
.detail-page {
  padding-bottom: 8px;
}
.detail-body {
  padding-bottom: 128px;
}
.detail-body { padding: 16px 16px 0; }
.detail-price { font-size: 1.55rem; font-weight: 750; letter-spacing: -0.02em; }
.detail-title { margin: 4px 0 8px; font-size: 1.2rem; font-weight: 700; line-height: 1.25; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.pill {
  background: var(--bg-2);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 600;
}
.pill.ok { background: #e4f0e9; color: var(--ok); }
.pill.warn { background: #f8eadf; color: #8a3b16; }
.desc {
  font-size: 0.95rem;
  white-space: pre-wrap;
  margin: 0 0 16px;
}
.box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
}
.box h3 { margin: 0 0 6px; font-size: 0.82rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.tax { font-size: 0.8rem; color: var(--muted); margin: 8px 0 16px; }
.sticky-buy {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--bottom) + env(safe-area-inset-bottom));
  z-index: 20;
  background: linear-gradient(transparent, var(--bg) 28%);
  padding: 12px 16px 14px;
  display: flex; gap: 8px;
  max-width: 760px;
  margin: 0 auto;
}
.btn {
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary { background: var(--coal); color: #f6f1e7; flex: 1; }
.btn-primary:hover { background: var(--coal-2); }
.btn-ghost {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  width: 52px;
  flex: 0 0 52px;
  padding: 0;
}
.btn-ghost svg { width: 22px; height: 22px; }
.btn-ghost[aria-pressed="true"] { color: var(--rust); }
.btn-ghost[aria-pressed="true"] svg path { fill: currentColor; }
.btn-block { width: 100%; }

/* Cart / checkout */
.page { max-width: 720px; margin: 0 auto; padding: 8px 14px 32px; }
.page h1 { font-size: 1.35rem; margin: 12px 0 16px; }
.cart-item {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
}
.cart-item img {
  width: 88px; height: 88px;
  object-fit: cover;
  border-radius: 8px;
  background: #e8e2d6;
}
.cart-item h3 { margin: 0 0 4px; font-size: 0.92rem; }
.cart-item .price { font-size: 0.95rem; }
.qty {
  display: inline-flex; align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 8px;
}
.qty button {
  width: 32px; height: 30px;
  border: 0; background: var(--bg-2);
}
.qty span { min-width: 28px; text-align: center; font-weight: 650; font-size: 0.9rem; }
.linkish {
  border: 0; background: none;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 4px 0 0;
  text-decoration: underline;
}
.summary {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin: 16px 0;
}
.summary-row, .form-row {
  display: flex; justify-content: space-between; gap: 10px;
  margin: 6px 0;
}
.summary-row.total { font-weight: 750; font-size: 1.1rem; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

form.checkout label { display: block; font-size: 0.8rem; font-weight: 650; margin: 12px 0 4px; }
form.checkout input, form.checkout textarea, form.checkout select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}
.warn-box {
  background: #f8eadf;
  border: 1px solid #e5c4ac;
  color: #5c2e16;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 8px 0 16px;
  font-size: 0.9rem;
}
.ok-box {
  background: #e4f0e9;
  border: 1px solid #b7d4c2;
  color: #1e4633;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 8px 0 16px;
}

/* Footer */
.footer {
  margin-top: 24px;
  background: var(--coal);
  color: #e8e2d4;
  padding: 28px 16px calc(24px + var(--bottom) + env(safe-area-inset-bottom));
}
@media (min-width: 760px) {
  .footer { padding: 36px 16px 40px; }
}
.footer-inner { max-width: var(--max); margin: 0 auto; }
.footer a { color: var(--brass-soft); text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer nav {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  margin: 10px 0 16px;
  font-size: 0.88rem;
}
.footer p { font-size: 0.8rem; color: #cfc6b5; margin: 6px 0; }
.footer .brand { font-weight: 750; color: #f6f1e7; }

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--bottom) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 25;
}
body.is-admin .bottom-nav {
  grid-template-columns: repeat(5, 1fr);
}
.bottom-nav a {
  text-decoration: none;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  font-size: 0.65rem;
  font-weight: 650;
  color: var(--muted);
  position: relative;
}
.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav a.is-on { color: var(--coal); }
.bottom-nav a.sell-nav { color: var(--red); }
.bottom-nav a.sell-nav .sell-plus {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--red); color: #fff;
  display: grid; place-items: center;
  font-size: 1.15rem; font-weight: 700; line-height: 1;
}
.bottom-nav a.sell-nav.is-on .sell-plus { box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--red); }
.bottom-nav .badge { top: 4px; right: calc(50% - 22px); }

.toast {
  position: fixed;
  left: 50%; bottom: calc(var(--bottom) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  background: var(--coal);
  color: #f6f1e7;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.85rem; font-weight: 600;
  opacity: 0; pointer-events: none;
  transition: 0.25s ease;
  z-index: 50;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.legal { max-width: 720px; margin: 0 auto; padding: 16px 16px 48px; }
.legal h1 { font-size: 1.4rem; }
.legal h2 { font-size: 1.05rem; margin-top: 1.4em; }
.legal .placeholder {
  background: #fff;
  border-left: 3px solid var(--red);
  padding: 10px 14px;
  margin: 16px 0;
}

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .bottom-nav { display: none; }
  .sticky-buy { bottom: 0; max-width: 760px; margin: 0 auto; }
  .grid { grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 0 16px 40px; }
  .header-row { padding: 10px 16px; }
  .search-row { padding: 0 16px 12px; }
  .chips, .sort-row { padding-left: 16px; padding-right: 16px; }
  .hero-img { aspect-ratio: 4 / 3; }
  .logo-text strong { font-size: 1.08rem; }
}

@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(5, 1fr); }
}

body.hide-search .search-row { display: none; }
.heart { pointer-events: auto; }

/* Shop profile (Vinted-like) */
.shop-profile { margin: 0 auto 4px; }
.shop-profile .shop-meta { max-width: var(--max); margin-left: auto; margin-right: auto; width: 100%; }
.shop-cover {
  height: 138px;
  overflow: hidden;
  background: var(--night);
}
.shop-cover img {
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 42%;
}
.shop-meta {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 0 14px 12px;
}
.shop-avatar {
  width: 86px; height: 86px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--bg);
  margin-top: -43px;
  flex-shrink: 0;
  background: var(--night);
  box-shadow: 0 2px 10px rgba(16, 33, 54, 0.28);
}
.shop-text { min-width: 0; padding-top: 8px; flex: 1; }
.shop-text h1 { margin: 0; font-size: 1.22rem; letter-spacing: -0.02em; }
.shop-loc {
  margin: 2px 0 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
}
.shop-tag { margin: 4px 0 0; font-size: 0.88rem; color: var(--muted); }
.shop-count { margin: 4px 0 0; font-size: 0.82rem; font-weight: 650; color: var(--ink); }

.sold-flag {
  position: absolute; left: 8px; bottom: 8px;
  background: var(--red); color: #fff;
  font-size: 0.7rem; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 6px;
}
.card.is-sold .thumb img, .hero-img .sold-flag + img { filter: saturate(0.75) brightness(0.92); }
.hero-img { position: relative; }
.thumbs { display: flex; gap: 8px; padding: 10px 16px 0; overflow-x: auto; }
.thumbs .mini { border: 2px solid transparent; padding: 0; background: none; border-radius: 8px; overflow: hidden; width: 56px; height: 56px; flex-shrink: 0; }
.thumbs .mini img { width: 100%; height: 100%; object-fit: cover; }
.thumbs .mini.is-on { border-color: var(--night); }

.owner-actions {
  display: grid;
  gap: 8px;
  margin: 8px 0 16px;
}
.btn-ghost-wide {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  width: 100%;
}
.btn-danger-outline {
  background: #fff;
  border: 1px solid var(--red);
  color: var(--red);
  width: 100%;
}

/* Sell / upload form */
.sell-page h1 { margin-bottom: 12px; }
.login-placeholder {
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: var(--muted);
}
.login-placeholder p { margin: 0 0 10px; }
.sell-form label { display: block; font-size: 0.8rem; font-weight: 650; margin: 12px 0 4px; }
.sell-form input, .sell-form textarea, .sell-form select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}
.sell-form fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px;
  margin: 0 0 8px;
}
.sell-form legend { font-size: 0.8rem; font-weight: 700; padding: 0 6px; }
.sell-form .hint { font-size: 0.78rem; color: var(--muted); margin: 8px 0 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.previews {
  display: flex; gap: 8px; flex-wrap: wrap;
  min-height: 8px;
}
.preview {
  position: relative;
  width: 96px; height: 96px;
  border-radius: 10px; overflow: hidden;
  background: var(--bg-2);
}
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview-actions {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 2px;
  background: linear-gradient(transparent, rgba(16,33,54,0.7));
  padding: 14px 4px 4px;
}
.preview-actions button {
  width: 24px; height: 24px;
  border: 0; border-radius: 6px;
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  font-weight: 700;
  line-height: 1;
}
.preview-actions button.danger { color: var(--red); }
.photo-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.file-btn { cursor: pointer; margin: 0; font-weight: 700; }
.sr-file {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}
.file-btn { position: relative; }

.empty .btn { margin-top: 12px; }

@media (min-width: 760px) {
  .shop-cover { height: 240px; }
  .shop-avatar { width: 112px; height: 112px; margin-top: -56px; border-width: 4px; }
  .shop-text h1 { font-size: 1.6rem; }
  .shop-meta { padding: 0 16px 18px; }
  .preview { width: 120px; height: 120px; }
}

/* Admin login */
.login-wrap { max-width: 420px; margin: 0 auto; padding: 24px 16px 48px; }
.login-wrap h1 { font-size: 1.4rem; margin: 12px 0 8px; }
.login-wrap .warn-box { margin: 12px 0 20px; }
.login-wrap label { display: block; font-size: 0.8rem; font-weight: 650; margin: 12px 0 4px; }
.login-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fff;
}
.login-wrap .back { padding-left: 0; }

.login-status { margin-top: 16px; }
