:root {
    --rw-bg: #EBE6E8;
    --rw-bg-mid: #E2E0EE;
    --rw-bg-deep: #D8E0F4;
    --rw-secondary: #E7EBF8;
    --rw-primary: #F45255;
    --rw-primary-dark: #F45255;
    --rw-accent-secondary: #F87B7E;
    --rw-highlight: #FFDADB;
    --rw-text: #111827;
    --rw-text-muted: #6B7280;
    --rw-surface: rgba(255, 255, 255, 0.95);
    --rw-surface-solid: #FFFFFF;
    --rw-button: #111827;
    --rw-border: #E5E7F5;
    --rw-card-radius: 32px;
    --rw-card-shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
    --reewaz-maroon: var(--rw-primary);
    --reewaz-saffron: var(--rw-accent-secondary);
    --reewaz-gold: var(--rw-highlight);
    --reewaz-ivory: var(--rw-bg);
    --reewaz-cream: var(--rw-bg-mid);
    --reewaz-charcoal: var(--rw-text);
    --rw-font: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
}

body.app-body {
    background: linear-gradient(180deg, #EBE6E8 0%, #D8E0F4 100%);
    color: var(--rw-text);
    font-family: var(--rw-font);
    min-height: 100vh;
}

.app-login-bg {
    background: linear-gradient(180deg, #EBE6E8 0%, #D8E0F4 100%);
}

.app-navbar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--rw-border);
}

.app-navbar .navbar-brand,
.app-navbar .nav-link {
    color: var(--rw-text) !important;
}

.app-brand {
    color: var(--rw-text);
    font-weight: 700;
}

.app-card {
    border-radius: var(--rw-card-radius);
    border: 1px solid var(--rw-border);
    background: var(--rw-surface-solid);
    box-shadow: var(--rw-card-shadow);
}

.app-card-header {
    background: var(--rw-bg-mid);
    border-bottom: 1px solid var(--rw-border);
}

.app-stat-card {
    background: var(--rw-surface-solid);
    border: 1px solid var(--rw-border);
    border-radius: var(--rw-card-radius);
    padding: 1.25rem;
    height: 100%;
    box-shadow: var(--rw-card-shadow);
}

.app-stat-card .label {
    display: block;
    font-size: 0.75rem;
    color: #6c757d;
    margin-bottom: 0.25rem;
}

.app-stat-card strong {
    font-size: 1.35rem;
    color: var(--rw-text);
    font-weight: 700;
}

.app-table thead th {
    background: var(--reewaz-cream);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom-width: 1px;
}

.app-table tbody tr:hover {
    background: rgba(244, 82, 85, 0.04);
}

.app-btn-primary {
    background: var(--rw-button);
    border-color: var(--rw-button);
    border-radius: 999px;
    min-height: 56px;
    padding-inline: 1.5rem;
    font-weight: 600;
}

.app-btn-primary:hover {
    background: #1f2937;
    border-color: #1f2937;
}

.app-badge {
    background: rgba(244, 82, 85, 0.1);
    color: var(--rw-primary);
    border-radius: 999px;
}

@media (max-width: 768px) {
    .app-stat-card strong {
        font-size: 1.1rem;
    }
}

.app-shell { display: flex; min-height: 100vh; }
.app-sidebar {
    width: 260px; flex-shrink: 0;
    background: var(--rw-surface-solid);
    color: var(--rw-text);
    border-right: 1px solid var(--rw-border);
    transition: width 0.25s ease;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 1040;
    box-shadow: var(--rw-card-shadow);
}
.app-sidebar.collapsed { width: 72px; }
.app-sidebar-brand { padding: 1.25rem 1rem; border-bottom: 1px solid var(--rw-secondary); }
.app-sidebar-brand a { color: var(--rw-text); display: flex; align-items: center; gap: 0.75rem; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--rw-border);
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 800; color: var(--rw-primary);
}
.app-logo-image {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    object-fit: cover;
    border: 1px solid rgba(220, 201, 193, 0.85);
}
.app-logo-image-sm {
    width: 28px;
    height: 28px;
    border-radius: 8px;
}
.brand-text { font-weight: 700; font-size: 1.1rem; }
.app-sidebar-nav { padding: 0.75rem 0.5rem; display: flex; flex-direction: column; gap: 0.25rem; }
.app-nav-link {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 0.85rem;
    border-radius: 12px; color: var(--rw-text); text-decoration: none; font-size: 0.9rem;
}
.app-nav-link:hover { background: var(--rw-bg-mid); color: var(--rw-primary); }
.app-nav-link.active {
    background: rgba(255, 218, 219, 0.55); color: var(--rw-primary); font-weight: 600;
}
.nav-icon { width: 1.5rem; text-align: center; flex-shrink: 0; }
.app-main { flex: 1; margin-left: 260px; min-width: 0; transition: margin-left 0.25s ease; }
.app-main.sidebar-collapsed { margin-left: 72px; }
.app-topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.85rem 1.25rem; background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--rw-border);
    position: sticky; top: 0; z-index: 1030;
}
.app-page-title { font-size: 1.75rem; font-weight: 700; color: var(--rw-text); font-family: var(--rw-font); }
.app-content { padding: 1.25rem; }
.app-icon-btn { background: rgba(255,255,255,0.8); border: 1px solid var(--rw-border); border-radius: 50%; width: 40px; height: 40px; }
.app-profile-btn { background: var(--rw-button); color: #fff; border: none; border-radius: 999px; }
.app-card { box-shadow: var(--rw-card-shadow); }
.app-stat-card { box-shadow: var(--rw-card-shadow); transition: transform 0.2s; }
.app-stat-card:hover { transform: translateY(-2px); }
.app-sidebar-backdrop { display: none; }
[x-cloak] { display: none !important; }
@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); width: 260px !important; }
    .app-sidebar.open { transform: translateX(0); }
    .app-main, .app-main.sidebar-collapsed { margin-left: 0; }
    .app-sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(44,36,22,0.45); z-index: 1035; }
}
.app-table-search { max-width: 280px; }

.app-tree-canvas { overflow-x: auto; min-height: 320px; background: linear-gradient(180deg, #fff 0%, var(--reewaz-cream) 100%); }
.app-tree-row { display: flex; flex-direction: column; align-items: center; position: relative; margin-bottom: 1.5rem; }
.app-tree-nodes { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; }
.app-tree-row-center { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 1rem; }
.app-tree-ego-group { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.75rem; }
.app-tree-siblings { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.app-tree-connector-vertical { width: 2px; height: 24px; background: var(--reewaz-gold); margin-bottom: 0.5rem; }
.app-tree-spouse-link { width: 32px; height: 2px; background: var(--reewaz-saffron); display: inline-block; }
.app-tree-node {
    min-width: 120px; max-width: 140px; padding: 0.65rem; border-radius: 14px;
    border: 2px solid rgba(107, 29, 29, 0.15); background: #fff; cursor: pointer;
    text-align: center; transition: transform 0.15s, box-shadow 0.15s;
}
.app-tree-node:hover { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(107, 29, 29, 0.12); }
.app-tree-node.ego { border-color: var(--reewaz-saffron); box-shadow: 0 0 0 3px rgba(232, 132, 42, 0.25); }
.app-tree-node.deceased { opacity: 0.85; border-style: dashed; }
.app-tree-node.compact { min-width: 100px; max-width: 110px; padding: 0.5rem; }
.app-tree-node-avatar { position: relative; margin-bottom: 0.35rem; }
.app-tree-node-avatar img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid var(--reewaz-cream); }
.app-tree-node.compact .app-tree-node-avatar img { width: 44px; height: 44px; }
.app-tree-deceased { position: absolute; bottom: -2px; right: -2px; font-size: 0.85rem; }
.app-tree-node-body strong { display: block; font-size: 0.85rem; line-height: 1.2; }
.app-tree-label { display: block; font-size: 0.7rem; color: #6c757d; text-transform: capitalize; }
.app-tree-nodes.collapsed { display: none; }
.app-timeline-item { border-left: 3px solid var(--reewaz-saffron); }
.app-memorial { background: #2c2416; color: #f5e6d3; }
.app-memorial .app-card { background: #3d3224; color: #f5e6d3; border-color: rgba(201, 162, 39, 0.3); }
.app-memorial-banner { background: rgba(201, 162, 39, 0.2); color: var(--reewaz-gold); }
@media (max-width: 576px) {
    .app-tree-node { min-width: 100px; max-width: 120px; }
    .app-tree-row-center { flex-direction: column; }
}

/* Mobile-first shell */
.app-shell-mobile { padding-bottom: env(safe-area-inset-bottom, 0); }
.pb-nav { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0)); }
.app-mobile-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.65rem 1rem; background: rgba(255,255,255,0.92); color: var(--rw-text);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--rw-border);
    position: sticky; top: 0; z-index: 1020;
}
.app-mobile-title { color: var(--rw-text); font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; gap: 0.5rem; }
.app-mobile-header .app-icon-btn { border: 1px solid var(--rw-border); background: rgba(255,255,255,0.8); color: var(--rw-text); border-radius: 50%; padding: 0.35rem 0.6rem; }
.app-notif-btn { color: #fff; text-decoration: none; font-size: 1.2rem; }
.app-notif-badge {
    position: absolute; top: -4px; right: -8px; min-width: 18px; height: 18px;
    background: var(--reewaz-saffron); color: #fff; font-size: 0.65rem; font-weight: 700;
    border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px;
}
.app-notif-badge-sm { top: -6px; right: -10px; }
.app-bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    display: flex; justify-content: space-around; align-items: center;
    background: rgba(255,255,255,0.96); backdrop-filter: blur(12px);
    border-top: 1px solid rgba(107,29,29,0.1);
    padding: 0.35rem 0 calc(0.35rem + env(safe-area-inset-bottom, 0));
    box-shadow: 0 -4px 20px rgba(44,36,22,0.08);
}
.app-bottom-nav a {
    flex: 1; text-align: center; text-decoration: none; color: var(--rw-text-muted);
    font-size: 0.65rem; padding: 0.25rem; transition: color 0.2s;
}
.app-bottom-nav a span { display: block; font-size: 1.25rem; line-height: 1.2; }
.app-bottom-nav a.active { color: var(--rw-primary); font-weight: 600; }
.app-fab {
    position: fixed; right: 1rem; bottom: calc(4.5rem + env(safe-area-inset-bottom, 0));
    width: 56px; height: 56px; border-radius: 50%; background: var(--rw-button);
    color: #fff; font-size: 1.75rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    text-decoration: none; box-shadow: var(--rw-card-shadow); z-index: 1025;
    transition: transform 0.2s;
}
.app-fab:active { transform: scale(0.94); }
.app-drawer {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; max-width: 85vw;
    background: var(--rw-surface); color: var(--rw-text); border-right: 1px solid var(--rw-secondary);
    z-index: 1045; transform: translateX(-100%); transition: transform 0.28s ease;
}
.app-drawer.open { transform: translateX(0); }
.app-drawer-inner { height: 100%; display: flex; flex-direction: column; }
.app-drawer-brand { padding: 1.25rem 1rem; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); }
.app-drawer-nav { flex: 1; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; }
.app-drawer-nav a { color: var(--rw-text); text-decoration: none; padding: 0.65rem 0.85rem; border-radius: 10px; }
.app-drawer-nav a.active, .app-drawer-nav a:hover { background: var(--rw-secondary); color: var(--rw-primary-dark); }
.app-drawer-backdrop { position: fixed; inset: 0; background: rgba(44,36,22,0.5); z-index: 1040; }
.app-fade-in { animation: appFadeIn 0.35s ease; }
@keyframes appFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.app-skeleton { background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; }
.app-skeleton-avatar { width: 72px; height: 72px; border-radius: 50%; }
.app-skeleton-line { height: 14px; margin-top: 8px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.app-spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 0.35rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.app-tree-viewport { overflow: hidden; touch-action: none; cursor: grab; border-radius: 12px; min-height: 340px; position: relative; }
.app-tree-viewport:active { cursor: grabbing; }
.app-tree-inner { transform-origin: center center; transition: transform 0.08s ease-out; padding: 1.5rem; }
.app-tree-controls { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-bottom: 0.75rem; }
.app-gen-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--reewaz-maroon); font-weight: 600; margin-bottom: 0.5rem; text-align: center; }
.app-tree-connector-vertical { animation: pulseLine 2s ease-in-out infinite; }
@keyframes pulseLine { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.app-tree-branch-toggle { border-radius: 999px; font-size: 0.75rem; }
.app-tree-branch-toggle.collapsed + .app-tree-nodes { display: none; }
.app-popover-avatar { width: 88px; height: 88px; object-fit: cover; border: 3px solid var(--reewaz-cream); }
.app-deceased-overlay { position: absolute; bottom: 0; right: calc(50% - 52px); font-size: 1.1rem; }
.app-profile-cover {
    height: 140px; border-radius: 16px 16px 0 0;
    background: linear-gradient(135deg, var(--reewaz-maroon), var(--reewaz-saffron));
}
.app-profile-cover.memorial { filter: grayscale(0.4); }
.app-profile-head { margin-top: -48px; padding: 0 1.25rem 1rem; position: relative; }
.app-profile-avatar {
    width: 96px; height: 96px; border-radius: 50%; border: 4px solid #fff;
    object-fit: cover; box-shadow: 0 4px 16px rgba(44,36,22,0.15);
}
.app-profile-card { overflow: hidden; margin-bottom: 1rem; }
.app-rel-card {
    border: 1px solid rgba(107,29,29,0.12); border-radius: 14px; padding: 1rem;
    margin-bottom: 0.75rem; background: #fff; transition: box-shadow 0.2s;
}
.app-rel-card:hover { box-shadow: 0 6px 20px rgba(107,29,29,0.1); }
.app-rel-card.pending { border-left: 4px solid var(--reewaz-saffron); }
/* Vertical alternating Parivaar timeline */
.app-vtimeline { position: relative; max-width: 720px; margin: 0 auto; padding: 0.5rem 0 2rem; }
.app-vtimeline::before {
    content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px;
    transform: translateX(-50%);
    background: linear-gradient(180deg, rgba(110,59,44,0.35), rgba(229,215,202,0.9));
    z-index: 0;
}
.app-vtimeline-row {
    display: grid; grid-template-columns: 1fr 52px 1fr; gap: 0.35rem;
    align-items: stretch; margin-bottom: 0.15rem; position: relative; z-index: 1;
    animation: appFadeIn 0.45s ease;
}
.app-vtimeline-spine {
    display: flex; flex-direction: column; align-items: center; padding-top: 0.25rem;
}
.app-vtimeline-year {
    font-size: 0.65rem; font-weight: 700; color: var(--reewaz-maroon);
    background: rgba(110,59,44,0.1); padding: 0.15rem 0.45rem; border-radius: 8px;
    margin-bottom: 0.35rem; letter-spacing: 0.03em;
}
.app-vtimeline-node {
    width: 2rem; height: 2rem; border-radius: 50%; display: flex; align-items: center;
    justify-content: center; font-size: 0.85rem; background: var(--reewaz-cream);
    border: 2px solid #fff; box-shadow: 0 2px 8px rgba(110,59,44,0.2);
}
.app-vtimeline-node--relationship { background: rgba(176,125,74,0.25); }
.app-vtimeline-node--memory { background: rgba(110,59,44,0.15); }
.app-vtimeline-node--birth { background: rgba(107,122,92,0.25); }
.app-vtimeline-node--memorial { background: rgba(121,85,72,0.2); }
.app-vtimeline-card {
    background: #fff; border-radius: 16px; padding: 0.9rem 1rem;
    border: 1px solid rgba(110,59,44,0.12);
    box-shadow: 0 4px 14px rgba(44,36,22,0.06);
    margin-bottom: 1.1rem;
}
.app-vtimeline-row--left .app-vtimeline-slot--start { padding-right: 0.35rem; }
.app-vtimeline-row--right .app-vtimeline-slot--end { padding-left: 0.35rem; }
.app-vtimeline-badge {
    display: inline-block; font-size: 0.65rem; font-weight: 700; text-transform: capitalize;
    color: var(--reewaz-maroon); background: rgba(110,59,44,0.08);
    padding: 0.2rem 0.5rem; border-radius: 8px; margin-bottom: 0.4rem;
}
.app-vtimeline-card--relationship .app-vtimeline-badge { color: #8a5a2a; background: rgba(176,125,74,0.15); }
.app-vtimeline-card--memory .app-vtimeline-badge { background: rgba(110,59,44,0.1); }
.app-vtimeline-title { font-size: 0.95rem; font-weight: 700; margin: 0 0 0.25rem; line-height: 1.3; }
.app-vtimeline-meta { font-size: 0.75rem; color: var(--reewaz-muted, #795548); display: block; }
.app-vtimeline-body { font-size: 0.82rem; margin: 0.5rem 0 0; line-height: 1.45; color: #3e2723; }
@media (max-width: 576px) {
    .app-vtimeline::before { left: 1.35rem; transform: none; }
    .app-vtimeline-row {
        display: flex; align-items: flex-start; gap: 0.65rem;
    }
    .app-vtimeline-spine { flex-shrink: 0; width: 44px; }
    .app-vtimeline-slot { flex: 1; min-width: 0; padding: 0 !important; }
    .app-vtimeline-slot:empty { display: none; }
}
/* Legacy compact list (dashboard snippets) */
.app-timeline-feed { position: relative; padding-left: 0.5rem; }
.app-timeline-date { font-size: 0.75rem; font-weight: 700; color: var(--reewaz-maroon); margin: 1.25rem 0 0.5rem; }
.app-timeline-card {
    display: flex; gap: 0.75rem; padding: 0.85rem; border-radius: 14px;
    background: #fff; border: 1px solid rgba(107,29,29,0.08); margin-bottom: 0.65rem;
    animation: appFadeIn 0.4s ease;
}
.app-timeline-icon {
    width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--reewaz-cream); font-size: 1.1rem;
}
.app-timeline-card.relationship .app-timeline-icon { background: rgba(232,132,42,0.2); }
.app-timeline-card.memory .app-timeline-icon { background: rgba(107,29,29,0.12); }
.app-gallery-masonry { columns: 2; column-gap: 0.65rem; }
@media (min-width: 768px) { .app-gallery-masonry { columns: 3; } }
.app-gallery-item {
    break-inside: avoid; margin-bottom: 0.65rem; border-radius: 12px; overflow: hidden;
    position: relative; cursor: pointer; transition: transform 0.2s;
}
.app-gallery-item:hover { transform: scale(1.02); }
.app-gallery-item img { width: 100%; display: block; }
.app-gallery-item .caption {
    position: absolute; bottom: 0; left: 0; right: 0; padding: 0.35rem 0.5rem;
    background: linear-gradient(transparent, rgba(0,0,0,0.65)); color: #fff; font-size: 0.7rem;
}
.app-lightbox {
    position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 2000;
    display: none; align-items: center; justify-content: center; flex-direction: column; padding: 1rem;
}
.app-lightbox.open { display: flex; }
.app-lightbox img { max-width: 100%; max-height: 80vh; border-radius: 8px; }
.app-lightbox-close { position: absolute; top: 1rem; right: 1rem; background: #fff; border: none; border-radius: 50%; width: 40px; height: 40px; font-size: 1.25rem; }
.app-btn-primary { color: #fff !important; }
.app-main-content { max-width: 960px; }

