:root {
  --bg: #f6f1e7;
  --panel: #fffdf8;
  --ink: #1d1a15;
  --muted: #7b7264;
  --line: #e4dccd;
  --gold: #a8823f;
  --gold-soft: #f0e5cf;
  --green: #2f6b4f;
  --red: #9c3b2e;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(29, 26, 21, 0.05), 0 10px 30px rgba(29, 26, 21, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

.shell { max-width: 1080px; margin: 0 auto; padding: 18px 16px 64px; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--ink);
  color: #f8f3e8; display: grid; place-items: center;
  font-family: ui-serif, Georgia, "Times New Roman", serif; font-size: 19px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-family: ui-serif, Georgia, serif; letter-spacing: 0.16em; font-size: 13px; }
.brand-text span { font-size: 10px; letter-spacing: 0.22em; color: var(--muted); text-transform: uppercase; }

.top-actions { display: flex; align-items: center; gap: 8px; }
.ghost-link {
  border: 1px solid var(--line); background: rgba(255,255,255,0.6);
  padding: 7px 12px; border-radius: 999px; font-size: 12px; color: var(--muted);
  cursor: pointer;
}
.ghost-link:hover { border-color: var(--gold); color: var(--ink); }

/* hero */
.hero { margin: 4px 0 18px; }
.hero h1 {
  margin: 0 0 6px; font-family: ui-serif, Georgia, serif; font-weight: 500;
  font-size: clamp(28px, 7vw, 44px); letter-spacing: -0.02em;
}
.hero p { margin: 0; color: var(--muted); font-size: 13px; }
.hero .rule { width: 44px; height: 2px; background: var(--gold); margin: 14px 0 0; }

/* search */
.searchbar { position: relative; margin: 0 0 16px; }
.searchbar input {
  width: 100%; border: 1px solid var(--line); background: var(--panel);
  border-radius: 999px; padding: 13px 18px 13px 44px; outline: none;
  box-shadow: var(--shadow);
}
.searchbar input:focus { border-color: var(--gold); }
.searchbar svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); opacity: 0.45; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 6px 12px; font-size: 12px; color: var(--muted); cursor: pointer;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #f8f3e8; }

.result-line { font-size: 12px; color: var(--muted); margin: 0 0 12px; }

/* grid */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 680px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.card {
  display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); transition: transform 160ms ease, box-shadow 160ms ease;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 16px 40px rgba(29,26,21,0.09); }
.card-photo { position: relative; aspect-ratio: 1 / 1; background: #fff; overflow: hidden; }
.card-photo img { width: 100%; height: 100%; object-fit: contain; padding: 8%; }
.card-photo .no-photo {
  width: 100%; height: 100%; display: grid; place-items: center;
  color: #c9bda7; font-family: ui-serif, Georgia, serif; font-size: 32px;
}
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.card-id { font-size: 10px; letter-spacing: 0.12em; color: var(--gold); font-weight: 700; }
.card-code { font-family: ui-serif, Georgia, serif; font-size: 17px; letter-spacing: 0.01em; }
.card-meta { font-size: 11px; color: var(--muted); }
.card-price { margin-top: auto; padding-top: 8px; }
.card-price strong { display: block; font-size: 13px; line-height: 1.3; }
.card-price span { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; }
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px;
  border-radius: 999px; font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
  background: #eef5ee; color: var(--green); font-weight: 600;
}
.badge.cert { background: var(--gold-soft); color: #6f5627; }

/* detail */
.detail { animation: fade 220ms ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.back {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none;
  padding: 0; margin: 0 0 14px; color: var(--muted); cursor: pointer; font-size: 13px;
}
.detail-grid { display: grid; gap: 18px; }
@media (min-width: 860px) { .detail-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }

.photo-frame {
  background: #fff; border: 1px solid var(--line); border-radius: 22px;
  padding: 18px; box-shadow: var(--shadow);
}
.photo-frame img { width: 100%; aspect-ratio: 1 / 1; object-fit: contain; }

.detail-eyebrow { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.detail-title { margin: 6px 0 2px; font-family: ui-serif, Georgia, serif; font-weight: 500; font-size: clamp(30px, 8vw, 44px); letter-spacing: -0.02em; }
.detail-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

.price-panel {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 16px; overflow: hidden; margin: 0 0 16px;
}
.price-cell { background: var(--panel); padding: 13px 14px; }
.price-cell span { display: block; font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-bottom: 5px; }
.price-cell strong { font-size: 21px; font-family: ui-serif, Georgia, serif; font-weight: 500; }
.price-cell small { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; }
.price-cell.sell strong { color: var(--gold); }

.section {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow);
}
.section h2 { margin: 0 0 12px; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.spec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.spec span { display: block; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.spec strong { font-size: 14px; font-weight: 600; }

.cert-card { display: flex; align-items: center; gap: 12px; }
.cert-icon {
  width: 44px; height: 44px; border-radius: 12px; background: var(--gold-soft);
  display: grid; place-items: center; color: #6f5627; flex: none;
}
.cert-card .cert-no { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; font-weight: 600; }
.cert-card .cert-lab { font-size: 11px; color: var(--muted); }
.cert-open {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  background: var(--ink); color: #f8f3e8; border-radius: 999px;
  padding: 9px 14px; font-size: 12px; white-space: nowrap;
}
.cert-open:hover { background: #3a342a; }

.qr-row { display: flex; align-items: center; gap: 14px; }
.qr-box { width: 86px; height: 86px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 5px; flex: none; }
.qr-box canvas, .qr-box img { width: 100% !important; height: 100% !important; }
.qr-text { font-size: 11px; color: var(--muted); word-break: break-all; }
.qr-text strong { display: block; color: var(--ink); font-size: 12px; margin-bottom: 2px; }

.note { font-size: 11px; color: var(--muted); }

/* buttons + forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--ink); background: var(--ink); color: #f8f3e8;
  border-radius: 999px; padding: 10px 16px; font-size: 13px; cursor: pointer;
}
.btn:hover { background: #3a342a; }
.btn.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--gold); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.field label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 9px 11px; outline: none; width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--gold); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.photo-edit { display: flex; gap: 14px; align-items: flex-start; }
.photo-edit-frame {
  width: 104px; height: 104px; flex: none; border: 1px solid var(--line);
  border-radius: 12px; background: #fff; display: grid; place-items: center; overflow: hidden;
}
.photo-edit-frame img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.photo-edit-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; }
.photo-edit-actions .btn { cursor: pointer; }
.photo-edit-actions .note { margin: 0; }

.login-box { max-width: 380px; margin: 40px auto; }
.login-box h1 { font-family: ui-serif, Georgia, serif; font-weight: 500; font-size: 30px; margin: 0 0 4px; }
.login-box p { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.admin-list { display: flex; flex-direction: column; gap: 8px; }
.admin-row {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 12px;
  align-items: center; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 8px 12px 8px 8px;
}
.admin-row img { width: 48px; height: 48px; object-fit: contain; background: #fff; border-radius: 8px; }
.admin-row .meta { font-size: 11px; color: var(--muted); }

.tag-toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.check-row { display: flex; align-items: center; gap: 9px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--ink); }
.check-row .grow { flex: 1; min-width: 0; }
.check-row strong { font-size: 13px; }
.check-row small { display: block; font-size: 11px; color: var(--muted); }

/* 100 x 15 mm tags */
.tag-sheet { display: flex; flex-direction: column; align-items: center; gap: 6mm; padding: 6mm 0; }
.tag {
  width: 100mm; height: 15mm; background: #fff; color: #000;
  border: 0.2mm solid #ddd; border-radius: 0.8mm;
  display: flex; align-items: center; gap: 2mm; padding: 1.4mm 2mm;
  overflow: hidden;
}
.tag .tag-qr { width: 11.6mm; height: 11.6mm; flex: none; }
.tag .tag-qr canvas, .tag .tag-qr img { width: 100% !important; height: 100% !important; }
.tag .tag-lines { min-width: 0; flex: 1; line-height: 1.22; }
.tag .l1 { font-size: 6.6pt; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag .l2 { font-size: 5.6pt; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag .l3 { font-size: 6.4pt; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag .l3 .sep { font-weight: 400; color: #777; padding: 0 1mm; }

.print-toolbar { display: flex; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 8mm; }
@media print {
  @page { size: 100mm 15mm; margin: 0; }
  body { background: #fff; }
  .print-toolbar { display: none !important; }
  .tag-sheet { padding: 0; gap: 0; display: block; }
  .tag { border: 0; border-radius: 0; page-break-after: always; break-after: page; }
  .tag:last-child { page-break-after: auto; break-after: auto; }
}

/* misc */
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { font-family: ui-serif, Georgia, serif; font-weight: 500; color: var(--ink); font-size: 24px; margin: 0 0 6px; }
.spinner { width: 22px; height: 22px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin 700ms linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: #f8f3e8; padding: 10px 16px; border-radius: 999px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 50;
}
.footer { margin-top: 40px; text-align: center; font-size: 11px; color: var(--muted); }
.footer a { color: var(--gold); }
