/* ===== KHANDAN.US - FAMILY TREE APP ===== */
/* Beautiful light, pastel UI */

:root {
    --primary: #6C63FF;
    --primary-light: #8B85FF;
    --primary-pale: #EEEdFF;
    --accent: #FF6B9D;
    --accent-light: #FFB3CC;
    --success: #4ECDC4;
    --warning: #FFE66D;
    --danger: #FF6B6B;
    --bg: #F8F9FE;
    --bg-card: #FFFFFF;
    --text: #2D3436;
    --text-light: #636E72;
    --text-lighter: #B2BEC3;
    --border: #E8ECF4;
    --shadow: 0 2px 16px rgba(108, 99, 255, 0.08);
    --shadow-hover: 0 8px 30px rgba(108, 99, 255, 0.15);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --font: 'Nunito', sans-serif;
    --male-color: #74B9FF;
    --female-color: #FD79A8;
    --male-bg: #E8F4FD;
    --female-bg: #FDE8F0;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 4px; }

/* ===== HEADER ===== */
.header {
    background: white;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 10px rgba(0,0,0,0.04);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 64px;
    gap: 32px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.logo i { font-size: 1.6rem; }
.logo small { font-weight: 400; color: var(--text-light); font-size: 0.7em; }

.nav {
    display: flex;
    gap: 4px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.nav-link:hover { background: var(--primary-pale); color: var(--primary); }
.nav-link.active { background: var(--primary); color: white; }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text);
    cursor: pointer;
    padding: 8px;
}

/* Auth buttons */
.auth-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: var(--font);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.25s ease;
}

.auth-user {
    color: var(--primary);
    font-weight: 700;
    font-size: 0.9rem;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: var(--font);
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(108, 99, 255, 0.3);
}
.btn-primary:hover {
    background: var(--primary-light);
    box-shadow: 0 6px 20px rgba(108, 99, 255, 0.4);
    transform: translateY(-2px);
}

.btn-secondary {
    background: white;
    color: var(--primary);
    border: 2px solid var(--primary);
}
.btn-secondary:hover {
    background: var(--primary-pale);
}

.btn-accent {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 157, 0.3);
}
.btn-accent:hover { background: #FF5290; transform: translateY(-2px); }

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

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover { background: #FF5252; }

.btn-ghost {
    background: transparent;
    color: var(--text-light);
}
.btn-ghost:hover { background: var(--border); color: var(--text); }

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

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-icon { padding: 8px 10px; }

/* ===== HERO ===== */
.hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 24px;
    gap: 40px;
}

.hero-content { flex: 1; }

.hero-title {
    font-size: 2.8rem;
    font-weight: 800;
    line-height: 1.2;
    margin-bottom: 16px;
    color: var(--text);
}

.brand { color: var(--primary); }

.hero-sub {
    font-size: 1.15rem;
    color: var(--text-light);
    margin-bottom: 32px;
    max-width: 500px;
    line-height: 1.7;
}

.hero-actions { display: flex; gap: 16px; flex-wrap: wrap; }

.hero-illustration {
    flex-shrink: 0;
}

.tree-icon-big {
    width: 250px;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-pale), #F0E6FF);
    animation: floatIcon 4s ease-in-out infinite;
}

.tree-icon-big i {
    font-size: 8rem;
    color: var(--primary);
    opacity: 0.7;
}

@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
}

/* ===== STATS ===== */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto 40px;
    padding: 0 24px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 28px 24px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    border: 1px solid var(--border);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-pale);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 12px;
    font-size: 1.4rem;
    color: var(--primary);
}

.stat-card:nth-child(2) .stat-icon { background: #FFE8F0; color: var(--accent); }
.stat-card:nth-child(3) .stat-icon { background: #E8FFF8; color: var(--success); }

.stat-number {
    font-size: 2.2rem;
    font-weight: 800;
    color: var(--text);
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 600;
}

/* ===== SECTIONS ===== */
.section {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px 40px;
}

.section-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.section-title i { color: var(--primary); }

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px 24px;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-header h1 i { color: var(--primary); }

/* ===== SEARCH ===== */
.search-box {
    display: flex;
    align-items: center;
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 16px;
    gap: 10px;
    transition: border-color 0.3s;
    min-width: 280px;
}

.search-box:focus-within { border-color: var(--primary); }

.search-box i { color: var(--text-lighter); }

.search-box input {
    border: none;
    outline: none;
    font-family: var(--font);
    font-size: 0.95rem;
    padding: 10px 0;
    width: 100%;
    background: transparent;
}

/* ===== MEMBER CARDS ===== */
.members-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

.member-card {
    background: white;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.35s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    animation: fadeInUp 0.5s ease;
}

.member-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-hover);
    border-color: var(--primary-light);
}

.member-card.male { border-top: 3px solid var(--male-color); }
.member-card.female { border-top: 3px solid var(--female-color); }

.member-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 14px;
    border: 3px solid var(--border);
    flex-shrink: 0;
}

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

.member-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.member-avatar .avatar-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--text-lighter);
}

.member-avatar.male .avatar-icon { color: var(--male-color); }
.member-avatar.female .avatar-icon { color: var(--female-color); }

.member-name {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.member-info {
    font-size: 0.8rem;
    color: var(--text-light);
    display: flex;
    align-items: center;
    gap: 4px;
}

.member-dates {
    font-size: 0.78rem;
    color: var(--text-lighter);
    margin-top: 4px;
}

/* ===== FORM ===== */
.member-form {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px 40px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 0;
}

.form-group {
    margin-bottom: 20px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 6px;
}

.form-group label i {
    color: var(--primary);
    font-size: 0.85rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.95rem;
    color: var(--text);
    background: white;
    transition: all 0.3s ease;
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.1);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-lighter);
}

.select-nice {
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    background: white;
    cursor: pointer;
    outline: none;
    color: var(--text);
}

.select-nice:focus { border-color: var(--primary); }

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.file-input {
    padding: 12px !important;
    background: var(--bg) !important;
}

.photo-preview {
    margin-top: 12px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    max-width: 200px;
}

.photo-preview img {
    max-width: 100%;
    border-radius: var(--radius-sm);
}

/* ===== PROFILE ===== */
.profile-card {
    max-width: 900px;
    margin: 32px auto;
    padding: 0 24px;
}

.profile-header {
    background: white;
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    gap: 32px;
    align-items: flex-start;
    margin-bottom: 24px;
}

.profile-avatar {
    width: 140px;
    height: 140px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 4px solid var(--border);
    position: relative;
}

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

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar .avatar-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
}

.profile-avatar.male .avatar-icon { color: var(--male-color); }
.profile-avatar.female .avatar-icon { color: var(--female-color); }

.profile-avatar .photo-btn {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s;
}

.profile-avatar .photo-btn:hover { background: var(--primary-light); transform: scale(1.1); }

.profile-details { flex: 1; }

.profile-name {
    font-size: 1.8rem;
    font-weight: 800;
    margin-bottom: 4px;
}

.profile-meta {
    color: var(--text-light);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.profile-meta i { color: var(--primary); margin-right: 4px; }

.profile-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.profile-info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-light);
}

.profile-info-item i {
    color: var(--primary);
    width: 18px;
    text-align: center;
}

.profile-bio {
    background: var(--bg);
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-light);
    line-height: 1.7;
    margin-bottom: 20px;
}

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

/* Relationships section */
.relations-section {
    background: white;
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.relations-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.relations-title i { color: var(--primary); }

.relation-group { margin-bottom: 20px; }
.relation-group:last-child { margin-bottom: 0; }

.relation-group-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-lighter);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.relation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.25s;
}

.relation-item:hover {
    background: var(--primary-pale);
    transform: translateX(4px);
}

.relation-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

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

.relation-avatar img { width: 100%; height: 100%; object-fit: cover; }

.relation-avatar .avatar-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.relation-avatar.male .avatar-icon { color: var(--male-color); }
.relation-avatar.female .avatar-icon { color: var(--female-color); }

.relation-name { font-weight: 700; font-size: 0.9rem; }

.relation-delete {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-lighter);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.relation-delete:hover {
    color: var(--danger);
    background: #FFF0F0;
}

/* ===== TREE ===== */
.tree-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tree-container {
    max-width: 100%;
    margin: 0 24px 40px;
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: auto;
    min-height: 500px;
    position: relative;
    cursor: grab;
    touch-action: pan-x pan-y;
}
.tree-container.grabbing { cursor: grabbing; }

.tree-canvas {
    padding: 40px;
    min-width: fit-content;
    transform-origin: top left;
    transition: transform 0.3s ease;
    display: inline-block;
    user-select: none;
}

/* Tree nodes */
.tree-node-group {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tree-couple {
    display: flex;
    align-items: center;
    gap: 0;
    margin-bottom: 0;
}

.tree-couple-link {
    width: 30px;
    height: 3px;
    background: var(--accent-light);
    position: relative;
}

.tree-couple-link::after {
    content: '\f004';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    color: var(--accent);
    font-size: 0.7rem;
}

.tree-node {
    background: white;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    text-align: center;
    min-width: 140px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.tree-node:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-hover);
    transform: translateY(-3px);
}

.tree-node.male { border-top: 3px solid var(--male-color); }
.tree-node.female { border-top: 3px solid var(--female-color); }

.tree-node.deceased { opacity: 0.7; }
.tree-node.deceased::after {
    content: '\f005';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: -8px;
    right: -4px;
    font-size: 0.6rem;
    color: var(--text-lighter);
}

.tree-node-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin: 0 auto 8px;
    overflow: hidden;
    border: 2px solid var(--border);
}

.tree-node-avatar.male { border-color: var(--male-color); background: var(--male-bg); }
.tree-node-avatar.female { border-color: var(--female-color); background: var(--female-bg); }

.tree-node-avatar img { width: 100%; height: 100%; object-fit: cover; }

.tree-node-avatar .avatar-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.tree-node-avatar.male .avatar-icon { color: var(--male-color); }
.tree-node-avatar.female .avatar-icon { color: var(--female-color); }

.tree-node-name {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text);
    white-space: nowrap;
}

.tree-node-dates {
    font-size: 0.7rem;
    color: var(--text-lighter);
}

.tree-children {
    display: flex;
    gap: 20px;
    padding-top: 20px;
    position: relative;
}

.tree-children::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 20px;
    background: var(--border);
}

.tree-children-line {
    position: absolute;
    top: 20px;
    height: 2px;
    background: var(--border);
}

.tree-child-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.tree-child-branch::before {
    content: '';
    width: 2px;
    height: 20px;
    background: var(--border);
    margin-bottom: 0;
}

/* Vertical connector from couple down to children horizontal trunk */
.tree-vertical-connector {
    width: 2px;
    height: 24px;
    background: var(--border);
    margin: 0 auto;
}

/* Sibling row with pure-CSS org-chart connectors (no inline JS math) */
.tree-children-wrapper {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 20px;
    position: relative;
}

.tree-child-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 12px;
    position: relative;
}

/* Horizontal trunk: border-top on ::before, half-masked for first/last children */
.tree-child-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--border);
}
.tree-child-item:first-child::before { left: 50%; }
.tree-child-item:last-child::before { right: 50%; }
.tree-child-item:only-child::before { display: none; }

/* Vertical drop to the node */
.tree-child-item::after {
    content: '';
    width: 2px;
    height: 20px;
    background: var(--border);
    margin-bottom: 0;
}

/* Collapsed state */
.tree-node-group.collapsed > .tree-vertical-connector,
.tree-node-group.collapsed > .tree-children-wrapper { display: none; }

/* Collapse caret */
.tree-collapse-btn {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: white;
    color: var(--primary);
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    box-shadow: var(--shadow);
}
.tree-collapse-btn:hover { background: var(--primary-pale); }

/* Stub node (truncated subtree) */
.tree-node-stub {
    background: var(--primary-pale);
    border: 2px dashed var(--primary-light);
    border-radius: var(--radius);
    padding: 12px 14px;
    min-width: 120px;
    text-align: center;
    cursor: pointer;
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 600;
}
.tree-node-stub:hover { background: white; border-color: var(--primary); }
.tree-node-stub i { margin-right: 4px; }

.tree-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-lighter);
}

.tree-empty i {
    font-size: 4rem;
    margin-bottom: 16px;
    color: var(--border);
}

.tree-empty p {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ===== MODALS ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: none;
    animation: fadeIn 0.25s ease;
}

.modal-overlay.active { display: block; }

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    background: white;
    border-radius: var(--radius);
    padding: 32px;
    z-index: 201;
    min-width: 400px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    display: none;
    opacity: 0;
    transition: all 0.3s ease;
}

.modal.active {
    display: block;
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-header h2 i { color: var(--primary); }

.modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-lighter);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.2s;
}

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

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 14px 28px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 300;
    opacity: 0;
    transition: all 0.4s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--text-lighter);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: 40px;
}

.footer i { color: var(--accent); }

/* ===== PAGES ===== */
.page { display: none; }
.page.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== GED IMPORT ===== */
.modal-wide { max-width: 560px; }

.ged-hint {
    font-size: 0.8rem;
    color: var(--text-lighter);
    margin-top: 8px;
    line-height: 1.5;
}

.ged-preview {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin: 16px 0 0;
    border: 1px solid var(--border);
}

.ged-preview-stat {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.ged-preview-stat:last-child { border-bottom: none; }
.ged-preview-stat i { color: var(--primary); width: 20px; text-align: center; }
.ged-preview-stat strong { margin-left: auto; color: var(--text); }

.ged-result {
    padding: 16px;
    border-radius: var(--radius-sm);
    margin-top: 12px;
    font-size: 0.9rem;
    font-weight: 600;
}

.ged-result.success { background: #E8FFF8; color: #00B894; border: 1px solid #4ECDC4; }
.ged-result.error { background: #FFF0F0; color: var(--danger); border: 1px solid var(--danger); }

.nav-link-danger { color: var(--danger) !important; }
.nav-link-danger:hover { background: #FFF0F0 !important; }

/* ===== GED file dropzone ===== */
.file-input-hidden {
    position: absolute;
    width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.ged-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 32px 20px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, #FBFAFF 0%, #F4F2FE 100%);
    color: var(--text);
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, background 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.ged-dropzone:hover {
    border-color: var(--primary);
    background: linear-gradient(180deg, #F4F2FE 0%, #ECE7FE 100%);
}
.ged-dropzone:active { transform: scale(0.995); }
.ged-dropzone.drag-over {
    border-color: var(--primary);
    background: #ECE7FE;
    box-shadow: 0 0 0 6px rgba(108,99,255,0.08) inset;
}
.ged-dropzone.has-file {
    border-style: solid;
    border-color: var(--success);
    background: #F1FFFB;
}

.ged-dropzone-icon {
    width: 56px; height: 56px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 6px 18px rgba(108,99,255,0.14);
    display: flex; align-items: center; justify-content: center;
    color: var(--primary);
    font-size: 1.5rem;
    margin-bottom: 4px;
}
.ged-dropzone.has-file .ged-dropzone-icon {
    color: var(--success);
    box-shadow: 0 6px 18px rgba(78,205,196,0.25);
}
.ged-dropzone-title { font-weight: 700; font-size: 0.95rem; }
.ged-dropzone-title strong { color: var(--primary); }
.ged-dropzone-sub { font-size: 0.82rem; color: var(--text-lighter); }
.ged-dropzone-file {
    display: none;
    margin-top: 8px;
    padding: 8px 14px;
    background: white;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--success);
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    max-width: 100%;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ged-dropzone.has-file .ged-dropzone-file { display: inline-block; }
.ged-dropzone.has-file .ged-dropzone-sub { display: none; }

/* ===== MOBILE BOTTOM NAV ===== */
.mobile-bottom-nav {
    display: none !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--border);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}

.mbn-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 4px;
    flex: 1;
    cursor: pointer;
    color: var(--text-lighter);
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
}

.mbn-item i {
    font-size: 1.1rem;
    margin-bottom: 1px;
}

.mbn-item.active { color: var(--primary); }
.mbn-item:active { color: var(--primary-light); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .nav { display: none; }
    .nav.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 64px;
        left: 0;
        right: 0;
        background: white;
        padding: 16px;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 8px 20px rgba(0,0,0,0.05);
        animation: slideDown 0.3s ease;
        z-index: 99;
    }
    .mobile-menu-btn { display: block; }
    .mobile-bottom-nav { display: flex !important; }

    body { padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px)); }

    .toast {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    }

    .hero {
        flex-direction: column;
        text-align: center;
        padding: 32px 20px;
        gap: 24px;
    }
    .hero-sub { margin: 0 auto 24px; }
    .hero-actions { justify-content: center; }
    .hero-title { font-size: 2rem; }
    .tree-icon-big { width: 130px; height: 130px; }
    .tree-icon-big i { font-size: 4rem; }

    .form-row { grid-template-columns: 1fr; }
    .profile-header { flex-direction: column; align-items: center; text-align: center; }
    .profile-info-grid { grid-template-columns: 1fr; }
    .profile-actions { justify-content: center; }

    .modal { min-width: auto; padding: 24px; }
    .members-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

    .page-header { flex-direction: column; align-items: flex-start; }
    .search-box { min-width: auto; width: 100%; }
    .tree-controls { flex-wrap: wrap; gap: 8px; }
    .tree-controls .select-nice { width: 100%; }

    /* Tree: make container full-width, touch-scrollable */
    .tree-container {
        margin: 0 0 80px;
        border-radius: 0;
        border-left: none;
        border-right: none;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x pan-y;
    }

    .tree-canvas { padding: 24px; }

    /* Profile actions stacked on mobile */
    .profile-actions .btn { flex: 1; justify-content: center; min-width: 0; }

    /* Relations section */
    .relations-section { border-radius: var(--radius-sm); }

    /* Stats row */
    .stats-row { grid-template-columns: repeat(3, 1fr); gap: 12px; }
    .stat-card { padding: 16px 12px; }
    .stat-number { font-size: 1.6rem; }
    .stat-icon { width: 40px; height: 40px; font-size: 1rem; }

    /* Footer hidden on mobile (bottom nav replaces it) */
    .footer { display: none; }

    /* Modals: bottom sheet on mobile */
    .modal {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        border-radius: var(--radius) var(--radius) 0 0;
        max-width: 100%;
        width: 100%;
        padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
        max-height: 90vh;
        overflow-y: auto;
    }
    .modal.active {
        transform: none;
    }
    .modal-overlay.active { display: block; }
}

@media (max-width: 480px) {
    .header-inner { padding: 0 16px; gap: 16px; }
    .logo span { font-size: 1.2rem; }
    .hero-title { font-size: 1.5rem; }
    .btn-lg { padding: 12px 18px; font-size: 0.9rem; }
    .members-grid { grid-template-columns: 1fr 1fr; padding: 0 12px; gap: 12px; }
    .stats-row { padding: 0 12px; gap: 10px; }
    .section { padding: 0 12px 40px; }
    .member-card { padding: 16px 12px; }
    .member-avatar { width: 60px; height: 60px; }
    .member-name { font-size: 0.9rem; }
    .profile-card { padding: 0 12px; margin: 16px auto; }
    .profile-header { padding: 24px 20px; gap: 16px; }
    .profile-name { font-size: 1.4rem; }
    .profile-avatar { width: 100px; height: 100px; }
    .tree-node { min-width: 110px; padding: 10px 12px; }
    .tree-node-avatar { width: 40px; height: 40px; }
    .tree-node-name { font-size: 0.75rem; }
    .page-header { padding: 20px 12px 16px; }
    .member-form { padding: 0 12px 40px; }
    .members-grid { grid-template-columns: 1fr; }
}

/* ===== TREE TYPEAHEAD + VIEW MODE ===== */
.tree-search {
    position: relative;
    min-width: 260px;
    flex: 1;
    max-width: 420px;
}
.tree-search input[type="search"] {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-family: inherit;
    background: white;
    transition: border-color 0.2s;
}
.tree-search input[type="search"]:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-pale);
}
.tree-search::before {
    content: '\f002';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    position: absolute;
    top: 50%;
    left: 14px;
    transform: translateY(-50%);
    color: var(--text-lighter);
    font-size: 0.85rem;
    z-index: 1;
}
.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    max-height: 420px;
    overflow-y: auto;
    z-index: 50;
    display: none;
}
.search-results.open { display: block; }
.search-result {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: var(--primary-pale); }
.search-result-name {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text);
}
.search-result-meta {
    font-size: 0.75rem;
    color: var(--text-lighter);
    margin-top: 2px;
}
.search-result-meta em {
    font-style: normal;
    color: var(--primary);
    font-weight: 600;
}
.search-result-group {
    padding: 6px 14px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-lighter);
    background: var(--bg);
    font-weight: 700;
}

/* View-mode toggle */
.view-mode-toggle {
    display: inline-flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.view-mode-toggle button {
    padding: 6px 14px;
    border: none;
    background: transparent;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-light);
    font-family: inherit;
}
.view-mode-toggle button.active {
    background: var(--primary);
    color: white;
}

/* Gen-nav bar (focus mode) */
.gen-nav-bar {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 20px;
    margin: 0 24px 8px;
    background: var(--primary-pale);
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.gen-nav-bar.active { display: flex; }
.gen-nav-bar .gen-nav-center {
    font-weight: 700;
    color: var(--primary);
}
.gen-nav-bar button {
    padding: 6px 12px;
    border: 1px solid var(--primary-light);
    background: white;
    color: var(--primary);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.8rem;
    font-family: inherit;
}
.gen-nav-bar button:hover { background: var(--primary); color: white; }
.gen-nav-bar button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Focus-mode row layout */
.focus-row {
    display: flex;
    gap: 16px;
    justify-content: center;
    align-items: flex-start;
    margin: 12px 0;
    position: relative;
}
.focus-row-label {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-lighter);
    font-weight: 700;
}
.focus-row-inner {
    display: flex;
    gap: 16px;
    justify-content: center;
    flex-wrap: wrap;
}
.focus-connector {
    width: 2px;
    height: 24px;
    background: var(--border);
    margin: 0 auto;
}
.focus-node-wrap { display: flex; flex-direction: column; align-items: center; }
.focus-node-wrap .tree-node.focus-highlight {
    border: 2px solid var(--accent);
    box-shadow: 0 0 0 4px var(--accent-light);
}

/* ===== SHARE MODAL / SHARE PAGE ===== */
.share-list { margin: 12px 0; }
.share-item {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
    background: var(--bg);
}
.share-item-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.share-item-url {
    font-family: monospace;
    font-size: 0.82rem;
    color: var(--primary);
    background: white;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    word-break: break-all;
}
.share-item-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.share-trees-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.share-tree-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: white;
    border-radius: 6px;
    font-size: 0.88rem;
}
.share-tree-row .remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 0.9rem;
}
.share-add-tree {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    align-items: center;
}
.share-add-tree .tree-search { min-width: 0; flex: 1; max-width: none; }
.share-body { background: var(--bg); }
.share-header { position: sticky; top: 0; z-index: 10; }
.share-title {
    font-weight: 700;
    color: var(--primary);
    flex: 1;
    text-align: center;
    font-size: 1.05rem;
}
.share-main { padding: 24px 0; }
.share-tree-section {
    margin: 0 24px 32px;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.share-tree-section h2 {
    padding: 16px 20px;
    margin: 0;
    font-size: 1.1rem;
    border-bottom: 1px solid var(--border);
    background: var(--primary-pale);
    color: var(--primary);
}
.share-tree-section .tree-container {
    margin: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
}
.share-status { text-align: center; padding: 40px; color: var(--text-lighter); }

@media (max-width: 768px) {
    .tree-search { min-width: 0; max-width: none; }
    .gen-nav-bar { margin: 0 12px 8px; flex-wrap: wrap; }
    .share-item-url { font-size: 0.75rem; }
    .view-mode-toggle button { padding: 5px 10px; font-size: 0.75rem; }
}

