:root {
  --bg: #f6f7f9; --card: #ffffff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #1d4ed8; --accent-text: #ffffff; --chip: #eef0f4; --chip-on: #1d4ed8; --danger: #b91c1c;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --card: #1a1d24; --text: #e5e7eb; --muted: #9aa0ad; --line: #2a2f3a;
          --accent: #3b82f6; --chip: #242833; --chip-on: #3b82f6; --danger: #f87171; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 17px; margin: 20px 0 8px; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.top h1 { font-size: 20px; margin: 0; }
.page { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); max-width: 960px; margin: 0 auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.wide { width: 100%; margin: 12px 0; }
.btn:disabled { opacity: .5; }

.search { display: flex; gap: 8px; margin-bottom: 6px; }
.search input { flex: 1; min-height: 42px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: inherit; font: inherit; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; align-items: center; }
.chips::-webkit-scrollbar { display: none; }
.chips .lbl { color: var(--muted); font-size: 13px; padding-right: 4px; white-space: nowrap; }
.chip { flex: 0 0 auto; padding: 6px 12px; border-radius: 999px; background: var(--chip); font-size: 14px; white-space: nowrap; }
.chip.on { background: var(--chip-on); color: #fff; }
.chip .n { opacity: .7; font-size: 12px; margin-left: 4px; }

.count { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 14px; margin: 6px 0 10px; }
.count select { font: inherit; font-size: 14px; background: var(--card); color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card img, .card .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--chip); display: block; }
.cbody { padding: 8px 10px 10px; }
.cname { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cmeta, .cpos { color: var(--muted); font-size: 12px; margin-top: 3px; }
@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr; }
  .card { flex-direction: row; align-items: stretch; }
  .card img, .card .noimg { width: 92px; height: 92px; aspect-ratio: auto; flex: 0 0 92px; }
  .cbody { flex: 1; min-width: 0; align-self: center; }
}

.gallery { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.gallery figure { position: relative; margin: 0; flex: 0 0 auto; }
.gallery img { height: 240px; width: auto; max-width: 80vw; border-radius: 10px; display: block; background: var(--chip); }
.gallery .x { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; font-size: 18px; line-height: 30px; cursor: pointer; }
.gallery .star { position: absolute; bottom: 6px; left: 6px; border: 0; border-radius: 8px; padding: 3px 8px; font-size: 12px;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.addphoto { flex: 0 0 auto; width: 120px; height: 240px; border: 2px dashed var(--line); border-radius: 10px; display: flex;
  align-items: center; justify-content: center; color: var(--muted); cursor: pointer; }
.addphoto input { display: none; }

.qty { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
.qty .btn { width: 52px; font-size: 24px; }
#qval { font-size: 26px; font-weight: 700; min-width: 44px; text-align: center; }
.qlbl { color: var(--muted); }

.fields { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 12px 0; }
.fields dt { color: var(--muted); font-size: 14px; }
.fields dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.danger { margin-top: 28px; }
.danger .btn { color: var(--danger); }

.form .f { display: block; margin-bottom: 12px; }
.form .f span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.form input, .form select, .form textarea, .locrow input { width: 100%; min-height: 42px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: inherit; font: inherit; }
.form textarea { resize: vertical; }
.form .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.form .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
.hint { color: var(--muted); font-size: 14px; }

.locrow { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.locrow .n { color: var(--muted); font-size: 13px; margin-left: 6px; }
.locrow input { background: var(--bg); }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.foot { text-align: center; color: var(--muted); font-size: 14px; margin: 24px 0; }
.foot a { text-decoration: underline; margin: 0 8px; }
.error { color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* ---- auth / account ---- */
.auth { max-width: 380px; margin: 10vh auto 0; padding: 12px; }
.auth h1 { font-size: 26px; margin: 0 0 4px; }
.auth .sub { color: var(--muted); margin: 0 0 18px; }
.auth .form .btn { width: 100%; margin-top: 4px; }
.auth .links { text-align: center; margin-top: 14px; font-size: 14px; color: var(--muted); }
.avatar { width: 40px; padding: 0; border-radius: 50%; font-weight: 700; text-transform: uppercase; }
.hdr-right { display: flex; gap: 8px; align-items: center; }
.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.section h2 { margin: 0 0 8px; }
.notice { background: #fff7ed; border: 1px solid #fdba74; color: #9a3412; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
@media (prefers-color-scheme: dark) { .notice { background: #3b2416; border-color: #9a3412; color: #fdba74; } }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); margin-left: 6px; }
.badge.on { background: #dcfce7; color: #166534; }
@media (prefers-color-scheme: dark) { .badge.on { background: #14532d; color: #bbf7d0; } }
.qr { display: block; width: 200px; height: 200px; margin: 10px auto; border-radius: 8px; background: #fff; image-rendering: pixelated; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 14px; word-break: break-all; text-align: center; color: var(--muted); }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: ui-monospace, Consolas, monospace; font-size: 15px; margin: 10px 0; }
.codes span { background: var(--chip); padding: 6px 10px; border-radius: 8px; text-align: center; }
.userrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.userrow:last-child { border-bottom: 0; }
.userrow .who { flex: 1; min-width: 160px; }
.userrow .who small { display: block; color: var(--muted); }
.userrow .btn { min-height: 34px; padding: 0 10px; font-size: 14px; }
.form .check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.form .check input { width: auto; min-height: 0; }
