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

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

:root {
    --bg: #faf6f0;
    --bg-warm: #f4ede3;
    --bg-card: #fffcf7;
    --bg-hover: #f0e8db;
    --border: rgba(139, 109, 71, 0.12);
    --border-light: rgba(139, 109, 71, 0.2);
    --text: #3d3428;
    --text-muted: #7a6e5d;
    --text-dim: #a89b88;
    --accent: #8b6d47;
    --accent-warm: #c4935a;
    --male: #5e85ad;
    --female: #b87a8f;
    --shadow: 0 1px 3px rgba(80, 50, 20, 0.06), 0 4px 12px rgba(80, 50, 20, 0.04);
    --shadow-lg: 0 4px 12px rgba(80, 50, 20, 0.08), 0 12px 40px rgba(80, 50, 20, 0.06);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
}

/* ===========================
   FAMILY-CHART THEME OVERRIDES
   =========================== */

.f3 {
    --female-color: #fffcf7;
    --male-color: #fffcf7;
    --genderless-color: #fffcf7;
    --background-color: transparent;
    --text-color: #3d3428;
}

#FamilyChart {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(210, 180, 140, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(180, 150, 110, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(200, 170, 130, 0.1) 0%, transparent 40%);
}

#FamilyChart .f3-cont {
    background-color: transparent !important;
}

/* Card styling */
.f3 .card-inner {
    border-radius: 12px !important;
    box-shadow: var(--shadow) !important;
    font-family: 'Inter', sans-serif !important;
}

/* Neutral card background with subtle gender outline */
.f3 div.card-male .card-inner,
.f3 div.card-female .card-inner,
.f3 div.card-genderless .card-inner {
    background-color: #fffcf7 !important;
}

.f3 div.card-male .card-inner {
    border-bottom: 3px solid #8fa89a !important;
}

.f3 div.card-female .card-inner {
    border-bottom: 3px solid #c4919f !important;
}

/* SVG card overrides */
.f3 rect.card-male,
.f3 .card-male .card-body-rect,
.f3 .card-male .text-overflow-mask {
    fill: #fffcf7;
}

.f3 rect.card-female,
.f3 .card-female .card-body-rect,
.f3 .card-female .text-overflow-mask {
    fill: #fffcf7;
}

/* Highlight logged-in user's card */
.f3 .my-card .card-inner {
    outline: 4px solid #e8a84c !important;
    outline-offset: 3px;
    box-shadow: 0 0 20px rgba(232, 168, 76, 0.5), 0 0 40px rgba(232, 168, 76, 0.2) !important;
}

/* Link lines */
.f3 .link {
    stroke: rgba(139, 109, 71, 0.3);
    stroke-width: 2px;
}

.f3 .link.f3-path-to-main {
    stroke: var(--accent);
    stroke-width: 3px;
}

/* Header */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(250, 246, 240, 0.88);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.01em;
}

header h1 span {
    color: var(--text);
}

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

/* User badge */
#user-badge {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    padding: 6px 14px;
    background: var(--bg-warm);
    border: 1px solid var(--border);
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
}

#user-badge:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.badge-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #5cb85c;
    flex-shrink: 0;
}

/* ===========================
   SEARCH
   =========================== */

.search-toggle {
    background: var(--bg-warm);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: all 0.15s;
}

.search-toggle:hover {
    background: var(--bg-hover);
    color: var(--text);
}

#search-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 150;
    background: var(--bg-card);
    box-shadow: var(--shadow-lg);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

#search-panel.hidden {
    display: none;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.search-bar input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    outline: none;
}

.search-bar input:focus {
    border-color: var(--accent);
}

.search-close-btn {
    background: var(--bg-warm);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    flex-shrink: 0;
}

.search-close-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.search-results {
    overflow-y: auto;
    padding: 8px;
}

.search-results .family-link {
    margin: 2px 8px;
}

.search-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* ===========================
   DETAIL PANEL
   =========================== */

#detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 200;
    overflow-y: auto;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
}

#detail-panel.hidden {
    transform: translateX(100%);
    box-shadow: none;
}

#detail-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--bg-warm);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.15s;
    z-index: 10;
}

#detail-close:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.detail-header {
    padding: 28px 24px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(210, 185, 150, 0.08) 0%, transparent 100%);
}

.detail-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
    margin-bottom: 14px;
}

.detail-avatar.male { background: var(--male); }
.detail-avatar.female { background: var(--female); }

.detail-header h2 {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}

.detail-header .birth-name {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 2px;
    font-style: italic;
}

.detail-header .lifespan {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.detail-body {
    padding: 8px 0;
}

.detail-section {
    padding: 12px 24px;
}

.detail-section h3 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
    margin-bottom: 10px;
    font-weight: 600;
}

.family-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin: 4px 0;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.family-link:hover {
    background: var(--bg-hover);
    border-color: var(--border-light);
}

.family-link-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.family-link-info {
    flex: 1;
    min-width: 0;
}

.family-link-name {
    font-weight: 500;
}

.family-link-sub {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 1px;
}

/* ===========================
   LOGIN SCREEN
   =========================== */

#login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 30% 40%, rgba(210, 180, 140, 0.2) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 60%, rgba(180, 150, 110, 0.15) 0%, transparent 50%);
    z-index: 500;
}

#login-screen.hidden {
    display: none;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 36px;
    width: 340px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 28px;
}

.login-prompt {
    font-size: 0.95rem;
    color: var(--text);
    margin-bottom: 16px;
    font-weight: 500;
}

.login-card label {
    display: block;
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 6px;
    margin-top: 14px;
    font-weight: 600;
}

.login-card label:first-of-type {
    margin-top: 0;
}

.login-card input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}

.login-card input:focus {
    border-color: var(--accent);
}

.login-btn {
    width: 100%;
    padding: 12px;
    margin-top: 20px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.login-btn:hover {
    background: var(--accent-warm);
}

.login-error {
    color: #c45050;
    font-size: 0.8rem;
    margin-top: 10px;
    min-height: 1.2em;
}

#login-step-name.hidden,
#login-step-code.hidden {
    display: none !important;
}

/* ===========================
   EDIT MODE & PHOTO
   =========================== */

.detail-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.edit-btn {
    background: var(--bg-warm);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.15s;
    flex-shrink: 0;
    position: absolute;
    top: 12px;
    right: 50px;
    z-index: 10;
}

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

/* Photo upload */
.photo-upload-area {
    cursor: pointer;
}

.photo-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    position: relative;
    overflow: hidden;
    border: 2px dashed var(--border-light);
    transition: border-color 0.15s;
}

.photo-upload-area:hover .photo-preview {
    border-color: var(--accent);
}

.photo-placeholder {
    background: var(--bg-warm);
    color: var(--text-dim);
}

.photo-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 3px 0;
    font-size: 0.55rem;
    text-align: center;
    background: rgba(0,0,0,0.5);
    color: white;
    font-weight: 500;
}

/* Edit form */
.edit-form {
    margin-top: 16px;
}

.edit-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    margin-bottom: 12px;
    font-weight: 600;
}

.edit-input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
}

.edit-input:focus {
    border-color: var(--accent);
}

.edit-textarea {
    min-height: 60px;
    resize: vertical;
}

select.edit-input {
    appearance: auto;
}

.edit-header {
    padding-bottom: 16px;
}

/* Edit action buttons */
.edit-actions {
    display: flex;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
}

.save-btn {
    flex: 1;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s;
}

.save-btn:hover {
    background: var(--accent-warm);
}

.save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.cancel-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-warm);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

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

/* Add person buttons & form */
.add-section {
    display: flex;
    gap: 8px;
}

.add-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg);
    border: 1px dashed var(--border-light);
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.add-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--text);
}

.add-form {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin: 0 24px 12px;
}

.add-form h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 12px;
    font-weight: 600;
}

.add-checkbox-label {
    flex-direction: row;
    display: flex !important;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    color: var(--text) !important;
    cursor: pointer;
}

.add-checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.add-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.link-results {
    max-height: 240px;
    overflow-y: auto;
    margin-top: 4px;
}

/* Relationship delete button */
.rel-delete-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex-shrink: 0;
    transition: all 0.15s;
    line-height: 1;
}

.rel-delete-btn:hover {
    background: #c45050;
    border-color: #c45050;
    color: white;
}

.family-link {
    position: relative;
}

/* Delete photo button */
.delete-photo-btn {
    width: 100%;
    padding: 8px;
    background: none;
    border: 1px solid #c4505044;
    border-radius: 8px;
    font-size: 0.8rem;
    font-family: inherit;
    color: #c45050;
    cursor: pointer;
    transition: all 0.15s;
}

.delete-photo-btn:hover {
    background: #c4505011;
    border-color: #c45050;
}

/* Photo lightbox */
.photo-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
}

.photo-lightbox-img {
    max-width: 85vw;
    max-height: 85vh;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    object-fit: contain;
}

/* Responsive */
@media (max-width: 768px) {
    /* Detail panel: full screen overlay */
    #detail-panel {
        width: 100vw;
        border-left: none;
    }

    header {
        padding: 6px 12px;
        background: rgba(250, 246, 240, 0.95);
    }

    header h1 {
        font-size: 1rem;
    }

    #user-badge {
        font-size: 0.7rem;
        padding: 5px 10px;
    }

    /* Make tree cards smaller on mobile */
    .f3 .card_cont {
        transform: scale(0.85);
    }

    .f3 .card-inner {
        border-radius: 8px !important;
    }

    /* Close & edit buttons: bigger tap targets */
    #detail-close {
        width: 40px;
        height: 40px;
        font-size: 1.3rem;
        top: 8px;
        right: 8px;
    }

    .edit-btn {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
        top: 8px;
        right: 54px;
    }

    /* Detail header */
    .detail-header {
        padding: 20px 16px 16px;
    }

    .detail-header h2 {
        font-size: 1.2rem;
    }

    /* Sections */
    .detail-section {
        padding: 10px 16px;
    }

    /* Edit form: larger inputs for touch */
    .edit-input {
        padding: 10px 12px;
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    .edit-textarea {
        min-height: 80px;
        font-size: 16px;
    }

    select.edit-input {
        font-size: 16px;
    }

    .edit-label {
        margin-bottom: 14px;
    }

    .edit-header {
        padding: 16px 16px 12px;
    }

    /* Action buttons: full width, larger */
    .edit-actions {
        padding: 12px 16px;
        gap: 8px;
    }

    .save-btn,
    .cancel-btn {
        padding: 12px;
        font-size: 0.9rem;
    }

    /* Add buttons */
    .add-section {
        flex-direction: column;
    }

    .add-btn {
        padding: 14px;
        font-size: 0.85rem;
    }

    .add-form {
        margin: 0 16px 12px;
        padding: 14px;
    }

    .add-form .edit-input {
        font-size: 16px;
    }

    /* Family links: bigger tap target */
    .family-link {
        padding: 12px;
        font-size: 0.9rem;
    }

    .family-link-avatar {
        width: 36px;
        height: 36px;
        font-size: 0.75rem;
    }

    /* Rel delete button: bigger for touch */
    .rel-delete-btn {
        width: 30px;
        height: 30px;
        font-size: 1.1rem;
    }

    /* Photo upload area */
    .photo-preview {
        width: 70px;
        height: 70px;
    }

    /* Lightbox */
    .photo-lightbox-img {
        max-width: 95vw;
        max-height: 85vh;
        border-radius: 8px;
    }

    /* Login card */
    .login-card {
        padding: 30px 24px;
        border-radius: 16px;
    }

    .login-title {
        font-size: 1.8rem;
    }

    .login-card input {
        font-size: 16px; /* Prevent iOS zoom */
    }
}

/* Small phones */
@media (max-width: 380px) {
    header h1 {
        font-size: 0.9rem;
    }

    .detail-header h2 {
        font-size: 1.1rem;
    }

    .detail-section {
        padding: 8px 12px;
    }

    .detail-header {
        padding: 16px 12px 12px;
    }

    .edit-actions {
        padding: 10px 12px;
    }
}
