:root {
  --bg: #ffffff;
  --text: #1f1f1f;
  --accent: #1a6db5;
  --accent-disabled: #b8c4cc;
  --border: #c9d1d6;
  --req: #d23;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
  color: var(--text);
  background: var(--bg);
  padding: env(safe-area-inset-top) 16px 16px;
}
.view { max-width: 480px; margin: 0 auto; }
h1 { font-size: 20px; margin: 16px 0; }
form { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
input, textarea {
  font-size: 16px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 44px;
}
textarea { min-height: 60px; resize: vertical; }
.req { color: var(--req); font-size: 11px; font-weight: 700; }
.opt { color: #888; font-size: 11px; font-weight: 700; }
.counter { color: #888; font-weight: 400; text-align: right; }
button {
  min-height: 44px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 12px;
}
button:disabled { background: var(--accent-disabled); }
.placeholder { color: #888; }

dialog {
  border: none;
  border-radius: 12px;
  padding: 20px;
  max-width: 360px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { font-size: 18px; margin: 0 0 12px; }
#resume-info { margin: 0 0 16px; }
#resume-info div { display: flex; gap: 8px; padding: 4px 0; font-size: 14px; }
#resume-info dt { width: 56px; color: #888; margin: 0; }
#resume-info dd { margin: 0; font-weight: 600; }
.dialog-actions { display: flex; gap: 8px; }
.dialog-actions button { flex: 1; }
.btn-secondary { background: #fff; color: var(--accent); border: 1px solid var(--accent); }

/* ---- ② スキャン画面 ---- */
.scan-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}
.session-line {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: #555;
}
.session-line .s-loc { font-weight: bold; color: #1f1f1f; }
.count-line { font-size: 14px; margin-top: 4px; }
.count-line b { font-size: 20px; }

.cam {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin: 10px 0;
}
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.flash { position: absolute; inset: 0; background: #fff; pointer-events: none; }
.flash.on { opacity: .7; transition: opacity 0s; }
.flash.off { opacity: 0; transition: opacity .25s ease; }
.cam-error {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: 12px;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.75); color: #fff; text-align: center; padding: 16px;
}
.cam-error[hidden] { display: none; } /* display:flex が UA の [hidden] を上書きするため明示的に消す */
.cam-error p { margin: 0; font-size: 14px; line-height: 1.5; }

.last-card {
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.last-card.empty { color: #999; }
.last-empty { font-size: 18px; padding: 10px 0; }
.last-jan { font-size: 13px; color: #888; }
.last-name { font-size: 22px; font-weight: bold; margin: 4px 0 12px; word-break: break-all; }
.qty-caption { display: block; font-size: 13px; color: #555; margin-bottom: 6px; }
#last-qty {
  width: 90px; min-height: 44px; font-size: 22px; text-align: center;
  border: 1px solid #ccc; border-radius: 10px;
}
.qty-row { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.btn-qty-save { min-height: 44px; min-width: 64px; padding: 0 16px; font-size: 15px; border-radius: 10px;
  border: 1px solid var(--accent, #516A39); background: var(--accent, #516A39); color: #fff; }
.qty-hint { font-size: 12px; color: #888; margin: 8px 0 0; }
.qty-saved { font-size: 13px; color: var(--accent, #516A39); font-weight: bold; }
.qty-saved[hidden] { display: none; }

/* ---- ③ リスト画面 ---- */
.list-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  padding: 8px 0;
  border-bottom: 1px solid #eee;
}
.list-rows { list-style: none; margin: 12px 0; padding: 0; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid #eee;
}
.row-main { flex: 1; min-width: 0; }
.row-jan { font-size: 12px; color: #888; }
.row-name { font-size: 16px; word-break: break-all; }
.row-qty {
  flex: none;
  width: 64px;
  min-height: 44px;
  font-size: 18px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.row-del {
  flex: none;
  min-width: 56px;
  padding: 0 12px;
  color: var(--req);
  background: #fff;
  border: 1px solid var(--req);
}
.list-empty { text-align: center; color: #888; padding: 40px 0; }
.list-empty[hidden] { display: none; }
.btn-open-list {
  width: 100%;
  margin-top: 12px;
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-back-scan { width: 100%; margin-top: 16px; }

/* ---- ①⇔④ 画面間の動線リンク ---- */
.nav-admin { margin: 8px 0; }
.nav-admin a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;            /* タップ最小44px（CLAUDE.md UI制約） */
  color: var(--accent);
  font-size: 14px;
  text-decoration: underline;
}

/* ---- ④ 管理画面 ---- */
.admin-block { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.file-label { font-weight: 600; font-size: 14px; }
.file-label input { margin-top: 6px; font-size: 16px; }
.master-status { font-size: 15px; }
.master-status.warn { color: #b26a00; font-weight: 700; } /* 5MB超のオレンジ警告 */
.master-error { color: var(--req); font-size: 14px; white-space: pre-line; line-height: 1.5; }
.master-error[hidden] { display: none; }
.admin-note { font-size: 12px; color: #888; line-height: 1.6; }
.admin-block .btn-secondary { align-self: flex-start; padding: 0 16px; }

/* ---- ②③ CSVダウンロードボタン ---- */
.btn-csv {
  width: 100%;
  margin-top: 12px;
  min-height: 44px;            /* タップ最小44px */
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-csv:disabled {
  color: #aaa;
  border-color: #ddd;
  background: #f7f7f7;
}
