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

/* ===== LIGHT THEME (Default) - Green ===== */
:root {
    --primary: #16a34a; --primary-dark: #15803d; --primary-light: #4ade80;
    --secondary: #0d9488; --accent: #f59e0b; --success: #22c55e;
    --danger: #ef4444; --warning: #f59e0b;
    --bg-body: #f0fdf4; --bg-card: #ffffff; --bg-card-rgb: 255,255,255;
    --bg-sidebar: #ffffff; --bg-input: #f0fdf4; --bg-table-head: #ecfdf5;
    --text-primary: #1e293b; --text-secondary: #475569; --text-muted: #94a3b8;
    --border-color: #d1fae5; --border-light: #ecfdf5;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06); --shadow: 0 4px 20px rgba(22,163,74,0.08);
    --shadow-lg: 0 10px 40px rgba(22,163,74,0.12);
    --glass-bg: rgba(255,255,255,0.85); --glass-border: rgba(22,163,74,0.08);
    --radius: 16px; --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --landing-bg: linear-gradient(135deg, #059669 0%, #0d9488 50%, #16a34a 100%);
    --landing-card-bg: rgba(255,255,255,0.93);
    --heading-color: #14532d;
    --node-bg: rgba(255,255,255,0.96);
    --scrollbar-track: #ecfdf5; --scrollbar-thumb: #a7f3d0;
}

/* ===== DARK THEME ===== */
[data-theme="dark"] {
    --bg-body: #0f172a; --bg-card: #1e293b; --bg-card-rgb: 30,41,59;
    --bg-sidebar: #1e293b; --bg-input: #0f172a; --bg-table-head: #334155;
    --text-primary: #f1f5f9; --text-secondary: #94a3b8; --text-muted: #64748b;
    --border-color: #334155; --border-light: #1e293b;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3); --shadow: 0 4px 20px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
    --glass-bg: rgba(30,41,59,0.8); --glass-border: rgba(255,255,255,0.08);
    --landing-bg: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
    --landing-card-bg: rgba(30,41,59,0.9);
    --heading-color: #e2e8f0;
    --node-bg: rgba(30,41,59,0.95);
    --scrollbar-track: #0f172a; --scrollbar-thumb: #334155;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Inter', sans-serif; background: var(--bg-body); color: var(--text-primary); min-height: 100vh; overflow-x: hidden; transition: background 0.4s, color 0.4s; }

/* ===== Theme Toggle ===== */
.theme-toggle { position: fixed; bottom: 1rem; right: 1rem; z-index: 999; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border-color); background: var(--bg-card); color: var(--text-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; box-shadow: var(--shadow-sm); transition: var(--transition); }
.theme-toggle:hover { transform: scale(1.1); box-shadow: var(--shadow); }

/* ===== Animated Background ===== */
.bg-animated { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--landing-bg); z-index: -2; }
.bg-animated::before { content: ''; position: absolute; top: -50%; left: -50%; width: 200%; height: 200%; background: radial-gradient(circle at 20% 50%, rgba(99,102,241,0.12) 0%, transparent 50%), radial-gradient(circle at 80% 20%, rgba(14,165,233,0.08) 0%, transparent 50%), radial-gradient(circle at 50% 80%, rgba(245,158,11,0.06) 0%, transparent 50%); animation: bgFloat 20s ease-in-out infinite; }
@keyframes bgFloat { 0%,100% { transform: translate(0,0) rotate(0deg); } 33% { transform: translate(30px,-30px) rotate(1deg); } 66% { transform: translate(-20px,20px) rotate(-1deg); } }

.particle { position: fixed; border-radius: 50%; pointer-events: none; background: rgba(255,255,255,0.4); z-index: -1; animation: particleFloat linear infinite; }
[data-theme="dark"] .particle { background: rgba(99,102,241,0.3); }
@keyframes particleFloat { 0% { transform: translateY(100vh) scale(0); opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { transform: translateY(-10vh) scale(1); opacity: 0; } }

/* ===== Landing Page ===== */
.landing-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.landing-card { background: var(--landing-card-bg); backdrop-filter: blur(20px); border: 1px solid var(--glass-border); border-radius: var(--radius); padding: 2.5rem; max-width: 440px; width: 100%; box-shadow: var(--shadow-lg); text-align: center; animation: fadeInUp 0.8s ease-out; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: translateY(0); } }
.landing-icon { width: 72px; height: 72px; margin: 0 auto 1.25rem; background: linear-gradient(135deg, var(--primary), var(--secondary)); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; color: #fff; box-shadow: 0 8px 30px rgba(99,102,241,0.35); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 8px 30px rgba(99,102,241,0.35); } 50% { box-shadow: 0 8px 50px rgba(99,102,241,0.55); } }
.landing-card h1 { font-family: 'Playfair Display', serif; font-size: 1.85rem; margin-bottom: 0.4rem; color: var(--heading-color); }
[data-theme="dark"] .landing-card h1 { background: linear-gradient(135deg, #fff 0%, #c7d2fe 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.landing-card p { color: var(--text-muted); margin-bottom: 1.75rem; font-size: 0.9rem; }

/* ===== Form Styles ===== */
.form-floating-custom { position: relative; margin-bottom: 1.25rem; }
.form-floating-custom input { width: 100%; padding: 0.9rem 1rem 0.9rem 2.75rem; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-primary); font-size: 0.95rem; transition: var(--transition); }
.form-floating-custom input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.form-floating-custom .input-icon { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.btn-primary-custom { width: 100%; padding: 0.9rem; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); border: none; border-radius: var(--radius-sm); color: #fff; font-weight: 600; font-size: 0.95rem; cursor: pointer; transition: var(--transition); }
.btn-primary-custom:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(99,102,241,0.4); }
.btn-primary-custom:active { transform: translateY(0); }
.btn-primary-custom .spinner-border { display: none; }
.btn-primary-custom.loading .spinner-border { display: inline-block; }
.btn-primary-custom.loading .btn-text { display: none; }
.admin-link { display: inline-block; margin-top: 1.25rem; color: var(--text-muted); text-decoration: none; font-size: 0.8rem; transition: var(--transition); }
.admin-link:hover { color: var(--primary); }

/* ===== Tree View ===== */
.tree-header { background: var(--glass-bg); backdrop-filter: blur(20px); border-bottom: 1px solid var(--border-color); padding: 0.75rem 1.5rem; position: sticky; top: 0; z-index: 100; display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.tree-header h2 { font-family: 'Playfair Display', serif; font-size: 1.25rem; color: var(--heading-color); white-space: nowrap; }
[data-theme="dark"] .tree-header h2 { background: linear-gradient(135deg, #fff, #c7d2fe); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.tree-container { padding: 2rem 1rem; overflow-x: auto; min-height: calc(100vh - 60px); }
.tree { display: flex; flex-direction: column; align-items: center; }
.tree ul { display: flex; justify-content: center; list-style: none; padding: 0; margin: 0; position: relative; padding-top: 40px; }
.tree ul::before { content: ''; position: absolute; top: 0; left: 50%; width: 2px; height: 40px; background: linear-gradient(to bottom, var(--primary-light), var(--border-color)); }
.tree li { display: flex; flex-direction: column; align-items: center; position: relative; padding: 0 0.75rem; }
.tree li::before, .tree li::after { content: ''; position: absolute; top: 0; width: 50%; height: 2px; background: var(--border-color); }
.tree li::before { right: 50%; }
.tree li::after { left: 50%; }
.tree li:first-child::before, .tree li:last-child::after { display: none; }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree-node { background: var(--node-bg); backdrop-filter: blur(10px); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 0.85rem; min-width: 140px; text-align: center; cursor: pointer; transition: var(--transition); position: relative; margin-bottom: 0.5rem; box-shadow: var(--shadow-sm); }
.tree-node:hover { border-color: var(--primary); transform: translateY(-4px); box-shadow: 0 10px 30px rgba(22,163,74,0.15); }
.tree-node.male { border-left: 3px solid var(--secondary); }
.tree-node.female { border-left: 3px solid #ec4899; }
.tree-node .node-photo { width: 50px; height: 50px; border-radius: 50%; margin: 0 auto 0.4rem; overflow: hidden; border: 2px solid var(--border-color); background: var(--bg-input); display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }
.tree-node .node-photo img { width: 100%; height: 100%; object-fit: cover; }
.tree-node .node-name { font-weight: 600; font-size: 0.8rem; margin-bottom: 0.15rem; color: var(--text-primary); }
.tree-node .node-years { font-size: 0.65rem; color: var(--text-muted); }
.node-deceased { opacity: 0.65; }
.node-deceased .node-name { text-decoration: line-through; }
.couple-wrapper { display: flex; align-items: center; gap: 0.4rem; position: relative; }
.couple-connector { width: 24px; height: 2px; background: linear-gradient(to right, var(--secondary), #ec4899); position: relative; }
.couple-connector::before { content: '❤'; position: absolute; top: -8px; left: 50%; transform: translateX(-50%); font-size: 0.55rem; }

/* ===== Detail Modal ===== */
.member-detail-card { background: var(--bg-card); border-radius: var(--radius); overflow: hidden; }
.member-detail-header { background: linear-gradient(135deg, var(--primary), var(--secondary)); padding: 1.75rem; text-align: center; color: #fff; }
.member-detail-header .detail-photo { width: 90px; height: 90px; border-radius: 50%; margin: 0 auto 0.75rem; overflow: hidden; border: 3px solid rgba(255,255,255,0.3); background: rgba(255,255,255,0.1); display: flex; align-items: center; justify-content: center; font-size: 2.2rem; }
.member-detail-header .detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.member-detail-body { padding: 1.25rem; }
.detail-row { display: flex; padding: 0.6rem 0; border-bottom: 1px solid var(--border-color); flex-wrap: wrap; }
.detail-row:last-child { border-bottom: none; }
.detail-label { width: 120px; color: var(--text-muted); font-size: 0.8rem; }
.detail-value { flex: 1; color: var(--text-primary); font-size: 0.8rem; min-width: 150px; }

/* ===== Admin Sidebar ===== */
.admin-sidebar { width: 240px; height: 100vh; position: fixed; background: var(--bg-sidebar); border-right: 1px solid var(--border-color); padding: 1.25rem 0; overflow-y: auto; z-index: 200; transition: var(--transition); box-shadow: var(--shadow-sm); }
.admin-sidebar .sidebar-brand { padding: 0 1.25rem 1.25rem; border-bottom: 1px solid var(--border-color); margin-bottom: 0.75rem; }
.admin-sidebar .sidebar-brand h3 { font-family: 'Playfair Display', serif; font-size: 1.15rem; color: var(--heading-color); }
[data-theme="dark"] .admin-sidebar .sidebar-brand h3 { background: linear-gradient(135deg, #fff, #c7d2fe); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.sidebar-nav { list-style: none; padding: 0; }
.sidebar-nav li a { display: flex; align-items: center; gap: 0.6rem; padding: 0.65rem 1.25rem; color: var(--text-secondary); text-decoration: none; transition: var(--transition); font-size: 0.85rem; border-left: 3px solid transparent; }
.sidebar-nav li a:hover, .sidebar-nav li a.active { color: var(--primary); background: rgba(99,102,241,0.08); border-left-color: var(--primary); }
.admin-content { margin-left: 240px; padding: 1.5rem; min-height: 100vh; }

/* ===== Stat Cards ===== */
.stat-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 1.25rem; transition: var(--transition); box-shadow: var(--shadow-sm); }
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card .stat-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.15rem; margin-bottom: 0.75rem; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 800; color: var(--heading-color); }
.stat-card .stat-label { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.2rem; }

/* ===== Table ===== */
.table-container { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); padding: 1.25rem; margin-top: 1.25rem; box-shadow: var(--shadow-sm); }
.table-container .table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.75rem; }
.table-container .table-header h5 { font-weight: 700; font-size: 1rem; color: var(--text-primary); }
.table-dark-custom { --bs-table-bg: transparent; --bs-table-color: var(--text-primary); }
.table-dark-custom th { background: var(--bg-table-head); color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.5px; border-color: var(--border-color); }
.table-dark-custom td { border-color: var(--border-color); vertical-align: middle; font-size: 0.85rem; color: var(--text-primary); }
.table-dark-custom tbody tr:hover { background: rgba(99,102,241,0.04); }

/* ===== Buttons ===== */
.btn-glow { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); border: none; color: #fff; padding: 0.5rem 1.1rem; border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; transition: var(--transition); font-size: 0.85rem; }
.btn-glow:hover { transform: translateY(-2px); color: #fff; box-shadow: 0 5px 20px rgba(99,102,241,0.35); }
.btn-sm-action { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border-color); background: transparent; color: var(--text-muted); cursor: pointer; transition: var(--transition); font-size: 0.75rem; }
.btn-sm-action:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-sm-action.danger:hover { background: var(--danger); border-color: var(--danger); }

/* ===== Modal ===== */
.modal-content { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: var(--radius); color: var(--text-primary); }
.modal-header { border-bottom: 1px solid var(--border-color); background: linear-gradient(135deg, rgba(99,102,241,0.06), rgba(14,165,233,0.06)); }
.modal-header .modal-title { font-weight: 700; color: var(--text-primary); }
.modal-header .btn-close { filter: none; }
[data-theme="dark"] .modal-header .btn-close { filter: invert(1); }
.modal-footer { border-top: 1px solid var(--border-color); }
.modal .form-control, .modal .form-select { background: var(--bg-input); border-color: var(--border-color); color: var(--text-primary); }
.modal .form-control:focus, .modal .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); }
.modal .form-label { color: var(--text-secondary); font-size: 0.8rem; font-weight: 500; }

/* ===== Badges ===== */
.badge-male { background: rgba(14,165,233,0.12); color: var(--secondary); }
.badge-female { background: rgba(236,72,153,0.12); color: #ec4899; }
.badge-gen { background: rgba(99,102,241,0.1); color: var(--primary); font-size: 0.7rem; padding: 0.2rem 0.5rem; border-radius: 4px; }

/* ===== Toast ===== */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 9999; }

/* ===== Search Box ===== */
.search-box { position: relative; }
.search-box input { background: var(--bg-input); border: 1px solid var(--border-color); color: var(--text-primary); border-radius: var(--radius-sm); padding: 0.45rem 0.9rem 0.45rem 2.2rem; font-size: 0.8rem; width: 100%; }
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.15); outline: none; }
.search-box .search-icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.8rem; }

.photo-thumb { width: 34px; height: 34px; border-radius: 50%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; background: var(--bg-input); border: 2px solid var(--border-color); font-size: 0.85rem; }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }

.admin-login-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--scrollbar-track); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Upload Preview ===== */
.upload-preview { width: 90px; height: 90px; border-radius: 50%; overflow: hidden; margin: 0 auto 0.75rem; border: 2px dashed var(--border-color); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: var(--transition); background: var(--bg-input); position: relative; }
.upload-preview:hover { border-color: var(--primary); }
.upload-preview img { width: 100%; height: 100%; object-fit: cover; }
.upload-preview .upload-icon { color: var(--text-muted); font-size: 1.4rem; }

/* ===== Mobile Menu Toggle ===== */
.menu-toggle { display: none; position: fixed; top: 0.75rem; left: 0.75rem; z-index: 300; background: var(--primary); border: none; color: #fff; width: 38px; height: 38px; border-radius: 10px; font-size: 1.1rem; cursor: pointer; }

/* ===== Overlay ===== */
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); z-index: 199; }

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

/* ===== RESPONSIVE ===== */
@media (max-width: 991px) {
    .admin-sidebar { transform: translateX(-100%); }
    .admin-sidebar.show { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-overlay.show { display: block; }
    .admin-content { margin-left: 0; padding: 1rem; padding-top: 3.5rem; }
    .menu-toggle { display: flex; align-items: center; justify-content: center; }
    .stat-card .stat-value { font-size: 1.4rem; }
    .stat-card { padding: 1rem; }
}
@media (max-width: 768px) {
    .landing-card { padding: 1.75rem 1.5rem; }
    .landing-icon { width: 60px; height: 60px; font-size: 1.4rem; }
    .landing-card h1 { font-size: 1.5rem; }
    .tree-container { padding: 1rem 0.5rem; }
    .tree-header { padding: 0.6rem 1rem; }
    .tree-header h2 { font-size: 1rem; }
    .tree-node { min-width: 110px; padding: 0.65rem; }
    .tree-node .node-photo { width: 40px; height: 40px; font-size: 1.1rem; }
    .tree-node .node-name { font-size: 0.7rem; }
    .tree li { padding: 0 0.35rem; }
    .couple-wrapper { flex-direction: column; }
    .couple-connector { width: 2px; height: 16px; }
    .couple-connector::before { top: 50%; left: 8px; transform: translateY(-50%); }
    .theme-toggle { width: 38px; height: 38px; font-size: 1rem; }
    .table-container { padding: 0.75rem; }
    .detail-label { width: 100px; }
}
@media (max-width: 480px) {
    .landing-container { padding: 1rem; }
    .landing-card { padding: 1.5rem 1.25rem; }
    .tree-node { min-width: 90px; padding: 0.5rem; }
    .tree-node .node-name { font-size: 0.65rem; }
    .tree-node .node-years { font-size: 0.55rem; }
    .stat-card .stat-value { font-size: 1.2rem; }
    .search-box input { width: 120px; }
}

/* ===== Expand/Collapse Branch ===== */
.branch-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--primary); color: #fff; border: 2px solid var(--bg-card);
    font-size: 0.65rem; cursor: pointer; transition: var(--transition);
    position: absolute; bottom: -13px; left: 50%; transform: translateX(-50%);
    z-index: 10; box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    line-height: 1;
}
.branch-toggle:hover {
    transform: translateX(-50%) scale(1.15);
    box-shadow: 0 4px 14px rgba(22,163,74,0.3);
}
.branch-toggle i { transition: transform 0.35s ease; }
.branch-toggle.collapsed i { transform: rotate(180deg); }

/* Animated branch children container */
.tree > ul, .tree li > ul {
    overflow: hidden;
    max-height: 2000px;
    opacity: 1;
    transition: max-height 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.35s ease,
                padding-top 0.35s ease;
}
.tree li > ul.branch-hidden,
.tree > ul.branch-hidden {
    max-height: 0 !important;
    opacity: 0;
    padding-top: 0 !important;
    overflow: hidden;
}

/* Couple wrapper needs relative for toggle positioning */
.couple-wrapper { position: relative; margin-bottom: 8px; }
