/* ============================================================
   GALALLY FAMILY TREE — Styles
   ============================================================ */

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Tree Wrapper (scrollable viewport) ===== */
.tree-wrapper {
    overflow-x: hidden;
    overflow-y: auto;
    width: 100%;
    min-height: calc(100vh - 68px);
    cursor: grab;
    position: relative;
    touch-action: pan-y;
}

.tree-wrapper:active {
    cursor: grabbing;
}

/* ===== Tree Container ===== */
.tree {
    padding: 50px 60px 100px;
    transform-origin: top center;
    transition: transform 0.25s ease;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ===== Tree Structure (nested ul/li) ===== */
.tree ul {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    width: fit-content;
    padding-top: 35px;
    position: relative;
    list-style: none;
}

.tree > ul {
    padding-top: 0;
}

/* Vertical line from parent down to children row */
.tree ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 35px;
    background: linear-gradient(to bottom, #3F3F46, #27272A);
    border-radius: 1px;
}

.tree > ul::before {
    display: none;
}

/* Each branch */
.tree li {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    padding: 35px 14px 0;
}

/* Horizontal connectors between siblings */
.tree li::before,
.tree li::after {
    content: '';
    position: absolute;
    top: 0;
    height: 2px;
    background: linear-gradient(to right, #3F3F46, #27272A);
    border-radius: 1px;
}

.tree li::before {
    right: 50%;
    width: 50%;
}

.tree li::after {
    left: 50%;
    width: 50%;
}

.tree li:first-child::before {
    display: none;
}

.tree li:last-child::after {
    display: none;
}

.tree li:only-child::before,
.tree li:only-child::after {
    display: none;
}

/* Vertical connector from horizontal bar down to node */
.node-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0;
}

.node-wrapper::before {
    content: '';
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 35px;
    background: linear-gradient(to bottom, #27272A, #3F3F46);
    border-radius: 1px;
}

.tree > ul > li > .node-wrapper::before {
    display: none;
}

/* ===== Marriage Connector ===== */
.marriage-connector {
    width: 24px;
    height: 2px;
    background: linear-gradient(to right, #3F3F4655, #F472B688, #3F3F4655);
    position: relative;
    flex-shrink: 0;
}

.marriage-connector::after {
    content: '♥';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 8px;
    color: #F472B6;
    line-height: 1;
}

/* ===== Person Card ===== */
.person-card {
    position: relative;
    width: 150px;
    padding: 18px 12px 14px;
    background: #1A1A1A;
    border-radius: 18px;
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.3),
        0 4px 16px rgba(0, 0, 0, 0.4);
    text-align: center;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(255, 255, 255, 0.06);
    cursor: default;
    flex-shrink: 0;
}

/* Level badge */
.level-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: #71717A;
    font-size: 0.55rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.person-card:hover {
    transform: translateY(-5px);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.4),
        0 12px 36px rgba(0, 0, 0, 0.5);
    border-color: rgba(255, 255, 255, 0.12);
}

/* Gender accent borders */
.person-card.male {
    border-color: rgba(96, 165, 250, 0.15);
}

.person-card.male:hover {
    border-color: rgba(96, 165, 250, 0.4);
}

.person-card.female {
    border-color: rgba(244, 114, 182, 0.15);
}

.person-card.female:hover {
    border-color: rgba(244, 114, 182, 0.4);
}

/* Expandable cards */
.person-card.expandable {
    cursor: pointer;
    padding-bottom: 28px;
}

.person-card.expandable:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.person-card.is-expanded {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.3),
        0 4px 16px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

.person-card.is-expanded.male {
    border-color: rgba(96, 165, 250, 0.3);
}

.person-card.is-expanded.female {
    border-color: rgba(244, 114, 182, 0.3);
}

/* Expand indicator at bottom of card */
.expand-indicator {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 2px 10px;
    border-radius: 10px 10px 0 0;
    background: rgba(255, 255, 255, 0.04);
    cursor: pointer;
    transition: all 0.25s ease;
}

.expand-indicator:hover {
    background: rgba(255, 255, 255, 0.08);
}

.expand-chevron {
    width: 12px;
    height: 12px;
    color: #71717A;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.expand-indicator.expanded .expand-chevron {
    transform: rotate(180deg);
}

.child-count {
    font-size: 0.6rem;
    font-weight: 700;
    color: #38BDF8;
    min-width: 12px;
    text-align: center;
    line-height: 1;
    text-shadow: 0 0 6px rgba(56, 189, 248, 0.5);
}

.expand-indicator.expanded .child-count {
    color: #22D3EE;
    text-shadow: 0 0 8px rgba(34, 211, 238, 0.6), 0 0 16px rgba(34, 211, 238, 0.3);
}

.expand-indicator.expanded .expand-chevron {
    color: #22D3EE;
    filter: drop-shadow(0 0 4px rgba(34, 211, 238, 0.5));
}

/* Deceased styling */
.person-card.deceased {
    opacity: 0.7;
}

.person-card.deceased .person-photo {
    filter: grayscale(30%);
}

/* ===== Person Photo ===== */
.person-photo {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    margin: 0 auto 10px;
    overflow: hidden;
    border: 3px solid #2A2A2A;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.person-card:hover .person-photo {
    border-color: #3F3F46;
    box-shadow: 0 3px 14px rgba(255, 255, 255, 0.08);
}

.person-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.person-photo .avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.male .person-photo .avatar-placeholder {
    background: linear-gradient(135deg, #1E293B, #1E3A5F);
}

.female .person-photo .avatar-placeholder {
    background: linear-gradient(135deg, #2D1B2E, #3F1B3D);
}

/* ===== Person Name ===== */
.person-name {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 600;
    font-size: 0.85rem;
    color: #FAFAFA;
    line-height: 1.3;
    margin-bottom: 3px;
    word-wrap: break-word;
}

/* ===== Person Dates ===== */
.person-dates {
    font-size: 0.68rem;
    color: #71717A;
    font-weight: 500;
    letter-spacing: 0.02em;
}

/* ===== Card Action Buttons (hover, when logged in) ===== */
.card-actions {
    position: absolute;
    top: -10px;
    right: -10px;
    display: flex;
    gap: 3px;
    opacity: 0;
    transform: scale(0.7) translateY(4px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    pointer-events: none;
}

.person-card:hover .card-actions {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: all;
}

.action-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.action-btn svg {
    width: 13px;
    height: 13px;
}

.action-btn.add-child {
    background: #10B981;
    color: white;
}

.action-btn.add-child:hover {
    background: #059669;
    transform: scale(1.15);
}

.action-btn.edit {
    background: #C9A96E;
    color: white;
}

.action-btn.edit:hover {
    background: #B89555;
    transform: scale(1.15);
}

.action-btn.delete {
    background: #EF4444;
    color: white;
}

.action-btn.delete:hover {
    background: #DC2626;
    transform: scale(1.15);
}

/* Add spouse mini button */
.add-spouse-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px dashed rgba(139, 115, 85, 0.25);
    background: transparent;
    color: rgba(139, 115, 85, 0.35);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    margin-left: 8px;
    flex-shrink: 0;
}

.add-spouse-btn:hover {
    border-color: #C9A96E;
    color: #C9A96E;
    background: rgba(201, 169, 110, 0.08);
    transform: scale(1.1);
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    text-align: center;
    padding: 40px 20px;
}

/* ===== Modals ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    padding: 16px;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    position: relative;
    background: #1A1A1A;
    border-radius: 24px;
    padding: 32px;
    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.4),
        0 25px 60px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transform: translateY(20px) scale(0.95);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 90vh;
    overflow-y: auto;
    width: 100%;
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

/* ===== Toast ===== */
#toast.show {
    display: block !important;
    animation: toastSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1),
               toastSlideOut 0.4s cubic-bezier(0.4, 0, 0.2, 1) 2.6s forwards;
}

#toast .success {
    background: linear-gradient(135deg, #065F46, #047857);
    color: white;
}

#toast .error {
    background: linear-gradient(135deg, #991B1B, #B91C1C);
    color: white;
}

#toast .info {
    background: linear-gradient(135deg, #27272A, #3F3F46);
    color: white;
}

@keyframes toastSlideIn {
    from { opacity: 0; transform: translate(-50%, 24px); }
    to   { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes toastSlideOut {
    from { opacity: 1; transform: translate(-50%, 0); }
    to   { opacity: 0; transform: translate(-50%, 24px); }
}

/* ===== Card Entrance Animations ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.person-card {
    animation: fadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) backwards;
}

.tree li:nth-child(1) .person-card { animation-delay: 0.02s; }
.tree li:nth-child(2) .person-card { animation-delay: 0.06s; }
.tree li:nth-child(3) .person-card { animation-delay: 0.10s; }
.tree li:nth-child(4) .person-card { animation-delay: 0.14s; }
.tree li:nth-child(5) .person-card { animation-delay: 0.18s; }
.tree li:nth-child(6) .person-card { animation-delay: 0.22s; }

/* ===== Background Decoration ===== */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(96, 165, 250, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(255, 255, 255, 0.02) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(244, 114, 182, 0.02) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* ===== Scrollbar ===== */
.tree-wrapper::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.tree-wrapper::-webkit-scrollbar-track {
    background: transparent;
}

.tree-wrapper::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.tree-wrapper::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Modal scrollbar */
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.modal-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .tree {
        padding: 30px 5px 80px;
    }

    /* Wrap children rows — max 3 per row */
    .tree ul {
        flex-wrap: wrap;
        max-width: 270px;
        margin: 0 auto;
        justify-content: center;
    }

    .tree > ul {
        max-width: none;
    }

    /* Hide horizontal connectors on mobile (they break with wrapping) */
    .tree li::before,
    .tree li::after {
        display: none;
    }

    /* Simpler vertical connector from parent */
    .tree ul::before {
        height: 20px;
    }

    .node-wrapper::before {
        height: 20px;
        top: -20px;
    }

    .tree li {
        padding: 20px 3px 0;
    }

    .person-card {
        width: 80px;
        padding: 8px 4px 6px;
        border-radius: 12px;
    }

    .level-badge {
        width: 14px;
        height: 14px;
        font-size: 0.45rem;
        top: 3px;
        right: 3px;
    }

    .person-card.expandable {
        padding-bottom: 16px;
    }

    .expand-indicator {
        padding: 1px 6px;
        gap: 2px;
    }

    .expand-chevron {
        width: 8px;
        height: 8px;
    }

    .child-count {
        font-size: 0.5rem;
        min-width: 8px;
    }

    .person-photo {
        width: 34px;
        height: 34px;
        margin-bottom: 4px;
    }

    .person-name {
        font-size: 0.6rem;
        line-height: 1.2;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .person-dates {
        font-size: 0.5rem;
    }

    .tree ul::before {
        height: 20px;
    }

    .modal-content {
        padding: 24px;
        border-radius: 20px;
    }

    .marriage-connector {
        width: 10px;
    }

    .add-spouse-btn {
        display: none;
    }
}

/* ===== Selection ===== */
::selection {
    background: rgba(255, 255, 255, 0.2);
    color: #FAFAFA;
}

/* ===== Search Highlight (persistent glow) ===== */
.person-card.search-highlight {
    box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.5), 0 0 12px rgba(56, 189, 248, 0.25);
    border-color: rgba(56, 189, 248, 0.6) !important;
}

.person-card.search-highlight-animate {
    animation: searchPulseIn 0.6s ease-out;
}

@keyframes searchPulseIn {
    0% {
        box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.7), 0 0 20px rgba(56, 189, 248, 0.4);
    }
    60% {
        box-shadow: 0 0 0 8px rgba(56, 189, 248, 0), 0 0 25px rgba(56, 189, 248, 0.15);
    }
    100% {
        box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.5), 0 0 12px rgba(56, 189, 248, 0.25);
    }
}

/* ===== Search Results scrollbar ===== */
#search-results::-webkit-scrollbar {
    width: 4px;
}

#search-results::-webkit-scrollbar-track {
    background: transparent;
}

#search-results::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* ===== Focus Visible ===== */
:focus-visible {
    outline: 2px solid #3F3F46;
    outline-offset: 2px;
    border-radius: 8px;
}
