/* ════════════════════════════════════════════════
   StockIn 共通のスタイル（紹介ページ・アプリ・規約）
   構成: 複写式の納品伝票。紙の上に緑の罫線、数字は等幅、朱色は「登録済」の印など要所だけ
   ════════════════════════════════════════════════ */

:root {
  --paper: #fbfaf4;
  --paper-2: #f1f2ea;
  --ink: #1f2826;
  --ink-2: #55625e;
  --rule: #8fb3a8;
  --rule-soft: #d3e2dc;
  --shu: #c0392b;
  --shu-soft: #f6e3dd;
  --ok: #2f6b4f;
  --ok-soft: #e1efe6;
  --warn: #8a5d0c;
  --warn-soft: #f6ecd5;
  --focus: #2f5fa8;

  --f-body: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --f-title: "BIZ UDPMincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --f-num: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 72px;
  --t-sm: .8125rem; --t-base: .9375rem; --t-md: 1.0625rem; --t-lg: 1.375rem; --t-xl: clamp(1.75rem, 1.2rem + 2.4vw, 2.75rem);
  --wrap: 1120px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161c1a; --paper-2: #1d2522; --ink: #e6ebe7; --ink-2: #a3b1ab;
    --rule: #4e7368; --rule-soft: #2b3a35; --shu: #e06a55; --shu-soft: #3a2420;
    --ok: #7cc29e; --ok-soft: #1f3329; --warn: #e0b45c; --warn-soft: #3a3020; --focus: #8db4f0;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: clip; margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--f-body); font-size: var(--t-base); line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
a { color: var(--ink); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.gutter { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.wrap { max-width: var(--wrap); margin-inline: auto; }

/* ── ボタン ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s5); border-radius: 3px; border: 1px solid var(--ink); background: transparent; cursor: pointer; text-decoration: none; font-weight: 700; white-space: nowrap; transition: background-color .15s, color .15s, border-color .15s; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn:not(.btn-primary):hover { background: var(--paper-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { min-height: 36px; padding: 0 var(--s4); font-size: var(--t-sm); }
.link-btn { border: 0; background: transparent; padding: 0; color: var(--ink); text-decoration: underline; cursor: pointer; font-size: var(--t-sm); }
.link-btn:hover { color: var(--shu); }

/* ── 入力 ── */
.input, .select { width: 100%; min-height: 40px; padding: 0 var(--s2); border: 1px solid var(--rule); background: var(--paper); border-radius: 2px; }
textarea.input { padding: var(--s2); min-height: 72px; }
.input:focus, .select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 2px var(--focus); }
.label { display: block; font-size: var(--t-sm); color: var(--ink-2); }
.req { color: var(--shu); font-size: .75rem; margin-left: 4px; }

/* ── 伝票 ── */
.slip { background: var(--paper); border: 1.5px solid var(--rule); position: relative; }
.slip-head { display: grid; grid-template-columns: 1fr auto; gap: var(--s4); align-items: center; padding: var(--s4) var(--s5); border-bottom: 1.5px solid var(--rule); }
.slip-title { font-family: var(--f-title); font-size: var(--t-lg); font-weight: 700; letter-spacing: .5em; }
.slip-no { font-size: var(--t-sm); color: var(--ink-2); text-align: right; line-height: 1.5; }
.slip-no .num { color: var(--ink); font-size: var(--t-base); }
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--rule); }
.field { padding: var(--s2) var(--s4); border-right: 1px solid var(--rule-soft); min-width: 0; }
.field:last-child { border-right: 0; }
.field select, .field input { width: 100%; border: 0; background: transparent; padding: 2px 0; font-weight: 700; min-height: 32px; }

.scan { display: flex; gap: var(--s3); align-items: center; padding: var(--s3) var(--s4); background: var(--paper-2); border-bottom: 1px solid var(--rule); }
.scan > label { font-size: var(--t-sm); color: var(--ink-2); white-space: nowrap; }
.scan input { flex: 1; min-width: 0; min-height: 48px; padding: 0 var(--s4); border: 1.5px solid var(--rule); background: var(--paper); font-family: var(--f-num); font-size: var(--t-md); letter-spacing: .06em; border-radius: 2px; }
.scan input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 2px var(--focus); }
.scan .btn { min-height: 48px; }

.panel { display: grid; gap: var(--s3); padding: var(--s4); border-bottom: 1px solid var(--rule); }
.panel-new { background: var(--warn-soft); }
.panel-sub { background: var(--paper-2); }
.panel .lead { font-size: var(--t-sm); }
.panel .lead b { font-family: var(--f-num); }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: var(--s3); min-width: 0; }
.panel-grid .wide { grid-column: span 2; }
.panel-actions { display: flex; gap: var(--s2); justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.panel-msg { color: var(--shu); font-size: var(--t-sm); font-weight: 700; margin-right: auto; }
.panel-msg:empty { display: none; }

.table-scroll { overflow-x: auto; }
table.lines { width: 100%; border-collapse: collapse; min-width: 640px; }
.lines th { font-weight: 400; font-size: var(--t-sm); color: var(--ink-2); text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--rule); border-right: 1px solid var(--rule-soft); white-space: nowrap; }
.lines td { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--rule-soft); border-right: 1px solid var(--rule-soft); vertical-align: middle; }
.lines th:last-child, .lines td:last-child { border-right: 0; }
.lines .r { text-align: right; }
.lines .c { text-align: center; }
.lines td.code { font-family: var(--f-num); font-size: var(--t-sm); color: var(--ink-2); white-space: nowrap; }
.lines td.name { min-width: 12em; }
.lines input.cell { width: 5.5em; text-align: right; border: 1px solid transparent; background: transparent; padding: 2px 4px; font-family: var(--f-num); }
.lines input.cell:hover, .lines input.cell:focus { border-color: var(--rule); background: var(--paper); }
.lines tr.blank td { height: 2.4em; }
.lines tr.flash td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--warn-soft); } to { background: transparent; } }
.lines tfoot td { font-weight: 700; border-top: 1.5px solid var(--rule); border-bottom: 0; }
.thumb { width: 28px; height: 28px; object-fit: cover; border-radius: 2px; vertical-align: middle; margin-right: var(--s2); border: 1px solid var(--rule-soft); }
.kind { display: inline-block; font-size: var(--t-sm); padding: 0 6px; border: 1px solid currentColor; border-radius: 2px; line-height: 1.6; white-space: nowrap; }
.kind.new { color: var(--warn); background: var(--warn-soft); }
.kind.has { color: var(--ink-2); }
.del { border: 0; background: transparent; color: var(--ink-2); cursor: pointer; padding: 4px 8px; font-size: var(--t-sm); text-decoration: underline; }
.del:hover { color: var(--shu); }

.photo-pick { display: flex; align-items: center; gap: var(--s2); min-height: 40px; padding: 0 var(--s2); border: 1px dashed var(--rule); background: var(--paper); border-radius: 2px; cursor: pointer; font-size: var(--t-sm); }
.photo-pick:hover { border-style: solid; }
.photo-pick img { width: 32px; height: 32px; object-fit: cover; border-radius: 2px; }
.photo:focus-within .photo-pick { outline: 2px solid var(--focus); outline-offset: 2px; }

.slip-foot { display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: var(--s5); align-items: center; padding: var(--s4) var(--s5); min-height: 88px; }
.memo input { width: 100%; border: 0; border-bottom: 1px solid var(--rule); background: transparent; padding: 4px 0; }
.done-seal { display: grid; place-items: center; }
.hanko { width: 56px; height: 56px; border: 2px solid var(--shu); border-radius: 50%; color: var(--shu); font-family: var(--f-title); font-weight: 700; display: grid; place-items: center; text-align: center; line-height: 1.1; font-size: .8rem; transform: rotate(-8deg); }
.hanko.stamp { animation: stamp .35s cubic-bezier(.2,.9,.3,1.3); }
@keyframes stamp { from { transform: rotate(-8deg) scale(1.6); opacity: 0; } to { transform: rotate(-8deg) scale(1); opacity: 1; } }
.submit { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; padding: var(--s3) var(--s5) var(--s5); }
.submit p { font-size: var(--t-sm); color: var(--ink-2); }
.submit p b { color: var(--ink); }
.ok-text { color: var(--ok); font-weight: 700; }
.err-text { color: var(--shu); font-weight: 700; }

@media (max-width: 600px) {
  .fields { grid-template-columns: minmax(0, 1fr); }
  .field { border-right: 0; border-bottom: 1px solid var(--rule-soft); }
  .slip-head { padding: var(--s3) var(--s4); }
  .slip-title { font-size: var(--t-md); letter-spacing: .3em; }
  .scan { flex-wrap: wrap; }
  .scan > label { width: 100%; }
  .panel-grid { grid-template-columns: minmax(0, 1fr); }
  .panel-grid .wide { grid-column: auto; }
  /* 明細は1行を2段に */
  table.lines { min-width: 0; }
  .lines thead { display: none; }
  .lines tbody tr { display: grid; grid-template-columns: 1fr auto auto; gap: 2px var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--rule-soft); }
  .lines tbody td { border: 0; padding: 0; }
  .lines td.no, .lines td.price { display: none; }
  .lines td.name { grid-column: 1 / -1; min-width: 0; font-weight: 700; }
  .lines td.code { grid-column: 1; }
  .lines tr.blank { display: none !important; }
  .lines tfoot tr { display: flex; justify-content: space-between; padding: var(--s3) var(--s4); }
  .lines tfoot td { border: 0; padding: 0; }
  .lines tfoot td.hide-sm { display: none; }
  .slip-foot { padding: var(--s4); }
  .submit { padding: var(--s3) var(--s4) var(--s4); }
  .submit .btn { width: 100%; min-height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  .hanko.stamp, .lines tr.flash td { animation: none; }
  .btn { transition: none; }
}
