/* ==========================================================================
   Pal Family Tree - Modern Interactive Styles
   ========================================================================== */

:root {
    /* Color Palette */
    --tree-paternal: #38bdf8;
    --tree-maternal: #f472b6;
    --tree-self: #fbbf24;
    --tree-line: rgba(56, 189, 248, 0.35);
    --tree-line-active: #38bdf8;
    --tree-node-bg: rgba(30, 41, 59, 0.85);
    --tree-node-hover: rgba(51, 65, 85, 0.95);
    --tree-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    --tree-glow-paternal: 0 0 20px rgba(56, 189, 248, 0.3);
    --tree-glow-maternal: 0 0 20px rgba(244, 114, 182, 0.3);
    --tree-glow-self: 0 0 25px rgba(251, 191, 36, 0.45);
    --badge-bg: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] {
    --tree-line: rgba(2, 132, 199, 0.3);
    --tree-line-active: #0284c7;
    --tree-node-bg: rgba(255, 255, 255, 0.92);
    --tree-node-hover: #ffffff;
    --tree-shadow: 0 10px 20px -5px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
    --tree-glow-paternal: 0 0 15px rgba(2, 132, 199, 0.2);
    --tree-glow-maternal: 0 0 15px rgba(236, 72, 153, 0.2);
    --tree-glow-self: 0 0 20px rgba(245, 158, 11, 0.35);
    --badge-bg: rgba(15, 23, 42, 0.06);
}

/* Page Layout */
.family-page {
    padding-top: 85px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Hero & Header Section */
.family-hero {
    text-align: center;
    padding: 2.5rem 1rem 1.5rem;
    position: relative;
}

.family-title-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.family-title-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(251, 191, 36, 0.2));
    border: 1px solid rgba(56, 189, 248, 0.4);
    color: var(--accent-color);
    font-size: 1.4rem;
}

.family-hero h1 {
    font-size: 2.4rem;
    margin-bottom: 0.25rem;
    background: linear-gradient(135deg, var(--text-color) 40%, var(--accent-color) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.family-hero-subtitle {
    font-size: 1.05rem;
    color: #94a3b8;
    max-width: 680px;
    margin: 0 auto 1.5rem;
    line-height: 1.6;
}

/* Control Toolbar */
.tree-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    background: var(--card-bg);
    border: var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    margin-bottom: 1.5rem;
    box-shadow: var(--tree-shadow);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* View Switcher Tabs */
.view-toggle {
    display: inline-flex;
    background: var(--secondary-bg);
    padding: 4px;
    border-radius: 12px;
    border: var(--glass-border);
}

.view-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-color);
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.view-btn.active {
    background: var(--accent-color);
    color: #0f172a;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

/* Search Box */
.search-wrapper {
    position: relative;
    min-width: 240px;
}

.search-input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.25rem;
    border-radius: 10px;
    border: var(--glass-border);
    background: var(--secondary-bg);
    color: var(--text-color);
    font-size: 0.875rem;
    outline: none;
    transition: var(--transition);
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.search-icon {
    position: absolute;
    left: 0.8rem;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
    font-size: 0.85rem;
    pointer-events: none;
}

/* Action Buttons */
.tool-btn {
    padding: 0.5rem 0.85rem;
    border: var(--glass-border);
    background: var(--secondary-bg);
    color: var(--text-color);
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: var(--transition);
}

.tool-btn:hover {
    background: var(--accent-color);
    color: #0f172a;
    transform: translateY(-1px);
}

.tool-btn-primary {
    background: linear-gradient(135deg, #38bdf8, #0284c7);
    color: #0f172a;
    font-weight: 600;
    border: none;
}

.tool-btn-primary:hover {
    filter: brightness(1.1);
    color: #0f172a;
}

/* Tree Canvas & Zoom Container */
.tree-viewport {
    position: relative;
    width: 100%;
    min-height: 600px;
    height: calc(100vh - 280px);
    background: radial-gradient(circle at 50% 20%, rgba(56, 189, 248, 0.05), transparent 70%),
                var(--secondary-bg);
    border: var(--glass-border);
    border-radius: 20px;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
}

.tree-viewport:active {
    cursor: grabbing;
}

.tree-viewport.fullscreen-mode {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    border-radius: 0;
}

.tree-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: 50% 50px;
    transition: transform 0.15s cubic-bezier(0.2, 0, 0, 1);
    display: flex;
    justify-content: center;
    padding: 60px 40px 140px;
}

/* Zoom Widget on Canvas */
.canvas-controls {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    z-index: 30;
    background: var(--card-bg);
    border: var(--glass-border);
    backdrop-filter: blur(12px);
    padding: 6px;
    border-radius: 12px;
    box-shadow: var(--tree-shadow);
}

.zoom-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--secondary-bg);
    color: var(--text-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: var(--transition);
}

.zoom-btn:hover {
    background: var(--accent-color);
    color: #0f172a;
}

.zoom-level-text {
    font-size: 0.72rem;
    font-weight: 700;
    color: #94a3b8;
    text-align: center;
    padding: 2px 0;
}

/* ==========================================================================
   Tree Hierarchical Layout Elements
   ========================================================================== */

.family-tree-graph {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 50px;
    position: relative;
    width: max-content;
    margin: 0 auto;
}

/* Generation Level Rows */
.generation-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 100%;
}

.generation-label {
    position: absolute;
    left: -130px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #64748b;
    background: var(--badge-bg);
    border: var(--glass-border);
    padding: 4px 10px;
    border-radius: 20px;
    white-space: nowrap;
}

/* Row Node Clusters */
.nodes-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 36px;
    position: relative;
}

/* Marriage / Couple Cluster */
.couple-cluster {
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 24px;
    border: 1px dashed rgba(56, 189, 248, 0.25);
}

.marriage-heart {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(244, 114, 182, 0.15);
    border: 1px solid rgba(244, 114, 182, 0.4);
    color: #f472b6;
    font-size: 0.85rem;
    box-shadow: 0 0 10px rgba(244, 114, 182, 0.3);
    animation: gentle-pulse 2.5s infinite ease-in-out;
}

@keyframes gentle-pulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.1); opacity: 1; }
}

/* Connector Lines (Pure CSS / SVG Hybrid) */
.connector-down {
    width: 2px;
    height: 50px;
    background: linear-gradient(to bottom, var(--tree-line-active), var(--tree-line));
    margin: 0 auto;
    position: relative;
}

.connector-down::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-color);
}

.branch-fork {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.fork-horizontal-line {
    height: 2px;
    background: var(--tree-line-active);
    width: 300px;
    position: relative;
}

.fork-down-stem {
    width: 2px;
    height: 25px;
    background: var(--tree-line-active);
}

/* ==========================================================================
   Family Member Card Node
   ========================================================================== */

.member-node {
    width: 220px;
    background: var(--tree-node-bg);
    border: var(--glass-border);
    backdrop-filter: blur(14px);
    border-radius: 18px;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    box-shadow: var(--tree-shadow);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.member-node:hover {
    transform: translateY(-5px) scale(1.02);
    background: var(--tree-node-hover);
    border-color: var(--accent-color);
}

/* Paternal / Male Card Styling */
.member-node.gender-male {
    border-top: 3px solid var(--tree-paternal);
}

.member-node.gender-male:hover {
    box-shadow: var(--tree-glow-paternal), var(--tree-shadow);
}

/* Maternal / Female Card Styling */
.member-node.gender-female {
    border-top: 3px solid var(--tree-maternal);
}

.member-node.gender-female:hover {
    box-shadow: var(--tree-glow-maternal), var(--tree-shadow);
    border-color: var(--tree-maternal);
}

/* Sounak (Self) Special Golden Glow */
.member-node.is-self {
    border-top: 3px solid var(--tree-self);
    border-color: rgba(251, 191, 36, 0.6);
    box-shadow: var(--tree-glow-self), var(--tree-shadow);
}

.member-node.is-self::after {
    content: 'YOU';
    position: absolute;
    top: -10px;
    right: 12px;
    background: linear-gradient(135deg, #fbbf24, #d97706);
    color: #0f172a;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 10px;
    letter-spacing: 1px;
    box-shadow: 0 2px 6px rgba(251, 191, 36, 0.4);
}

/* Node Avatar & Initials */
.node-avatar {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    position: relative;
    background: var(--secondary-bg);
    border: 2px solid var(--glass-border);
    transition: var(--transition);
}

.gender-male .node-avatar {
    color: var(--tree-paternal);
    border-color: rgba(56, 189, 248, 0.4);
    background: rgba(56, 189, 248, 0.08);
}

.gender-female .node-avatar {
    color: var(--tree-maternal);
    border-color: rgba(244, 114, 182, 0.4);
    background: rgba(244, 114, 182, 0.08);
}

.is-self .node-avatar {
    color: var(--tree-self);
    border-color: rgba(251, 191, 36, 0.6);
    background: rgba(251, 191, 36, 0.12);
}

.node-name {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text-color);
    line-height: 1.25;
}

.node-relation {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}

.gender-female .node-relation {
    color: var(--tree-maternal);
}

.is-self .node-relation {
    color: var(--tree-self);
}

.node-generation-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #94a3b8;
    background: var(--badge-bg);
    padding: 3px 8px;
    border-radius: 12px;
}

/* Highlight search match or lineage trail */
.member-node.highlighted {
    transform: scale(1.06);
    border-color: var(--accent-color);
    box-shadow: 0 0 25px rgba(56, 189, 248, 0.6), var(--tree-shadow);
}

.member-node.lineage-active {
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.5);
    border-color: var(--accent-color);
}

/* ==========================================================================
   Alternative View: Timeline / Generational Milestone List
   ========================================================================== */

.timeline-view-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem 0 3rem;
}

.gen-timeline-block {
    position: relative;
    padding-left: 2.5rem;
    margin-bottom: 3rem;
}

.gen-timeline-block::before {
    content: '';
    position: absolute;
    left: 14px;
    top: 24px;
    bottom: -40px;
    width: 2px;
    background: linear-gradient(to bottom, var(--accent-color), rgba(56, 189, 248, 0.2));
}

.gen-timeline-block:last-child::before {
    display: none;
}

.gen-timeline-marker {
    position: absolute;
    left: 0;
    top: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--secondary-bg);
    border: 2px solid var(--accent-color);
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 800;
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.gen-timeline-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.gen-timeline-header h3 {
    font-size: 1.4rem;
    margin-bottom: 0;
    color: var(--text-color);
}

.gen-timeline-era {
    font-size: 0.85rem;
    color: #94a3b8;
    background: var(--badge-bg);
    padding: 2px 10px;
    border-radius: 12px;
}

.timeline-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.25rem;
}

.timeline-member-card {
    background: var(--card-bg);
    border: var(--glass-border);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 1.25rem;
    cursor: pointer;
    transition: var(--transition);
}

.timeline-member-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent-color);
    box-shadow: var(--tree-shadow);
}

/* ==========================================================================
   Modals & Drawers (Detail Profile & Add Relative)
   ========================================================================== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-backdrop.open {
    opacity: 1;
    visibility: visible;
}

.modal-dialog {
    background: var(--bg-color);
    border: var(--glass-border);
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: translateY(20px) scale(0.97);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
}

.modal-backdrop.open .modal-dialog {
    transform: translateY(0) scale(1);
}

.modal-header {
    padding: 1.5rem 1.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: var(--glass-border);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.25rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

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

.modal-body {
    padding: 1.5rem;
}

/* Detail Modal Specifics */
.profile-hero {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 700;
    background: var(--secondary-bg);
    border: 3px solid var(--accent-color);
}

.profile-title-text h2 {
    font-size: 1.6rem;
    margin-bottom: 0.25rem;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
}

.profile-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.profile-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--secondary-bg);
    color: var(--accent-color);
    border: var(--glass-border);
}

/* Lineage Breadcrumb in Modal */
.lineage-trail {
    background: var(--secondary-bg);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1.25rem;
    border: var(--glass-border);
}

.lineage-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #94a3b8;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.lineage-nodes {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
}

.lineage-node-btn {
    background: var(--card-bg);
    border: var(--glass-border);
    padding: 3px 9px;
    border-radius: 8px;
    color: var(--text-color);
    cursor: pointer;
    transition: var(--transition);
}

.lineage-node-btn:hover {
    color: var(--accent-color);
    border-color: var(--accent-color);
}

.lineage-arrow {
    color: #64748b;
    font-size: 0.75rem;
}

/* Relation Blocks in Profile */
.profile-section {
    margin-bottom: 1.25rem;
}

.profile-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #94a3b8;
    margin-bottom: 0.5rem;
}

.relatives-chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.relative-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--secondary-bg);
    border: var(--glass-border);
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
}

.relative-chip:hover {
    background: var(--accent-color);
    color: #0f172a;
    border-color: var(--accent-color);
}

.profile-bio-box {
    background: var(--secondary-bg);
    border: var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-color);
}

/* Form Styling in Add Relative Modal */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #94a3b8;
    margin-bottom: 0.35rem;
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    border: var(--glass-border);
    background: var(--secondary-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.code-export-box {
    background: #090d16;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #38bdf8;
    border-radius: 10px;
    padding: 1rem;
    font-family: monospace;
    font-size: 0.8rem;
    max-height: 180px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 0.75rem;
}

/* Toast Notification */
.toast-notice {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #0f172a;
    color: #ffffff;
    border: 1px solid var(--accent-color);
    padding: 0.75rem 1.5rem;
    border-radius: 30px;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    z-index: 3000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
}

.toast-notice.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */

@media (max-width: 900px) {
    .generation-label {
        position: static;
        transform: none;
        margin-bottom: 0.75rem;
    }

    .family-hero h1 {
        font-size: 2rem;
    }

    .tree-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group {
        justify-content: center;
    }

    .search-wrapper {
        min-width: 100%;
    }

    .nodes-group {
        gap: 20px;
    }

    .member-node {
        width: 190px;
        padding: 0.9rem;
    }

    .fork-horizontal-line {
        width: 240px;
    }
}

@media (max-width: 600px) {
    .nodes-group {
        flex-direction: column;
        gap: 16px;
    }

    .couple-cluster {
        flex-direction: column;
        gap: 10px;
    }

    .fork-horizontal-line {
        width: 160px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}
