:root {
  --bg: #f3f4f6; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --primary: #1d4ed8; --primary-dark: #1e40af; --danger: #dc2626; --ok: #059669; --warn: #d97706;
  --radius: 12px; --nav-h: 60px; --header-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", "Segoe UI", sans-serif; font-size: 16px; -webkit-text-size-adjust: 100%; }
body { padding-top: var(--header-h); padding-bottom: calc(var(--nav-h) + var(--safe-b)); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; }

#header { position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; z-index: 50; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
#header .brand { color: #fff; font-weight: 700; font-size: 16px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 8px; }
#header select { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 8px; padding: 6px 8px; max-width: 48vw; }
#header select option { color: #000; }

#nav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: #fff; border-top: 1px solid var(--line); display: flex; z-index: 50; }
#nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); gap: 2px; }
#nav a .ic { font-size: 22px; line-height: 1; }
#nav a.active { color: var(--primary); font-weight: 700; }
#nav a.scan .ic { background: var(--primary); color: #fff; border-radius: 50%; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; font-size: 20px; margin-top: -18px; box-shadow: 0 2px 6px rgba(0,0,0,.25); }

#view { padding: 12px; max-width: 760px; margin: 0 auto; }
@media (min-width: 900px) { #view { max-width: 1000px; } }
.loading { text-align: center; color: var(--muted); padding: 40px; }

h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 16px 0 8px; color: var(--text); }
h3 { font-size: 14px; margin: 12px 0 6px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card.step { border-left: 4px solid var(--line); }
.card.step.done { border-left-color: var(--ok); }
.card.step.active { border-left-color: var(--primary); }
.card .title { font-weight: 700; display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font-weight: 600; min-height: 44px; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.block { width: 100%; }
.btn.lg { font-size: 18px; min-height: 54px; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; background: #fff; min-height: 44px; }
.field textarea { min-height: 80px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
@media (max-width: 400px) { .grid3 { grid-template-columns: 1fr 1fr; } }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid #d1d5db; background: #fff; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--primary); color: #fff; border-color: var(--primary); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #e5e7eb; color: #374151; white-space: nowrap; }
.badge.在庫 { background: #d1fae5; color: #065f46; }
.badge.移動中 { background: #fef3c7; color: #92400e; }
.badge.販売済 { background: #dbeafe; color: #1e3a8a; }
.badge.廃棄 { background: #fee2e2; color: #991b1b; }
.badge.ai { background: #ede9fe; color: #5b21b6; }

.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.item { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); align-items: center; color: inherit; }
.item:last-child { border-bottom: 0; }
.item .thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: #e5e7eb; flex: none; display: flex; align-items: center; justify-content: center; font-size: 24px; }
.item .body { flex: 1; min-width: 0; }
.item .t1 { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.item .t2 { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.selectable { cursor: pointer; }
.item.selected { background: #eff6ff; }

.kv { display: grid; grid-template-columns: 7.5em 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.stat .n { font-size: 26px; font-weight: 800; }
.stat .l { font-size: 12px; color: var(--muted); }

.photo-box { width: 100%; aspect-ratio: 4/3; background: #e5e7eb; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted); }
.photo-box img { width: 100%; height: 100%; object-fit: contain; background: #000; }
.photo-sm { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; background: #000; }
input[type=file].hidden { display: none; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.timeline .when { font-size: 12px; color: var(--muted); }

.copy-grid { display: grid; grid-template-columns: 1fr auto; gap: 6px 8px; align-items: center; }
.copy-grid .k { font-size: 12px; color: var(--muted); }
.copy-grid .v { font-weight: 600; word-break: break-all; }
.copy-grid .copy-cell { display: flex; flex-direction: column; }
pre.copybox { background: #f9fafb; border: 1px solid var(--line); border-radius: 10px; padding: 10px; white-space: pre-wrap; font-size: 13px; font-family: inherit; }

.alert { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 10px; }
.alert.info { background: #eff6ff; color: #1e3a8a; }
.alert.warn { background: #fffbeb; color: #92400e; }
.alert.err { background: #fef2f2; color: #991b1b; }
.alert.ok { background: #ecfdf5; color: #065f46; }

.tabs { display: flex; gap: 4px; background: #e5e7eb; padding: 4px; border-radius: 10px; margin-bottom: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs button.on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); }

.searchbar { display: flex; gap: 8px; margin-bottom: 10px; }
.searchbar input { flex: 1; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 10px; min-height: 44px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 14px); transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast .t { background: #111827; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.25); max-width: 90vw; animation: fadein .2s; }
#toast .t.err { background: var(--danger); } #toast .t.ok { background: var(--ok); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 90; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 640px) { .modal-bg { align-items: center; } }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px; padding-bottom: calc(16px + var(--safe-b)); }
@media (min-width: 640px) { .modal { border-radius: 16px; } }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; gap: 8px; margin-top: 14px; }
.modal .actions .btn { flex: 1; }

.scanner { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4/3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; inset: 15% 10%; border: 3px solid rgba(255,255,255,.8); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scanner .frame.qr { inset: 12% 20%; }
.scanner .msg { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; color: #fff; font-size: 13px; text-shadow: 0 1px 2px #000; }

.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu-grid a { background: #fff; border-radius: var(--radius); padding: 18px 12px; text-align: center; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.menu-grid a .ic { display: block; font-size: 28px; margin-bottom: 6px; }

.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid rgba(0,0,0,.15); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn.primary .spin { border-color: rgba(255,255,255,.4); border-top-color: #fff; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; border-radius: var(--radius); overflow: hidden; }
table.tbl th, table.tbl td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.tbl th { background: #f9fafb; color: var(--muted); font-weight: 600; }
.qr-big { width: 160px; height: 160px; }

/* ログイン画面 */
body.login { padding: 0; }
body.login #header, body.login #nav { display: none; }
body.login #view { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: #fff; border-radius: 16px; padding: 28px 22px; width: 100%; max-width: 380px; box-shadow: 0 4px 16px rgba(0,0,0,.08); text-align: center; }
.login-card .logo { font-size: 48px; }
.login-card h1 { margin: 4px 0 2px; }
.login-card .field { text-align: left; }
.login-card .btn { margin-top: 6px; }
