/* ==========================================================================
   家系図作成ツール 専用CSS
   すべてのセレクタは .ft-tool 以下、またはページ全体で使う ft- 接頭辞に限定
   ========================================================================== */

.ft-tool {
  --ft-main: #295596;
  --ft-main-dark: #21467b;
  --ft-bg: #f5f7fa;
  --ft-border: #d9dee5;
  --ft-danger: #b91c1c;
  --ft-danger-bg: #fef2f2;
  --ft-male-border: #90b4e0;
  --ft-female-border: #e8a9b8;
  --ft-neutral-border: #b8bec7;
}

/* モーダルやカードメニューは .ft-tool の外（<main> 直下）に置かれているため、
   [hidden] の解除はページ全体に対して行う */
[hidden] { display: none !important; }

/* ---------------------------------------------------------------------- */
/* 導入文・メッセージ                                                          */
/* ---------------------------------------------------------------------- */

.ft-lead-intro {
  font-size: 0.95rem;
  line-height: 1.8;
  color: #374151;
  margin: 0 0 10px;
}

.ft-lead-features {
  font-size: 0.85rem;
  line-height: 1.8;
  color: #4b5563;
  margin: 0 0 10px;
  padding-left: 1.3em;
}

.ft-lead-features li { margin-bottom: 4px; }

.ft-howto-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 14px 18px;
  margin: 0 0 14px;
}

.ft-howto {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ft-howto li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #1f2937;
}

.ft-howto-num {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #295596;
  color: #fff;
  font-size: 0.76rem;
  font-weight: 700;
}

@media (min-width: 768px) {
  .ft-howto {
    flex-direction: row;
    flex-wrap: wrap;
    row-gap: 8px;
    column-gap: 28px;
  }
}

.ft-message {
  min-height: 1.2em;
  font-size: 0.9rem;
  padding: 8px 12px;
  margin-bottom: 10px;
  border-radius: 6px;
}

.ft-message.is-success { color: #1a7f37; font-weight: 600; background: #f0fdf4; }
.ft-message.is-error { color: var(--ft-danger); font-weight: 600; background: var(--ft-danger-bg); }

.ft-save-status {
  font-size: 0.8rem;
  color: #6b7280;
  margin: 0 0 12px;
}

.ft-field-error {
  font-size: 0.8rem;
  color: var(--ft-danger);
  margin: 4px 0 0;
  line-height: 1.5;
}

.ft-field-warning {
  font-size: 0.8rem;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 8px 0 0;
  line-height: 1.5;
}

/* ---------------------------------------------------------------------- */
/* ボタン                                                                    */
/* ---------------------------------------------------------------------- */

.ft-tool button.ft-btn {
  font: inherit;
  cursor: pointer;
  background: #f3f4f6;
  color: #1f2937;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 11px 18px;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
  min-height: 44px;
}

.ft-tool button.ft-btn:hover { background: #e5e7eb; }

.ft-tool button.ft-btn:focus-visible {
  outline: 2px solid var(--ft-main);
  outline-offset: 2px;
}

.ft-tool button.ft-btn-primary {
  background: var(--ft-main);
  border-color: var(--ft-main-dark);
  color: #fff;
}

.ft-tool button.ft-btn-primary:hover { background: var(--ft-main-dark); }

.ft-tool button.ft-btn-danger {
  background: #fff;
  border-color: var(--ft-danger);
  color: var(--ft-danger);
}

.ft-tool button.ft-btn-danger:hover { background: var(--ft-danger-bg); }

.ft-tool button.ft-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ft-tool button.ft-btn:disabled:hover { background: #f3f4f6; }

.ft-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.ft-btn-group .ft-btn { flex: 1 1 auto; min-width: 150px; }

.ft-btn-group-compact {
  margin-top: 12px;
}

.ft-btn-group-compact .ft-btn {
  min-width: 0;
  padding: 9px 12px;
  font-size: 0.85rem;
}

/* 「最初から作成」はやり直しが効かず、かつ使用頻度が低いため、
   他の操作ボタンと同列の押しやすい位置には置かず、区切り線の下に
   控えめなテキストリンクとして分離し、誤クリックを防ぐ */
.ft-danger-zone {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--ft-border);
  text-align: center;
}

.ft-tool button.ft-btn-text-danger {
  font: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: #9ca3af;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 10px 8px;
  min-height: 44px;
}

.ft-tool button.ft-btn-text-danger:hover { color: var(--ft-danger); }

.ft-tool button.ft-btn-text-danger:focus-visible {
  outline: 2px solid var(--ft-main);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .ft-btn-group { flex-direction: column; }
  .ft-btn-group .ft-btn { width: 100%; }
  .ft-btn-group-compact { flex-direction: row; }
}

/* ---------------------------------------------------------------------- */
/* レイアウト（PC 2カラム／モバイル 縦並び。プレビューを先に見せる）                 */
/* ---------------------------------------------------------------------- */

.ft-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

.ft-preview-column { order: -1; }

@media (min-width: 1024px) {
  .ft-layout {
    grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }
  .ft-preview-column { order: 0; }

  /* 人物未登録の間は左カラム（操作／人物一覧）が空になるため、
     グリッド幅を確保させず1カラムにして空の状態を中央に見せる */
  .ft-layout.ft-layout-single {
    grid-template-columns: 1fr;
  }
}

.ft-panel {
  background: #fff;
  border: 1px solid var(--ft-border);
  border-radius: 10px;
  padding: 18px 18px 20px;
  margin-bottom: 20px;
}

.ft-panel:last-child { margin-bottom: 0; }

.ft-panel-title {
  font-size: 1.02rem;
  font-weight: 700;
  margin: 0 0 14px;
  color: #111827;
}

/* ---------------------------------------------------------------------- */
/* 人物一覧                                                                  */
/* ---------------------------------------------------------------------- */

.ft-person-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
}

.ft-person-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 8px;
  border-bottom: 1px solid #f0f1f3;
  font-size: 0.88rem;
}

.ft-person-list-item:last-child { border-bottom: none; }

.ft-person-list-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  flex: 1 1 auto;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: #1f2937;
  padding: 4px 2px;
  min-height: 44px;
}

.ft-person-list-btn:hover,
.ft-person-list-btn:focus-visible { color: var(--ft-main); }

.ft-person-list-main { display: flex; align-items: baseline; flex-wrap: wrap; }

.ft-person-list-name { font-weight: 600; }
.ft-person-list-relation { color: #6b7280; font-size: 0.82rem; margin-left: 6px; }

.ft-person-list-memo {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
  color: #9ca3af;
}

.ft-person-list-root .ft-person-list-name::after {
  content: "（基準）";
  font-size: 0.75rem;
  color: var(--ft-main);
  font-weight: 600;
  margin-left: 4px;
}

/* ---------------------------------------------------------------------- */
/* 空の状態                                                                  */
/* ---------------------------------------------------------------------- */

.ft-empty-state {
  max-width: 520px;
  margin: 0 auto;
  text-align: center;
  padding: 48px 20px;
  background: #fff;
  border: 1px dashed var(--ft-border);
  border-radius: 10px;
}

.ft-empty-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #111827;
  margin: 0 0 8px;
}

.ft-empty-state p {
  font-size: 0.9rem;
  color: #4b5563;
  margin: 0 0 18px;
}

/* ---------------------------------------------------------------------- */
/* 家系図プレビュー（SVG）                                                     */
/* ---------------------------------------------------------------------- */

.ft-tree-wrap {
  position: relative;
  background: var(--ft-bg);
  border: 1px solid var(--ft-border);
  border-radius: 10px;
  padding: 4px;
}

.ft-tree-viewport {
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  height: 60vh;
  min-height: 320px;
  max-height: 640px;
  border-radius: 6px;
}

.ft-tree-viewport.is-dragging { cursor: grabbing; }

.ft-tree-svg {
  display: block;
  /* SVG自体の大きさは常にビューポート（枠）いっぱいにする。
     これにより、中の#ftPanZoomGroupを動かしても表示領域の外側で
     意図せずクリップされない（SVG要素自身がクリップ境界になるため、
     内容の実サイズのままだとパン・ズームした内容がすぐ枠外扱いで消えてしまう）。 */
  width: 100%;
  height: 100%;
}

/* ---------------------------------------------------------------------- */
/* 拡大縮小の操作ボタン（隅に配置。カード・線を隠さない）                          */
/* ---------------------------------------------------------------------- */

.ft-zoom-controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ft-tool button.ft-zoom-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--ft-border);
  box-shadow: 0 2px 6px rgba(17, 24, 39, 0.15);
  color: #1f2937;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ft-tool button.ft-zoom-btn:hover { background: #f3f4f6; }

.ft-tool button.ft-zoom-btn-fit { font-size: 1rem; }

.ft-card {
  cursor: pointer;
}

.ft-card-rect {
  fill: #fff;
  stroke: var(--ft-neutral-border);
  stroke-width: 1.5;
  rx: 8;
}

.ft-card[data-gender="male"] .ft-card-rect { stroke: var(--ft-male-border); }
.ft-card[data-gender="female"] .ft-card-rect { stroke: var(--ft-female-border); }

.ft-card:hover .ft-card-rect,
.ft-card:focus-visible .ft-card-rect {
  stroke-width: 2.5;
}

.ft-card:focus-visible { outline: none; }

/* 人物一覧からのジャンプ時に、対象カードを一時的に強調する */
.ft-card--jump .ft-card-rect {
  animation: ft-card-jump-pulse 1.4s ease-out 1;
}

@keyframes ft-card-jump-pulse {
  0% { stroke: #f59e0b; stroke-width: 4; }
  55% { stroke: #f59e0b; stroke-width: 4; }
  100% { stroke: #f59e0b; stroke-width: 1.5; }
}

.ft-card-name {
  font-size: 14px;
  font-weight: 700;
  fill: #111827;
}

.ft-card-sub {
  font-size: 11px;
  fill: #6b7280;
}

.ft-tree-line {
  fill: #9ca3af;
  stroke: none;
}

.ft-card-memo-icon { cursor: pointer; }
.ft-card-memo-icon-bg { fill: #fef3c7; stroke: #d97706; stroke-width: 1; }
.ft-card-memo-icon-line { fill: #92400e; }
.ft-card-memo-icon:hover .ft-card-memo-icon-bg,
.ft-card-memo-icon:focus-visible .ft-card-memo-icon-bg { fill: #fde68a; }
.ft-card-memo-icon:focus-visible { outline: 2px solid var(--ft-main); outline-offset: 1px; }

/* ---------------------------------------------------------------------- */
/* 人物カードのコンテキストメニュー                                              */
/* ---------------------------------------------------------------------- */

.ft-card-menu {
  position: fixed;
  z-index: 1200;
  background: #fff;
  border: 1px solid var(--ft-border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 6px;
  min-width: 160px;
}

.ft-card-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  color: #1f2937;
  padding: 10px 10px;
  border-radius: 6px;
  min-height: 44px;
}

.ft-card-menu-item:hover,
.ft-card-menu-item:focus-visible { background: #f3f4f6; }

.ft-card-menu-item-danger { color: var(--ft-danger); }

/* ---------------------------------------------------------------------- */
/* モーダル                                                                  */
/* ---------------------------------------------------------------------- */

.ft-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.5);
  z-index: 1300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 640px) {
  .ft-modal-overlay {
    align-items: center;
    padding: 20px;
  }
}

.ft-modal {
  background: #fff;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 12px 12px 0 0;
  padding: 22px 20px 24px;
}

@media (min-width: 640px) {
  .ft-modal { border-radius: 12px; }
}

.ft-modal-small { max-width: 380px; }

.ft-modal h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #111827;
  margin: 0 0 14px;
}

.ft-modal-lead {
  font-size: 0.88rem;
  color: #4b5563;
  margin: -8px 0 16px;
}

.ft-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 480px) {
  .ft-modal-actions { flex-direction: column-reverse; }
  .ft-modal-actions .ft-btn { width: 100%; }
}

/* ---------------------------------------------------------------------- */
/* フォーム部品                                                              */
/* ---------------------------------------------------------------------- */

.ft-field { margin-bottom: 14px; }
.ft-field:last-child { margin-bottom: 0; }

.ft-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.ft-tool label,
.ft-field-legend {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 5px;
}

.ft-required {
  color: var(--ft-danger);
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 6px;
}

.ft-tool input[type="text"],
.ft-tool input[type="number"],
.ft-tool select,
.ft-tool textarea {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: #111827;
  min-height: 44px;
  box-sizing: border-box;
}

.ft-tool textarea { min-height: 72px; resize: vertical; }

.ft-tool input:focus-visible,
.ft-tool select:focus-visible,
.ft-tool textarea:focus-visible {
  outline: 2px solid var(--ft-main);
  outline-offset: 1px;
}

.ft-radio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.ft-radio-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  font-size: 0.88rem;
  color: #1f2937;
  margin: 0;
  min-height: 44px;
}

/* ---------------------------------------------------------------------- */
/* 使い方・解説セクション（SEO本文）                                          */
/* ---------------------------------------------------------------------- */

.ft-doc-section {
  max-width: 960px;
  margin: 32px auto;
  padding: 0 16px 8px;
  line-height: 1.8;
  color: #333;
}

.ft-doc-section h2 {
  margin: 40px 0 14px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #111827;
  border-left: 4px solid var(--ft-main, #295596);
  padding-left: 10px;
}

.ft-doc-section h2:first-of-type { margin-top: 0; }

.ft-doc-section h3 {
  margin: 20px 0 8px;
  font-size: 1.05rem;
  font-weight: 700;
  color: #1f2937;
  border-left: 3px solid var(--ft-male-border, #90b4e0);
  padding-left: 8px;
}

.ft-doc-section p,
.ft-doc-section li {
  font-size: 0.92rem;
  line-height: 1.85;
  color: #374151;
}

.ft-doc-section p { margin: 0 0 12px; }
.ft-doc-section ul { padding-left: 1.4em; margin: 0 0 12px; }
.ft-doc-section li { margin-bottom: 4px; }

.ft-doc-table-wrap { overflow-x: auto; margin: 0 0 20px; }

.ft-doc-section table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.875rem;
}

.ft-doc-section th,
.ft-doc-section td {
  border: 1px solid #e5e7eb;
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.ft-doc-section th {
  background: #f9fafb;
  font-weight: 700;
  color: #111827;
}

.ft-doc-box {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 16px 20px;
  margin: 0 0 16px;
}

.ft-doc-box p:last-child { margin-bottom: 0; }

.ft-faq-item {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 12px;
}

.ft-faq-item h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ft-main, #295596);
  border-left: none;
  padding-left: 0;
}

.ft-faq-item h3::before { content: "Q. "; }
.ft-faq-item p { margin: 0; }
.ft-faq-item p::before { content: "A. "; font-weight: 700; color: #6b7280; }

ul.related-links {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

ul.related-links li a {
  display: block;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px 14px;
  color: #1d4ed8;
  text-decoration: none;
  font-size: 0.875rem;
  background: #fff;
}

ul.related-links li a:hover { background: #eff6ff; }

/* ---------------------------------------------------------------------- */
/* 印刷用スタイル                                                            */
/* ---------------------------------------------------------------------- */

@media print {
  #header, #footer,
  #ftBreadcrumb, #ftIntro,
  .ft-side-column,
  .ft-message,
  .ft-save-status,
  .ft-card-menu,
  .ft-zoom-controls,
  .ft-card-memo-icon,
  #familyTreeGuide {
    display: none !important;
  }

  /* 画面上のズーム／パン位置に関わらず、家系図全体を印刷する */
  .ft-tree-wrap {
    background: #fff !important;
    border: none !important;
    padding: 0 !important;
  }

  .ft-tree-viewport {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  /* 画面用の width/height:100% を解除し、SVG自身のwidth/height属性（家系図の実寸）で表示する */
  .ft-tree-svg {
    width: auto !important;
    height: auto !important;
  }

  #ftPanZoomGroup {
    transform: none !important;
  }
}
