/* ========================================
   GLOBAL STYLES & VARIABLES
   ======================================== */

:root {
    --bl-primary: #be123c;
    /* Soothing Rose 700 */
    --bl-primary-hover: #9f1239;
    /* Rose 800 */
    --bl-secondary: #f472b6;
    /* Soft Pink/Peach 400 */
    --bl-accent: #fbcfe8;
    /* Soft Pink/Peach 200 */
    --bl-deep-red: #4c0519;
    /* Deep Maroon/Rose 950 */
    --bl-slate: #0f172a;
    --bl-gradient-main: linear-gradient(135deg, #4c0519 0%, #0f172a 100%);
    --bl-gradient-brand: linear-gradient(135deg, #be123c 0%, #fb923c 100%);
    --bl-glass: rgba(255, 255, 255, 0.05);
    --bl-glass-border: rgba(255, 255, 255, 0.1);
}

html {
    scroll-behavior: smooth;
}

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

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at 0% 0%, rgba(220, 38, 38, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(251, 146, 60, 0.15) 0%, transparent 50%),
        var(--bl-gradient-main);
    background-attachment: fixed;
    min-height: 100vh;
    width: 100vw;
    margin: 0;
    padding: 0;
    /* Safe area handled by individual layout containers (.main-layout or admin #container) */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    overflow-y: visible;
    /* Allow browser scroll */
    color: #f8fafc;
    display: flex;
    flex-direction: column;
}

.main-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: calc(65px + env(safe-area-inset-top, 0));
    /* Matched to nav height */
    overflow-y: visible;
}

.content-wrapper {
    flex: 1;
    /* Critical for flex scrolling */
    display: flex;
    flex-direction: column;
    overflow-y: visible;
}

/* ========================================
   SCROLLBAR STYLING (Premium Look)
   ======================================== */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.5);
}

::-webkit-scrollbar-thumb {
    background: rgba(190, 18, 60, 0.2);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(190, 18, 60, 0.4);
}

/* ========================================
   TREE CONTAINER
   ======================================== */

#family-tree-root {
    width: 100%;
    margin: 0 auto;
    transition: opacity 0.3s ease;
    position: relative;
    padding-bottom: 10px;
}

.tree-container {
    position: relative;
    padding: 40px 20px;
    min-height: 500px;
    /* Reduced from 100vh to avoid huge empty spaces */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

/* ========================================
   ROWS AND COLUMNS
   ======================================== */

.row {
    display: flex;
    gap: 45px;
    /* Increased from 20px */
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.row.middle {
    gap: 80px;
    /* Increased from 40px */
}

.column {
    display: flex;
    flex-direction: column;
    gap: 35px;
    /* Increased from 15px */
    align-items: center;
}

/* ========================================
   INVITATION BANNER
   ======================================== */

.invite-banner {
    position: fixed;
    top: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.8);
    backdrop-filter: blur(12px);
    padding: 12px 24px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 3000;
    animation: bannerSlideDown 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(190, 18, 60, 0.2);
    color: #f8fafc;
}

@keyframes bannerSlideDown {
    from {
        transform: translate(-50%, -100px);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* Badges */
.badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 5px;
    vertical-align: middle;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-registered {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.4);
}

.badge-unregistered {
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
    border: 1px solid rgba(100, 116, 139, 0.4);
}

.banner-content {
    display: flex;
    align-items: center;
    gap: 20px;
    font-size: 14px;
}

.banner-actions {
    display: flex;
    gap: 10px;
}

.btn-banner-accept {
    background: #48bb78;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
}

/* ========================================
   NAVIGATION BAR (Consolidated)
   ======================================== */

.app-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 65px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(15px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: env(safe-area-inset-top, 0) 20px 0;
    height: calc(65px + env(safe-area-inset-top, 0));
    z-index: 2000;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    overflow: visible;
    /* CRITICAL: allow dropdown to escape */
}

.app-nav::-webkit-scrollbar,
.nav-actions::-webkit-scrollbar {
    display: none;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    flex-shrink: 0;
}

.nav-logo {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.nav-brand-text {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--bl-gradient-brand);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-admin-badge {
    background: rgba(190, 18, 60, 0.2);
    color: #fca5a5;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid rgba(190, 18, 60, 0.3);
    letter-spacing: 1px;
    margin-left: 5px;
}

.nav-search-container {
    display: flex;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 6px 12px;
    max-width: 400px;
    min-width: 140px;
    flex: 1;
    margin: 0 15px;
}

.nav-icon-group {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 10px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-icon-group:last-of-type {
    border-right: none;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

#global-search-input {
    width: 100%;
    background: transparent;
    border: none;
    color: white;
    outline: none;
    font-size: 0.9rem;
    padding: 4px 8px;
}

.nav-welcome {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--bl-secondary);
    margin-right: 15px;
    padding: 4px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: inline-flex;
    align-items: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.nav-welcome:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding: 5px 10px;
    flex: 2;
    /* Increased importance for actions */
    justify-content: flex-end;
    min-width: 0;
}

.nav-actions::-webkit-scrollbar {
    display: none;
}

@media (max-width: 768px) {
    .nav-brand-text {
        display: none !important;
    }

    .nav-search-container {
        margin: 0 10px;
        flex: 0 1 auto;
        width: 140px;
        max-width: 180px;
        min-width: 100px;
    }

    .nav-actions {
        gap: 12px;
        flex: 1;
        justify-content: flex-start;
        padding-right: 20px;
        display: flex;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        min-width: 0;
    }

    .nav-welcome {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .nav-search-container {
        width: 110px;
        max-width: 130px;
        min-width: 90px;
    }

    .nav-actions {
        gap: 8px;
    }
}

/* ========================================
   GLOBAL SEARCH & MODALS
   ======================================== */

.search-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: 100%;
    min-width: 280px;
    /* Ensure results aren't truncated by parent width on mobile */
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-height: 400px;
    overflow-y: auto;
    z-index: 9999;
}

@media (max-width: 768px) {
    .nav-search-container {
        position: static;
    }

    .search-input-wrapper {
        position: static;
    }

    .search-dropdown {
        /* Detach from the small input and anchor to the viewport edges */
        position: fixed;
        top: calc(65px + env(safe-area-inset-top, 0px) + 8px);
        left: 12px;
        right: 12px;
        width: auto;
        min-width: 0;
        max-width: none;
        max-height: 55vh;
        border-radius: 14px;
        z-index: 9999;
    }
}

.search-dropdown.hidden {
    display: none;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.search-result-item img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.search-result-item .result-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #fff;
}

.search-result-item .result-meta {
    font-size: 0.75rem;
    color: #94a3b8;
}

/* Standardized Navigation Icons */
.nav-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    color: #94a3b8;
    flex-shrink: 0;
}

.nav-icon-btn img {
    width: 22px;
    height: 22px;
    object-fit: contain;
}

.nav-icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.btn-signout:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-admin:hover {
    background: rgba(251, 146, 60, 0.15);
    border-color: rgba(251, 146, 60, 0.3);
}



.reaction-names-list {
    background: rgba(15, 23, 42, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    padding: 12px;
    margin-top: 10px;
    font-size: 0.85rem;
    box-shadow: 0 4px 25px rgba(0, 0, 0, 0.7);
    z-index: 1000;
    position: relative;
    display: block;
}

.reaction-names-list.hidden {
    display: none !important;
}

.reaction-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.names-list {
    color: #f8fafc;
    font-weight: 600;
}

/* ========================================
   GLOBAL FOOTER
   ======================================== */

.app-footer {
    position: relative;
    clear: both !important;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 30px 20px calc(30px + env(safe-area-inset-bottom, 0));
    margin-top: auto; /* Standard push to bottom */
    width: 100%;
    color: #94a3b8;
    z-index: 10;
}

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

.footer-links {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    gap: 20px;
}

.footer-links a {
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.85rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--bl-accent);
}

.footer-socials {
    display: flex;
    gap: 15px;
}

.footer-socials a {
    color: #94a3b8;
    transition: transform 0.2s, color 0.2s;
    display: flex;
    align-items: center;
}

.footer-socials a:hover {
    color: var(--bl-secondary);
    transform: translateY(-2px);
}

.footer-bottom {
    max-width: 1200px;
    margin: 15px auto 0;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
}