:root {
  --fg: #1f2328;
  --bg: #fafafa;
  --line: #d0d7de;
  --muted: #6e7781;
  --accent: #0969da;
  --delivery: #0969da;
  --invoice: #1a7f37;
  --warn-bg: #fff8c5;
  --err-bg: #ffebe9;
  --err-fg: #cf222e;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  color: var(--fg);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}
header.app {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .6rem 1rem; background: #fff; border-bottom: 1px solid var(--line);
}
header.app h1 { font-size: 1.05rem; margin: 0; }
header.app .who { margin-left: auto; color: var(--muted); font-size: .9rem; }
header.app nav a { margin-right: .8rem; color: var(--accent); text-decoration: none; }
header.app nav a[aria-current="page"] { font-weight: 600; text-decoration: underline; }
body[data-doc-type="delivery"] header.app { border-top: 4px solid var(--delivery); }
body[data-doc-type="invoice"]  header.app { border-top: 4px solid var(--invoice); }
main { padding: 1rem; max-width: 1200px; margin: 0 auto; }
button, .btn {
  font: inherit; padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; cursor: pointer;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border: 1px solid var(--line); padding: .35rem .5rem; text-align: left; vertical-align: top; }
th { background: #f6f8fa; font-weight: 600; }
td.num, th.num { text-align: right; }
.low { background: var(--warn-bg); }
.err { background: var(--err-bg); color: var(--err-fg); }
.muted { color: var(--muted); }
.notice { padding: .6rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.notice.error { border-color: var(--err-fg); background: var(--err-bg); color: var(--err-fg); }
@media (max-width: 600px) {
  body { font-size: 16px; }
  main { padding: .6rem; }
}

/* 登録画面 */
.capture { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.capture .btn-file { display: inline-block; padding: .7rem 1.2rem; background: var(--accent); color: #fff; border-radius: 6px; cursor: pointer; }
.capture input[type=file] { display: none; }
.guide { font-size: .9rem; color: var(--muted); }
.editor-body { display: grid; grid-template-columns: minmax(280px, 45%) 1fr; gap: 1rem; margin-top: .6rem; }
.img-pane .zoom { display: flex; gap: 1rem; align-items: center; font-size: .9rem; margin-bottom: .3rem; }
.img-scroll { overflow: auto; max-height: 75vh; border: 1px solid var(--line); background: #fff; }
.img-scroll img { display: block; width: 100%; }
.header-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; margin-bottom: .6rem; }
.header-grid label { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); padding: .2rem; border-radius: 4px; }
.header-grid input, table.lines input { font: inherit; width: 100%; padding: .3rem .4rem; border: 1px solid var(--line); border-radius: 4px; background: transparent; }
table.lines td { padding: .15rem .2rem; }
table.lines td.num input { text-align: right; }
table.lines td.low input, .header-grid label.low input { background: var(--warn-bg); }
table.lines td.err input, .header-grid label.err input { background: var(--err-bg); border-color: var(--err-fg); }
table.lines button.del { padding: .1rem .4rem; }
.issues { list-style: none; padding: 0; margin: .6rem 0; font-size: .9rem; }
.issues li { padding: .15rem .5rem; margin-bottom: .2rem; border-left: 4px solid var(--line); }
.issues li.block, .issues li.error { border-color: var(--err-fg); background: var(--err-bg); }
.issues li.warn { border-color: #bf8700; background: var(--warn-bg); }
.actions { display: flex; gap: .6rem; margin: .6rem 0; }
.actions #discard { margin-left: auto; }
@media (max-width: 800px) {
  .editor-body { grid-template-columns: 1fr; }
  .img-scroll { max-height: 45vh; }
}

/* 撮るだけ画面 */
main.simple { max-width: 560px; text-align: center; }
.big-button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem;
  width: 100%; min-height: 40vh; margin: 1rem 0; border-radius: 16px; background: var(--accent); color: #fff;
  font-size: 1.6rem; font-weight: 600; cursor: pointer; user-select: none; }
body[data-doc-type="invoice"] .big-button { background: var(--invoice); }
.big-button:active { filter: brightness(.9); }
.big-button .icon { font-size: 3rem; width: 64px; height: 64px; }
.big-button input { display: none; }
.sent-list { list-style: none; padding: 0; margin: 0; text-align: left; }
.sent-list li { display: flex; gap: .6rem; align-items: baseline; padding: .5rem .7rem; background: #fff; border: 1px solid var(--line); border-radius: 6px; margin-bottom: .4rem; }
.sent-list li .mark { font-weight: 700; width: 1.2rem; }
.sent-list li.ok .mark { color: var(--invoice); }
.sent-list li.err { background: var(--err-bg); }
/* 受信箱 */
.toolbar { display: flex; gap: .6rem; align-items: center; margin-bottom: .6rem; }
.toolbar select { font: inherit; padding: .4rem; }
table.inbox tr[data-id] { cursor: pointer; }
table.inbox tr[data-id]:hover { background: #f0f6ff; }
table.inbox tr.selected { outline: 2px solid var(--accent); }
table.inbox .thumb { width: 48px; height: 48px; object-fit: cover; display: block; border-radius: 4px; }

/* ---- 第 1 段階: 撮るだけ画面 (/u) ---- */
body.capture-page main.simple { padding-top: 1.2rem; }
.capture-title { font-size: 1.3rem; margin: 0 0 .4rem; }
.big-button.disabled { background: var(--muted); pointer-events: none; }
body[data-doc-type="invoice"] .big-button { background: var(--invoice); }
.sent-list li .state { flex: 1; }
.sent-list li button { padding: .3rem .7rem; }

/* ---- 受信箱 ---- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.badge { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 999px; background: #eee; color: var(--fg); vertical-align: middle; }
.badge.open { background: var(--warn-bg); color: #7a5b00; }
.badge.done { background: #dafbe1; color: #116329; }
.seg button[aria-pressed="true"] .badge { background: #fff; color: var(--accent); }
.photo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.photo { display: flex; gap: .7rem; padding: .5rem; background: #fff; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.photo:hover { background: #f0f6ff; }
.photo.selected { outline: 2px solid var(--accent); }
.photo.done { opacity: .75; }
.photo .thumb { width: 84px; height: 84px; object-fit: cover; border-radius: 6px; flex: none; background: #eee; }
.photo .meta { font-size: .9rem; min-width: 0; }
.photo .note-preview { font-size: .85rem; color: #57606a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.small { font-size: .85rem; }
.viewer { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .8rem; }
.viewer-head { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.viewer-head .link { margin-left: auto; border: 0; background: none; color: var(--accent); }
.viewer-body { display: grid; grid-template-columns: minmax(300px, 55%) 1fr; gap: 1rem; }
.viewer .img-scroll { position: relative; }
.viewer .img-scroll img { display: block; width: auto; max-width: none; }
.side-pane { min-width: 0; }
.review-box { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; background: #f6f8fa; margin-bottom: .8rem; }
.review-box .actions { margin: .3rem 0; }
.review-box .memo { display: flex; flex-direction: column; font-size: .9rem; color: var(--muted); margin-top: .4rem; }
.review-box textarea { font: inherit; width: 100%; padding: .4rem; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--fg); }
button.danger { color: var(--err-fg); border-color: var(--err-fg); margin-left: auto; }
.extract h3 { font-size: 1rem; margin: .4rem 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: 0 0 .6rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.chip { display: inline-block; font-size: .8rem; padding: .05rem .4rem; border: 1px solid var(--line); border-radius: 4px; background: #fff; margin: .1rem .2rem .1rem 0; }
.extras { margin-top: .15rem; }
.masked { color: var(--muted); font-family: monospace; }
span.low { background: var(--warn-bg); padding: 0 .2rem; border-radius: 3px; }
.table-scroll { overflow-x: auto; }
table.lines.ro { font-size: .85rem; white-space: nowrap; }
table.lines.ro td { padding: .25rem .4rem; }
details.option { margin-top: .8rem; border-top: 1px dashed var(--line); padding-top: .5rem; }
details.option summary { cursor: pointer; color: var(--muted); }
@media (max-width: 800px) {
  .viewer-body { grid-template-columns: 1fr; }
}

/* ---- 出力・設定 ---- */
main.narrow { max-width: 820px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; }
.card h2 { font-size: 1.05rem; margin: .2rem 0 .5rem; }
.actions.wrap { flex-wrap: wrap; }
a.btn { text-decoration: none; color: var(--fg); display: inline-block; }
.url-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: .4rem 0; }
.url-row code { flex: 1; min-width: 200px; padding: .3rem .5rem; background: #f6f8fa; border: 1px solid var(--line); border-radius: 4px; overflow-wrap: anywhere; user-select: all; }
#form label { display: block; margin: .5rem 0; font-size: .9rem; color: var(--muted); }
#form label input[type=text], #form label input[type=number], #form label select { display: block; width: 100%; max-width: 420px; font: inherit; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 4px; margin-top: .15rem; color: var(--fg); }
#form label input[type=checkbox] { margin-right: .4rem; }

/* 出力: バックアップ表 */
#backups th.num, #backups td.num { white-space: nowrap; }
/* 設定: QR コード */
.qr { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin: .6rem 0 .2rem; }
.qr .code { background: #fff; padding: 8px; border: 1px solid var(--line); border-radius: 6px; line-height: 0; }
.qr .code img, .qr .code canvas { display: block; }
.qr .hint { font-size: .85rem; color: var(--muted); max-width: 26rem; }
@media print { header.app, .card:not(.print), button, .guide, #form { display: none !important; } .qr .code { border: 0; } }
.link-btn { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; cursor: pointer; font: inherit; }
/* ログイン */
main.login { max-width: 460px; }
main.login label { display: block; margin: .5rem 0; font-size: .9rem; color: var(--muted); }
main.login label input { display: block; width: 100%; font: inherit; font-size: 1.1rem; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; margin-top: .2rem; color: var(--fg); background: #fff; }
main.login #code { letter-spacing: .3em; font-family: ui-monospace, Menlo, monospace; text-align: center; }
main.login .actions { align-items: center; }
.pick-link { color: var(--accent); text-decoration: underline; cursor: pointer; }
.pick-link input { display: none; }
a.btn.disabled { opacity: .45; pointer-events: none; }
