/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --male-color: #ADD8E6;
    --male-color-dark: #7AB8D4;
    --male-border: #6BAACC;
    --female-color: #FFB6C1;
    --female-color-dark: #E89BA6;
    --female-border: #D98A95;
    --bg-primary: #f5f7fa;
    --bg-white: #ffffff;
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #888;
    --border-color: #e0e0e0;
    --primary: #4a6cf7;
    --primary-hover: #3b5de7;
    --primary-light: #eef1fe;
    --danger: #e74c3c;
    --danger-hover: #c0392b;
    --success: #27ae60;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: 0.2s ease;
    --spouse-link-color: #e74c8b;
    --child-link-color: #8b9dc3;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* ===== PAGES ===== */
.page {
    display: none;
    height: 100vh;
    flex-direction: column;
}
.page.active {
    display: flex;
}

/* ===== LOGIN PAGE ===== */
.login-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 2rem;
}

.login-hero {
    text-align: center;
    color: white;
    margin-bottom: 3rem;
}

.tree-icon {
    font-size: 5rem;
    margin-bottom: 1rem;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

.login-hero h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.login-hero p {
    font-size: 1.2rem;
    opacity: 0.9;
}

.login-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
    max-width: 320px;
}

.login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition);
    font-family: inherit;
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.google-btn {
    background: white;
    color: #333;
}

.facebook-btn {
    background: #1877f2;
    color: white;
}

/* ===== HEADER ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    z-index: 100;
    flex-shrink: 0;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    font-size: 1.5rem;
}

.app-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
}

.user-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.badge {
    background: var(--primary-light);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-outline:hover {
    background: var(--bg-primary);
    border-color: var(--text-secondary);
}

.btn-icon {
    padding: 6px;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}
.btn-icon:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.btn-small {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-danger:hover {
    background: var(--danger-hover);
}

/* ===== DASHBOARD ===== */
.dashboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.dashboard-actions {
    margin-bottom: 1.5rem;
}

.trees-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.tree-card {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    text-align: center;
}

.tree-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.tree-card-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 50%;
    line-height: 1;
    opacity: 0;
    transition: all var(--transition);
}

.tree-card:hover .tree-card-delete {
    opacity: 1;
}

.tree-card-delete:hover {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
}

.tree-card-delete .material-icons {
    font-size: 18px;
}

.tree-card-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.tree-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.tree-card-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: center;
    gap: 0.4rem;
}

.tree-card-footer {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.7;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h3 {
    font-size: 1.3rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* ===== TREE CONTAINER ===== */
.tree-container {
    flex: 1;
    overflow: hidden;
    background: var(--bg-primary);
    position: relative;
}

.tree-container svg {
    width: 100%;
    height: 100%;
}

/* ===== TREE NODES (SVG) ===== */
.node-group {
    cursor: pointer;
}

.node-rect {
    rx: 8;
    ry: 8;
    stroke-width: 2;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
    transition: filter 0.2s;
}

.node-group:hover .node-rect {
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

.node-rect.male {
    fill: var(--male-color);
    stroke: var(--male-border);
}

.node-rect.female {
    fill: var(--female-color);
    stroke: var(--female-border);
}

.spouse-rect {
    rx: 8;
    ry: 8;
    stroke-width: 2;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.spouse-rect.male {
    fill: var(--male-color);
    stroke: var(--male-border);
}

.spouse-rect.female {
    fill: var(--female-color);
    stroke: var(--female-border);
}

.node-name {
    font-size: 13px;
    font-weight: 600;
    fill: var(--text-primary);
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: middle;
}

.node-year {
    font-size: 10px;
    fill: var(--text-muted);
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: middle;
}

.spouse-name {
    font-size: 13px;
    font-weight: 600;
    fill: var(--text-primary);
    pointer-events: none;
    text-anchor: middle;
    dominant-baseline: middle;
}

.collapse-btn {
    cursor: pointer;
    font-size: 12px;
    fill: var(--text-secondary);
    font-weight: 700;
}

.collapse-btn:hover {
    fill: var(--primary);
}

.link-path {
    fill: none;
    stroke: var(--child-link-color);
    stroke-width: 2;
    stroke-opacity: 0.6;
}

.spouse-link {
    fill: none;
    stroke: var(--spouse-link-color);
    stroke-width: 2;
    stroke-dasharray: 6, 4;
    stroke-opacity: 0.7;
}

.heart-icon {
    font-size: 12px;
    fill: var(--spouse-link-color);
}

/* ===== NODE ACTION BUTTONS ===== */
.node-action-btn {
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}

.node-group:hover .node-action-btn {
    opacity: 1;
}

.node-action-circle {
    fill: var(--primary);
    r: 10;
}

.node-action-circle:hover {
    fill: var(--primary-hover);
}

.node-action-icon {
    fill: white;
    font-size: 12px;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}

/* ===== CONTEXT MENU ===== */
.context-menu {
    position: fixed;
    background: var(--bg-white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px 0;
    z-index: 1000;
    min-width: 200px;
}

.context-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

.context-item:hover {
    background: var(--bg-primary);
}

.context-item .material-icons {
    font-size: 18px;
    color: var(--text-secondary);
}

.context-item.danger {
    color: var(--danger);
}
.context-item.danger .material-icons {
    color: var(--danger);
}

.context-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 4px 0;
}

/* ===== MODALS ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    margin: 1rem;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group input[type="text"],
.form-group input[type="number"] {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color var(--transition);
    outline: none;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.1);
}

.gender-select {
    display: flex;
    gap: 0.75rem;
}

.gender-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
}

.gender-btn.male.selected {
    border-color: var(--male-border);
    background: var(--male-color);
}

.gender-btn.female.selected {
    border-color: var(--female-border);
    background: var(--female-color);
}

.gender-btn:not(.selected):hover {
    border-color: var(--text-muted);
}

/* ===== SHARE MODAL ===== */
.share-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #ccc;
    border-radius: 26px;
    transition: var(--transition);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

.share-link-section {
    margin-top: 1rem;
}

.share-link-row {
    display: flex;
    gap: 0.5rem;
}

.share-link-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    background: var(--bg-primary);
}

.share-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    z-index: 2000;
    transition: transform 0.3s ease;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ===== LOADING SPINNER ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===== TREE TITLE EDITABLE ===== */
.tree-header h2[contenteditable="true"] {
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    outline: none;
    background: var(--primary-light);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
    .login-hero h1 {
        font-size: 2rem;
    }
    .app-header {
        padding: 0.5rem 1rem;
    }
    .user-name {
        display: none;
    }
    .dashboard-content {
        padding: 1rem;
    }
    .trees-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== SELECTED NODE ===== */
.node-rect.selected {
    stroke: #e74c3c;
    stroke-width: 3;
    filter: drop-shadow(0 0 6px rgba(231, 76, 60, 0.4));
}

/* ===== SEARCH HIGHLIGHT ===== */
.node-rect.search-highlight {
    stroke: #f39c12;
    stroke-width: 3;
    filter: drop-shadow(0 0 8px rgba(243, 156, 18, 0.5));
}

.node-rect.selected.search-highlight {
    stroke: #e74c3c;
    stroke-width: 3;
    filter: drop-shadow(0 0 8px rgba(231, 76, 60, 0.5));
}

/* ===== PENDING EDIT STYLES ===== */
.node-rect.pending {
    stroke: #f39c12;
    stroke-width: 2;
    stroke-dasharray: 6 3;
    opacity: 0.7;
}

.node-rect.pending-delete {
    stroke: #e74c3c;
    stroke-width: 2;
    stroke-dasharray: 6 3;
    opacity: 0.5;
}

.node-rect.pending-edit {
    stroke: #3498db;
    stroke-width: 2;
    stroke-dasharray: 6 3;
    opacity: 0.8;
}

.pending-badge {
    fill: #f39c12;
    font-weight: 600;
    font-family: var(--font-primary);
    pointer-events: none;
}

/* ===== TOOLBAR ACTIVE STATE ===== */
.btn-active {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
}

/* ===== SEARCH CONTAINER ===== */
.search-container {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
}

.search-container input {
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.85rem;
    font-family: inherit;
    width: 160px;
    padding: 4px 6px;
}

.search-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 50px;
    text-align: center;
}

/* ===== EDITOR LIST ===== */
.editors-list {
    margin-bottom: 0.75rem;
}

.editor-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--bg-primary);
}

.add-editor-row {
    display: flex;
    gap: 0.5rem;
}

.add-editor-row input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
}

.add-editor-row input:focus {
    border-color: var(--primary);
}

/* ===== SUGGESTIONS PANEL ===== */
.suggestions-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 360px;
    max-width: 90vw;
    background: var(--bg-white);
    box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    z-index: 500;
    display: flex;
    flex-direction: column;
}

.suggestions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.suggestions-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.suggestions-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.empty-suggestions {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 1rem;
    font-size: 0.9rem;
}

.suggestion-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.suggestion-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.suggestion-info strong {
    font-size: 0.85rem;
}

.suggestion-by {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.suggestion-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 8px;
}

/* ===== EDITOR GROUP (pending edits grouped by editor) ===== */
.editor-group {
    margin-bottom: 1rem;
}

.editor-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary, #f0f0f0);
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
    position: sticky;
    top: 0;
    z-index: 1;
}

.editor-group-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
}

.editor-group-count {
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 4px;
    font-size: 0.8rem;
}

.editor-group-actions {
    display: flex;
    gap: 4px;
}

.editor-group-actions .btn {
    font-size: 0.7rem;
    padding: 2px 8px;
    display: flex;
    align-items: center;
    gap: 2px;
}

/* ===== SUGGESTIONS FAB ===== */
.suggestions-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    box-shadow: var(--shadow-lg);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    transition: all var(--transition);
}

.suggestions-fab:hover {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.suggestions-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}
