:root {
    --primary: #1877f2;
    --primary-dark: #166ada;
    --primary-light: #4292ff;
    --secondary: #42b72a;
    --secondary-dark: #36a420;
    --background: #f0f2f5;
    --surface: #ffffff;
    --surface-light: #f7f8fa;
    --text: #050505;
    --text-secondary: #65676b;
    --text-muted: #8a8d91;
    --success: #42b72a;
    --warning: #f7b928;
    --error: #f02849;
    --danger: #f02849;
    --border: #ced0d4;
    --shadow: rgba(0, 0, 0, 0.1);
    --header-bg: #ffffff;
    --card-radius: 8px;
    --input-bg: #f5f6f7;
}

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

body {
    font-family: Segoe UI, Helvetica, Arial, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.34;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Header */
header {
    background: var(--header-bg);
    box-shadow: 0 2px 4px var(--shadow);
    padding: 0.5rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    max-width: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 800;
    text-decoration: none;
    color: var(--primary);
    flex-shrink: 0;
}

.header-search {
    flex: 1;
    max-width: 320px;
    margin: 0 1rem;
    position: relative;
    display: none;
    /* Hidden on mobile by default, show on desktop */
}

@media (min-width: 768px) {
    .header-search {
        display: block;
    }
}

.header-search input {
    width: 100%;
    padding: 9px 16px 9px 40px !important;
    background: #f0f2f5 !important;
    border: none !important;
    border-radius: 50px !important;
    font-size: 0.93rem !important;
}

.header-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    pointer-events: none;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    color: white;
}

.logo-text {
    letter-spacing: -1px;
    font-size: 1.8rem;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

nav a {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

nav a:hover {
    background: var(--surface-light);
    color: var(--primary);
}

.nav-icon {
    display: inline-block;
}

.mobile-only {
    display: none;
}

/* User Profile Dropdown */
.user-profile-nav {
    position: relative;
    margin-left: 0.5rem;
}

.badge-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: var(--error);
    border: 2px solid white;
    border-radius: 50%;
}

.badge-small {
    background: var(--error);
    color: white;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: auto;
    font-weight: bold;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text);
    text-decoration: none;
    border-radius: 6px;
    transition: background 0.2s;
}

.user-dropdown-item:hover {
    background: var(--surface-light);
}

.icon-circle {
    width: 36px;
    height: 36px;
    background: #e4e6eb;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.user-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 4px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    background: transparent;
}

.user-toggle:hover {
    background: var(--surface-light);
}

.user-avatar-small {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--surface-light);
    border: 1px solid var(--border);
}

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 280px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 12px 28px 0 rgba(0, 0, 0, 0.2), 0 2px 4px 0 rgba(0, 0, 0, 0.1);
    padding: 8px;
    display: none;
    flex-direction: column;
    z-index: 1000;
}

.user-dropdown.show {
    display: flex;
}

.user-dropdown-header {
    padding: 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.user-dropdown-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border-radius: 8px;
    text-decoration: none;
    transition: background 0.2s;
}

.user-dropdown-info:hover {
    background: var(--surface-light);
}

.user-dropdown-info .name {
    font-weight: 700;
    color: var(--text);
    font-size: 1rem;
}

.user-dropdown-info .view-profile {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.user-dropdown-item:hover {
    background: var(--surface-light);
}

.user-dropdown-item i,
.user-dropdown-item .icon-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e4e6eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px 16px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
    transition: border 0.1s, box-shadow 0.1s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
    background: #fff;
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* Container */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

@media (max-width: 480px) {
    .container {
        padding: 1rem 0.75rem;
    }
}

/* Grid Utilities */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-2,
.grid-3 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.container-full {
    max-width: 100%;
    margin: 0 auto;
    padding: 1rem;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--card-radius);
    padding: 1rem;
    box-shadow: 0 1px 2px var(--shadow);
    margin-bottom: 1rem;
}

.tree-card {
    padding: 0 !important;
    overflow: hidden;
}

.card-header {
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.8rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    color: var(--text);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    gap: 0.4rem;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: #e4e6eb;
    color: #050505;
}

.btn-secondary:hover {
    background: #d8dadf;
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #d32341;
}

/* Member Grid (Facebook Friend List Style) */
.member-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

@media (max-width: 480px) {
    .member-grid {
        grid-template-columns: 1fr;
    }
}

.member-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--card-radius);
    display: flex;
    padding: 1rem;
    gap: 1rem;
    align-items: center;
    transition: background 0.2s;
}

.member-item:hover {
    background: var(--surface-light);
}

.member-photo {
    width: 100px;
    height: 100px;
    border-radius: 8px;
    object-fit: cover;
    background: #e4e6eb;
    flex-shrink: 0;
}

.member-photo.placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 3rem;
}

.member-info {
    flex: 1;
}

.member-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    display: block;
    margin-bottom: 0.2rem;
}

.member-name:hover {
    text-decoration: underline;
}

.member-meta {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.member-actions {
    display: flex;
    gap: 0.5rem;
}

/* Stats */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--card-radius);
    text-align: center;
    box-shadow: 0 1px 2px var(--shadow);
}

.stat-card h3 {
    color: var(--primary);
    font-size: 1.8rem;
    margin-bottom: 0.2rem;
}

.stat-card p {
    color: var(--text-secondary);
    font-weight: 600;
}

/* Profile View */
.profile-header {
    background: var(--surface);
    border-radius: 0 0 8px 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    box-shadow: 0 1px 2px var(--shadow);
}

.cover-photo {
    height: 200px;
    background: linear-gradient(to bottom, #d8dadf, #f0f2f5);
}

.profile-main-info {
    padding: 0 2rem 2rem;
    display: flex;
    gap: 2rem;
    align-items: flex-end;
    margin-top: -80px;
}

.profile-pic-large {
    width: 168px;
    height: 168px;
    border-radius: 50%;
    border: 4px solid var(--surface);
    background: #e4e6eb;
    object-fit: cover;
}

@media (max-width: 768px) {
    .profile-pic-large {
        width: 120px;
        height: 120px;
        border-width: 3px;
    }
}

.profile-name-section h1 {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

@media (max-width: 480px) {
    .profile-name-section h1 {
        font-size: 1.5rem;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .member-grid {
        grid-template-columns: 1fr;
    }

    .profile-main-info {
        flex-direction: column;
        align-items: center;
        text-align: center;
        margin-top: -100px;
    }

    .nav {
        display: block !important;
        position: static;
        width: auto;
        height: auto;
        background: transparent;
        padding: 0;
        z-index: 1;
    }

    .logo-text {
        font-size: 1.4rem;
    }

    .nav ul {
        flex-direction: row;
        gap: 0.1rem;
    }

    .nav-text,
    .desktop-only {
        display: none;
    }

    .mobile-only {
        display: flex;
    }

    .nav a {
        padding: 0.5rem;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
    }

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

    .user-profile-nav {
        margin-top: 0;
        padding: 0;
        border: none;
    }

    .user-dropdown {
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        width: 250px;
        box-shadow: 0 12px 28px 0 rgba(0, 0, 0, 0.2);
        border: none;
    }

    .mobile-search-container {
        display: none !important;
    }
}

/* Spinner */
.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Search Results Page */
.search-result-card {
    display: flex;
    gap: 1rem;
    padding: 1.5rem;
    align-items: center;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.search-result-card:hover {
    background: #f0f2f5;
}

.search-result-info {
    flex: 1;
}

.search-result-name {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
    display: block;
    margin-bottom: 0.2rem;
}

.search-result-name:hover {
    text-decoration: underline;
}

.search-result-meta {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.search-result-actions {
    display: flex;
    gap: 0.5rem;
}

.search-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    background: #e4e6eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(240, 242, 245, 0.85);
    /* Slightly translucent grey background */
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-overlay.show {
    display: flex;
}

.modal-overlay .card {
    box-shadow: 0 12px 28px 0 rgba(0, 0, 0, 0.2), 0 2px 4px 0 rgba(0, 0, 0, 0.1);
    animation: modalAppear 0.3s ease-out;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.add-member-card:hover {
    opacity: 1 !important;
    border-color: var(--primary) !important;
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.05);
}

/* Country Selector Components */
.phone-input-container {
    display: flex;
    align-items: center;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 0 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--surface);
    margin-bottom: 0.5rem;
}

.phone-input-container:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.1);
}

.country-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.5rem 0.6rem 0;
    border-right: 1.5px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.flag-icon {
    width: 24px;
    height: 16px;
    border-radius: 2px;
    object-fit: cover;
}

.country-code {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
}

.dropdown-arrow {
    width: 12px;
    height: 12px;
    color: var(--text-secondary);
}

.phone-field {
    flex: 1;
    border: none;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    background: transparent;
}

.phone-field:focus {
    outline: none;
}

/* Reusable Modal Styles (used by Country Picker) */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: var(--surface);
    margin: 10% auto;
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
}

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

.close {
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-secondary);
}

.close:hover {
    color: var(--text);
}

.search-result-item {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.search-result-item:hover {
    background-color: var(--surface-light);
    border-color: var(--primary);
}

/* Tree Search Components */
.tree-header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    width: 300px;
}

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

.tree-search-input {
    width: 100%;
    padding: 10px 16px 10px 40px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.95rem;
    background: #fff url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="%2365676b" viewBox="0 0 16 16"><path d="M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z"/></svg>') no-repeat 12px center;
    transition: box-shadow 0.2s;
}

.tree-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.1);
}

.tree-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-top: 8px;
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.tree-search-results.show {
    display: block;
}

.tree-search-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    gap: 12px;
    border-bottom: 1px solid #f0f2f5;
    transition: background 0.2s;
}

.tree-search-item:last-child {
    border-bottom: none;
}

.tree-search-item:hover {
    background: var(--surface-light);
}

.tree-search-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: #e4e6eb;
    border: 1px solid var(--border);
}

.tree-search-info h4 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text);
    font-weight: 600;
}

.tree-search-info p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.tree-search-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Pulse Animation for Logged-in User */
@keyframes pulse-user-highlight {
    0% {
        transform: scale(1);
        filter: drop-shadow(0 0 0px var(--primary-light));
    }

    50% {
        transform: scale(1.05);
        filter: drop-shadow(0 0 10px var(--primary-light));
    }

    100% {
        transform: scale(1);
        filter: drop-shadow(0 0 0px var(--primary-light));
    }
}

.pulse-user-circle {
    animation: pulse-user-highlight 3s ease-in-out infinite;
    transform-origin: center;
    transform-box: fill-box;
}

/* Tree Context Menu */
.tree-context-menu {
    position: fixed;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    padding: 4px;
    min-width: 140px;
    animation: menuFadeIn 0.15s ease-out;
}

@keyframes menuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.tree-context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s;
}

.tree-context-menu-item:hover {
    background: var(--surface-light);
    color: var(--primary);
}

.tree-context-menu-item i {
    font-size: 1rem;
    opacity: 0.7;
}