/* 許氏家族族譜 v3.6 - 樹狀結構樣式 */

/* === 基礎設定 === */
:root {
    /* 主色調 - 古典莊重 */
    --primary: #8B4513;
    --primary-dark: #6B3410;
    --primary-light: #A0522D;
    --secondary: #D4AF37;

    /* 背景色 */
    --bg-cream: #FDF8F0;
    --bg-white: #FFFFFF;
    --bg-light: #FAF6F0;

    /* 文字色 */
    --text-primary: #2D2D2D;
    --text-secondary: #5A5A5A;
    --text-muted: #888888;

    /* 連接線 */
    --line-color: #A0522D;
    --line-width: 2px;

    /* 世代顏色 */
    --gen-2: #8B4513;
    --gen-3: #A0522D;
    --gen-4: #CD853F;
    --gen-5: #DEB887;

    /* 性別顏色 */
    --male-bg: #E8F4FD;
    --male-border: #4A90D9;
    --female-bg: #FDE8F0;
    --female-border: #D94A8C;

    /* 尺寸 */
    --indent: 2.5rem;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 18px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Noto Serif TC', serif;
    background: var(--bg-cream);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    position: relative;
}

/* 太岳衍派祠堂淡化背景圖 */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('background.jpg');
    background-size: 100% auto;
    background-position: center 20%;
    background-repeat: no-repeat;
    background-attachment: fixed;
    opacity: 0.22;
    z-index: -1;
    pointer-events: none;
}

/* === Header === */
header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-icon {
    width: 60px;
    height: 60px;
    background: var(--secondary);
    color: var(--primary-dark);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    font-weight: 700;
}

.logo-text h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

.version {
    background: rgba(255,255,255,0.2);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* === Toolbar === */
.toolbar {
    background: var(--bg-white);
    padding: 1rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.search-box {
    display: flex;
    align-items: center;
    background: var(--bg-light);
    border: 2px solid #e0d5c5;
    border-radius: 30px;
    padding: 0.5rem 1rem;
    flex: 1;
    max-width: 400px;
    min-width: 200px;
}

.search-box:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
}

.search-icon {
    width: 24px;
    height: 24px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    border: none;
    background: transparent;
    padding: 0.5rem;
    font-size: 1rem;
    font-family: inherit;
    flex: 1;
    min-width: 0;
}

.search-box input:focus {
    outline: none;
}

.clear-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.5rem;
    line-height: 1;
}

.clear-btn:hover {
    color: var(--text-primary);
}

.toolbar-actions {
    display: flex;
    gap: 0.75rem;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: 25px;
    font-size: 1rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-outline {
    background: var(--bg-white);
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

/* === Quick Navigation === */
.quick-nav {
    background: var(--bg-white);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e0d5c5;
}

.quick-nav-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.quick-nav-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.quick-nav-btn {
    background: var(--bg-light);
    border: 1px solid #d5c9b8;
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.quick-nav-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* === Stats Section === */
.stats-section {
    padding: 1.5rem;
    background: var(--bg-light);
}

.stats-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
}

.stat-card {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    min-width: 140px;
}

.stat-icon {
    font-size: 2rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* === Main Content === */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* === Ancestor Section === */
.ancestor-section {
    margin-bottom: 2rem;
}

.ancestor-card {
    background: linear-gradient(135deg, #FFF8DC 0%, #F5E6C8 100%);
    border: 3px solid var(--secondary);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.ancestor-badge {
    position: absolute;
    top: -12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--secondary);
    color: var(--primary-dark);
    padding: 0.25rem 1.5rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 1rem;
}

.ancestor-names {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

.ancestor-person {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.ancestor-icon {
    font-size: 3rem;
}

.ancestor-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.ancestor-connector {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.heart {
    font-size: 2rem;
    color: #E74C3C;
}

/* === Family Tree === */
.family-tree {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.tree-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* === Tree Branch (第二代) === */
.tree-branch {
    border-left: var(--line-width) solid var(--line-color);
    margin-left: 1rem;
    transition: all 0.3s;
}

.tree-branch.highlight {
    border-left-color: var(--secondary);
    background: rgba(212, 175, 55, 0.1);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.tree-branch.search-match {
    background: rgba(212, 175, 55, 0.15);
}

.branch-header {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    cursor: pointer;
    position: relative;
    min-height: 70px;
    transition: background 0.2s;
}

.branch-header:hover {
    background: var(--bg-light);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.branch-line-vertical {
    position: absolute;
    left: -1rem;
    top: 50%;
    width: 1rem;
    height: var(--line-width);
    background: var(--line-color);
}

.branch-toggle {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 0.9rem;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.tree-branch.expanded > .branch-header .branch-toggle {
    transform: rotate(0deg);
}

.tree-branch:not(.expanded) > .branch-header .branch-toggle {
    transform: rotate(-90deg);
}

.branch-person {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    background: var(--male-bg);
    border: 2px solid var(--male-border);
}

.branch-person.female {
    background: var(--female-bg);
    border-color: var(--female-border);
}

.person-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.person-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}

.person-name {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.person-type {
    font-size: 0.9rem;
    color: var(--primary);
    background: rgba(139, 69, 19, 0.1);
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    display: inline-block;
    width: fit-content;
}

.person-spouse {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.person-deceased {
    font-size: 0.85rem;
    color: #888;
    background: #f0f0f0;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
}

.descendant-count {
    background: var(--primary);
    color: white;
    padding: 0.35rem 0.75rem;
    border-radius: 15px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

/* === Branch Content (子代內容) === */
.branch-content {
    display: none;
    margin-left: var(--indent);
    padding-top: 0.5rem;
    border-left: var(--line-width) solid var(--line-color);
    position: relative;
}

.tree-branch.expanded > .branch-content {
    display: block;
}

.branch-children {
    padding-top: 0.5rem;
}

/* === Tree Node (子節點) === */
.tree-node {
    position: relative;
    margin-bottom: 0.25rem;
}

.tree-node.search-match > .node-content {
    background: rgba(212, 175, 55, 0.2);
    border-radius: var(--radius);
}

.node-connector {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--indent);
}

.connector-horizontal {
    position: absolute;
    left: -1px;
    top: 35px;
    width: calc(var(--indent) - 0.5rem);
    height: var(--line-width);
    background: var(--line-color);
}

.connector-vertical {
    position: absolute;
    left: -1px;
    top: 0;
    width: var(--line-width);
    height: 100%;
    background: var(--line-color);
}

.connector-vertical.half {
    height: 35px;
}

.last-node > .node-connector .connector-vertical {
    height: 35px;
}

.node-content {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    margin-left: var(--indent);
    cursor: pointer;
    transition: background 0.2s;
    min-height: 60px;
}

.node-content:hover {
    background: var(--bg-light);
    border-radius: var(--radius);
}

.node-content.has-children {
    cursor: pointer;
}

.node-toggle {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 0.8rem;
    transition: transform 0.3s;
    flex-shrink: 0;
}

.tree-node.expanded > .node-content .node-toggle {
    transform: rotate(0deg);
}

.tree-node:not(.expanded) > .node-content .node-toggle {
    transform: rotate(-90deg);
}

.node-person {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    background: var(--male-bg);
    border: 2px solid var(--male-border);
    min-width: 0;
}

.node-person.female {
    background: var(--female-bg);
    border-color: var(--female-border);
}

.node-person.deceased {
    opacity: 0.7;
}

.node-person .person-icon {
    font-size: 1.5rem;
}

.node-person .person-name {
    font-size: 1.1rem;
}

.node-person .person-type {
    font-size: 0.8rem;
}

.node-person .person-spouse {
    font-size: 0.85rem;
}

.node-person .descendant-count {
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
}

/* === 子節點的子節點 === */
.tree-node > .branch-content {
    display: none;
    margin-left: calc(var(--indent) + 0.5rem);
}

.tree-node.expanded > .branch-content {
    display: block;
}

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

.modal-person {
    text-align: center;
}

.modal-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    margin: 0 auto 1rem;
    background: var(--male-bg);
    border: 3px solid var(--male-border);
}

.modal-avatar.female {
    background: var(--female-bg);
    border-color: var(--female-border);
}

.modal-person h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.modal-details {
    text-align: left;
}

.modal-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem;
    border-bottom: 1px solid #eee;
}

.modal-detail-row:last-child {
    border-bottom: none;
}

.modal-detail-row .label {
    color: var(--text-secondary);
    font-weight: 500;
}

.modal-detail-row .value {
    color: var(--text-primary);
    font-weight: 600;
}

/* === Footer === */
footer {
    background: var(--primary-dark);
    color: white;
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
}

.footer-note {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-top: 0.5rem;
}

/* === Error Message === */
.error-message {
    text-align: center;
    padding: 3rem;
    color: var(--text-secondary);
}

.error-message p:first-child {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

/* === Responsive === */
@media (max-width: 768px) {
    html {
        font-size: 16px;
    }

    .header-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .logo {
        flex-direction: column;
    }

    .toolbar {
        flex-direction: column;
        gap: 1rem;
    }

    .search-box {
        max-width: 100%;
        width: 100%;
    }

    .toolbar-actions {
        width: 100%;
        justify-content: center;
    }

    .quick-nav-buttons {
        justify-content: center;
    }

    .stats-container {
        gap: 0.75rem;
    }

    .stat-card {
        min-width: 120px;
        padding: 0.75rem 1rem;
    }

    .ancestor-names {
        gap: 1rem;
    }

    .ancestor-icon {
        font-size: 2.5rem;
    }

    .ancestor-name {
        font-size: 1.25rem;
    }

    :root {
        --indent: 1.5rem;
    }

    .branch-person {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .branch-person .descendant-count {
        align-self: flex-end;
    }

    .node-person {
        flex-wrap: wrap;
    }

    .node-person .descendant-count {
        margin-top: 0.5rem;
        margin-left: auto;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 15px;
    }

    .main-content {
        padding: 1rem;
    }

    .family-tree {
        padding: 1rem;
    }

    .btn {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .quick-nav-btn {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    .stat-card {
        min-width: 100px;
    }

    .stat-icon {
        font-size: 1.5rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }
}

/* === Animation === */
@keyframes highlightPulse {
    0%, 100% { background-color: transparent; }
    50% { background-color: rgba(212, 175, 55, 0.2); }
}

.tree-branch.highlight {
    animation: highlightPulse 0.5s ease-in-out 3;
}
