:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --ink: #221d18;
  --muted: #6f675e;
  --line: #e2ddd3;
  --accent: #9c2f1e;
  --accent-ink: #ffffff;
  --accent-soft: #f6e7e2;
  --ok: #2c6e49;
  --warn: #a15c00;
  --warn-soft: #fdf1dc;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
a { color: var(--accent); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--accent); }

/* 枠 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 16px;
}
.brand { font-weight: 700; letter-spacing: .02em; margin-right: auto; }
.brand small { font-weight: 400; opacity: .7; margin-left: 6px; }
.topbar .who { font-size: 13px; opacity: .85; }
.topbar button.link { color: #fff; opacity: .85; }
.seg { display: inline-flex; background: rgba(255,255,255,.14); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; color: inherit; padding: 5px 12px; border-radius: 6px; font: inherit; font-size: 13px; cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); font-weight: 600; }
.seg.light { background: #ebe7df; }
.seg.light button.on { background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.nav { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; padding: 0 8px; }
.nav a { padding: 11px 13px; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 3px solid transparent; font-size: 14px; }
.nav a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }
.pagehead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.pagehead h1 { margin-right: auto; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.card > h2 { margin-bottom: 10px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { font-size: 12.5px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }
.cols { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .cols { grid-template-columns: 1fr 1fr; } }

/* 入力 */
label.f { display: block; font-size: 12.5px; color: var(--muted); }
label.f > span { display: block; margin-bottom: 3px; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink);
  width: 100%; padding: 8px 10px;
  border: 1px solid #cfc8bb; border-radius: 8px; background: #fff;
}
input:disabled, select:disabled { background: #f1eee8; color: var(--muted); }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 140px; }
.row > .fit { flex: 0 0 auto; }
.fields { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.fields .wide { grid-column: 1 / -1; }
button { font: inherit; cursor: pointer; }
.btn { border: 1px solid #cfc8bb; background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; font-size: 14px; text-decoration: none; display: inline-block; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.big { padding: 12px 22px; font-size: 16px; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; font-size: inherit; }

/* 表 */
.tablewrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: #faf8f4; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #faf6f0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; }
tr.off td { color: #a39c92; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: #ece8df; color: var(--ink); white-space: nowrap; }
.badge.in { background: #e1efe6; color: var(--ok); }
.badge.out { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.empty { color: var(--muted); text-align: center; padding: 22px 0; }
.notice { background: var(--warn-soft); color: #6b3d00; border-radius: 8px; padding: 9px 12px; font-size: 13.5px; margin-bottom: 12px; }

/* 入出庫入力 */
.types { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; }
.types button { border: 1px solid #cfc8bb; background: var(--surface); border-radius: 8px; padding: 10px 4px; font-size: 14px; color: var(--ink); }
.types button.on { background: var(--ink); color: #fff; border-color: var(--ink); font-weight: 600; }
.line { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: #fcfbf8; }
.line .row > .qty { flex: 1 1 90px; }
.line .meta { display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; font-weight: 700; padding: 6px 2px 12px; }

.line.uncertain { border-color: #e0b25c; background: #fffaf0; }
.line.extra { border-color: #e0b25c; border-style: dashed; background: var(--warn-soft); }
.scan { border-style: dashed; }
.scanres { display: flex; gap: 14px; align-items: flex-start; }
.scanres img { width: 110px; max-height: 150px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; flex: 0 0 auto; }

/* 履歴 */
.slip { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin-bottom: 10px; }
.slip header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.slip header .date { font-weight: 700; font-variant-numeric: tabular-nums; }
.slip header .acts { margin-left: auto; display: flex; gap: 6px; }
.slip table td { border-bottom: 0; padding: 4px 12px; }
.slip footer { padding: 6px 12px 9px; font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

/* ログイン */
.login { max-width: 380px; margin: 9vh auto 0; padding: 0 16px; }
.login h1 { text-align: center; margin-bottom: 4px; }
.login p.lead { text-align: center; color: var(--muted); margin: 0 0 18px; font-size: 13.5px; }
.login form { display: grid; gap: 12px; }
.err { color: var(--accent); font-size: 13.5px; min-height: 1.2em; }

/* ダイアログ・通知 */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); color: var(--ink); }
dialog::backdrop { background: rgba(30, 25, 20, .45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
dialog .dhead { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; }
dialog .dbody { padding: 14px 18px; overflow-y: auto; }
dialog .dfoot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
dialog .dfoot .err { margin-right: auto; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 9px 18px; border-radius: 99px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; }

/* 納品書 */
.sheet { background: #fff; border: 1px solid var(--line); padding: 34px 38px; max-width: 800px; margin: 0 auto; color: #000; font-size: 13.5px; }
.sheet h1 { text-align: center; font-size: 24px; letter-spacing: .5em; margin-bottom: 22px; }
.sheet .heads { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 18px; }
.sheet .to { font-size: 18px; font-weight: 700; border-bottom: 1px solid #000; padding-bottom: 4px; margin-bottom: 6px; }
.sheet .from { text-align: right; font-size: 12.5px; line-height: 1.7; }
.sheet .from strong { font-size: 15px; }
.sheet .sum { font-size: 18px; font-weight: 700; border-bottom: 2px solid #000; display: inline-block; padding: 2px 6px 2px 0; margin: 4px 0 14px; }
.sheet table th, .sheet table td { border: 1px solid #333; padding: 5px 8px; }
.sheet table th { background: #eee; color: #000; text-align: center; }
.sheet .totals { margin-left: auto; width: 280px; margin-top: 10px; }
.sheet .foot { margin-top: 16px; font-size: 12px; white-space: pre-wrap; }

@media (max-width: 600px) {
  .hide-s { display: none; }
  .sheet { padding: 18px 14px; }
}
@media print {
  body { background: #fff; }
  .topbar, .nav, .no-print, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { border: 0; padding: 0; max-width: none; }
  @page { size: A4; margin: 16mm 14mm; }
}
