/* style.css - Ekskluzywne style dla wielkoformatowego drzewa genealogicznego */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100vw;
    max-width: 100vw;
    overflow-x: hidden; /* Blokada bocznego przewijania całej strony */
    position: relative;
    overscroll-behavior: none; /* Całkowicie blokuje przeciąganie i "gumowanie" całej strony na iOS/Safari/Chrome */
}

body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background-color: #faf6ee;
    color: #2d1e15;
    height: 100%;
    height: 100dvh; /* Dynamiczny viewport - zapobiega przesunięciom paska adresu na telefonie */
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
}

/* NAGŁÓWEK (HUD) */
header {
    position: relative; /* Pozwala na działanie właściwości z-index */
    background-color: rgba(243, 237, 211, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #ebdcb9;
    padding: 16px 24px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    z-index: 1100; /* Wyższa wartość niż panel boczny (1001) */
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    height: 80px;
    flex-shrink: 0;
    max-width: 100vw;
    box-sizing: border-box;
    /* Usunięto overflow: hidden, aby wyskakujący panel wyszukiwarki nie był ucinany */
}
.header-logo-container {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}
.header-icon {
    padding: 10px;
    background-color: #7c593c;
    color: #fdfbf7;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(124, 89, 60, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
}
.header-title-wrapper h1 {
    font-family: 'Cinzel', serif;
    font-size: 20px;
    font-weight: 700;
    color: #3d2716;
    letter-spacing: 0.5px;
}
.header-title-wrapper p {
    font-size: 10px;
    color: #7c593c;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

/* PANEL KONTROLNY / WYSZUKIWARKA */
.controls-wrapper {
    display: flex;
    align-items: center;
    gap: 16px;
    width: auto;
}
.stats-block {
    display: none;
    gap: 20px;
    text-align: center;
    border-left: 1px solid #ebdcb9;
    border-right: 1px solid #ebdcb9;
    padding: 0 24px;
    align-items: center;
}
@media (min-width: 1400px) {
    .stats-block {
        display: flex;
    }
}
.stat-item-title {
    font-size: 9px;
    color: #7c593c;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.stat-item-val {
    font-family: 'Cinzel', serif;
    font-size: 18px;
    font-weight: 700;
    color: #3d2716;
}
.search-container {
    position: relative;
    width: 280px;
}
.search-input {
    width: 100%;
    background-color: #fdfbf7;
    border: 1px solid #c5b59f;
    border-radius: 12px;
    padding: 10px 16px 10px 40px;
    font-size: 14px;
    color: #2d1e15;
    outline: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.02);
    transition: all 0.2s;
}
.search-input:focus {
    border-color: #7c593c;
    box-shadow: 0 0 0 2px rgba(124, 89, 60, 0.15);
}
.search-icon-svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%); /* Zawsze idealnie na środku w pionie */
    color: #7c593c;
    display: flex;
    align-items: center;
}
.search-dropdown {
    position: absolute;
    top: 100%; /* Wyświetla panel tuż pod oknem wyszukiwania */
    left: 0;
    width: 100%;
    background-color: #fdfbf7;
    border: 1px solid #c5b59f;
    border-radius: 12px;
    margin-top: 4px;
    display: none;
    font-size: 14px;
    max-height: 256px;
    overflow-y: auto;
    z-index: 9999 !important; /* Absolutny priorytet - zawsze na wierzchu, nad mapą */
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.search-result-item {
    padding: 12px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid #f3edd3;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.search-result-item:last-child {
    border-bottom: none;
}
.search-result-item:hover {
    background-color: #ebdcb9;
}
.reset-btn {
    padding: 10px;
    background-color: #fdfbf7;
    border: 1px solid #c5b59f;
    color: #7c593c;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.reset-btn:hover {
    background-color: #7c593c;
    color: #fdfbf7;
}

/* STRUKTURA GŁÓWNA */
/* Zabezpieczenie przed ucinaniem, zapadaniem wysokości i kurczeniem się mapy */
.workspace-wrapper {
    flex: 1 1 0%; /* Wymusza poprawne rozciąganie w pionie w elastycznym kontenerze */
    display: flex;
    flex-direction: row;
    align-items: stretch; /* Rozciąga dzieci (mapę) w pionie do pełnej wysokości parenta */
    width: 100%;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

#map-container {
    flex: 1 1 0%; /* Wymusza automatyczne zajęcie całej dostępnej szerokości */
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
    position: relative;
    outline: none;
    background-color: #fcf9f2;
    background-image:
        radial-gradient(circle at 50% 50%, rgba(253, 251, 247, 0.8) 0%, rgba(244, 236, 220, 0.4) 100%),
        url('data:image/svg+xml;utf8,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="noiseFilter"><feTurbulence type="fractalNoise" baseFrequency="0.8" numOctaves="3" stitchTiles="stitch"/></filter><rect width="100%" height="100%" filter="url(%23noiseFilter)" opacity="0.015"/></svg>');
    touch-action: none;
}

#map-container svg {
    touch-action: none; /* Wymusza brak reakcji systemowej przeglądarki na gesty wewnątrz SVG */
}

/* DYNAMICZNY TYPOGRAFICZNY NAGŁÓWEK RODU */
.klan-title-header {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Cinzel', serif;
    font-size: 22px;
    font-weight: 800;
    color: #3d2716;
    letter-spacing: 2px;
    text-transform: uppercase;
    background-color: rgba(253, 251, 247, 0.95);
    padding: 10px 30px;
    border-radius: 16px;
    border: 2px double #ebdcb9;
    box-shadow: 0 10px 25px rgba(124, 89, 60, 0.1);
    z-index: 999;
    display: none;
}

/* KRZYWE GAŁĘZI */
.link {
    fill: none;
    stroke: #7c593c;
    stroke-width: 2.5px;
    stroke-opacity: 0.45;
    transition: stroke-opacity 0.3s, stroke-width 0.3s;
}
.tree-branch-line {
    stroke-linecap: round;
    filter: drop-shadow(0px 3px 4px rgba(60, 42, 28, 0.15));
}

/* PASEK BOCZNY */
#info-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 384px;
    height: 100%;
    background-color: #fdfbf7;
    border-left: 1px solid #dcd2be;
    z-index: 1001; /* Niższa wartość niż nagłówek (1100) */
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: -10px 0 30px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #f3edd3;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background-color: #fcf9f2;
}
.side-badge {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 9999px;
    display: inline-block;
}
.side-badge-m {
    background-color: #cbd5c5;
    color: #4d5d49;
}
.side-badge-f {
    background-color: #eecac0;
    color: #8c4f3e;
}
#side-name {
    font-family: 'Cinzel', serif;
    font-size: 20px;
    font-weight: 700;
    color: #3d2716;
    margin-top: 8px;
}
.sidebar-close-btn {
    background: none;
    border: none;
    color: #7c593c;
    cursor: pointer;
    padding: 6px;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-close-btn:hover {
    background-color: #f0e7d5;
}
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}
.sidebar-details-card {
    background-color: #faf6ee;
    border-radius: 16px;
    border: 1px solid #e8dfcc;
    padding: 16px;
    margin-bottom: 24px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.01);
}
.details-row {
    display: flex;
    align-items: start;
    gap: 12px;
}
.details-divider {
    border: none;
    border-top: 1px solid #e8dfcc;
    margin: 12px 0;
}
.details-label {
    font-size: 9px;
    color: #a6927d;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.details-val {
    font-size: 14px;
    font-weight: 600;
    color: #2d1e15;
    margin-top: 2px;
}
.details-place {
    font-size: 12px;
    color: #5e412a;
    margin-top: 1px;
}
.sidebar-section-title {
    font-family: 'Cinzel', serif;
    font-size: 14px;
    font-weight: 700;
    color: #3d2716;
    border-bottom: 1px solid #dcd2be;
    padding-bottom: 8px;
    margin-bottom: 16px;
}
.relative-link-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background-color: #fdfbf7;
    border: 1px solid #e8dfcc;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.relative-link-item:hover {
    background-color: #ebdcb9;
    transform: translateY(-1px);
}

/* INTERAKTYWNA KARTA MAŁŻEŃSKA */
.foreign-card-wrapper {
    width: 320px;
    height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.couple-frame {
    width: 300px;
    height: 120px;
    background: linear-gradient(135deg, #fdfbf7 0%, #f4ecd8 100%);
    border: 2px double #c5b59f;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(74, 51, 33, 0.08);
    display: flex;
    position: relative;
    padding: 4px;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.2s, box-shadow 0.2s;
}
.couple-frame:hover {
    transform: scale(1.08) !important;
    box-shadow: 0 15px 35px rgba(124, 89, 60, 0.22);
    border-color: #7c593c;
}
.couple-frame-highlight {
    border-color: #d4af37 !important;
    box-shadow: 0 0 30px rgba(212, 175, 55, 0.5) !important;
    animation: pulse-glow 2s infinite;
}
@keyframes pulse-glow {
    0% { transform: scale(1); }
    50% { transform: scale(1.03); }
    100% { transform: scale(1); }
}

/* PRESTIŻOWE ZŁOTE KARTY HERBOWE RODÓW */
.klan-label-card {
    width: 260px;
    height: 100px;
    background: linear-gradient(135deg, #fdfbf7 0%, #eddca7 100%);
    border: 2px solid #bfa054;
    border-radius: 20px;
    box-shadow: 0 8px 22px rgba(124, 89, 60, 0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.2s, border-color 0.2s;
    position: relative;
    padding: 12px;
}
.klan-label-card:hover {
    transform: scale(1.08) !important;
    box-shadow: 0 15px 35px rgba(191, 160, 84, 0.3);
    border-color: #7c593c;
}
.klan-label-title {
    font-family: 'Cinzel', serif;
    font-size: 13px;
    font-weight: 800;
    color: #3d2716;
    letter-spacing: 1.5px;
    text-align: center;
}
.klan-label-subtitle {
    font-size: 10px;
    font-weight: 700;
    color: #7c593c;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}
.klan-label-action {
    font-size: 8px;
    font-weight: 800;
    color: #7c593c;
    margin-top: 10px;
    letter-spacing: 0.5px;
    opacity: 0.85;
}

/* PRESTIŻOWY WIRTUALNY SYGNET WOSKOWY */
.virtual-seal-container {
    width: 320px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.virtual-seal {
    width: 115px;
    height: 115px;
    background: radial-gradient(circle, #dfc88a 0%, #7c593c 100%);
    border: 3px double #dfc88a;
    border-radius: 9999px;
    box-shadow: 0 10px 25px rgba(124, 89, 60, 0.35), inset 0 2px 6px rgba(253, 251, 247, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.virtual-seal:hover {
    transform: scale(1.1) rotate(6deg);
}
.seal-inner {
    text-align: center;
    color: #fdfbf7;
}
.seal-icon {
    font-size: 26px;
    margin-bottom: 2px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}
.seal-title {
    font-family: 'Cinzel', serif;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: 1px;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.seal-subtitle {
    font-family: 'Cinzel', serif;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    opacity: 0.85;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* POŁÓWKI PARTNERSKIE */
.partner-half {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px;
    cursor: pointer;
    border-radius: 14px;
    transition: background-color 0.2s;
}
.partner-half:hover {
    background-color: rgba(124, 89, 60, 0.05);
}
.partner-m {
    border-right: 1px dashed rgba(197, 181, 159, 0.4);
    background-color: rgba(138, 154, 134, 0.03);
}
.partner-f {
    background-color: rgba(207, 159, 144, 0.03);
}
.partner-name {
    font-family: 'Cinzel', serif;
    font-size: 11px;
    font-weight: 700;
    color: #2d1e15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.partner-surname {
    font-family: 'Cinzel', serif;
    font-size: 12px;
    font-weight: 800;
    color: #3d2716;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.partner-date {
    font-size: 8px;
    font-weight: 700;
    color: #7c593c;
    letter-spacing: 0.5px;
    margin-top: auto;
}

/* ZŁOTE OBRĄCZKI */
.marriage-rings {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background-color: #fdfbf7;
    border: 1px solid #ebdcb9;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    pointer-events: none;
    color: #d4af37;
    font-size: 11px;
}

/* PRZYCISK ROZWIJANIA GAŁĘZI */
.node-toggle-btn {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 22px;
    background: linear-gradient(135deg, #dfc88a, #bfa054);
    border: 2px solid #fdfbf7;
    border-radius: 9999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fdfbf7;
    font-weight: 800;
    font-size: 11px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    transition: transform 0.2s;
    z-index: 20;
    outline: none;
}
.node-toggle-btn:hover {
    transform: translateX(-50%) scale(1.15);
}

/* PŁYWAJĄCY PRZYCISK WSTECZ */
.back-floating-btn {
    position: absolute;
    bottom: 24px;
    left: 24px;
    background-color: #7c593c;
    color: #fdfbf7;
    border: 1px solid #ebdcb9;
    border-radius: 12px;
    padding: 12px 20px;
    font-family: 'Cinzel', serif;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    display: none;
    box-shadow: 0 10px 25px rgba(124, 89, 60, 0.25);
    transition: all 0.2s;
    z-index: 1000;
}
.back-floating-btn:hover {
    background-color: #3d2716;
    transform: translateY(-2px);
}

/* --- REGUŁY RESPONSYWNE DLA TABLETÓW I TELEFONÓW (PODWYŻSZONY PRÓG DO 1770px) --- */

@media (max-width: 1770px) {
    header {
        height: auto !important; /* Nadpisujemy stałe 80px */
        flex-direction: column !important;
        align-items: center !important;
        padding: 12px 16px !important;
        gap: 12px !important;
    }

    .klan-title-header {
    font-size: 13px !important;
    padding: 6px 16px !important;
    top: 10px !important;
    max-width: 85% !important;
    text-align: center !important;
    border: 1px solid #ebdcb9 !important; /* Pojedyncza, nowoczesna linia zamiast grubej, podwójnej ramki */
    border-radius: 10px !important;
    box-shadow: 0 4px 12px rgba(124, 89, 60, 0.06) !important;
}

    .header-logo-container {
        width: 100%;
        justify-content: center;
        text-align: center;
        margin-bottom: 2px;
    }

    .header-title-wrapper h1 {
        font-size: 17px !important;
    }

    .header-title-wrapper p {
        font-size: 8px !important;
    }

    /* Pełne zawijanie przycisków i opcji - gwarancja 100% widoczności */
    .controls-wrapper {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
        height: auto !important;
        white-space: normal !important; /* Zezwolenie na przechodzenie do nowej linii */
        overflow: visible !important;   /* Usunięcie obcinania wyskakującej wyszukiwarki */
        padding: 4px !important;
    }

    /* Każdy przycisk automatycznie dostosowuje się na małym ekranie */
    .controls-wrapper .reset-btn,
    .controls-wrapper .klan-select-dropdown,
    .controls-wrapper #hover-highlight-label,
    .controls-wrapper #dot-mode-btn,
    .controls-wrapper #organic-toggle-btn {
        font-size: 11px !important;
        padding: 8px 12px !important;
        height: 38px !important; /* Jednolita wysokość elementów */
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 10px !important;
        box-sizing: border-box !important;
        flex-shrink: 0 !important;
    }

    /* Tylko przycisk dopasowania widoku (resetu), który nie ma tekstu, robimy kwadratowy */
        .controls-wrapper button[onclick*="resetTreePerspective"] {
            width: 38px !important;
            padding: 0 !important;
            flex-shrink: 0 !important;
        }

        /* Pozostałe przyciski z tekstem (Tryb Punktowy, Piękne Drzewo) muszą mieć automatyczną szerokość */
        .controls-wrapper #dot-mode-btn,
        .controls-wrapper #organic-toggle-btn {
            width: auto !important;
            padding: 8px 14px !important;
            white-space: nowrap !important; /* Blokujemy łamanie tekstu wewnątrz przycisków */
            flex-shrink: 0 !important;
        }

    #hover-highlight-label {
        gap: 6px !important;
        cursor: pointer;
    }

    #hover-highlight-label input {
        width: 15px !important;
        height: 15px !important;
        margin: 0 !important;
    }

    .klan-select-container select, .klan-select-dropdown {
        padding: 8px 12px !important;
        font-size: 11px !important;
        border-radius: 10px !important;
    }

    .search-container {
        width: 100% !important; /* Na małych ekranach wyszukiwarka ląduje w nowej linii */
        max-width: 280px !important;
        height: 38px !important;
        margin: 4px 0 !important;
        position: relative !important;
    }

    .search-input {
        height: 38px !important;
        padding: 6px 12px 6px 36px !important;
        font-size: 12px !important;
        border-radius: 10px !important;
    }

    /* Korekta położenia ikonki lupki */
    .search-icon-svg {
        left: 12px !important;
        top: 50% !important;
        transform: translateY(-50%) !important; /* Idealne wyśrodkowanie w pionie */
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    .search-icon-svg svg {
        width: 15px !important;
        height: 15px !important;
    }
}

@media (max-width: 1400px) {
    /* Ukrycie statystyk poniżej 1400px dla zachowania czystości interfejsu */
    .stats-block {
        display: none !important;
    }
}

@media (max-width: 768px) {
    /* Na małych ekranach panel boczny zajmuje 100% szerokości */
    #info-sidebar {
        width: 100% !important;
        border-left: none;
    }

    /* Zmniejszenie nagłówka panelu bocznego, by zmieścić więcej treści */
    .sidebar-header {
        padding: 14px;
    }

    #side-name {
        font-size: 18px;
    }

    /* Przearanżowanie pływających przycisków sterowania klanami na dole ekranu */
    #clan-controls-container {
        bottom: 16px;
        left: 16px;
        right: 16px;
        flex-direction: column;
        gap: 8px;
    }

    #clan-controls-container button {
        width: 100%;
        justify-content: center;
        padding: 10px;
        font-size: 12px;
    }

    /* Dodatkowe zmniejszenie i podciągnięcie napisu na najmniejszych telefonach */
    .klan-title-header {
        font-size: 11px !important;
        padding: 4px 10px !important;
        top: 6px !important;
        border-radius: 6px !important;
    }
}
