/* 組織図専用CSS */
.family-tree-container {
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
}

/* 組織図用のスタイル */
.family-tree-container-wrapper {
    width: 100%;
    max-width: 100%;
    height: 80vh;
    margin: 0;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    overflow: hidden;
    background: #ffffff;
    position: relative;
    box-sizing: border-box;
}

/* ズームコントロール */
.chart-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 100;
    display: flex;
    gap: 5px;
}

.chart-controls .btn {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ツリーノード構造 */
.tree-node {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.tree-children {
    display: flex;
    gap: 40px;
    margin-top: 60px;
    position: relative;
}

.tree-children.hidden {
    display: none;
}

/* ノードカード */
.node-card {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 16px;
    width: 180px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    z-index: 10;
}

.node-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.node-card.root {
    border-color: #8b5cf6;
    background: linear-gradient(135deg, #f3e8ff 0%, #ffffff 100%);
}

.node-card.approved {
    border-color: #10b981;
    background: linear-gradient(135deg, #ecfdf5 0%, #ffffff 100%);
}

.node-card.unapproved {
    border-color: #f59e0b;
    background: linear-gradient(135deg, #fffbeb 0%, #ffffff 100%);
}

.node-card.vip {
    border-width: 3px;
}

.node-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.node-toggle {
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.node-toggle:hover {
    background: #2563eb;
    transform: scale(1.1);
}

.node-status {
    font-size: 20px;
}

.node-body {
    text-align: center;
}

.node-id {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 8px;
}

.node-tickets {
    font-size: 13px;
    color: #3b82f6;
    font-weight: 600;
}

/* 接続線 */

/* 親ノードから下に伸びる縦線（子ノードがある場合） */
.tree-children::after {
    content: '';
    position: absolute;
    top: -120px; /* 親ノードの下端から横線まで（60px + 60px） */
    left: 50%;
    width: 2px;
    height: 60px; /* 親ノードから横線まで */
    background: #3b82f6;
    transform: translateX(-1px);
    z-index: -1; /* 横線の下に配置 */
}

/* 子ノードから上に伸びる縦線 + 横線 */
/* 最初の子ノード：縦線 + 右方向に横線（L字の左） */
.tree-children > .tree-node:first-child::before {
    content: '';
    position: absolute;
    top: -60px;
    left: 50%;
    width: 2px;
    height: 60px;
    background: #3b82f6;
    transform: translateX(-1px);
    z-index: 1;
}

.tree-children > .tree-node:first-child::after {
    content: '';
    position: absolute;
    top: -60px;
    left: 50%;
    right: -20px;
    height: 2px;
    background: #3b82f6;
    z-index: 0;
}

/* 最後の子ノード：縦線 + 左方向に横線（L字の右） */
.tree-children > .tree-node:last-child::before {
    content: '';
    position: absolute;
    top: -60px;
    left: 50%;
    width: 2px;
    height: 60px;
    background: #3b82f6;
    transform: translateX(-1px);
    z-index: 1;
}

.tree-children > .tree-node:last-child::after {
    content: '';
    position: absolute;
    top: -60px;
    right: 50%;
    left: -20px;
    height: 2px;
    background: #3b82f6;
    z-index: 0;
}

/* 中間の子ノード：縦線 + 左右両方向に横線（T字） */
.tree-children > .tree-node:not(:first-child):not(:last-child)::before {
    content: '';
    position: absolute;
    top: -60px;
    left: 50%;
    width: 2px;
    height: 60px;
    background: #3b82f6;
    transform: translateX(-1px);
    z-index: 1;
}

.tree-children > .tree-node:not(:first-child):not(:last-child)::after {
    content: '';
    position: absolute;
    top: -60px;
    left: -20px;
    right: -20px;
    height: 2px;
    background: #3b82f6;
    z-index: 0;
}

/* 子ノードが1つだけの場合：縦線のみ（横線なし） */
.tree-children > .tree-node:only-child::before {
    content: '';
    position: absolute;
    top: -60px;
    left: 50%;
    width: 2px;
    height: 60px;
    background: #3b82f6;
    transform: translateX(-1px);
    z-index: 1;
}

.tree-children > .tree-node:only-child::after {
    display: none;
}

@media (min-width: 1200px) {
    .family-tree-container-wrapper {
        width: 100%;
        max-width: 100%;
    }
}

#family-tree-chart {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* OrgChartコンテナのスムーズな変換 */
#family-tree-chart .orgchart {
    transition: none;
    will-change: transform;
}

.org-member-card {
    background: #ffffff;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 12px;
    width: 140px;
    height: 90px;
    text-align: center;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.org-member-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    border-color: #004085;
}

.org-member-card.approved {
    border-color: #28a745;
    background: linear-gradient(135deg, #f8fff9 0%, #ffffff 100%);
}

.org-member-card.unapproved {
    border-color: #ffc107;
    background: linear-gradient(135deg, #fffdf8 0%, #ffffff 100%);
}

.org-member-status {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 14px;
}

.org-member-id {
    color: #333;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 6px;
}

.org-member-tickets {
    font-size: 11px;
    color: #004085;
    font-weight: bold;
}

/* d3-org-chart の線のスタイル */
.svg-chart-container .link {
    stroke: #004085;
    stroke-width: 2;
    fill: none;
}

.svg-chart-container .node {
    cursor: pointer;
}

/* ズームコントロール */
.d3-org-chart .zoom-in-button,
.d3-org-chart .zoom-out-button,
.d3-org-chart .fit-button {
    background: rgba(255, 255, 255, 0.9) !important;
    border: 1px solid #e9ecef !important;
    color: #004085 !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    transition: all 0.3s ease !important;
}

.d3-org-chart .zoom-in-button:hover,
.d3-org-chart .zoom-out-button:hover,
.d3-org-chart .fit-button:hover {
    background: rgba(255, 255, 255, 1) !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2) !important;
}

.family-tree-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
}

.family-tree-header {
    background: white;
    color: #004085;
    padding: 20px;
    text-align: center;
}

.family-tree-title {
    font-size: 24px;
    font-weight: bold;
    margin: 0 0 10px 0;
}

.family-tree-subtitle {
    opacity: 0.9;
    margin: 0;
}

.family-tree-content {
    padding: 20px;
    box-sizing: border-box;
    width: 100%;
    overflow-x: hidden;
}

/* 統計情報 */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: #004085;
    color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-number {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 14px;
    opacity: 0.9;
}

/* 組織図スタイル */
.family-tree {
    overflow-x: auto;
    padding: 40px 20px;
    position: relative;
}

.generation {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    margin-bottom: 60px;
    position: relative;
}

.generation:last-child {
    margin-bottom: 40px;
}

.generation-label {
    position: absolute;
    left: -120px;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #fe7432 0%, #004085 100%);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.members-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 25px;
    position: relative;
}

.member-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* 組織図の線 */
.generation:not(:first-child)::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 50%;
    width: 2px;
    height: 40px;
    background: linear-gradient(to bottom, #fe7432, #004085);
    transform: translateX(-50%);
    z-index: 1;
}

/* 兄弟間を繋ぐ横線 */
.generation:not(:first-child) .members-container::before {
    content: '';
    position: absolute;
    top: -40px;
    left: 20%;
    right: 20%;
    height: 2px;
    background: linear-gradient(to right, #fe7432, #004085);
    z-index: 0;
}

/* 各メンバーへの縦線 */
.generation:not(:first-child) .member-group::after {
    content: '';
    position: absolute;
    top: -40px;
    left: 50%;
    width: 2px;
    height: 20px;
    background: linear-gradient(to bottom, #fe7432, #004085);
    transform: translateX(-50%);
    z-index: 2;
}

/* 単独メンバーの場合は横線を非表示 */
.generation:not(:first-child) .members-container:has(.member-group:only-child)::before {
    display: none;
}

.member-card {
    background: #ffffff;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 12px;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    min-width: 120px;
    max-width: 150px;
    text-align: center;
}

.member-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
    border-color: #004085;
}

.member-card.approved {
    border-color: #28a745;
    background: linear-gradient(135deg, #f8fff9 0%, #ffffff 100%);
}

.member-card.unapproved {
    border-color: #ffc107;
    background: linear-gradient(135deg, #fffdf8 0%, #ffffff 100%);
}

.member-status {
    position: absolute;
    top: 5px;
    right: 8px;
    font-size: 14px;
}

.member-id {
    color: #333;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 6px;
}

.member-tickets {
    font-size: 11px;
    color: #004085;
    font-weight: bold;
}

/* 空状態のスタイル */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #666;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 18px;
    margin-bottom: 10px;
    font-weight: 600;
}

.empty-state-subtext {
    font-size: 14px;
    opacity: 0.7;
    margin-bottom: 20px;
}

/* ボタンスタイル */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: 500;
    text-align: center;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
}

.btn-primary {
    background: linear-gradient(135deg, #004085 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(108, 117, 125, 0.3);
}

/* フィルター機能のスタイル */
.family-tree-filters {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-select {
    padding: 6px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: white;
}

.filter-checkbox {
    margin-right: 5px;
}

/* 代理店・VIP代理店アイコン */
.org-member-agent-icon {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 16px;
}

/* 招待詳細情報 */
.invite-details {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
}

.invite-details p {
    margin: 5px 0;
    font-size: 14px;
    color: #666;
}

/* スマートフォン対応 */
@media (max-width: 768px) {
    .family-tree-container {
        padding: 10px;
    }

    .family-tree-title {
        font-size: 20px;
    }

    .family-tree-header {
        padding: 15px;
    }

    .family-tree-content {
        padding: 15px;
    }

    /* フィルターのスマホ対応 */
    .family-tree-filters {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 15px;
    }

    .filter-group {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }

    .filter-group label {
        font-size: 14px;
        font-weight: 600;
        color: #333;
    }

    .filter-select {
        width: 100%;
        padding: 10px 12px;
        font-size: 14px;
        border-radius: 6px;
        border: 1px solid #ced4da;
        background: white;
        box-sizing: border-box;
    }

    .btn {
        width: 100%;
        padding: 12px 20px;
        font-size: 14px;
        margin-top: 5px;
    }

    .family-tree {
        padding: 20px 10px;
    }

    .generation {
        margin-bottom: 60px;
    }

    .generation-label {
        left: -80px;
        font-size: 12px;
        padding: 6px 12px;
    }

    .members-container {
        gap: 20px;
        flex-direction: column;
        align-items: center;
    }

    .member-card {
        min-width: 100px;
        max-width: 130px;
        width: auto;
        padding: 10px;
    }

    .generation:not(:first-child)::before {
        top: -30px;
        height: 30px;
    }

    .generation:not(:first-child) .member-group::after {
        top: -30px;
        height: 15px;
    }

    .generation:not(:first-child) .members-container::before {
        top: -30px;
        left: 10%;
        right: 10%;
    }

    .stats-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-number {
        font-size: 20px;
    }

    .member-card {
        padding: 12px;
    }

    .level-title {
        padding: 8px 12px;
        font-size: 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    .org-chart {
        padding: 10px 0;
    }

    .empty-state {
        padding: 40px 15px;
    }

    .empty-state-icon {
        font-size: 36px;
    }

    .empty-state-text {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .stats-container {
        grid-template-columns: 1fr;
    }
    
    .level-title {
        font-size: 13px;
    }
    
    .member-name {
        font-size: 15px;
    }
    
    .member-id {
        font-size: 13px;
    }
}

/* デバッグ情報スタイル */
.debug-info {
    background: #f0f0f0;
    padding: 10px;
    margin-bottom: 20px;
    border-radius: 5px;
    font-family: monospace;
    font-size: 12px;
    border: 1px solid #ddd;
}
/* OrgChart.js カスタムスタイル */
.orgchart {
    background: #fff;
    padding: 20px;
    cursor: grab;
    user-select: none;
    transform-origin: center center;
}

.orgchart:active {
    cursor: grabbing;
}

/* カスタムノードコンテンツ */
.custom-node-content {
    background: #ffffff;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    padding: 12px;
    width: 140px;
    min-height: 90px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.custom-node-content:hover {
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    border-color: #004085;
}

/* 承認済み・未承認の色分け */
.orgchart .node.approved .custom-node-content {
    border-color: #28a745;
    background: linear-gradient(135deg, #f8fff9 0%, #ffffff 100%);
}

.orgchart .node.unapproved .custom-node-content {
    border-color: #ffc107;
    background: linear-gradient(135deg, #fffdf8 0%, #ffffff 100%);
}

/* ノード内のコンテンツスタイル */
.node-status {
    font-size: 16px;
    margin-bottom: 4px;
    align-self: flex-end;
    width: 100%;
    text-align: right;
}

.node-id {
    color: #333;
    font-size: 12px;
    font-weight: bold;
    margin-bottom: 6px;
}

.node-tickets {
    font-size: 11px;
    color: #004085;
    font-weight: bold;
}

/* OrgChart.jsのデフォルトスタイルを上書き */
.orgchart .node .title {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

.orgchart .lines .downLine,
.orgchart .lines .topLine,
.orgchart .lines .leftLine,
.orgchart .lines .rightLine {
    background-color: #004085 !important;
}

/* 展開/折りたたみボタン */
.orgchart .toggleBtn {
    background-color: #004085 !important;
    border: 2px solid #fff !important;
}

.orgchart .toggleBtn:hover {
    background-color: #003366 !important;
}

/* ズーム・パン用のカーソル */
.orgchart-container {
    cursor: grab;
}

.orgchart-container:active {
    cursor: grabbing;
}

/* トグルボタンを下側のみに表示 */
.orgchart .topEdge,
.orgchart .leftEdge,
.orgchart .rightEdge {
    display: none !important;
}

/* 下側のトグルボタンのみ表示 */
.orgchart .bottomEdge {
    display: block !important;
}

/* トグルボタンのスタイル改善 */
.orgchart .bottomEdge .toggleBtn {
    background-color: #004085 !important;
    border: 2px solid #fff !important;
    width: 20px !important;
    height: 20px !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    font-size: 12px !important;
    line-height: 16px !important;
    text-align: center !important;
}

.orgchart .bottomEdge .toggleBtn:hover {
    background-color: #003366 !important;
    transform: scale(1.1);
}

/* トグルボタンのアイコン */
.orgchart .bottomEdge .toggleBtn::before {
    content: '−';
    color: #fff;
    font-weight: bold;
}

.orgchart .collapsed .bottomEdge .toggleBtn::before {
    content: '+';
}
