:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --danger: #b91c1c;
  --ok-bg: #dcfce7;
  --ok-text: #166534;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111a2e;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #1f2a44;
    --primary: #3b82f6;
    --primary-dark: #93c5fd;
    --danger: #f87171;
    --ok-bg: #052e16;
    --ok-text: #86efac;
    --error-bg: #450a0a;
    --error-text: #fca5a5;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 0.75rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.4rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.brand-mark { background: var(--primary); color: #fff; border-radius: 8px; padding: 0.1rem 0.4rem; font-size: 0.85rem; }
.nav { display: flex; align-items: center; gap: 0.5rem; }

.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; font-size: 1.4rem; padding: 0.2rem 0.5rem; user-select: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel {
  position: absolute;
  right: 0;
  top: 2.6rem;
  min-width: 13rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.15);
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
}
.menu-panel a, .menu-panel .link { padding: 0.7rem 0.8rem; border-radius: 10px; color: var(--text); text-decoration: none; text-align: left; font: inherit; }
.menu-panel a:hover, .menu-panel .link:hover { background: var(--bg); }
.menu-panel form { margin: 0; display: flex; }
.menu-panel .link { flex: 1; }

.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 2rem 1rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; }
.narrow { max-width: 440px; margin: 1.5rem auto; }
.stack { display: flex; flex-direction: column; gap: 0.9rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

label { display: flex; flex-direction: column; gap: 0.3rem; font-weight: 600; font-size: 0.9rem; }
input, select, textarea {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
  font-weight: 400;
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type="checkbox"] { width: auto; }
input[type="file"] { padding: 0.5rem; }
.code-input { font-family: ui-monospace, Menlo, monospace; letter-spacing: 0.15em; text-transform: uppercase; font-size: 1.25rem; text-align: center; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 0.8rem; }
legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.3rem; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.75rem 1.1rem;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  min-height: 44px;
}
.button:hover { filter: brightness(1.08); }
.button-small { padding: 0.4rem 0.8rem; min-height: 36px; font-size: 0.9rem; }
.button-secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.button-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.link { background: none; border: 0; cursor: pointer; }

.alert { padding: 0.75rem 1rem; border-radius: 10px; margin: 0 0 1rem; }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

.filters { display: grid; grid-template-columns: 1fr; gap: 0.5rem; margin-bottom: 1rem; }
@media (min-width: 640px) { .filters { grid-template-columns: 1fr 220px auto; } }

.item-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
@media (min-width: 640px) { .item-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .item-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.item-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); text-decoration: none; display: flex; flex-direction: column; }
.item-card.is-sold { opacity: 0.55; }
.item-thumb { position: relative; aspect-ratio: 1; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-thumb .badge { position: absolute; top: 0.5rem; left: 0.5rem; }
.no-image { color: var(--muted); font-size: 0.85rem; }
.item-info { padding: 0.6rem 0.7rem 0.8rem; display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; }
.item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-price { font-size: 1.05rem; }

.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 700; color: #fff; }
.badge-reserved { background: #d97706; }
.badge-sold { background: #4b5563; }

.detail { max-width: 640px; margin: 0 auto; }
.gallery { display: flex; gap: 0.5rem; overflow-x: auto; scroll-snap-type: x mandatory; margin-bottom: 1rem; border-radius: var(--radius); }
.gallery a { flex: 0 0 100%; scroll-snap-align: start; }
.gallery img { width: 100%; max-height: 70vh; object-fit: contain; background: var(--surface); border-radius: var(--radius); display: block; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; }
.detail-price { font-size: 1.5rem; font-weight: 700; margin: 0 0 0.75rem; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 1rem; margin: 0 0 0.75rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.description { white-space: pre-wrap; margin: 0; }
.status-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.thumb-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.thumb-remove { flex-direction: column; align-items: center; font-weight: 400; font-size: 0.8rem; }
.thumb-remove img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.7rem 0; border-top: 1px solid var(--border); }
.list li > div { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.list form { margin: 0; flex-shrink: 0; }
