:root {
  --bg: #f3f5f8;
  --card: #fff;
  --ink: #1d2733;
  --muted: #6b7684;
  --line: #dde2e8;
  --primary: #1f6feb;
  --primary-ink: #fff;
  --danger: #d1242f;
  --ok-bg: #e7f6ec; --ok-ink: #1a7f37;
  --ng-bg: #fdecec; --ng-ink: #b42318;
  --info-bg: #eaf2fe; --info-ink: #1d4ed8;
  --bar: #1f2a37;
  --admin-bar: #3b2f5c;
  --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 16px; line-height: 1.6; }
a { color: var(--primary); }
h1 { font-size: 1.35rem; margin: .6em 0 .6em; }
h2 { font-size: 1.05rem; margin: 0 0 .6em; }

/* ---- header ---- */
.topbar { background: var(--bar); color: #fff; display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 6px 16px; padding: 10px 16px; position: sticky; top: 0; z-index: 10; }
.admin-bar { background: var(--admin-bar); }
.brand { color: #fff; text-decoration: none; font-weight: 700; }
.topnav { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .92rem; }
.topnav a { color: #dfe6ee; text-decoration: none; padding: 2px 0; border-bottom: 2px solid transparent; }
.topnav a.on, .topnav a:hover { color: #fff; border-bottom-color: #fff; }
.topnav a.muted { color: #aab4bf; }
.tag { display: inline-block; font-size: .72rem; padding: 0 6px; border-radius: 4px; background: rgba(255,255,255,.18); vertical-align: 2px; }
td .tag { background: var(--info-bg); color: var(--info-ink); }

.container { max-width: 560px; margin: 0 auto; padding: 12px 16px 48px; }
.container.wide { max-width: 1200px; }

/* ---- parts ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 12px; font-size: .95rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash-ng { background: var(--ng-bg); color: var(--ng-ink); }
.flash-info { background: var(--info-bg); color: var(--info-ink); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 160px; min-width: 0; }

label { display: block; font-weight: 600; font-size: .92rem; margin: 0 0 14px; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
input[type=text], input[type=password], input[type=email], input[type=search], input[type=number], input[type=date], select {
  width: 100%; font: inherit; font-size: 16px; /* iOSのズーム防止 */
  padding: 10px 12px; border: 1px solid #c5ccd5; border-radius: 8px; background: #fff; color: var(--ink); margin-top: 4px; }
.row input, .row select, .filters input, .filters select { width: auto; margin-top: 0; }
.row .grow { width: auto; }
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: var(--primary); }
.w-sort { width: 90px !important; }
.w-pw { width: 140px !important; padding: 6px 8px !important; font-size: 14px !important; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: .95rem;
  padding: 9px 16px; border-radius: 8px; border: 1px solid #c5ccd5; background: #fff; color: var(--ink);
  text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f4f7; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #1a5fd0; }
.btn-danger { color: var(--danger); border-color: #f0b4b8; }
.btn-danger:hover { background: var(--ng-bg); }
.btn-big { width: 100%; padding: 14px; font-size: 1.05rem; font-weight: 700; margin: 0 0 10px; }
.btn-sm { padding: 4px 10px; font-size: .82rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.ico { font-size: 1.2em; line-height: 1; }

/* ---- login / menu ---- */
.login-card { max-width: 420px; margin: 24px auto; }
.login-card h1 { margin-top: 0; text-align: center; }
.menu-grid { display: grid; gap: 14px; margin-top: 12px; }
.menu-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 28px 16px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: 1.2rem; font-weight: 700; }
.menu-btn .ico { font-size: 2.2rem; }
.menu-btn small { font-size: .82rem; font-weight: 400; color: var(--muted); }
.menu-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.menu-btn.primary small { color: #dbe7ff; }

/* ---- scan ---- */
.reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; margin-bottom: 12px; min-height: 40px; }
.code-badge { display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700;
  background: var(--bar); color: #fff; padding: 1px 10px; border-radius: 6px; letter-spacing: .08em; }
.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li a { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 8px; color: var(--ink); text-decoration: none; }
.r-sub { font-size: .85rem; color: var(--muted); margin-top: 2px; }

/* ---- admin ---- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form.narrow { max-width: 360px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { background: #f7f9fb; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.table th a { color: inherit; text-decoration: none; }
.table th a.on { color: var(--ink); }
.table tbody tr:hover { background: #fafbfd; }
.table tr.inactive td { color: var(--muted); background: #fafafa; }
.table tr.warn td { background: #fff6f6; }
.table.small { font-size: .85rem; }
.ops { display: flex; flex-wrap: wrap; gap: 6px; }
.ops form { margin: 0; }
.clip { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { display: flex; flex-wrap: wrap; gap: 4px; margin: 14px 0; align-items: center; }
.pager a, .pager span.on { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; background: #fff; }
.pager span.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--primary); font-weight: 600; }

/* ---- 出荷 ---- */
.btn-ship { background: #e8590c; border-color: #e8590c; color: #fff; }
.btn-ship:hover { background: #cf4f0a; }
.btn-ship:disabled { background: #f3b48e; border-color: #f3b48e; opacity: 1; }
.list-head { margin: 4px 0 8px; }
.result-list li { position: relative; }
.result-list .r-item { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 8px; font-weight: 400; }
.result-list .r-top, .result-list .r-sub { display: block; }
.selectable .r-item { display: flex; gap: 12px; align-items: center; padding-right: 64px; cursor: pointer; margin: 0 0 8px; }
.selectable .r-item input { width: 24px; height: 24px; flex: none; accent-color: #e8590c; margin: 0; }
.selectable li:has(input:checked) .r-item { border-color: #e8590c; background: #fff4ec; }
.r-edit { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: .82rem;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; text-decoration: none; }
.ship-bar { position: sticky; bottom: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(243,245,248,0), var(--bg) 30%); margin-top: 8px; }
.ship-bar .btn-big { margin: 0; box-shadow: 0 4px 14px rgba(0,0,0,.15); }
.ship-summary dl { display: grid; grid-template-columns: 6em 1fr; gap: 6px 10px; margin: 0; }
.ship-summary dt { color: var(--muted); }
.ship-summary dd { margin: 0; font-weight: 700; }

/* ---- 管理画面 追加 ---- */
label.check.inline { margin: 0; white-space: nowrap; }
.btn.toggle { color: var(--muted); }
.btn.toggle.on { color: var(--ok-ink); border-color: #9fd6ae; background: var(--ok-bg); }
.qr-cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid2 .span2 { grid-column: 1 / -1; }
details summary { cursor: pointer; color: var(--primary); }

/* ---- 管理画面：左サイドバー ---- */
body.with-side { display: flex; min-height: 100vh; }
.sidebar { width: 200px; flex: none; background: var(--admin-bar); color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: block; padding: 16px 18px; font-size: 1.05rem; border-bottom: 1px solid rgba(255,255,255,.12); }
.sidenav { display: flex; flex-direction: column; padding: 8px 0; flex: 1; }
.sidenav a { color: #dcd6ec; text-decoration: none; padding: 10px 18px; border-left: 3px solid transparent; font-size: .95rem; }
.sidenav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidenav a.on { background: rgba(255,255,255,.14); color: #fff; border-left-color: #fff; font-weight: 700; }
.side-user { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: .85rem; display: flex; justify-content: space-between; gap: 8px; }
.side-user a { color: #dcd6ec; }
body.with-side > main { flex: 1; min-width: 0; margin: 0; max-width: none; padding: 12px 24px 48px; }
@media (max-width: 760px) {
  body.with-side { display: block; }
  .sidebar { width: auto; height: auto; position: static; }
  .sidebar .brand { padding: 10px 16px; }
  .sidenav { flex-direction: row; flex-wrap: wrap; padding: 4px 8px; }
  .sidenav a { padding: 6px 10px; border-left: 0; border-bottom: 2px solid transparent; font-size: .88rem; }
  .sidenav a.on { border-bottom-color: #fff; background: none; }
  .side-user { padding: 6px 16px 10px; justify-content: flex-start; }
  body.with-side > main { padding: 12px 16px 48px; }
}

/* ---- 在庫の編集 ---- */
.table td.ops-cell { white-space: nowrap; }
.table td.ops-cell form { display: inline; margin: 0; }
.form-narrow { max-width: 520px; }
@media (max-width: 760px) {
  .filters > input, .filters > select, .filters > .row { width: 100%; }
  .filters > .row input { flex: 1; min-width: 0; width: auto; }
}

/* ---- 出荷履歴：チェックボックス ---- */
.table .chk-col { width: 1%; white-space: nowrap; }
.table td.chk-col input, .chk-all input { width: 18px; height: 18px; vertical-align: middle; accent-color: var(--danger); margin: 0; }
.chk-all { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 600; font-size: .82rem; color: var(--ink); cursor: pointer; }
.table tr.selected td { background: #fff1f1; }

/* ---- 読み取り専用の項目（登録者） ---- */
.field-static { margin: 0 0 14px; }
.field-static .field-label { display: block; font-weight: 600; font-size: .92rem; }
.field-static .field-value { display: block; margin-top: 4px; padding: 10px 12px; border-radius: 8px; background: #f1f4f7; border: 1px solid var(--line); }
.inline-field { margin: 0; font-size: .82rem; }
.inline-field input { margin-top: 2px; }

/* ---- スキャン画面 ---- */
.section-title { font-size: 1.15rem; margin: 24px 0 8px; padding-left: 10px; border-left: 4px solid var(--primary); }
.card h3 { font-size: .98rem; margin: 0 0 .6em; }
.reader[hidden] { display: none; }
[hidden] { display: none !important; }
