/* ============================================================
   Family Tree Web App - Styles
   ============================================================ */

/* CSS Variables — dark-first web3 theme */
:root,
[data-theme="dark"] {
    --bg-primary: #12141c;
    --bg-secondary: #090a0f;
    --bg-tertiary: #1a1d28;
    --bg-elevated: #161922;
    --text-primary: #f0f2f8;
    --text-secondary: #a8b0c2;
    --text-muted: #6b7289;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);
    --accent: #2ee59d;
    --accent-hover: #24c985;
    --accent-secondary: #38bdf8;
    --accent-light: rgba(46, 229, 157, 0.12);
    --accent-glow: rgba(46, 229, 157, 0.22);
    --accent-gradient: linear-gradient(135deg, #2ee59d 0%, #38bdf8 100%);
    --surface-glass: rgba(18, 20, 28, 0.82);
    --male-color: #60a5fa;
    --female-color: #f472b6;
    --success: #2ee59d;
    --warning: #fbbf24;
    --danger: #f87171;
    --sidebar-width: 320px;
    --header-height: 60px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.2s ease;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f3f4f6;
    --bg-tertiary: #e5e7eb;
    --bg-elevated: #ffffff;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --border-color: #d1d5db;
    --border-strong: #cbd5e1;
    --accent: #059669;
    --accent-hover: #047857;
    --accent-secondary: #0284c7;
    --accent-light: rgba(5, 150, 105, 0.12);
    --accent-glow: rgba(5, 150, 105, 0.18);
    --accent-gradient: linear-gradient(135deg, #059669 0%, #0284c7 100%);
    --surface-glass: rgba(255, 255, 255, 0.88);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Optional heritage preset — activate with AppTheme.apply('heritage') */
[data-theme="heritage"] {
    --bg-primary: #1a1410;
    --bg-secondary: #0f0c09;
    --bg-tertiary: #2a2218;
    --bg-elevated: #221c14;
    --text-primary: #f5efe6;
    --text-secondary: #c4b8a8;
    --text-muted: #8a7d6e;
    --border-color: rgba(201, 162, 39, 0.14);
    --border-strong: rgba(201, 162, 39, 0.28);
    --accent: #c9a227;
    --accent-hover: #b08e1f;
    --accent-secondary: #d4a574;
    --accent-light: rgba(201, 162, 39, 0.14);
    --accent-glow: rgba(201, 162, 39, 0.22);
    --accent-gradient: linear-gradient(135deg, #c9a227 0%, #d4a574 100%);
    --surface-glass: rgba(26, 20, 16, 0.88);
    --male-color: #7eb8e8;
    --female-color: #e8a0c0;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow: hidden;
    max-width: 100%;
}

body {
    font-family: 'Source Sans 3', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    overflow-x: hidden;
    max-width: 100vw;
    height: var(--viewport-height, 100vh);
    min-height: var(--viewport-height, 100vh);
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse 50% 40% at 10% 0%, rgba(46, 229, 157, 0.07), transparent 55%),
        radial-gradient(ellipse 40% 35% at 90% 10%, rgba(56, 189, 248, 0.06), transparent 50%);
}

#app {
    position: relative;
    z-index: 1;
}

/* App Layout */
#app {
    display: flex;
    flex-direction: column;
    height: var(--viewport-height, 100vh);
    max-width: 100vw;
    overflow-x: hidden;
}

/* Header */
.header,
.app-header {
    height: var(--header-height);
    background: var(--surface-glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    padding: 0 var(--space-4, 16px);
    gap: var(--space-3, 12px);
    flex-shrink: 0;
    box-shadow: var(--shadow);
    z-index: var(--z-header, 100);
    min-width: 0;
}

.header-logo,
.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 700;
    font-size: var(--text-md, 17px);
    color: var(--text-primary);
    white-space: nowrap;
    flex-shrink: 0;
}

.header-context {
    display: flex;
    align-items: center;
    gap: var(--space-2, 8px);
    min-width: 0;
    flex: 1 1 auto;
}

.header-logo-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.header-logo .member-count {
    font-family: 'Source Sans 3', sans-serif;
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    margin-left: 2px;
}

.member-count-near-limit {
    color: var(--warning-text, #b45309) !important;
    font-weight: 600;
}

.tree-progress-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
}

.tree-progress-overlay.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.tree-progress-card {
    min-width: 280px;
    max-width: 90vw;
    padding: 24px 28px;
    border-radius: 14px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border, rgba(0,0,0,0.08));
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
    text-align: center;
}

.tree-progress-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto 12px;
    border: 3px solid rgba(37, 99, 235, 0.2);
    border-top-color: var(--accent, #2563eb);
    border-radius: 50%;
    animation: ft-spin 0.7s linear infinite;
}

.tree-progress-text {
    margin: 0 0 12px;
    font-size: 13px;
    color: var(--text-secondary, #475569);
}

.tree-progress-track {
    height: 6px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.12);
    overflow: hidden;
}

.tree-progress-bar {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--accent, #2563eb);
    transition: width 0.2s ease;
}

.tree-large-hint {
    font-size: 12px;
    color: var(--text-muted);
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px dashed var(--border);
}

.ft-picker-hint,
.ft-picker-more {
    font-size: 11px;
    color: var(--text-muted, #64748b);
    padding: 8px 6px;
    line-height: 1.4;
}

.ft-picker-more {
    text-align: center;
    font-style: italic;
}

.ft-picker-spacer {
    flex-shrink: 0;
    width: 100%;
}

.ft-picker-virtual {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-logo svg {
    width: 28px;
    height: 28px;
}

.header-nav {
    display: flex;
    gap: 4px;
    margin-left: 24px;
}

.nav-btn {
    padding: 7px 12px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
    white-space: nowrap;
}

.nav-btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.nav-btn-accent {
    border-color: rgba(46, 229, 157, 0.35);
    color: var(--accent);
}

.nav-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.nav-btn.active {
    background: var(--accent-gradient);
    color: #04120c;
    border-color: transparent;
    box-shadow: 0 0 20px var(--accent-glow);
    font-weight: 600;
}

.nav-btn.active .ui-icon {
    stroke: #04120c;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.header-drawer-top {
    padding: 4px 4px 12px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-color);
}

.header-drawer-top-demo {
    padding: 8px 6px 14px;
}

.header-drawer-demo-label {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-drawer-demo-hint {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.header-user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 4px 8px 4px 4px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.03);
}

.header-user-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: #04120c;
    background: var(--accent-gradient);
    box-shadow: 0 0 12px var(--accent-glow);
}

.header-user-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.header-user-kicker {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.header-user-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-user-email {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-variant-numeric: tabular-nums;
}

.header-drawer-top .header-user-chip {
    width: 100%;
    border-radius: 12px;
    padding: 10px 12px;
    border: none;
    background: var(--bg-secondary);
}

.header-drawer-top .header-user-meta {
    display: flex;
}

.header-drawer-plan {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.header-drawer-plan-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.header-drawer-plan-kicker {
    margin: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.header-drawer-plan-name {
    margin: 0;
    font-family: 'Fraunces', Georgia, serif;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.header-drawer-plan-meta {
    margin: 0 0 6px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.header-drawer-plan-btn {
    align-self: flex-start;
    margin-top: 4px;
    padding: 6px 12px;
    font-size: 12px;
}

.modal-billing-hub {
    width: min(96vw, 560px);
    max-width: 560px;
}

.billing-hub-current {
    padding-bottom: 4px;
}

.billing-hub-plan-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.billing-hub-status {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--accent);
    border: 1px solid rgba(52, 211, 153, 0.35);
    background: rgba(52, 211, 153, 0.1);
}

.billing-hub-usage {
    margin: 8px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.billing-hub-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 18px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.billing-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px;
    font-size: 14px;
}

.billing-paywall-footer {
    justify-content: space-between;
    gap: 8px;
}

@media (max-width: 520px) {
    .billing-paywall-footer {
        flex-direction: column-reverse;
        align-items: stretch;
    }
}

.header-nav-desktop {
    display: flex;
    gap: 4px;
    margin-left: 16px;
    flex-wrap: wrap;
    min-width: 0;
}

.header-nav-mobile {
    display: none;
    margin-left: 12px;
}

.nav-views-mobile-select {
    min-width: 148px;
    max-width: min(200px, 42vw);
    padding: 7px 10px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-primary);
}

.undo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    min-height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.undo-btn:not(:disabled):hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.undo-btn-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.15;
    text-align: left;
}

.undo-btn-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.undo-btn-hint {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
}

.undo-btn.icon-btn-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.header-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1300;
}

.header-drawer-overlay[hidden] {
    display: none;
}

.header-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: min(320px, 92vw);
    height: 100vh;
    z-index: 1310;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.2);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    display: flex;
    flex-direction: column;
}

.header-drawer.open {
    transform: translateX(0);
}

.header-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}

.header-drawer-close {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
}

.header-drawer-body {
    padding: 12px 10px 24px;
    overflow-y: auto;
}

.header-drawer-section-title {
    margin: 14px 8px 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.header-drawer-section-title:first-child {
    margin-top: 4px;
}

.header-drawer-subsection {
    margin-bottom: 4px;
}

.header-drawer-subtitle {
    margin: 4px 8px 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.header-drawer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    transition: var(--transition);
}

.header-drawer-item:hover {
    background: var(--bg-tertiary);
}

.header-drawer-item-danger {
    color: var(--danger, #dc2626);
}

.header-drawer-item-danger:hover {
    background: rgba(220, 38, 38, 0.08);
}

.header-drawer-account {
    padding: 4px 12px 10px;
}

.header-drawer-account-role .header-role-badge {
    max-width: 100%;
}

.header-drawer-account-muted {
    font-size: 13px;
    color: var(--text-muted);
}

.header-role-badge-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.member-jump-search {
    position: relative;
    width: 100%;
}

.member-jump-input-wrap {
    position: relative;
    width: 100%;
}

.member-jump-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.member-jump-input {
    width: 100%;
    padding: 7px 10px 7px 32px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 12px;
    outline: none;
    transition: var(--transition);
}

.member-jump-input:focus {
    border-color: rgba(46, 229, 157, 0.45);
    box-shadow: 0 0 0 2px var(--accent-light);
}

.member-jump-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 50;
    max-height: 280px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    box-shadow: var(--shadow);
}

.member-jump-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.member-jump-item:last-child {
    border-bottom: none;
}

.member-jump-item:hover,
.member-jump-item-active {
    background: var(--bg-secondary);
}

.member-jump-name {
    font-size: 13px;
    font-weight: 600;
}

.member-jump-sub {
    font-size: 11px;
    color: var(--text-muted);
}

.folder-view-toolbar .family-line-picker {
    margin: 0;
}

.folder-view-toolbar.tree-panel-edit-mode {
    background: #fffbeb;
    border-bottom-color: #fcd34d;
}

.folder-view-toolbar.folder-toolbar-hanging-mode {
    background: #faf5ff;
    border-bottom-color: #c4b5fd;
}

[data-theme="dark"] .folder-view-toolbar.folder-toolbar-hanging-mode {
    background: rgba(91, 33, 182, 0.12);
    border-bottom-color: rgba(167, 139, 250, 0.35);
}

.directory-jump-search-host {
    min-width: 200px;
    flex: 1;
    max-width: 280px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent);
    border-color: rgba(46, 229, 157, 0.3);
}

.icon-btn:disabled,
.icon-btn.icon-btn-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.icon-btn:disabled:hover,
.icon-btn.icon-btn-disabled:hover {
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    border-color: var(--border-color);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* Folder View */
.folder-view {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.folder-view-toolbar {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
    z-index: 3;
}

.folder-toolbar-primary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    min-width: 0;
}

.folder-toolbar-edit-btn,
.folder-add-line-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    min-height: 36px;
}

.folder-family-picker-slot {
    flex: 1 1 auto;
    min-width: 0;
}

.folder-family-picker-slot .family-line-picker {
    margin: 0;
}

.folder-add-line-btn-label-short {
    display: none;
}

.folder-toolbar-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.folder-toolbar-search-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
    max-width: min(100%, 440px);
}

.folder-toolbar-search-row .folder-toolbar-search {
    flex: 1 1 auto;
    min-width: 120px;
    max-width: none;
}

.folder-hanging-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    min-height: 34px;
    line-height: 1.2;
    border-radius: var(--radius-sm);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.folder-hanging-btn .ui-icon {
    flex-shrink: 0;
    opacity: 0.9;
}

.folder-hanging-btn.all-clear:not(.active) {
    color: var(--text-muted);
}

.folder-hanging-btn.all-clear:not(.active):hover {
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

.folder-hanging-btn.all-clear .folder-hanging-btn-count {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-muted);
}

[data-theme="dark"] .folder-hanging-btn.all-clear .folder-hanging-btn-count {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
}

.folder-hanging-btn.has-unassigned:not(.active) {
    border-color: #c4b5fd;
    background: #f5f3ff;
    color: #5b21b6;
}

.folder-hanging-btn.has-unassigned:not(.active):hover {
    background: #ede9fe;
    border-color: #a78bfa;
    color: #5b21b6;
}

[data-theme="dark"] .folder-hanging-btn.has-unassigned:not(.active) {
    border-color: rgba(167, 139, 250, 0.45);
    background: rgba(91, 33, 182, 0.18);
    color: #ddd6fe;
}

[data-theme="dark"] .folder-hanging-btn.has-unassigned:not(.active):hover {
    background: rgba(91, 33, 182, 0.28);
    border-color: rgba(167, 139, 250, 0.65);
    color: #ede9fe;
}

.folder-hanging-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.folder-hanging-btn.active:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.folder-hanging-btn-label-short,
.folder-hanging-btn-count {
    display: none;
}

.folder-hanging-btn-count {
    align-items: center;
    justify-content: center;
    min-width: 1.35em;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(91, 33, 182, 0.14);
    color: #5b21b6;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.5;
}

[data-theme="dark"] .folder-hanging-btn-count {
    background: rgba(255, 255, 255, 0.14);
    color: #ede9fe;
}

.folder-hanging-btn.active .folder-hanging-btn-count {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.folder-toolbar-search {
    flex: 1 1 200px;
    min-width: 160px;
    max-width: 360px;
}

.folder-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.folder-view-panels {
    flex: 1;
    min-height: 0;
    display: flex;
    width: 100%;
    overflow: hidden;
}

.folder-tree-panel {
    width: var(--tree-panel-width, 350px);
    min-width: 150px;
    max-width: 60vw;
    border-right: 1px solid var(--border-color);
    background: var(--bg-primary);
    overflow: hidden;
    flex-shrink: 0;
    resize: none;
    display: flex;
    flex-direction: column;
}

#aft-tree-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

/* Resize Handle */
.resize-handle {
    width: 5px;
    cursor: col-resize;
    background: var(--border-color);
    flex-shrink: 0;
    transition: background 0.15s ease;
    position: relative;
}

.resize-handle:hover,
.resize-handle:active {
    background: var(--accent);
}

.resize-handle::after {
    content: '';
    position: absolute;
    left: -3px;
    right: -3px;
    top: 0;
    bottom: 0;
}

.folder-view-toolbar .tree-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tree-action-btn {
    padding: 2px 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 11px;
    transition: var(--transition);
}

.tree-action-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.tree-edit-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: #fef3c7;
    color: #92400e;
    border-bottom: 1px solid #fcd34d;
    font-size: 12px;
    flex-shrink: 0;
    z-index: 2;
}

.tree-edit-banner-text {
    flex: 1;
    line-height: 1.4;
}

.tree-hanging-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: #ede9fe;
    color: #5b21b6;
    border-bottom: 1px solid #c4b5fd;
    font-size: 12px;
    flex-shrink: 0;
    z-index: 2;
    flex-wrap: wrap;
}

[data-theme="dark"] .tree-hanging-banner {
    background: rgba(91, 33, 182, 0.22);
    color: #ddd6fe;
    border-bottom-color: rgba(167, 139, 250, 0.35);
}

.tree-hanging-banner-text {
    display: inline-flex;
    align-items: flex-start;
    gap: 8px;
    flex: 1;
    line-height: 1.45;
    font-weight: 500;
    min-width: 0;
}

.tree-hanging-banner-text .ui-icon {
    flex-shrink: 0;
    margin-top: 1px;
    opacity: 0.85;
}

.tree-hanging-banner-text > span {
    min-width: 0;
}

.tree-hanging-back-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: #fff;
    border-color: #a78bfa;
    color: #5b21b6;
    min-height: 34px;
    padding: 6px 12px;
    font-weight: 600;
}

.tree-hanging-back-btn:hover {
    background: #f5f3ff;
    border-color: #8b5cf6;
    color: #5b21b6;
}

[data-theme="dark"] .tree-hanging-back-btn {
    background: rgba(15, 23, 42, 0.45);
    border-color: rgba(167, 139, 250, 0.5);
    color: #ede9fe;
}

[data-theme="dark"] .tree-hanging-back-btn:hover {
    background: rgba(91, 33, 182, 0.35);
    color: #fff;
}

@media (min-width: 769px) {
    .tree-hanging-back-btn {
        display: none;
    }
}

.hanging-tree-list {
    padding: 6px 0 10px;
}

.tree-node-content.hanging-tree-item {
    background: rgba(139, 92, 246, 0.05);
    border-radius: 6px;
}

.tree-node-content.hanging-tree-item:hover {
    background: rgba(139, 92, 246, 0.1);
}

.tree-node-content.hanging-tree-item.selected {
    background: rgba(139, 92, 246, 0.16);
    outline: 1px solid rgba(167, 139, 250, 0.55);
    outline-offset: -1px;
}

[data-theme="dark"] .tree-node-content.hanging-tree-item {
    background: rgba(139, 92, 246, 0.1);
}

[data-theme="dark"] .tree-node-content.hanging-tree-item:hover {
    background: rgba(139, 92, 246, 0.16);
}

.hanging-tree-node .hanging-tree-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.hanging-tree-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hanging-tree-reason {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    white-space: normal;
}

.hanging-tree-empty {
    padding: 32px 20px 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.55;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: 320px;
    margin: 0 auto;
}

.hanging-tree-empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
}

[data-theme="dark"] .hanging-tree-empty-icon {
    background: rgba(139, 92, 246, 0.18);
    color: #c4b5fd;
}

.hanging-tree-empty p {
    margin: 0;
}

@media (max-width: 480px) {
    .folder-hanging-btn-label-short {
        display: none;
    }

    .folder-hanging-btn-count {
        display: inline-flex;
    }

    .tree-hanging-banner-text {
        font-size: 11px;
    }
}

@media (min-width: 769px) and (max-width: 1080px) {
    .folder-hanging-btn-label-full,
    .folder-add-line-btn-label-full {
        display: none;
    }

    .folder-add-line-btn-label-short {
        display: inline;
    }

    .folder-hanging-btn-label-short,
    .folder-hanging-btn-count {
        display: inline-flex;
    }
}

.tree-edit-done-btn {
    flex-shrink: 0;
    background: #fff;
    border-color: #f59e0b;
    color: #92400e;
    font-weight: 600;
}

.tree-edit-done-btn:hover {
    background: #f59e0b;
    color: #fff;
    border-color: #f59e0b;
}

.folder-tree-panel.tree-panel-edit-mode {
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
}

.folder-tree-panel.tree-panel-hanging-mode {
    outline: 2px solid #a78bfa;
    outline-offset: -2px;
}


/* Tree Node */
.tree-node {
    user-select: none;
}

/* Drag and Drop States */
.tree-node-content.dragging {
    opacity: 0.4;
    background: var(--bg-tertiary);
}

.tree-node-content.drag-over {
    background: var(--accent-light) !important;
    outline: 2px dashed var(--accent);
    outline-offset: -2px;
}

.tree-node-content.invalid-drop {
    outline: 2px dashed var(--danger);
    outline-offset: -2px;
    cursor: no-drop;
}

.tree-node-content.tree-edit-draggable {
    cursor: grab;
}

.tree-node-content.tree-edit-draggable:active {
    cursor: grabbing;
}

.tree-node-content {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    padding-left: calc(16px + var(--depth, 0) * 20px);
    cursor: pointer;
    transition: var(--transition);
    border-radius: 4px;
    margin: 1px 4px;
    gap: 4px;
    position: relative;
}

.tree-node-content:hover {
    background: var(--bg-secondary);
}

.tree-node-content.selected {
    background: var(--accent-light);
    color: var(--accent);
}

.tree-node-content.highlighted {
    background: var(--warning);
    color: #fff;
}

.tree-toggle {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 10px;
    transition: transform var(--transition);
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-toggle.leaf {
    visibility: hidden;
}

.tree-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

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

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

.tree-label {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.tree-child-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: auto;
}

.tree-add-child {
    opacity: 0;
    width: 20px;
    height: 20px;
    border: none;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition);
    flex-shrink: 0;
}

.tree-node-content:hover .tree-add-child {
    opacity: 1;
}

/* Detail Panel */
.detail-panel {
    flex: 1;
    background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent 120px), var(--bg-primary);
    overflow-y: auto;
    padding: 24px;
}

.detail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 12px;
}

.detail-empty svg {
    width: 64px;
    height: 64px;
    opacity: 0.4;
}

.detail-empty p {
    font-size: 16px;
}

/* Empty tree onboarding */
.empty-tree-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 24px;
    gap: 12px;
    min-height: 240px;
}

.empty-tree-cta-canvas {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: rgba(var(--bg-primary-rgb, 15, 15, 20), 0.92);
    backdrop-filter: blur(4px);
}

.empty-tree-cta h3 {
    margin: 0;
    font-size: 20px;
    color: var(--text-primary);
}

.empty-tree-cta p {
    margin: 0;
    color: var(--text-secondary);
    max-width: 320px;
    line-height: 1.5;
}

.empty-tree-cta-btn {
    margin-top: 8px;
    padding: 14px 28px !important;
    font-size: 16px !important;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 220px;
}

.empty-tree-cta-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    max-width: 320px;
    margin-top: 8px;
}

.empty-tree-cta-banner {
    min-height: auto;
    padding: 16px;
    margin-bottom: 12px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: var(--bg-secondary);
}

.empty-tree-cta-banner h3 {
    font-size: 16px;
}

.empty-tree-cta-banner .empty-tree-cta-actions {
    max-width: none;
}

.empty-tree-cta-banner .empty-tree-cta-btn {
    min-width: 0;
    padding: 12px 16px !important;
    font-size: 14px !important;
}

.clan-manage-section {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.empty-tree-cta-icon {
    opacity: 0.7;
    color: var(--accent);
}

/* Structural change dialog */
.struct-modal-body {
    max-height: none;
    overflow: visible;
}

.struct-deps {
    color: var(--text-secondary);
    font-size: 13px;
}

.struct-strategy {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 16px 0;
}

.struct-strategy-opt {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1.4;
}

.struct-branch-note {
    font-size: 13px;
    color: var(--text-muted);
    margin: 8px 0 12px;
    line-height: 1.5;
}

.struct-resolve {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-top: 12px;
    background: var(--bg-secondary);
}

.struct-resolve-intro {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0 0 12px;
}

.struct-resolve-heading {
    margin: 12px 0 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.struct-resolve-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.struct-resolve-row:last-child {
    border-bottom: none;
}

.struct-resolve-name {
    font-weight: 600;
    min-width: 100px;
}

.struct-resolve-row label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text-muted);
    font-size: 11px;
}

.struct-resolve-row select {
    min-width: 160px;
    padding: 6px 8px;
    font-size: 13px;
}

/* Export menu */
.export-menu-wrap {
    position: relative;
}

.export-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg, 0 8px 24px rgba(0,0,0,0.2));
    z-index: 100;
    padding: 6px;
}

.export-dropdown.open {
    display: block;
}

.export-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
}

.export-dropdown button:hover {
    background: var(--bg-tertiary);
}

.header-role-badge-wrap {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    max-width: min(280px, 36vw);
}

.header-role-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-family: 'Source Sans 3', sans-serif;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid var(--border-color);
}

.header-role-badge--viewer {
    background: rgba(147, 51, 234, 0.12);
    color: #c084fc;
    border-color: rgba(192, 132, 252, 0.35);
}

.header-role-badge--editor {
    background: var(--accent-light);
    color: var(--accent);
}

.pedigree-more-wrap {
    position: relative;
}

.pedigree-more-menu {
    min-width: 220px;
}

.pedigree-more-section {
    padding: 4px 8px 8px;
}

.pedigree-more-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.pedigree-more-select {
    width: 100%;
    margin-bottom: 4px;
}

[data-theme="light"] .header-role-badge--viewer {
    color: #7e22ce;
    background: rgba(126, 34, 206, 0.08);
}

.import-template-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.import-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 12px;
}

.import-preview-table th,
.import-preview-table td {
    border: 1px solid var(--border);
    padding: 6px 8px;
    text-align: left;
}

.import-preview-table .err {
    color: var(--danger, #ef4444);
}

.import-preview-table .ok {
    color: var(--success, #22c55e);
}

/* Person Card */
.person-card {
    max-width: 600px;
    margin: 0 auto;
}

.person-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
}

.person-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    color: var(--text-muted);
    flex-shrink: 0;
    overflow: hidden;
    border: 3px solid var(--border-color);
}

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

.person-avatar.uploadable {
    cursor: pointer;
    position: relative;
}

.person-avatar.uploadable::after {
    content: '📷';
    position: absolute;
    bottom: -4px;
    right: -4px;
    font-size: 16px;
    background: var(--bg-primary);
    border-radius: 50%;
    padding: 2px;
    border: 1px solid var(--border-color);
}

.person-name-section {
    flex: 1;
}

.person-name {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.person-relation {
    font-size: 14px;
    color: var(--text-secondary);
}

.person-gender-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

.person-gender-badge.male {
    background: var(--male-color);
    color: white;
}

.person-gender-badge.female {
    background: var(--female-color);
    color: white;
}

.person-actions {
    display: flex;
    gap: 8px;
}

.person-actions button {
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    transition: var(--transition);
}

.person-actions button:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.person-actions .btn-danger {
    color: var(--danger);
    border-color: var(--danger);
}

.person-actions .btn-danger:hover {
    background: var(--danger);
    color: white;
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.info-item {
    background: var(--bg-secondary);
    padding: 12px 16px;
    border-radius: var(--radius);
}

.info-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.info-value {
    font-size: 15px;
    font-weight: 500;
}

.info-value a {
    color: var(--accent);
    text-decoration: none;
}

.info-value a:hover {
    text-decoration: underline;
}

/* Children Section */
.children-section {
    margin-top: 24px;
}

.children-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.children-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
}

.child-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

.child-card:hover {
    background: var(--accent-light);
    transform: translateY(-1px);
}

.child-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.child-card-icon.male {
    background: var(--male-color);
    color: white;
}

.child-card-icon.female {
    background: var(--female-color);
    color: white;
}

.child-card-info {
    flex: 1;
    min-width: 0;
}

.child-card-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.child-card-relation {
    font-size: 11px;
    color: var(--text-muted);
}

/* Inline Editor */
.inline-edit {
    display: none;
}

.inline-edit.active {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.inline-edit input {
    padding: 2px 6px;
    border: 2px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: inherit;
    font-family: inherit;
    outline: none;
}

.inline-edit button {
    padding: 2px 8px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
}

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

.inline-cancel {
    background: var(--danger);
    color: white;
}

/* Context Menu */
.context-menu {
    display: none;
    position: fixed;
    background: var(--surface-glass);
    backdrop-filter: blur(14px);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    min-width: 180px;
    max-width: min(280px, calc(100vw - 24px));
    max-height: min(70vh, 480px);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 6px;
}

.context-menu.active {
    display: block;
}

.context-menu-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
}

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

.context-menu-item.danger {
    color: var(--danger);
}

.context-menu-item.danger:hover {
    background: rgba(248, 113, 113, 0.15);
    color: var(--danger);
}

.context-menu-item-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.context-menu-item-disabled:hover {
    background: transparent;
    color: inherit;
}

.context-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 8px;
}

.tree-node-content.tree-node-placeholder {
    opacity: 0.85;
    border-left: 3px dashed var(--text-muted);
}

.tree-node-content.tree-node-clan {
    border-left: 3px solid var(--accent);
    font-weight: 600;
}

.tree-add-child-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.person-actions .person-action-disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Modal Overlay */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(2, 4, 8, 0.72);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal, 2000);
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

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

/* Duplicate-name confirm — above add panels, drawers, pedigree popovers, tours */
.modal-overlay.duplicate-name-confirm-overlay {
    z-index: var(--z-confirm, 9800);
}

.modal {
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    width: min(92vw, 520px);
    max-width: 520px;
    max-height: min(86dvh, calc(var(--viewport-height, 100dvh) - 32px), 720px);
    overflow: hidden;
    box-shadow: var(--shadow-md), 0 0 0 1px rgba(46, 229, 157, 0.06);
}

.modal.modal-member-link {
    width: min(92vw, 440px);
    max-width: 440px;
}

.modal.modal-member-link .modal-body {
    max-height: none;
}

.modal-header {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

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

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 20px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.modal-footer {
    display: flex;
    flex-shrink: 0;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

body.modal-open .mobile-tab-bar,
body.member-add-panel-open .mobile-tab-bar {
    display: none !important;
}

.modal-paywall {
    width: min(96vw, 1080px);
    max-width: 1080px;
    max-height: min(92dvh, calc(var(--viewport-height, 100dvh) - 32px));
}

.modal-paywall .modal-body {
    padding: 24px 24px 12px;
}

.billing-paywall-intro {
    text-align: center;
    max-width: 640px;
    margin: 0 auto 24px;
}

.billing-paywall-kicker {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 8px;
}

.billing-paywall-title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(24px, 3vw, 32px);
    margin-bottom: 8px;
}

.billing-paywall-subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.6;
}

.billing-paywall-alert {
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.25);
    color: var(--warning);
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 18px;
    font-size: 13px;
    line-height: 1.5;
}

.billing-interval-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-bottom: 22px;
}

.billing-interval-tab {
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    font-family: inherit;
}

.billing-interval-tab:hover {
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.billing-interval-tab.active {
    background: var(--accent-gradient);
    color: #04120c;
    border-color: transparent;
    box-shadow: 0 0 18px var(--accent-glow);
}

[data-theme="light"] .billing-interval-tab.active {
    color: #ffffff;
}

.billing-interval-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.18);
}

.billing-interval-tab.active .billing-interval-badge {
    background: rgba(255, 255, 255, 0.22);
}

.billing-plan-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    align-items: stretch;
}

.billing-plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 22px 18px 18px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.02);
    min-height: 100%;
}

.billing-plan-featured {
    border-color: rgba(46, 229, 157, 0.45);
    background: linear-gradient(180deg, rgba(46, 229, 157, 0.08), rgba(255, 255, 255, 0.02));
    box-shadow: 0 0 0 1px rgba(46, 229, 157, 0.12), 0 12px 32px rgba(46, 229, 157, 0.08);
    transform: translateY(-2px);
}

.billing-plan-current {
    border-color: rgba(56, 189, 248, 0.35);
}

.billing-plan-badge {
    align-self: flex-start;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--accent-light);
    color: var(--accent);
    border: 1px solid rgba(46, 229, 157, 0.22);
}

.billing-plan-badge-current {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-secondary);
    border-color: rgba(56, 189, 248, 0.22);
}

.billing-plan-badge-value {
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-secondary);
}

.billing-plan-name {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 24px;
    line-height: 1.1;
}

.billing-plan-tagline {
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
}

.billing-plan-price {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0 4px;
}

.billing-plan-amount {
    font-size: 34px;
    font-weight: 700;
    line-height: 1;
}

.billing-plan-equiv,
.billing-plan-period {
    font-size: 13px;
    color: var(--text-muted);
}

.billing-plan-summary {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.55;
    min-height: 40px;
}

.billing-plan-features,
.billing-shared-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
}

.billing-plan-features li,
.billing-shared-features li {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.45;
}

.billing-plan-features {
    flex: 1;
}

.billing-plan-shared {
    color: var(--text-muted);
    font-style: italic;
}

.billing-check-icon {
    color: var(--accent);
    margin-top: 1px;
}

.billing-plan-cta {
    width: 100%;
    margin-top: 4px;
}

.billing-paywall-footnote {
    text-align: center;
    margin: 18px 0 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.billing-founders-block {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.billing-founders-header {
    text-align: center;
    max-width: 640px;
    margin: 0 auto 20px;
}

.billing-founders-title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 22px;
    margin-bottom: 8px;
}

.billing-founders-sub,
.billing-founders-seats {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.billing-founders-seats {
    margin-top: 8px;
    color: var(--accent, #d97706);
    font-weight: 600;
}

.billing-founders-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.billing-founders-card {
    border-color: rgba(217, 119, 6, 0.25);
    background: linear-gradient(165deg, rgba(217, 119, 6, 0.06), transparent 55%);
}

.billing-settings-lifetime {
    color: var(--accent, #10b981);
    font-weight: 500;
}

.billing-appsumo-redeem {
    margin: 16px 0;
    padding: 14px;
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--border-color);
    background: var(--bg-secondary, rgba(255, 255, 255, 0.03));
}

.billing-appsumo-redeem-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.billing-appsumo-redeem-row .form-input {
    flex: 1;
    min-width: 0;
}

@media (max-width: 768px) {
    .billing-founders-grid {
        grid-template-columns: 1fr;
    }
}

.billing-shared-features {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
}

.billing-settings-current {
    margin-bottom: 16px;
}

.billing-settings-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.billing-settings-plan {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 24px;
    margin-bottom: 4px;
}

.billing-settings-tagline {
    color: var(--text-secondary);
    font-size: 14px;
}

.billing-settings-features {
    margin-bottom: 16px;
}

.billing-settings-note {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 12px;
}

/* Billing & plan — cancel, refund, access transparency */
.billing-manage-panel {
    margin: 0 0 20px;
    padding: 18px;
    border-radius: 12px;
    border: 1px solid rgba(52, 211, 153, 0.22);
    background: linear-gradient(165deg, rgba(52, 211, 153, 0.06), rgba(56, 189, 248, 0.04));
}

.billing-manage-title {
    margin: 0 0 4px;
    font-family: var(--font-display, Georgia, serif);
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}

.billing-manage-sub {
    margin: 0 0 14px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.billing-manage-explainer {
    margin: 0 0 14px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-muted);
}

.billing-manage-explainer p {
    margin: 0 0 8px;
}

.billing-manage-explainer p:last-child {
    margin-bottom: 0;
}

.billing-manage-outcome {
    margin: 0 0 14px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.55;
}

.billing-manage-outcome p {
    margin: 0;
}

.billing-manage-outcome-cancel {
    background: rgba(251, 191, 36, 0.08);
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: var(--text-secondary);
}

.billing-manage-outcome-refund {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.25);
    color: var(--text-secondary);
}

.billing-manage-appsumo {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px dashed rgba(255, 255, 255, 0.15);
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-muted);
}

.billing-manage-appsumo-title {
    margin: 0 0 6px;
    font-weight: 700;
    color: var(--text-primary);
}

.billing-manage-appsumo .billing-manage-btn {
    margin-top: 10px;
    display: inline-flex;
}

.billing-refund-countdown-note a {
    color: var(--accent-secondary, #38bdf8);
    text-decoration: underline;
}

.billing-manage-access {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
}

.billing-manage-access-kicker {
    margin: 0 0 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
}

.billing-manage-access-date {
    margin: 0 0 6px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.35;
}

.billing-manage-access-note {
    margin: 0;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.billing-refund-countdown {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px dashed rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.06);
}

.billing-refund-countdown-kicker {
    margin: 0 0 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--accent-secondary, #38bdf8);
}

.billing-refund-countdown-time {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.billing-refund-countdown-note {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.billing-manage-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.billing-manage-btn {
    flex: 1 1 auto;
    min-width: min(100%, 160px);
}

.billing-manage-btn-refund {
    border-color: rgba(56, 189, 248, 0.4);
}

.billing-manage-scheduled {
    margin: 0;
    flex: 1 1 100%;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
}

.billing-hub-status-canceling {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.4);
    background: rgba(251, 191, 36, 0.1);
}

.billing-hub-status-refunded {
    color: var(--text-muted);
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.05);
}

.modal-billing-manage {
    width: min(96vw, 480px);
    max-width: 480px;
}

.billing-manage-confirm p {
    margin: 0 0 12px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.billing-manage-confirm-list {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-muted);
}

.billing-manage-confirm-list li {
    margin-bottom: 6px;
}

.billing-manage-refund-window {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.25);
}

.billing-manage-confirm-footer {
    flex-wrap: wrap;
    gap: 8px;
}

.billing-manage-confirm-footer .btn {
    flex: 1 1 auto;
    min-width: min(100%, 140px);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.12));
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

@media (max-width: 900px) {
    .billing-plan-grid {
        grid-template-columns: 1fr;
    }

    .billing-plan-featured {
        transform: none;
    }

    .billing-shared-features {
        grid-template-columns: 1fr;
    }
}

/* Form Styles */
.form-section-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 20px 0 10px;
    padding-top: 4px;
    border-top: 1px solid var(--border-color);
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: rgba(46, 229, 157, 0.45);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Buttons */
.btn {
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    font-family: inherit;
}

.btn-primary {
    background: var(--accent-gradient);
    color: #04120c;
    border-color: transparent;
    font-weight: 600;
}

.btn-primary:hover {
    filter: brightness(1.06);
    box-shadow: 0 0 18px var(--accent-glow);
}

.btn-secondary {
    background: var(--bg-primary);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

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

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

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

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

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

.toast.warning {
    background: var(--warning);
}

.toast.info {
    background: var(--accent);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

/* Bulk Import Styles */
.bulk-import-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    margin-bottom: 16px;
}

.bulk-import-area:hover,
.bulk-import-area.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.bulk-import-area svg {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.bulk-import-area p {
    color: var(--text-secondary);
    font-size: 14px;
}

.bulk-paste-area {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
    font-size: 13px;
    resize: vertical;
    outline: none;
}

.bulk-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 12px;
}

.bulk-preview-table th,
.bulk-preview-table td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: left;
}

.bulk-preview-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    font-size: 12px;
}

/* View Header */
.view-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
}

.view-header h2 {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.view-header .member-count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 2px 10px;
    border-radius: 12px;
}

/* Org Chart View */
.org-view {
    padding: 24px;
    overflow: auto;
    height: 100%;
}

.org-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.org-level {
    display: flex;
    justify-content: center;
    gap: 16px;
    position: relative;
    padding: 8px 0;
}

.org-level::before {
    content: '';
    position: absolute;
    top: -4px;
    left: 50%;
    width: 0;
    height: 8px;
    border-left: 2px solid var(--border-color);
}

.org-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 16px;
    min-width: 140px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: var(--shadow);
}

.org-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--accent);
}

.org-card.selected {
    border-color: var(--accent);
    background: var(--accent-light);
}

.org-card-name {
    font-weight: 600;
    font-size: 14px;
}

.org-card-relation {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Pedigree View */
.pedigree-view {
    padding: 24px;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.pedigree-chart-root {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.pedigree-scroll-stage {
    background: var(--bg-secondary, #f8fafc);
}

.pedigree-scroll-inner {
    min-width: 100%;
    min-height: 100%;
}

.pg-svg {
    font-family: 'Source Sans 3', system-ui, -apple-system, sans-serif;
}

.pg-svg-fan .pg-fan-sector path {
    transition: stroke-width 0.15s ease, fill 0.15s ease;
}

.pg-svg-ancestry-arc .pg-arc-subject-ring {
    transition: stroke 0.15s ease, fill 0.15s ease;
}

.pg-land-node {
    transition: transform 0.12s ease;
}

.pg-land-node:hover {
    filter: brightness(1.02);
}

.pg-expand {
    pointer-events: all;
}

.pedigree-view-header .tree-action-btn.active {
    background: var(--accent, #2563eb);
    color: #fff;
    border-color: var(--accent, #2563eb);
}

.pedigree-focus-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 6px;
}

.pedigree-focus-select {
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--radius, 6px);
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    max-width: 200px;
}

.pedigree-ancestor-only {
    align-items: center;
    gap: 4px;
}

.pedigree-gen {
    display: flex;
    gap: 0;
    margin-bottom: 8px;
}

.pedigree-gen-label {
    width: 80px;
    flex-shrink: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    padding-top: 8px;
}

.pedigree-members {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    flex: 1;
}

.pedigree-member {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px 14px;
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
    box-shadow: var(--shadow);
}

.pedigree-member:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.pedigree-member.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
/* Family Tree View (Balkan-style) */
#view-container {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ft-app-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.ft-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.ft-view-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px 8px;
    flex-shrink: 0;
}

.ft-view-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
}

.ft-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 20px 12px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-primary);
}

.ft-toolbar-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.ft-toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 4px;
}

.tree-root-picker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    font-size: 12px;
    color: var(--text-secondary);
}

.tree-root-select {
    min-width: 160px;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 12px;
}

.member-link-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 12px;
    line-height: 1.45;
}

.member-merge-warn {
    font-size: 13px;
    color: var(--text-primary);
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(239, 68, 68, 0.08);
    border-left: 3px solid #ef4444;
    line-height: 1.45;
}

.member-link-integrity {
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 10px 12px;
    border-radius: 8px;
    border-left: 3px solid var(--accent, #2563eb);
}

.member-link-hint-sub {
    margin-bottom: 8px;
}

.member-link-dup-msg {
    margin: 10px 0 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: #fef2f2;
    color: #991b1b;
    font-size: 13px;
}

.member-link-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 12px;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.member-link-divider::before,
.member-link-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.member-link-results {
    margin-top: 6px;
    max-height: 180px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
}

.member-link-result {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.member-link-result:last-child {
    border-bottom: none;
}

.member-link-result:hover {
    background: var(--bg-secondary);
}

.member-link-result-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.member-link-result-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.member-link-selected {
    margin-top: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(37, 99, 235, 0.08);
    font-size: 13px;
}

.member-link-new-disabled {
    opacity: 0.45;
    pointer-events: none;
}

.ft-inline-popover .member-link-hint {
    font-size: 11px;
    margin-bottom: 8px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.ft-inline-popover .member-link-results {
    max-height: 110px;
}

.ft-theme-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 20px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    transition: var(--transition);
}

.ft-theme-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ft-theme-btn-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.ft-view.ft-edit-active {
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
}

.ft-view.ft-edit-active .ft-photo-hit {
    cursor: pointer;
}

.invite-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(37, 99, 235, 0.12);
    border-bottom: 1px solid rgba(37, 99, 235, 0.2);
    font-size: 13px;
}

.invite-banner .btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.auth-invite-banner {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(37, 99, 235, 0.12);
    border: 1px solid rgba(37, 99, 235, 0.22);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
}

.auth-email-locked {
    opacity: 0.85;
    cursor: not-allowed;
}

.org-switcher {
    display: inline-flex;
    align-items: center;
    margin-left: 10px;
    max-width: min(280px, 36vw);
}

.org-switcher-select {
    width: 100%;
    max-width: 280px;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 8px;
    border: 1px solid var(--border, rgba(148, 163, 184, 0.35));
    background: var(--surface, rgba(15, 23, 42, 0.5));
    color: var(--text-primary);
}

.tree-switcher {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    max-width: min(240px, 30vw);
}

.tree-switcher-select {
    width: 100%;
    max-width: 240px;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.notifications-wrap {
    position: relative;
}

.notifications-btn {
    position: relative;
}

.notifications-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.notifications-panel {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: min(360px, 92vw);
    max-height: 420px;
    overflow: auto;
    border-radius: 12px;
    border: 1px solid var(--border, rgba(148, 163, 184, 0.35));
    background: var(--card-bg, #0f172a);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
    z-index: 1200;
}

.notifications-panel.open {
    display: block;
}

.notifications-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border, rgba(148, 163, 184, 0.25));
}

.notifications-close {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.notifications-panel-body {
    padding: 8px 0 12px;
}

.notifications-section {
    padding: 0 14px 12px;
}

.notifications-section-title {
    margin: 8px 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.notifications-empty {
    margin: 0;
    font-size: 13px;
    color: var(--text-muted);
}

.notification-item {
    display: flex;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border, rgba(148, 163, 184, 0.15));
}

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

.notification-item-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(37, 99, 235, 0.15);
    color: #60a5fa;
}

.notification-item-title {
    font-size: 14px;
    font-weight: 600;
}

.notification-item-meta {
    margin-top: 2px;
    font-size: 12px;
    color: var(--text-muted);
}

.notification-item-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.notification-item-actions .btn-sm {
    padding: 5px 10px;
    font-size: 11px;
}

.ft-view .ft-edit-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 16px;
    background: #fef3c7;
    color: #92400e;
    border-bottom: 1px solid #fcd34d;
    font-size: 12px;
    flex-shrink: 0;
}

.ft-body {
    display: flex;
    flex: 1;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

.ft-member-picker {
    position: relative;
    width: var(--sidebar-width, 300px);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-primary, #fff);
    border-right: 1px solid var(--border-color, #e2e8f0);
    transition: width 0.2s ease;
}

.ft-member-picker.ft-picker-collapsed {
    width: 44px;
}

.ft-member-picker.ft-picker-collapsed .ft-picker-inner {
    display: none;
}

.ft-member-picker.ft-picker-collapsed .ft-picker-collapsed-label {
    display: flex;
}

.ft-picker-collapsed-label {
    display: none;
    flex: 1;
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted, #64748b);
    user-select: none;
}

.ft-picker-toggle {
    position: absolute;
    top: 50%;
    right: -12px;
    z-index: 5;
    width: 24px;
    height: 48px;
    margin-top: -24px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 0 8px 8px 0;
    background: var(--bg-primary, #fff);
    color: var(--text-muted, #64748b);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    box-shadow: 2px 0 6px rgba(15, 23, 42, 0.06);
}

.ft-picker-toggle:hover {
    color: var(--accent, #2563eb);
    border-color: var(--accent, #2563eb);
}

.ft-picker-inner {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 10px 10px 10px 12px;
}

.ft-picker-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding-right: 8px;
}

.ft-picker-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
}

.ft-picker-count {
    font-size: 11px;
    color: var(--text-muted, #64748b);
}

.ft-picker-search-wrap {
    margin-bottom: 8px;
    padding-right: 8px;
}

.ft-picker-search {
    width: 100%;
    box-sizing: border-box;
    padding: 7px 10px;
    font-size: 13px;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    background: var(--bg-secondary, #f8fafc);
    color: var(--text-primary, #0f172a);
}

.ft-picker-search:focus {
    outline: none;
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.ft-picker-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ft-picker-empty {
    padding: 16px 8px;
    font-size: 12px;
    color: var(--text-muted, #64748b);
    text-align: center;
}

.ft-picker-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

.ft-picker-item:hover:not(:disabled) {
    background: var(--bg-secondary, #f1f5f9);
}

.ft-picker-item-active {
    background: rgba(37, 99, 235, 0.1);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.25);
}

.ft-picker-item-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.ft-picker-badge {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
}

.ft-picker-badge-m {
    background: #dbeafe;
    color: #1d4ed8;
}

.ft-picker-badge-f {
    background: #fce7f3;
    color: #be185d;
}

.ft-picker-badge-clan {
    background: #fef3c7;
    color: #b45309;
}

.ft-picker-badge-ph {
    background: #e2e8f0;
    color: #64748b;
}

.ft-picker-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.ft-picker-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #0f172a);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ft-picker-sub {
    font-size: 11px;
    color: var(--text-muted, #64748b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ft-canvas-wrap {
    flex: 1;
    width: 100%;
    min-height: 0;
    overflow: hidden;
    position: relative;
    cursor: grab;
}

.ft-loading {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(248, 250, 252, 0.72);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    pointer-events: none;
}

.ft-loading.ft-loading-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.ft-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(37, 99, 235, 0.2);
    border-top-color: var(--accent, #2563eb);
    border-radius: 50%;
    animation: ft-spin 0.7s linear infinite;
}

.ft-loading-text {
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

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

[data-theme="dark"] .ft-loading {
    background: rgba(15, 23, 42, 0.75);
}

.ft-canvas-wrap:active {
    cursor: grabbing;
}

.ft-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.ft-svg {
    display: block;
}

.ft-node-focus {
    filter: drop-shadow(0 8px 16px rgba(37, 99, 235, 0.18));
}

.ft-node-selected rect {
    filter: drop-shadow(0 4px 10px rgba(37, 99, 235, 0.12));
}

.ft-node-clan > rect {
    stroke: #b45309;
    fill: #fffbeb;
}

.ft-node-clan.ft-node-focus > rect {
    fill: #fef3c7;
}

.ft-node-placeholder > rect {
    fill: #f1f5f9;
    stroke-dasharray: 4, 3;
}

.ft-node-placeholder.ft-node-selected > rect {
    stroke-dasharray: 6, 3;
}

[data-theme="dark"] .ft-node-placeholder > rect {
    fill: #1e293b;
}

.ft-add-slot:hover rect {
    stroke: var(--accent);
    opacity: 1;
}

.ft-action-rail-in-card .ft-action-btn circle {
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35));
}

.ft-action-rail-below .ft-action-btn circle {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.ft-action-btn circle {
    transition: transform 0.15s ease, filter 0.15s ease;
}

.ft-action-btn:hover circle {
    filter: brightness(1.1);
}

.ft-edge-add circle {
    transition: transform 0.15s ease, filter 0.15s ease;
}

.ft-edge-add:hover circle {
    filter: brightness(1.08);
}

.ft-edge-add-disabled circle {
    cursor: not-allowed;
}

.ft-edge-add-disabled:hover circle {
    filter: none;
}

.ft-handle-help {
    position: absolute;
    z-index: 60;
    max-width: 280px;
    padding: 10px 12px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12);
    font-size: 12px;
    line-height: 1.45;
    color: var(--text, #334155);
    white-space: pre-line;
    pointer-events: none;
}

[data-theme="dark"] .ft-handle-help {
    background: var(--bg-secondary, #1e293b);
    border-color: var(--border, #334155);
    color: var(--text, #e2e8f0);
}

.ft-inline-popover {
    position: absolute;
    z-index: 50;
    box-sizing: border-box;
    width: min(280px, calc(100vw - 24px));
    max-width: min(280px, calc(100vw - 24px));
    min-width: 0;
    max-height: min(420px, calc(100vh - 24px));
    padding: 10px 12px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.ft-inline-popover--link {
    width: min(300px, calc(100vw - 24px));
    max-width: min(300px, calc(100vw - 24px));
}

.ft-inline-popover-sheet {
    position: fixed !important;
    left: 10px !important;
    right: 10px !important;
    bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
    top: auto !important;
    width: auto !important;
    max-width: none !important;
    max-height: min(58dvh, 440px) !important;
    z-index: 8500;
}

.ft-inline-popover .member-link-form {
    min-width: 0;
    width: 100%;
}

.ft-inline-popover .member-link-integrity-compact {
    font-size: 11px;
    padding: 8px 10px;
    margin-bottom: 8px;
    line-height: 1.4;
}

.ft-inline-popover .member-link-search,
.ft-inline-popover .ft-pop-input,
.ft-inline-popover input,
.ft-inline-popover select,
.ft-inline-popover textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.ft-inline-popover .member-link-divider {
    margin: 10px 0 8px;
    font-size: 10px;
}

.ft-inline-popover .ft-pop-save {
    min-height: 36px;
}

.ft-pop-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ft-pop-input {
    width: 100%;
    padding: 6px 8px;
    font-size: 13px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 6px;
    background: var(--bg-secondary, #f8fafc);
    color: var(--text-primary, #0f172a);
    box-sizing: border-box;
}

.ft-pop-save {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: var(--accent, #2563eb);
    color: #fff;
    cursor: pointer;
}

.ft-pop-save:hover {
    filter: brightness(1.05);
}

.ft-pop-hint {
    margin: 0 0 8px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-muted, #64748b);
}

.ft-pop-unknown {
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 500;
    border: 1px dashed var(--border, #cbd5e1);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted, #64748b);
    cursor: pointer;
}

.ft-pop-unknown:hover {
    border-color: var(--accent, #2563eb);
    color: var(--accent, #2563eb);
}

.ft-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: var(--z-modal, 2000);
    display: none;
    align-items: center;
    justify-content: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

.ft-modal-overlay.active {
    display: flex;
}

.ft-modal-overlay .modal {
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    border-radius: var(--radius-lg, 12px);
    max-width: 440px;
    width: min(92vw, 440px);
    max-height: min(86dvh, calc(var(--viewport-height, 100dvh) - 32px), 720px);
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

@media (max-width: 768px) {
    .modal-footer {
        flex-wrap: wrap;
        justify-content: stretch;
    }

    .modal-footer .btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }

    .folder-view-toolbar {
        padding: 8px 12px;
        gap: 8px;
    }

    .folder-toolbar-search-row {
        flex: 1 1 100%;
        order: 3;
        max-width: none;
        width: 100%;
    }

    .folder-toolbar-search-row .folder-toolbar-search {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        width: auto;
    }

    .folder-hanging-btn {
        flex: 0 0 auto;
        min-height: 44px;
        padding: 0 12px;
        font-size: 11px;
    }

    .folder-hanging-btn-label-full,
    .folder-add-line-btn-label-full {
        display: none;
    }

    .folder-add-line-btn-label-short {
        display: inline;
    }

    .folder-hanging-btn-label-short,
    .folder-hanging-btn-count {
        display: inline-flex;
    }

    .folder-toolbar-primary {
        flex: 1 1 100%;
        order: 1;
    }

    .folder-family-picker-slot {
        flex: 1 1 100%;
        min-width: 0;
    }

    .folder-family-picker-slot .family-line-select {
        width: 100%;
        max-width: none;
    }

    .folder-add-line-btn,
    .folder-toolbar-edit-btn {
        min-height: 44px;
    }

    .folder-toolbar-search {
        flex: 1 1 auto;
        min-width: 0;
        max-width: none;
        order: 3;
    }

    .folder-toolbar-actions {
        margin-left: 0;
        width: 100%;
        order: 4;
    }

    .tree-hanging-banner {
        flex-direction: column;
        align-items: stretch;
    }

    .tree-hanging-back-btn {
        width: 100%;
        justify-content: center;
        min-height: 44px;
    }

    .ft-toolbar {
        padding: 8px 12px;
    }

    .ft-theme-group {
        width: 100%;
    }

    .header-nav-desktop {
        display: none;
    }


    .info-grid {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .person-header {
        flex-direction: column;
        text-align: center;
    }
}

/* Supabase auth gate — scrollable document (app shell locks html/body elsewhere) */
html.auth-page,
html:has(body.auth-page) {
    overflow-x: hidden;
    overflow-y: auto;
    height: auto;
    min-height: var(--viewport-height, 100vh);
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

body.auth-page {
    overflow-x: hidden;
    overflow-y: visible;
    height: auto;
    min-height: var(--viewport-height, 100vh);
    background: var(--bg-secondary);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

body.auth-page #app {
    padding-bottom: 0;
}

body.auth-page .mobile-tab-bar {
    display: none !important;
}

body.auth-page::before {
    background:
        radial-gradient(ellipse 60% 50% at 15% 0%, rgba(46, 229, 157, 0.12), transparent 55%),
        radial-gradient(ellipse 50% 40% at 85% 20%, rgba(56, 189, 248, 0.1), transparent 50%);
}

.ui-icon,
.ui-icon svg {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.icon-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.icon-label .ui-icon {
    color: var(--accent);
}

.logo-icon,
.title-icon {
    color: var(--accent);
}

.nav-icon {
    opacity: 0.9;
}

.context-menu-item .icon-label {
    width: 100%;
}

.context-menu-item .menu-icon {
    color: var(--text-muted);
}

.children-section h3 .icon-label,
.folder-view-toolbar .icon-label {
    font-size: inherit;
    font-weight: inherit;
}

/* Folder mobile panel tabs — see layout overhaul block at end of file */

.child-card-icon .ui-icon,
.person-avatar .ui-icon,
.tree-icon .ui-icon {
    color: inherit;
}

.tree-icon.male .ui-icon { color: var(--male-color); }
.tree-icon.female .ui-icon { color: var(--female-color); }
.child-card-icon.male .ui-icon { color: var(--male-color); }
.child-card-icon.female .ui-icon { color: var(--female-color); }

.person-actions button,
.tree-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.auth-shell {
    --auth-hero-bg: linear-gradient(155deg, #07080d 0%, #10131c 40%, #0f1724 100%);
    --auth-panel-bg: var(--bg-primary);
    --auth-accent: var(--accent);
    --auth-hero-fg: #ffffff;
    --auth-hero-fg-muted: rgba(255, 255, 255, 0.88);
    --auth-hero-node: rgba(255, 255, 255, 0.85);
    --auth-hero-node-sm: rgba(255, 255, 255, 0.6);
    --auth-hero-link: rgba(255, 255, 255, 0.45);
    --auth-hero-trunk: rgba(46, 229, 157, 0.9);
    --auth-hero-root: rgba(46, 229, 157, 0.85);
    --auth-hero-grid: rgba(255, 255, 255, 0.04);
    min-height: var(--viewport-height, 100vh);
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
}

[data-theme="light"] .auth-shell {
    --auth-hero-bg: linear-gradient(155deg, #ecfdf5 0%, #f0f9ff 55%, #e0f2fe 100%);
    --auth-hero-fg: #0f172a;
    --auth-hero-fg-muted: #475569;
    --auth-hero-node: rgba(5, 150, 105, 0.24);
    --auth-hero-node-sm: rgba(5, 150, 105, 0.16);
    --auth-hero-link: rgba(5, 150, 105, 0.42);
    --auth-hero-trunk: rgba(5, 150, 105, 0.72);
    --auth-hero-root: rgba(2, 132, 199, 0.72);
    --auth-hero-grid: rgba(15, 23, 42, 0.06);
}

.auth-hero {
    position: relative;
    overflow: hidden;
    background: var(--auth-hero-bg);
    color: var(--auth-hero-fg);
    padding: 48px 56px;
    display: flex;
    align-items: center;
    border-right: 1px solid var(--border-color);
}

.auth-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: radial-gradient(circle at 1px 1px, var(--auth-hero-grid) 1px, transparent 0);
    background-size: 22px 22px;
    pointer-events: none;
}

.auth-hero::after {
    content: '';
    position: absolute;
    inset: auto -20% -30% 20%;
    height: 280px;
    background: radial-gradient(circle, rgba(46, 229, 157, 0.18), transparent 65%);
    pointer-events: none;
}

.auth-hero-inner {
    position: relative;
    z-index: 1;
    max-width: 440px;
}

.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--auth-hero-fg);
    text-decoration: none;
    font-family: 'Fraunces', Georgia, serif;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 40px;
}

.auth-brand .logo-icon {
    color: var(--accent);
}

.auth-brand svg {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.auth-brand:hover {
    opacity: 0.92;
}

.auth-hero-svg {
    width: min(100%, 300px);
    height: auto;
    margin-bottom: 28px;
    filter: drop-shadow(0 8px 24px rgba(0, 0, 0, 0.12));
}

.auth-tree-node {
    fill: var(--auth-hero-node);
}

.auth-tree-node-sm {
    fill: var(--auth-hero-node-sm);
}

.auth-tree-link,
.auth-tree-ground {
    stroke: var(--auth-hero-link);
    stroke-linecap: round;
    fill: none;
}

.auth-tree-link {
    stroke-width: 3;
}

.auth-tree-ground {
    stroke-width: 4;
}

.auth-tree-trunk {
    stroke: var(--auth-hero-trunk);
    stroke-width: 5;
    stroke-linecap: round;
}

.auth-tree-root {
    fill: var(--auth-hero-root);
}

.auth-hero-title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: clamp(28px, 4vw, 38px);
    font-weight: 700;
    line-height: 1.15;
    margin-bottom: 14px;
    letter-spacing: -0.02em;
    color: var(--auth-hero-fg);
}

.auth-hero-text {
    font-size: 16px;
    line-height: 1.65;
    color: var(--auth-hero-fg-muted);
    margin-bottom: 28px;
}

.auth-hero-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 32px;
}

.auth-hero-features li {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 15px;
    color: var(--auth-hero-fg);
}

.auth-feature-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--accent-light);
    border: 1px solid rgba(46, 229, 157, 0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

[data-theme="light"] .auth-feature-icon {
    background: rgba(5, 150, 105, 0.08);
    border-color: rgba(5, 150, 105, 0.18);
}

.auth-feature-icon .ui-icon {
    color: var(--accent);
}

.auth-hero-foot a {
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.auth-hero-foot a .icon-label {
    color: var(--accent);
}

.auth-hero-foot a:hover {
    text-decoration: underline;
}

.auth-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: safe center;
    padding: 32px 24px max(24px, env(safe-area-inset-bottom, 0px));
    background: var(--bg-secondary);
    min-height: 0;
}

.auth-panel-top {
    width: 100%;
    max-width: 440px;
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.auth-theme-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--auth-panel-bg);
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.auth-theme-btn:hover {
    background: var(--bg-secondary);
    transform: scale(1.05);
}

.auth-panel-card {
    width: 100%;
    max-width: 440px;
    background: var(--auth-panel-bg);
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    padding: 36px 32px 28px;
    box-shadow: var(--shadow-md), 0 0 40px rgba(46, 229, 157, 0.04);
}

[data-theme="dark"] .auth-panel-card {
    border-color: var(--border-color);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.auth-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    margin-bottom: 28px;
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .auth-tabs {
    background: var(--bg-secondary);
}

.auth-tab {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 12px;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.auth-tab:hover {
    color: var(--text-primary);
}

.auth-tab.active {
    background: var(--bg-primary);
    color: var(--accent);
    box-shadow: 0 0 16px var(--accent-glow);
}

[data-theme="dark"] .auth-tab.active {
    color: var(--text-primary);
}

.auth-title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.auth-subtitle {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.55;
}

.auth-form {
    display: flex;
    flex-direction: column;
}

.auth-field {
    margin-bottom: 18px;
}

.auth-field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.auth-field input {
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    font-size: 15px;
}

.auth-field input:focus {
    border-color: rgba(46, 229, 157, 0.45);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.auth-input-wrap {
    position: relative;
}

.auth-input-wrap input {
    padding-right: 72px;
}

.auth-toggle-pw {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
}

.auth-toggle-pw:hover {
    background: var(--accent-light);
}

.auth-toggle-pw .auth-eye-hide {
    display: none;
}

.auth-toggle-pw.is-visible .auth-eye-show {
    display: none;
}

.auth-toggle-pw.is-visible .auth-eye-hide {
    display: inline;
}

.auth-row-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.auth-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.45;
}

.auth-check input {
    margin-top: 3px;
    accent-color: var(--accent);
}

.auth-check-terms {
    margin-bottom: 16px;
}

.auth-check a {
    color: var(--accent);
    font-weight: 600;
}

.auth-link-btn {
    border: none;
    background: none;
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-link-btn:hover {
    color: var(--accent-hover);
}

.auth-alert {
    font-size: 13px;
    line-height: 1.5;
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.auth-alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: #b91c1c;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

[data-theme="dark"] .auth-alert-error {
    color: #fca5a5;
}

.auth-alert-info {
    background: var(--accent-light);
    color: var(--text-secondary);
    border: 1px solid rgba(46, 229, 157, 0.22);
}

[data-theme="light"] .auth-alert-info {
    color: #065f46;
    background: rgba(5, 150, 105, 0.08);
    border-color: rgba(5, 150, 105, 0.18);
}

[data-theme="dark"] .auth-alert-info {
    color: var(--text-secondary);
}

.auth-submit {
    width: 100%;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 4px;
    background: var(--accent-gradient);
    border: none;
    color: #04120c;
}

[data-theme="light"] .auth-submit {
    color: #ffffff;
}

.auth-submit:hover:not(:disabled) {
    filter: brightness(1.06);
    box-shadow: 0 0 20px var(--accent-glow);
}

.auth-submit:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.auth-submit.auth-loading {
    position: relative;
    color: transparent;
}

.auth-submit.auth-loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    top: 50%;
    left: 50%;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin 0.7s linear infinite;
}

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

.auth-switch {
    text-align: center;
    margin-top: 22px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 14px;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.auth-demo-btn {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
}

.auth-demo-note {
    text-align: center;
    font-size: 12px;
    line-height: 1.55;
    color: var(--text-muted);
    margin: 0 0 4px;
}

.auth-qa-btn {
    display: block;
    width: 100%;
    margin: 8px 0 0;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px;
    font-family: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-qa-btn:hover {
    color: var(--accent);
}

.demo-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background: rgba(56, 189, 248, 0.12);
    color: var(--accent-secondary);
    border-bottom: 1px solid rgba(56, 189, 248, 0.22);
    padding: 10px 16px;
    font-size: 13px;
}

.demo-banner-text {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 200px;
    line-height: 1.5;
}

.demo-banner-icon {
    flex-shrink: 0;
}

.demo-banner-link {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.demo-banner-exit {
    font-size: 12px;
    padding: 6px 12px;
    white-space: nowrap;
}

.auth-back-btn {
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    margin-bottom: 20px;
    font-family: inherit;
}

.auth-back-btn:hover {
    color: var(--accent);
}

.auth-strength {
    margin: -8px 0 14px;
}

.auth-strength-track {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 99px;
    overflow: hidden;
    margin-bottom: 4px;
}

.auth-strength-fill {
    height: 100%;
    width: 0;
    border-radius: 99px;
    transition: width 0.25s ease, background 0.25s ease;
    background: var(--danger);
}

.auth-strength-fill[data-level="2"] {
    background: var(--warning);
}

.auth-strength-fill[data-level="3"],
.auth-strength-fill[data-level="4"] {
    background: var(--accent);
}

.auth-strength-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.auth-success-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--accent-light);
    border: 1px solid rgba(46, 229, 157, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.auth-mail-icon {
    color: var(--accent);
}

.auth-legal {
    margin-top: 20px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.auth-legal a {
    color: var(--text-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-legal a:hover {
    color: var(--accent);
}

.auth-signup-policies {
    margin: 16px 0 0;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}

.auth-signup-policies a {
    color: var(--text-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.auth-signup-policies a:hover {
    color: var(--accent);
}

@media (max-width: 960px) {
    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-hero {
        padding: 32px 24px 36px;
        min-height: auto;
    }

    .auth-hero-inner {
        max-width: none;
        text-align: center;
    }

    .auth-brand {
        margin-bottom: 20px;
    }

    .auth-hero-svg {
        margin: 0 auto 20px;
        width: min(220px, 70%);
    }

    .auth-hero-features {
        align-items: flex-start;
        text-align: left;
        max-width: 320px;
        margin-left: auto;
        margin-right: auto;
    }

    .auth-hero-foot {
        display: none;
    }

    .auth-panel {
        justify-content: flex-start;
        padding: max(12px, env(safe-area-inset-top, 0px)) 16px max(32px, env(safe-area-inset-bottom, 0px));
    }

    .auth-panel-card {
        padding: 28px 22px 22px;
        border-radius: 16px;
    }

    .auth-legal {
        margin-top: 16px;
        padding-bottom: 8px;
    }
}

@media (max-width: 480px) {
    .auth-title {
        font-size: 24px;
    }

    .auth-tabs {
        margin-bottom: 22px;
    }

    .auth-panel-top {
        margin-bottom: 4px;
    }

    .auth-check-terms span {
        font-size: 13px;
        line-height: 1.45;
    }
}

/* --- PRD Phase 2: Directory & search --- */
.directory-view {
    padding: 16px 20px 24px;
    height: 100%;
    overflow: auto;
}

.directory-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    margin-bottom: 20px;
}

.directory-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-left: auto;
}

.directory-controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.directory-controls select,
.directory-controls input {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
}

.directory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 14px;
}

.directory-card {
    display: flex;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.directory-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-sm);
}

.directory-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}

.directory-card-avatar.male { background: #dbeafe; color: #2563eb; }
.directory-card-avatar.female { background: #fce7f3; color: #db2777; }
.directory-card-avatar img { width: 100%; height: 100%; object-fit: cover; }

.directory-card-name { font-weight: 600; margin-bottom: 4px; }
.directory-card-meta { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.directory-card-contact { font-size: 12px; color: var(--text-muted); }
.directory-contact-muted { font-style: italic; }
.directory-you-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    vertical-align: middle;
}

.directory-hanging-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.hanging-nodes-view .hanging-intro {
    margin: 0 0 16px;
    padding: 0 4px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    max-width: 720px;
}

.hanging-card-reasons {
    margin: 8px 0 10px;
    padding-left: 18px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.45;
}

.hanging-card-parents {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.hanging-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.hanging-card-actions .btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

.tree-node-content.search-dimmed {
    opacity: 0.32;
}

.tree-node-content.search-dimmed:hover {
    opacity: 0.55;
}

/* --- PRD Phase 3: Gift & growth --- */
.viewer-growth-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 10px 16px;
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.12), rgba(6, 182, 212, 0.1));
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
}

.viewer-growth-banner p { margin: 0; flex: 1; min-width: 200px; }
.viewer-growth-dismiss {
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
}

.billing-gift-cta {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.billing-gift-cta p { margin: 0 0 10px; font-size: 14px; }
.gift-lead { color: var(--text-secondary); margin-bottom: 16px; }

/* --- Brand voice: sanctuary & care --- */
.brand-trust-strip {
    margin-top: 20px;
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-secondary);
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(6, 182, 212, 0.08));
    border: 1px solid var(--border-color);
}

.brand-trust-strip a { color: var(--accent); font-weight: 600; }

.app-sanctuary-strip {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-secondary);
    background: linear-gradient(90deg, rgba(34, 197, 94, 0.1), rgba(6, 182, 212, 0.08));
    border-bottom: 1px solid var(--border-color);
}

.app-sanctuary-text { flex: 1; min-width: 0; }
.app-sanctuary-text a { color: var(--accent); font-weight: 600; white-space: nowrap; }

.app-sanctuary-dismiss {
    border: none;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px 6px;
}

.brand-sanctuary-note {
    margin-top: 16px;
    padding: 14px 16px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    font-size: 13px;
    line-height: 1.55;
}

.brand-sanctuary-lead { margin: 0 0 8px; color: var(--text-primary); }
.brand-sanctuary-note p { margin: 0 0 10px; color: var(--text-secondary); }
.brand-sanctuary-foot { margin: 12px 0 0 !important; font-size: 12px; }

.brand-never-list {
    margin: 8px 0 0;
    padding-left: 1.2rem;
    color: var(--text-secondary);
}

.brand-never-list li { margin-bottom: 6px; }

/* --- Unified member add panel --- */
.member-add-panel {
    position: fixed;
    inset: 0;
    z-index: 9200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.member-add-panel.open {
    pointer-events: auto;
    opacity: 1;
}

.member-add-panel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 14, 0.55);
    backdrop-filter: blur(4px);
}

.member-add-panel-dialog {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(420px, 100%);
    max-height: min(88vh, 720px);
    background: var(--bg-primary);
    border: 1px solid var(--border-strong);
    border-radius: 16px;
    box-shadow: var(--shadow-md), 0 24px 48px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    transform: translateY(12px) scale(0.98);
    transition: transform 0.22s ease;
}

.member-add-panel.open .member-add-panel-dialog {
    transform: translateY(0) scale(1);
}

.member-add-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    flex-shrink: 0;
}

.member-add-panel-heading h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.3;
}

.member-add-panel-close {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.member-add-panel-close:hover {
    background: var(--accent-light);
    color: var(--text-primary);
}

.member-add-panel-context {
    margin-top: 10px;
}

.member-add-context-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
}

.member-add-context-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    overflow: hidden;
}

.member-add-context-avatar.male { background: #dbeafe; color: #1d4ed8; }
.member-add-context-avatar.female { background: #fce7f3; color: #be185d; }
.member-add-context-avatar img { width: 100%; height: 100%; object-fit: cover; }

.member-add-context-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.member-add-context-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.member-add-context-text strong {
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-add-context-relation {
    font-size: 12px;
    color: var(--text-secondary);
}

.member-add-panel-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 16px 20px;
}

.member-add-panel-body .form-group {
    margin-bottom: 14px;
}

.member-add-panel-body .form-group:last-child {
    margin-bottom: 0;
}

.member-add-panel-body .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.member-add-note {
    margin: 0 0 12px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
}

.member-add-panel-body .member-link-results {
    max-height: 160px;
}

.member-add-panel-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.member-add-panel-footer .btn {
    min-height: 40px;
}

body.member-add-panel-open {
    overflow: hidden;
}

.map-field-input,
.member-add-panel-body .ft-pop-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-sizing: border-box;
    transition: border-color 0.15s ease;
}

.map-field-input:focus,
.member-add-panel-body .ft-pop-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.member-add-panel-body .ft-pop-unknown {
    width: 100%;
    margin-bottom: 10px;
    padding: 10px 12px;
    font-size: 13px;
}

@media (max-width: 520px) {
    .member-add-panel {
        align-items: flex-end;
        padding: 0;
    }

    .member-add-panel-dialog {
        width: 100%;
        max-height: min(92dvh, var(--viewport-height, 100dvh));
        border-radius: 16px 16px 0 0;
        border-bottom: none;
    }

    .member-add-panel-body .form-row {
        grid-template-columns: 1fr;
    }

    .member-add-panel-footer {
        justify-content: stretch;
    }

    .member-add-panel-footer .btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .member-add-panel,
    .member-add-panel-dialog {
        transition: none !important;
    }
}

/* --- PRD Phase 4: Person drawer & polish --- */
.person-drawer {
    position: fixed;
    inset: 0;
    z-index: 9000;
    pointer-events: none;
}

.person-drawer.open { pointer-events: auto; }

.person-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.person-drawer.open .person-drawer-backdrop { opacity: 1; }

.person-drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: min(380px, 92vw);
    height: 100%;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    padding: 20px;
    overflow-y: auto;
}

.person-drawer.open .person-drawer-panel { transform: translateX(0); }

.person-drawer-close {
    position: absolute;
    top: 12px;
    right: 12px;
    border: none;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 6px;
    cursor: pointer;
}

.person-drawer-header {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    padding-right: 36px;
}

.person-drawer-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    overflow: hidden;
    flex-shrink: 0;
}

.person-drawer-avatar.male { background: #dbeafe; }
.person-drawer-avatar.female { background: #fce7f3; }
.person-drawer-avatar img { width: 100%; height: 100%; object-fit: cover; }

.person-drawer-relation { color: var(--text-secondary); font-size: 13px; margin: 4px 0 0; }
.person-drawer-notes { font-size: 13px; color: var(--text-secondary); margin-top: 12px; }
.person-drawer-actions { margin-top: 20px; }

@media (max-width: 768px) {
    .nav-btn,
    .nav-btn-icon,
    .icon-btn,
    .tree-action-btn {
        min-height: 44px;
        min-width: 44px;
    }

    .member-jump-input {
        min-height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .person-drawer-panel,
    .person-drawer-backdrop,
    .directory-card,
    .tree-progress-spinner {
        transition: none !important;
        animation: none !important;
    }
}

/* ============================================================
   Layout overhaul — app chrome, mobile nav, folder panels
   See docs/DESIGN-SYSTEM.md
   ============================================================ */

#app {
    padding-bottom: 0;
}

.app-alerts {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex-shrink: 0;
}

.app-version-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--space-3, 12px);
    padding: var(--space-3, 12px) var(--space-4, 16px);
    background: var(--accent-muted, #1e3a5f);
    color: var(--text-primary, #f8fafc);
    font-size: var(--text-sm, 13px);
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    z-index: 1200;
}

.app-version-banner-text {
    text-align: center;
}

.app-alert {
    flex-shrink: 0;
}

.billing-banner {
    background: var(--warning-bg, #fef3c7);
    color: var(--warning-text, #92400e);
    padding: var(--space-3, 12px) var(--space-4, 16px);
    text-align: center;
    font-size: var(--text-sm, 13px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.billing-banner-link {
    font-weight: 600;
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.mobile-tab-bar {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100vw;
    z-index: var(--z-mobile-nav, 1400);
    box-sizing: border-box;
    height: var(--mobile-tab-inset, calc(var(--mobile-tab-height, 60px) + env(safe-area-inset-bottom, 0px)));
    padding: var(--space-1, 4px) 0 env(safe-area-inset-bottom, 0px);
    background: var(--bg-elevated, var(--bg-primary));
    border-top: 1px solid var(--border-strong);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    gap: 0;
    overflow: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

.mobile-tab-btn {
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    max-width: 20%;
    min-height: 0;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 2px 1px;
    border: none;
    border-radius: var(--radius-sm, 6px);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-xs, 11px);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--transition), background var(--transition);
}

.mobile-tab-btn span {
    display: block;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-tab-btn .ui-icon {
    opacity: 0.9;
    color: inherit;
}

.mobile-tab-btn .ui-icon svg {
    display: block;
    width: 20px;
    height: 20px;
    stroke: currentColor;
    color: inherit;
}

.mobile-tab-btn.active {
    color: var(--accent);
    background: var(--accent-light);
}

.mobile-tab-btn.active .ui-icon {
    opacity: 1;
}

.ft-mobile-member-search {
    display: none;
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    max-width: none;
}

.folder-mobile-tabs {
    display: none;
    flex-shrink: 0;
    padding: var(--space-2, 8px) var(--space-4, 16px);
    gap: var(--space-2, 8px);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.folder-mobile-tab {
    flex: 1;
    min-height: var(--touch-min, 44px);
    padding: var(--space-2, 8px) var(--space-3, 12px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius, 10px);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: var(--text-sm, 13px);
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}

.folder-mobile-tab.active {
    background: var(--accent-light);
    color: var(--accent);
    border-color: rgba(46, 229, 157, 0.35);
}

.nav-views-mobile-fallback {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.btn {
    min-height: var(--touch-min, 44px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-sm {
    min-height: 36px;
}

.modal-close {
    min-width: var(--touch-min, 44px);
    min-height: var(--touch-min, 44px);
}

.header-drawer-close {
    min-width: var(--touch-min, 44px);
    min-height: var(--touch-min, 44px);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.header-drawer-item {
    min-height: var(--touch-min, 44px);
}

.tree-action-btn {
    min-height: 36px;
    padding: var(--space-2, 8px) var(--space-3, 12px);
    font-size: var(--text-xs, 12px);
}

.import-preview-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: var(--space-3, 12px);
}

@media (max-width: 640px) {
    .modal-overlay.active,
    .modal-overlay.duplicate-name-confirm-overlay.active,
    .ft-modal-overlay.active {
        align-items: flex-end;
        padding: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .modal-overlay.active .modal,
    .ft-modal-overlay.active .modal {
        width: 100%;
        max-width: none;
        max-height: min(92dvh, var(--viewport-height, 100dvh));
        border-radius: var(--radius-xl, 16px) var(--radius-xl, 16px) 0 0;
        border-bottom: none;
    }

    .ft-inline-popover-sheet {
        bottom: max(calc(var(--mobile-tab-inset, 60px) + 8px), env(safe-area-inset-bottom, 0px)) !important;
        max-height: min(50dvh, calc(var(--viewport-height, 100dvh) - var(--mobile-tab-inset, 60px) - 24px)) !important;
    }

    body.modal-open .ft-inline-popover-sheet {
        bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
        max-height: min(58dvh, 440px) !important;
    }

    .detail-panel {
        padding: var(--space-4, 16px);
    }

    .person-actions {
        flex-wrap: wrap;
    }

    .person-actions button {
        flex: 1 1 calc(50% - var(--space-2, 8px));
        min-height: var(--touch-min, 44px);
    }
}

@media (max-width: 768px) {
    #app {
        height: calc(var(--viewport-height, 100vh) - var(--mobile-tab-inset));
        padding-bottom: 0;
    }

    .mobile-tab-bar {
        display: flex;
    }

    .mobile-tab-btn {
        font-size: 10px;
    }

    .mobile-tab-btn .ui-icon svg {
        width: 18px;
        height: 18px;
    }

    .ft-mobile-member-search {
        display: block;
        order: -1;
    }

    .ft-member-picker {
        display: none !important;
    }

    .ft-body {
        flex-direction: column;
    }

    .ft-canvas-wrap {
        width: 100%;
        flex: 1;
    }

    .header-nav-mobile.nav-views-mobile-fallback {
        display: block;
    }

    .header-nav-mobile:not(.nav-views-mobile-fallback) {
        display: none;
    }

    .header-logo-text {
        display: none;
    }

    .header-context {
        flex: 1 1 auto;
        min-width: 0;
    }

    .member-count {
        display: none;
    }

    .undo-btn-text {
        display: none;
    }

    .folder-mobile-tabs {
        display: flex;
    }

    .folder-view-panels[data-mobile-panel="tree"] .detail-panel {
        display: none;
    }

    .folder-view-panels[data-mobile-panel="detail"] .folder-tree-panel,
    .folder-view-panels[data-mobile-panel="detail"] .resize-handle {
        display: none;
    }

    .folder-view-panels[data-mobile-panel="detail"] .detail-panel {
        flex: 1;
        min-height: 0;
    }

    .toast-container {
        bottom: calc(var(--mobile-tab-inset) + var(--space-4, 16px));
        right: var(--space-3, 12px);
        left: var(--space-3, 12px);
    }

    .toast {
        max-width: none;
    }
}

@media (max-width: 768px) and (orientation: portrait) {
    .folder-view-panels[data-mobile-panel="tree"] {
        flex-direction: column;
    }

    .folder-view-panels[data-mobile-panel="tree"] .folder-tree-panel {
        width: 100% !important;
        max-width: none;
        height: 100%;
        min-height: 0;
        flex: 1;
        border-right: none;
    }

    .folder-view-panels[data-mobile-panel="tree"] .resize-handle {
        display: none;
    }
}

@media (min-width: 769px) {
    .folder-mobile-tabs {
        display: none !important;
    }
}

/* ============================================================
   Desktop UX polish — header, profiles, toolbars (≥769px)
   ============================================================ */

.header-context .header-role-badge-wrap {
    display: inline-flex;
    align-items: center;
    max-width: min(220px, 24vw);
    min-width: 0;
    flex-shrink: 1;
}

.header-context .header-role-badge-wrap:empty {
    display: none;
}

.header-desktop-tree-actions {
    display: none;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.header-desktop-tree-actions .tree-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.header-import-btn span,
.header-export-trigger span {
    font-size: var(--text-xs, 12px);
    font-weight: 600;
}

.nav-btn-label--short {
    display: none;
}

.person-actions-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.person-actions-primary {
    flex-wrap: wrap;
}

.person-actions-more-wrap {
    position: relative;
    flex-shrink: 0;
}

.person-actions-more-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
}

.ft-toolbar-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-right: 2px;
    flex-shrink: 0;
}

.ft-toolbar-mobile-only {
    display: none;
}

.pedigree-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

@media (min-width: 769px) {
    .header-desktop-tree-actions {
        display: inline-flex;
    }

    .header-nav-desktop {
        margin-left: 8px;
        gap: 2px;
        flex-shrink: 1;
        min-width: 0;
    }

    .nav-btn {
        padding: 6px 8px;
        font-size: 12px;
    }

    .nav-btn-label--full {
        display: none;
    }

    .nav-btn-label--short {
        display: inline;
    }

    .undo-btn-text {
        display: none;
    }

    .undo-btn {
        padding: 6px 10px;
    }

    .person-card {
        max-width: none;
        width: 100%;
    }

    .person-header {
        margin-bottom: 0;
    }

    .pedigree-view {
        padding: 0;
    }

    .pedigree-view-header {
        flex-wrap: wrap;
        row-gap: 8px;
    }

    .ft-toolbar {
        row-gap: 10px;
    }

    .ft-toolbar-group {
        padding-right: 8px;
        border-right: 1px solid var(--border-color);
    }

    .ft-toolbar-group:last-of-type,
    .ft-theme-group {
        border-right: none;
    }

    .ft-toolbar-desktop-only {
        display: inline-flex;
    }

    .ft-toolbar-mobile-only {
        display: none;
    }

    .tree-root-picker {
        margin-left: auto;
    }
}

@media (min-width: 1024px) {
    .view-header-slim .view-header-title {
        display: none;
    }

    .view-header-slim {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .directory-view {
        padding: 12px 24px 24px;
    }

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

    .children-list {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

@media (min-width: 1200px) {
    .nav-btn {
        padding: 7px 12px;
        font-size: 13px;
    }

    .nav-btn-label--full {
        display: inline;
    }

    .nav-btn-label--short {
        display: none;
    }

    .undo-btn-text {
        display: flex;
    }
}

@media (max-width: 768px) {
    .header-desktop-tree-actions {
        display: none !important;
    }

    .header-context .header-role-badge-wrap {
        display: none;
    }

    .ft-toolbar-desktop-only {
        display: none !important;
    }

    .ft-toolbar-mobile-only {
        display: inline-flex;
    }

    .ft-toolbar-group {
        border-right: none;
        padding-right: 0;
    }

    .ft-toolbar-label {
        display: none;
    }
}