/* Main Styles */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

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

/* ── A4: Card scale design tokens (Decision D4) ──────────────────────────────
   Three fixed breakpoints. Change values here; everything that uses these
   variables scales automatically. Migrate to clamp() later if needed.
   ─────────────────────────────────────────────────────────────────────────── */
:root {
    /* Desktop (≥ 769px) — default */
    --card-width: 220px;
    --card-font-size: 13px;
    --card-avatar-size: 40px;
    --card-padding: 10px 14px;
    --card-name-size: 14px;
    --card-detail-size: 11px;
    --touch-target-min: 36px;
}

@media (max-width: 768px) {
    /* Tablet / large phone */
    :root {
        --card-width: 190px;
        --card-font-size: 12px;
        --card-avatar-size: 36px;
        --card-padding: 8px 10px;
        --card-name-size: 13px;
        --card-detail-size: 11px;
        --touch-target-min: 44px; /* WCAG / Apple HIG minimum */
    }
}

@media (max-width: 480px) {
    /* Small phone */
    :root {
        --card-width: 160px;
        --card-font-size: 11px;
        --card-avatar-size: 32px;
        --card-padding: 6px 8px;
        --card-name-size: 12px;
        --card-detail-size: 10px;
        --touch-target-min: 44px;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        'Mukta', 'Noto Sans Devanagari', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: #f5f5f5;
    color: #333;
    height: 100vh;
    overflow: hidden;
    /* A1: prevent any child from causing horizontal scroll */
    max-width: 100vw;
}

/* ── App Language Switcher in Header ──────────────────────────────────────── */
.app-lang-switcher {
    display: inline-flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 16px;
    padding: 2px;
}

.app-lang-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.app-lang-btn:hover {
    color: #fff;
}

.app-lang-btn.is-active {
    background: #6366f1;
    color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Light background theme (Landing page / index.html) */
body.landing-page .app-lang-switcher {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
}

body.landing-page .app-lang-btn {
    color: #64748b;
}

body.landing-page .app-lang-btn:hover {
    color: #0f172a;
}

body.landing-page .app-lang-btn.is-active {
    background: #3b82f6;
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* App Layout */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    /* A1: ensure nothing bleeds past the viewport edge */
    max-width: 100%;
}

.app-header {
    background-color: #2c3e50;
    color: white;
    padding: 0.7rem 1.5rem;
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    padding-top: max(0.7rem, env(safe-area-inset-top, 0px));
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.header-title__brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: inherit;
    min-width: 0;
}

.header-title__logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: block;
}

.header-title h1 {
    margin: 0;
    font-size: 1.5rem;
}

.header-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.app-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

/* Hamburger toggle — hidden on desktop */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    color: white;
    flex-direction: column;
    gap: 5px;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}
.menu-toggle:hover { background: rgba(255,255,255,0.15); }
.menu-toggle .bar {
    display: block;
    width: 22px;
    height: 2px;
    background: white;
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.25s;
}
.menu-toggle[aria-expanded="true"] .bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] .bar:nth-child(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] .bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.app-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.app-sidebar {
    width: 280px;
    background-color: #f5f5f5;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.app-main {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: rgb(33, 33, 33);
}

.app-main.full-width {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: rgb(33, 33, 33);
    width: 100%;
}

/* A1: allow normal touch interactions on UI chrome above the canvas */
.app-header,
.search-bar,
.search-bar-inner {
    touch-action: pan-y;
}

/* Family Chart Component */
.f3 {
    width: 100%;
    height: 100%;
    min-height: 0;
    background-color: rgb(33, 33, 33);
    color: #fff;
    position: relative;
    /* touch-action: none is set inline on #FamilyChart in shrotriya.html
       so the library's pan/zoom gestures work correctly */

    /* Suppress iOS Safari native long-press callout (copy/share/preview)
       and text-selection handles on chart cards so our custom context menu
       can fire instead. -webkit-touch-callout is iOS Safari-specific. */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* iOS Safari also tries to select/callout on SVG text nodes inside the chart.
   Explicitly suppress on the SVG and all its descendants so iOS doesn't
   intercept the long-press before our touchstart capture listener fires. */
#f3Canvas svg,
#f3Canvas svg * {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Make sure chart elements display correctly */
.card_cont {
    position: absolute;
    transform-origin: 0 0;
}

/* Data & Loading Indicators */
.loading-indicator,
.data-source-indicator {
    position: absolute;
    padding: 10px 15px;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 4px;
    z-index: 100;
}

.loading-indicator {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
}

.data-source-indicator {
    top: 10px;
    left: 10px;
    font-size: 14px;
}

/* Search bar styling */
.search-bar {
    background-color: #f5f5f5;
    border-bottom: 1px solid #ddd;
    z-index: 5;
    /* Smooth collapse via max-height */
    overflow: hidden;
    transition: max-height 0.32s ease, border-color 0.28s ease;
    /* A2: tall enough for the 2-field form even when it wraps on mid-size screens */
    max-height: 320px;
}

/* The inner wrapper holds padding so collapse doesn't jump */
.search-bar-inner {
    padding: 0.8rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Collapsed state — toggled by JS on mobile after a successful search */
.search-bar.collapsed {
    max-height: 0;
    border-bottom-color: transparent;
}

/* Selected-node chip — overlaid bottom-left on the chart */
.selected-node-chip {
    /* fixed so env(safe-area-inset-*) measures from the real viewport edge */
    position: fixed;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(0, 0, 0, 0.72);
    color: #fff;
    padding: 5px 10px 5px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    z-index: 200;
    max-width: calc(100vw - 80px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    backdrop-filter: blur(4px);
}

.chip-clear-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 14px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s;
}
.chip-clear-btn:hover { color: #fff; }

/* Floating search button — shown only on mobile via media query */
.search-fab {
    display: none; /* hidden on desktop */
    /* fixed, not absolute — env(safe-area-inset-bottom) is viewport-relative
       and only works correctly on a fixed element */
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: calc(20px + env(safe-area-inset-right, 0px));
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background-color: #3498db;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    align-items: center;
    justify-content: center;
    z-index: 300;
    transition: background-color 0.2s, transform 0.2s;
}
.search-fab:hover { background-color: #2980b9; transform: scale(1.08); }
.search-fab[aria-expanded="true"] { background-color: #e74c3c; }
/* Rotate icon to × when open */
.search-fab[aria-expanded="true"] svg {
    transform: rotate(45deg);
    transition: transform 0.2s;
}

.search-container {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    max-width: 650px;
}

.search-type {
    display: flex;
    gap: 1rem;
}

.search-type label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #2c3e50;
}

.search-input-container {
    display: flex;
    gap: 0.5rem;
    flex-grow: 1;
}

#search-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

#search-button {
    padding: 0.5rem 1rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

#search-button:hover {
    background-color: #2980b9;
}

/* Search results dropdown */
.search-results-dropdown {
    position: absolute;
    top: 95px;
    /* Positioned below search bar */
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 600px;
    max-height: 400px;
    background-color: white;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.close-results-btn {
    padding: 0.5rem;
    background-color: #95a5a6;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 0.5rem;
    align-self: center;
    transition: background-color 0.2s;
}

.close-results-btn:hover {
    background-color: #7f8c8d;
}

/* Node info styling */
.node-info-container {
    display: flex;
    align-items: center;
}

.selected-node-info {
    padding: 0.5rem 1rem;
    background-color: #ecf0f1;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #2c3e50;
}

.selected-node-info span {
    font-weight: bold;
    color: #3498db;
}

/* Search Component */
.search-component {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    background-color: white;
    border-bottom: 1px solid #ddd;
    transition: padding 0.5s ease;
}

.search-component h2 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.search-component.results-hidden .search-results {
    max-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.search-error {
    padding: 0.5rem;
    background-color: #fde2e2;
    color: #e74c3c;
    border-radius: 4px;
    font-size: 0.9rem;
}

.results-count {
    font-weight: bold;
    margin-bottom: 0.5rem;
    transition: opacity 0.3s ease, margin 0.3s ease;
}

.results-count.hiding {
    opacity: 0;
    margin: 0;
}

.person-cards {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 0.5rem;
    transition: max-height 0.5s ease, opacity 0.5s ease;
}

.person-cards.hiding {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

/* Person Card */
.person-card {
    position: relative;
    display: flex;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background-color: white;
    transition: opacity 0.5s ease, transform 0.5s ease, max-height 0.5s ease, padding 0.5s ease, margin 0.5s ease, box-shadow 0.2s;
    cursor: pointer;
    max-height: 200px;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease forwards;
}

.person-card:not(.adding):hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.person-card.adding {
    background-color: #34495e;
    border-color: #2c3e50;
    color: white;
    pointer-events: none;
    cursor: default;
}

.adding-indicator {
    width: 100%;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
}

.adding-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.person-card-avatar {
    width: 80px;
    min-width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background-color: #f5f5f5;
}

.avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar.male {
    border: 3px solid #3498db;
}

.avatar.female {
    border: 3px solid #e84393;
}

.avatar.neutral {
    border: 3px solid #95a5a6;
}

.person-card-info {
    flex: 1;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.person-name {
    margin: 0;
    font-size: 1.1rem;
    color: #2c3e50;
}

.person-details {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.detail {
    display: flex;
    font-size: 0.9rem;
}

.detail-label {
    color: #7f8c8d;
    min-width: 65px;
}

.detail-value {
    font-weight: 500;
    color: #34495e;
}

.person-card-action {
    display: flex;
    align-items: center;
    padding: 0.5rem;
}

.add-to-tree-btn {
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.add-to-tree-btn:hover {
    background-color: #24a868;
    transform: scale(1.05);
}

/* Control Panel */
.control-panel {
    background-color: #2c3e50;
    color: white;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-panel h2 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.control-panel h3 {
    font-size: 1rem;
    margin: 1.5rem 0 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}

.control-panel-section {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.control-panel-section+.control-panel-section {
    margin-top: 0.8rem;
    padding-top: 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.control-btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.control-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.control-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.control-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
    opacity: 0.7;
}

.edit-btn {
    background-color: #3498db;
    color: white;
}

.edit-btn.active {
    background-color: #e74c3c;
}

.highlight-btn {
    background-color: #f39c12;
    color: white;
}

.highlight-btn.active {
    background-color: #27ae60;
}

.reset-btn {
    background-color: #e74c3c;
    color: white;
}

.download-btn {
    background-color: #2ecc71;
    color: white;
}

.clear-btn {
    background-color: #e74c3c;
    color: white;
}

.clear-btn:hover {
    background-color: #c0392b;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.clear-btn:active {
    transform: translateY(0);
}

.add-person-btn {
    background-color: #2ecc71;
    color: white;
}

.add-person-btn:hover {
    background-color: #2980b9;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.add-person-btn:active {
    transform: translateY(0);
}

.export-btn {
    background-color: #2980b9;
    color: white;
}

.export-btn:hover:not(:disabled) {
    background-color: #1f6391;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
    transform: translateY(-1px);
}

.export-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.route-finder-btn {
    background-color: #9b59b6;
    color: white;
    text-decoration: none;
    display: inline-block;
}

.route-finder-btn:hover {
    background-color: #8e44ad;
    color: white;
    text-decoration: none;
}

.route-finder-btn:active {
    transform: translateY(0);
}

/* Edit Form */
.edit-form {
    position: absolute;
    right: -400px;
    top: 0;
    width: 380px;
    height: 100%;
    background-color: white;
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
    transition: right 0.3s ease;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.edit-form.visible {
    right: 0;
}

.edit-form-header {
    padding: 1rem;
    background-color: #34495e;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.edit-form-header h2 {
    margin: 0;
    font-size: 1.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.close-button {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    transition: background-color 0.2s;
    border-radius: 50%;
}

.close-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.edit-form-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Empty Chart State */
.empty-chart-message {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(33, 33, 33, 0.9);
    color: white;
    z-index: 5;
}

.empty-chart-content {
    text-align: center;
    max-width: 400px;
    padding: 2rem;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.empty-chart-content h2 {
    margin: 0 0 1rem 0;
    font-size: 1.8rem;
    color: #3498db;
}

.empty-chart-content p {
    margin: 0 0 1.5rem 0;
    font-size: 1.1rem;
    opacity: 0.9;
    line-height: 1.5;
}

.empty-chart-icon {
    font-size: 4rem;
    margin-top: 1rem;
}

/* Override family-chart.js styles */
.f3-form {
    font-family: inherit !important;
}

/* ── Edit form: horizontal label:input layout ────────────────────────────────
   Apply to f3-native fields AND injected ef-field rows.
   Label: fixed 100px wide on the left; input: fills remaining space.
   The gender radio row and the living checkbox row are excluded so they keep
   their existing flex layout.
   ─────────────────────────────────────────────────────────────────────────── */

/* f3-native fields (.f3-form-field rendered by family-chart) */
#edit-form-content .f3-form-field {
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: center;
    gap: 0 8px;
    margin-bottom: 0.55rem;
}

/* The gender field contains radio buttons — keep it block (not grid) */
#edit-form-content .f3-form-field:has(input[type="radio"]),
#edit-form-content .f3-form-field:has(.f3-radio-group) {
    display: block;
}

#edit-form-content .f3-form-field label {
    display: block;
    margin-bottom: 0;
    font-weight: 600;
    font-size: 0.82rem;
    color: #2c3e50;
    line-height: 1.3;
    align-self: center;
}

#edit-form-content .f3-form-field input,
#edit-form-content .f3-form-field textarea,
#edit-form-content .f3-form-field select {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 0;
    font-size: 0.9rem;
}

/* Injected extra fields (.ef-field inside #ef-extra-fields) */
#ef-extra-fields .ef-field {
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: center;
    gap: 0 8px;
    margin-bottom: 0.55rem;
}

#ef-extra-fields .ef-field .f3-form-field__label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    color: #2c3e50;
    line-height: 1.3;
    margin-bottom: 0;
    align-self: center;
}

/* Wrap elements (typeahead, transliterate button) fill the second column */
#ef-extra-fields .ef-field .f3-form-field__input,
#ef-extra-fields .ef-field .ef-namehi-wrap,
#ef-extra-fields .ef-field .ef-field-wrap {
    min-width: 0;  /* prevent overflow */
}

#ef-extra-fields .ef-field .f3-form-field__input {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.f3-form-field label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: bold;
    color: #2c3e50;
}

.f3-form-field input,
.f3-form-field textarea,
.f3-form-field select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.f3-form-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1rem;
}

.f3-form-buttons button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.f3-form-buttons button[type="submit"] {
    background-color: #2ecc71;
    color: white;
}

.f3-form-buttons button[type="button"] {
    background-color: #e74c3c;
    color: white;
}

.f3-delete-btn {
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    margin-top: 1rem;
}

.f3-delete-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
}

/* Hide f3's Delete button from the edit panel.
   Deletion is a deliberate action via the context menu, not an inline form control. */
#edit-form-content .f3-delete-btn {
    display: none !important;
}

/* Highlighting Connected Nodes */
.f3-path-to-main {
    filter: brightness(1.3);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}

/* Fade out non-highlighted nodes */
.highlight-mode .card_cont:not(.highlight) {
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

/* Scrollbar styling */
.person-cards::-webkit-scrollbar,
.edit-form-content::-webkit-scrollbar,
.search-results-dropdown::-webkit-scrollbar,
.add-person-form::-webkit-scrollbar {
    width: 6px;
}

.person-cards::-webkit-scrollbar-track,
.edit-form-content::-webkit-scrollbar-track,
.search-results-dropdown::-webkit-scrollbar-track,
.add-person-form::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.person-cards::-webkit-scrollbar-thumb,
.edit-form-content::-webkit-scrollbar-thumb,
.search-results-dropdown::-webkit-scrollbar-thumb,
.add-person-form::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 4px;
}

.person-cards::-webkit-scrollbar-thumb:hover,
.edit-form-content::-webkit-scrollbar-thumb:hover,
.search-results-dropdown::-webkit-scrollbar-thumb:hover,
.add-person-form::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

/* Form Status Messages */
.form-status-message {
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    text-align: center;
    font-weight: 500;
    animation: fadeIn 0.3s ease;
}

.form-status-message.success {
    background-color: rgba(46, 204, 113, 0.2);
    color: #27ae60;
    border: 1px solid #2ecc71;
}

.form-status-message.error {
    background-color: rgba(231, 76, 60, 0.2);
    color: #c0392b;
    border: 1px solid #e74c3c;
}

/* Add Person Modal Styles */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-backdrop.visible {
    opacity: 1;
}

.add-person-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    width: 92%;
    max-width: 560px;   /* matches the edit-form panel feel — no wasted whitespace */
    max-height: 90vh;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 9001;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.add-person-modal.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.add-person-header {
    padding: 1rem 1.5rem;
    background-color: #34495e;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.add-person-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close-modal-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.8rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.close-modal-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.add-person-form {
    padding: 0;
    overflow-y: auto;
    max-height: calc(90vh - 60px);
}

/* Location typeahead wrapper inside add-person modal */
.location-field-wrap {
    position: relative;
}

/* Scoped suggestions panel for the add-person modal.
   Reuses .location-suggestion item styles from search.css. */
.location-field-wrap .ap-location-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e9ecef;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 180px;
    overflow-y: auto;
    z-index: 10000;   /* above modal content */
    display: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}

/* Tabs */
.form-tabs {
    display: flex;
    border-bottom: 1px solid #ddd;
}

.tab-btn {
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-weight: 600;
    color: #7f8c8d;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    color: #3498db;
    border-bottom-color: #3498db;
}

.tab-content {
    padding: 1.5rem;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

/* Form Columns */
.form-columns {
    display: flex;
    gap: 2rem;
}

.form-column {
    flex: 1;
}

.relationships-column {
    border-left: 1px solid #ddd;
    padding-left: 2rem;
}

.form-field {
    margin-bottom: 0.9rem;  /* was 1.2rem — tighter on mobile */
}

.form-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.3rem;  /* was 0.4rem */
    color: #2c3e50;
    font-size: 0.9rem;      /* was inherited ~1rem — keeps labels compact */
}

.form-field input[type="text"] {
    width: 100%;
    padding: 0.55rem 0.75rem;  /* was 0.7rem — matches edit form density */
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.95rem;        /* was 1rem */
}

/* ─── Add Person: collapsible sections ──────────────────────────────────────── */

/* Section container */
.ap-section {
    border-bottom: 1px solid #e9ecef;
}
.ap-section:last-of-type {
    border-bottom: none;
}

/* Section header — fixed (Identity) */
.ap-section-header--fixed {
    padding: 0.75rem 1.25rem;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}
.ap-section-header--fixed .ap-section-title {
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6c757d;
}

/* Section header — toggle button */
.ap-section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    background: #f8f9fa;
    border: none;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.ap-section-toggle:hover {
    background: #f0f2f5;
}
.ap-section--open .ap-section-toggle {
    background: #f0f2f5;
}
.ap-section-title {
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6c757d;
}
.ap-chevron {
    font-size: 0.9rem;
    color: #6c757d;
    transition: transform 0.2s;
}

/* Section body */
.ap-section-body {
    padding: 1rem 1.25rem;
}
.ap-section-body--collapsed {
    display: none;
}

/* Identity section always-visible */
.ap-section--identity .ap-section-body {
    padding: 1rem 1.25rem;
}

/* Two-column name row */
.ap-row--two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* Gender + Living inline */
.ap-row--inline-group {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
    margin-bottom: 1.2rem;
}
.ap-gender-field { flex: 1; margin-bottom: 0; }
.ap-living-field { flex: 0 0 auto; margin-bottom: 0; padding-bottom: 0.2rem; }

/* Gotra field wrap — same rules as location-field-wrap */
.gotra-field-wrap {
    position: relative;
}
.gotra-field-wrap .ap-gotra-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e9ecef;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 180px;
    overflow-y: auto;
    z-index: 10000;
    display: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}

/* Gotra inherit hint */

/* Edit form injected extra fields + collapsible sections */
/* margin-bottom handled by the horizontal-layout grid rule above */
#ef-extra-fields .ef-field-wrap {
    position: relative;
}
.ef-hint {
    font-weight: 400;
    font-size: 0.72em;
    color: #6c757d;
    margin-left: 0.3em;
}

/* ── Hindi name field wrap (edit form + add person modal) ── */
.ef-namehi-wrap,
.ap-namehi-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.ef-namehi-wrap input,
.ap-namehi-wrap input {
    flex: 1 1 auto;
    min-width: 0;
}
.ef-transliterate-btn,
.ap-transliterate-btn {
    flex: 0 0 auto;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: #f0f4f8;
    border: 1px solid #d0d7de;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    color: #444;
    transition: background 0.15s;
}
.ef-transliterate-btn:hover:not(:disabled),
.ap-transliterate-btn:hover:not(:disabled) {
    background: #e2e8f0;
}
.ef-transliterate-btn:disabled,
.ap-transliterate-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Tighten the gap between f3's name fields and the injected sections */
#ef-extra-fields {
    margin-top: -0.5rem;
}

/* ef-section — collapsible sections inside the edit form */
.ef-section {
    border-top: 1px solid #e9ecef;
    margin-left: -1rem;   /* bleed to panel edge to match edit-form-content padding */
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
}
.ef-section:first-child {
    border-top: none;
}
.ef-section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
}
.ef-section-toggle:hover {
    background: #f8f9fa;
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
}
.ef-section-title {
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: #6c757d;
    transition: color 0.15s;
}
.ef-chevron {
    font-size: 0.8rem;
    color: #adb5bd;
}
/* Open state — accent the left edge like a tab indicator */
.ef-section--open > .ef-section-toggle {
    border-left: 3px solid #3498db;
    margin-left: -1rem;
    padding-left: calc(1rem - 3px);
}
.ef-section--open .ef-section-title {
    color: #2c3e50;
}
.ef-section--open .ef-chevron {
    color: #3498db;
}
.ef-section-body {
    padding-top: 0.25rem;
    padding-bottom: 0.75rem;
}
.ef-section-body--collapsed {
    display: none;
}


.gotra-inherit-hint {
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: #6c757d;
    font-style: italic;
}

/* Birth/death year selects */
.ap-section-body select {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
    background: #fff;
    appearance: auto;
}

/* Form actions — always-visible sticky footer */
.ap-form-actions {
    padding: 0.75rem 1.25rem;
    background: #fff;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    position: sticky;
    bottom: 0;
}

/* Create Person button — full width on mobile, matching Save Changes prominence */
.ap-form-actions .submit-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    border-radius: 6px;
    text-align: center;
}

/* Mobile: stack name fields */
@media (max-width: 480px) {
    .ap-row--two-col {
        grid-template-columns: 1fr;
    }
    .ap-row--inline-group {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}


/* ── Photo section: compact horizontal card matching the edit-form avatarManager layout ── */
/* Wraps the ImageUpload component in an avatar-display-section style card:
   [camera icon circle] [upload text + remove button]                        */
#ap-section-photo-body .image-upload-component {
    max-width: 100%;
}

/* Outer card — mirrors .avatar-display-section from avatarManager.css */
#ap-section-photo-body .upload-area {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    min-height: unset;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    background: #fafbfc;
    border-style: solid;   /* remove dashed */
    text-align: left;
    cursor: pointer;
}
#ap-section-photo-body .upload-area:hover {
    border-color: #3498db;
    background: #f5f9ff;
}
#ap-section-photo-body .upload-area.has-file {
    border-color: #27ae60;
    background: #f5fbf7;
}

/* Camera icon circle — mirrors .avatar-preview */
#ap-section-photo-body .upload-icon {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #adb5bd;
}
#ap-section-photo-body .upload-icon svg {
    width: 22px;
    height: 22px;
}

/* Text column */
#ap-section-photo-body .upload-content {
    flex-direction: row;
    align-items: center;
    gap: 0;
    flex: 1;
}
#ap-section-photo-body .upload-text {
    text-align: left;
}
#ap-section-photo-body .upload-main-text {
    font-size: 0.88rem;
    font-weight: 600;
    color: #2c3e50;
    margin: 0 0 2px;
}
#ap-section-photo-body .upload-sub-text {
    font-size: 0.75rem;
    color: #6c757d;
    margin: 0;
}
#ap-section-photo-body .upload-note {
    font-size: 0.72rem;
    color: #17a2b8;
    font-style: italic;
    margin: 2px 0 0;
    background: none;
    padding: 0;
    display: block;
}

/* Preview section — compact, no extra margin */
#ap-section-photo-body .preview-section {
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background: #fff;
}
#ap-section-photo-body .preview-container {
    gap: 12px;
}
#ap-section-photo-body .preview-image {
    width: 52px;
    height: 52px;
    border-radius: 50%;   /* circular like avatarManager */
}
#ap-section-photo-body .upload-actions {
    margin-top: 8px;
}

/* "optional" hint text on the Photo section toggle */
#ap-section-photo .ap-section-toggle::after {
    content: 'optional';
    font-size: 0.7rem;
    font-weight: 400;
    color: #adb5bd;
    text-transform: lowercase;
    letter-spacing: 0;
    margin-right: auto;
    margin-left: 0.5rem;
}

/* Relationship sub-labels (Father / Mother / Spouse) — lighter than identity field labels */
#ap-section-rels .form-field > label {
    font-weight: 500;           /* was 600 — less heavy than identity fields */
    color: #57606a;             /* was #2c3e50 — muted, secondary */
    font-size: 0.82rem;         /* slightly smaller to further signal hierarchy */
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.required {
    color: #e74c3c;
}

.radio-group {
    display: flex;
    gap: 1.5rem;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal;
    cursor: pointer;
}

/* Relationship Search */
.relationship-selector {
    position: relative;
}

.relationship-search {
    width: 100%;
    padding: 0.5rem 0.75rem;  /* was 0.7rem — matches tightened input density */
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    max-height: 250px;
    overflow-y: auto;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 0 0 4px 4px;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    display: none;
}

.search-result-item {
    display: flex;
    align-items: flex-start;
    padding: 0.8rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background 0.2s;
}

.search-result-item:hover {
    background-color: #f5f7fa;
}

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

.result-avatar {
    width: 40px;
    height: 40px;
    margin-right: 1rem;
    margin-top: 2px;   /* align with name text when flex-start */
    flex-shrink: 0;
}

.result-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #3498db;
}

.result-info {
    flex: 1;
}

.result-name {
    font-weight: 600;
    color: #2c3e50;
}

.result-details {
    font-size: 0.8rem;
    color: #7f8c8d;
}

/* Third line in relationship search results — father/native/birth year */
.result-disambig {
    font-size: 0.75rem;
    color: #a0aab4;
    margin-top: 1px;
    font-style: italic;
}

.search-loading,
.no-results,
.search-error {
    padding: 1rem;
    text-align: center;
    color: #7f8c8d;
}

.search-error {
    color: #e74c3c;
}

/* Selected Relatives */
.selected-relative,
.selected-relatives {
    margin-top: 0.5rem;
    min-height: 40px;
}

.no-selection {
    color: #95a5a6;
    font-style: italic;
    font-size: 0.9rem;
}

.selected-person,
.selected-child {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background-color: #f5f7fa;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.selected-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    margin-right: 0.8rem;
    object-fit: cover;
    border: 2px solid #3498db;
}

.selected-name {
    flex: 1;
    font-weight: 500;
    color: #2c3e50;
}

.remove-relative-btn,
.remove-child-btn {
    background: none;
    border: none;
    color: #e74c3c;
    font-size: 1.2rem;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.remove-relative-btn:hover,
.remove-child-btn:hover {
    background-color: rgba(231, 76, 60, 0.1);
}

.selected-children-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Form Actions */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.form-actions button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.next-tab-btn {
    background-color: #3498db;
    color: white;
}

.next-tab-btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.prev-tab-btn {
    background-color: #95a5a6;
    color: white;
}

.prev-tab-btn:hover {
    background-color: #7f8c8d;
    transform: translateY(-2px);
}

.submit-btn {
    background: #27ae60;   /* matches Save Changes exactly */
    color: #fff;
    border-radius: 6px;    /* slightly softer corners like Save Changes */
}

.submit-btn:hover {
    background: #219a52;
}

.submit-btn:active {
    background: #1a7d42;
}

.submit-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
}

/* Update Success Summary */
.update-success-summary {
    margin: 20px auto;
    padding: 20px;
    background-color: rgba(46, 204, 113, 0.1);
    border: 1px solid #2ecc71;
    border-radius: 4px;
    animation: fadeIn 0.5s ease;
    max-width: 90%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.update-success-summary h3 {
    margin: 0 0 15px 0;
    color: #27ae60;
    font-size: 1.1rem;
    border-bottom: 1px solid #2ecc71;
    padding-bottom: 8px;
}

.summary-item {
    margin-bottom: 8px;
    line-height: 1.5;
    display: flex;
}

.summary-label {
    font-weight: 600;
    color: #34495e;
    width: 80px;
    flex-shrink: 0;
}

.summary-value {
    color: #2c3e50;
}

.close-edit-form-btn {
    display: block;
    margin: 20px auto 5px auto;
    padding: 8px 20px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.close-edit-form-btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.close-edit-form-btn:active {
    transform: translateY(0);
}

/* Notification Messages */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 4px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    animation: slideIn 0.3s ease, fadeOut 0.5s ease 2.5s forwards;
    max-width: 300px;
}

.notification.error {
    background-color: #e74c3c;
}

.notification.success {
    background-color: #2ecc71;
}

.notification.info {
    background-color: #3498db;
}

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

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

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* ── auth-hidden: JS hides the hamburger when logged out */
.menu-toggle.auth-hidden {
    display: none !important;
}

/* ─── Responsive Adjustments ─── */

/* Tablet ≤ 768px and Landscape Phones (width ≤ 1024px & height ≤ 520px) */
@media (max-width: 768px), (max-height: 520px) and (max-width: 1024px) {
    /* Base header: allow wrapping so the dropdown row can appear below */
    .app-header {
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0;
        padding-left:  calc(1rem + env(safe-area-inset-left,  0px));
        padding-right: calc(1rem + env(safe-area-inset-right, 0px));
    }

    .header-title h1 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
        flex: 1;
    }

    /* Hamburger sits right of the title, only shown when logged in */
    .menu-toggle {
        display: flex;
        order: 2;
        flex-shrink: 0;
        margin-left: auto;
    }

    /* Header controls: collapsed by default, drops to full-width row when open */
    .header-controls {
        order: 3;
        width: 100%;
        flex-wrap: wrap;
        gap: 6px;
        padding: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.25s ease;
    }

    .header-controls.open {
        max-height: 220px;
        padding: 0.5rem 0 0.4rem;
    }

    /* ── Logged OUT: no hamburger → controls sit inline in the title row ── */
    /* :has() — Chrome 105+, Safari 15.4+, Firefox 121+ */
    .app-header:has(.menu-toggle.auth-hidden) .header-controls {
        max-height: none !important;
        overflow: visible;
        width: auto;
        order: 2;               /* sit beside the title, not below it */
        margin-left: auto;
        padding: 0;
        flex-wrap: nowrap;
    }

    /* JS fallback class for older WebView */
    .app-header.no-hamburger .header-controls {
        max-height: none !important;
        overflow: visible;
        width: auto;
        order: 2;
        margin-left: auto;
        padding: 0;
        flex-wrap: nowrap;
    }

    .control-btn {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 0.8rem;
        padding: 0.4rem 0.6rem;
        text-align: center;
        white-space: nowrap;
    }

    /* Search bar: hidden by default on mobile, shown when FAB is tapped */
    .search-bar {
        max-height: 0;
        overflow: hidden;
        border-bottom-color: transparent;
    }

    /* A2: when open — tall enough for the stacked 2-field form + actions row */
    .search-bar.search-open {
        max-height: 360px;
        border-bottom-color: #ddd;
    }

    .search-bar-inner {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    .search-container {
        width: 100%;
        max-width: none;
    }

    /* Show the FAB on mobile */
    .search-fab {
        display: flex;
        /* A2: ensure FAB clears home indicator on iOS and nav bar on Android */
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }

    /* A2: chip sits above the FAB with safe-area awareness */
    .selected-node-chip {
        bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    }

    /* Edit form as full-screen overlay */
    .edit-form {
        position: fixed;
        right: -100vw;
        top: 0;
        width: 100vw;
        height: 100%;
        z-index: 2000;
        transition: right 0.3s ease;
    }
    .edit-form.visible {
        right: 0;
    }

    /* Add-person modal full screen */
    .add-person-modal {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        top: 0;
        left: 0;
        transform: none;
        transition: opacity 0.3s ease;
    }
    .add-person-modal.visible {
        transform: none;
    }

    .form-columns {
        flex-direction: column;
        gap: 1rem;
    }

    .relationships-column {
        border-left: none;
        padding-left: 0;
        border-top: 1px solid #ddd;
        padding-top: 1rem;
    }

    /* Search results as bottom sheet */
    .search-results-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 60vh;
        transform: none;
        border-radius: 12px 12px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
        z-index: 1500;
    }
}

/* Mobile ≤ 480px */
@media (max-width: 480px) {
    .search-form {
        flex-direction: column;
        gap: 8px;
    }

    .search-field {
        width: 100%;
    }

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

    .search-actions .search-btn,
    .search-actions .clear-btn {
        flex: 1;
    }

    .notification {
        left: 12px;
        right: 12px;
        top: auto;
        bottom: 80px;
        max-width: none;
    }
}

/* Person Card in Chart Indicator */
.person-card.in-chart {
    border-left: 4px solid #3498db;
    background-color: rgba(52, 152, 219, 0.05);
}

/* Locate in Tree Button */
.locate-in-tree-btn {
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    margin-left: 0.5rem;
}

.locate-in-tree-btn:hover {
    background-color: #2980b9;
    transform: scale(1.05);
}

.locate-in-tree-btn:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
    transform: none;
}

/* Locating Indicator */
.locating-indicator {
    width: 100%;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    color: #3498db;
    font-weight: 500;
}

.locating-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(52, 152, 219, 0.3);
    border-radius: 50%;
    border-top-color: #3498db;
    animation: spin 1s ease-in-out infinite;
}

/* Update person card actions to accommodate new button */
.person-card-action {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    gap: 0.5rem;
}

/* Ensure the spin animation is defined (if not already present) */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.person-card {
    position: relative;
    display: flex;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background-color: white;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
    margin-bottom: 0.5rem;
}

/* Card already in chart */
.person-card.in-chart {
    border-left: 4px solid #3498db;
    background-color: rgba(52, 152, 219, 0.05);
}

.person-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.locate-in-tree-btn {
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.locate-in-tree-btn:hover {
    background-color: #2980b9;
    transform: scale(1.05);
}

.add-to-tree-btn {
    background-color: #2ecc71;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.add-to-tree-btn:hover {
    background-color: #27ae60;
    transform: scale(1.05);
}

/* Loading indicators */
.adding-indicator,
.locating-indicator {
    width: 100%;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
}

.adding-indicator {
    color: #2ecc71;
}

.locating-indicator {
    color: #3498db;
}

.adding-spinner,
.locating-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    animation: spin 1s ease-in-out infinite;
}

.adding-spinner {
    border-top-color: #2ecc71;
}

.locating-spinner {
    border-top-color: #3498db;
}

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

/* Notification */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 4px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    animation: slideIn 0.3s ease, fadeOut 0.5s ease 2.5s forwards;
    max-width: 300px;
}

.notification.success {
    background-color: #2ecc71;
}

.notification.error {
    background-color: #e74c3c;
}

.notification.info {
    background-color: #3498db;
}

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

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

@keyframes fadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* ── Offline banner (D5) ─────────────────────────────────────────────────────
   Appears when the user tries to edit/add while navigator.onLine is false.
   ─────────────────────────────────────────────────────────────────────────── */
.offline-banner {
    position: fixed;
    bottom: 1.2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: #1a1a1a;
    color: #fff;
    padding: 0.7rem 1.1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    max-width: calc(100vw - 2rem);
    animation: offline-slide-up 0.25s ease;
}
.offline-banner__close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.7;
}
.offline-banner__close:hover { opacity: 1; }
@keyframes offline-slide-up {
    from { opacity: 0; transform: translateX(-50%) translateY(16px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Living / deceased field (edit panel + add person form) ──────────────────*/
.form-field--inline {
    padding: 8px 0 4px;
}

/* Inline label — sits inside the gender radio row */
.living-field__label,
.inline-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    color: inherit;   /* adapts to both dark edit panel and light add-person form */
    vertical-align: middle;
}

/* Separator pipe between gender radios and Living checkbox */
.living-field__sep {
    display: inline-block;
    width: 1px;
    height: 1em;
    background: currentColor;
    opacity: 0.25;
    margin: 0 10px;
    vertical-align: middle;
}

/* Tap target */
.living-field__label input[type="checkbox"],
.inline-checkbox-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #2ecc71;
    vertical-align: middle;
}

/* Hint below the add-person form field (not used in edit panel) */
.field-hint {
    font-size: 0.78rem;
    color: #888;
    margin: 2px 0 0 0;
}

.field-hint-inline {
    font-size: 0.78rem;
    color: #95a5a6;   /* was #888 — slightly more contrast, still clearly secondary */
    font-weight: 400;
}

/* ── Landscape & Short Viewports (Landscape Phones / Short Viewports ≤520px height) ── */
@media (max-height: 520px) {
    .app-header {
        padding: 0.35rem 1rem;
        padding-left: max(1rem, env(safe-area-inset-left, 0px));
        padding-right: max(1rem, env(safe-area-inset-right, 0px));
        padding-top: max(0.35rem, env(safe-area-inset-top, 0px));
    }

    .header-title h1 {
        font-size: 1rem;
    }

    .header-title__logo {
        width: 22px;
        height: 22px;
    }

    .search-fab {
        bottom: max(12px, env(safe-area-inset-bottom, 0px));
        right: max(12px, env(safe-area-inset-right, 0px));
        width: 44px;
        height: 44px;
    }

    .selected-node-chip {
        bottom: max(64px, calc(52px + env(safe-area-inset-bottom, 0px)));
        right: max(12px, env(safe-area-inset-right, 0px));
    }

    .add-person-modal {
        max-height: calc(100dvh - 16px);
        width: 95%;
        max-width: 600px;
    }

    .add-person-form {
        max-height: calc(100dvh - 66px);
    }

    .add-person-header {
        padding: 0.6rem 1rem;
    }

    .add-person-header h2 {
        font-size: 1.15rem;
    }

    .tab-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}
