/* Variables */
:root {
    --bg-primary: #111215;
    --bg-secondary: #1a1c20;
    --bg-card: #212428;
    --bg-card-end: #272a2f;
    --bg-hover: #2d3137;
    --accent: #5cb88a;
    --accent-dim: #3d8a65;
    --text-main: #e4e6ea;
    --text-dim: #808890;
    --muted: #808890;
    --border: #2d3238;
    --danger: #c0392b;
    --danger-hover: #e74c3c;
    --shadow: rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.55);
    --radius-sm: 4px;
    --radius: 10px;
    --radius-lg: 16px;
    --node-width: 200px;
    --male-color: #6ab2e2;
    --female-color: #e07898;
    --root-color: #ffffff;
    --status-success: #4caf50;
    --status-error: #e85050;
    --status-warning: #e8a838;
    --toggle-off: #606060;
}

:root[data-theme="light"] {
    --bg-primary: #f0f4f0;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-card-end: #f2f7f2;
    --bg-hover: #e4ede4;
    --accent: #2d8a4e;
    --accent-dim: #4aad6a;
    --text-main: #1a2e1a;
    --text-dim: #4d6d4d;
    --muted: #6b8a6b;
    --border: #c4d9c4;
    --danger: #c0392b;
    --danger-hover: #e74c3c;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.15);
    --male-color: #4a9fb5;
    --female-color: #d4668a;
    --root-color: #1a2e1a;
    --status-success: #2e7d32;
    --status-error: #c62828;
    --status-warning: #e8a838;
    --toggle-off: #aaa;
}

/* Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.header-logo {
    width: 24px;
    height: 24px;
}

.header h1 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-dim);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.root-select {
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: border-color 0.2s;
    display: none;
}

.root-select:hover { border-color: var(--accent-dim); }
.root-select:focus { outline: none; border-color: var(--accent); }

.home-btn,
.back-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 8px;
    transition: background 0.2s, opacity 0.2s;
}

.home-btn:hover:not(:disabled),
.back-btn:hover:not(:disabled) { background: var(--bg-hover); }
.home-btn:disabled,
.back-btn:disabled { opacity: 0.4; cursor: default; }

.root-select-wrapper {
    position: relative;
}

.root-search {
    display: block;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.8rem;
    width: 200px;
    transition: border-color 0.2s;
}

.root-search:focus { outline: none; border-color: var(--accent); }

.root-search-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    z-index: 500;
    box-shadow: var(--shadow-md);
}

.root-search-list.active { display: block; }

.root-search-item {
    padding: 8px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-main);
}

.root-search-item:hover { background: var(--bg-hover); }
.root-search-item.dim { color: var(--text-dim); cursor: default; }

.existing-person-radios {
    display: flex;
    gap: 16px;
    margin-bottom: 8px;
}

.existing-person-radios .radio-label {
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-main);
    white-space: nowrap;
}

.existing-person-search-wrapper {
    position: relative;
}

.existing-person-search {
    display: block;
    width: 100%;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.85rem;
    transition: border-color 0.2s, opacity 0.2s;
    box-sizing: border-box;
}

.existing-person-search:focus { outline: none; border-color: var(--accent); }
.existing-person-search:disabled { opacity: 0.4; cursor: default; }

.existing-person-list {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-top: 4px;
    z-index: 500;
    box-shadow: var(--shadow-md);
}

.existing-person-list.active { display: block; }

.existing-person-item {
    padding: 8px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-main);
}

.existing-person-item:hover { background: var(--bg-hover); }
.existing-person-item.dim { color: var(--text-dim); cursor: default; }
.existing-person-item.selected { background: var(--bg-hover); font-weight: 500; }

.existing-person-mobile-label {
    display: none;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.existing-person-mobile {
    display: none;
    width: 100%;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.85rem;
}

.person-select-wrapper {
    position: relative;
}

.person-select-search {
    display: block;
    width: 100%;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.85rem;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.person-select-search:focus { outline: none; border-color: var(--accent); }

.person-select-mobile {
    display: none;
    width: 100%;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 12px;
    font-size: 0.85rem;
}

.branch-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.root-label,
.branch-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-right: 2px;
}

.branch-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 8px;
    transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}

.branch-btn:hover:not(:disabled) { background: var(--bg-hover); }
.branch-btn:disabled { opacity: 0.4; cursor: default; }
.branch-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
}

.view-group {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    padding-left: 12px;
    border-left: 1px solid var(--border);
}

.view-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 8px;
    transition: background 0.2s, border-color 0.2s, opacity 0.2s;
}

.view-btn:hover:not(:disabled) { background: var(--bg-hover); }
.view-btn:disabled { opacity: 0.4; cursor: default; }
.view-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
}

/* Hamburger menu */
.menu-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius);
    transition: background 0.2s;
}

.menu-btn:hover { background: var(--bg-hover); }
.menu-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
}

.menu-overlay.active { display: block; }

.menu-panel {
    position: fixed;
    top: 0;
    right: -280px;
    width: 280px;
    height: 100%;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    padding: 20px;
    transition: right 0.3s ease;
    z-index: 201;
}

.menu-panel.active { right: 0; }

.menu-panel h2 {
    font-size: 1rem;
    margin-bottom: 20px;
    color: var(--accent);
}

.menu-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 8px;
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
    transition: background 0.2s;
}

.menu-item:hover { background: var(--bg-hover); }

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 0;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-main);
    padding: 8px 0;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--toggle-off);
    border-radius: 22px;
    cursor: pointer;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

.toggle-switch input:focus-visible + .toggle-slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.branch-btn:focus-visible,
.view-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Canvas area */
.canvas-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    user-select: none;
}

.canvas-container.grabbing { cursor: grabbing; }

.tree-canvas {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    min-width: 100%;
    min-height: 100%;
}

.tree-canvas svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* Zoom slider */
.zoom-slider-container {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 50;
    background: rgba(10, 22, 40, 0.75);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 5px;
    backdrop-filter: blur(6px);
}

.zoom-slider-container input[type="range"] {
    writing-mode: vertical-lr;
    direction: rtl;
    height: 100px;
    width: 3px;
    accent-color: var(--accent);
    cursor: pointer;
    opacity: 0.8;
}

.zoom-slider-container input[type="range"]:hover {
    opacity: 1;
}

.zoom-slider-container input[type="range"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.zoom-slider-value {
    font-size: 0.6rem;
    color: var(--text-dim);
    opacity: 0.8;
}

/* Nodes */
.node {
    position: absolute;
    width: var(--node-width);
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-end) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 14px 14px 34px;
    cursor: pointer;
    z-index: 2;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
    box-shadow: var(--shadow-sm);
}

.node:hover:not(:has(.node-top-marker:hover)):not(:has(.node-bottom-marker:hover)) {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.node-name {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 3px;
    letter-spacing: 0.2px;
}

.node-years {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.node-age {
    font-size: 0.7rem;
    color: var(--accent);
    margin-top: 3px;
    font-weight: 500;
}

.node.male {
    border-left: 3px solid var(--male-color);
}

.node.female {
    border-left: 3px solid var(--female-color);
}

.node.uncertain {
    border: 2px dashed var(--text-dim);
    border-left: 3px dashed var(--male-color);
}

.node.female.uncertain {
    border-left-color: var(--female-color);
}

.node-photo {
    position: absolute;
    left: -10px;
    top: -10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    background: var(--bg-card);
}

.node.male .node-photo {
    border-color: var(--male-color);
}

.node.female .node-photo {
    border-color: var(--female-color);
}

.tooltip-photo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    display: block;
    margin: 0 auto 8px;
}

.modal-photo-section {
    text-align: center;
    padding: 24px 0;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    align-self: stretch;
}

.modal-right-panel {
    width: 200px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    padding-left: 16px;
    margin-left: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.modal-right-panel > hr {
    width: 100%;
    margin-top: 8px;
}

.modal-uncertain-section {
    align-self: stretch;
    padding: 8px 0;
}

.modal-uncertain-section .checkbox-label {
    font-size: 0.85rem;
}

.modal-photo-wrapper {
    position: relative;
    display: inline-block;
}

.modal-photo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.modal-photo-actions {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    align-content: center;
    gap: 4px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.2s;
}

.modal-photo-wrapper:hover .modal-photo-actions {
    opacity: 1;
}

.modal-photo-action {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.modal-photo-action:hover {
    background: #fff;
}

.modal-photo-action.danger:hover {
    background: rgba(192, 57, 43, 0.15);
}

.crop-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.crop-modal.active {
    display: flex;
}

.crop-modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 16px;
    width: 90vw;
    max-width: 500px;
}

.crop-modal-header {
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-main);
}

.crop-container {
    width: 100%;
    max-height: 60vh;
    overflow: hidden;
}

.crop-container img {
    display: block;
    max-width: 100%;
}

.crop-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
}

/* Attachments */
.modal-body-columns {
    display: flex;
    gap: 0;
}

.modal-body-columns #modalFormFields {
    flex: 1;
    min-width: 0;
}

.modal-attachments-panel {
    width: 100%;
    display: flex;
    flex-direction: column;
}

.modal-attachments-panel h3 {
    margin: 0 0 8px 0;
    font-size: 0.95em;
    font-weight: 600;
}

.btn-attachment-add {
    margin-top: 8px;
    font-size: 0.8em;
    padding: 4px 10px;
}

.attachment-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
}

.attachment-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px;
    background: var(--bg-card-end);
    border-radius: var(--radius-sm);
    font-size: 0.8em;
}

.attachment-item a {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--accent);
    text-decoration: none;
}

.attachment-item a:hover {
    text-decoration: underline;
}

.attachment-item .attachment-size {
    color: var(--muted);
    font-size: 0.8em;
    white-space: nowrap;
}

.attachment-item .attachment-delete {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    padding: 0 2px;
    opacity: 0.6;
}

.attachment-item .attachment-delete:hover {
    opacity: 1;
}

.attachment-item.attachment-deleted {
    opacity: 0.4;
}

.attachment-item.attachment-deleted a {
    text-decoration: line-through;
    pointer-events: none;
    color: var(--muted);
}

.attachment-item.attachment-new {
    border-left: 2px solid var(--accent);
}

.attachment-empty {
    color: var(--muted);
    font-size: 0.85em;
}

.modal-attachments-panel.drag-over {
    background: rgba(91, 159, 212, 0.08);
    border-left-style: dashed;
    border-left-color: var(--accent);
}

.photo-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.85);
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.photo-lightbox.active {
    display: flex;
}

.photo-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.node.not-born {
    opacity: 0.25;
}

.node.bloodline {
    box-shadow: inset 0 0 0 2px var(--accent), 0 0 12px rgba(91, 159, 212, 0.4);
}

.node.root-person {
    box-shadow: inset 0 0 0 3px var(--root-color), 0 0 20px rgba(91, 159, 212, 0.5);
    background: linear-gradient(135deg, var(--accent-dim) 0%, var(--accent) 100%);
    color: #ffffff;
}

.node.root-person.uncertain {
    border: 3px dashed var(--root-color);
    box-shadow: 0 0 20px rgba(91, 159, 212, 0.5);
}

.node.root-person .node-years,
.node.root-person .node-age,
.node.root-person .node-deceased-marker {
    color: rgba(255, 255, 255, 0.8);
}

.node.deceased-at-year {
    opacity: 0.6;
}

.node.bloodline.deceased-at-year {
    opacity: 1;
    background: color-mix(in srgb, var(--bg-card) 50%, var(--bg-primary));
    color: color-mix(in srgb, currentColor 50%, var(--bg-primary));
}

.node.root-person.deceased-at-year {
    opacity: 1;
    background: linear-gradient(135deg, var(--accent-dim) 0%, var(--accent) 100%);
    color: #ffffff;
}

.node-deceased-marker {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.node-top-marker {
    position: absolute;
    top: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--bg-secondary);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    cursor: pointer;
    line-height: 1;
    z-index: 2;
}

.node-top-marker:hover {
    background: var(--accent);
    color: #fff;
}

.node-bottom-marker {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--bg-secondary);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    cursor: pointer;
    line-height: 1;
    z-index: 2;
}

.node-bottom-marker:hover,
.node-bottom-marker.partner-hover {
    background: var(--accent);
    color: #fff;
}

/* Relationship modal */
.relationship-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.relationship-modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 440px;
    text-align: center;
}

.relationship-persons {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 16px;
    margin-bottom: 16px;
}

.relationship-person {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex: 1;
}

.relationship-photo {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.relationship-person-name {
    font-size: 0.8rem;
    color: var(--text-dim);
    max-width: 100px;
    text-align: center;
    word-wrap: break-word;
}

.relationship-arrow {
    font-size: 1.2rem;
    color: var(--text-dim);
    flex-shrink: 0;
    height: 56px;
    display: flex;
    align-items: center;
}

.relationship-result {
    font-size: 0.85rem;
    margin-bottom: 16px;
    line-height: 1.5;
}

.relationship-link {
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-thickness: 1px;
    text-decoration-color: #aaa;
    text-underline-offset: 3px;
    cursor: help;
    position: relative;
    transition: color 0.15s;
}

.relationship-link:hover {
    color: var(--accent);
}

.relationship-name-popup {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    box-shadow: 0 2px 8px var(--shadow);
    pointer-events: none;
    z-index: 3000;
}

.relationship-close {
    margin-top: 8px;
}

/* Context menu */
.context-menu {
    display: none;
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 0;
    min-width: 160px;
    z-index: 10000;
    box-shadow: 0 4px 12px var(--shadow);
    user-select: none;
    -webkit-user-select: none;
}

.context-menu.active { display: block; }

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 16px;
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.context-menu-item img {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    opacity: 0.7;
}

:root:not([data-theme="light"]) .context-menu-item img {
    filter: invert(0.85) sepia(0.2) saturate(0.5) hue-rotate(160deg);
}

.context-menu-item:hover { background: var(--bg-hover); }

.context-menu-separator {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 300;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 792px;
    max-width: 90vw;
}

.modal.uncertain {
    border: 2px dashed var(--text-dim);
}

.modal h2 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--accent);
}

.modal-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.modal-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-main);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.85rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(91, 159, 212, 0.15);
}

.modal-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0 0 0;
}

.modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.btn {
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: background 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-dim); }

.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-main);
}

.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover { background: var(--danger-hover); }

/* SVG lines */
.connector-line {
    stroke: var(--accent-dim);
    stroke-width: 2;
    fill: none;
    pointer-events: stroke;
    cursor: pointer;
    opacity: 0.7;
    transition: stroke 0.15s, stroke-width 0.15s, opacity 0.15s;
}

.connector-line:hover {
    stroke: var(--accent);
    stroke-width: 3;
    opacity: 1;
}

.connector-line.partner {
    stroke: var(--accent);
    stroke-width: 1.5;
    stroke-dasharray: 5 4;
    opacity: 0.6;
}

.connector-line.partner:hover {
    stroke-width: 2.5;
    opacity: 1;
}

.connector-line.couple-child {
    stroke: var(--accent);
}

/* Tooltip */
.hover-tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.8rem;
    color: var(--text-main);
    z-index: 9999;
    display: none;
    max-width: 320px;
    line-height: 1.6;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(8px);
}

.hover-tooltip strong {
    font-size: 1rem;
    display: block;
    margin-bottom: 4px;
}

.hover-tooltip .tooltip-section {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

.hover-tooltip .tooltip-label {
    color: var(--text-dim);
}

.tooltip-name {
    line-height: 1.2;
}

.tooltip-gender {
    opacity: 0.6;
}

.tooltip-uncertain {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-bottom: 2px;
}

.tooltip-occupation {
    font-size: 0.75rem;
    line-height: 1.2;
}

.tooltip-hint {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: 6px;
    margin-bottom: 3px;
}

.tooltip-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 6px 0;
}

.tooltip-cousin-row {
    margin-bottom: 4px;
}

.tooltip-notes {
    font-size: 0.8rem;
    white-space: pre-wrap;
}

.tooltip-relationship-link {
    font-size: 0.8rem;
    color: var(--accent);
    cursor: pointer;
    text-align: center;
    padding: 4px 0;
}

.relationship-back {
    font-size: 0.8rem;
    color: var(--accent);
    cursor: pointer;
    text-align: center;
    padding: 4px 0;
    margin-top: 8px;
}

/* Toast */
.toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: var(--bg-card);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 20px;
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 600;
}

.toast.active {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Save overlay */
.save-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

.save-overlay.visible {
    display: flex;
}

.save-overlay-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 36px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-lg);
}

.save-spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--text-dim);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.save-overlay.error .save-spinner { display: none; }

.save-overlay-text {
    font-size: 1rem;
    color: var(--text-main);
}

.save-overlay.error .save-overlay-text {
    color: var(--status-error);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Online counter */
.online-counter {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: 4px;
    cursor: help;
}

.version-banner {
    display: none;
    background: var(--status-warning);
    color: #000;
    padding: 2px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    margin-left: 8px;
}

.version-banner.active {
    display: inline-block;
}

/* History */
.history-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

.history-overlay.active {
    display: flex;
}

.history-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.history-header h2 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-main);
    margin: 0;
}

.history-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0 4px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 20px;
}

.history-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.history-entry-time {
    color: var(--text-main);
}

.history-entry-actions {
    display: flex;
    gap: 6px;
}

.history-entry-actions button {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    font-size: 0.75rem;
    color: var(--text-main);
    cursor: pointer;
}

.history-entry-actions button:hover {
    border-color: var(--accent);
}

.history-diff {
    padding: 12px 20px;
    overflow-y: auto;
    min-height: 120px;
    max-height: 50vh;
    font-size: 0.8rem;
    line-height: 1.5;
    display: none;
    border-top: 1px solid var(--border);
}

.history-diff.active {
    display: block;
}

.diff-added { color: var(--status-success); }
.diff-removed { color: var(--status-error); }
.diff-changed { color: var(--status-warning); }

/* Year slider */
.year-slider-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 4px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.year-slider-container label {
    font-size: 0.75rem;
    color: var(--text-dim);
    white-space: nowrap;
    padding-bottom: 0;
}

.year-slider-wrapper {
    flex: 1;
    position: relative;
    padding-top: 14px;
}

.year-slider-wrapper input[type="range"] {
    width: 100%;
    height: 3px;
    accent-color: var(--accent);
    cursor: pointer;
}

.year-slider-value {
    position: absolute;
    top: 0;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent);
    transform: translateX(-50%);
    pointer-events: none;
}

/* Year picker overlay */
.year-picker-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 400;
    align-items: center;
    justify-content: center;
}

.year-picker-overlay.active {
    display: flex;
}

.year-picker-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    min-width: 160px;
    box-shadow: var(--shadow-lg);
}

.year-picker-display {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--accent);
    user-select: none;
}

.year-picker-btn {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s, background 0.1s;
}

.year-picker-btn:active {
    transform: scale(0.9);
    background: var(--bg-hover);
}

.year-picker-btn:disabled {
    opacity: 0.3;
    pointer-events: none;
}

.year-picker-close {
    background: var(--bg-card);
    color: var(--accent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 32px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.2s;
}

.year-picker-close:active {
    background: var(--bg-hover);
}

/* Help panel */
.help-btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: var(--radius);
    transition: background 0.2s, color 0.2s;
}

.help-btn:hover { background: var(--bg-hover); color: var(--text-main); }

.help-panel {
    display: none;
    position: fixed;
    z-index: 250;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    max-width: 280px;
    box-shadow: 0 8px 24px var(--shadow);
    font-size: 0.8rem;
    line-height: 1.8;
    box-sizing: border-box;
}

.help-panel.active { display: block; }

.help-panel h3 {
    font-size: 0.9rem;
    color: var(--accent);
    margin-bottom: 8px;
}

.help-panel .help-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.help-panel .help-key {
    color: var(--text-dim);
    white-space: nowrap;
}

.help-panel .help-val {
    text-align: right;
    color: var(--text-main);
}

/* Checkbox group */
.form-group-checkbox label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
}

.form-group-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

/* Deceased row */
.deceased-row {
    display: flex;
    align-items: center;
    gap: 12px;
    align-self: flex-end;
}

.deceased-row label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    white-space: nowrap;
}

.deceased-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.deceased-row .date-fields {
    flex: 1;
}

.deceased-row .date-fields input:disabled {
    opacity: 0.3;
}

/* Date fields */
.date-fields {
    display: flex;
    gap: 6px;
}

.date-fields input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.9rem;
    text-align: center;
}

.date-fields input:first-child { flex: 2; }
.date-fields input:nth-child(2),
.date-fields input:nth-child(3) { flex: 1; }

.date-fields input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Bottom sheet */
.bottom-sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 9998;
}

.bottom-sheet-overlay.active {
    display: block;
}

.bottom-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 80vh;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    z-index: 9999;
    transform: translateY(100%);
    transition: transform 0.3s ease, visibility 0s 0.3s;
    visibility: hidden;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.bottom-sheet.active {
    transform: translateY(0);
    visibility: visible;
    transition: transform 0.3s ease, visibility 0s;
}

.bottom-sheet::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: linear-gradient(transparent, var(--bg-secondary));
    pointer-events: none;
    z-index: 1;
    transition: opacity 0.2s;
}

.bottom-sheet.scroll-end::after {
    opacity: 0;
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--text-dim);
    border-radius: 2px;
    margin: 10px auto 6px;
    opacity: 0.5;
}

.bottom-sheet-edit {
    position: absolute;
    top: 10px;
    right: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 12px;
    cursor: pointer;
}

.bottom-sheet-edit:active {
    background: var(--bg-hover);
}

.bottom-sheet-content {
    padding: 0 20px 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-main);
}

.bottom-sheet-content strong {
    font-size: 1rem;
    display: block;
    margin-bottom: 4px;
}

.bottom-sheet-content .tooltip-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.bottom-sheet-content .tooltip-label {
    color: var(--text-dim);
}

.bottom-sheet-content .tooltip-photo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    display: block;
    margin: 0 auto 8px;
}

.bottom-sheet-content .relationship-persons {
    gap: 12px;
    margin-bottom: 12px;
}

.bottom-sheet-content .relationship-photo {
    width: 48px;
    height: 48px;
}

.bottom-sheet-content .relationship-person-name {
    font-size: 0.75rem;
    max-width: 80px;
}

.bottom-sheet-content .relationship-arrow {
    font-size: 1rem;
    margin-top: 14px;
}

.bottom-sheet-content .relationship-result {
    font-size: 0.85rem;
    margin-bottom: 8px;
    text-align: center;
}

.bottom-sheet-content .relationship-persons {
    justify-content: center;
}

/* Header toggle — hidden on desktop */
.header-toggle {
    display: none;
}

.collapsed-year-badge {
    display: none;
}

.menu-branch-group {
    display: none;
}

.menu-view-group {
    display: none;
}

/* Mobile */
@media (max-width: 768px), (max-width: 1024px) and (max-height: 500px) {
    .node-top-marker {
        font-size: 1rem;
        padding: 6px 12px;
        top: -14px;
    }

    .node-bottom-marker {
        font-size: 1rem;
        padding: 6px 12px;
        bottom: -14px;
    }

    .header-toggle {
        display: block;
        position: relative;
        left: 50%;
        transform: translateX(-50%);
        z-index: 199;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-top: none;
        border-radius: 0 0 8px 8px;
        padding: 2px 16px;
        font-size: 0.7rem;
        cursor: pointer;
        color: var(--text-main);
        line-height: 1;
        width: fit-content;
        box-shadow: 0 2px 4px var(--shadow);
    }

    body.header-collapsed .header,
    body.header-collapsed .year-slider-container {
        display: none !important;
    }

    body.header-collapsed .header-toggle {
        position: fixed;
        top: 0;
        background: var(--accent);
        color: #fff;
        border: none;
    }

    body.header-collapsed .collapsed-year-badge {
        display: block;
        position: fixed;
        top: 6px;
        right: 10px;
        z-index: 199;
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-dim);
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 2px 8px;
        pointer-events: none;
    }

    .header {
        padding: 6px 10px;
        gap: 6px;
    }

    .header h1 { display: none; }
    .header-logo { width: 20px; height: 20px; }

    .header-controls {
        gap: 6px;
    }

    .branch-group,
    .view-group {
        display: none;
    }

    .root-select {
        display: block;
        font-size: 0.75rem;
        padding: 4px 8px;
        max-width: 140px;
    }

    .root-search,
    .root-search-list,
    .root-label {
        display: none !important;
    }

    .back-btn {
        font-size: 0.9rem;
        padding: 4px 8px;
    }

    .home-btn {
        font-size: 0.9rem;
        padding: 4px 8px;
    }

    .zoom-slider-container { display: none !important; }

    .year-slider-container {
        padding: 3px 24px;
        touch-action: none;
        align-items: center;
    }

    .year-slider-wrapper {
        display: flex;
        align-items: center;
        gap: 10px;
        padding-top: 0;
    }

    .year-slider-wrapper input[type="range"] {
        height: 28px;
        flex: 1;
    }

    .year-slider-value {
        position: static;
        transform: none;
        font-size: 0.8rem;
        white-space: nowrap;
        order: 1;
        pointer-events: auto;
        border: 1px solid var(--accent);
        border-radius: var(--radius-sm);
        padding: 4px 8px;
        line-height: 1;
        cursor: pointer;
    }

    .year-slider-container label {
        font-size: 0.7rem;
        padding-bottom: 0;
    }

    .hover-tooltip { display: none !important; }

    .context-menu {
        min-width: 200px;
    }

    .context-menu-item {
        padding: 12px 20px;
        font-size: 0.9rem;
    }

    .context-menu-item img {
        width: 36px;
        height: 36px;
    }

    .modal-overlay.active {
        align-items: stretch;
    }

    .modal {
        width: 100%;
        max-width: 100%;
        height: 100%;
        border-radius: 0;
        padding: 16px;
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    .modal.uncertain {
        border: none;
        border-top: 4px dashed var(--text-dim);
    }

    .modal-body-columns {
        flex-direction: column;
    }

    .modal-right-panel {
        width: 100%;
        border-left: none;
        padding-left: 0;
        margin-left: 0;
        margin-top: 16px;
        padding-top: 16px;
        border-top: 1px solid var(--border);
    }

    .modal-row {
        flex-direction: column;
        gap: 0;
    }

    .modal-row .form-group {
        margin-bottom: 12px;
    }

    .deceased-row {
        flex-direction: column;
        align-items: flex-start;
        align-self: stretch;
        gap: 8px;
    }

    .modal-row .form-group[style*="flex"] {
        flex: 1 1 auto !important;
    }

    .modal-right-panel {
        display: contents;
    }

    .modal-photo-section {
        order: -2;
    }

    .modal-attachments-panel {
        order: 99;
    }

    .modal-uncertain-section {
        order: -1;
        flex: none;
        display: block;
        padding: 8px 0 12px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 0;
    }

    .modal-right-panel > hr.modal-divider {
        display: none;
    }

    textarea#inputNotes {
        min-height: 120px;
    }

    .modal-buttons {
        margin-top: auto;
        padding-top: 12px;
    }

    .existing-person-desktop { display: none !important; }
    .existing-person-mobile-label { display: block; }
    .existing-person-mobile { display: block; }
    .person-select-search { display: none !important; }
    .person-select-wrapper .existing-person-list { display: none !important; }
    .person-select-mobile { display: block; }

    .menu-panel {
        width: 260px;
    }

    .theme-toggle {
        font-size: 0.8rem;
    }

    .scroll-zoom-toggle {
        display: none;
    }

    .menu-desktop-only {
        display: none !important;
    }

    .menu-branch-group {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
    }

    .menu-branch-label {
        font-size: 0.8rem;
        color: var(--text-dim);
    }

    .menu-branch-btn {
        flex: 1;
        padding: 8px 0;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--bg-card);
        color: var(--text-main);
        font-size: 0.85rem;
        cursor: pointer;
    }

    .menu-branch-btn.active {
        background: var(--accent);
        color: white;
        border-color: var(--accent);
    }

    .menu-branch-btn:disabled {
        opacity: 0.4;
        cursor: default;
    }

    .menu-view-group {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px 12px;
    }

    .menu-view-btn {
        flex: 1;
        padding: 8px 0;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--bg-card);
        color: var(--text-main);
        font-size: 0.85rem;
        cursor: pointer;
    }

    .menu-view-btn.active {
        background: var(--accent);
        color: white;
        border-color: var(--accent);
    }

    .uncertain-entry-name {
        cursor: default;
    }

    .uncertain-btn-hint {
        display: inline-block !important;
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 3px 7px;
        font-size: 0.75rem;
        cursor: pointer;
        line-height: 1;
        font-weight: 600;
        color: var(--text-dim);
    }

    .uncertain-entry-actions {
        margin-left: auto;
    }

    .uncertain-entry-reason {
        display: none;
    }
}

/* Uncertain list panel */
.uncertain-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
}

.uncertain-overlay.active {
    display: flex;
}

.uncertain-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.uncertain-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.uncertain-header h2 {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-main);
    margin: 0;
}

.uncertain-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0 4px;
}

.uncertain-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 20px;
}

.uncertain-entry {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.uncertain-entry:hover {
    color: var(--accent);
}

.uncertain-entry:last-child {
    border-bottom: none;
}

.uncertain-entry-name {
    font-size: 0.85rem;
    color: var(--text-main);
    white-space: nowrap;
    flex-shrink: 0;
}

.uncertain-entry-hint {
    display: none;
}

.uncertain-btn-hint {
    display: none;
}

.uncertain-entry:hover .uncertain-entry-name {
    color: var(--accent);
}

.uncertain-entry-reason {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-left: auto;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.uncertain-entry-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.uncertain-btn-find,
.uncertain-btn-edit {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 7px;
    font-size: 0.75rem;
    cursor: pointer;
    line-height: 1;
}

.uncertain-btn-find:hover,
.uncertain-btn-edit:hover {
    border-color: var(--accent);
}

.uncertain-empty {
    padding: 20px 0;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.uncertain-reason-tooltip {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--accent-dim);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.8rem;
    color: var(--text-main);
    z-index: 10000;
    max-width: 260px;
    line-height: 1.4;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 0.15s;
}

.uncertain-reason-tooltip.visible {
    opacity: 1;
}
