/* ============================================================
   Slipform Web版 — スタイルシート
   デザインシステム: double-em / refiner 準拠
   ============================================================ */

/* ---- リセット ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ---- CSS変数 ---- */
:root {
  --slate:         #2F4F4F;
  --teal:          #A2C4C9;
  --primary:       #347883;
  --bg:            #f7f9f9;
  --muted:         #6b8a8a;
  --border:        #d0dede;
  --white:         #ffffff;
  --text:          #2F4F4F;

  /* 既存コードが使うエイリアス */
  --accent:        #2F4F4F;
  --accent-hover:  #1a3333;
  --accent2:       #eef4f4;
  --doc-accent:    #2F4F4F;
  --danger:        #dc2626;
  --radius:        2px;
  --shadow:        0 2px 12px rgba(0,0,0,.08);
}

/* ---- ベース ---- */
body {
  font-family: 'BIZ UDPGothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ============================================================
   サイトヘッダー（refiner 完全準拠）
   ============================================================ */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 56px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid #e8eded;
  display: flex;
  align-items: center;
}
.site-header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.site-header-logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--slate);
  flex-shrink: 0;
}
.site-header-logo svg {
  width: 22px;
  height: 22px;
}
.site-header-logo span {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.site-header-sep {
  color: #c0d0d0;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.site-header-title {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--slate);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.site-header-desc {
  font-size: 0.75rem;
  color: #8a9e9e;
  white-space: nowrap;
}
@media (max-width: 580px) {
  .site-header-desc { display: none; }
}

/* ヘッダー内ナビタブ */
.site-header-nav {
  display: flex;
  align-items: center;
  gap: 0;
  margin-left: auto;
}
.nav-tab {
  font-family: 'Quicksand', sans-serif;
  font-weight: 500;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0 1rem;
  height: 56px;
  display: flex;
  align-items: center;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.18s;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--slate); }
.nav-tab.active {
  color: var(--slate);
  border-bottom-color: var(--slate);
  font-weight: 700;
}

.issuer-tab {
  color: var(--muted);
  transition: all 0.15s;
}
.issuer-tab:hover { color: var(--slate); }
.issuer-tab.active {
  color: var(--slate);
  border-bottom-color: var(--slate) !important;
}

.master-preview { pointer-events: none; user-select: none; filter: blur(1.2px); opacity: 0.65; }
.premium-section { background: #fff8e1 !important; border: 1.5px solid #ffc107 !important; }
.premium-section .card-head { background: transparent !important; color: #7a5800 !important; border-bottom: none !important; padding-bottom: 0 !important; }
.premium-section .settings-body { padding-top: 4px !important; }
.premium-section .settings-hint { color: #7a5800 !important; }
.premium-section .premium-feature-list li { background: rgba(255,255,255,0.6); }
.premium-feature-list { list-style: none; padding: 0; margin: 0 0 4px; display: flex; flex-direction: column; gap: 10px; }
.premium-feature-list li { padding: 10px 12px; background: #f7f9fa; border-radius: 2px; display: flex; flex-direction: column; gap: 3px; }
.premium-feature-list strong { font-size: 13px; color: var(--text); font-weight: 700; }
.premium-feature-list span { font-size: 12px; color: var(--muted); line-height: 1.6; }
.master-preview-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(255,255,255,0.45) 0%, rgba(255,255,255,0.75) 50%, rgba(255,255,255,0.45) 100%);
  backdrop-filter: blur(1px);
}

/* PC/SPモード切替ボタン */
.mode-toggle-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-family: 'Quicksand', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  flex-shrink: 0;
}
.mode-toggle-btn:hover {
  border-color: var(--slate);
  color: var(--slate);
}

/* noteバッジ（右上常設） */
.note-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--slate);
  color: #fff;
  font-family: 'Quicksand', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-decoration: none;
  border-radius: var(--radius);
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.18s;
}
.note-badge:hover { opacity: 0.75; }

/* サイトフッター（refiner 準拠） */
.site-footer {
  border-top: 1px solid #e0e8e8;
  background: #fff;
  padding: 0.8rem 0;
  margin-top: 40px;
}
.site-footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.5rem;
}
.site-footer-links {
  display: flex;
  gap: 1.2rem;
  flex-wrap: wrap;
  align-items: center;
}
.site-footer-links a {
  font-size: 0.7rem;
  color: #8a9e9e;
  text-decoration: none;
}
.site-footer-links a:hover { color: #2F4F4F; }
.site-footer-links small {
  font-size: 0.7rem;
  color: #8a9e9e;
  margin-left: auto;
}
@media (max-width: 640px) {
  .site-footer-links { justify-content: center; }
  .site-footer-links small { margin-left: 0; width: 100%; text-align: center; margin-top: 0.3rem; }
}

/* ハンバーガーボタン（SP用） */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  cursor: pointer;
  border: none;
  background: none;
  flex-shrink: 0;
}
.nav-hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--slate);
  border-radius: 2px;
  transition: all 0.25s;
}
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ドロワー（SP用） */
.nav-drawer {
  display: none;
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  background: var(--slate);
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  z-index: 99;
  flex-direction: column;
  padding: 8px 0;
}
.nav-drawer.open { display: flex; }
.nav-drawer-item {
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.nav-drawer-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-drawer-item.active {
  color: #fff;
  border-left: 3px solid #fff;
  padding-left: 17px;
}
.nav-drawer-divider {
  height: 1px;
  background: rgba(255,255,255,.15);
  margin: 6px 0;
}

/* SP時：ハンバーガー表示・タブ非表示 */
@media (max-width: 560px) {
  .nav-hamburger { display: flex; }
  .site-header-nav { display: none; }
  .mode-toggle-btn { display: none; }
  .note-badge { margin-left: auto; }
  .promo-banner { flex-direction: column; align-items: flex-start; gap: 6px; }
  .promo-banner p { flex: 0 1 auto; }
}

/* ============================================================
   ページレイアウト
   ============================================================ */
/* ヘッダー高さ分のオフセット */
#page-doc,
#page-settings,
#page-help-sp {
  margin-top: 56px;
}

.app-wrapper {
  display: flex;
  gap: 24px;
  padding: 24px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: flex-start;
}
.panel-left  { flex: 1 1 480px; min-width: 0; }
.panel-right { flex: 1 1 460px; min-width: 0; position: sticky; top: 72px; }

/* ============================================================
   カード
   ============================================================ */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  background: var(--slate);
  color: var(--white);
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 13px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  letter-spacing: 0.05em;
}
.card-head.collapsible { cursor: pointer; user-select: none; }
.card-head.collapsible::after { content: "▲"; font-size: 10px; opacity: .7; transition: transform .2s; }
.card-head.collapsible.collapsed::after { content: "▼"; }
.card-body { padding: 16px; }
.card-body.collapsed { display: none; }

/* ============================================================
   フォーム要素
   ============================================================ */
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  letter-spacing: 0.04em;
}
input[type="text"],
input[type="date"],
input[type="number"],
input[type="email"],
input[type="tel"],
select,
textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color .2s;
  outline: none;
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--slate);
  box-shadow: 0 0 0 3px rgba(47,79,79,.12);
}
textarea { resize: vertical; min-height: 72px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-col { display: flex; flex-direction: column; }
.form-col.full { grid-column: 1 / -1; }

/* ============================================================
   書類タブ（見積書／請求書／領収書）
   ============================================================ */
.doc-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
}
.doc-tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--bg);
  color: var(--muted);
  transition: all .2s;
  letter-spacing: 0.05em;
}
.doc-tab.active {
  background: var(--slate);
  color: var(--white);
  border-color: var(--slate);
}
.doc-tab:hover:not(.active) {
  border-color: var(--slate);
  color: var(--slate);
}

/* ============================================================
   購入誘導バナー
   ============================================================ */
.promo-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff8e1;
  border: 1.5px solid #ffc107;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
}
.promo-banner p { font-size: 12px; color: #7a5800; flex: 1; }
.promo-banner a {
  font-size: 12px;
  font-weight: 700;
  color: var(--slate);
  white-space: nowrap;
  text-decoration: none;
}
.promo-banner a:hover { opacity: 0.75; }

/* ============================================================
   ボタン（refiner 準拠）
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-family: 'Quicksand', sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all .18s;
  letter-spacing: 0.04em;
}
.btn:hover { opacity: 0.6; }
.btn:active { transform: translateY(2px); }

.btn-primary {
  background: var(--slate);
  color: var(--white);
  border: 1px solid var(--slate);
}
.btn-secondary {
  background: transparent;
  color: var(--slate);
  border: 1px solid var(--slate);
}
.btn-danger {
  background: var(--danger);
  color: var(--white);
  border: 1px solid var(--danger);
}
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

/* ============================================================
   明細テーブル
   ============================================================ */
.items-table { width: 100%; border-collapse: collapse; }
.items-table th {
  background: var(--accent2);
  color: var(--slate);
  font-weight: 700;
  font-size: 11px;
  padding: 6px 8px;
  text-align: left;
  border-bottom: 2px solid var(--slate);
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.items-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: top; }
.items-table td input,
.items-table td select { padding: 5px 6px; font-size: 13px; }

.col-cat  { width: 110px; }
.col-item { width: 160px; }
.col-qty  { width: 56px; }
.col-unit { width: 52px; }
.col-price{ width: 90px; }
.col-tax  { width: 64px; }
.col-del  { width: 36px; text-align: center; }

.custom-name-input { margin-top: 3px; font-size: 12px; padding: 3px 6px !important; }

.btn-del {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.btn-del:hover { transform: scale(1.2); }

.add-row-btn {
  text-align: center;
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  margin-top: 6px;
  cursor: pointer;
  transition: all .18s;
  user-select: none;
}
.add-row-btn:hover { border-color: var(--slate); color: var(--slate); }

/* ============================================================
   プレビューエリア
   ============================================================ */
/* ローディング */
#loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
  font-weight: 700;
  color: var(--slate);
  font-size: 15px;
  background: var(--bg);
  margin-top: 56px;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--accent2);
  border-top-color: var(--slate);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* プレビューコンテナ */
#preview-wrap {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.preview-toolbar {
  background: var(--slate);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 8px 16px;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 13px;
}
.preview-a4-outer { padding: 20px; background: #888; overflow: hidden; }
.preview-a4-scaler { transform-origin: top left; display: block; }
#preview-doc {
  width: 210mm;
  min-height: 297mm;
  padding: 20mm;
  background: var(--white);
  box-shadow: 0 2px 16px rgba(0,0,0,.15);
  font-family: 'BIZ UDPGothic', 'Noto Sans JP', sans-serif;
  font-size: 13px;
  line-height: 1.8;
}

/* ============================================================
   帳票プレビュー内部スタイル
   ============================================================ */
.pv-header    { display: flex; justify-content: space-between; align-items: flex-end; }
.pv-left      { flex: 1; }
.pv-right     { flex: 0 0 auto; font-size: 12px; line-height: 1.9; word-break: break-all; padding-left: 24px; min-width: 0; margin-bottom: 35px; }
.pv-issue-date { text-align: right; font-size: 11px; color: #666; margin-bottom: 8px; }
.pv-doc-num    { font-size: 11px; color: #666; margin-top: 2px; }
.pv-title     { clear: both; font-size: 26px; font-weight: 700; letter-spacing: .12em; text-align: center; margin-top: 16px; margin-bottom: 20px; }
.pv-from      { position: relative; }
.pv-to        { font-size: 17px; font-weight: 700; margin-bottom: 20px; padding-bottom: 8px; }
.pv-to-inner  { display: block; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-right: 20px; }
.pv-intro     { font-size: 13px; margin-bottom: 12px; }
.pv-meta-block{ font-size: 12px; margin-bottom: 20px; padding-bottom: 14px; }
.pv-meta-block td { padding: 2px 24px 2px 0; vertical-align: top; }
.pv-meta-block td:first-child { color: var(--muted); white-space: nowrap; }
.pv-subject { font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.pv-subject span { color: var(--text); font-weight: 700; }
.pv-amount-block {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 20px;
  margin-top: -12px;
  padding: 12px 0;
  border-bottom: 2px solid var(--text);
}
.pv-amount-label { font-size: 13px; font-weight: 700; }
.pv-amount-value { font-size: 28px; font-weight: 700; letter-spacing: .04em; }
.pv-table         { width: 100%; border-collapse: collapse; margin-bottom: 20px; font-size: 12px; }
.pv-table th      { padding: 7px 10px; text-align: left; font-weight: 700; font-size: 11px; color: #fff; }
.pv-table td      { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.pv-table tr:nth-child(even) td { background: var(--accent2); }
.pv-table .text-right { text-align: right; }
.pv-total-area  { display: flex; justify-content: flex-end; margin-bottom: 24px; }
.pv-total-table { width: 260px; font-size: 12px; }
.pv-total-table td { padding: 5px 10px; border-bottom: 1px solid var(--border); }
.pv-total-table .total-row { font-size: 15px; font-weight: 700; color: #fff; }
.pv-total-table .text-right { text-align: right; }
.pv-stamp { width: 100px; position: absolute; top: 60px; left: 63px; opacity: 1; z-index: 0; }
.pv-logo  { max-width: 160px; max-height: 60px; object-fit: contain; margin-bottom: 6px; display: block; }
.pv-from > div { position: relative; z-index: 1; }
.pv-note  {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 12px;
  white-space: pre-wrap;
}

/* カラースウォッチ */
.doc-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid rgba(255,255,255,.4);
  cursor: pointer;
  transition: transform .15s;
  flex-shrink: 0;
}
.doc-swatch:hover    { transform: scale(1.2); border-color: rgba(255,255,255,.9); }
.doc-swatch.selected { border-color: #fff; transform: scale(1.15); box-shadow: 0 0 0 1px rgba(0,0,0,.3); }

/* ============================================================
   設定ページ
   ============================================================ */
#page-settings {
  padding: 24px;
  max-width: 860px;
  margin: 56px auto 0;
}
#page-settings.pc-in-panel {
  padding: 0;
  max-width: none;
  margin: 0;
  width: 100%;
}
.settings-section {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.settings-section .card-head { cursor: default; }
.settings-body { padding: 20px; }

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all .18s;
  position: relative;
  overflow: hidden;
}
.upload-area:hover { border-color: var(--slate); background: var(--accent2); }
.upload-area input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.upload-area .upload-label { font-size: 13px; color: var(--muted); pointer-events: none; }

.upload-preview { max-width: 200px; max-height: 80px; object-fit: contain; margin-top: 8px; border-radius: 2px; border: 1px solid var(--border); }
.settings-hint  { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* プリセットリスト */
.preset-list    { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.preset-item    { display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: var(--radius); padding: 8px 12px; border: 1px solid var(--border); }
.preset-item-name { flex: 1; font-size: 13px; }
.preset-add-form  { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 8px; align-items: end; }

/* トースト */
.save-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--slate);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 999;
}
.save-toast.show { opacity: 1; }

/* ============================================================
   品目マスター
   ============================================================ */
.master-cat-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.master-cat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--accent2);
  border-bottom: 1px solid var(--border);
}
.master-cat-name {
  font-weight: 700;
  font-size: 13px;
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 2px 4px;
  border-radius: var(--radius);
}
.master-cat-name:focus { background: var(--white); box-shadow: 0 0 0 2px var(--slate); }

.master-items-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.master-items-table th {
  background: var(--accent2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  padding: 5px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.master-items-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.master-items-table td input,
.master-items-table td select { padding: 4px 6px; font-size: 13px; border-radius: var(--radius); }
.master-items-table td input[type=number] { text-align: right; }

.master-add-item {
  text-align: center;
  padding: 6px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px dashed var(--border);
  cursor: pointer;
  transition: all .15s;
}
.master-add-item:hover { background: var(--accent2); color: var(--slate); }

.add-cat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  margin-top: 4px;
}
.add-cat-btn:hover { border-color: var(--slate); color: var(--slate); background: var(--accent2); }

/* ============================================================
   SPプレビューオーバーレイ
   ============================================================ */
#sp-preview-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
#sp-preview-overlay.open { display: flex; }
#sp-preview-inner {
  background: var(--white);
  border-radius: 4px;
  width: 100%;
  max-width: 600px;
  overflow: hidden;
}
.sp-preview-header {
  background: var(--slate);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 13px;
}

/* SPプレビューボタン（SPのみ表示） */
#preview-btn-sp {
  display: none;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  background: var(--accent2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-family: 'Quicksand', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--slate);
  margin-bottom: 12px;
  transition: all .18s;
}
#preview-btn-sp:hover { background: var(--slate); color: #fff; border-color: var(--slate); }

/* ============================================================
   SPアイテムカード
   ============================================================ */
#sp-items-list { display: none; }

.sp-item-card {
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
  overflow: hidden;
  transition: border-color .18s;
}
.sp-item-card.active { border-color: var(--slate); }

.sp-item-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
}
.sp-item-num {
  width: 22px;
  height: 22px;
  background: var(--accent2);
  color: var(--slate);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}
.sp-item-card.active .sp-item-num { background: var(--slate); color: #fff; }
.sp-item-label  { flex: 1; font-size: 13px; color: var(--text); font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-item-amount { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.sp-item-chevron{ font-size: 10px; color: var(--muted); transition: transform .2s; flex-shrink: 0; }
.sp-item-card.active .sp-item-chevron { transform: rotate(180deg); }

.sp-item-body { display: none; padding: 0 14px 14px; }
.sp-item-card.active .sp-item-body { display: block; }
.sp-item-body .form-col { margin-bottom: 10px; }

.sp-item-add-btn {
  width: 100%;
  padding: 12px;
  border: 2px dashed var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  transition: all .15s;
}
.sp-item-add-btn:hover { border-color: var(--slate); color: var(--slate); }

/* ============================================================
   ヘルプページ（SP用）
   ============================================================ */
#page-help-sp {
  padding: 16px;
  max-width: 600px;
  margin: 56px auto 0;
}

/* ============================================================
   レスポンシブ
   ============================================================ */
@media (max-width: 768px) {
  .app-wrapper { flex-direction: column; padding: 12px; }
  .panel-right { display: none; }
  .form-row { grid-template-columns: 1fr; }
  label { font-size: 13px; }
  input[type="text"], input[type="date"], input[type="number"],
  input[type="email"], input[type="tel"], select, textarea {
    font-size: 16px;
    padding: 10px 12px;
  }
  .btn { padding: 12px 18px; font-size: 14px; }
  .btn-sm { padding: 9px 14px; font-size: 13px; }
  .items-table { display: none; }
  #sp-items-list { display: block; }
  #add-row-trigger-pc { display: none; }
  #add-row-trigger-sp { display: block; }
  #preview-btn-sp { display: flex; }
}
@media (max-width: 1100px) {
  .app-wrapper { flex-direction: column; }
  .panel-right { position: static; width: 100%; }
}
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
  .panel-left, .panel-right { min-width: 0; }
}

/* ---- モバイルモード（JS強制） ---- */
body.mobile-mode .app-wrapper  { flex-direction: column; padding: 12px; }
body.mobile-mode .panel-right  { display: none; }
body.mobile-mode .form-row     { grid-template-columns: 1fr; }
body.mobile-mode label         { font-size: 13px; }
body.mobile-mode input[type="text"], body.mobile-mode input[type="date"],
body.mobile-mode input[type="number"], body.mobile-mode input[type="email"],
body.mobile-mode input[type="tel"], body.mobile-mode select, body.mobile-mode textarea {
  font-size: 16px; padding: 10px 12px;
}
body.mobile-mode .btn    { padding: 12px 18px; font-size: 14px; }
body.mobile-mode .btn-sm { padding: 9px 14px; font-size: 13px; }
body.mobile-mode .items-table          { display: none; }
body.mobile-mode #sp-items-list        { display: block; }
body.mobile-mode #add-row-trigger-pc   { display: none; }
body.mobile-mode #add-row-trigger-sp   { display: block; }
body.mobile-mode #preview-btn-sp       { display: flex; }

/* ---- PC強制モード（JS強制） ---- */
body.force-pc .app-wrapper  { flex-direction: row !important; padding: 24px !important; }
body.force-pc .panel-right  { display: block !important; }
body.force-pc .form-row     { grid-template-columns: 1fr 1fr !important; }
body.force-pc label         { font-size: 12px !important; }
body.force-pc input[type="text"], body.force-pc input[type="date"],
body.force-pc input[type="number"], body.force-pc input[type="email"],
body.force-pc input[type="tel"], body.force-pc select, body.force-pc textarea {
  font-size: 14px !important; padding: 7px 10px !important;
}
body.force-pc .btn    { padding: 9px 18px !important; font-size: 14px !important; }
body.force-pc .btn-sm { padding: 5px 12px !important; font-size: 12px !important; }
body.force-pc .items-table         { display: table !important; }
body.force-pc #sp-items-list       { display: none !important; }
body.force-pc #add-row-trigger-pc  { display: block !important; }
body.force-pc #add-row-trigger-sp  { display: none !important; }
body.force-pc #preview-btn-sp      { display: none !important; }

/* マスターテーブル SP */
@media (max-width: 768px) {
  .master-items-table thead { display: none; }
  .master-items-table tr {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .master-items-table tr:last-child { border-bottom: none; }
  .master-items-table td { padding: 0; border: none; display: flex; align-items: center; gap: 8px; }
  .master-items-table td:first-child { justify-content: flex-end; }
  .master-items-table td input, .master-items-table td select { font-size: 16px; padding: 8px 10px; }
  .master-items-table td::before { font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; min-width: 60px; }
  .master-items-table td:nth-child(2)::before { content: "品目名"; }
  .master-items-table td:nth-child(3)::before { content: "単価"; }
  .master-items-table td:nth-child(4)::before { content: "単位"; }
  .master-items-table td:nth-child(5)::before { content: "税区分"; }
}

/* ============================================================
   印刷スタイル
   ============================================================ */
@media print {
  body { background: white !important; }
  .site-header, .panel-left, .preview-toolbar { display: none !important; }
  .app-wrapper   { padding: 0 !important; display: block !important; }
  .panel-right   { display: block !important; }
  #preview-wrap  { box-shadow: none !important; border-radius: 0 !important; }
  .preview-a4-outer {
    padding: 0 !important;
    background: none !important;
    height: auto !important;
  }
  .preview-a4-scaler {
    transform: none !important;
    width: auto !important;
    height: auto !important;
  }
  #preview-doc {
    width: auto !important;
    min-height: 0 !important;
    padding: 15mm !important;
    box-shadow: none !important;
    background: white !important;
  }
}
