/* =====================================================
   contract-form.css — 賃貸借契約書 入力・プレビュー
   ===================================================== */

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

:root {
  --primary   : #1a3a6b;
  --accent    : #e6702a;
  --bg-page   : #f0f2f5;
  --bg-form   : #ffffff;
  --bg-doc    : #ffffff;
  --border    : #c8cdd6;
  --border-lt : #dde2ea;
  --text-main : #1e2533;
  --text-sub  : #5a6478;
  --text-lbl  : #3a4560;
  --flash-bg  : rgba(255, 245, 120, 0.82);
  --topbar-h  : 56px;
  --form-w    : 360px;
  --doc-w     : 740px;
  --radius    : 8px;
  --shadow    : 0 2px 12px rgba(0,0,0,0.10);
}

html {
  height: 100%;
}

body {
  height: 100%;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-page);
  /* overflow: hidden は削除 — ページ全体が隠れてしまうため */
}

/* =====================================================
   トップバー
   ===================================================== */
#cf-topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--primary);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.cf-back-btn {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  transition: background 0.18s;
  white-space: nowrap;
  flex-shrink: 0;
}
.cf-back-btn:hover { background: rgba(255,255,255,0.12); }

.cf-topbar-title {
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.cf-topbar-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

/* =====================================================
   ボタン
   ===================================================== */
.cf-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: opacity 0.18s, transform 0.1s;
  font-family: 'Noto Sans JP', sans-serif;
  white-space: nowrap;
}
.cf-btn:hover   { opacity: 0.87; }
.cf-btn:active  { transform: scale(0.97); }

.cf-btn-primary {
  background: var(--primary);
  color: #fff;
}
.cf-btn-outline {
  background: rgba(255,255,255,0.12);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.4);
}
.cf-btn-print {
  background: var(--accent);
  color: #fff;
}
.cf-btn-block {
  width: 100%;
  justify-content: center;
  padding: 11px;
  font-size: 14px;
}

/* =====================================================
   2カラムレイアウト（固定高さ・スクロール内包）
   ===================================================== */
#cf-layout {
  display: flex;
  position: fixed;           /* 画面全体をピン留め */
  top: var(--topbar-h);
  left: 0; right: 0; bottom: 0;
}

/* ---- 左フォームパネル ---- */
#cf-form-panel {
  width: var(--form-w);
  min-width: 300px;
  background: var(--bg-form);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;          /* 内側の .cf-form-body がスクロール */
  flex-shrink: 0;
}

.cf-panel-header {
  padding: 13px 16px;
  background: #f7f9fc;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-lbl);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.cf-panel-sub {
  font-weight: 400;
  font-size: 11px;
  color: var(--text-sub);
  margin-left: 4px;
}

.cf-form-body {
  flex: 1;
  overflow-y: auto;          /* ← ここだけスクロール */
  overflow-x: hidden;
  padding: 16px 14px 20px;
}
.cf-form-body::-webkit-scrollbar { width: 5px; }
.cf-form-body::-webkit-scrollbar-track { background: transparent; }
.cf-form-body::-webkit-scrollbar-thumb { background: #c5cad4; border-radius: 3px; }

/* ---- セクション ---- */
.cf-sec {
  margin-bottom: 18px;
  background: #f8fafd;
  border: 1px solid var(--border-lt);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
}
.cf-sec-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.cf-sec-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ---- フィールド行 ---- */
.cf-row {
  display: flex;
  gap: 8px;
  margin-bottom: 7px;
}
.cf-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.cf-field.cf-full { flex: 0 0 100%; width: 100%; }

.cf-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sub);
  display: flex;
  align-items: center;
  gap: 4px;
}
.req {
  font-size: 10px;
  background: #e53e3e;
  color: #fff;
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 700;
}

/* ---- 入力フィールド ---- */
.cf-input {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  font-family: 'Noto Sans JP', sans-serif;
  color: var(--text-main);
  background: #fff;
  transition: border-color 0.18s, box-shadow 0.18s;
  outline: none;
}
.cf-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(26,58,107,0.12);
}
.cf-textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.6;
}
input[type="number"].cf-input { text-align: right; }
input[type="date"].cf-input   { letter-spacing: 0.03em; }

/* ---- 保存エリア ---- */
.cf-save-area {
  margin-top: 8px;
  padding: 10px 0 2px;
  border-top: 1px solid var(--border-lt);
}

/* =====================================================
   右プレビューパネル
   ===================================================== */
#cf-preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;          /* 内側の .cf-preview-scroll がスクロール */
  background: var(--bg-page);
  min-width: 0;
}

.cf-preview-scroll {
  flex: 1;
  overflow-y: auto;          /* ← ここだけスクロール */
  overflow-x: hidden;
  padding: 24px 32px 40px;
}
.cf-preview-scroll::-webkit-scrollbar { width: 6px; }
.cf-preview-scroll::-webkit-scrollbar-track { background: transparent; }
.cf-preview-scroll::-webkit-scrollbar-thumb { background: #bbc2cf; border-radius: 3px; }

/* =====================================================
   契約書ドキュメント本体
   ===================================================== */
.cf-doc {
  max-width: var(--doc-w);
  margin: 0 auto;
  background: var(--bg-doc);
  padding: 48px 56px 56px;
  box-shadow: var(--shadow);
  border-radius: 4px;
  font-family: 'Noto Serif JP', 'Noto Sans JP', serif;
  font-size: 12.5px;
  line-height: 1.85;
  color: #1e2533;
}

/* ---- タイトル ---- */
.cf-doc-title {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.18em;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary);
  color: var(--primary);
}

/* ---- 前文 ---- */
.cf-doc-parties {
  font-size: 12.5px;
  line-height: 2;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: #f5f7fa;
  border-left: 4px solid var(--primary);
  border-radius: 0 4px 4px 0;
}

/* ---- 章見出し ---- */
.cf-chapter {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  background: #eef2f9;
  padding: 7px 12px;
  margin: 18px 0 6px;
  border-left: 4px solid var(--primary);
  letter-spacing: 0.05em;
}
.cf-chapter-sub {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin: 22px 0 8px;
  padding: 6px 10px;
  border-bottom: 2px solid var(--primary);
  letter-spacing: 0.05em;
}

/* =====================================================
   頭書テーブル
   ===================================================== */
.cf-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 4px;
}
.cf-tbl td {
  border: 1px solid #b0b8c8;
  padding: 6px 10px;
  vertical-align: middle;
  line-height: 1.65;
}
.cf-tbl .cf-lbl {
  background: #eef2f9;
  color: var(--text-lbl);
  font-weight: 700;
  white-space: nowrap;
  width: 100px;
  text-align: center;
  font-size: 11.5px;
  letter-spacing: 0.05em;
}
.cf-tbl .cf-lbl2 {
  background: #f3f5fa;
  color: var(--text-lbl);
  font-weight: 700;
  white-space: nowrap;
  width: 72px;
  text-align: center;
  font-size: 11px;
}
.cf-tbl .cf-lbl2-inline {
  white-space: nowrap;
  font-size: 11.5px;
}
.cf-tbl .cf-amt {
  text-align: right;
  font-family: 'Noto Sans JP', monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.cf-tbl .cf-total {
  background: #fff8f0;
  font-weight: 700;
  color: #b84500;
}
.cf-tbl .cf-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* =====================================================
   空白スパン（転記ターゲット）
   ===================================================== */
.cf-blank {
  display: inline-block;
  border-bottom: 1px solid #8899bb;
  min-width: 40px;
  padding: 0 2px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 12.5px;
  color: #1e2533;
  transition: background 0.3s;
  vertical-align: bottom;
  letter-spacing: 0.02em;
}
.cf-blank-lg  { min-width: 160px; }
.cf-inline-amt {
  display: inline-block;
  border-bottom: 1px solid #8899bb;
  min-width: 80px;
  text-align: right;
  font-weight: 600;
}

/* フラッシュアニメーション */
@keyframes pvFlash {
  0%   { background: var(--flash-bg); }
  100% { background: transparent; }
}
.cf-blank.flash,
span[id^="pv-"].flash {
  animation: pvFlash 0.6s ease forwards;
}

/* =====================================================
   条文
   ===================================================== */
.cf-article {
  margin-bottom: 12px;
}
.cf-art-title {
  font-weight: 700;
  font-size: 12.5px;
  color: var(--primary);
  margin-bottom: 3px;
}
.cf-art-body {
  font-size: 12px;
  line-height: 1.9;
  text-align: justify;
  padding-left: 4px;
}
.cf-list {
  margin: 4px 0 2px 20px;
  font-size: 12px;
  line-height: 1.85;
}

/* ---- 特約事項エリア ---- */
.cf-special-area {
  min-height: 72px;
  white-space: pre-wrap;
  border: 1px dashed #aab;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12px;
  background: #fafbfc;
  color: #333;
  line-height: 1.85;
}

/* =====================================================
   署名欄
   ===================================================== */
.cf-sign-section {
  margin-top: 32px;
  padding-top: 18px;
  border-top: 2px solid var(--primary);
}
.cf-sign-date {
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text-lbl);
}

.cf-sign-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.cf-sign-block {
  border: 1px solid #b0b8c8;
  border-radius: 4px;
  padding: 10px 12px 14px;
  background: #fafbfd;
}
.cf-sign-role {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 1px solid var(--border-lt);
  padding-bottom: 6px;
  margin-bottom: 8px;
  text-align: center;
  letter-spacing: 0.05em;
}
.cf-sign-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.75;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.cf-sign-lbl {
  color: var(--text-sub);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  width: 36px;
}
.cf-sign-name {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  border-bottom: 1px solid #8899bb;
  min-width: 80px;
  display: inline-block;
}
.cf-sign-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border: 2px solid #cc3333;
  border-radius: 50%;
  font-size: 14px;
  color: #cc3333;
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0.55;
}

/* =====================================================
   フッター
   ===================================================== */
.cf-doc-footer {
  text-align: center;
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 28px;
  padding-top: 14px;
  border-top: 1px solid var(--border-lt);
  line-height: 1.8;
}

/* =====================================================
   トースト通知
   ===================================================== */
#cf-toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cf-toast {
  background: #222c3d;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.3s ease;
  min-width: 220px;
}
.cf-toast.success { border-left: 4px solid #34c478; }
.cf-toast.error   { border-left: 4px solid #e53e3e; }
.cf-toast.info    { border-left: 4px solid #3b82f6; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =====================================================
   印刷スタイル
   ===================================================== */
@media print {
  #cf-topbar,
  #cf-form-panel,
  #cf-toast-container {
    display: none !important;
  }

  html, body {
    height: auto;
    overflow: visible;
    background: #fff;
    font-size: 11pt;
  }

  /* 印刷時はfixed配置を解除して通常フローに戻す */
  #cf-layout {
    position: static;
    display: block;
    height: auto;
    overflow: visible;
  }

  #cf-preview-panel {
    display: block;
    overflow: visible;
    background: #fff;
  }

  .cf-panel-header { display: none; }

  .cf-preview-scroll {
    overflow: visible;
    padding: 0;
    height: auto;
  }

  .cf-doc {
    max-width: 100%;
    margin: 0;
    padding: 16mm 18mm 20mm;
    box-shadow: none;
    border-radius: 0;
    font-size: 10pt;
  }

  .cf-doc-title  { font-size: 16pt; }
  .cf-chapter    { font-size: 10pt; }
  .cf-art-title  { font-size: 10pt; }

  .cf-blank,
  .cf-inline-amt {
    border-bottom: 1px solid #555;
  }

  .cf-sign-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8mm;
  }

  .cf-sign-seal {
    opacity: 1;
    border-color: #cc3333;
  }

  @page {
    size: A4 portrait;
    margin: 12mm 14mm;
  }
}

/* =====================================================
   レスポンシブ（タブレット・スマホ）
   ===================================================== */
@media (max-width: 960px) {
  :root { --form-w: 300px; }
  .cf-doc { padding: 28px 28px 36px; }
  .cf-sign-grid { grid-template-columns: 1fr; gap: 10px; }
}

@media (max-width: 700px) {
  #cf-layout {
    flex-direction: column;
  }
  #cf-form-panel {
    width: 100%;
    height: 45vh;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #cf-preview-panel {
    height: 55vh;
  }
  .cf-preview-scroll { padding: 12px 12px 24px; }
  .cf-doc { padding: 18px 14px 28px; }
}
