/* ============================================================
   Balan Genealogy v2  –  Premium Mobile-First Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-darker: #047857;
    --primary-light: #d1fae5;
    --primary-lighter: #ecfdf5;
    --primary-gradient: linear-gradient(135deg, #34d399, #059669);
    --primary-gradient-vibrant: linear-gradient(135deg, #6ee7b7 0%, #10b981 50%, #047857 100%);
    --accent: #6366f1;
    --accent-dark: #4f46e5;
    --accent-light: #e0e7ff;
    --accent-gradient: linear-gradient(135deg, #818cf8, #6366f1);
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --error: #ef4444;
    --error-light: #fee2e2;
    --success: #22c55e;
    --info: #3b82f6;
    --info-light: #dbeafe;

    --background: #f8fafc;
    --surface: #ffffff;
    --surface-alt: #f1f5f9;
    --surface-raised: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;

    --radius-xs: 8px;
    --radius-sm: 12px;
    --radius-md: 16px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-sm: 0 2px 8px -2px rgba(0,0,0,0.06), 0 1px 4px -1px rgba(0,0,0,0.04);
    --shadow-md: 0 8px 24px -4px rgba(0,0,0,0.08), 0 4px 8px -2px rgba(0,0,0,0.04);
    --shadow-lg: 0 20px 40px -8px rgba(0,0,0,0.1), 0 8px 16px -4px rgba(0,0,0,0.06);
    --shadow-xl: 0 25px 50px -12px rgba(0,0,0,0.15);
    --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.15);
    --shadow-primary: 0 4px 14px rgba(16, 185, 129, 0.35);
    --shadow-accent: 0 4px 14px rgba(99, 102, 241, 0.35);

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

    --font-xs: 0.7rem;
    --font-sm: 0.8rem;
    --font-base: 0.95rem;
    --font-md: 1rem;
    --font-lg: 1.25rem;
    --font-xl: 1.5rem;
    --font-2xl: 1.75rem;
}

[data-theme="dark"] {
    --background: #0c1222;
    --surface: #1a2332;
    --surface-alt: #151d2b;
    --surface-raised: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --border: #2d3a4d;
    --border-light: #1e293b;
    --primary-light: #064e3b;
    --primary-lighter: #022c22;
    --accent-light: #312e81;
    --warning-light: #78350f;
    --error-light: #7f1d1d;
    --info-light: #1e3a5f;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-sm: 0 2px 8px -2px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 24px -4px rgba(0,0,0,0.4);
    --shadow-lg: 0 20px 40px -8px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.1);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --background: #0c1222;
        --surface: #1a2332;
        --surface-alt: #151d2b;
        --surface-raised: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-tertiary: #64748b;
        --border: #2d3a4d;
        --border-light: #1e293b;
        --primary-light: #064e3b;
        --primary-lighter: #022c22;
        --accent-light: #312e81;
        --warning-light: #78350f;
        --error-light: #7f1d1d;
        --info-light: #1e3a5f;
        --shadow-xs: 0 1px 2px rgba(0,0,0,0.2);
        --shadow-sm: 0 2px 8px -2px rgba(0,0,0,0.3);
        --shadow-md: 0 8px 24px -4px rgba(0,0,0,0.4);
        --shadow-lg: 0 20px 40px -8px rgba(0,0,0,0.5);
        --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.1);
    }
}

html[data-font-size="large"] { font-size: 110%; }
html[data-font-size="small"] { font-size: 90%; }

/* ---- Reset ---- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background:
        radial-gradient(ellipse at top left, rgba(16, 185, 129, 0.08), transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(99, 102, 241, 0.05), transparent 50%),
        var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-bottom: 88px;
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
}
body.drawer-open {
    overflow: hidden;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast), opacity var(--transition-fast);
}
a:active { opacity: 0.7; }

img { max-width: 100%; height: auto; }

/* ---- App Shell ---- */
.app-container {
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    min-height: 100vh;
    min-height: 100dvh;
}

/* ---- Top Utility Bar ---- */
.top-utility-bar {
    position: sticky;
    top: 0;
    z-index: 60;
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 16px 8px;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0.95), rgba(248, 250, 252, 0.85));
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}
[data-theme="dark"] .top-utility-bar {
    background: linear-gradient(180deg, rgba(12, 18, 34, 0.95), rgba(12, 18, 34, 0.85));
    border-bottom-color: rgba(45, 58, 77, 0.5);
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .top-utility-bar {
        background: linear-gradient(180deg, rgba(12, 18, 34, 0.95), rgba(12, 18, 34, 0.85));
        border-bottom-color: rgba(45, 58, 77, 0.5);
    }
}

.top-utility-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text-primary);
    padding: 10px 16px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-fast);
}
.top-utility-button:active {
    transform: scale(0.95);
    box-shadow: var(--shadow-xs);
}

.top-utility-pills {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
    mask-image: linear-gradient(to right, transparent 0, black 0, black calc(100% - 20px), transparent 100%);
    -webkit-mask-image: linear-gradient(to right, transparent 0, black 0, black calc(100% - 20px), transparent 100%);
}
.top-utility-pills::-webkit-scrollbar { display: none; }

.utility-pill {
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 16px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    box-shadow: var(--shadow-xs);
    transition: all var(--transition-fast);
    text-decoration: none;
}
.utility-pill:active {
    transform: scale(0.95);
}
.utility-pill.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: var(--shadow-primary);
}

/* ---- Header ---- */
.app-header {
    position: sticky;
    top: 49px;
    background: rgba(255, 255, 255, 0.82);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 50;
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    border-bottom: 1px solid rgba(226, 232, 240, 0.4);
}
[data-theme="dark"] .app-header {
    background: rgba(26, 35, 50, 0.85);
    border-bottom-color: rgba(45, 58, 77, 0.4);
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .app-header {
        background: rgba(26, 35, 50, 0.85);
        border-bottom-color: rgba(45, 58, 77, 0.4);
    }
}
.app-header h1 {
    font-size: var(--font-lg);
    font-weight: 800;
    letter-spacing: -0.03em;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 480px;
    margin: 0 auto;
    background: var(--surface);
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: space-around;
    padding: 6px 4px 0;
    z-index: 100;
    padding-bottom: max(env(safe-area-inset-bottom, 8px), 8px);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-tertiary);
    font-size: 0.6rem;
    font-weight: 600;
    gap: 3px;
    padding: 6px 12px 4px;
    flex: 1;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    position: relative;
    -webkit-tap-highlight-color: transparent;
    text-decoration: none;
}
.nav-item:active {
    transform: scale(0.9);
}
.nav-item.active {
    color: var(--primary);
    font-weight: 700;
}
.nav-item.active::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    background: var(--primary-gradient);
    border-radius: 0 0 3px 3px;
}
.nav-item.active .nav-icon {
    filter: drop-shadow(0 2px 4px rgba(16, 185, 129, 0.3));
}
.nav-icon {
    width: 22px;
    height: 22px;
    transition: all var(--transition-fast);
}

/* ---- Page Content ---- */
.page-content {
    padding: 20px 16px;
}

.page-intro {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}
.page-kicker {
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    display: flex;
    align-items: center;
    gap: 6px;
}
.page-kicker::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 3px;
    background: var(--primary-gradient);
    border-radius: 2px;
}
.page-intro h2 {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -0.03em;
    margin-top: 6px;
}
.page-intro p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-top: 6px;
    line-height: 1.5;
}

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px 20px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    border: 1px solid var(--border-light);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
    position: relative;
    overflow: hidden;
}
.card-compact {
    padding: 18px 16px;
}
.card-muted {
    background: linear-gradient(135deg, rgba(241,245,249,0.8), rgba(248,250,252,0.95));
    border-color: transparent;
}
[data-theme="dark"] .card-muted {
    background: linear-gradient(135deg, rgba(26,35,50,0.9), rgba(21,29,43,0.95));
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .card-muted {
        background: linear-gradient(135deg, rgba(26,35,50,0.9), rgba(21,29,43,0.95));
    }
}
.card:active {
    transform: scale(0.985);
}
.card:hover {
    box-shadow: var(--shadow-md);
}
.card-gradient {
    background: linear-gradient(135deg, #34d399 0%, #059669 50%, #047857 100%);
    color: white;
    border: none;
    box-shadow: var(--shadow-md), 0 4px 20px rgba(5, 150, 105, 0.3);
}
.card-gradient::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255,255,255,0.12), transparent 70%);
    pointer-events: none;
}
.card-glass {
    background: rgba(255,255,255,0.65);
    backdrop-filter: blur(20px) saturate(1.5);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    border-color: rgba(255,255,255,0.4);
}
[data-theme="dark"] .card-glass {
    background: rgba(30, 41, 59, 0.65);
    border-color: rgba(45, 58, 77, 0.4);
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .card-glass {
        background: rgba(30, 41, 59, 0.65);
        border-color: rgba(45, 58, 77, 0.4);
    }
}

/* Card accent stripe */
.card-accent-top {
    border-top: 3px solid var(--primary);
}
.card-accent-left {
    border-left: 3px solid var(--primary);
}

/* ---- Forms & Inputs ---- */
.form-group {
    margin-bottom: 20px;
}
.form-label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.form-control {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-base);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
}
.form-control::placeholder {
    color: var(--text-tertiary);
}
.form-control:hover {
    border-color: var(--text-tertiary);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.12);
    background: var(--surface);
}
select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}
textarea.form-control {
    min-height: 80px;
    line-height: 1.5;
    resize: vertical;
}
.form-hint {
    font-size: var(--font-xs);
    color: var(--text-tertiary);
    margin-top: 6px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 14px 24px;
    font-family: inherit;
    font-size: var(--font-md);
    font-weight: 700;
    letter-spacing: 0.01em;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
    position: relative;
    overflow: hidden;
}
.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,0.1), transparent);
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.btn:hover::after {
    opacity: 1;
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.btn:active {
    transform: scale(0.97) translateY(0);
    box-shadow: var(--shadow-sm);
}
.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: var(--shadow-primary);
}
.btn-primary:active {
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}
.btn-outline {
    background: transparent;
    border: 2px solid var(--border);
    color: var(--text-primary);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-lighter);
}
.btn-outline:active {
    background: var(--primary-light);
}
.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
}
.btn-ghost:hover {
    background: var(--surface-alt);
    color: var(--text-primary);
    box-shadow: none;
}
.btn-sm {
    padding: 8px 16px;
    font-size: 0.82rem;
    width: auto;
    border-radius: var(--radius-sm);
}
.btn-icon {
    width: auto;
    padding: 10px;
    border-radius: var(--radius-full);
    background: var(--surface-alt);
    border: 1px solid var(--border-light);
}
.btn-icon:hover {
    background: var(--primary-light);
    color: var(--primary-dark);
    box-shadow: none;
}
/* Loading state */
.btn.loading {
    pointer-events: none;
    opacity: 0.7;
}
.btn.loading::before {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 4px;
}

/* ---- Avatars ---- */
.avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--primary-dark);
    flex-shrink: 0;
    border: 2.5px solid var(--surface);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast);
}
.avatar-lg {
    width: 80px;
    height: 80px;
    font-size: 1.8rem;
    border-width: 3px;
    box-shadow: var(--shadow-md);
}
.avatar-sm {
    width: 38px;
    height: 38px;
    font-size: 0.85rem;
    border-width: 2px;
}
.avatar-male { background: linear-gradient(135deg, #dbeafe, #bfdbfe); color: #2563eb; }
.avatar-female { background: linear-gradient(135deg, #fce7f3, #fbcfe8); color: #db2777; }
[data-theme="dark"] .avatar-male { background: linear-gradient(135deg, #1e3a5f, #1e40af); color: #93c5fd; }
[data-theme="dark"] .avatar-female { background: linear-gradient(135deg, #831843, #9d174d); color: #f9a8d4; }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .avatar-male { background: linear-gradient(135deg, #1e3a5f, #1e40af); color: #93c5fd; }
    html:not([data-theme="light"]) .avatar-female { background: linear-gradient(135deg, #831843, #9d174d); color: #f9a8d4; }
}

/* Avatar ring for important profiles */
.avatar-ring {
    box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--primary);
}

/* ---- Badges ---- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: var(--font-xs);
    font-weight: 700;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-admin { background: var(--accent-light); color: var(--accent); }
.badge-member { background: var(--primary-light); color: var(--primary-dark); }
.badge-warning { background: var(--warning-light); color: #92400e; }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-danger { background: var(--error-light); color: var(--error); }
.badge-success { background: var(--primary-light); color: var(--primary-dark); }

/* ---- List Items ---- */
.list-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    transition: all var(--transition-fast);
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
}
.list-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: var(--primary-gradient);
    transition: width var(--transition-fast);
}
.list-item:hover::before {
    width: 3px;
}
.list-item:hover {
    background: var(--surface-alt);
    padding-left: 22px;
}
.list-item:active {
    background: var(--border-light);
}
.list-item:last-child {
    border-bottom: none;
}
.list-item-body {
    flex: 1;
    min-width: 0;
}
.list-item-title {
    font-weight: 700;
    font-size: var(--font-base);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.list-item-subtitle {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.4;
}
.list-item-chevron {
    color: var(--text-tertiary);
    flex-shrink: 0;
    transition: transform var(--transition-fast);
}
.list-item:hover .list-item-chevron {
    transform: translateX(2px);
    color: var(--primary);
}

/* ---- Section Headers ---- */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
    margin-bottom: 14px;
}
.section-title {
    font-size: var(--font-md);
    font-weight: 800;
    letter-spacing: -0.01em;
}
.section-action {
    font-size: var(--font-sm);
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all var(--transition-fast);
}
.section-action:hover {
    gap: 6px;
}

/* ---- Quick Actions Grid ---- */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 22px 14px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 2px solid var(--border-light);
    text-decoration: none;
    color: inherit;
    transition: all var(--transition-normal);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.action-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary-gradient);
    opacity: 0;
    transition: opacity var(--transition-normal);
}
.action-card:active {
    transform: scale(0.95);
}
.action-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: var(--shadow-md), var(--shadow-glow);
}
.action-card:hover::after {
    opacity: 0.04;
}
.action-card-icon {
    font-size: 2rem;
    line-height: 1;
    position: relative;
    z-index: 1;
}
.action-card-label {
    font-weight: 700;
    font-size: 0.85rem;
    position: relative;
    z-index: 1;
}

/* ---- Stats Row ---- */
.stats-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.stat-chip {
    flex: 1;
    text-align: center;
    padding: 16px 10px;
    background: var(--surface);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}
.stat-chip::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-gradient);
    opacity: 0;
    transition: opacity var(--transition-normal);
}
.stat-chip:hover::before {
    opacity: 1;
}
.stat-chip:hover {
    border-color: rgba(16, 185, 129, 0.2);
    box-shadow: var(--shadow-sm), var(--shadow-glow);
    transform: translateY(-2px);
}
.stat-number {
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    line-height: 1;
}
.stat-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 6px;
    font-weight: 600;
}

/* ---- Horizontal Scroll ---- */
.scroll-row {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin: 0 -16px;
    padding-left: 16px;
    padding-right: 16px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.scroll-row::-webkit-scrollbar { display: none; }
.scroll-card {
    min-width: 140px;
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* ---- Alert / Toast ---- */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 4px solid transparent;
    animation: slideDown 0.3s ease-out;
}
.alert-error {
    background: var(--error-light);
    color: var(--error);
    border-left-color: var(--error);
}
.alert-success {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-left-color: var(--primary);
}
.alert-warning {
    background: var(--warning-light);
    color: #92400e;
    border-left-color: var(--warning);
}
.alert-info {
    background: var(--info-light);
    color: var(--info);
    border-left-color: var(--info);
}
[data-theme="dark"] .alert-warning { color: #fbbf24; }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .alert-warning { color: #fbbf24; }
}
[data-theme="dark"] .badge-warning { color: #fbbf24; }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .badge-warning { color: #fbbf24; }
}

/* ---- Toast Notifications ---- */
.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 448px;
    pointer-events: none;
}
.toast {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    pointer-events: auto;
    animation: toastIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.toast-out {
    animation: toastOut 0.3s ease-in forwards;
}
.toast-success { border-left: 4px solid var(--primary); color: var(--primary-dark); }
.toast-error { border-left: 4px solid var(--error); color: var(--error); }
.toast-info { border-left: 4px solid var(--info); color: var(--info); }

.inline-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--text-secondary);
    font-size: var(--font-sm);
}
.pill-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.soft-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    transition: all var(--transition-fast);
    text-decoration: none;
}
.soft-pill:active {
    transform: scale(0.95);
}
.soft-pill.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.soft-pill:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.list-card {
    padding: 0;
    overflow: hidden;
}

.list-item-meta {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.helper-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
}

/* ---- Divider ---- */
.divider {
    height: 1px;
    background: var(--border-light);
    margin: 16px 0;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}
.empty-state-icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    display: block;
    filter: grayscale(0.2);
}
.empty-state-text {
    color: var(--text-secondary);
    font-size: var(--font-base);
    margin-bottom: 20px;
    line-height: 1.5;
}

/* ---- Swipe Container ---- */
.swipe-container {
    touch-action: pan-y;
    transition: transform var(--transition-slow);
}

/* ---- Admin Section ---- */
.admin-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px dashed var(--border);
}
.admin-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-gradient);
    color: white;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    box-shadow: var(--shadow-accent);
}

/* ---- Toggle Switch ---- */
.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border-light);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-label {
    font-size: 0.9rem;
    font-weight: 600;
}
.toggle-value {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ---- Info Grid ---- */
.info-grid {
    display: grid;
    gap: 14px;
}
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-light);
}
.info-row:last-child { border-bottom: none; }
.info-label {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.info-value {
    font-weight: 700;
    font-size: var(--font-base);
    text-align: right;
}

/* ---- Relation Chip ---- */
.relation-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.relation-parent { background: #dbeafe; color: #2563eb; }
.relation-child { background: #fef3c7; color: #d97706; }
.relation-spouse { background: #fce7f3; color: #db2777; }
.relation-sibling { background: #e0e7ff; color: #6366f1; }
[data-theme="dark"] .relation-parent { background: #1e3a5f; color: #60a5fa; }
[data-theme="dark"] .relation-child { background: #78350f; color: #fbbf24; }
[data-theme="dark"] .relation-spouse { background: #831843; color: #f472b6; }
[data-theme="dark"] .relation-sibling { background: #312e81; color: #a5b4fc; }
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .relation-parent { background: #1e3a5f; color: #60a5fa; }
    html:not([data-theme="light"]) .relation-child { background: #78350f; color: #fbbf24; }
    html:not([data-theme="light"]) .relation-spouse { background: #831843; color: #f472b6; }
    html:not([data-theme="light"]) .relation-sibling { background: #312e81; color: #a5b4fc; }
}

/* ---- Profile Hero ---- */
.profile-hero {
    text-align: center;
    padding: 32px 20px 24px;
    position: relative;
}
.profile-hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: var(--primary-gradient);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    opacity: 0.12;
}
.profile-hero .avatar {
    position: relative;
    z-index: 1;
    margin: 0 auto 16px;
}

/* ---- Event Card ---- */
.event-card {
    min-width: 165px;
    max-width: 210px;
    flex: 0 0 auto;
    scroll-snap-align: start;
    padding: 16px;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--border-light);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}
.event-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.event-card-today {
    border-color: var(--primary);
    background: var(--primary-lighter);
}
.event-card-today::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-gradient);
}
.event-card-icon {
    font-size: 1.6rem;
    margin-bottom: 10px;
    line-height: 1;
}
.event-card-name {
    font-size: var(--font-base);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.event-card-type {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-bottom: 10px;
}
.event-card-date {
    display: inline-flex;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: var(--radius-full);
}
.event-card-today .event-card-date {
    background: var(--primary);
    color: white;
}

/* ---- Notification Card ---- */
.notification-item {
    display: flex;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border-light);
    align-items: flex-start;
    transition: all var(--transition-fast);
}
.notification-item:last-child { border-bottom: none; }
.notification-unread {
    background: var(--primary-lighter);
    border-left: 3px solid var(--primary);
}
.notification-read {
    opacity: 0.65;
}

/* ---- Login Page ---- */
.login-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px 16px;
    position: relative;
    margin-bottom: -88px;
}
.login-wrapper::before {
    content: '';
    position: absolute;
    top: -100px;
    left: -100px;
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.15), transparent 70%);
    pointer-events: none;
}
.login-wrapper::after {
    content: '';
    position: absolute;
    bottom: -50px;
    right: -50px;
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.1), transparent 70%);
    pointer-events: none;
}
.login-logo {
    width: 72px;
    height: 72px;
    border-radius: var(--radius-lg);
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    box-shadow: var(--shadow-primary);
    position: relative;
}
.login-card {
    width: 100%;
    max-width: 380px;
    position: relative;
    z-index: 1;
}

/* ---- Password Toggle ---- */
.password-wrapper {
    position: relative;
}
.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    display: flex;
}

/* ---- Search Input Enhanced ---- */
.search-wrapper {
    position: relative;
}
.search-wrapper .search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    transition: color var(--transition-fast);
    pointer-events: none;
}
.search-wrapper .form-control:focus ~ .search-icon,
.search-wrapper .form-control:focus + .search-icon {
    color: var(--primary);
}
.search-input {
    padding-left: 46px !important;
    border-radius: var(--radius-full) !important;
}
.search-count {
    font-size: var(--font-xs);
    color: var(--text-tertiary);
    font-weight: 600;
    text-align: center;
    padding: 8px;
}

/* ---- Utilities ---- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.gap-sm { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    box-shadow: var(--shadow-md), 0 0 0 4px rgba(16, 185, 129, 0.15);
}
.p-3 { padding: 0.75rem; }

/* ---- Animations ---- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.animate-in {
    animation: fadeInUp 0.4s ease-out both;
}
.animate-in:nth-child(1) { animation-delay: 0.04s; }
.animate-in:nth-child(2) { animation-delay: 0.08s; }
.animate-in:nth-child(3) { animation-delay: 0.12s; }
.animate-in:nth-child(4) { animation-delay: 0.16s; }
.animate-in:nth-child(5) { animation-delay: 0.2s; }
.animate-in:nth-child(6) { animation-delay: 0.24s; }
.animate-in:nth-child(7) { animation-delay: 0.28s; }

.animate-scale {
    animation: scaleIn 0.35s ease-out both;
}

/* ---- Skeleton for loading ---- */
@keyframes shimmer {
    to { background-position: -200% 0; }
}
.skeleton {
    background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

/* ---- Responsive polish ---- */
@media (min-width: 481px) {
    .app-container {
        border-left: 1px solid var(--border-light);
        border-right: 1px solid var(--border-light);
        box-shadow: -1px 0 20px rgba(0,0,0,0.03), 1px 0 20px rgba(0,0,0,0.03);
    }
}

/* ---- Confirmation Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}
.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}
.modal-sheet {
    background: var(--surface);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 24px 20px 32px;
    width: 100%;
    max-width: 480px;
    transform: translateY(100%);
    transition: transform var(--transition-slow);
    box-shadow: var(--shadow-xl);
}
.modal-overlay.active .modal-sheet {
    transform: translateY(0);
}
.modal-handle {
    width: 40px;
    height: 5px;
    background: var(--border);
    border-radius: 3px;
    margin: 0 auto 20px;
}

/* ---- Drawer ---- */
.menu-fab {
    position: fixed;
    right: max(16px, calc((100vw - 480px) / 2 + 16px));
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--accent-gradient);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-accent), var(--shadow-lg);
    cursor: pointer;
    z-index: 120;
    transition: all var(--transition-normal);
}
.menu-fab:hover {
    transform: scale(1.08);
}
.menu-fab:active {
    transform: scale(0.92);
}

.app-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 220;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}
.app-drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.app-drawer {
    position: absolute;
    inset: 0 0 0 auto;
    width: min(85vw, 340px);
    background: var(--surface);
    box-shadow: var(--shadow-xl);
    padding: 20px 16px 40px;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform var(--transition-slow);
}
.app-drawer-overlay.active .app-drawer {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}
.drawer-title {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.drawer-subtitle {
    color: var(--text-tertiary);
    font-size: var(--font-sm);
    margin-top: 4px;
}
.drawer-section + .drawer-section {
    margin-top: 20px;
}
.drawer-section-label {
    color: var(--text-tertiary);
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
    padding-left: 14px;
}
.drawer-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-weight: 600;
    font-size: var(--font-base);
    transition: all var(--transition-fast);
    text-decoration: none;
}
.drawer-link:hover {
    background: var(--surface-alt);
}
.drawer-link.active {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 700;
}
.drawer-link-icon {
    width: 20px;
    height: 20px;
    opacity: 0.7;
    flex-shrink: 0;
}
.drawer-link.active .drawer-link-icon {
    opacity: 1;
}

@media (max-width: 380px) {
    .app-header {
        top: 46px;
    }
    .menu-fab {
        width: 48px;
        height: 48px;
    }
}

/* ---- Checkbox / Radio Enhanced ---- */
.choice-group {
    display: flex;
    gap: 12px;
}
.choice-card {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-weight: 600;
    font-size: 0.9rem;
}
.choice-card:hover {
    border-color: var(--primary);
}
.choice-card:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-lighter);
}
.choice-card input {
    accent-color: var(--primary);
}

/* ---- Duplicate Warning ---- */
.duplicate-warning {
    background: var(--warning-light);
    color: #92400e;
    border-radius: var(--radius-md);
    border: 1px solid #fcd34d;
    border-left: 4px solid var(--warning);
    padding: 14px 16px;
    font-size: 0.85rem;
    margin-bottom: 20px;
}
.duplicate-warning strong {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}
.duplicate-warning ul {
    margin-left: 18px;
    margin-top: 6px;
}
.duplicate-warning li {
    margin-bottom: 4px;
    line-height: 1.5;
}
[data-theme="dark"] .duplicate-warning {
    background: var(--warning-light);
    color: #fbbf24;
    border-color: #92400e;
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) .duplicate-warning {
        background: var(--warning-light);
        color: #fbbf24;
        border-color: #92400e;
    }
}

/* ---- Relationship Visual ---- */
.relation-visual {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
}
.relation-visual:last-child { border-bottom: none; }
.relation-person {
    flex: 1;
    font-weight: 700;
    font-size: 0.88rem;
    line-height: 1.3;
}
.relation-person:first-child { text-align: right; }
.relation-person:last-child { text-align: left; }
.relation-connector {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

/* ---- Scrollbar styling ---- */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* ---- Focus visible for accessibility ---- */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ===== Flipbook ===== */
.flipbook-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
    height: calc(100dvh - 140px);
    background: var(--bg-secondary);
    position: relative;
}
.flipbook-container:fullscreen {
    height: 100vh;
    height: 100dvh;
    background: #1a1a1a;
}
.flipbook-container:fullscreen .flipbook-toolbar {
    background: rgba(0,0,0,0.8);
}
.flipbook-container:fullscreen .flipbook-page-info {
    color: #fff;
}
.flipbook-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 5;
}
.flipbook-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.flipbook-btn:active {
    transform: scale(0.92);
    background: var(--bg-tertiary);
}
.flipbook-page-info {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 60px;
    text-align: center;
    user-select: none;
}
.flipbook-viewport {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    -webkit-overflow-scrolling: touch;
}
.flipbook-book {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.flipbook-page {
    display: none;
    width: 100%;
    justify-content: center;
    align-items: flex-start;
    min-height: 200px;
}
.flipbook-page img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.2s ease;
    user-select: none;
    -webkit-user-drag: none;
}
.flipbook-slider-wrap {
    padding: 8px 16px 12px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.flipbook-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-tertiary);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}
.flipbook-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--bg-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: grab;
}
.flipbook-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--bg-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: grab;
}
/* TOC Overlay */
.flipbook-toc {
    position: absolute;
    bottom: 50px;
    left: 8px;
    right: 8px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: 20;
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}
.flipbook-toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.flipbook-toc-list {
    padding: 8px 0;
}
.flipbook-toc-item {
    display: block;
    padding: 10px 16px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
}
.flipbook-toc-item:active {
    background: var(--bg-tertiary);
}

/* ==========================================================================
   Final edition additions: events calendar, heritage, visual tree,
   accessibility for larger fonts and easier tapping.
   ========================================================================== */

/* Extra-large font mode for easier reading */
html[data-font-size="x-large"] { font-size: 125%; }

/* Filter chips (events calendar) */
.filter-chip-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 10px;
    margin-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.filter-chip-row::-webkit-scrollbar { display: none; }
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 10px 16px;
    min-height: 44px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 1.5px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    text-decoration: none;
    transition: all 150ms ease;
}
.filter-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.filter-chip-count {
    background: rgba(0,0,0,0.12);
    border-radius: var(--radius-full);
    padding: 1px 8px;
    font-size: 0.72rem;
}
.filter-chip.active .filter-chip-count { background: rgba(255,255,255,0.25); }

/* Event calendar date badge */
.event-date-badge {
    width: 46px;
    height: 46px;
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1.1;
}
.event-date-badge-today {
    background: var(--primary);
    color: #fff;
}
.event-date-day { font-size: 1rem; font-weight: 800; }
.event-date-month { font-size: 0.62rem; font-weight: 700; text-transform: uppercase; opacity: 0.75; }

/* View mode toggle (visual tree / list) */
.view-toggle {
    display: flex;
    background: var(--surface-alt);
    border-radius: var(--radius-full);
    padding: 4px;
    margin-bottom: 16px;
    gap: 4px;
}
.view-toggle-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 150ms ease;
}
.view-toggle-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

/* Visual family tree */
.tree-visual-hint {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}
.tree-visual-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px 12px;
    margin-bottom: 22px;
    overflow: hidden;
}
.tree-generation { text-align: center; }
.tree-gen-label {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    background: var(--surface-alt);
    border-radius: var(--radius-full);
    padding: 4px 12px;
    margin-bottom: 10px;
}
.tree-node-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 4px 2px 10px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.tree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-width: 96px;
    max-width: 120px;
    padding: 12px 8px;
    background: var(--surface-alt);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text-primary);
    flex-shrink: 0;
    transition: all 150ms ease;
}
.tree-node:active { transform: scale(0.97); }
.tree-node-self {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}
.tree-node-unlinked { opacity: 0.75; border-style: dashed; }
.tree-node-name {
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.25;
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.tree-node-years { font-size: 0.68rem; color: var(--text-tertiary); }
.tree-gen-connector {
    color: var(--primary);
    opacity: 0.6;
    padding: 4px 0 10px;
}

/* Easier tapping for older family members */
.list-item { min-height: 56px; }
.bottom-nav .nav-item { min-height: 52px; }
.btn, .form-control { min-height: 46px; }

/* ==========================================================================
   Colorful theme layer — multi-hue accents across the app
   ========================================================================== */
:root {
    --violet: #8b5cf6;
    --violet-dark: #7c3aed;
    --violet-light: #ede9fe;
    --rose: #f43f5e;
    --rose-dark: #e11d48;
    --rose-light: #ffe4e6;
    --amber: #f59e0b;
    --amber-dark: #d97706;
    --amber-light: #fef3c7;
    --sky: #0ea5e9;
    --sky-dark: #0284c7;
    --sky-light: #e0f2fe;
    --teal: #14b8a6;
    --teal-light: #ccfbf1;
    --orange: #f97316;
    --orange-light: #ffedd5;
    --pink: #ec4899;
    --pink-light: #fce7f3;
    --violet-gradient: linear-gradient(135deg, #a78bfa, #7c3aed);
    --rose-gradient: linear-gradient(135deg, #fb7185, #e11d48);
    --amber-gradient: linear-gradient(135deg, #fbbf24, #d97706);
    --sky-gradient: linear-gradient(135deg, #38bdf8, #0284c7);
    --rainbow-gradient: linear-gradient(90deg, #10b981, #0ea5e9, #8b5cf6, #ec4899, #f59e0b);
}
[data-theme="dark"] {
    --violet-light: #312a56;
    --rose-light: #4c1d2b;
    --amber-light: #46320b;
    --sky-light: #0c3a54;
    --teal-light: #0f3d38;
    --orange-light: #4a2508;
    --pink-light: #4a1533;
}
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --violet-light: #312a56;
        --rose-light: #4c1d2b;
        --amber-light: #46320b;
        --sky-light: #0c3a54;
        --teal-light: #0f3d38;
        --orange-light: #4a2508;
        --pink-light: #4a1533;
    }
}

/* Soft colorful wash behind the page */
body {
    background-image:
        radial-gradient(600px 300px at 10% -5%, rgba(16,185,129,0.07), transparent 60%),
        radial-gradient(500px 280px at 90% 0%, rgba(139,92,246,0.06), transparent 60%),
        radial-gradient(400px 240px at 50% 100%, rgba(14,165,233,0.05), transparent 60%);
    background-attachment: fixed;
}

/* Rainbow brand accents */
.app-header h1 {
    background: linear-gradient(90deg, #059669, #0284c7 55%, #7c3aed);
    -webkit-background-clip: text;
    background-clip: text;
}
.page-kicker::before { background: var(--rainbow-gradient); width: 18px; }

/* Stat chips — one hue each */
.stats-row .stat-chip:nth-child(1) { background: linear-gradient(160deg, var(--primary-lighter), var(--surface) 70%); }
.stats-row .stat-chip:nth-child(2) { background: linear-gradient(160deg, var(--violet-light), var(--surface) 70%); }
.stats-row .stat-chip:nth-child(3) { background: linear-gradient(160deg, var(--sky-light), var(--surface) 70%); }
.stats-row .stat-chip::before { opacity: 1; }
.stats-row .stat-chip:nth-child(2)::before { background: var(--violet-gradient); }
.stats-row .stat-chip:nth-child(3)::before { background: var(--sky-gradient); }
.stats-row .stat-chip:nth-child(2) .stat-number { background: var(--violet-gradient); -webkit-background-clip: text; background-clip: text; }
.stats-row .stat-chip:nth-child(3) .stat-number { background: var(--sky-gradient); -webkit-background-clip: text; background-clip: text; }

/* Quick action cards — rotating hues with soft tints */
.action-grid .action-card:nth-child(8n+1) { background: linear-gradient(160deg, var(--primary-lighter), var(--surface) 75%); border-color: rgba(16,185,129,0.25); }
.action-grid .action-card:nth-child(8n+2) { background: linear-gradient(160deg, var(--amber-light), var(--surface) 75%); border-color: rgba(245,158,11,0.3); }
.action-grid .action-card:nth-child(8n+3) { background: linear-gradient(160deg, var(--rose-light), var(--surface) 75%); border-color: rgba(244,63,94,0.25); }
.action-grid .action-card:nth-child(8n+4) { background: linear-gradient(160deg, var(--sky-light), var(--surface) 75%); border-color: rgba(14,165,233,0.28); }
.action-grid .action-card:nth-child(8n+5) { background: linear-gradient(160deg, var(--violet-light), var(--surface) 75%); border-color: rgba(139,92,246,0.28); }
.action-grid .action-card:nth-child(8n+6) { background: linear-gradient(160deg, var(--teal-light), var(--surface) 75%); border-color: rgba(20,184,166,0.3); }
.action-grid .action-card:nth-child(8n+7) { background: linear-gradient(160deg, var(--orange-light), var(--surface) 75%); border-color: rgba(249,115,22,0.28); }
.action-grid .action-card:nth-child(8n+8) { background: linear-gradient(160deg, var(--pink-light), var(--surface) 75%); border-color: rgba(236,72,153,0.26); }

/* Utility pills — gentle tints */
.utility-pill { border: 1px solid var(--border); }
.utility-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Event type colors (home cards + calendar page) */
.event-card { border-top: 4px solid var(--primary); }
.event-card.ev-birthday { border-top-color: var(--amber); }
.event-card.ev-anniversary, .event-card.ev-wedding { border-top-color: var(--rose); }
.event-card.ev-death { border-top-color: var(--violet); }
.event-date-badge.ev-birthday { background: var(--amber-light); color: var(--amber-dark); }
.event-date-badge.ev-anniversary, .event-date-badge.ev-wedding { background: var(--rose-light); color: var(--rose-dark); }
.event-date-badge.ev-death { background: var(--violet-light); color: var(--violet-dark); }
.event-date-badge.event-date-badge-today { background: var(--primary); color: #fff; }

/* Filter chips — active hue matches the event type */
.filter-chip.chip-birthday.active { background: var(--amber); border-color: var(--amber); }
.filter-chip.chip-anniversary.active { background: var(--rose); border-color: var(--rose); }
.filter-chip.chip-death.active { background: var(--violet); border-color: var(--violet); }

/* Drawer link icons — soft colored chips per row */
.drawer-section .drawer-link:nth-child(2) .drawer-link-icon { color: var(--primary); }
.drawer-section .drawer-link:nth-child(3) .drawer-link-icon { color: var(--sky); }
.drawer-section .drawer-link:nth-child(4) .drawer-link-icon { color: var(--violet); }
.drawer-section .drawer-link:nth-child(5) .drawer-link-icon { color: var(--amber); }
.drawer-section .drawer-link:nth-child(6) .drawer-link-icon { color: var(--rose); }
.drawer-section .drawer-link:nth-child(7) .drawer-link-icon { color: var(--teal); }
.drawer-section .drawer-link:nth-child(8) .drawer-link-icon { color: var(--orange); }

/* Visual tree — gender-tinted nodes, colorful generation labels */
.tree-node-male { border-color: rgba(14,165,233,0.45); background: linear-gradient(160deg, var(--sky-light), var(--surface-alt) 80%); }
.tree-node-female { border-color: rgba(236,72,153,0.4); background: linear-gradient(160deg, var(--pink-light), var(--surface-alt) 80%); }
.tree-node-self { border-color: var(--primary) !important; }
.tree-generation:nth-child(4n+1) .tree-gen-label { background: var(--primary-light); color: var(--primary-darker); }
.tree-generation:nth-child(4n+2) .tree-gen-label { background: var(--sky-light); color: var(--sky-dark); }
.tree-generation:nth-child(4n+3) .tree-gen-label { background: var(--violet-light); color: var(--violet-dark); }
.tree-generation:nth-child(4n+4) .tree-gen-label { background: var(--amber-light); color: var(--amber-dark); }
[data-theme="dark"] .tree-generation:nth-child(4n+1) .tree-gen-label { color: #6ee7b7; }
[data-theme="dark"] .tree-generation:nth-child(4n+2) .tree-gen-label { color: #7dd3fc; }
[data-theme="dark"] .tree-generation:nth-child(4n+3) .tree-gen-label { color: #c4b5fd; }
[data-theme="dark"] .tree-generation:nth-child(4n+4) .tree-gen-label { color: #fcd34d; }

/* Gradient banner variants */
.card-gradient-violet { background: linear-gradient(135deg, #a78bfa 0%, #7c3aed 55%, #5b21b6 100%); box-shadow: var(--shadow-md), 0 4px 20px rgba(124,58,237,0.3); }
.card-gradient-sky { background: linear-gradient(135deg, #38bdf8 0%, #0284c7 55%, #075985 100%); box-shadow: var(--shadow-md), 0 4px 20px rgba(2,132,199,0.3); }

/* Bottom nav — livelier active state */
.nav-item.active span { color: var(--primary-dark); }
.nav-item.active .nav-icon { transform: translateY(-1px) scale(1.08); transition: transform var(--transition-spring); }

/* Section headers get a tiny colorful tick */
.section-title { position: relative; padding-left: 12px; }
.section-title::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 70%;
    border-radius: 2px;
    background: var(--rainbow-gradient);
}

/* ============================================================
   DEDICATED ADMIN PANEL  (.admin-shell namespace)
   Responsive: persistent sidebar >=1024px, off-canvas <1024px
   ============================================================ */
body.admin-body { background: var(--surface-alt); }
.admin-shell {
    --admin-sidebar-w: 250px;
    --admin-topbar-h: 60px;
    min-height: 100vh;
    display: flex;
    color: var(--text-primary);
}
.admin-shell * { box-sizing: border-box; }

/* Sidebar */
.admin-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--admin-sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 120;
    overflow-y: auto;
    transition: transform var(--transition-normal);
}
.admin-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 20px;
    font-weight: 800; font-size: 1.02rem;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    text-decoration: none;
    position: sticky; top: 0;
    background: var(--surface);
    z-index: 2;
}
.admin-brand .admin-brand-badge {
    width: 30px; height: 30px; border-radius: 9px;
    background: var(--primary-gradient);
    display: grid; place-items: center; color: #fff; flex: none;
}
.admin-nav { padding: 10px 0 24px; flex: 1; }
.admin-nav-label {
    font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-tertiary); font-weight: 700;
    padding: 16px 20px 6px;
}
.admin-nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none; font-size: 0.88rem; font-weight: 600;
    border-left: 3px solid transparent;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.admin-nav-link svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.admin-nav-link:hover { background: var(--surface-alt); color: var(--text-primary); }
.admin-nav-link.active {
    color: var(--primary-dark);
    background: var(--primary-lighter);
    border-left-color: var(--primary);
}
.admin-nav-link .admin-nav-count {
    margin-left: auto;
    background: var(--surface-alt); color: var(--text-secondary);
    font-size: 0.68rem; font-weight: 700;
    padding: 1px 8px; border-radius: var(--radius-full);
}
.admin-nav-link.active .admin-nav-count { background: var(--primary); color: #fff; }

/* Main column */
.admin-main {
    flex: 1;
    margin-left: var(--admin-sidebar-w);
    min-width: 0;
    display: flex; flex-direction: column;
}
.admin-topbar {
    position: sticky; top: 0;
    height: var(--admin-topbar-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 90;
}
.admin-hamburger {
    display: none;
    background: var(--surface-alt); border: 1px solid var(--border);
    border-radius: var(--radius-xs); padding: 8px;
    color: var(--text-primary); cursor: pointer; line-height: 0;
}
.admin-topbar-title { font-weight: 700; font-size: 1rem; }
.admin-topbar-spacer { flex: 1; }
.admin-topbar-user {
    display: flex; align-items: center; gap: 10px;
    font-size: 0.82rem; color: var(--text-secondary);
}
.admin-topbar-user .avatar { width: 30px; height: 30px; font-size: 0.8rem; }
.admin-topbar-link {
    color: var(--text-secondary); text-decoration: none; font-weight: 600;
    font-size: 0.8rem; padding: 6px 10px; border-radius: var(--radius-xs);
}
.admin-topbar-link:hover { background: var(--surface-alt); color: var(--text-primary); }

.admin-content { padding: 22px; max-width: 1200px; width: 100%; }
.admin-page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 14px; margin-bottom: 20px; flex-wrap: wrap;
}
.admin-page-head h1 { font-size: 1.4rem; font-weight: 800; margin: 0 0 3px; }
.admin-page-head p { color: var(--text-secondary); font-size: 0.85rem; margin: 0; }

/* Cards / KPIs */
.admin-kpi-grid {
    display: grid; gap: 14px; margin-bottom: 24px;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.admin-kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 16px 18px;
    text-decoration: none; color: inherit; display: block;
    transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.admin-kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.admin-kpi-value { font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.admin-kpi-label { font-size: 0.78rem; color: var(--text-secondary); margin-top: 4px; font-weight: 600; }
.admin-kpi.attn { border-color: var(--warning); }
.admin-kpi.attn .admin-kpi-value { color: var(--warning); }

.admin-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); margin-bottom: 20px; overflow: hidden;
}
.admin-card-head {
    padding: 14px 18px; border-bottom: 1px solid var(--border-light);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    flex-wrap: wrap;
}
.admin-card-head h2 { font-size: 0.98rem; font-weight: 700; margin: 0; }
.admin-card-body { padding: 18px; }
.admin-card-body.flush { padding: 0; }

/* Tables (scroll horizontally on small screens) */
.admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 560px; }
.admin-table th, .admin-table td {
    text-align: left; padding: 11px 14px;
    border-bottom: 1px solid var(--border-light); vertical-align: middle;
}
.admin-table th {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-tertiary); font-weight: 700; background: var(--surface-alt);
    position: sticky; top: 0;
}
.admin-table tbody tr:hover { background: var(--surface-alt); }
.admin-table td.actions { white-space: nowrap; text-align: right; }
.admin-table a { color: var(--primary-dark); text-decoration: none; font-weight: 600; }
.admin-table a:hover { text-decoration: underline; }

/* Forms */
.admin-form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.admin-field { display: flex; flex-direction: column; gap: 5px; }
.admin-field.full { grid-column: 1 / -1; }
.admin-field label { font-size: 0.76rem; font-weight: 700; color: var(--text-secondary); }
.admin-input, .admin-select, .admin-textarea {
    width: 100%; padding: 9px 12px; font-size: 0.88rem;
    background: var(--surface); color: var(--text-primary);
    border: 1px solid var(--border); border-radius: var(--radius-xs);
    font-family: inherit;
}
.admin-input:focus, .admin-select:focus, .admin-textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-lighter);
}
.admin-textarea { min-height: 92px; resize: vertical; }
.admin-form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

/* Buttons */
.admin-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; font-size: 0.83rem; font-weight: 700;
    border-radius: var(--radius-xs); border: 1px solid transparent;
    cursor: pointer; text-decoration: none; line-height: 1.2;
    font-family: inherit;
}
.admin-btn-primary { background: var(--primary); color: #fff; }
.admin-btn-primary:hover { background: var(--primary-dark); }
.admin-btn-outline { background: var(--surface); color: var(--text-primary); border-color: var(--border); }
.admin-btn-outline:hover { background: var(--surface-alt); }
.admin-btn-danger { background: var(--surface); color: var(--error); border-color: var(--error); }
.admin-btn-danger:hover { background: var(--error); color: #fff; }
.admin-btn-sm { padding: 5px 11px; font-size: 0.76rem; }

/* Badges / pills */
.admin-pill {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 9px; border-radius: var(--radius-full);
    font-size: 0.68rem; font-weight: 700;
    background: var(--surface-alt); color: var(--text-secondary);
}
.admin-pill.green { background: var(--primary-lighter); color: var(--primary-dark); }
.admin-pill.amber { background: var(--warning-light); color: var(--warning); }
.admin-pill.red { background: var(--error-light); color: var(--error); }
.admin-pill.blue { background: var(--accent-light); color: var(--accent-dark); }

.admin-alert {
    padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px;
    font-size: 0.86rem; font-weight: 600;
}
.admin-alert.success { background: var(--primary-lighter); color: var(--primary-darker); border: 1px solid var(--primary-light); }
.admin-alert.error { background: var(--error-light); color: var(--error); border: 1px solid var(--error); }

.admin-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.admin-toolbar .admin-input { max-width: 320px; }
.admin-empty { padding: 40px 18px; text-align: center; color: var(--text-tertiary); }

/* Overlay + off-canvas behaviour */
.admin-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 110;
}
.admin-overlay.open { display: block; }

@media (max-width: 1023px) {
    .admin-main { margin-left: 0; }
    .admin-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-md); }
    .admin-shell.nav-open .admin-sidebar { transform: translateX(0); }
    .admin-hamburger { display: inline-flex; }
}
@media (max-width: 600px) {
    .admin-content { padding: 16px 14px; }
    .admin-page-head h1 { font-size: 1.2rem; }
    .admin-topbar-user .admin-topbar-user-name { display: none; }
}

/* Legacy admin views rendered inside the panel content slot */
.admin-content .admin-legacy { padding: 0; }
.admin-content .admin-legacy .app-header { display: none; }

/* ============================================================
   Error pages (404 / 403 / 419) — rendered standalone by index.php
   ============================================================ */
.error-page {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.error-page-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 40px 32px;
    text-align: center;
    max-width: 420px;
    width: 100%;
}
.error-page-code {
    font-size: 3.25rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.04em;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
    margin-bottom: 12px;
}
.error-page-title {
    font-size: var(--font-lg);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}
.error-page-text {
    color: var(--text-secondary);
    font-size: var(--font-base);
    margin-bottom: 24px;
}

/* ============================================================
   Desktop / tablet layout
   The app is mobile-first; below 1024px nothing here applies and the
   phone shell (bottom nav + slide-over drawer) is used unchanged.
   At >=1024px the drawer becomes a permanent sidebar, which removes the
   need for the bottom nav, the FAB and the "Menu" button.
   ============================================================ */
@media (min-width: 1024px) {
    body {
        padding-bottom: 0;
    }
    /* The drawer overlay is reused as a static sidebar. It carries [hidden]
       when closed on mobile, so both states must be forced visible here. */
    #app_drawer.app-drawer-overlay,
    #app_drawer.app-drawer-overlay[hidden] {
        display: block;
        position: fixed;
        inset: 0 auto 0 0;
        width: 272px;
        background: var(--surface);
        border-right: 1px solid var(--border);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        opacity: 1;
        pointer-events: auto;
        z-index: 80;
        transition: none;
    }
    #app_drawer .app-drawer {
        position: static;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        transform: none;
        box-shadow: none;
        padding: 22px 14px 32px;
        transition: none;
    }
    #menu_close_button,
    .menu-fab,
    .bottom-nav,
    .top-utility-bar .top-utility-button {
        display: none;
    }

    body[data-auth="in"] .app-container {
        max-width: none;
        margin: 0;
        padding-left: 272px;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }
    body[data-auth="in"] .app-container > .top-utility-bar,
    body[data-auth="in"] .app-container > .app-header,
    body[data-auth="in"] .app-container > .page-content {
        max-width: 1080px;
        margin-left: auto;
        margin-right: auto;
    }
    .page-content {
        padding: 26px 28px 48px;
    }
    .top-utility-bar {
        padding: 12px 28px 10px;
    }
    /* Enough room to lay the pills out flat, so nothing is clipped */
    .top-utility-pills {
        flex-wrap: wrap;
        overflow: visible;
        mask-image: none;
        -webkit-mask-image: none;
    }
    .app-header {
        padding: 16px 28px;
    }

    /* Generation rows scroll sideways on phones. With the full width available
       there is room to wrap them, so a whole generation is visible at once
       instead of hidden behind a horizontal scrollbar. */
    .tree-node-row {
        flex-wrap: wrap;
        justify-content: center;
        overflow-x: visible;
    }
    .tree-node {
        min-width: 118px;
        max-width: 152px;
    }
    .tree-visual-wrap {
        padding: 24px 20px;
    }
    .tree-scroll-hint {
        display: none;
    }

    /* Directory listings: 353 members in a single column is an unusable
       scroll on a wide screen, so flow them into responsive columns. */
    body[data-route="members"] .list-card,
    body[data-route="users"] .list-card,
    body[data-route="families"] .list-card {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 10px;
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
    }
    body[data-route="members"] .list-card .list-item,
    body[data-route="users"] .list-card .list-item,
    body[data-route="families"] .list-card .list-item {
        border: 1px solid var(--border-light);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-xs);
    }
    body[data-route="members"] .list-card .empty-state,
    body[data-route="users"] .list-card .empty-state,
    body[data-route="families"] .list-card .empty-state {
        grid-column: 1 / -1;
    }
}

@media (min-width: 1400px) {
    body[data-auth="in"] .app-container > .top-utility-bar,
    body[data-auth="in"] .app-container > .app-header,
    body[data-auth="in"] .app-container > .page-content {
        max-width: 1240px;
    }
}

/* ---- Tablet (768-1023px): keep the touch shell, but stop wasting the width ---- */
@media (min-width: 768px) and (max-width: 1023px) {
    body[data-auth="in"] .app-container,
    body[data-auth="in"] .bottom-nav {
        max-width: 760px;
    }
    body[data-auth="in"] .menu-fab {
        right: max(16px, calc((100vw - 760px) / 2 + 16px));
    }
    body[data-route="members"] .list-card,
    body[data-route="users"] .list-card,
    body[data-route="families"] .list-card {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        background: transparent;
        border: none;
        box-shadow: none;
        overflow: visible;
    }
    body[data-route="members"] .list-card .list-item,
    body[data-route="users"] .list-card .list-item,
    body[data-route="families"] .list-card .list-item {
        border: 1px solid var(--border-light);
        border-radius: var(--radius-md);
    }
    body[data-route="members"] .list-card .empty-state,
    body[data-route="users"] .list-card .empty-state,
    body[data-route="families"] .list-card .empty-state {
        grid-column: 1 / -1;
    }
    .tree-node-row {
        flex-wrap: wrap;
        justify-content: center;
        overflow-x: visible;
    }
    .tree-scroll-hint {
        display: none;
    }
}
