:root {
  --accent: #f97316;
  --accent-d: #ea580c;
  --accent-soft: #fff0e2;
  --grad: linear-gradient(135deg, #fb923c, #f97316);
  --bg: #faf6f1;
  --card: #ffffff;
  --text: #3a322c;
  --muted: #9a8f85;
  --border: #ece4da;
  --danger: #e0533d;
  --shadow: 0 2px 10px rgba(80, 55, 30, .07), 0 1px 3px rgba(80, 55, 30, .05);
  --shadow-lg: 0 8px 24px rgba(80, 55, 30, .16);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  line-height: 1.5;
}

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }

/* ---- ヘッダー ---- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  background: var(--grad); color: #fff;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  box-shadow: 0 3px 12px rgba(249, 115, 22, .28);
}
.topbar h1 { font-size: 18px; font-weight: 800; letter-spacing: .02em; }
.brand { display: flex; align-items: center; gap: 9px; }
.brand-icon svg { width: 24px; height: 24px; display: block; }
.iconbtn {
  width: 36px; height: 36px; flex: none; border: none; cursor: pointer;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .2); color: #fff; text-decoration: none;
}
.iconbtn:active { background: rgba(255, 255, 255, .35); }
.iconbtn svg { width: 20px; height: 20px; }

.pad { padding: 18px 16px 48px; animation: fadeIn .22s ease; }
.has-tabbar .pad { padding-bottom: 96px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- ボタン ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 16px; border-radius: 14px;
  background: #fff; color: var(--text);
  border: 1px solid var(--border); font-size: 15px; font-weight: 700;
  text-decoration: none; cursor: pointer; transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); color: #fff; border: none; box-shadow: 0 4px 14px rgba(249, 115, 22, .32); }
.btn.danger { background: #fff; color: var(--danger); border-color: #f3cdc6; }
.btn.small { padding: 9px 14px; font-size: 14px; border-radius: 11px; }
.btn.full { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: .55; }
.filelabel { display: inline-flex; }

/* ---- 検索 ---- */
.search-wrap { position: relative; margin-bottom: 16px; }
.search-wrap > svg {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 19px; height: 19px; color: var(--muted); pointer-events: none;
}
.search {
  width: 100%; padding: 13px 14px 13px 41px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 14px; background: #fff;
  box-shadow: var(--shadow); color: var(--text);
}
.search:focus { outline: none; border-color: var(--accent); }

/* ---- 一覧カード ---- */
.list { display: flex; flex-direction: column; gap: 11px; }
.card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid #f3ece3;
  border-radius: 18px; padding: 11px;
  box-shadow: var(--shadow); text-decoration: none; color: var(--text);
  transition: transform .08s ease;
}
.card:active { transform: scale(.985); }
.card-thumb {
  width: 60px; height: 60px; flex: none;
  border-radius: 14px; overflow: hidden; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.card-thumb.placeholder svg { width: 30px; height: 30px; color: var(--accent); }
.card-main { flex: 1; min-width: 0; }
.card-title { font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.card-hit { font-size: 12.5px; color: var(--accent-d); margin-top: 4px; font-weight: 700; }
.chev { flex: none; color: #d8cec2; display: flex; }
.chev svg { width: 18px; height: 18px; }

/* ---- 空の状態 ---- */
.empty { text-align: center; padding: 56px 24px; }
.empty-icon { font-size: 56px; line-height: 1; }
.empty-title { font-size: 17px; font-weight: 800; margin-top: 14px; }
.empty-sub { color: var(--muted); margin-top: 7px; font-size: 14px; }

/* ---- フォーム ---- */
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 7px; }
.field input, .field textarea {
  width: 100%; padding: 12px 13px; font-size: 16px; color: var(--text);
  border: 1px solid var(--border); border-radius: 13px; background: #fff;
  font-family: inherit;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.field textarea { min-height: 76px; resize: vertical; }

/* ---- セクション ---- */
section {
  margin-top: 16px; background: var(--card);
  border: 1px solid #f3ece3; border-radius: 18px; padding: 16px;
  box-shadow: var(--shadow);
}
section h3 { font-size: 14px; font-weight: 800; margin-bottom: 12px; color: var(--text); }
.boxname { font-size: 21px; font-weight: 800; margin-bottom: 4px; }
.note { color: var(--muted); margin-bottom: 4px; white-space: pre-wrap; }

/* ---- アイテム行 ---- */
#items { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.item-row { display: flex; gap: 8px; }
.item-row .it-name { flex: 1; }
.item-row .it-qty { width: 62px; text-align: center; }
.item-row input {
  padding: 11px; font-size: 15px; border: 1px solid var(--border);
  border-radius: 11px; background: #fff; color: var(--text);
}
.item-row input:focus { outline: none; border-color: var(--accent); }
.it-del {
  width: 40px; flex: none; border: 1px solid var(--border); border-radius: 11px;
  background: #fff; color: var(--danger); font-size: 20px; cursor: pointer;
}
.item-view { padding: 9px 2px; border-bottom: 1px solid #f3ece3; font-size: 15px; }
.item-view:last-child { border-bottom: none; }

/* ---- 写真 ---- */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.photo { position: relative; aspect-ratio: 1; }
.photo img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 13px; border: 1px solid var(--border);
}
.photo-del {
  position: absolute; top: 5px; right: 5px;
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: rgba(0, 0, 0, .58); color: #fff; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ---- QR ---- */
.qr-section { text-align: center; }
.qr-frame {
  display: inline-block; padding: 14px; background: #fff;
  border: 2px solid var(--accent-soft); border-radius: 18px;
}
.qr { width: 200px; max-width: 70vw; display: block; }
.qr-section .actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }

/* ---- スキャナ ---- */
.reader {
  width: 100%; border-radius: 18px; overflow: hidden;
  background: #000; min-height: 260px; box-shadow: var(--shadow);
}

/* ---- メッセージ ---- */
.msg { font-size: 14px; margin-top: 10px; min-height: 18px; }
.msg.err, .error { color: var(--danger); }
.error { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.hint.warn { color: var(--accent-d); font-weight: 700; }
code { background: #f0e9e0; padding: 1px 6px; border-radius: 5px; font-size: 13px; }

/* ---- ローダー ---- */
.loader { display: flex; justify-content: center; padding: 52px 0; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- トースト ---- */
.toast {
  position: fixed; left: 50%; bottom: 96px;
  transform: translate(-50%, 16px);
  background: #3a322c; color: #fff;
  padding: 11px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 700; box-shadow: var(--shadow-lg);
  opacity: 0; transition: opacity .26s ease, transform .26s ease;
  z-index: 100; max-width: 86%; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

/* ---- FAB ---- */
.fab {
  position: fixed; right: 18px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--grad); color: #fff; border: none;
  box-shadow: 0 8px 20px rgba(249, 115, 22, .45);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; z-index: 50; transition: transform .1s ease;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.92); }

/* ---- 下部タブバー ---- */
.tabbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 560px; display: flex;
  background: #fff; border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); z-index: 40;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 0 9px; text-decoration: none;
  color: var(--muted); font-size: 11px; font-weight: 700;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }

.tabbar[hidden], .fab[hidden] { display: none; }

/* ---- セグメント切替 ---- */
.segmented { display: flex; background: #f0e9e0; border-radius: 13px; padding: 4px; margin-bottom: 16px; }
.segmented button {
  flex: 1; border: none; background: transparent; padding: 10px;
  border-radius: 10px; font-weight: 700; font-size: 14px;
  color: var(--muted); cursor: pointer; font-family: inherit;
}
.segmented button.active { background: #fff; color: var(--accent-d); box-shadow: var(--shadow); }

.row2 { display: flex; gap: 12px; }
.row2 .field { flex: 1; }

.select {
  width: 100%; padding: 12px 13px; font-size: 16px; color: var(--text);
  border: 1px solid var(--border); border-radius: 13px; background: #fff;
  font-family: inherit;
}
.select:focus { outline: none; border-color: var(--accent); }

/* ---- 数値入力グリッド ---- */
.nf-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.nf { display: flex; flex-direction: column; }
.nf span { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.nf input {
  padding: 10px; font-size: 15px; color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
}
.nf input:focus { outline: none; border-color: var(--accent); }

/* ---- チェックリスト ---- */
.check-list { display: flex; flex-direction: column; max-height: 244px; overflow-y: auto; }
.check-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 2px; font-size: 15px; cursor: pointer;
  border-bottom: 1px solid #f3ece3;
}
.check-row.all { font-weight: 700; }
.check-row:last-child { border-bottom: none; }
.check-row input { width: 19px; height: 19px; accent-color: var(--accent); flex: none; }
.check-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- ラベルシート プレビュー ---- */
.sheet-preview {
  margin-top: 8px; background: #e7ded3; border-radius: 14px;
  padding: 14px; overflow: auto;
}
.sheet-scaler { margin: 0 auto; }
.sheet {
  width: 210mm; height: 297mm; background: #fff; position: relative;
  transform-origin: top left; box-shadow: var(--shadow);
}
.sheet .label {
  position: absolute; box-sizing: border-box;
  display: flex; align-items: center; gap: 1.6mm;
  padding: 1.6mm; overflow: hidden; outline: 1px dashed #d8cec0;
}
.sheet .label img { height: 100%; width: auto; aspect-ratio: 1 / 1; flex: none; }
.sheet .label-name {
  font-size: 3.2mm; font-weight: 700; line-height: 1.25;
  color: #000; word-break: break-word;
  display: -webkit-box; -webkit-box-orient: vertical;
  -webkit-line-clamp: 3; overflow: hidden;
}

/* ---- アカウント ---- */
.topbar-right { margin-left: auto; }
.acc-status { font-size: 16px; font-weight: 700; }
.acc-status b { color: var(--accent-d); }
.acc-id { font-size: 15px; color: var(--muted); margin-top: 4px; word-break: break-all; }
.row2 > .btn { flex: 1; }

/* ---- 部屋・ステータス ---- */
.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.st-packing  { background: #fdebc8; color: #b25e02; }
.st-packed   { background: #dbe8fe; color: #1d4ed8; }
.st-moved    { background: #e9e3fb; color: #6d28d9; }
.st-unpacked { background: #d3f3e2; color: #047857; }
.st-none     { background: #ece4da; color: #9a8f85; }

.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; }
.room-chip {
  font-size: 11px; font-weight: 700; color: var(--muted);
  background: #f0e9e0; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.box-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }

.progress { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.progress[hidden] { display: none; }
.prog-chip {
  font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px;
}

/* ---- タグ ---- */
.tags { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 12px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent-d);
  border-radius: 999px; padding: 6px 7px 6px 12px;
  font-size: 13px; font-weight: 700;
}
.tag-chip.readonly { padding: 6px 12px; }
.tag-chip .tag-x {
  border: none; cursor: pointer; width: 19px; height: 19px;
  border-radius: 50%; background: rgba(234, 88, 12, .16); color: var(--accent-d);
  font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.tag-add { display: flex; gap: 8px; }
.tag-add input {
  flex: 1; padding: 10px 12px; font-size: 15px; color: var(--text);
  border: 1px solid var(--border); border-radius: 11px; background: #fff;
}
.tag-add input:focus { outline: none; border-color: var(--accent); }
.tag-add .btn { flex: none; }

/* ---- ホームの絞り込み（部屋・タグ）---- */
.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.filter-row[hidden] { display: none; }
.filter-label {
  flex: none; font-size: 12px; font-weight: 700; color: var(--accent-d);
  background: var(--accent-soft); padding: 5px 10px; border-radius: 8px;
}
.filter-row .tag-filter { flex: 1; min-width: 0; margin-bottom: 0; }

.tag-filter {
  display: flex; gap: 8px; overflow-x: auto;
  margin-bottom: 14px; padding-bottom: 3px;
  -webkit-overflow-scrolling: touch;
}
.tag-filter::-webkit-scrollbar { height: 0; }
.tag-filter[hidden] { display: none; }
.tag-pill {
  flex: none; cursor: pointer; white-space: nowrap; font-family: inherit;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 700;
}
.tag-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---- カード上のタグ ---- */
.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.ctag {
  font-size: 11px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent-d);
  padding: 2px 8px; border-radius: 999px;
}

/* ---- 複数選択 ---- */
.card.selected { border-color: var(--accent); background: var(--accent-soft); }
.card-check {
  width: 24px; height: 24px; flex: none; border-radius: 50%;
  border: 2px solid #d0c6b8; background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.card.selected .card-check { border-color: var(--accent); background: var(--accent); }
.card.selected .card-check::after,
.select-all.checked .card-check::after {
  content: "✓"; color: #fff; font-size: 14px; font-weight: 900;
}

.select-all {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 4px 12px; cursor: pointer;
  font-weight: 700; font-size: 14px; color: var(--muted);
}
.select-all[hidden] { display: none; }
.select-all .card-check { width: 22px; height: 22px; }
.select-all.checked { color: var(--accent-d); }
.select-all.checked .card-check { border-color: var(--accent); background: var(--accent); }
.select-all.checked .card-check::after { font-size: 13px; }

.selbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 100%; max-width: 560px; z-index: 45;
  background: #fff; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; padding-bottom: calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgba(80, 55, 30, .08);
}
.selbar[hidden] { display: none; }
.selbar .sel-count { font-weight: 800; font-size: 14px; }
.selbar .spacer { flex: 1; }

/* ---- モーダル ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(40, 30, 20, .45);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: #fff; border-radius: 18px; padding: 20px;
  width: 100%; max-width: 360px; box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 16px; margin-bottom: 14px; }
.modal-input {
  width: 100%; padding: 12px 13px; font-size: 16px; color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; margin-bottom: 16px;
}
.modal-input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
.modal.busy {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  text-align: center; font-weight: 700; color: var(--text);
}

/* ---- 共有 ---- */
.share-link-row { display: flex; gap: 8px; margin: 8px 0; }
.share-link {
  flex: 1; min-width: 0; padding: 10px 11px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 10px;
  background: #faf6f1; color: var(--muted);
}
.share-section .btn { margin-top: 8px; margin-right: 8px; }
.share-section .share-link-row .btn { margin: 0; }

/* ---- 紹介CTA（公開ページ用）---- */
.cta { text-align: center; background: var(--accent-soft); border-color: #f6dcc2; }
.cta-icon { font-size: 40px; line-height: 1; }
.cta-title { font-size: 18px; font-weight: 800; color: var(--accent-d); margin-top: 4px; }
.cta-text { font-size: 14px; color: var(--text); margin: 8px 0 14px; line-height: 1.65; }

/* ---- 印刷時 ---- */
@media print {
  @page { size: A4; margin: 0; }
  body.print-mode { background: #fff; }
  body.print-mode .topbar,
  body.print-mode #tabbar,
  body.print-mode #fab,
  body.print-mode .pad > section,
  body.print-mode .pad > .btn,
  body.print-mode .pad > .hint { display: none !important; }
  body.print-mode .pad { padding: 0 !important; animation: none !important; }
  body.print-mode .sheet-preview {
    margin: 0 !important; padding: 0 !important;
    background: none !important; overflow: visible !important;
  }
  body.print-mode .sheet-scaler { width: auto !important; height: auto !important; margin: 0 !important; }
  body.print-mode .sheet { transform: none !important; box-shadow: none !important; }
  body.print-mode .sheet .label { outline: none !important; }
}
