body,
html {
    overflow: hidden;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    font-family: 'Lekton', sans-serif;
    background-color: #ffffff;
    /* pure white background overall */
}

/* MapLibre reset */
.maplibregl-map {
    position: absolute !important;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    font-family: "Lekton", sans-serif !important;
}

/* Main Layout Setup */
.container {
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    height: 100%;
}

.top-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    z-index: 10;
}

.top-controls span {
    color: #252e6b;
    font-size: 18px;
    margin-right: 15px;
    font-weight: 400;
}

/* Custom Dropdown Styles */
.custom-select-wrapper {
    position: relative;
    display: inline-block;
    font-family: 'Lekton', monospace;
    font-size: 20px;
    color: #252e6b;
    z-index: 1000;
}

.custom-select-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 25px 2px 10px;
    font-weight: 400;
    cursor: pointer;
    border-bottom: 2px solid #252e6b;
    background: url("data:image/svg+xml;utf8,<svg viewBox='0 0 140 140' width='20' height='20' xmlns='http://www.w3.org/2000/svg'><g><polyline points='0,40 50,100 100,40' fill='none' stroke='rgb(37,46,107)' stroke-width='12px'/></g></svg>") no-repeat right 5px center;
    background-size: 14px;
    min-width: 260px;
    transition: all 150ms ease;
    text-align: center;
    box-sizing: border-box;
    white-space: nowrap;
    line-height: 1.4;
}

.trigger-text {
    position: absolute;
    left: 10px;
    right: 30px;
    top: 50%;
    transform: translateY(-50%);
    text-align: center;
}

.longest-option-ghost {
    visibility: hidden;
    pointer-events: none;
}

.custom-select-options {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    margin-top: 5px;
    background: #ffffff;
    border: 2px solid #252e6b;
    display: none;
    flex-direction: column;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 1001;
    box-sizing: border-box;
}

.custom-select-wrapper.open .custom-select-options {
    display: flex;
}

.custom-option {
    padding: 10px 20px;
    cursor: pointer;
    text-align: center;
    transition: background 0.2s;
    background: #ffffff;
    white-space: nowrap;
}

.custom-option:hover {
    background: #e6e6e6;
}

.custom-option.selected {
    background: #f0f0f0;
}

.container-map {
    flex-grow: 1;
    position: relative;
    /* important so absolute children stick here */
}

#maplibre-map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    background-color: #ffffff;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

#maplibre-map.loaded {
    opacity: 1;
}

.container-timeline {
    position: relative;
    flex-grow: 0;
    flex-shrink: 0;
    height: 120px;
    /* Fixed rough height for the timeline area */
    background: #fff;
    user-select: none;
}

.sidebar-controls {
    position: absolute;
    top: 20px;
    left: 20px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: 10px;
}

.timeline-controls {
    pointer-events: none;
}

.timeline-controls ul {
    pointer-events: all;
    background: transparent;
    list-style-type: none;
    display: -ms-flexbox;
    display: flex;
    margin: 0 .5rem .5rem 0;
    padding: 0;
    border-radius: 4px;
    font-weight: 800;
    text-transform: uppercase;
    font-size: 10px;
    box-shadow: 0 0 4px rgba(0, 0, 0, .35);
    border: 2px solid currentColor;
    color: #fff;
    float: left;
}

.timeline-controls ul li {
    padding: 1px 6px;
    line-height: 20px;
    cursor: pointer;
    margin: 0;
    background: rgba(0, 0, 0, 0.25);
    transition: all 0.2s;
}

.timeline-controls ul li.selected {
    background: #fff;
    color: #333;
}

.timeline-controls ul li:first-child {
    border-radius: 3px 0 0 3px;
}

.timeline-controls ul li:last-child {
    border-radius: 0 3px 3px 0;
}


/* Legend */
.event-counter {
    text-shadow: none;
    pointer-events: none;
    user-select: none;
    display: inline-flex;
    flex-direction: column;
}

.event-counter.legend {
    background: #252E6B;
    color: #FFDD00;
    padding: 12px 16px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    position: relative;
    top: auto;
    left: auto;
    width: 200px;
    /* Fixed width to prevent jitter */
}

.event-counter.legend .counter-item {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.event-counter.legend .counter-item:last-child {
    margin-bottom: 0;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    flex-shrink: 0;
}

.legend-label {
    flex-grow: 1;
    margin-right: 8px;
    color: #FFDD00;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.event-counter.legend .counter-item-value {
    text-align: right;
    font-weight: 500;
    font-size: 14px;
    min-width: 35px;
    /* Fixed space for numbers */
    flex-shrink: 0;
}

/* Play/Pause Button */
.timeline-playback-button {
    position: absolute;
    top: 50%;
    /* center in the timeline height */
    transform: translateY(-50%);
    left: 21px;
    width: 32px;
    height: 32px;
    border: 1px solid #252E6B;
    border-radius: 50%;
    background: #252E6B;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    outline: none;
    z-index: 10;
}

.timeline-playback-button:after {
    /* Using FontAwesome unicode via CSS content */
    content: '\f04c';
    /* pause icon */
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    color: #FFD500;
    line-height: 32px;
    position: absolute;
    font-size: 0.85rem;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
}

.timeline-playback-button.paused:after {
    content: '\f04b';
    /* play icon */
    left: 2px;
    /* slight visual offset for play triangle to look perfectly centered */
}

.timeline-playback-button:hover {
    background: #1b2251;
}

/* Chart SVG Base Rules */
#timeline-chart {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin-left: 70px;
    /* Leave space for play button */
}

svg {
    display: block;
    transform: translate3d(0, 0, 0);
}

svg .tick text {
    font-family: "Lekton", sans-serif;
    font-size: 12px;
}

svg .domain {
    display: none;
    /* hide main axis lines nicely */
}

svg .x-axis .domain,
svg .y-axis .domain {
    display: block;
    stroke: #000;
    stroke-width: 1px;
}

/* Make sure titles don't get trapped by pointer events */
.map-title {
    pointer-events: none;
    text-align: center;
    margin: 0;
    padding: 16px 0;
    font-weight: 400;
    font-size: clamp(18px, 4vw, 24px);
    letter-spacing: 0.5px;
    background: #fff;
    color: #252E6B;
    /* ensures clean solid background at top */
    z-index: 1000;
    /* Force hardware acceleration and clean rendering to prevent accent glitches on Mac */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transform: translateZ(0);
}

/* D3 Timeline SVG Styles */
.line-invazios {
    fill: none;
    stroke: #ffd500;
    stroke-width: 2;
}

.line-oshonos {
    fill: none;
    stroke: #00bfff;
    stroke-width: 2;
}

.line-masik {
    fill: none;
    stroke: #b70141;
    stroke-width: 2;
}

/* Interactive scrubber */
.scrubber-line {
    stroke: #333;
    stroke-width: 2;
}

/* MapLibre Tooltip Styles */
.mapboxgl-popup {
    z-index: 1000;
    /* Exactly as Flourish: using the SVG filter from index.html */
    filter: url(#dropshadow-1000) !important;
    /* Ensure the shadow isn't clipped by the parent container */
    overflow: visible !important;
}

.mapboxgl-popup-content {
    padding: 15px 20px !important;
    border-radius: 4px !important;
    box-shadow: none !important;
    /* Remove standard box-shadow since we use the SVG filter */
    background: #fff !important;
    font-family: 'Source Sans Pro', sans-serif !important;
    font-size: 14px !important;
    color: #333 !important;
    pointer-events: none;
    /* Keep pointer-events none as it was */
    line-height: 1.1;
    /* Keep line-height as it was */
    border: none !important;
    /* Keep border none as it was */
}

.mapboxgl-popup-tip {
    border-top-color: #fff !important;
    border-bottom-color: #fff !important;
}

.mapboxgl-popup-content strong {
    font-weight: 700;
    color: #444;
}

.mapboxgl-popup-close-button {
    display: none;
}

.scrubber-handle {
    fill: #333;
    cursor: pointer;
}

.scrubber-text {
    font-size: 10px;
    fill: #333;
    font-weight: bold;
    text-anchor: middle;
}

/* ========================================== */
/* Mobile Responsiveness                      */
/* ========================================== */
@media (max-width: 768px) {
    .top-controls span {
        font-size: 16px !important;
    }

    .custom-select-wrapper {
        font-size: 15px !important;
        min-width: 0 !important;
    }

    .custom-select-trigger {
        min-width: 0 !important;
        padding: 2px 25px 2px 10px;
    }

    .custom-option {
        font-size: 15px !important;
    }

    .event-counter.legend {
        width: 160px;
        padding: 8px 12px;
        font-size: 11px;
    }

    .sidebar-controls {
        top: 10px;
        left: 10px;
    }
}