/* ---------- Theme ---------- */
:root {
  --bg: #f6f1ea; --card: #fffdfa; --card-2: #f1ebe2; --text: #2a2420; --muted: #857a70;
  --accent: #d9692b; --accent-ink: #fff; --accent-soft: #fbe6d8; --danger: #c4332b;
  --border: #e6ddd1; --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 16px; --tabbar: 64px;
  --safe-b: env(safe-area-inset-bottom); --safe-t: env(safe-area-inset-top);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171412; --card: #221e1b; --card-2: #2c2723; --text: #f1ebe4; --muted: #a39789;
    --accent: #ef8547; --accent-soft: #3a271b; --border: #3a332d; --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-padding-top: 70px; }
body {
  margin: 0; font: 16px/1.45 ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- App bar ---------- */
#appbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px;
  min-height: 56px; padding: calc(6px + var(--safe-t)) 10px 6px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
#appbar .title { flex: 1; font-size: 1.25rem; font-weight: 800; letter-spacing: -.01em; padding-left: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center; font-size: 1.25rem; flex: none; text-decoration: none;
}
.icon-btn:hover { background: var(--card-2); }

main { max-width: 760px; margin: 0 auto; padding: 4px 14px calc(var(--tabbar) + 28px + var(--safe-b)); }

/* ---------- Tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--border); padding-bottom: var(--safe-b);
}
#tabbar .inner { display: flex; width: 100%; max-width: 560px; height: var(--tabbar); align-items: center; }
#tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none;
  font-size: .72rem; font-weight: 600; color: var(--muted); padding: 6px 0;
}
#tabbar a .ic { font-size: 1.35rem; line-height: 1; filter: grayscale(1); opacity: .75; }
#tabbar a.active { color: var(--accent); }
#tabbar a.active .ic { filter: none; opacity: 1; }
#tabbar a.add .ic {
  width: 52px; height: 52px; margin-top: -26px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 1.9rem; font-weight: 400; filter: none; opacity: 1;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 45%, transparent); border: 4px solid var(--card);
}

/* ---------- Building blocks ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 18px 4px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--card); text-decoration: none;
  font-weight: 600; cursor: pointer; white-space: nowrap; max-width: 100%;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }

input, textarea, select {
  width: 100%; min-height: 46px; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-weight: 700; font-size: .92rem; margin: 0 2px 6px; }
.field .hint { font-size: .8rem; color: var(--muted); margin: 6px 2px 0; }

/* Chips */
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 6px; margin: 0 -2px; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none; height: 34px; padding: 0 12px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--card); font-size: .87rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; text-decoration: none;
}
.chip .n { color: var(--muted); font-weight: 500; }
.chip.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip.on .n { color: inherit; opacity: .7; }
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .78rem;
  font-weight: 700; background: var(--card-2); white-space: nowrap; }
.tag.fragile { background: #fde2e1; color: #b42318; }
@media (prefers-color-scheme: dark) { .tag.fragile { background: #4a1f1d; color: #ffb4ab; } }

/* Loading */
.loading { display: grid; place-items: center; padding: 80px 0; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Place picker / inline add */
.chip.add { border-style: dashed; color: var(--accent); background: transparent; }
.chips-lead { align-self: center; color: var(--muted); padding: 0 2px 0 6px; flex: none; }
.sub-label { font-weight: 700; font-size: .88rem; margin: 14px 2px 6px; }
.add-row { display: flex; gap: 8px; margin-top: 8px; }
.add-row input { flex: 1; min-width: 0; }
.add-row .btn { flex: none; }
.where { font-size: 1.05rem; }
.place-card .pc-head { display: flex; align-items: center; gap: 2px; }
.place-card .pc-name { font-weight: 800; font-size: 1.1rem; }
.place-card a { color: var(--accent); text-decoration: none; font-weight: 600; }
.spots { margin: 10px 0 2px; }
.spot-row { display: flex; align-items: center; gap: 2px; padding: 2px 0 2px 28px; border-top: 1px solid var(--border); }

/* Toggle switch */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 4px 2px; font-weight: 600; }
.switch input { appearance: none; width: 50px; min-height: 0; height: 30px; padding: 0; border-radius: 99px; background: var(--border);
  position: relative; flex: none; border: 0; cursor: pointer; transition: background .2s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

/* ---------- List ---------- */
.searchbar { position: relative; margin: 4px 0 10px; }
.searchbar input { padding-left: 44px; padding-right: 44px; height: 52px; font-size: 1.05rem; border-radius: 14px; box-shadow: var(--shadow); }
.searchbar input::-webkit-search-cancel-button { display: none; }
.searchbar .ic { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); font-size: 1.1rem; opacity: .6; pointer-events: none; }
.searchbar .clear { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); }
.list-head { display: flex; align-items: center; gap: 8px; margin: 8px 4px; }
.list-head select { width: auto; min-height: 36px; padding: 4px 12px; font-size: 16px; border-radius: 99px; } /* 16px: no iOS zoom */
.group-title { display: flex; align-items: center; gap: 8px; font-weight: 800; margin: 20px 4px 8px; }
.group-title .n { color: var(--muted); font-weight: 500; font-size: .9rem; }

.box-item { display: flex; gap: 14px; align-items: center; text-decoration: none; padding: 12px; margin-bottom: 10px;
  transition: transform .1s; }
.box-item:active { transform: scale(.99); }
.thumb { width: 72px; height: 72px; border-radius: 12px; background: var(--card-2); object-fit: cover; flex: none;
  display: grid; place-items: center; font-size: 2rem; overflow: hidden; }
.box-item .info { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.box-item .top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.box-item .id { font-weight: 800; letter-spacing: .01em; }
.box-item .desc { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box-item .meta { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box-item .match { font-size: .82rem; color: var(--muted); }
.box-item .chev { color: var(--muted); font-size: 1.3rem; }
mark { background: #ffe08a; color: #2a2420; border-radius: 3px; padding: 0 2px; }

.empty { text-align: center; padding: 48px 20px; }
.empty .big { font-size: 4rem; line-height: 1; margin-bottom: 12px; }
.empty h2 { margin: 0 0 6px; font-size: 1.3rem; }
.empty p { margin: 0 auto 20px; max-width: 320px; color: var(--muted); }

/* ---------- Detail ---------- */
.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  margin: 0 -14px 14px; padding: 0 14px; }
.gallery::-webkit-scrollbar { display: none; }
.gallery img { height: 260px; max-width: 85%; flex: none; scroll-snap-align: center; border-radius: var(--radius);
  object-fit: cover; background: var(--card-2); cursor: zoom-in; aspect-ratio: 3/4; }
.gallery img:only-child { max-width: 100%; width: 100%; aspect-ratio: auto; }
.hero-empty { height: 140px; border-radius: var(--radius); background: var(--card-2); display: grid; place-items: center;
  margin-bottom: 14px; border: 2px dashed var(--border); cursor: pointer; color: var(--muted); font-weight: 600; text-align: center; }
.hero-empty .big { font-size: 2.4rem; }
.detail-head .id { font-size: 2rem; font-weight: 900; letter-spacing: -.01em; line-height: 1.1; }
.detail-head .desc { font-size: 1.15rem; margin: 4px 0 10px; }
.info-row { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border); }
.info-row:first-child { border-top: 0; padding-top: 0; }
.info-row .ic { font-size: 1.2rem; width: 26px; text-align: center; flex: none; }
.info-row .k { font-size: .76rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.info-row a { text-decoration: none; font-weight: 600; color: var(--accent); }
.contents-list { margin: 4px 0 0; padding-left: 20px; }
.contents-list li { padding: 2px 0; }
.pre { white-space: pre-wrap; }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.actions .btn { flex-direction: column; height: 70px; gap: 2px; font-size: .78rem; padding: 0 4px; }
.actions .btn .ic { font-size: 1.35rem; }

/* ---------- Form ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 10px; }
.photo-grid:empty { display: none; }
.photo-grid .ph { position: relative; aspect-ratio: 1; }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; background: var(--card-2); }
.photo-grid .del { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 14px; display: grid; place-items: center; }
.photo-grid .new::after { content: 'new'; position: absolute; left: 6px; bottom: 6px; font-size: .68rem; font-weight: 700;
  background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 99px; }
.sticky-save { position: sticky; bottom: calc(var(--tabbar) + var(--safe-b) + 10px); z-index: 5; display: flex; gap: 8px;
  padding: 10px; margin: 0 -4px; border-radius: 18px; background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--border); box-shadow: var(--shadow); }
.sticky-save .btn { flex: 1; }

/* ---------- Sheet & lightbox & toast ---------- */
.backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(20, 14, 8, .45); display: flex; align-items: flex-end;
  justify-content: center; animation: fade .15s; }
.sheet-panel { width: 100%; max-width: 560px; background: var(--card); border-radius: 22px 22px 0 0; padding: 10px 18px calc(18px + var(--safe-b));
  animation: up .22s cubic-bezier(.2,.8,.2,1); max-height: 85vh; overflow: auto; }
.sheet-panel .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--border); margin: 0 auto 12px; }
.sheet-panel h3 { margin: 0 0 14px; font-size: 1.2rem; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.94); display: flex; align-items: center; justify-content: center;
  touch-action: pan-y; }
#lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; user-select: none; }
#lightbox .nav, #lightbox .close { position: absolute; color: #fff; background: rgba(255,255,255,.12); }
#lightbox .nav { top: 50%; transform: translateY(-50%); }
#lightbox .prev { left: 10px; } #lightbox .next { right: 10px; }
#lightbox .close { top: calc(10px + var(--safe-t)); right: 10px; }
#lightbox .count { position: absolute; bottom: calc(16px + var(--safe-b)); color: #fff; opacity: .8; font-size: .9rem; }

#toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 18px + var(--safe-b)); transform: translateX(-50%); z-index: 80;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600; box-shadow: var(--shadow);
  animation: up .2s; max-width: 90vw; }
#offline { background: #6b5b4b; color: #fff; text-align: center; font-size: .85rem; padding: 6px; font-weight: 600; }

/* ---------- Login ---------- */
.login { max-width: 380px; margin: 9vh auto 0; text-align: center; }
.login .big { font-size: 4.5rem; }
.login h1 { margin: 6px 0 4px; }
.login p { color: var(--muted); margin: 0 0 22px; }
.login input { text-align: center; margin-bottom: 12px; height: 52px; font-size: 1.1rem; }
body.locked #tabbar, body.locked #appbar { display: none; }

/* ---------- Scan ---------- */
.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 3/4; max-height: 62vh; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.9); border-radius: 22px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
.scanner .msg { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; color: #fff; font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,.7); padding: 0 12px; }

/* ---------- Labels (screen) ---------- */
.sel-item { display: flex; gap: 12px; align-items: center; padding: 10px 2px; border-top: 1px solid var(--border); cursor: pointer; }
.sel-item:first-child { border-top: 0; }
.sel-item input { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex: none; }
.sel-item .t { flex: 1; min-width: 0; }
.sel-item .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.print-bar { position: sticky; bottom: calc(var(--tabbar) + var(--safe-b) + 10px); z-index: 5; }
.preview-wrap { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
.preview-wrap .sheet { zoom: .42; box-shadow: 0 4px 24px rgba(0,0,0,.18); }
@media (max-width: 520px) { .preview-wrap .sheet { zoom: .4; } }
details.card summary { cursor: pointer; font-weight: 700; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: '›'; float: right; transition: transform .2s; color: var(--muted); }
details.card[open] summary::after { transform: rotate(90deg); }

/* ---------- Labels (the printed thing): 4 per A4 ---------- */
.sheet { width: 210mm; height: 297mm; display: grid; grid-template-columns: 105mm 105mm; grid-template-rows: 148.5mm 148.5mm;
  background: #fff; color: #000; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.plabel { border: .3mm dashed #c8c8c8; padding: 7mm 8mm; display: flex; flex-direction: column; align-items: center;
  text-align: center; overflow: hidden; position: relative; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.plabel.blank { border-color: #eee; }
.plabel .qr { width: 72mm; height: 72mm; margin-top: 4mm; }
.plabel .qr svg { width: 100%; height: 100%; display: block; }
.plabel .lid { font-size: 34pt; font-weight: 900; margin-top: 4mm; letter-spacing: .5pt; line-height: 1; word-break: break-all; }
.plabel .ldesc { font-size: 15pt; margin-top: 3mm; line-height: 1.2; max-height: 3.6em; overflow: hidden; font-weight: 500; }
.plabel .foot { margin-top: auto; display: flex; justify-content: center; align-items: center; align-self: stretch;
  font-size: 10pt; color: #444; gap: 3mm; }
.plabel .frag { border: .6mm solid #000; padding: .8mm 2.5mm; font-weight: 900; font-size: 11pt; letter-spacing: 1pt; color: #000; }

@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff !important; }
  body > *:not(main), main > *:not(#print-area) { display: none !important; }
  main { padding: 0 !important; max-width: none; margin: 0; }
  .preview-wrap { display: block; gap: 0; }
  .preview-wrap .sheet { zoom: 1; box-shadow: none; break-after: page; page-break-after: always; }
  .preview-wrap .sheet:last-child { break-after: auto; page-break-after: auto; }
}
