/* 材料在庫管理 — スマホ優先。幅 900px 以上で PC 向けの並びにする */
:root {
  --ink: #1d1f23;
  --sub: #6b7078;
  --line: #d5d8dd;
  --bg: #eef0f3;
  --panel: #ffffff;
  --accent: #1f5fbf;
  --accent-soft: #e6eefb;
  --edge: #1f7aff;
  --seam: #ff2d8a;
  --warn: #b3261e;
  --ok: #1d7a3a;
  --tabh: 58px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Yu Gothic UI", "Hiragino Sans", "Noto Sans JP", "Meiryo", sans-serif; color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.muted { color: var(--sub); font-size: 13px; }
.warn { color: var(--warn); }
.hint { font-size: 12px; color: var(--sub); line-height: 1.7; margin: 0; }
.hint.flash { color: var(--warn); }
.c-edge { color: var(--edge); }
.c-seam { color: var(--seam); }
code { font-size: 12px; background: #f3f4f6; padding: 1px 4px; border-radius: 4px; word-break: break-all; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
       border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer; font-size: 14px; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn.ghost { background: #fff; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.block { display: flex; width: 100%; margin-top: 16px; min-height: 48px; font-size: 16px; }
.btn:disabled { opacity: .45; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--sub); text-decoration: underline; cursor: pointer; font-size: 12px; padding: 4px; }

/* ---------- ログイン ---------- */
#login { max-width: 380px; margin: 0 auto; padding: 48px 16px; }
#login h1 { font-size: 22px; text-align: center; margin: 0 0 20px; }
#login .card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
#login label { display: block; font-size: 13px; color: var(--sub); margin: 12px 0 6px; }
#login input { width: 100%; font-size: 18px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
#login .msg { color: var(--warn); font-size: 13px; white-space: pre-line; margin-top: 12px; min-height: 1em; }
#login .hint { margin-top: 12px; text-align: center; }

/* ---------- 枠 ---------- */
header { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line);
         display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
header .title { font-weight: 700; font-size: 16px; }
header .who { font-size: 12px; color: var(--sub); }
main { padding: 12px 12px calc(var(--tabh) + 16px + env(safe-area-inset-bottom)); max-width: 1200px; margin: 0 auto; }

/* スマホ: タブは画面の下 */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; background: var(--panel);
        border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs button { flex: 1; height: var(--tabh); border: 0; background: none; display: flex; flex-direction: column; align-items: center;
               justify-content: center; gap: 2px; font-size: 11px; color: var(--sub); cursor: pointer; }
#tabs button i { font-style: normal; font-size: 20px; line-height: 1; }
#tabs button[aria-selected="true"] { color: var(--accent); font-weight: 700; }

@media (min-width: 900px) {
  main { padding-bottom: 24px; }
  #tabs { position: static; border: 0; padding: 0; margin-left: 12px; gap: 4px; background: none; }
  #tabs button { flex: none; height: 36px; flex-direction: row; font-size: 14px; padding: 0 14px; border-radius: 8px; }
  #tabs button i { font-size: 15px; }
  #tabs button[aria-selected="true"] { background: var(--accent-soft); }
}

.rbar { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-bottom: 12px; }
.rbar label { font-size: 13px; color: var(--sub); display: inline-flex; gap: 6px; align-items: center; }
.rbar input[type=date], .rbar select { padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.empty { text-align: center; color: var(--sub); padding: 56px 16px; border: 2px dashed var(--line); border-radius: 12px; background: var(--panel); line-height: 1.8; }
.empty.drag { border-color: var(--accent); color: var(--accent); }

/* ---------- 選ぶ部品 ---------- */
.picker { display: flex; flex-direction: column; gap: 14px; }
.pgroup .ptitle { font-size: 13px; font-weight: 700; color: var(--sub); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 40px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 20px; background: #fff; cursor: pointer; font-size: 15px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.chip.add { border-style: dashed; color: var(--accent); }
.chip.editing { border-color: var(--warn); color: var(--warn); }
.chip.recent { font-size: 13px; }
.chip.size { font-variant-numeric: tabular-nums; }

/* ---------- 撮影 ---------- */
.selbar { display: flex; gap: 8px; align-items: stretch; margin-bottom: 10px; }
.selbtn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; text-align: left; padding: 10px 12px;
          border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; font-size: 15px; font-weight: 700; }
.selbtn .sel-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selbtn .sel-change { font-size: 12px; font-weight: 400; color: var(--accent); }
.selbtn.empty { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.s-date { padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; background: #fff; max-width: 150px; }
.cam { position: relative; background: #000; border-radius: 12px; overflow: hidden; min-height: 200px; }
.cam video { display: block; width: 100%; max-height: 64vh; object-fit: contain; background: #000; }
.live-label { position: absolute; left: 8px; bottom: 8px; display: flex; gap: 8px; align-items: center; background: rgba(255,255,255,.94);
              border-radius: 6px; padding: 6px; max-width: calc(100% - 16px); }
.live-label canvas { width: 56px; height: 56px; flex: none; }
.live-label .lbl-text { font-size: 13px; font-weight: 700; line-height: 1.35; color: #000; }
.cam-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
           padding: 24px; color: #fff; font-size: 14px; line-height: 1.7; background: rgba(0,0,0,.6); }
.cam-ctrl { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; padding: 14px 4px 4px; }
.cam-ctrl .pickfile { justify-self: start; }
.shutter { width: 74px; height: 74px; border-radius: 50%; border: 5px solid var(--accent); background: #fff; cursor: pointer;
           box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 40px var(--accent); }
.shutter:active { transform: scale(.94); }
.cam-tip { font-size: 12px; color: var(--sub); justify-self: end; text-align: right; }
.result .res-head { font-weight: 700; margin-bottom: 8px; }
/* スマホでは撮ったあとすぐ押せるよう、タブのすぐ上に貼り付けておく */
.res-btns { display: flex; gap: 10px; margin-top: 12px; position: sticky; z-index: 5;
            bottom: calc(var(--tabh) + env(safe-area-inset-bottom)); background: var(--bg); padding: 8px 0; }
@media (min-width: 900px) { .res-btns { position: static; padding: 0; } }
.res-btns .btn { flex: 1; min-height: 50px; font-size: 16px; }

/* ---------- 数える部品 ---------- */
.counter { display: flex; flex-direction: column; gap: 12px; }
.cview { position: relative; align-self: center; }
.cview canvas.cmain { display: block; border-radius: 8px; touch-action: none; }
.counter.tap .cview canvas.cmain { touch-action: pan-x pan-y pinch-zoom; cursor: crosshair; }
.loupe { position: absolute; left: 8px; border: 2px solid #fff; border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.4); display: none; pointer-events: none; }
.cside { display: flex; flex-direction: column; gap: 8px; }
.count { display: flex; align-items: center; justify-content: center; gap: 12px; }
.count button { width: 52px; height: 52px; font-size: 26px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.count output { font-size: 44px; font-weight: 700; min-width: 80px; text-align: center; font-variant-numeric: tabular-nums; }
.count .unit { font-size: 16px; }
.est { font-size: 13px; color: var(--sub); line-height: 1.6; text-align: center; }
.est b { color: var(--ink); }
.wt { font-size: 14px; text-align: center; }
@media (min-width: 900px) {
  .counter { flex-direction: row; align-items: flex-start; }
  .cview { align-self: flex-start; }
  .cside { flex: 1; min-width: 240px; }
  .count { justify-content: flex-start; }
  .est, .wt { text-align: left; }
}

/* ---------- 記録 ---------- */
.r-sum { font-size: 14px; margin-bottom: 8px; }
.r-list { display: flex; flex-direction: column; gap: 8px; }
.rrow { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.rrow img { width: 72px; height: 96px; object-fit: cover; border-radius: 6px; background: #ddd; flex: none; cursor: zoom-in; }
.rinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.rmat { font-size: 15px; }
.rloc { font-size: 12px; color: var(--sub); }
.rqty { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rqty button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 18px; cursor: pointer; }
.rqty output { font-size: 22px; font-weight: 700; min-width: 36px; text-align: center; font-variant-numeric: tabular-nums; }
.rqty .rkg { font-size: 13px; color: var(--sub); }
.rqty .warn { font-size: 12px; }
.rdel { align-self: flex-start; background: none; border: 0; color: var(--warn); font-size: 12px; cursor: pointer; padding: 4px; }
.r-note { margin-top: 16px; }

/* ---------- 取り込み ---------- */
.i-list { display: flex; flex-direction: column; gap: 14px; }
.icard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.icard.saved { border-color: var(--ok); }
.i-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.i-name { font-size: 12px; color: var(--sub); word-break: break-all; }
.i-qr { font-size: 12px; padding: 2px 8px; border-radius: 10px; }
.i-qr.ok { background: #e8f5ec; color: var(--ok); }
.i-qr.ng { background: #fff4e5; color: #8a4b00; }
.i-pick.need { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); font-weight: 700; }

/* ---------- QR札 ---------- */
.lwrap { display: flex; flex-direction: column; gap: 16px; }
.lside { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.lmain { flex: 1; min-width: 0; }
.lrow { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; }
.lrow span { font-size: 12px; color: var(--sub); min-width: 90px; }
.lrow b { flex: 1; }
@media (min-width: 900px) {
  .lwrap { flex-direction: row; align-items: flex-start; }
  .lside { width: 420px; flex: none; position: sticky; top: 70px; }
}

/* ---------- シート・通知 ---------- */
#sheet { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
              background: var(--panel); border-bottom: 1px solid var(--line); font-weight: 700; }
.sheet-body { flex: 1; overflow-y: auto; padding: 14px 14px calc(24px + env(safe-area-inset-bottom)); max-width: 900px; width: 100%; margin: 0 auto; }
#toast { position: fixed; left: 50%; bottom: calc(var(--tabh) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
         z-index: 40; background: #1d1f23; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
         max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.25); white-space: pre-line; }
#toast.err { background: var(--warn); }

/* ---------- 印刷（棚卸しPDF・QR札） ---------- */
#print { display: none; }
@page { size: A4 portrait; margin: 0; }
@media print {
  body { background: #fff; }
  body[data-print] #app, body[data-print] #login, body[data-print] #sheet, body[data-print] #toast { display: none !important; }
  body[data-print] #print { display: block; }
  .page, .lpage { width: 210mm; height: 297mm; padding: 10mm; page-break-after: always; break-after: page; }
  .page:last-child, .lpage:last-child { page-break-after: auto; break-after: auto; }
  .page { display: flex; flex-direction: column; }
  .page .head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: .4mm solid #000; padding-bottom: 2mm; margin-bottom: 3mm; }
  .page .head h1 { font-size: 6mm; margin: 0; }
  .page .head span { font-size: 3.2mm; }
  .page .grid { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 3mm; min-height: 0; }
  .page .cell { border: .3mm solid #000; display: flex; padding: 2mm; gap: 2mm; min-height: 0; overflow: hidden; }
  /* 写真は枠の高さいっぱいに（縦長の写真が多いため）。表の幅を残すため幅 52% で頭打ち */
  .page .ph { flex: none; height: 100%; max-width: 52%; display: flex; align-items: center; justify-content: center; min-height: 0; }
  .page .ph img { height: 100%; width: auto; max-width: 100%; object-fit: contain; display: block; }
  .page table { flex: 1; border-collapse: collapse; font-size: 3mm; }
  .page th, .page td { border: .25mm solid #000; padding: .6mm 1.4mm; text-align: left; }
  .page th { width: 13mm; background: #e6e6e6; font-weight: 600; white-space: nowrap; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .page table { min-width: 40mm; }
  .page td { overflow-wrap: anywhere; }
  .page td.size { white-space: nowrap; font-size: 2.8mm; }   /* 19×2438×8100 を数字の途中で折らない */
  .page td.qty { font-size: 4.2mm; font-weight: 700; }
  .page td.qty small { display: block; font-size: 2.8mm; font-weight: 400; }
  .lpage { display: grid; }
  .label { border: .3mm dashed #b5b9bf; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3mm; overflow: hidden; text-align: center; color: #000; }
  .label svg { display: block; margin-bottom: 2mm; }
  .label .t1 { font-weight: 700; line-height: 1.25; }
  .label .t2 { color: #333; margin-top: 1mm; }
}
