:root {
    --bg-color: #fdfdfd;
    --text-main: #2c3e50;
    --color-present: #e74c3c;
    --pin-color: #c0392b; 
    --axis-color: #cbd5e1;
    --tracker-color: #f39c12; 
    --shadow-subtle: 0 4px 15px rgba(0,0,0,0.08);
}

body, html { margin: 0; padding: 0; height: 100%; font-family: 'Inter', sans-serif; background: var(--bg-color); overflow: hidden; color: var(--text-main); }
#visualization { width: 100vw; height: 100vh; cursor: crosshair; } 
#visualization:active { cursor: grabbing; }

/* UI Meniu & Butoane */
#menu-btn {
    position: fixed; top: 20px; right: 25px; z-index: 100; background: white; border: 1px solid #eee; border-radius: 50%;
    width: 48px; height: 48px; cursor: pointer; box-shadow: var(--shadow-subtle); display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
#menu-btn:hover { background: #f9f9f9; transform: scale(1.05); }
#menu-btn svg { width: 22px; height: 22px; fill: #555; }

.bottom-actions { position: fixed; bottom: 30px; right: 25px; z-index: 98; display: flex; gap: 15px; }

.action-btn {
    background: white; border: 1px solid #eee; border-radius: 30px; padding: 12px 20px; font-family: 'Inter', sans-serif; font-weight: 600; font-size: 13px;
    color: var(--text-main); cursor: pointer; box-shadow: var(--shadow-subtle); transition: 0.2s; display: flex; align-items: center; gap: 8px; letter-spacing: 0.5px;
}
.action-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 25px rgba(0,0,0,0.1); }
.btn-today:hover { color: var(--color-present); border-color: #ffdad6; }
.btn-export:hover { color: #2980b9; border-color: #d6eaf8; }
.action-btn svg { width: 16px; height: 16px; fill: currentColor; }

.overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); backdrop-filter: blur(3px); z-index: 99; display: none; opacity: 0; transition: 0.3s;
}
.overlay.active { display: block; opacity: 1; }

#drawer {
    position: fixed; top: 0; right: -320px; width: 300px; height: 100%; background: white; z-index: 101; box-shadow: -5px 0 20px rgba(0,0,0,0.05); transition: 0.3s ease-out; display: flex; flex-direction: column;
}
#drawer.open { right: 0; }

.drawer-header { padding: 20px; border-bottom: 1px solid #f0f0f0; display: flex; justify-content: space-between; align-items: center; }
.drawer-header h3 { margin: 0; font-size: 1.1rem; }
.close-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: #888; }
.drawer-content { padding: 20px; overflow-y: auto; flex: 1; }
.search-box { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 6px; margin-bottom: 20px; box-sizing: border-box; outline: none; }
.filter-section-title { font-size: 0.85rem; color: #7f8c8d; text-transform: uppercase; margin: 15px 0 10px 0; font-weight: 600; }
.filter-label { display: flex; align-items: center; margin-bottom: 10px; cursor: pointer; font-size: 0.95rem; }
.filter-label input { margin-right: 10px; }

/* Modale */
.custom-modal {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -45%); width: 90%; max-width: 450px; background: white; z-index: 102; 
    border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,0.15); display: none; opacity: 0; transition: 0.3s; overflow: hidden; max-height: 85vh; flex-direction: column;
}
.custom-modal:not(.active) { display: none !important; }
.custom-modal.active { display: flex !important; opacity: 1; transform: translate(-50%, -50%); }

.modal-img-container { width: 100%; height: 320px; background: #f5f5f5; display: none; position: relative; flex-shrink: 0; }
.modal-img-container img { width: 100%; height: 100%; object-fit: cover; }

.modal-body { padding: 25px; overflow-y: auto; flex: 1; }
#modal-badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; margin-bottom: 10px; }
#modal-title { margin: 0 0 5px 0; font-size: 1.4rem; }
#modal-date { margin: 0 0 15px 0; font-size: 0.85rem; color: #7f8c8d; }
#modal-desc { line-height: 1.6; color: #444; margin: 0 0 20px 0; font-size: 0.95rem; white-space: pre-wrap; }

/* Link-uri externe */
.links-container { display: flex; flex-direction: column; gap: 8px; margin-top: 15px; }
.external-btn { width: 100%; background: #f8f9fa; border: 1px solid #ddd; padding: 10px 15px; border-radius: 8px; text-align: left; font-weight: 600; font-size: 0.9rem; color: #2c3e50; text-decoration: none; display: flex; align-items: center; gap: 10px; transition: 0.2s; box-sizing: border-box; cursor: pointer; }
.external-btn:hover { background: #ebf5fb; border-color: #2980b9; color: #2980b9; transform: translateX(3px); }
.rr-btn { color: #2980b9; border-color: #d6eaf8; background: #ebf5fb; }
.rr-btn:hover { background: #d6eaf8; border-color: #2980b9; color: #2980b9; }
.om-btn { color: #d35400; border-color: #fae5d3; background: #fdf2e9; }
.om-btn:hover { background: #fdebd0; border-color: #d35400; color: #d35400; }

/* Iframe Modal */
#iframe-modal {
    position: fixed; top: 2%; left: 2%; width: 96%; height: 96%; background: white; z-index: 1000; border-radius: 12px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.4); display: flex; flex-direction: column; opacity: 0; pointer-events: none; transition: 0.3s; transform: scale(0.98);
}
#iframe-modal.active { opacity: 1; pointer-events: auto; transform: scale(1); }
.iframe-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid #eee; background: #fdfdfd; border-radius: 12px 12px 0 0; }
.iframe-header h3 { margin: 0; font-size: 1.1rem; color: #2c3e50; }
.iframe-fallback { font-size: 0.85rem; color: #e74c3c; text-decoration: none; margin-left: 15px; font-weight: 500; border: 1px solid #fadbd8; padding: 4px 10px; border-radius: 20px; background: #fdedec;}
.iframe-fallback:hover { background: #fadbd8; }
#map-frame { flex: 1; width: 100%; border: none; border-radius: 0 0 12px 12px; background: #f0f0f0; }

.export-option-btn { width: 100%; padding: 15px; margin-bottom: 10px; border: 2px solid #eee; border-radius: 8px; background: white; cursor: pointer; text-align: left; transition: 0.2s; }
.export-option-btn:hover { border-color: #2980b9; background: #f4f9fd; }
.export-option-btn h4 { margin: 0 0 5px 0; font-size: 1.1rem; color: #2c3e50; }
.export-option-btn p { margin: 0; font-size: 0.85rem; color: #7f8c8d; }

/* D3.js Elements */
.axis-line path { stroke: var(--axis-color); stroke-width: 2px; }
.axis-line line { stroke: var(--axis-color); stroke-opacity: 0.5; }
.axis-line text { fill: #94a3b8; font-family: 'Inter', sans-serif; font-size: 12px; font-weight: 500; }

.person-bar { rx: 6; ry: 6; cursor: pointer; transition: opacity 0.2s; stroke: rgba(0,0,0,0.1); stroke-width: 1px; }
.person-bar:hover { opacity: 0.8; stroke: rgba(0,0,0,0.3); }
.person-label { fill: #111; font-size: 12px; font-family: 'Inter'; font-weight: 600; pointer-events: none; }
.genealogy-link { fill: none; stroke: #94a3b8; stroke-width: 2px; stroke-dasharray: 4,4; opacity: 0.5; }

.event-line { stroke: var(--pin-color); stroke-width: 1.5px; opacity: 0.7; }
.event-dot { fill: white; stroke: var(--pin-color); stroke-width: 2.5px; cursor: pointer; }
.event-label { fill: var(--text-main); font-size: 12px; font-family: 'Inter'; font-weight: 600; cursor: pointer; }
.event-label-bg { fill: white; opacity: 0.9; }

.event-brace-path { fill: none; stroke-width: 2.5px; stroke-linecap: round; stroke-linejoin: round; cursor: pointer; transition: stroke-width 0.2s; opacity: 0.85; }
.event-brace-path:hover { stroke-width: 3.5px; opacity: 1; }
.event-brace-label { font-size: 12px; font-family: 'Inter'; font-weight: 600; cursor: pointer; text-shadow: 0 1px 2px rgba(255,255,255,0.8); }

.today-line { stroke: var(--color-present); stroke-width: 1.5px; stroke-dasharray: 5,5; opacity: 0.7; }
.today-text { fill: var(--color-present); font-size: 11px; font-weight: bold; font-family: 'Inter'; letter-spacing: 1px; }

.crosshair-line { stroke: var(--tracker-color); stroke-width: 1.5px; stroke-dasharray: 4,4; opacity: 0.7; }
.crosshair-bg { fill: #2c3e50; opacity: 0.9; }
.crosshair-text { fill: white; font-size: 12px; font-family: 'Inter'; font-weight: 600; text-anchor: middle; }

/* Tooltip Vârstă Dinamică */
#hover-tooltip {
    position: absolute;
    background: #2c3e50;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    pointer-events: none; 
    opacity: 0; 
    transition: opacity 0.15s;
    z-index: 2000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    line-height: 1.4;
}
#hover-tooltip b { color: #f39c12; }

/* =========================================
   PREMIUM DARK MODE
========================================= */
body.dark-mode { background-color: #121212 !important; color: #e2e8f0 !important; }

body.dark-mode #menu-panel, body.dark-mode .sidebar, body.dark-mode .side-panel, body.dark-mode #info-panel {
    background-color: #1e1e1e !important; color: #e2e8f0 !important; border-left: 1px solid #333 !important;
}

body.dark-mode #menu-panel label, body.dark-mode .sidebar label, body.dark-mode h2, body.dark-mode h3 { color: #e2e8f0 !important; }
body.dark-mode input[type="text"], body.dark-mode input[type="search"] { background-color: #121212 !important; color: #fff !important; border: 1px solid #444 !important; }

body.dark-mode .custom-modal, body.dark-mode .modal-body, body.dark-mode .iframe-header { background-color: #1e1e1e !important; color: #e2e8f0 !important; border-color: #333 !important; }
body.dark-mode .export-option { background-color: #2c3e50 !important; border: 1px solid #444 !important; }
body.dark-mode .export-option:hover { background-color: #34495e !important; }

body.dark-mode .export-option strong, body.dark-mode .export-option h4, body.dark-mode .export-option p, body.dark-mode .export-option div { color: #f8fafc !important; }

body.dark-mode button, body.dark-mode .btn, body.dark-mode .btn-export, body.dark-mode .btn-tool, body.dark-mode .close-btn {
    background-color: #2c3e50 !important; color: #e2e8f0 !important; border: 1px solid #444 !important;
}
body.dark-mode button:hover { background-color: #34495e !important; }

/* Corecție culori casete pe Dark Mode */
body.dark-mode .person-bar { 
    filter: none !important;
    -webkit-filter: none !important;
    opacity: 0.65 !important;
    stroke: rgba(255,255,255,0.2) !important;
}

body.dark-mode .person-label { fill: #f8fafc !important; text-shadow: 0 1px 3px rgba(0,0,0,0.8) !important; }
body.dark-mode .axis-line path, body.dark-mode .axis-line line { stroke: #475569 !important; }
body.dark-mode .axis-line text { fill: #94a3b8 !important; font-weight: 500; }
body.dark-mode .event-line { stroke: #e74c3c !important; opacity: 0.9 !important; }
body.dark-mode .today-text { fill: #ff6b6b !important; }
body.dark-mode .event-label { fill: #f8fafc !important; text-shadow: 0 1px 3px rgba(0,0,0,0.8) !important; }
body.dark-mode .event-label-bg { fill: #1e1e1e !important; opacity: 0.9; }
body.dark-mode .event-brace-label, body.dark-mode .event-title { fill: #64b5f6 !important; text-shadow: 0 1px 2px rgba(0,0,0,0.9) !important; filter: brightness(1.4) saturate(1.2); }

/* =========================================
   REPARAȚII FINALE: BUTOANE, ACOLADE & MENIURI
========================================= */
#theme-toggle {
    width: 44px !important; height: 44px !important; border-radius: 50% !important; display: flex !important;
    align-items: center !important; justify-content: center !important; padding: 0 !important; font-size: 1.2rem;
    line-height: 1; border: 1px solid #eee; background: white;
}

.event-brace-path { stroke: #555 !important; }
.event-brace-label { font-weight: bold; }
body.dark-mode #drawer { background-color: #1e1e1e !important; border-left: 1px solid #333 !important; color: #e2e8f0 !important; }
body.dark-mode .drawer-header { background-color: #1e1e1e !important; border-bottom: 1px solid #333 !important; }
body.dark-mode .drawer-header h3, body.dark-mode .filter-section-title, body.dark-mode .filter-label { color: #e2e8f0 !important; }
body.dark-mode .close-btn { color: #aaa !important; }
body.dark-mode .close-btn:hover { color: #fff !important; }
body.dark-mode #drawer input[type="text"] { background-color: #121212 !important; color: #fff !important; border: 1px solid #444 !important; }
body.dark-mode .export-option-btn { background-color: #2c3e50 !important; border: 1px solid #444 !important; }
body.dark-mode .export-option-btn:hover { background-color: #34495e !important; }
body.dark-mode .export-option-btn h4 { color: #f8fafc !important; }
body.dark-mode .export-option-btn p { color: #b0bec5 !important; }

/* =========================================
   REPARAȚII MOBILE (Fără hack-uri de scroll)
========================================= */
@media (max-width: 768px) {
    #hover-tooltip { display: none !important; } /* Fără tooltip enervant pe mobil */
}

@media (max-width: 600px) {
    /* Butoane aliniate perfect la bază */
    .bottom-actions { right: 0 !important; left: 0 !important; bottom: 15px !important; justify-content: center !important; width: 100% !important; padding: 0 10px; box-sizing: border-box; gap: 8px !important; }
    .action-btn { padding: 10px 12px !important; font-size: 11px !important; flex: 1; justify-content: center; }
    #theme-toggle { flex-shrink: 0; width: 42px !important; height: 42px !important; }
}