/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2c5282;
    --primary-hover: #1a365d;
    --secondary-color: #718096;
    --background-color: #f7fafc;
    --surface-color: #ffffff;
    --text-color: #2d3748;
    --text-muted: #718096;
    --border-color: #e2e8f0;
    --error-color: #c53030;
    --warning-color: #d69e2e;
    --success-color: #38a169;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.5;
    min-width: 1024px;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Views */
.view {
    min-height: 100vh;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s;
}

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

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

.btn-secondary {
    background-color: var(--surface-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

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

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

.btn:disabled:hover {
    background-color: var(--surface-color);
}

/* Form elements */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--surface-color);
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Link to existing person search results */
.link-search-results {
    position: absolute;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    margin-top: 2px;
}

.link-search-results:empty {
    display: none;
}

.link-search-result {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

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

.link-search-result:hover {
    background: var(--border-color);
}

.link-search-result.selected {
    background: var(--primary-color);
    color: white;
}

.link-search-result .person-name {
    font-weight: 500;
}

.link-search-result .person-info {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.link-search-result.selected .person-info {
    color: rgba(255, 255, 255, 0.8);
}

#parent-link-search-group,
#partner-link-search-group {
    position: relative;
}

.link-selected-person {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
}

/* Consanguinity warning */
.consanguinity-warning {
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 4px;
    color: #856404;
    font-size: 0.875rem;
}

.consanguinity-warning strong {
    display: block;
    margin-bottom: 0.25rem;
}

/* Auth view */
.auth-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 4rem 1rem;
}

.auth-container h1 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.auth-container .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.auth-form {
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.auth-form .btn {
    width: 100%;
    margin-top: 0.5rem;
}

.error-message {
    color: var(--error-color);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.warning-message {
    background-color: #fefcbf;
    border: 1px solid #f6e05e;
    color: #744210;
    padding: 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background-color: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.header h1 {
    font-size: 1.25rem;
}

.header h2 {
    font-size: 1.125rem;
    font-weight: 500;
}

.header .spacer {
    width: 100px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Main content */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.tree-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.tree-list-header h2 {
    font-size: 1.5rem;
}

/* Tree list controls (search, sort, count) */
.tree-list-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.tree-search-wrapper {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

.tree-search-wrapper input {
    width: 100%;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--surface-color);
}

.tree-search-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

.tree-search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.tree-search-clear:hover {
    color: var(--text-color);
}

.tree-list-controls select {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--surface-color);
    cursor: pointer;
    min-width: 180px;
}

.tree-list-controls select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

.tree-list-count {
    font-size: 0.875rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Responsive tree list controls */
@media (max-width: 600px) {
    .tree-list-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .tree-search-wrapper {
        max-width: none;
    }

    .tree-list-controls select {
        width: 100%;
    }
}

/* Tree list */
.tree-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.tree-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1.25rem;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

.tree-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.tree-card h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
}

.tree-card .patient-name {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
}

.tree-card .tree-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    background-color: var(--surface-color);
    border: 1px dashed var(--border-color);
    border-radius: 0.5rem;
    max-width: 500px;
    margin: 2rem auto;
}

.empty-state-icon {
    color: var(--primary-color);
    margin-bottom: 1.5rem;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-color);
}

.empty-state p {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.empty-state .btn {
    margin-top: 0.5rem;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background-color: var(--surface-color);
    padding: 1.5rem;
    border-radius: 0.5rem;
    max-width: 450px;
    width: 100%;
    margin: 1rem;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content-wide {
    max-width: 650px;
}

.modal-content h2 {
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* Editor view */
#tree-editor-view {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

#tree-editor-view .header {
    flex-shrink: 0;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
}

.editor-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Header rows */
.header-row {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.5rem 1rem;
}

.header-row-nav {
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.header-row-tools {
    justify-content: space-between;
    padding: 0.375rem 1rem;
}

/* Header left section */
.header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Header center section */
.header-center {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Header right section */
.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Toolbar tools section */
.toolbar-tools {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#help-btn {
    font-weight: bold;
    font-size: 1rem;
    min-width: 36px;
    padding: 0.5rem;
}

/* Onboarding hint */
.onboarding-hint {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.onboarding-hint-content {
    background-color: var(--surface-color);
    border: 1px solid var(--primary-color);
    border-radius: 0.5rem;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    max-width: 500px;
    position: relative;
}

.onboarding-hint-content p {
    font-size: 0.875rem;
    color: var(--text-color);
    margin: 0;
    line-height: 1.5;
}

.onboarding-hint-content kbd {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.75rem;
    color: var(--text-color);
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
}

.onboarding-hint-dismiss {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
}

.onboarding-hint-dismiss:hover {
    color: var(--text-color);
}

/* Search container */
.search-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper input {
    width: 200px;
    padding: 0.375rem 1.75rem 0.375rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--surface-color);
}

.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(44, 82, 130, 0.1);
}

.clear-search-btn {
    position: absolute;
    right: 4px;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
}

.clear-search-btn:hover {
    color: var(--text-color);
}

.search-results-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 280px;
    max-height: 300px;
    overflow-y: auto;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    z-index: 100;
    margin-top: 0.25rem;
}

.search-result-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.1s;
}

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

.search-result-item:hover,
.search-result-item.selected {
    background-color: var(--background-color);
}

.search-result-item.selected {
    background-color: #e6f0fa;
}

.search-result-name {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-color);
}

.search-result-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.search-result-highlight {
    background-color: #fef3c7;
    padding: 0 1px;
    border-radius: 2px;
}

.search-no-results {
    padding: 0.75rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.search-filters select {
    padding: 0.375rem 0.5rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--surface-color);
    cursor: pointer;
}

.search-filters select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Person node highlight state for search */
.person-node.search-highlight .node-shape {
    stroke: var(--warning-color);
    stroke-width: 4;
    animation: pulse-highlight 1s ease-in-out 3;
}

@keyframes pulse-highlight {
    0%, 100% { stroke-opacity: 1; }
    50% { stroke-opacity: 0.5; }
}


/* Save status indicator */
.save-status {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: all 0.2s ease;
}

.save-status.saving {
    color: var(--primary-color);
}

.save-status.saving .save-status-icon {
    animation: spin 1s linear infinite;
}

.save-status.saved {
    color: var(--success-color);
}

.save-status.error {
    color: var(--error-color);
}

.save-status.offline {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

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

/* Inactivity warning modal */
#inactivity-warning-modal .modal-content {
    text-align: center;
}

#inactivity-warning-modal #timeout-countdown {
    font-size: 1.5rem;
    color: var(--error-color);
}

/* Toolbar toggle button (for mobile/smaller screens) */
.toolbar-toggle {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    cursor: pointer;
    color: var(--text-color);
}

.toolbar-toggle:hover {
    background-color: var(--background-color);
}

/* Collapsible toolbar container */
.toolbar-collapsible {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Responsive header - smaller screens (< 1024px) */
@media (max-width: 1023px) {
    .header-row-nav {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .header-center {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .header-row-tools {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .toolbar-toggle {
        display: block;
    }

    .toolbar-collapsible {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        background-color: var(--surface-color);
        border: 1px solid var(--border-color);
        border-radius: 0.375rem;
        padding: 0.5rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        z-index: 50;
        min-width: 150px;
    }

    .toolbar-collapsible.show {
        display: flex;
    }

    .toolbar-collapsible .btn {
        justify-content: flex-start;
        width: 100%;
    }

    .toolbar-tools {
        position: relative;
    }

    .search-container {
        flex: 1;
    }

    .search-input-wrapper input {
        width: 100%;
    }
}

#zoom-level {
    font-size: 0.875rem;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
}

/* Tree Canvas */
.tree-canvas {
    width: 100%;
    height: 100%;
    background-color: var(--surface-color);
    cursor: grab;
}

.tree-canvas:active {
    cursor: grabbing;
}

.canvas-background {
    pointer-events: all;
}

/* Person nodes */
.person-node {
    cursor: pointer;
}

.person-node .node-shape {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: var(--surface-color);
    transition: stroke 0.15s, stroke-width 0.15s;
}

.person-node:hover .node-shape {
    stroke: var(--primary-color);
}

.person-node.patient .node-shape {
    stroke: var(--primary-color);
    stroke-width: 3;
    fill: #e6f0fa;
}

.person-node .node-label {
    font-size: 12px;
    fill: var(--text-color);
    text-anchor: middle;
    pointer-events: none;
}

.person-node .node-birth-year {
    font-size: 10px;
    fill: var(--text-muted);
    text-anchor: middle;
    pointer-events: none;
}

/* Gender symbols: square for male, circle for female, diamond for other/unknown */
.person-node.gender-male .node-shape {
    /* Square handled via rect element */
}

.person-node.gender-female .node-shape {
    /* Circle handled via circle element */
}

.person-node.gender-other .node-shape,
.person-node.gender-unknown .node-shape {
    /* Diamond handled via polygon element */
}

/* Selected node */
.person-node.selected .node-shape {
    stroke: var(--success-color);
    stroke-width: 3;
}

/* Locked position node */
.person-node.position-locked .node-shape {
    stroke-dasharray: 4 2;
}

.person-node.position-locked .lock-indicator {
    fill: var(--secondary-color);
    font-size: 10px;
}

/* Unknown person styling */
.person-node.unknown-person .node-shape {
    stroke-dasharray: 4 2;
    fill: var(--background-color);
}

.person-node.unknown-person .node-label {
    font-style: italic;
    fill: var(--text-muted);
}

/* Pregnancy styling (triangle) */
.person-node.pregnancy .node-shape {
    fill: var(--surface-color);
    stroke: var(--text-color);
    stroke-width: 2;
}

/* Pregnancy loss (miscarriage/abortion) styling */
.person-node.pregnancy-loss .node-shape {
    fill: var(--background-color);
    stroke: var(--text-color);
    stroke-width: 2;
}

.person-node.pregnancy-loss .loss-marker line {
    stroke: var(--text-color);
    stroke-width: 2;
}

.person-node.miscarriage .node-label,
.person-node.abortion .node-label {
    font-size: 10px;
    fill: var(--text-muted);
}

/* Visibility toggle button */
.visibility-btn {
    min-width: 40px;
    padding: 0.375rem 0.5rem;
}

.visibility-btn .visibility-icon {
    font-size: 1.1rem;
}

/* Dragging node */
.person-node.dragging {
    cursor: grabbing;
    opacity: 0.8;
}

.person-node.dragging .node-shape {
    stroke: var(--primary-color);
    stroke-width: 3;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    min-width: 150px;
    z-index: 200;
    padding: 0.25rem 0;
}

.context-menu-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.5rem 1rem;
    text-align: left;
    background: none;
    border: none;
    font-size: 0.875rem;
    color: var(--text-color);
    cursor: pointer;
}

.shortcut-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    background-color: var(--background-color);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    margin-left: 1rem;
}

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

.context-menu-divider {
    height: 1px;
    background-color: var(--border-color);
    margin: 0.25rem 0;
}

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

.context-menu-item.danger:hover {
    background-color: #fff5f5;
}

/* Relationship lines */
.relationship-line {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: none;
}

.relationship-line.parent {
    stroke: var(--text-color);
}

/* Partner relationship lines */
.relationship-line.partner {
    stroke: var(--text-color);
    stroke-width: 2;
}

/* Union type styles per genogram standards */
.relationship-line.partner.union-married {
    /* Solid line for married */
    stroke: var(--text-color);
}

.relationship-line.partner.union-divorced {
    /* Dashed line with slashes for divorced */
    stroke-dasharray: 8 4;
    stroke: var(--error-color);
}

.relationship-line.partner.union-separated {
    /* Dashed line for separated */
    stroke-dasharray: 8 4;
    stroke: var(--text-color);
}

.relationship-line.partner.union-cohabiting {
    /* Dotted line for cohabiting */
    stroke-dasharray: 2 4;
    stroke: var(--text-color);
}

.relationship-line.partner.union-engaged {
    /* Long dash for engaged */
    stroke-dasharray: 12 4;
    stroke: var(--text-color);
}

/* Parent connector - horizontal line between parents */
.parent-connector {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: none;
}

/* Child relationship line from union point to child */
.child-line {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: none;
}

/* Sibling connector - horizontal line connecting siblings */
.sibling-connector {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: none;
}

/* Twin/triplet connectors */
.twin-connector {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: none;
}

.twin-connector.identical {
    /* Identical twins: converging lines meeting at a point */
    stroke-width: 2;
}

.twin-connector.fraternal {
    /* Fraternal twins: converging lines that don't quite meet */
    stroke-width: 2;
}

/* Deceased person styling - X through shape */
.person-node.deceased .node-shape {
    fill: #f0f0f0;
}

.person-node.deceased .deceased-x {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: none;
}

/* Clinical conditions palette */
.conditions-palette {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background-color: var(--background-color);
    border-radius: 0.375rem;
}

.condition-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.condition-checkbox input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.condition-symbol {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-color);
    border-radius: 2px;
    position: relative;
}

/* Genogram standard: quadrant fills for conditions */
.condition-symbol.mental-illness::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 50%;
    height: 50%;
    background-color: var(--text-color);
}

.condition-symbol.substance-abuse::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 50%;
    height: 50%;
    background-color: var(--text-color);
}

.condition-symbol.physical-illness::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 50%;
    background-color: var(--text-color);
}

/* Custom conditions */
.custom-conditions {
    margin-top: 0.75rem;
}

.custom-condition-input {
    display: flex;
    gap: 0.5rem;
}

.custom-condition-input input {
    flex: 1;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

.custom-conditions-list {
    margin-top: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.custom-condition-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    font-size: 0.75rem;
}

.custom-condition-tag button {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.custom-condition-tag button:hover {
    color: var(--error-color);
}

/* Condition fills on person nodes (genogram quadrants) */
.person-node .condition-fill {
    pointer-events: none;
}

.person-node .condition-fill.mental-illness {
    fill: var(--text-color);
}

.person-node .condition-fill.substance-abuse {
    fill: var(--text-color);
}

.person-node .condition-fill.physical-illness {
    fill: var(--text-color);
}

.person-node .condition-fill.custom {
    fill: var(--secondary-color);
}

/* Relationship quality line styles per genogram standards */
.relationship-line.quality-close {
    /* Close: solid line (default) */
    stroke-width: 2;
}

.relationship-line.quality-very_close {
    /* Very close/fused: double line - use thicker stroke */
    stroke-width: 4;
}

.relationship-line.quality-hostile {
    /* Hostile: zigzag line - handled via path */
    stroke: var(--error-color);
    stroke-width: 2;
}

.relationship-line.quality-distant {
    /* Distant: dotted line */
    stroke-dasharray: 2 4;
    stroke-width: 2;
}

.relationship-line.quality-cutoff {
    /* Cutoff: line with breaks */
    stroke-dasharray: 10 6;
    stroke-width: 2;
}

.relationship-line.quality-abuse {
    /* Abuse: solid line with directional marks */
    stroke: var(--error-color);
    stroke-width: 2;
}

.relationship-line.quality-violence {
    /* Violence: solid line with directional marks (more intense) */
    stroke: var(--error-color);
    stroke-width: 3;
}

/* Consanguinity: double line for related-then-partnered individuals */
.relationship-line.consanguinity {
    stroke: var(--text-color);
    stroke-width: 2;
}

.relationship-line.consanguinity-double {
    stroke: var(--text-color);
    stroke-width: 2;
}

/* Clickable relationship line overlay */
.relationship-line-hitarea {
    stroke: transparent;
    stroke-width: 12;
    fill: none;
    cursor: pointer;
    pointer-events: stroke;
}

.relationship-line-hitarea:hover + .relationship-line,
.relationship-line.hover {
    stroke: var(--primary-color);
}

.relationship-line-hitarea:hover + .child-line {
    stroke: var(--primary-color);
}

/* Selected relationship line */
.relationship-line.selected {
    stroke: var(--success-color);
    stroke-width: 3;
}

/* Direction indicators (arrows) */
.direction-arrow {
    fill: var(--error-color);
    stroke: none;
}

/* Very close/fused double line effect - second line */
.relationship-double-line {
    stroke: var(--text-color);
    stroke-width: 2;
    fill: none;
}

/* Relationship info in modal */
.relationship-info {
    background-color: var(--background-color);
    padding: 0.75rem;
    border-radius: 0.375rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
}

.relationship-info strong {
    display: block;
    margin-bottom: 0.25rem;
}

/* Zigzag pattern for hostile relationships */
.zigzag-line {
    stroke: var(--error-color);
    stroke-width: 2;
    fill: none;
}

/* Delete button */
.btn-danger {
    background-color: var(--error-color);
    color: white;
}

.btn-danger:hover {
    background-color: #9b2c2c;
}

/* Modal danger zone (for destructive actions) */
.modal-divider {
    margin: 1rem 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

.modal-danger-zone {
    padding-top: 0.5rem;
}

/* Delete person modal */
.delete-info {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: var(--background-color);
    border-radius: 0.375rem;
}

.delete-info strong {
    display: block;
    margin-bottom: 0.25rem;
}

.delete-children-section {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: #fff5f5;
    border: 1px solid #feb2b2;
    border-radius: 0.375rem;
}

.delete-children-section p {
    margin-bottom: 0.75rem;
    font-weight: 500;
}

.radio-option {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    cursor: pointer;
    font-weight: normal;
}

.radio-option input[type="radio"] {
    width: auto;
    margin-right: 0.5rem;
}

/* Photo upload styles */
.photo-upload-group {
    margin-bottom: 1rem;
}

.photo-preview-container {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    margin-top: 0.5rem;
}

.photo-preview {
    width: 80px;
    height: 80px;
    border: 2px dashed var(--border-color);
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background-color: var(--background-color);
}

.photo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
}

.photo-preview .no-photo {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: center;
}

.photo-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.photo-upload-btn {
    cursor: pointer;
}

.btn-small {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

.btn-danger-text {
    color: var(--error-color);
}

.btn-danger-text:hover {
    background-color: #fee;
}

/* Photo in tree nodes */
.node-photo {
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

.node-photo-clickable {
    cursor: pointer;
}

/* Photo viewer modal */
.photo-viewer-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 90vw;
    max-height: 90vh;
    z-index: 1001;
}

.photo-viewer-content img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 10px 20px rgba(0, 0, 0, 0.15);
}

.photo-viewer-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
}

.photo-viewer-close:hover {
    color: #ddd;
}

/* Export image modal styles */
.export-progress {
    margin: 1rem 0;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background-color: var(--primary-color);
    transition: width 0.2s ease;
}

.progress-text {
    font-size: 0.875rem;
    color: var(--text-muted);
}

#export-size-preview {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-muted);
}

/* Print modal styles */
.print-info {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.checkbox-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.checkbox-option input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* Print header (visible only during print) */
.print-header {
    display: none;
}

/* Print legend (visible only during print) */
.print-legend {
    display: none;
}

/* Print styles */
@media print {
    /* Hide UI chrome */
    .header,
    .modal,
    .context-menu,
    #auth-view,
    #tree-list-view,
    .toolbar-tools,
    .search-container,
    #back-to-list-btn {
        display: none !important;
    }

    /* Reset body and html */
    html, body {
        width: 100%;
        height: auto;
        margin: 0;
        padding: 0;
        background: white !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* Show print header */
    .print-header {
        display: block !important;
        padding: 0.5cm 0;
        border-bottom: 1px solid #333;
        margin-bottom: 0.5cm;
        page-break-after: avoid;
    }

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

    .print-header-title {
        font-size: 16pt;
        font-weight: bold;
        margin: 0;
        color: #333;
    }

    .print-header-patient {
        font-size: 12pt;
        color: #555;
        margin: 0.25cm 0 0 0;
    }

    .print-header-date {
        font-size: 10pt;
        color: #666;
        text-align: right;
    }

    /* Show print legend if enabled */
    .print-legend.show-legend {
        display: block !important;
        margin-top: 0.5cm;
        padding-top: 0.5cm;
        border-top: 1px solid #ccc;
        page-break-inside: avoid;
    }

    .print-legend-title {
        font-size: 11pt;
        font-weight: bold;
        margin-bottom: 0.25cm;
        color: #333;
    }

    .print-legend-content {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5cm 1cm;
        font-size: 9pt;
    }

    .legend-section {
        min-width: 3cm;
    }

    .legend-section-title {
        font-weight: bold;
        margin-bottom: 0.15cm;
        color: #333;
    }

    .legend-item {
        display: flex;
        align-items: center;
        gap: 0.2cm;
        margin-bottom: 0.1cm;
        color: #444;
    }

    .legend-symbol {
        display: inline-block;
        width: 16px;
        height: 16px;
        border: 1.5px solid #333;
        flex-shrink: 0;
    }

    .legend-symbol.square {
        border-radius: 0;
    }

    .legend-symbol.circle {
        border-radius: 50%;
    }

    .legend-symbol.diamond {
        width: 12px;
        height: 12px;
        transform: rotate(45deg);
        margin: 2px;
    }

    .legend-symbol.deceased::after {
        content: "X";
        display: block;
        text-align: center;
        font-size: 10px;
        line-height: 13px;
        color: #333;
    }

    .legend-line {
        display: inline-block;
        width: 24px;
        height: 2px;
        background: #333;
        flex-shrink: 0;
        vertical-align: middle;
    }

    .legend-line.dashed {
        background: repeating-linear-gradient(
            to right,
            #333 0px, #333 4px,
            transparent 4px, transparent 8px
        );
    }

    .legend-line.dotted {
        background: repeating-linear-gradient(
            to right,
            #333 0px, #333 2px,
            transparent 2px, transparent 5px
        );
    }

    .legend-line.zigzag {
        background: none;
        border-bottom: 2px solid #c53030;
        height: 0;
    }

    .legend-line.double {
        height: 4px;
        background: linear-gradient(to bottom, #333 0px, #333 1px, white 1px, white 3px, #333 3px, #333 4px);
    }

    .legend-quadrant {
        display: inline-block;
        width: 16px;
        height: 16px;
        border: 1.5px solid #333;
        position: relative;
        flex-shrink: 0;
    }

    .legend-quadrant.mental-illness::after {
        content: "";
        position: absolute;
        bottom: 0;
        left: 0;
        width: 50%;
        height: 50%;
        background: #333;
    }

    .legend-quadrant.substance-abuse::after {
        content: "";
        position: absolute;
        bottom: 0;
        right: 0;
        width: 50%;
        height: 50%;
        background: #333;
    }

    .legend-quadrant.physical-illness::after {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 50%;
        height: 50%;
        background: #333;
    }

    /* Make editor view fill the page */
    #tree-editor-view {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        padding: 0.5cm;
    }

    .editor-content {
        height: auto !important;
        overflow: visible !important;
    }

    /* Tree canvas for print */
    .tree-canvas {
        width: 100% !important;
        height: auto !important;
        background: white !important;
        cursor: default !important;
    }

    .tree-canvas .canvas-background {
        fill: white !important;
    }

    /* Ensure high contrast for print */
    .person-node .node-shape {
        stroke: #333 !important;
        fill: white !important;
    }

    .person-node.patient .node-shape {
        stroke: #1a365d !important;
        stroke-width: 3px !important;
        fill: #e6f0fa !important;
    }

    .person-node .node-label {
        fill: #000 !important;
    }

    .person-node .node-years {
        fill: #333 !important;
    }

    .relationship-line,
    .child-line,
    .sibling-connector,
    .parent-connector {
        stroke: #333 !important;
    }

    .relationship-line.quality-hostile,
    .relationship-line.quality-abuse,
    .relationship-line.quality-violence,
    .zigzag-line {
        stroke: #c53030 !important;
    }

    .direction-arrow {
        fill: #c53030 !important;
    }

    .deceased-x line {
        stroke: #333 !important;
    }

    .condition-fill {
        fill: #333 !important;
    }

    /* Page settings */
    @page {
        size: landscape;
        margin: 1cm;
    }

    /* Avoid page breaks inside nodes */
    .person-node {
        page-break-inside: avoid;
    }
}

/* Keyboard shortcuts modal */
.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.shortcuts-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.shortcut-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.375rem 0;
    font-size: 0.875rem;
}

.shortcut-row span {
    color: var(--text-muted);
    flex: 1;
    margin-left: 0.75rem;
}

kbd {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.75rem;
    color: var(--text-color);
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
}

/* Person node selection indicator */
.person-node.keyboard-focused rect,
.person-node.keyboard-focused circle,
.person-node.keyboard-focused polygon {
    stroke: var(--primary-color) !important;
    stroke-width: 4 !important;
}

/* Help modal */
.help-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.help-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border-color);
}

.help-section ol,
.help-section ul {
    padding-left: 1.25rem;
    font-size: 0.875rem;
    color: var(--text-color);
}

.help-section li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.help-section li strong {
    color: var(--text-color);
}

.help-section kbd {
    display: inline-block;
    padding: 0.125rem 0.375rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.7rem;
    color: var(--text-color);
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    vertical-align: baseline;
}

/* Export modal tabs */
.export-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.25rem;
    gap: 0;
}

.export-tab {
    flex: 1;
    padding: 0.625rem 1rem;
    background: none;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}

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

.export-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.export-tab-content {
    display: none;
}

.export-tab-content.active {
    display: block;
}

/* Export visibility overrides */
.export-visibility-overrides {
    margin-top: 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0;
}

.export-visibility-overrides summary {
    padding: 0.625rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-muted);
}

.export-visibility-overrides summary:hover {
    color: var(--text-color);
}

.export-visibility-controls {
    padding: 0.5rem 0.75rem 0.75rem;
}

.export-vis-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.export-visibility-controls label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 0;
    font-size: 0.8125rem;
    cursor: pointer;
}

.export-visibility-controls input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* Mermaid export modal styles */
.mermaid-export-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: var(--background-color);
    border-radius: 0.375rem;
}

.mermaid-output {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background-color: var(--surface-color);
    resize: vertical;
    min-height: 200px;
}

.mermaid-output:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(44, 82, 130, 0.1);
}

/* Visibility dropdown */
.visibility-dropdown-container {
    position: relative;
    display: inline-block;
}

.visibility-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 60;
    padding: 0.5rem 0.75rem;
    min-width: 200px;
    margin-top: 0.25rem;
}

.visibility-dropdown label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    font-size: 0.8125rem;
    cursor: pointer;
    white-space: nowrap;
}

.visibility-dropdown label:hover {
    color: var(--primary-color);
}

.visibility-dropdown input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.visibility-dropdown hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 0.375rem 0;
}

.visibility-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

/* Household groups (cohabitation circles) */
.household-group-label {
    font-size: 11px;
    font-weight: 500;
    pointer-events: none;
}

/* Household groups modal */
.household-groups-list {
    margin-bottom: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.household-groups-empty {
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: center;
    padding: 1.5rem 0;
}

.household-group-card {
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}

.household-group-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.household-group-card-header .group-card-name {
    flex: 1;
    font-size: 0.875rem;
}

.household-group-card-actions {
    display: flex;
    gap: 0.25rem;
}

.household-group-card-members {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.375rem;
}

.group-color-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.color-swatches {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    transition: border-color 0.15s, transform 0.1s;
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.active {
    border-color: var(--text-color);
}

.group-members-checklist {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.5rem;
}

.group-members-checklist .checkbox-option {
    padding: 0.25rem 0;
}

.household-group-edit-form {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
}

