:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --line: #d9dee5;
  --text: #1f2933;
  --muted: #66727f;
  --accent: #2f6db5;
  --accent-light: #e6effa;
  --danger: #c8372d;
  --ok: #2e8b57;
  --warn: #b7791f;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: bold; }
button.primary:hover:not(:disabled) { filter: brightness(1.1); }
button.danger { color: var(--danger); }
input[type=text], input[type=search], input[type=number], input[type=date], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  background: #fff;
  min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-light); border-color: var(--accent); }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 6px 0; }
.warn { color: var(--warn); font-size: 12.5px; margin: 6px 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 8px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; min-width: 0; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.field.inline input { width: 80px; }
.check { display: flex; align-items: center; gap: 6px; margin: 6px 0 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; flex: none; }

/* ---------- ヘッダー ---------- */
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top));
}
.top h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.top h1 small { font-size: 11px; color: var(--muted); font-weight: normal; }
.top .spacer { flex: 1; }
.alert-btn { background: #fff4e0; border-color: #f0c070; color: #8a4b00; }
.alert-btn b { background: #e07b1f; color: #fff; border-radius: 10px; padding: 0 7px; margin-left: 4px; }
.sync-badge { color: var(--muted); }
.sync-badge.ok { color: var(--ok); }
.sync-badge.err { color: var(--danger); }
.sync-badge.busy { color: var(--accent); }

/* ---------- 3列 ---------- */
.layout { flex: 1; display: grid; grid-template-columns: minmax(270px, 330px) minmax(360px, 1fr) minmax(380px, 1fr); min-height: 0; }
.pane { background: var(--panel); border-right: 1px solid var(--line); overflow: auto; padding: 12px 14px; min-height: 0; }
.pane:last-child { border-right: 0; background: #f7f8fa; }

/* 一覧 */
.list-pane { display: flex; flex-direction: column; padding: 0; }
.list-tools { padding: 12px 12px 6px; border-bottom: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 2px; }
.chips button { padding: 3px 9px; border-radius: 14px; font-size: 12.5px; }
.chips button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.item-list { list-style: none; margin: 0; padding: 4px 0; flex: 1; overflow: auto; }
.item-list li {
  display: grid; grid-template-columns: 26px 30px 1fr auto; align-items: center; gap: 4px;
  padding: 7px 10px; border-bottom: 1px solid #f0f2f5; cursor: pointer;
}
.item-list li:hover { background: #f7f9fc; }
.item-list li.sel { background: var(--accent-light); }
.item-list .pick { width: 18px; height: 18px; margin: 0 auto; }
.item-list .ic { font-size: 20px; text-align: center; font-family: "Segoe UI Emoji", "Apple Color Emoji", sans-serif; }
.item-list .tx { min-width: 0; }
.item-list .nm { font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-list .nm .no { color: var(--muted); font-weight: normal; font-size: 12px; margin-left: 4px; }
.item-list .sb { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-list .sb mark { background: #fff2a8; }
.item-list .qty { display: flex; align-items: center; gap: 2px; }
.item-list .qty input { width: 46px; padding: 4px; text-align: right; }
.item-list .qty button { padding: 3px 6px; font-size: 12px; }
.item-list .qty button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.badge { display: inline-block; font-size: 11px; border-radius: 9px; padding: 0 6px; margin-left: 4px; }
.badge.near { background: #fff1d6; color: #8a4b00; }
.badge.over { background: #fde2e0; color: var(--danger); }
.item-list li.empty-list { display: block; color: var(--muted); padding: 28px 16px; text-align: center; line-height: 1.9; cursor: default; font-size: 14px; }
.item-list li.empty-list:hover { background: none; }
.item-list .ic img.thumb { width: 30px; height: 30px; object-fit: cover; border-radius: 5px; display: block; margin: 0 auto; }

/* 写真 */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }
.photo-grid:empty { display: none; }
.photo-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; display: block; background: #f3f4f6; }
.photo-grid .busy { display: flex; align-items: center; justify-content: center; aspect-ratio: 1; border: 1px dashed var(--line); border-radius: 6px; color: var(--muted); font-size: 12px; }
.btn-like { display: inline-block; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn-like:hover { border-color: var(--accent); }
.photo-dialog img { display: block; max-width: 100%; max-height: 68vh; max-height: 68dvh; margin: 0 auto 6px; border-radius: 8px; }
.viewer-photos { display: grid; gap: 8px; margin: 0 0 14px; }
.viewer-photos img { width: 100%; border-radius: 10px; display: block; }
.list-foot { border-top: 1px solid var(--line); padding: 6px 12px; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; }
.list-foot .check { margin: 0; }

/* 編集 */
.one-preview { display: flex; flex-direction: column; align-items: center; padding: 6px 0 12px; border-bottom: 1px dashed var(--line); margin-bottom: 12px; }
.one-preview canvas { max-width: 100%; height: auto; background: transparent; }
.empty-editor { color: var(--muted); text-align: center; padding: 30px 10px; }
.icons { display: flex; flex-wrap: wrap; gap: 3px; max-height: 92px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.icons button { width: 34px; height: 32px; padding: 0; font-size: 18px; font-family: "Segoe UI Emoji", "Apple Color Emoji", sans-serif; }
.icons button.on { background: var(--accent-light); border-color: var(--accent); }
.colors { display: flex; flex-wrap: wrap; gap: 6px; }
.colors button { width: 30px; height: 30px; border-radius: 50%; padding: 0; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); }
.colors button.on { box-shadow: 0 0 0 2px var(--text); }
.colors button.none { background: linear-gradient(135deg, #fff 45%, #c8372d 47%, #c8372d 53%, #fff 55%); }

/* 印刷 */
.sheet-head { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0; }
.sheet-head button { padding: 3px 12px; }
.sheet-wrap { display: flex; justify-content: center; }
.sheet-wrap canvas { width: 100%; max-width: 430px; height: auto; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15); background: #fff; cursor: pointer; }
.adjust { margin: 10px 0; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.adjust summary { cursor: pointer; color: var(--muted); }
.adjust[open] summary { margin-bottom: 8px; }
.custom { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 10px 10px 0; margin-bottom: 10px; }
.print-bar { position: sticky; bottom: -12px; background: #f7f8fa; padding: 10px 0; display: flex; gap: 8px; align-items: center; justify-content: flex-end; border-top: 1px solid var(--line); margin-top: 10px; flex-wrap: wrap; }
.print-bar #printInfo { margin-right: auto; color: var(--muted); font-size: 12.5px; }
.print-bar .primary { padding: 9px 26px; font-size: 15px; }

/* ---------- モーダル ---------- */
.modal { position: fixed; inset: 0; background: rgba(20, 28, 38, 0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.dialog {
  position: relative; background: #fff; border-radius: 12px; padding: 18px 20px; width: min(520px, 100%);
  max-height: 92vh; max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
/* 右上の「✕」：画面をスクロールしても上に残る */
.dialog-x {
  position: sticky; top: -8px; float: right; z-index: 3; margin: -8px -10px 0 8px;
  width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 18px; line-height: 1; background: #fff; color: var(--muted);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
body.modal-open { overflow: hidden; }
.dialog.wide { width: min(760px, 100%); }
.dialog h2 { font-size: 18px; margin: 0 0 12px; }
.dialog h3 { font-size: 15px; margin: 0 0 8px; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; }
.kind-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.kind-grid button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; text-align: left; white-space: normal; }
.kind-grid .ki { font-size: 24px; font-family: "Segoe UI Emoji", "Apple Color Emoji", sans-serif; }
.kind-grid .kn { font-weight: bold; }
.kind-grid .kh { font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.exp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.exp-table th, .exp-table td { border-bottom: 1px solid #eef0f3; padding: 6px 4px; text-align: left; }
.exp-table tr { cursor: pointer; }
.exp-table tr:hover td { background: #f7f9fc; }
.exp-table .over { color: var(--danger); font-weight: bold; }
.exp-table td.nw { white-space: nowrap; }
.exp-table .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.exp-table .near { color: #b25b00; font-weight: bold; }
.sync-on { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.sync-on canvas { border: 1px solid var(--line); border-radius: 6px; width: 160px; height: 160px; }
.sync-on > div { flex: 1; min-width: 240px; }
.code { font-family: Consolas, "Courier New", monospace; font-size: 16px; letter-spacing: 1px; }
.sync-state { font-size: 13px; }
#syncInput { max-width: 300px; font-family: Consolas, monospace; letter-spacing: 1px; }
.help { line-height: 1.9; padding-left: 20px; }

/* ---------- QRコードから開いたとき ---------- */
.viewer { position: fixed; inset: 0; background: #f2f5f9; z-index: 80; overflow: auto; padding: 18px 14px; }
.viewer-card { background: #fff; border-radius: 14px; max-width: 560px; margin: 0 auto; padding: 22px 20px; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1); }
.viewer-kind { color: var(--muted); margin: 0; font-size: 13px; }
.viewer-card h2 { font-size: 26px; margin: 4px 0; font-family: "Zen Maru Gothic", "BIZ UDPGothic", sans-serif; }
.viewer-sub { color: var(--muted); margin: 0 0 12px; }
.viewer-list { font-size: 19px; line-height: 1.8; padding-left: 22px; margin: 10px 0 16px; }
.viewer-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 12px; }
.viewer-meta dt { color: var(--muted); }
.viewer-meta dd { margin: 0; font-weight: bold; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: #26303b; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s; z-index: 100; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.mobile-tabs { display: none; }
.print-area { display: none; }

/* ---------- スマホ ---------- */
@media (max-width: 900px) {
  body { font-size: 15px; }
  .top { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .top h1 { font-size: 16px; }
  #helpBtn { display: none; }
  .layout { display: block; overflow: hidden; }
  .pane { display: none; height: 100%; border-right: 0; padding-bottom: 80px; }
  .pane.show { display: block; }
  .list-pane.show { display: flex; }
  .grid2 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: 1fr 1fr; }
  input, select, textarea { font-size: 16px !important; }
  .mobile-tabs {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom); z-index: 40;
  }
  .mobile-tabs button { flex: 1; border: 0; border-radius: 0; padding: 12px 0; font-size: 15px; background: #fff; }
  .mobile-tabs button.on { color: var(--accent); font-weight: bold; box-shadow: inset 0 3px 0 var(--accent); }
  .print-bar { position: static; margin-bottom: 8px; }
  .hint { font-size: 13.5px; }
  /* 一覧：枚数の欄は名前の下の段に */
  .item-list li { grid-template-columns: 30px 34px 1fr; row-gap: 4px; padding: 9px 10px; }
  .item-list .qty { grid-column: 3; justify-self: start; }
  .item-list .qty input { width: 56px; }
  .item-list .nm { white-space: normal; overflow: visible; }
  .top .alert-btn, .top .sync-badge { font-size: 13px; padding: 6px 9px; }
}

/* ---------- 印刷 ---------- */
@media print {
  body { background: #fff; display: block; }
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; }
  .print-area img { display: block; page-break-after: always; break-after: page; }
  .print-area img:last-child { page-break-after: auto; break-after: auto; }
}
