/* ============================================================================
   INFINITE CANVAS FAMILY TREE VIEWER - STYLES
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-image: url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

/* ============================================================================
   MAIN CONTAINER
   ============================================================================ */

#canvas-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: transparent;
    transform-origin: center center;
    transition: opacity 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), filter 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
}

#canvas-container.layer-fade-out {
    opacity: 0.05;
    filter: blur(8px) saturate(0.35);
    transform: scale(0.985);
}

#main-svg {
    width: 100%;
    height: 100%;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

#main-svg * {
    user-select: none;
    -webkit-user-select: none;
}

#main-svg.dragging {
    cursor: grabbing;
}

body.dragging-ui {
    cursor: grabbing;
}

.drag-shield {
    position: fixed;
    inset: 0;
    z-index: 13000;
    background: transparent;
    cursor: grabbing;
}

/* ============================================================================
   CONTROLS PANEL
   ============================================================================ */

#controls-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 1110;
    width: 280px;
    min-width: 280px;
    height: auto;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#controls-panel .controls-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid #6b6f7a;
    padding-bottom: 8px;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}

#controls-panel .controls-title-row:active {
    cursor: grabbing;
}

#controls-panel .controls-title-text {
    flex: 1;
    min-width: 0;
}

#controls-panel .controls-title-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#controls-panel .controls-title-actions button {
    cursor: pointer;
}

#controls-panel h3 {
    color: #e0e6ed;
    margin-bottom: 0;
    font-size: 16px;
    border-bottom: none;
    padding-bottom: 0;
}

#tree-home-btn {
    background: #4a90e2;
    flex: 1;
    padding: 7px 10px;
    font-size: 12px;
    min-width: 0;
}

#print-view-btn {
    flex: 1;
    padding: 7px 10px;
    font-size: 12px;
    min-width: 0;
}

#controls-panel-toggle-btn {
    flex: 0 0 auto;
    padding: 6px 10px;
    font-size: 11px;
    min-width: 70px;
    margin: 0;
}

#controls-panel.collapsed {
    max-height: none;
    padding: 12px;
}

#controls-panel.collapsed .controls-title-row {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

#controls-panel.collapsed .control-group {
    display: none;
}

#controls-panel .control-group:last-child .control-buttons {
    flex-wrap: nowrap;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

#controls-panel .control-group:last-child .control-buttons button {
    font-size: 13px;
    padding: 8px 10px;
    width: 100%;
}

#controls-panel .control-group:last-child {
    margin-top: auto;
    margin-bottom: 0;
}

#admin-tools-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    left: auto;
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 1100;
    width: 280px;
    min-width: 280px;
    max-width: 280px;
    height: auto;
    max-height: calc(100vh - 40px);
    display: none;
    flex-direction: column;
    overflow: hidden;
}

#admin-tools-panel.visible,
#admin-tools-panel.active {
    display: flex;
}

#admin-tools-panel .admin-tools-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
    border-bottom: 1px solid #6b6f7a;
    padding-bottom: 8px;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}

#admin-tools-panel .admin-tools-title-row:active {
    cursor: grabbing;
}

#admin-tools-panel .admin-tools-title-text {
    flex: 1;
    min-width: 0;
}

#admin-tools-panel .admin-tools-title-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#admin-tools-panel .admin-tools-title-actions button {
    cursor: pointer;
}

#admin-tools-toggle-btn {
    flex: 0 0 auto;
    padding: 6px 10px;
    font-size: 11px;
    min-width: 70px;
    margin: 0;
}

#admin-tools-panel h3 {
    color: #e0e6ed;
    margin-bottom: 0;
    font-size: 16px;
}

#admin-tools-panel.collapsed {
    max-height: none;
    padding: 12px;
}

#admin-tools-panel.collapsed .admin-tools-title-row {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

#admin-tools-panel.collapsed .control-group {
    display: none;
}

#admin-tools-panel .control-buttons button {
    width: auto;
    flex: 1;
}

.admin-tools-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.admin-tools-buttons button {
    width: 66% !important;
    flex: none !important;
    margin: 0;
    margin-left: auto;
    margin-right: auto;
}

#admin-tools-panel #toggle-grid-btn {
    width: 66% !important;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

#admin-tools-panel .control-group {
    margin-bottom: 18px;
}

#admin-tools-panel .admin-lock-row {
    min-height: 28px;
    gap: 8px;
}

#admin-tools-panel .admin-layer-sync-status {
    margin-top: 8px;
    font-size: 11px;
    line-height: 1.35;
    color: #b0b6bd;
    min-height: 16px;
}

#admin-tools-panel .admin-lock-row .switch {
    transform: scale(0.92);
    transform-origin: left center;
}

#admin-tools-panel #admin-layer-lock-status {
    white-space: nowrap;
    font-weight: 600;
}

#admin-tools-panel .control-group:last-child {
    margin-top: auto;
    margin-bottom: 0;
}

#admin-tools-panel:not(.collapsed) {
    overflow-y: auto;
}

#admin-tools-panel .admin-tools-tools-group {
    border-top: 1px solid #6b6f7a;
    padding-top: 12px;
}

#wiring-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    min-width: 320px;
    max-width: 440px;
    max-height: calc(100vh - 40px);
    overflow: auto;
    display: none;
}

#wiring-panel.active {
    display: block;
}

#wiring-panel h3 {
    color: #e0e6ed;
    margin-bottom: 0;
    font-size: 16px;
}

.wiring-panel-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 12px;
    border-bottom: 1px solid #6b6f7a;
    padding-bottom: 8px;
    padding-right: 40px;
    cursor: default;
    user-select: none;
    position: relative;
}

#wiring-panel-header {
    cursor: move;
}

#wiring-close-btn {
    top: -6px;
    right: 8px;
}

#wiring-panel select,
#wiring-panel input,
#wiring-panel button:not(.close-btn) {
    width: 100%;
}

#admin-layer-switch {
    width: 100%;
    padding: 7px 8px;
    background: #1a1d24;
    border: 1px solid #44474e;
    border-radius: 4px;
    color: #e0e6ed;
    font-size: 12px;
}

#wiring-panel .control-buttons button {
    width: auto;
    flex: 1;
}

.wiring-points {
    color: #e0e6ed;
    font-size: 12px;
    line-height: 1.6;
    background: rgba(31, 34, 39, 0.75);
    border: 1px solid #6b6f7a;
    border-radius: 6px;
    padding: 10px;
}

#wiring-status {
    margin-top: 8px;
    font-size: 12px;
    color: #b0b6bd;
}

.wiring-list-wrap {
    margin-top: 10px;
}

#wiring-lines-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.52);
    z-index: 1250;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

#wiring-lines-modal .wiring-lines-modal-content {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(920px, 96vw);
    max-height: min(82vh, 900px);
    overflow: auto;
    background: rgba(68, 71, 78, 0.98);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

#wiring-lines-modal-header {
    cursor: move;
}

#wiring-lines-modal #wiring-lines-close-btn {
    top: -6px;
    right: 8px;
}

#add-data-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    width: min(760px, calc(100vw - 40px));
    height: calc(100vh - 40px);
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 1200;
    display: none;
    overflow: hidden;
}

#placements-panel {
    position: absolute;
    top: 20px;
    left: 20px;
    width: min(440px, calc(100vw - 40px));
    height: calc(100vh - 40px);
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 1200;
    display: none;
    overflow: hidden;
}

#image-upload-panel {
    position: absolute;
    top: 26px;
    left: 56px;
    width: min(860px, calc(100vw - 80px));
    height: min(540px, calc(100vh - 90px));
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    z-index: 1210;
    display: none;
    overflow: hidden;
}

#placements-panel.active {
    display: block;
}

#image-upload-panel.active {
    display: block;
}

#add-data-panel.active {
    display: block;
}

.floating-panel-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    border-bottom: 1px solid #6b6f7a;
    padding: 10px 44px 10px 14px;
    cursor: move;
    user-select: none;
    position: relative;
}

.floating-panel-header h3 {
    color: #e0e6ed;
    font-size: 16px;
    margin: 0;
}

.floating-panel-content {
    height: calc(100% - 46px);
    width: 100%;
    background: transparent;
}

#add-data-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
}

#placements-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
}

#image-upload-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
}

#add-data-close-btn {
    top: 10px;
    right: 12px;
}

#placements-close-btn {
    top: 4px;
    right: 10px;
}

#image-upload-close-btn {
    top: 4px;
    right: 10px;
    background: #ff4d4f;
    color: #ffffff;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 18px;
}

#wiring-lines-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

#wiring-lines-table th,
#wiring-lines-table td {
    border-bottom: 1px solid #4a4f5a;
    padding: 6px;
    text-align: left;
    color: #e0e6ed;
}

#wiring-lines-table th {
    color: #b0b6bd;
    font-weight: 600;
}

#wiring-lines-table input[type="checkbox"] {
    width: auto;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    color: #e0e6ed;
    margin-bottom: 5px;
    font-size: 13px;
}

.control-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.grid-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.grid-color-hint {
    margin-top: 8px;
    color: #b0b6bd;
    font-size: 11px;
    display: flex;
    gap: 12px;
}

.grid-color-hint span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    top: 4px;
}

.dot {
    width: 9px;
    top: 4px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.dot-grey {
    background: #888888;
}

.dot-blue {
    background: #4a90e2;
}

.grid-label {
    color: #e0e6ed;
    font-size: 12px;
    min-width: 46px;
    text-align: center;
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #6b6f7a;
    transition: 0.2s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    transition: 0.2s;
    border-radius: 50%;
}

.switch input:checked + .slider {
    background-color: #4a90e2;
}

.switch input:checked + .slider:before {
    transform: translateX(24px);
}

button {
    background: #4a90e2;
    color: #ffffff;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s, transform 0.08s, box-shadow 0.2s;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), 0 4px 10px rgba(0, 0, 0, 0.2);
}

button:hover {
    background: #357abd;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 6px 12px rgba(0, 0, 0, 0.22);
}

button:active {
    background: #2868a8;
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.18);
}

.close-btn {
    box-shadow: none !important;
}

button.secondary {
    background: #6b6f7a;
}

button.secondary:hover {
    background: #5a5d68;
}

#search-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #6b6f7a;
    border-radius: 4px;
    background: #2a2d35;
    color: #e0e6ed;
    font-size: 13px;
}

#search-input:focus {
    outline: none;
    border-color: #4a90e2;
}

#relationship-from-input,
#relationship-to-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #c7ced8;
    border-radius: 4px;
    background: #ffffff;
    color: #1f2937;
    font-size: 13px;
}

#relationship-from-input::placeholder,
#relationship-to-input::placeholder {
    color: #6b7280;
}

#relationship-to-input {
    margin-top: 6px;
}

#relationship-from-input:focus,
#relationship-to-input:focus {
    outline: none;
    border-color: #4a90e2;
}

#relationship-finder-group .relationship-actions {
    margin-top: 8px;
}

#relationship-finder-group .relationship-actions button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

#relationship-status {
    margin-top: 8px;
    font-size: 12px;
    color: var(--viewer-panel-text, #e0e6ed);
}

#relationship-result {
    margin-top: 8px;
    max-height: 150px;
    overflow: auto;
    background: rgba(31, 34, 39, 0.75);
    border: 1px solid #6b6f7a;
    border-radius: 6px;
    padding: 8px;
    color: #e0e6ed;
    font-size: 12px;
    line-height: 1.45;
}

#relationship-result:empty {
    display: none;
}

.relationship-summary {
    font-weight: 600;
    color: #e0e6ed;
}

.relationship-scope-note {
    margin-top: 4px;
    font-size: 11px;
    color: #9ec5ff;
}

.relationship-path-list {
    margin: 8px 0 0 18px;
}

.relationship-path-step {
    margin: 0 0 6px 0;
}

.relationship-focus-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.relationship-focus-actions button {
    flex: 1;
}

.relationship-candidates {
    margin-top: 6px;
    padding-left: 18px;
}

.relationship-candidates li {
    margin-bottom: 4px;
}

#story-route-group,
#story-route-labels-group {
    pointer-events: none;
}

.story-route-segment-complete {
    fill: none;
    stroke: rgba(107, 111, 122, 0.46);
    stroke-width: 16;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: none;
    vector-effect: non-scaling-stroke;
}

.story-route-segment-progress {
    fill: none;
    stroke: rgba(107, 111, 122, 0.72);
    stroke-width: 22;
    stroke-linecap: butt;
    stroke-linejoin: round;
    stroke-dasharray: none;
    vector-effect: non-scaling-stroke;
}

.story-route-arrowhead {
    fill: rgba(107, 111, 122, 0.78);
    stroke: rgba(107, 111, 122, 0.78);
    stroke-width: 1.6;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 0 1px rgba(42, 45, 53, 0.22));
}

.story-route-node {
    fill: rgba(43, 129, 219, 0.12);
    stroke: rgba(255, 255, 255, 0.75);
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.story-route-node.reached {
    fill: rgba(69, 158, 247, 0.35);
    stroke: rgba(220, 238, 255, 0.95);
}

.story-route-node.reached.active {
    fill: rgba(255, 204, 77, 0.42);
    stroke: rgba(255, 236, 168, 1);
    stroke-width: 2.6;
}

.story-route-label-bg {
    fill: #8d919b;
    stroke: #757984;
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
}

.story-route-label-text {
    fill: #ffffff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    paint-order: normal;
    stroke: none;
}

.story-route-label.active .story-route-label-text {
    fill: #ffffff;
}

.story-route-label.active .story-route-label-bg {
    fill: #838791;
    stroke: #6c707b;
}

#zoom-display {
    color: #e0e6ed;
    font-size: 13px;
    text-align: center;
    padding: 5px;
    background: #2a2d35;
    border-radius: 4px;
    margin-top: 5px;
}

/* ============================================================================
   GRID ELEMENTS
   ============================================================================ */

.rectangle {
    fill: none;
    stroke: #d0d0d0;
    stroke-width: 0.5;
    opacity: 0;
}

.rectangle.admin-view {
    opacity: 1;
}

.rectangle[data-grid-type="offset"] {
    stroke: #4a90e2;
    stroke-width: 1;
}

.rectangle-label {
    font-size: 18px;
    fill: #888888;
    opacity: 0;
    pointer-events: none;
    font-weight: 600;
    paint-order: stroke;
    stroke: #ffffff;
    stroke-width: 2px;
    stroke-linejoin: round;
    dominant-baseline: hanging;
}

.rectangle-label.admin-view {
    opacity: 1;
}

.rectangle-label[data-grid-type="offset"] {
    fill: #4a90e2;
}

.center-axis-line {
    opacity: 0;
    pointer-events: none;
}

.center-axis-line.admin-view {
    opacity: 0.6;
}

.node {
    fill: #888888;
    stroke: #ffffff;
    stroke-width: 2;
    opacity: 0;
    pointer-events: none;
}

.node.admin-view {
    opacity: 1;
    pointer-events: auto;
}

.node.wiring-selected {
    fill: #f6e05e;
    stroke: #fefcbf;
    stroke-width: 3;
}

.node[data-grid-type="offset"] {
    fill: #4a90e2;
}

.cell-node {
    fill: #b37d52;
    stroke: #fff7e6;
    stroke-width: 2;
}

.cell-node.admin-view {
    opacity: 1;
    pointer-events: auto;
}

.node-label {
    font-size: 10px;
    fill: #666666;
    opacity: 0;
    pointer-events: none;
    font-weight: 600;
}

.node-label.admin-view {
    opacity: 1;
}

.node-label[data-grid-type="offset"] {
    fill: #3e7cc7;
}

/* ============================================================================
   FAMILY CELLS
   ============================================================================ */

.family-cell {
    transition: opacity 0.2s;
}

.family-cell:hover {
    opacity: 1;
}

.cell-background {
    fill: rgba(255, 255, 255, 0.08);
    stroke: rgba(255, 255, 255, 0.72);
    stroke-width: 1.2;
    rx: 5;
    ry: 5;
    transition: fill 0.2s ease, stroke 0.2s ease;
}

.family-cell:hover .cell-background {
    fill: rgba(255, 255, 255, 0.12);
    stroke: rgba(255, 255, 255, 0.82);
}

.cell-background.highlighted {
    fill: #4a90e2;
    stroke: #ffd700;
    stroke-width: 3;
    animation: cellGlow 2s ease-out forwards;
}

@keyframes cellGlow {
    0% {
        filter: drop-shadow(0 0 10px #ffd700);
    }
    50% {
        filter: drop-shadow(0 0 20px #ffd700);
    }
    100% {
        fill: rgba(255, 255, 255, 0.08);
        stroke: rgba(255, 255, 255, 0.72);
        stroke-width: 1.2;
        filter: drop-shadow(0 0 0 transparent);
    }
}

.cell-name {
    font-size: 24px;
    fill: #6b3818;
    font-weight: 600;
    text-anchor: middle;
    pointer-events: none;
}

.cell-dates {
    font-size: 15px;
    fill: #6b3818;
    text-anchor: middle;
    pointer-events: none;
}

.cell-uid {
    font-size: 11px;
    fill: #74401d;
    text-anchor: middle;
    pointer-events: none;
}

.cell-icon-group {
    transition: opacity 0.2s;
}

.cell-icon-group:hover {
    opacity: 0.8;
}

.cell-icon-group circle {
    transition: all 0.2s;
}

.cell-icon-group:hover circle {
    filter: brightness(1.2);
}

.cell-hover-preview {
    position: fixed;
    width: 210px;
    display: none;
    pointer-events: none;
    z-index: 950;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--viewer-panel-border);
    background: var(--viewer-panel-bg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.32);
}

.cell-hover-preview.visible {
    display: block;
}

.cell-hover-preview-image {
    display: none;
    width: 100%;
    height: 138px;
    object-fit: cover;
    background: var(--viewer-canvas-bg);
}

.cell-hover-preview-caption {
    color: var(--viewer-panel-text);
    font-size: 12px;
    line-height: 1.35;
    padding: 8px 10px;
    text-align: center;
}

.lineage-overlay {
    position: fixed;
    inset: 0;
    display: none;
    justify-content: center;
    align-items: flex-start;
    padding: 22px;
    background: rgba(0, 0, 0, 0.56);
    z-index: 2200;
}

.lineage-overlay.active {
    display: flex;
}

.lineage-overlay-panel {
    width: min(1040px, 96vw);
    max-height: calc(100vh - 44px);
    border: 1px solid var(--viewer-panel-border);
    border-radius: 12px;
    background:
        linear-gradient(rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
        var(--viewer-panel-bg);
    color: var(--viewer-panel-text);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lineage-overlay-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--viewer-panel-border);
}

.lineage-overlay-header h3 {
    margin: 0;
    color: var(--viewer-panel-heading);
    font-size: 18px;
    font-weight: 700;
}

.lineage-overlay-close {
    background: var(--viewer-modal-close-bg, #c93e3e);
    color: var(--viewer-modal-close-text, #ffffff);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}

.lineage-overlay-close:hover {
    opacity: 0.82;
}

.lineage-overlay-status {
    margin-top: 4px;
    font-size: 12px;
    color: var(--viewer-panel-muted);
}

.lineage-overlay-status.success {
    color: var(--viewer-panel-heading);
}

.lineage-overlay-status.error {
    color: var(--viewer-modal-close-bg, #ffb4b4);
}

.lineage-overlay-content {
    padding: 14px 16px 16px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.lineage-overlay-loading,
.lineage-overlay-empty {
    border: 1px solid var(--viewer-panel-border);
    border-radius: 8px;
    padding: 12px;
    color: var(--viewer-panel-text);
    background: rgba(0, 0, 0, 0.16);
}

.lineage-branches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
}

.lineage-branch {
    border: 1px solid var(--viewer-panel-border);
    border-radius: 10px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.16);
}

.lineage-branch[data-branch='paternal'] {
    border-left: 4px solid var(--viewer-btn-primary);
}

.lineage-branch[data-branch='maternal'] {
    border-left: 4px solid var(--viewer-btn-secondary);
}

.lineage-branch h4 {
    margin: 0;
    font-size: 15px;
    color: var(--viewer-panel-heading);
}

.lineage-branch-meta {
    margin-top: 4px;
    font-size: 12px;
    color: var(--viewer-panel-muted);
}

.lineage-rows {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lineage-row {
    border: 1px dashed var(--viewer-panel-border);
    border-radius: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.12);
}

.lineage-row-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.lineage-row-generation {
    color: var(--viewer-panel-heading);
    font-weight: 700;
    font-size: 13px;
}

.lineage-row-template {
    color: var(--viewer-panel-muted);
    font-size: 12px;
}

.lineage-row-empty {
    border: 1px dashed var(--viewer-panel-border);
    border-radius: 8px;
    padding: 9px;
    font-size: 12px;
    color: var(--viewer-panel-muted);
}

.lineage-people-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 8px;
}

.lineage-person-card {
    border: 1px solid var(--viewer-panel-border);
    border-radius: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.18);
}

.lineage-person-name {
    color: var(--viewer-panel-heading);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.25;
}

.lineage-person-uid {
    margin-top: 2px;
    color: var(--viewer-panel-muted);
    font-size: 11px;
    letter-spacing: 0.02em;
}

.lineage-person-life {
    margin-top: 6px;
    font-size: 12px;
    color: var(--viewer-panel-text);
}

.lineage-person-life-muted {
    color: var(--viewer-panel-muted);
}

.lineage-warnings {
    border: 1px solid var(--viewer-modal-close-bg, #c93e3e);
    border-radius: 8px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.18);
}

.lineage-warnings h4 {
    margin: 0 0 6px;
    color: var(--viewer-panel-heading);
    font-size: 14px;
}

.lineage-warnings ul {
    margin: 0;
    padding-left: 18px;
    display: grid;
    gap: 5px;
    color: var(--viewer-panel-text);
    font-size: 12px;
}

.lineage-generated-at {
    color: var(--viewer-panel-muted);
    font-size: 11px;
    text-align: right;
}

body.print-review-mode .lineage-overlay {
    display: none !important;
}

/* ============================================================================
   CONNECTION LINES
   ============================================================================ */

.connection-line {
    fill: none;
    stroke: #6b6f7a;
    stroke-width: 2;
    pointer-events: none;
}

.connection-line.spouse {
    stroke: #4a90e2;
}

.connection-line.parent-child {
    stroke: #6b6f7a;
}

.connection-line.sibling {
    stroke: #8a8e95;
    stroke-dasharray: 5, 3;
}

.wiring-line {
    fill: none;
    stroke: #ffffff;
    stroke-width: 3;
    stroke-linecap: round;
    pointer-events: stroke;
}

.wiring-line.wiring-kind-single-horizontal,
.wiring-line.wiring-kind-vertical,
.wiring-line.wiring-kind-cell-top-vertical {
    stroke-width: 6;
}

.wiring-line.selected {
    stroke: #f6e05e;
    stroke-width: 4;
}

.wiring-line.wiring-kind-single-horizontal.selected,
.wiring-line.wiring-kind-vertical.selected,
.wiring-line.wiring-kind-cell-top-vertical.selected {
    stroke-width: 7;
}

.wiring-marker-circle {
    fill: rgba(31, 34, 39, 0.95);
    stroke: #ffffff;
    stroke-width: 2;
}

.wiring-marker-text {
    fill: #ffffff;
    font-size: 12px;
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}

/* ============================================================================
   INFO PANEL
   ============================================================================ */

#info-panel {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    padding: 12px;
    color: #e0e6ed;
    font-size: 12px;
    z-index: 1000;
    max-width: 300px;
}

#info-panel .info-row {
    margin: 4px 0;
}

#info-panel .info-label {
    color: #b0b6bd;
    font-weight: 600;
}

/* ============================================================================
   LOADING OVERLAY
   ============================================================================ */

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#loading-overlay .spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #6b6f7a;
    border-top-color: #4a90e2;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-overlay.hidden {
    display: none;
}

/* ============================================================================
   LAYER INDICATOR
   ============================================================================ */

#layer-indicator {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(68, 71, 78, 0.95);
    border: 2px solid #6b6f7a;
    border-radius: 8px;
    padding: 10px 15px;
    color: #e0e6ed;
    font-size: 14px;
    font-weight: 600;
    z-index: 1000;
}

/* ============================================================================
   MODALS
   ============================================================================ */

#printModal .print-modal-content {
    width: min(1400px, 96vw);
    max-width: min(1400px, 96vw);
    max-height: min(90vh, 940px);
    overflow: auto;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.26), rgba(68, 71, 78, 0.26)),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    padding: 14px 10px 12px;
}

#printModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 0 !important;
}

#printModal #closePrintModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

#printViewContent {
    padding: 8px 0 0;
}

.print-view-shell {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.print-toolbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.print-orientation-toggle {
    display: flex;
    gap: 8px;
}

.print-summary {
    color: #6f3b19;
    font-size: 12px;
}

.print-fit-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    color: #5f3c22;
    font-size: 12px;
}

.print-mode-row {
    display: flex;
    gap: 8px;
}

.print-mode-row button {
    min-width: 130px;
}

.print-fit-row label {
    font-weight: 600;
}

#print-fit-slider {
    width: 100%;
}

#print-fit-value {
    min-width: 44px;
    text-align: right;
    color: #2e4a8c;
    font-weight: 700;
}

.active-print-option {
    outline: 2px solid #d6aa78;
    background: #4a90e2 !important;
    color: #ffffff;
}

.print-preview-wrap {
    border: 1px solid rgba(214, 170, 120, 0.36);
    border-radius: 8px;
    background: rgba(255, 249, 240, 0.76);
    overflow: hidden;
}

.print-preview-svg {
    width: 100%;
    height: 560px;
    display: block;
}

.print-preview-bg {
    fill: rgba(255, 255, 255, 0.95);
}

.print-preview-line {
    stroke: #121212;
    fill: none;
    stroke-width: 1.4;
    stroke-linecap: round;
}

.print-preview-line.thick {
    stroke-width: 2;
}

.print-preview-marker-circle {
    fill: #ffffff;
    stroke: #111111;
    stroke-width: 1.2;
}

.print-preview-marker-text {
    fill: #111111;
    font-size: 8.5px;
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: middle;
}

.print-preview-cell {
    fill: #ffffff;
    stroke: #121212;
    stroke-width: 1;
}

.print-preview-name {
    fill: #111111;
    font-size: 9px;
    font-weight: 600;
    text-anchor: middle;
}

.print-preview-date {
    fill: #111111;
    font-size: 7.8px;
    text-anchor: middle;
}

.print-preview-page {
    fill: rgba(113, 142, 255, 0.08);
    stroke: rgba(45, 78, 215, 0.72);
    stroke-width: 1;
    cursor: pointer;
}

.print-preview-page.manual {
    fill: rgba(56, 111, 224, 0.12);
    stroke: rgba(32, 88, 220, 0.95);
    stroke-width: 1.4;
    cursor: move;
}

.print-preview-page.selected {
    fill: rgba(60, 132, 255, 0.14);
    stroke: rgba(32, 88, 220, 0.95);
    stroke-width: 1.2;
}

.print-preview-page-number {
    fill: #1d3f9e;
    font-size: 10px;
    font-weight: 700;
}

.print-pages-panel {
    max-height: 148px;
    overflow: auto;
    border: 1px solid rgba(214, 170, 120, 0.28);
    border-radius: 8px;
    padding: 8px;
    background: rgba(255, 249, 240, 0.6);
}

.print-page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 8px;
}

.print-page-item {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(162, 121, 82, 0.32);
    border-radius: 6px;
    padding: 7px 9px;
    color: #4e341f;
    background: rgba(255, 255, 255, 0.86);
    font-size: 12px;
}

.print-page-item.selected {
    border-color: rgba(44, 100, 224, 0.7);
    background: rgba(224, 236, 255, 0.86);
}

.print-page-item input[type="checkbox"] {
    width: auto;
}

.print-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.print-empty {
    color: #8b623f;
    font-size: 12px;
}

#print-pages-output {
    display: none;
}

@media print {
    body.print-review-mode {
        background: #ffffff !important;
        overflow: visible !important;
    }

    body.print-review-mode #canvas-container,
    body.print-review-mode #controls-panel,
    body.print-review-mode #admin-tools-panel,
    body.print-review-mode #add-data-panel,
    body.print-review-mode #image-upload-panel,
    body.print-review-mode #placements-panel,
    body.print-review-mode #wiring-panel,
    body.print-review-mode #wiring-lines-modal,
    body.print-review-mode #layer-indicator,
    body.print-review-mode #info-panel,
    body.print-review-mode .modal {
        display: none !important;
    }

    body.print-review-mode #print-pages-output {
        display: block !important;
        position: static !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body.print-review-mode #print-pages-output .print-sheet {
        page-break-after: always;
        break-after: page;
        margin: 0;
    }

    body.print-review-mode #print-pages-output .print-sheet:last-child {
        page-break-after: auto;
        break-after: auto;
    }

    body.print-review-mode #print-pages-output .print-page-label {
        font-size: 10pt;
        margin: 0 0 4mm 0;
        color: #000;
        font-family: Arial, Helvetica, sans-serif;
    }

    body.print-review-mode #print-pages-output .print-svg {
        width: 100%;
        height: auto;
        display: block;
    }

    body.print-review-mode #print-pages-output .print-cell {
        fill: #ffffff;
        stroke: #000000;
        stroke-width: 1.1;
        rx: 4;
        ry: 4;
    }

    body.print-review-mode #print-pages-output .print-name {
        fill: #000000;
        font-size: 11px;
        font-weight: 600;
        text-anchor: middle;
    }

    body.print-review-mode #print-pages-output .print-date {
        fill: #000000;
        font-size: 9px;
        text-anchor: middle;
    }

    body.print-review-mode #print-pages-output .print-line {
        stroke: #000000;
        fill: none;
        stroke-width: 1.8;
        stroke-linecap: round;
    }

    body.print-review-mode #print-pages-output .print-line.thick {
        stroke-width: 2.4;
    }

    body.print-review-mode #print-pages-output .print-marker-circle {
        fill: #ffffff;
        stroke: #000000;
        stroke-width: 1.4;
    }

    body.print-review-mode #print-pages-output .print-join-dot {
        fill: #000000;
        stroke: none;
    }

    body.print-review-mode #print-pages-output .print-marker-text {
        fill: #000000;
        font-size: 9px;
        font-weight: 700;
        text-anchor: middle;
        dominant-baseline: middle;
    }
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-y: auto;
}

.modal-content {
    background: var(--theme-modal-bg, #232733);
    color: var(--theme-modal-text, #e0e6ed);
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.38);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    padding: 50px 25px 30px 25px;
}

.modal-content.gallery-modal {
    max-width: 800px;
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--theme-overlay-close-bg, #ff4d4f);
    color: var(--theme-accent-text, #ffffff);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    transition: opacity 0.2s;
    z-index: 1001;
}

.close-btn:hover {
    opacity: 0.8;
}

/* Modal Title */
.modal-title {
    color: #4a90e2 !important;
    font-size: 24px !important;
    font-weight: 700 !important;
    margin: 0 0 10px 0 !important;
    padding: 0 !important;
    text-align: center !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Further Details modal - match Home User Guide/About modal styling */
#detailsModal {
    background: rgba(0, 0, 0, 0.56);
}

#detailsModal .modal-content {
    width: min(700px, 94vw);
    max-width: 700px;
    max-height: min(82vh, 760px);
    padding: 18px 16px 16px;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.26), rgba(68, 71, 78, 0.26)),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    overflow-x: hidden;
    overflow-y: auto;
}

#detailsModal .modal-content.details-compact {
    max-height: min(82vh, 640px);
}

#detailsModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 0 !important;
}

#detailsModal #detailsContent {
    margin-top: 0;
}

#detailsModal .detail-content {
    padding: 0 !important;
    margin: 0 !important;
}

#detailsModal .detail-section {
    margin-bottom: 0 !important;
}

#detailsModal #closeDetailsModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

#detailsModal .detail-section.first-section {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
}

#detailsModal .detail-row {
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    height: 36px;
}

#detailsModal .detail-label {
    color: #6f3b19;
    text-align: left;
    justify-content: flex-start;
    padding-left: 12px;
}

#detailsModal .detail-data {
    color: #6b3818;
}

#detailsModal .detail-data .data-empty {
    color: #74401d;
}

#detailsModal .detail-links {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
    margin-top: 12px;
    padding-top: 10px;
    padding-bottom: 38px;
}

#detailsModal .detail-links h3 {
    color: #6f3b19 !important;
}

#detailsModal .detail-icon {
    color: #6b3818;
    border: 1px solid rgba(111, 59, 25, 0.55);
    border-radius: 8px;
    min-width: 84px;
    padding: 10px 12px;
}

#detailsModal .detail-icon:hover {
    background: rgba(166, 102, 42, 0.16);
    transform: none;
}

#detailsModal .link-icons {
    gap: 10px;
}

#detailsModal .detail-icon span:first-child {
    font-size: 26px;
}

#detailsModal .detail-icon span:last-child {
    font-size: 10px;
}

#detailsModal .detail-icon.detail-icon-timeline span:first-child {
    font-size: 24px;
}

#detailsModal .detail-icon[data-title]:hover::after {
    top: 110%;
}

/* Military Service modal styling */
#militaryModal {
    background: rgba(0, 0, 0, 0.56);
}

#militaryModal .modal-content {
    width: min(760px, 95vw);
    max-width: 760px;
    max-height: min(82vh, 760px);
    padding: 18px 16px 16px;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.26), rgba(68, 71, 78, 0.26)),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    overflow-x: hidden;
    overflow-y: auto;
}

#militaryModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 8px !important;
}

#militaryModal #closeMilitaryModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

#militaryModal #militaryContent h2 {
    margin: 0 0 10px 0;
    color: #6f3b19;
    font-size: 20px;
    text-align: center;
}

.military-shell {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
    padding-top: 10px;
}

#militaryModal .detail-section.first-section {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
}

#militaryModal .detail-row {
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    height: 36px;
}

#militaryModal .detail-label {
    color: #6f3b19;
    text-align: left;
    justify-content: flex-start;
    padding-left: 12px;
}

#militaryModal .detail-data {
    color: #6b3818;
}

/* Documents modal styling */
#documentsModal {
    background: rgba(0, 0, 0, 0.56);
}

#documentsModal .modal-content {
    width: min(860px, 95vw);
    max-width: 860px;
    max-height: min(82vh, 760px);
    padding: 18px 16px 16px;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.26), rgba(68, 71, 78, 0.26)),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Notes modal styling */
#notesModal {
    background: rgba(0, 0, 0, 0.56);
}

#notesModal .modal-content {
    width: min(760px, 95vw);
    max-width: 760px;
    max-height: min(82vh, 760px);
    padding: 18px 16px 16px;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.26), rgba(68, 71, 78, 0.26)),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    overflow-x: hidden;
    overflow-y: auto;
}

#notesModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 8px !important;
}

#notesModal #closeNotesModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

.notes-shell h2 {
    margin: 0 0 10px;
    color: #6f3b19;
    text-align: center;
}

.notes-source-badge {
    display: inline-block;
    margin: 0 0 8px;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid rgba(111, 59, 25, 0.36);
    background: rgba(255, 233, 204, 0.64);
    color: #6f3b19;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.notes-body {
    border: 1px solid rgba(214, 170, 120, 0.34);
    border-radius: 8px;
    padding: 10px 12px;
    background: rgba(255, 245, 233, 0.58);
    color: #5e3218;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* Timeline modal styling */
#timelineModal {
    background: rgba(0, 0, 0, 0.56);
}

#timelineModal .modal-content {
    width: min(920px, 96vw);
    max-width: 920px;
    max-height: min(84vh, 780px);
    padding: 18px 16px 16px;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.20), rgba(68, 71, 78, 0.20)),
        radial-gradient(circle at 18% 12%, rgba(255, 221, 173, 0.34), transparent 42%),
        radial-gradient(circle at 86% 88%, rgba(219, 173, 122, 0.26), transparent 40%),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    overflow-x: hidden;
    overflow-y: auto;
}

#timelineModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 8px !important;
}

#timelineModal #closeTimelineModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

.timeline-shell {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
    padding-top: 10px;
}

.timeline-shell h2 {
    margin: 0;
    color: #6f3b19;
    font-size: 20px;
    text-align: center;
}

.timeline-mode-toggle {
    margin-top: 10px;
    display: flex;
    justify-content: center;
    gap: 8px;
}

.timeline-mode-btn {
    border: 1px solid rgba(111, 59, 25, 0.44);
    background: rgba(255, 245, 229, 0.70);
    color: #6f3b19;
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    cursor: pointer;
}

.timeline-mode-btn:hover {
    background: rgba(255, 236, 208, 0.88);
}

.timeline-mode-btn.active {
    background: rgba(97, 138, 193, 0.22);
    border-color: rgba(67, 103, 153, 0.62);
    color: #3c6293;
}

.timeline-meta {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.timeline-chip {
    border: 1px solid rgba(111, 59, 25, 0.40);
    background: rgba(255, 240, 219, 0.64);
    color: #6f3b19;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.timeline-track {
    margin: 14px 2px 0;
    position: relative;
    padding: 4px 0 0;
}

.timeline-track::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 3px;
    transform: translateX(-50%);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(84, 136, 199, 0.65), rgba(162, 104, 52, 0.68));
    opacity: 0.74;
}

.timeline-event {
    position: relative;
    width: calc(50% - 26px);
    margin-bottom: 14px;
}

.timeline-event.left {
    margin-right: auto;
}

.timeline-event.right {
    margin-left: auto;
}

.timeline-event-dot {
    position: absolute;
    top: 16px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid rgba(96, 52, 23, 0.62);
    background: #e7a45f;
    box-shadow: 0 0 0 2px rgba(247, 224, 196, 0.78);
    z-index: 2;
}

.timeline-event.left .timeline-event-dot {
    right: -33px;
}

.timeline-event.right .timeline-event-dot {
    left: -33px;
}

.timeline-event-card {
    border: 1px solid rgba(111, 59, 25, 0.40);
    border-radius: 10px;
    background: rgba(255, 247, 234, 0.70);
    color: #5b3015;
    padding: 10px 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    backdrop-filter: blur(1px);
}

.timeline-event-date {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: #4877b3;
    text-transform: uppercase;
}

.timeline-event.undated .timeline-event-date {
    color: #8a623f;
}

.timeline-event-title {
    margin: 4px 0 4px;
    font-size: 15px;
    color: #6f3b19;
}

.timeline-event-details {
    margin: 0;
    font-size: 13px;
    line-height: 1.4;
}

.timeline-type-birth .timeline-event-dot {
    background: #6fb19f;
}

.timeline-type-marriage .timeline-event-dot {
    background: #6b93c8;
}

.timeline-type-occupation .timeline-event-dot {
    background: #c29853;
}

.timeline-type-death .timeline-event-dot {
    background: #b06d66;
}

.timeline-type-internment .timeline-event-dot {
    background: #9a958d;
}

.timeline-type-notes .timeline-event-dot {
    background: #9f84bf;
}

.timeline-type-sibling-birth .timeline-event-dot {
    background: #7db7d4;
}

.timeline-type-child-birth .timeline-event-dot {
    background: #6fc28d;
}

.timeline-type-parent-death .timeline-event-dot {
    background: #ad7b74;
}

.timeline-type-grandparent-death .timeline-event-dot {
    background: #8f8279;
}

.timeline-type-sibling-death .timeline-event-dot {
    background: #987782;
}

.timeline-type-anniversary .timeline-event-dot {
    background: #8f74c6;
}

.timeline-type-milestone .timeline-event-dot {
    background: #d09b5b;
}

.timeline-type-military-enlistment .timeline-event-dot {
    background: #4f8f74;
}

.timeline-type-military-discharge .timeline-event-dot {
    background: #567f96;
}

.timeline-track.compact-mode {
    padding-left: 26px;
}

.timeline-track.compact-mode::before {
    left: 16px;
    transform: none;
}

.timeline-event.compact {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    padding-left: 10px;
}

.timeline-event.compact .timeline-event-dot {
    left: -6px;
    right: auto;
}

.timeline-empty {
    border: 1px dashed rgba(111, 59, 25, 0.38);
    border-radius: 10px;
    background: rgba(255, 247, 234, 0.58);
    color: #6b3818;
    text-align: center;
    padding: 16px;
    margin-top: 6px;
}

.timeline-empty h4 {
    margin: 0 0 6px;
    font-size: 16px;
    color: #6f3b19;
}

.timeline-empty p {
    margin: 0;
    font-size: 13px;
}

.timeline-footnote {
    margin: 4px 0 0;
    color: #714220;
    font-size: 11px;
    text-align: center;
}

@media (max-width: 760px) {
    .timeline-mode-toggle {
        flex-wrap: wrap;
    }

    .timeline-track {
        padding-left: 26px;
    }

    .timeline-track::before {
        left: 16px;
        transform: none;
    }

    .timeline-event {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
        padding-left: 10px;
    }

    .timeline-event.left .timeline-event-dot,
    .timeline-event.right .timeline-event-dot {
        left: -6px;
        right: auto;
    }
}

#documentsModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 8px !important;
}

#documentsModal #closeDocumentsModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

#documentsModal #documentsContent h2 {
    margin: 0 0 10px 0;
    color: #6f3b19;
    font-size: 20px;
    text-align: center;
}

.documents-shell {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
    padding-top: 10px;
}

.documents-toolbar {
    margin-bottom: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(214, 170, 120, 0.34);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.18);
    color: #6b3818;
    font-weight: 600;
}

.documents-loading {
    padding: 12px;
    color: #6b3818;
}

.documents-list-wrap {
    border: 1px solid rgba(214, 170, 120, 0.34);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.22);
}

.documents-list {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.documents-list thead th {
    text-align: left;
    padding: 9px 10px;
    color: #6f3b19;
    background: rgba(255, 255, 255, 0.32);
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
}

.documents-list tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(214, 170, 120, 0.30);
    color: #6b3818;
    vertical-align: middle;
}

.documents-list tbody tr:last-child td {
    border-bottom: none;
}

.doc-name-cell {
    font-weight: 600;
}

.doc-actions-cell {
    white-space: nowrap;
}

.doc-action-btn {
    padding: 5px 10px;
    margin-right: 6px;
    border-radius: 5px;
    border: 1px solid rgba(111, 59, 25, 0.55);
    background: rgba(166, 102, 42, 0.10);
    color: #6b3818;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.doc-action-btn:last-child {
    margin-right: 0;
}

.doc-action-btn:hover {
    background: rgba(166, 102, 42, 0.18);
}

.doc-action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Details Modal Content */
.detail-content {
    position: relative;
}

.details-member-title {
    color: #6f3b19 !important;
    font-size: 18px !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    margin: 0 !important;
    padding: 0 !important;
    min-height: 32px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34) !important;
}

.detail-section {
    margin-bottom: 0;
}

.detail-section.first-section {
    border-top: 1px solid var(--theme-modal-border, #4a5568);
}

.detail-row {
    display: flex;
    padding: 0;
    border-bottom: 1px solid var(--theme-modal-border, #4a5568);
    height: 44px;
    align-items: center;
}

.detail-label {
    width: 180px;
    flex-shrink: 0;
    font-weight: 600;
    color: var(--theme-muted-text, #a0aec0);
    text-align: center;
    padding-right: 15px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-data {
    flex: 1;
    color: var(--theme-modal-text, #e0e6ed);
    height: 100%;
    display: flex;
    align-items: center;
}

.detail-data .data-value {
    text-align: left;
    width: 100%;
}

.detail-data .data-empty {
    text-align: center;
    color: #95a5a6;
    font-style: italic;
    width: 100%;
}

/* Detail Action Links */
.detail-links {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 2px solid var(--theme-modal-border, #4a5568);
}

.detail-links h3 {
    margin-top: 0;
    overflow: hidden;
    color: var(--theme-muted-text, #a0aec0);
    font-size: 16px;
}

.link-icons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.detail-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 15px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--theme-modal-text, #ffffff);
    cursor: pointer;
    min-width: 90px;
    position: relative;
}

.detail-icon:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.detail-icon[data-title]:hover::after {
    content: attr(data-title);
    position: absolute;
    left: 50%;
    top: 110%;
    transform: translateX(-50%);
    background: rgba(100, 100, 100, 0.95);
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 10000;
}

.detail-icon span:first-child {
    font-size: 28px;
    line-height: 1;
}

.detail-icon span:last-child {
    font-size: 11px;
    font-weight: 600;
}

/* Gallery/Images modal styling */
#galleryModal {
    background: rgba(0, 0, 0, 0.56);
}

#galleryModal .modal-content {
    width: min(860px, 95vw);
    max-width: 860px;
    max-height: min(82vh, 760px);
    padding: 18px 16px 16px;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.26), rgba(68, 71, 78, 0.26)),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    overflow-x: hidden;
    overflow-y: auto;
}

#galleryModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 8px !important;
}

#galleryModal #closeGalleryModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

#galleryModal #galleryContent h2 {
    margin: 0 0 10px 0;
    color: #6f3b19;
    font-size: 20px;
    text-align: center;
}

.image-viewer-shell {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
    padding-top: 10px;
}

.gallery-loading {
    padding: 12px;
    color: #6b3818;
    text-align: center;
}

.tv-viewer-wrap {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
}

.tv-screen {
    width: min(680px, 72vw);
    max-height: 56vh;
    background: #8e9399;
    border: 2px solid rgba(111, 59, 25, 0.45);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    margin: 0 auto;
    aspect-ratio: 16 / 9;
}

.tv-screen img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.tv-arrow {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 1px solid rgba(111, 59, 25, 0.55);
    background: rgba(166, 102, 42, 0.12);
    color: #6b3818;
    font-size: 38px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.tv-arrow:hover:not(:disabled) {
    background: rgba(166, 102, 42, 0.2);
}

.tv-arrow:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.tv-caption {
    margin-top: 10px;
    text-align: center;
    color: #6b3818;
    font-weight: 600;
    min-height: 20px;
}

.tv-counter {
    margin-top: 4px;
    text-align: center;
    color: #6f3b19;
    font-weight: 600;
    font-size: 12px;
}

.tv-frame-empty {
    background: #8e9399;
    border: 2px solid rgba(111, 59, 25, 0.45);
    border-radius: 8px;
    color: #6b3818;
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
}

/* Sound modal styling */
#soundModal {
    background: rgba(0, 0, 0, 0.56);
}

#soundModal .modal-content {
    width: min(760px, 95vw);
    max-width: 760px;
    max-height: min(82vh, 760px);
    padding: 18px 16px 16px;
    border: 1px solid rgba(222, 184, 138, 0.33);
    border-radius: 10px;
    background-image:
        linear-gradient(rgba(68, 71, 78, 0.26), rgba(68, 71, 78, 0.26)),
        url('/Images/Possible%20background.jpg');
    background-size: cover;
    background-position: center center;
    color: #6b3818;
    overflow-x: hidden;
    overflow-y: auto;
}

#soundModal .modal-title {
    color: #6f3b19 !important;
    border-bottom: 1px solid rgba(214, 170, 120, 0.34);
    padding-bottom: 4px !important;
    margin-bottom: 8px !important;
}

#soundModal #closeSoundModal {
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    font-size: 22px;
    background: #c93e3e;
    color: #ffffff;
}

#soundModal #soundContent h2 {
    margin: 0 0 10px 0;
    color: #6f3b19;
    font-size: 20px;
    text-align: center;
}

.sound-shell {
    border-top: 1px solid rgba(214, 170, 120, 0.34);
    padding-top: 10px;
}

.sound-player-frame {
    background: #8e9399;
    border: 2px solid rgba(111, 59, 25, 0.45);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 10px;
}

.sound-title {
    text-align: center;
    color: #6b3818;
    font-weight: 700;
    margin-bottom: 10px;
}

.sound-audio {
    width: 100%;
}

.sound-nav {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
}

.sound-nav-btn {
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid rgba(111, 59, 25, 0.55);
    background: rgba(166, 102, 42, 0.12);
    color: #6b3818;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}

.sound-nav-btn:hover:not(:disabled) {
    background: rgba(166, 102, 42, 0.2);
}

.sound-nav-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.sound-counter {
    text-align: center;
    color: #6f3b19;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 8px;
}

.sound-list {
    border: 1px solid rgba(214, 170, 120, 0.34);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.22);
}

.sound-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.sound-table th,
.sound-table td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(214, 170, 120, 0.30);
    color: #6b3818;
    text-align: left;
}

.sound-table th {
    background: rgba(255, 255, 255, 0.32);
    color: #6f3b19;
}

.sound-table tr:last-child td {
    border-bottom: none;
}

.sound-row-btn {
    padding: 4px 10px;
    border-radius: 5px;
    border: 1px solid rgba(111, 59, 25, 0.55);
    background: rgba(166, 102, 42, 0.10);
    color: #6b3818;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}
