
  :root {
    --accent: #a8562b;
    --accent-deep: #7c3f1e;
    --accent-soft: #f1e0d1;
    --kombu: #33523f;
    --bg: #f6f3ee;
    --surface: #ffffff;
    --surface-raised: #fffdfa;
    --border: #e1d8c8;
    --border-strong: #cabb9f;
    --text: #2a251e;
    --text-muted: #746a5c;
    --text-faint: #a89c88;
    --danger: #a5402f;
    --danger-soft: #f6e2dd;
    --success: #3f6b4f;
    --focus: #a8562b;
    --shadow: 0 1px 2px rgba(42, 37, 30, 0.06), 0 4px 16px rgba(42, 37, 30, 0.06);
    --radius: 10px;
    --font-display: "Shippori Mincho", "Hiragino Mincho ProN", "Noto Serif CJK JP", "Noto Sans CJK JP", serif;
    --font-body: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Noto Sans CJK JP", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --accent: #e0965f;
      --accent-deep: #f0b285;
      --accent-soft: #3a2c22;
      --kombu: #7fae90;
      --bg: #201c17;
      --surface: #2a251e;
      --surface-raised: #322c23;
      --border: #43392c;
      --border-strong: #5a4d3a;
      --text: #f1ece2;
      --text-muted: #b9ac97;
      --text-faint: #7d715e;
      --danger: #e2897a;
      --danger-soft: #3c2620;
      --success: #8fc7a3;
      --focus: #e0965f;
      --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
    }
  }
  :root[data-theme="dark"] {
    --accent: #e0965f;
    --accent-deep: #f0b285;
    --accent-soft: #3a2c22;
    --kombu: #7fae90;
    --bg: #201c17;
    --surface: #2a251e;
    --surface-raised: #322c23;
    --border: #43392c;
    --border-strong: #5a4d3a;
    --text: #f1ece2;
    --text-muted: #b9ac97;
    --text-faint: #7d715e;
    --danger: #e2897a;
    --danger-soft: #3c2620;
    --success: #8fc7a3;
    --focus: #e0965f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 20px rgba(0, 0, 0, 0.35);
  }

  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }
  ::selection { background: var(--accent-soft); }
  a { color: var(--accent-deep); }
  button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
  button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
  }
  h1, h2, h3 { font-family: var(--font-display); font-weight: 700; text-wrap: balance; margin: 0; }

  /* ---------- app shell ---------- */
  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }
  .topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-shrink: 0;
  }
  .brand-mark {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-deep);
    white-space: nowrap;
  }
  .brand-sub {
    font-size: 11px;
    color: var(--text-faint);
    letter-spacing: 0.06em;
  }
  .topbar-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }
  .btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
    white-space: nowrap;
  }
  .btn:hover { background: var(--accent-soft); border-color: var(--accent); }
  .btn:active { transform: translateY(1px); }
  .btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
  }
  .btn-primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
  .btn-primary:disabled, .btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
  }
  .btn-ghost { border-color: transparent; background: transparent; }
  .btn-ghost:hover { background: var(--accent-soft); }
  .btn-danger { color: var(--danger); }
  .btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
  .btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
  input[type="file"] { display: none; }

  .main {
    flex: 1;
    display: grid;
    grid-template-columns: 300px 1fr;
    min-height: 0;
  }
  @media (max-width: 860px) {
    .main { grid-template-columns: 1fr; }
    .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  }

  /* ---------- sidebar / product list ---------- */
  .sidebar {
    border-right: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    min-height: 0;
  }
  .sidebar-head {
    padding: 16px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .search-input {
    width: 100%;
    padding: 8px 10px;
    border-radius: 7px;
    border: 1px solid var(--border-strong);
    background: var(--surface-raised);
    color: var(--text);
  }
  .product-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 10px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .product-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 9px 10px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
  }
  .product-item:hover { background: var(--accent-soft); }
  .product-item.active {
    background: var(--accent-soft);
    border-color: var(--accent);
  }
  .product-item .p-name { font-weight: 600; font-size: 13.5px; }
  .product-item .p-code {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 11.5px;
    color: var(--text-muted);
  }
  .empty-note {
    padding: 20px 16px;
    color: var(--text-faint);
    font-size: 12.5px;
    line-height: 1.7;
  }

  /* ---------- work area ---------- */
  .workarea { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
  .workarea-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-faint);
    font-size: 14px;
    text-align: center;
    padding: 40px;
  }
  .tabs {
    display: flex;
    gap: 4px;
    padding: 10px 24px 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .tab-btn {
    padding: 9px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
  }
  .tab-btn.active { color: var(--accent-deep); border-bottom-color: var(--accent); }
  .tab-panels { flex: 1; overflow-y: auto; padding: 22px 24px 60px; }
  .tab-panel { display: none; }
  .tab-panel.active { display: block; }

  /* ---------- edit form ---------- */
  .product-header-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
  }
  .product-header-row h2 { font-size: 22px; }
  .product-header-row .code-pill {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    padding: 3px 9px;
    border-radius: 999px;
  }
  .section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
  }
  .section-card h3 {
    font-size: 14.5px;
    color: var(--accent-deep);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .section-card h3::before {
    content: "";
    width: 4px;
    height: 14px;
    background: var(--accent);
    border-radius: 2px;
    display: inline-block;
  }
  .field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px 16px;
  }
  .field-grid.wide { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
  }
  .field.span-2 { grid-column: span 2; }
  .field.span-all { grid-column: 1 / -1; }
  .field label {
    font-size: 11.5px;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.01em;
  }
  .field-auto-hint {
    font-weight: 400;
    color: var(--text-faint);
    font-size: 10.5px;
    margin-left: 2px;
  }
  .field input, .field textarea, .field select {
    padding: 7px 9px;
    border-radius: 6px;
    border: 1px solid var(--border-strong);
    background: var(--surface-raised);
    color: var(--text);
    width: 100%;
  }
  .field textarea { resize: vertical; min-height: 46px; font-family: inherit; }
  .field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }

  /* ---------- gift-format repeaters: 詰合せ内容 / 単品明細 ---------- */
  .giftitem-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
  .giftitem-table td { padding: 4px 6px; }
  .giftitem-table input { width: 100%; padding: 6px 8px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface-raised); color: var(--text); }
  .giftitem-table td.col-qty { width: 110px; }
  .giftitem-table td.col-remove { width: 60px; }
  .subitem-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 14px;
    background: var(--surface-raised);
  }
  .subitem-card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
  .subitem-card-head .field { flex: 1 1 auto; }
  .subitem-card-head .subitem-badge {
    font-size: 11px; color: var(--text-muted); background: var(--surface);
    border: 1px solid var(--border); padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  }
  .subitem-card h4 { font-size: 12.5px; color: var(--text-muted); margin: 12px 0 8px; font-weight: 700; }

  .allergy-groups { display: flex; flex-direction: column; gap: 16px; }
  .allergy-group-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 8px;
  }
  .allergy-chips { display: flex; flex-wrap: wrap; gap: 8px; }
  .allergy-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--surface-raised);
    cursor: pointer;
    font-size: 12.5px;
    user-select: none;
  }
  .allergy-chip input { accent-color: var(--accent); }
  .allergy-chip.checked {
    background: var(--accent-soft);
    border-color: var(--accent);
    font-weight: 600;
    color: var(--accent-deep);
  }

  .ing-table-wrap { overflow-x: auto; }
  table.ing-table { border-collapse: collapse; width: 100%; min-width: 920px; }
  table.ing-table th {
    text-align: left;
    font-size: 11px;
    color: var(--text-muted);
    padding: 6px 8px;
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
  }
  table.ing-table td {
    padding: 4px 6px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
  }
  table.ing-table input {
    width: 100%;
    padding: 5px 7px;
    border-radius: 5px;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    font-size: 12.5px;
  }
  table.ing-table input:focus { border-color: var(--accent); }

  .photo-editor { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
  .photo-preview {
    width: 140px;
    height: 92px;
    border-radius: 8px;
    border: 1px dashed var(--border-strong);
    background: var(--surface-raised);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-faint);
    font-size: 11px;
    overflow: hidden;
    flex-shrink: 0;
  }
  .photo-preview img { width: 100%; height: 100%; object-fit: cover; }

  .hint { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; line-height: 1.6; }

  /* ---------- preview tab ---------- */
  .preview-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
  }
  .preview-scroll {
    overflow-x: auto;
    padding-bottom: 20px;
  }
  .sheet-stack {
    display: flex;
    flex-direction: column;
    gap: 28px;
    align-items: flex-start;
  }

  /* ---------- printed sheet: exact recreation of the original 商品規格書 form ---------- */
  .sheet {
    width: 210mm;
    min-height: 297mm;
    background: #ffffff;
    color: #111111;
    box-shadow: var(--shadow);
    padding: 8mm 10mm;
    font-family: "Noto Sans JP", "Hiragino Sans", "Noto Sans CJK JP", sans-serif;
    font-size: 8.4px;
    line-height: 1.32;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
  }
  .sheet * { box-sizing: border-box; }
  .sheet-body { flex: 1 0 auto; }
  .sheet-footer {
    margin-top: auto;
    padding-top: 4px;
    display: flex;
    justify-content: space-between;
    font-size: 8px;
    color: #111;
  }

  .sheet-header { position: relative; margin-bottom: 4px; min-height: 26px; }
  .sheet-title {
    font-family: "Noto Sans JP", "Hiragino Sans", "Noto Sans CJK JP", sans-serif;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5em;
    color: #111111;
    text-align: center;
    padding: 3px 0 7px;
  }
  .sheet-title-left {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: #111111;
    display: inline-block;
    vertical-align: middle;
    margin-right: 14px;
  }
  .p2-header { display: flex; align-items: center; padding: 4px 0 6px; }
  .p2-header table.spec { width: auto; flex: 0 0 auto; min-width: 240px; }
  .sheet-dates {
    position: absolute;
    top: 1px;
    right: 0;
    text-align: right;
    font-size: 8.4px;
    line-height: 1.7;
    white-space: nowrap;
  }

  .sheet-page-break { break-after: page; }

  /* ---- shared grid-table look: black borders, peach (#FFCC99) label cells ---- */
  /* font-size/color set explicitly (not just inherited) because <table> can fail to
     inherit them from ancestors in some rendering contexts (e.g. quirks mode). */
  table.spec {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    margin-top: -1px; /* fuse borders between stacked tables */
    font-size: inherit;
    color: inherit;
  }
  table.spec:first-child { margin-top: 0; }
  table.spec td {
    border: 1px solid #000000;
    padding: 2.5px 6px;
    vertical-align: middle;
    word-break: break-word;
  }
  table.spec tr { break-inside: avoid; }
  table.spec td.lbl { background: #ffcc99; font-weight: 700; text-align: center; }
  table.spec td.band { background: #ffcc99; font-weight: 700; text-align: center; }
  table.spec td.val { background: #ffffff; }
  table.spec td.val-c { background: #ffffff; text-align: center; font-variant-numeric: tabular-nums; }
  table.spec td.note { background: #ffffff; font-size: 7.2px; }
  table.spec td.diag {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='none'%3E%3Cline x1='0' y1='100' x2='100' y2='0' stroke='%23000000' stroke-width='1.3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: center;
  }
  table.spec td.box { background: #ffffff; padding: 0; vertical-align: top; }
  .box-head { background: #ffcc99; font-weight: 700; text-align: center; padding: 2.5px 4px; border-bottom: 1px solid #000; font-size: 7.8px; }
  .box-body { padding: 2.5px 5px; font-size: 7.4px; line-height: 1.4; }
  .circle {
    display: inline-block;
    border: 1.2px solid #000;
    border-radius: 50%;
    padding: 0 4px;
    line-height: 1.5;
  }

  td.sheet-photo { padding: 0; background: #fff; }
  .sheet-photo-inner { display: flex; flex-direction: column; height: 100%; }
  .sheet-photo-inner .box-head { flex: 0 0 auto; }
  .sheet-photo-img { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; padding: 4px; min-height: 32mm; overflow: hidden; }
  .sheet-photo-img img { width: 100%; height: 100%; object-fit: contain; }
  .sheet-photo-img.empty { color: #8a7d68; font-size: 7px; }
  .sheet-photo-img.dual { gap: 4px; }
  .sheet-photo-img.dual .photo-slot {
    flex: 1 1 50%; height: 100%; display: flex; flex-direction: column;
    align-items: center; justify-content: center; overflow: hidden; min-width: 0;
  }
  .sheet-photo-img.dual .photo-slot img { width: 100%; height: 100%; object-fit: contain; }
  .sheet-photo-img.dual .photo-slot .slot-label { font-size: 6.4px; color: #8a7d68; margin-top: 2px; }
  .sheet-photo-img.dual .photo-slot.empty { color: #8a7d68; font-size: 6.4px; text-align: center; }

  /* ---- gift format: 詰合せ内容 grid cells & text-based allergy box ---- */
  table.spec td.giftitem { background: #ffffff; text-align: center; font-size: 7.6px; }
  table.spec td.allergy-text-lbl { background: #ffcc99; font-weight: 700; text-align: center; }
  table.spec td.allergy-text-val { background: #ffffff; }

  /* ---- page 2: allergy matrix ---- */
  table.allergy2 { border-collapse: collapse; width: 100%; margin-top: 4px; table-layout: fixed; }
  table.allergy2 th, table.allergy2 td {
    border: 1px solid #000000;
    text-align: center;
    padding: 2px 1px;
    font-size: 7.6px;
  }
  /* 「たてがき」風の縦積み文字。headless Chromium ではCJK漢字が2文字以上連続すると
     writing-mode: vertical-rl で文字が重なって表示される既知の不具合があるため、
     真の縦書きは使わず1文字ずつ<br>で改行して積み上げる（vstack()ヘルパー参照）。
     全ブラウザで確実に表示できる。 */
  table.allergy2 th.rowlbl {
    background: #ffcc99;
    font-weight: 700;
    font-size: 7px;
    line-height: 1.4;
    width: 22px;
  }
  /* rowlbl のセルは thead 側で rowspan=2（グループ行＋項目行）のみとし、tbody のデータ行には
     境界線を消した同色の空セルを別途置いて縦につながって見えるようにする。rowspan を
     thead → tbody をまたいで張ると、headless Chromium の印刷（PDF化）レンダリングでは
     tbody側のセルが1列分ズレて描画される不具合があるため（画面表示・DOM上は正しく見えても
     印刷結果だけがズレる）、thead/tbody をまたぐ rowspan は使わないこと。 */
  table.allergy2 td.rowlbl-body { background: #ffcc99; border-top: none; }
  table.allergy2 thead tr.grp th { background: #ffcc99; font-weight: 700; font-size: 8px; }
  table.allergy2 thead tr.item th {
    background: #ffcc99;
    line-height: 1.32;
    height: 54px;
    font-weight: 500;
  }
  table.allergy2 td.mark { background: #ffffff; font-weight: 700; font-size: 9.5px; }

  /* ---- page 2: ingredient table ---- */
  table.ing2 { border-collapse: collapse; width: 100%; margin-top: 10px; table-layout: fixed; }
  table.ing2 th, table.ing2 td {
    border: 1px solid #000000;
    padding: 2px 5px;
    font-size: 8.6px;
    word-break: break-word;
  }
  table.ing2 thead th { background: #ffcc99; font-weight: 700; text-align: center; }
  table.ing2 tbody td { background: #ffffff; }
  table.ing2 tbody tr.grp-row td { font-weight: 700; }
  table.ing2 tbody tr.empty-row td { height: 15px; }

  /* ---------- import panel ---------- */
  .modal-backdrop {
    position: fixed; inset: 0; background: rgba(20, 16, 10, 0.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 100; padding: 20px;
  }
  .modal {
    background: var(--surface); border-radius: 12px; padding: 26px;
    max-width: 480px; width: 100%; box-shadow: var(--shadow);
    border: 1px solid var(--border);
  }
  .modal h3 { font-size: 16px; margin-bottom: 10px; }
  .modal p { font-size: 12.5px; color: var(--text-muted); line-height: 1.7; margin: 0 0 14px; }
  .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
  .toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: var(--text); color: var(--bg); padding: 10px 18px;
    border-radius: 8px; font-size: 12.5px; z-index: 200; box-shadow: var(--shadow);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .toast.show { opacity: 1; }

  @media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
  }

  /* ---------- print ---------- */
  @media print {
    @page { size: A4; margin: 0; }
    body { background: #fff; }
    .topbar, .sidebar, .tabs, .preview-toolbar, .modal-backdrop, .toast { display: none !important; }
    .tab-panels { padding: 0; overflow: visible; }
    .tab-panel { display: none !important; }
    .tab-panel.printing { display: block !important; }
    .preview-scroll { overflow: visible; padding: 0; }
    .sheet-stack { gap: 0; }
    .sheet {
      box-shadow: none;
      width: 210mm;
      min-height: 297mm;
      margin: 0;
      break-after: page;
    }
    .sheet:last-child { break-after: auto; }
  }
