/* Base Styles matching Mockup */
:root {
    --text-primary: #333;
    --text-meta: #777;
    --border-color: #d1d5db;
    --tab-inactive-bg: #fdfdfd;
    --tab-active-bg: #252E6B;
    /* User's specific button blue */
    --tab-active-text: #ffffff;
    --tab-inactive-text: #252E6B;
}

body {
    font-family: 'Lekton', monospace;
    color: var(--text-primary);
    margin: 0;
    padding: 1vh 0;
    /* Minimal vertical, zero horizontal to allow edge alignment */
    background-color: #ffffff;
    display: flex;
    justify-content: center;
    height: 100vh;
    /* force 100vh overall */
    box-sizing: border-box;
    overflow: hidden;
    /* disable body scrolling */
}

.map-container {
    max-width: 1400px;
    width: 100%;
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 0;
    position: relative;
    /* Base for absolute overlays */
}

/* Header Elements Decoupled */
.map-title-row {
    text-align: center;
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

.map-title-row h1 {
    font-size: 23px;
    line-height: 28px;
    font-weight: 400;
    letter-spacing: 0.5px;
    margin-top: 1vh;
    margin-bottom: 0;
    text-transform: uppercase;
    color: #00091D;
}

.map-subtitle-row {
    text-align: center;
    margin-top: 0.5rem;
    /* 0.5rem margin + 0.5rem title padding = 1rem */
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

.map-subtitle-row p {
    font-size: 18px;
    line-height: 22px;
    font-weight: 400;
    margin: 0;
    color: #00091D;
}

.map-tabs-row {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
    /* 0.5rem margin + 0.5rem subtitle padding = 1rem */
    padding-bottom: 0.5rem;
    flex-shrink: 0;
}

.species-tabs {
    display: flex;
    border: 2px solid var(--tab-active-bg);
    border-radius: 4px;
    overflow: hidden;
}

.map-legend-row {
    display: flex;
    justify-content: center;
    margin-top: 0.5rem;
    /* 0.5rem margin + 0.5rem tabs padding = 1rem */
    flex-shrink: 0;
}

.legend {
    display: flex;
    gap: 12px;
    font-size: 0.9375rem;
    line-height: normal;
    font-weight: 400;
    color: var(--text-meta);
    align-items: center;
}

.tab-btn {
    appearance: none;
    border: none;
    background: var(--tab-inactive-bg);
    color: var(--tab-inactive-text);
    padding: 8px 12px;
    font-family: 'Lekton', monospace;
    font-weight: 700;
    font-size: 0.9375rem;
    line-height: 15px;
    cursor: pointer;
    border-right: 2px solid rgb(37, 46, 107);
    transition: all 0.2s ease;
}

.tab-btn:last-child {
    border-right: none;
    border-radius: 0 3px 3px 0;
    /* User's specific radius */
}

.tab-btn.active {
    background: var(--tab-active-bg);
    color: var(--tab-active-text);
}

/* Legend */
.legend {
    display: flex;
    gap: 12px;
    font-size: 16px;
    /* Increased by ~1px from 0.9375rem (15px) */
    line-height: normal;
    font-weight: 400;
    color: var(--text-meta);
    align-items: center;
    margin-top: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.color-box {
    display: inline-block;
    width: 21px;
    /* 1.3x of 16px */
    height: 13px;
    /* 1.3x of 10px */
}

/* Search Box - Absolute Overlay */
.search-box {
    position: absolute;
    top: 190px;
    left: 0;
    z-index: 1000;
    width: 15rem;
    /* ~15px wider than 14rem */
    height: 2.3rem;
    /* ~5px taller than 2rem */
    background: rgb(255, 255, 255);
    padding: 0 0 0 calc(-4px + 2.3rem);
    border: 2px solid rgba(37, 46, 107, 0.4);
    border-radius: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    text-align: left;
    direction: ltr;
    box-sizing: border-box;
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: -2px;
    width: 15rem;
    /* ~15px wider than 14rem */
    box-sizing: border-box;
    max-height: 400px;
    background: white;
    border: 2px solid rgba(37, 46, 107, 0.4);
    border-radius: 4px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    z-index: 1001;
    font-family: 'Lekton', monospace;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */
}

.search-results::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.search-results div {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 16px;
    /* Scaled down font size */
    color: #252E6B;
    transition: background 0.2s;
    border-bottom: none;
}

.search-results div:hover {
    background: #f0f3ff;
}

.search-results.hidden {
    display: none;
}

/* Custom Scrollbar removed via display:none */

.search-icon {
    position: absolute;
    left: 8px;
    width: 18px;
    height: 18px;
    color: #1a237e;
    /* Darker blue like reference */
}

#search-input {
    border: none;
    outline: none;
    font-family: 'Lekton', monospace;
    font-size: 1.1rem;
    line-height: normal;
    font-weight: 400;
    color: rgb(37, 46, 107);
    width: 100%;
    background: transparent;
}

#search-input::placeholder {
    color: #b0b5c1;
}

/* Map SVG Area */
#d3-map-wrapper {
    width: 100%;
    flex: 1;
    /* Grow to fill available space in 100vh flex container */
    position: relative;
    overflow: hidden;
    padding-top: 10px;
    box-sizing: border-box;
}

.county-border {
    fill: none;
    stroke: #333;
    stroke-width: 0.8px;
    pointer-events: none;
    /* Ignore mouse over for counties */
}

/* The sub-grid squares */
.grid-cell {
    stroke: #ffffff;
    /* White borders between squares like mockup */
    stroke-width: 0.3px;
    cursor: pointer;
}

.grid-cell:hover {
    opacity: 0.8;
    stroke: #000;
    stroke-width: 1px;
}

/* Footer text */
.map-footer {
    margin-top: 10px;
    padding: 0;
    font-size: 0.9375rem;
    /* ~15px */
    font-weight: 400;
    line-height: normal;
    color: #888;
    text-align: justify;
    flex-shrink: 0;
}

.map-footer a {
    color: #888;
    text-decoration: underline;
}

/* Search Highlight */
.grid-cell.highlighted {
    stroke: #000;
    stroke-width: 1.5px;
    opacity: 1 !important;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(255, 255, 255, 0.98);
    border: none;
    /* Border removed */
    padding: 12px 16px;
    border-radius: 4px;
    pointer-events: none;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    font-family: 'Lekton', monospace;
    z-index: 1000;
    line-height: 1.2;
}

.tooltip-species {
    font-size: 19px;
    color: #252E6B;
    font-weight: 700;
}

.tooltip-settlement {
    font-size: 19px;
    color: #252E6B;
    font-weight: 700;
    margin-bottom: 4px;
}

.tooltip-likelihood {
    font-size: 18px;
    color: #252E6B;
    font-weight: 400;
}

.tooltip.hidden {
    display: none;
}

.tooltip.locked {
    pointer-events: auto;
    /* Allow clicking the close button */
}

.tooltip-close {
    position: absolute;
    top: 4px;
    right: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    color: #252E6B;
    line-height: 1;
}

.tooltip-close:hover {
    color: #d32f2f;
}

/* ========================================== */
/* Mobile Responsiveness                      */
/* ========================================== */
@media (max-width: 768px) {
    body {
        height: 100vh;
        overflow: hidden;
        padding: 5px 0;
    }

    .map-container {
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .map-title-row h1 {
        font-size: 18px;
        line-height: 22px;
    }

    .map-subtitle-row p {
        font-size: 14px;
        line-height: 18px;
        padding: 0 10px;
    }

    .tab-btn {
        padding: 6px 8px;
        font-size: 0.8rem;
    }

    .legend {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        font-size: 14px;
        margin-top: 10px;
        padding: 0 10px;
    }

    .search-box {
        position: relative;
        top: 0 !important;
        left: 0 !important;
        margin: 5px auto !important;
        width: 90% !important;
        max-width: 15rem !important;
        z-index: 100 !important;
        flex-shrink: 0;
    }

    #d3-map-wrapper {
        flex: 1;
        min-height: 0;
        padding: 0;
    }

    .map-footer {
        padding: 0 15px 20px 15px;
        font-size: 0.85rem;
    }

    .tooltip {
        padding: 8px 12px;
    }

    .tooltip-species,
    .tooltip-settlement {
        font-size: 16px;
    }

    .tooltip-likelihood {
        font-size: 15px;
    }
}