/* =====================================================================
   帳票レイアウト編集画面（care_plans#sheet_edit）
   公式様式（第1表・第2表）の見た目のまま、色のついた欄を直接編集する。
   モック mockups/easy_wizard/step4b_sheet_edit.html の視覚言語を app 内で再現。
   ===================================================================== */

:root {
  --cpse-purple: #7c3aed;
  --cpse-edit-bg: rgba(124, 58, 237, 0.04);
  --cpse-edit-bg-hover: rgba(124, 58, 237, 0.07);
  --cpse-edit-outline: rgba(124, 58, 237, 0.4);
}

/* ---- 上部バー ---- */
.cpse-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 0 16px;
  flex-wrap: wrap;
}

.cpse-topbar-title h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  margin: 0;
}

.cpse-topbar-title p {
  font-size: 13px;
  color: var(--gray-500);
  margin: 2px 0 0;
}

.cpse-topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex-wrap: wrap;
}

/* ---- ボタン ---- */
.cpse-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1.5px solid transparent;
  white-space: nowrap;
  transition: opacity 0.15s, background 0.15s, transform 0.1s;
  font-family: inherit;
}

.cpse-btn-primary {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
  box-shadow: 0 3px 10px rgba(192, 160, 98, 0.3);
}

.cpse-btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.cpse-btn-ghost {
  background: #fff;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.cpse-btn-ghost:hover { background: var(--gray-50); }

.cpse-btn-lg {
  padding: 15px 32px;
  font-size: 16px;
  font-weight: 800;
  border-radius: 12px;
}

/* ---- 凡例 ---- */
.cpse-legend {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 9px 16px;
  background: #f5f0ff;
  border: 1px solid #ddd6fe;
  border-radius: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.cpse-lg-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--cpse-purple);
}

.cpse-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-600);
}

.cpse-swatch {
  width: 18px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.cpse-swatch.editable { background: var(--cpse-edit-bg-hover); }
.cpse-swatch.readonly { background: #f3f4f6; border-color: #e5e7eb; }

/* ---- タブ ---- */
.cpse-tabs {
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  margin-bottom: 18px;
}

.cpse-tab {
  padding: 10px 26px;
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-500);
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
  font-family: inherit;
}

.cpse-tab.active {
  color: var(--cpse-purple);
  border-bottom-color: var(--cpse-purple);
}

.cpse-tab:hover:not(.active) { color: var(--navy); }

/* ---- パネル ---- */
.cpse-panel { display: none; }
.cpse-panel.active { display: block; }

.cpse-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 6px;
}

/* ---- 帳票本体（印刷様式ベース・画面用に文字サイズ調整） ---- */
.kp-sheet {
  min-width: 1080px;
  font-family: 'Hiragino Mincho ProN', 'Hiragino Mincho Pro', 'Yu Mincho', 'YuMincho', 'MS Mincho', 'Noto Serif JP', serif;
  font-size: 12px;
  color: #111;
  line-height: 1.45;
  background: #fff;
  padding: 6px 2px;
}

.kp-sheet table {
  border-collapse: collapse;
  width: 100%;
}

.kp-sheet td,
.kp-sheet th {
  border: 1.5px solid #333;
  vertical-align: top;
  padding: 4px 7px;
  font-size: 12px;
}

/* タイトル行 */
.kp-title-row {
  display: flex;
  align-items: stretch;
  margin-bottom: 6px;
}

.kp-title-badge {
  border: 2px solid #333;
  font-weight: 700;
  font-size: 15px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  white-space: nowrap;
  background: #f0f0f0;
}

.kp-title-main {
  flex: 1;
  text-align: center;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #333;
  border-left: none;
  padding: 6px;
}

.kp-title-meta {
  font-size: 12px;
  text-align: right;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
  padding: 6px 14px;
  border: 2px solid #333;
  border-left: none;
}

/* ラベルセル */
.kp-lbl {
  background: #f0f0f0;
  font-weight: 700;
  font-size: 12px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  line-height: 1.35;
}

/* 読み取り専用セル */
.kp-readonly {
  background: #fafafa;
  color: #444;
}

/* ---- 編集可能セル（視覚言語の核心） ---- */
.kp-editable {
  background: var(--cpse-edit-bg);
  position: relative;
}

.kp-editable:hover { background: var(--cpse-edit-bg-hover); }

.kp-editable:focus-within {
  outline: 2px solid var(--cpse-edit-outline);
  outline-offset: -1px;
}

/* 枠線なし textarea — セルに溶け込む */
.sheet-ta {
  width: 100%;
  border: none;
  background: transparent;
  font-family: 'Hiragino Mincho ProN', 'Hiragino Mincho Pro', 'Yu Mincho', 'YuMincho', 'MS Mincho', 'Noto Serif JP', serif;
  font-size: 12px;
  line-height: 1.55;
  color: #111;
  resize: none;
  outline: none;
  padding: 0;
  margin: 0;
  display: block;
  box-sizing: border-box;
  overflow: hidden;
}

.sheet-ta:focus {
  background: var(--cpse-edit-bg-hover);
  border-radius: 2px;
}

.sheet-ta::placeholder { color: #b9a9dd; }

/* セル内テキスト入力（サービス種別・頻度・期間） */
.cpse-cell-input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: 'Hiragino Mincho ProN', 'Hiragino Mincho Pro', 'Yu Mincho', 'YuMincho', 'MS Mincho', 'Noto Serif JP', serif;
  font-size: 12px;
  line-height: 1.5;
  color: #111;
  outline: none;
  padding: 0;
  box-sizing: border-box;
}

.cpse-cell-input.center { text-align: center; }
.cpse-cell-input::placeholder { color: #b9a9dd; }
.cpse-cell-input:focus { background: var(--cpse-edit-bg-hover); border-radius: 2px; }

/* 日付入力 */
.cpse-date-input {
  border: 1px solid var(--gray-300);
  background: #fff;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 11px;
  font-family: inherit;
  color: #111;
}

.cpse-date-input:focus {
  outline: 2px solid var(--cpse-edit-outline);
  outline-offset: -1px;
  border-color: var(--cpse-purple);
}

.cpse-date-sm { padding: 1px 3px; font-size: 10.5px; width: 100%; }

.cpse-plandate-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}

/* 期間（開始〜終了を縦に） */
.cpse-period {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.cpse-period-sep { font-size: 10px; color: #666; line-height: 1; }

/* 意向 + 課題分析（1セル内2欄） */
.cpse-subfield { padding: 5px 7px; }

.cpse-subfield-divider { border-top: 1px dashed #c9c9c9; }

.cpse-sublabel {
  font-size: 9.5px;
  color: #8a8a8a;
  font-weight: 600;
  margin-bottom: 3px;
  font-family: -apple-system, 'Hiragino Kaku Gothic ProN', sans-serif;
}

/* AI マーク */
.ai-mark {
  display: inline-block;
  font-size: 11px;
  margin-right: 2px;
  vertical-align: middle;
  line-height: 1;
  opacity: 0.85;
}

/* 要介護度の丸囲み */
.care-ring {
  display: inline-block;
  border: 1.5px solid #333;
  border-radius: 50%;
  padding: 0 4px;
  font-weight: 700;
}

.care-off { padding: 0 4px; }

/* 生活援助算定理由 */
.kp-riyu {
  border: 1.5px solid #333;
  padding: 5px 10px;
  font-size: 11.5px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.kp-riyu .rt { font-weight: 700; white-space: nowrap; }

/* 同意・署名ボックス */
.kp-consent {
  border: 1.5px solid #333;
  padding: 6px 10px;
  font-size: 11.5px;
  margin-top: 6px;
  line-height: 1.7;
}

.kp-consent .sign-row {
  display: flex;
  gap: 32px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.kp-consent .sign-field {
  flex: 1;
  min-width: 220px;
  border-bottom: 1px solid #333;
  padding-bottom: 2px;
}

/* ページラベル */
.kp-page-label {
  text-align: right;
  font-size: 11.5px;
  font-weight: 700;
  border: 1.5px solid #333;
  display: inline-block;
  padding: 2px 10px;
  float: right;
}

/* ======= 第2表 ======= */
.t2-note {
  font-size: 10.5px;
  color: #333;
  margin-bottom: 5px;
  line-height: 1.45;
}

.kp-sheet .t2 th {
  background: #f0f0f0;
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
  font-size: 11px;
  padding: 4px 3px;
  line-height: 1.3;
}

.kp-sheet .t2 td {
  font-size: 11.5px;
  padding: 4px 5px;
  vertical-align: top;
}

.kp-sheet .t2 td.center { text-align: center; vertical-align: middle; }

.kp-sheet .t2 .need-cell {
  font-weight: 600;
  background: var(--cpse-edit-bg);
}

/* ニーズブロックの D&D ハンドル（ニーズ欄セル内・列数を増やさない） */
.cpse-need-drag {
  display: flex;
  justify-content: flex-start;
  margin: -2px 0 2px -2px;
}
.cpse-need-drag .drag-handle {
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--gray-400, #9ca3af);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.cpse-need-drag .drag-handle:hover { color: #7c3aed; background: rgba(124, 58, 237, 0.08); }
.cpse-need-drag .drag-handle:active { cursor: grabbing; }

/* ドラッグ中の tbody（ニーズブロック）の見た目 */
.kp-sheet .t2 tbody.sortable-ghost { opacity: 0.45; }
.kp-sheet .t2 tbody.sortable-ghost td { background: rgba(124, 58, 237, 0.06); }
.kp-sheet .t2 tbody.sortable-chosen td { background: var(--cpse-edit-bg-hover); }

/* サービス追加行 — うっすら区別して「追加できる」を示す */
.cpse-add-cell { background: rgba(124, 58, 237, 0.02); }
.cpse-add-cell:hover { background: var(--cpse-edit-bg); }
.cpse-add-ta { min-height: 1.5em; }

/* 通常表示への案内 */
.cpse-need-note {
  margin-top: 10px;
  font-size: 12px;
  color: var(--gray-600);
  background: var(--ivory);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 10px 14px;
}

/* 下部アクション */
.cpse-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--gray-200);
  flex-wrap: wrap;
}

/* ======= 第3表（週間サービス計画表）グリッド ======= */
/* 縦軸=時間帯ブロック × 横軸=曜日 + 右端「主な日常生活上の活動」。
   care_plans#sheet_edit と同じ kp-editable / sheet-ta の視覚言語を踏襲する。 */

.kp-sheet .w3 {
  table-layout: fixed;
}

.kp-sheet .w3 th,
.kp-sheet .w3 td {
  font-size: 11px;
  padding: 3px 4px;
}

/* 見出し行（時間帯・曜日・活動） */
.kp-sheet .w3 thead th {
  background: #f0f0f0;
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
  line-height: 1.25;
}

.kp-sheet .w3 .w3-timehead { width: 9%; }
.kp-sheet .w3 .w3-dayhead { width: 10.7%; }
.kp-sheet .w3 .w3-activityhead { width: 15%; }

/* 時間帯ラベル列（読み取り専用の見出し扱い） */
.kp-sheet .w3 .w3-blocklabel {
  width: 4%;
  background: #f0f0f0;
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.kp-sheet .w3 .w3-blocksub {
  width: 5%;
  background: #fafafa;
  color: #555;
  font-size: 9.5px;
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  line-height: 1.2;
}

/* サービスセル（編集可能） */
.kp-sheet .w3 .w3-cell {
  vertical-align: top;
  padding: 2px 3px;
}

/* グリッドセル内 textarea — 最小高さを確保しつつ内容で伸びる */
.w3-ta {
  min-height: 2.2em;
  line-height: 1.5;
  font-size: 11px;
}

/* 右端「主な日常生活上の活動」欄（全行ぶち抜き） */
.kp-sheet .w3 .w3-activitycell {
  vertical-align: top;
  padding: 4px 6px;
}

.w3-activity-ta {
  min-height: 100%;
  line-height: 1.6;
}

/* 土日カラムをうっすら色分け（見出し・セルとも） */
.kp-sheet .w3 .w3-sat { background: rgba(37, 99, 235, 0.05); }
.kp-sheet .w3 .w3-sun { background: rgba(220, 38, 38, 0.05); }
.kp-sheet .w3 .w3-cell.w3-sat { background: rgba(37, 99, 235, 0.05); }
.kp-sheet .w3 .w3-cell.w3-sun { background: rgba(220, 38, 38, 0.05); }
/* 編集セルは土日でも編集色を優先（hover/focus 時） */
.kp-sheet .w3 .w3-cell.kp-editable:hover { background: var(--cpse-edit-bg-hover); }
.kp-sheet .w3 .w3-cell.kp-editable:focus-within { background: var(--cpse-edit-bg-hover); }

/* 週単位以外のサービス欄 */
.kp-sheet .w3-weekly .w3-weeklylabel {
  width: 9%;
  text-align: center;
  vertical-align: middle;
  line-height: 1.3;
}

/* 帳票エリアは横幅を活かすので、メインの max-width 制約下でも横スクロールで対応する */
