/* ==========================================================
   1. BASIS & LAYOUT
   ========================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f5f5f5;
    padding: 15px;
    line-height: 1.5;
}

h3 {
    margin-bottom: 15px;
    font-size: 22px;
    color: #333;
}

.main-container {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.controls {
    margin-bottom: 20px;
    background: white;
    padding: 10px 15px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: inline-block;
}

.controls label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
    user-select: none;
}

.controls select {
    padding: 6px 10px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    background: white;
}

/* ==========================================================
   2. SVG & KARTEN-STYLING
   ========================================================== */
.legal-container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    line-height: 1.6;
}

.legal-container h1 {
    margin-bottom: 20px;
    color: #333;
}

.legal-container h2 {
    margin-top: 30px;
    margin-bottom: 15px;
    font-size: 1.4em;
    color: #444;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.legal-container p {
    margin-bottom: 15px;
}

.back-link {
    display: inline-block;
    margin-bottom: 20px;
    color: #0056b3;
    text-decoration: none;
    font-weight: bold;
}

.back-link:hover {
    text-decoration: underline;
}

.svg-container {
    flex: 1;
    min-width: 350px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 10px;
    overflow: hidden;
    max-width: 900px;
}

svg {
    width: 100%;
    height: auto;
    display: block;
}

.haus1,
.flur1 {
    display: none;
}

.haus,
.haus1,
.flur,
.flur1 {
    cursor: pointer;
    transition: opacity 0.2s;
    stroke: #000000;
    stroke-width: 3px;
    paint-order: fill stroke !important;
}

.haus:hover,
.haus1:hover,
.flur:hover,
.flur1:hover {
    opacity: 0.7;
}

@keyframes breathe-blue {
    0% {
        stroke: #0044cc;
        filter: drop-shadow(0 0 3px rgba(0, 68, 204, 0.5));
    }

    50% {
        stroke: #00ccff;
        filter: drop-shadow(0 0 12px rgba(0, 204, 255, 0.8));
    }

    100% {
        stroke: #0044cc;
        filter: drop-shadow(0 0 3px rgba(0, 68, 204, 0.5));
    }
}

.active-group path,
.active-element {
    stroke-width: 20px !important;
    paint-order: stroke fill !important;
    stroke-linecap: round;
    stroke-linejoin: round;
    animation: breathe-blue 3s ease-in-out infinite;
    opacity: 1 !important;
}

.highlight-hover,
.highlight-hover path,
.highlight-hover rect,
.highlight-hover circle {
    stroke: #00f2ff !important;
    stroke-width: 20px !important;
    filter: drop-shadow(0 0 10px rgba(0, 242, 255, 0.9));
    transition: all 0.2s ease;
    cursor: pointer;
    paint-order: stroke fill !important;
    animation: none !important;
}

/* ==========================================================
   HISTORISCHE FARBEN (Zeitstrahl < Baujahr)
   ========================================================== */

/* Gruppe Grün */
#Flurstück29.historical-mode,
#Flurstück10.historical-mode,
#Flurstück8.historical-mode,
#Flurstück2_neu.historical-mode {
    fill: #aedb34 !important;
    /* Grün */
    stroke-width: 3px;
    opacity: 1 !important;
}

/* Gruppe Rosa */
#Flurstück14.historical-mode,
#Flurstück31.historical-mode,
#Flurstück32.historical-mode,
#Flurstück92.historical-mode {
    fill: #ffd9d9 !important;
    /* Hellrosa */
    stroke-width: 3px;
    opacity: 1 !important;
}

/* Gruppe Gelb (Haus 29 vor Baujahr) */
#H29.historical-mode {
    fill: #ffff00 !important;
    /* Gelb */
    stroke-width: 3px;
    opacity: 1 !important;
}

/* Hover-Effekte für Historische Ansicht */
#Flurstück29.historical-mode:hover,
#Flurstück14.historical-mode:hover,
#Flurstück10.historical-mode:hover,
#Flurstück8.historical-mode:hover {
    stroke-width: 5px;
    filter: drop-shadow(0 0 6px rgba(174, 219, 52, 0.6));
}

#Flurstück31.historical-mode:hover,
#Flurstück32.historical-mode:hover {
    stroke-width: 5px;
    filter: drop-shadow(0 0 6px rgba(255, 217, 217, 0.6));
}

#H29.historical-mode:hover {
    stroke-width: 5px;
    filter: drop-shadow(0 0 6px rgba(255, 255, 0, 0.8));
}

/* ==========================================================
   3. TABELLEN-STYLING
   ========================================================== */
.table-container {
    flex: 0 1 700px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: none;
    max-height: 90vh;
    overflow-y: auto;
    position: sticky;
    top: 20px;
}

.table-container.active {
    display: block;
}

.table-header {
    padding: 15px;
    border-bottom: 1px solid #eee;
    background: #fafafa;
    position: sticky;
    top: 0;
    z-index: 10;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th,
td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

th {
    background: #f8f9fa;
    font-weight: 600;
    color: #555;
    position: sticky;
    top: 50px;
}

tr:nth-child(even) {
    background: #fcfcfc;
}

.quelle-cell {
    position: relative !important;
}

/* Datum-Spalte: Kein Umbruch */
th:nth-child(1),
td:nth-child(1) {
    white-space: nowrap;
    min-width: 90px;
}

/* ==========================================================
   4. LINK-STYLING & DESKTOP TOOLTIPS
   ========================================================== */
/* ==========================================================
   4. LINK-STYLING & DESKTOP TOOLTIPS
   ========================================================== */
.is-house-link,
.info-highlight-only,
.js-ext-link {
    color: #0056b3;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.year-link {
    color: inherit;
    border-bottom: 2px dotted #0056b3;
    font-weight: 500;
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.info-highlight-only {
    font-weight: bold;
    border-bottom: 2px dotted #0056b3;
    text-decoration: none;
    color: inherit;
}

.gb-ensemble {
    cursor: pointer;
    display: inline;
    position: relative;
    white-space: nowrap;
}

.gb-link-text {
    color: #0056b3;
    text-decoration: underline;
    font-weight: 500;
}

.digit-highlight {
    font-weight: 500;
    color: #444;
    padding: 0 2px;
    /* border-bottom entfernt */
}

/* Spezialfall: Keine Quelle verfügbar */
.gb-ensemble.no-link .gb-link-text {
    color: #888 !important;
    cursor: not-allowed !important;
}

.gb-ensemble.no-link .digit-highlight {
    color: #888 !important;
}

@keyframes fadeInSlide {
    from {
        opacity: 0;
        transform: translateY(5px) translateX(-50%);
    }

    to {
        opacity: 1;
        transform: translateY(0) translateX(-50%);
    }
}

/* --- ALLE DESKTOP HOVER EFFEKTE IN EINER KLAMMER --- */
@media (hover: hover) {

    /* Basiskonstruktion Tooltip */
    .is-house-link:hover::after,
    .info-highlight-only:hover::after,
    .js-ext-link:hover::after,
    .gb-ensemble:hover::after,
    .year-link:hover::after {
        display: block;
        position: absolute;
        bottom: 130%;
        left: 50%;
        transform: translateX(-50%);
        background: #333;
        color: white;
        padding: 4px 8px;
        border-radius: 4px;
        font-size: 10px;
        white-space: nowrap;
        z-index: 1000;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
        animation: fadeInSlide 0.2s ease-out forwards;
    }

    /* Texte zuweisen */
    .is-house-link:hover::after,
    .info-highlight-only:hover::after {
        content: "siehe Grafik";
    }

    .js-ext-link:hover::after {
        content: "externer Link";
    }

    .year-link:hover::after {
        content: "siehe Grafik";
        left: 0 !important;
        transform: none !important;
    }

    /* Gerichtsbücher Normalzustand */
    .gb-ensemble:not(.no-link):hover::after {
        content: "bitte die markierte Zahl merken";
    }

    .gb-ensemble:not(.no-link):hover .digit-highlight {
        color: #ffffff;
        background-color: #d32f2f;
        border-bottom-style: solid;
        transition: all 0.3s ease;
        /* Sanfter Übergang */
    }

    /* Gerichtsbücher ohne Link */
    .gb-ensemble.no-link:hover::after {
        content: "Link noch nicht gespeichert";
        background: #888;
    }

    .gb-ensemble.no-link:hover .digit-highlight {
        background-color: transparent !important;
    }

    /* Spezial-Regel für die rechte Spalte (Quelle) */
    .quelle-cell .gb-ensemble:hover::after {
        left: auto;
        /* Zentrierung aufheben */
        right: 0;
        /* Tooltip bündig an der rechten Kante des Elements */
        transform: none;
        /* Verschiebung nach links deaktivieren */
        white-space: nowrap;
        /* Sicherstellen, dass er einzeilig bleibt */
    }
}

/* ==========================================================
   5. MOBILE OPTIMIERUNG
   ========================================================== */
@media (pointer: coarse) {

    .notiz-cell,
    .quelle-cell,
    #houseInfo small {
        position: relative !important;
    }

    /* A) Das allgemeine Tooltip-Gehäuse */
    .is-primed-house::after,
    .is-primed-info::after,
    .is-primed-ext::after,
    .gb-ensemble.is-primed::after,
    .year-link.is-active::after {
        display: block;
        position: absolute;
        bottom: 140%;
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        min-width: 150px;
        max-width: 220px;
        white-space: normal;
        text-align: center;
        background: #333 !important;
        color: white !important;
        padding: 8px 12px;
        border-radius: 6px;
        font-size: 11px;
        line-height: 1.3;
        z-index: 10000;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
        pointer-events: none;
        animation: fadeInSlide 0.2s ease-out forwards;
    }

    /* B) Standard-Texte */
    .is-primed-house::after {
        content: "Haus markiert, für Aufruf erneut tippen";
    }

    .is-primed-info::after {
        content: "siehe Grafik";
    }

    .is-primed-ext::after {
        content: "externer Link, zum Aufruf erneut tippen";
    }

    .year-link.is-active::after {
        content: "siehe Grafik";
        left: 0 !important;
        transform: none !important;
        text-align: middle;
    }

    /* C) Gerichtsbücher Spezial (Zweizeilig) */
    .gb-ensemble.is-primed::after {
        content: var(--d, "Zahl") "\A & erneut tippen";
        white-space: pre-wrap;
    }

    /* D) AUSNAHME: Gerichtsbücher OHNE Link (Muss nach C stehen!) */
    .gb-ensemble.no-link.is-primed::after {
        content: "Link noch nicht gespeichert";
        background: #666 !important;
        white-space: normal;
        /* Zurück auf normaler Umbruch */
    }

    .highlight-hover,
    .active-group path,
    .active-element {
        stroke-width: 30px !important;
    }

    /* Spezial-Ausrichtung für Tooltips in der rechten Spalte am Handy */
    .quelle-cell .gb-ensemble.is-primed::after {
        left: auto;
        right: 0;
        transform: none;
    }

    /* Neu: Jahr-Link Tooltip soll nach rechts aufklappen (links bündig) */
    .quelle-cell .year-link.is-active::after {
        left: 0;
        right: auto;
        transform: none;
        text-align: left;
    }

    /* Falls es ein externer Link in der Quelle-Zelle ist, soll dieser auch nicht abschneiden */
    .quelle-cell .is-primed-ext::after {
        left: auto;
        right: 0;
        transform: none;
    }

    /* Markierung der Ziffer am Handy, wenn die Quelle angetippt wurde */
    .gb-ensemble:not(.no-link).is-primed .digit-highlight {
        color: #ffffff;
        background-color: #d32f2f;
        border-bottom-style: solid;
        padding: 0 2px;
        /* Kleiner Puffer für die rote Box */
        border-radius: 2px;
        /* Ecken leicht abrunden für modernen Look */
    }

}

/* ==========================================================
   6. OVERLAYS & SONSTIGES
   ========================================================== */
.info-trigger {
    cursor: help;
    background: #eee;
    border-radius: 50%;
    padding: 2px 7px;
    font-size: 0.85em;
    margin-left: 5px;
    font-weight: bold;
    border: 1px solid #ccc;
    display: inline-block;
}

.info-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
}

.info-overlay.active {
    opacity: 1;
    visibility: visible;
}

.info-content {
    background: white;
    padding: 25px;
    border-radius: 15px;
    width: 85%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    position: relative;
    overflow-y: auto;
    max-height: 90vh;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #aaa;
}

#tooltip {
    position: fixed;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid #ccc;
    padding: 8px 12px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: none;
    z-index: 1000;
    display: none;
    font-size: 13px;
}

@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
    }

    .table-container {
        flex: 1;
        min-width: 100%;
        max-height: none;
        position: static;
    }
}

@media (max-width: 600px) {
    .svg-container {
        min-width: 100% !important;
        /* Passt sich dem Handy an */
        padding: 5px;
        /* Weniger Rand für mehr Platz */
    }

    .slider-labels span {
        font-size: 9px !important;
    }

    /* Verstecke unwichtigere Jahre auf Handy */
    .slider-labels span:nth-child(2),
    /* 1600 */
    .slider-labels span:nth-child(4),
    /* 1700 */
    .slider-labels span:nth-child(5),
    /* 1750 */
    .slider-labels span:nth-child(8)

    /* 1900 */
        {
        display: none;
    }
}