body {
    margin: 0;
    padding: 0;
}

#map {
    height: 80vh;
    width: 100%;
    position: relative;
    z-index: 1;
    /* Lower z-index for the map */
}

.timeline-container {
    height: 20vh;
    width: 100%;
    padding: 20px 50px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;

    position: relative;
    z-index: 2;
    /* Higher z-index for timeline and tooltips */
    background: white;
    /* Ensures timeline area is opaque */
}

#timeline {
    width: 100%;
    height: 25px;
    position: relative;
    overflow: visible;
}

#year-display {
    font-size: 24px;
    margin: 10px 0;
    font-family: Arial, sans-serif;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 250px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px 8px;
    border-radius: 4px;
    position: relative;
    display: inline-block;
}

#year-display:hover {
    background-color: #f3f4f6;
    color: #1f2937;
    transform: scale(1.02);
}

#year-display:focus-within {
    background-color: #eff6ff;
    transform: scale(1.02);
}

/* Style for the input when editing */
#year-display input {
    font-size: inherit !important;
    font-family: inherit !important;
    font-weight: inherit !important;
    border: 2px solid #3b82f6 !important;
    border-radius: 4px !important;
    padding: 2px 6px !important;
    background: white !important;
    color: #1f2937 !important;
    width: 120px !important;
    text-align: center !important;
    outline: none !important;
    margin: 0 !important;
}

/* Responsive year display for tablets and mobile */
@media (max-width: 768px) {
    #year-display {
        font-size: 18px;
        min-width: 180px;
    }
}

@media (max-width: 640px) {
    #year-display {
        font-size: 16px;
        min-width: 160px;
    }
}

.timeline-marker {
    width: 20px;
    height: 20px;
    background: #2b4c82;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
    position: absolute;
    bottom: 1px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 5;
}

/* .timeline-marker::after {
    content: '';
    position: absolute;
    bottom: -5px;
    left: -8px;
    width: 24px;
    height: 24px;
    background: #2b4c82;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
} */

.timeline-marker:hover {
    transform: scale(1.2);
}

.timeline-marker:hover::after {
    background: #3b82f6;
    transform: scale(1.2);
}

.timeline-tooltip {
    position: absolute;
    bottom: 35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.95);
    /* Darker, slightly transparent */
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 6;
    /* Highest z-index for tooltips */
}

/* Tooltip visibility is now controlled by JavaScript */


.timeline-tooltip::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 8px;
    height: 8px;
    background: rgba(30, 41, 59, 0.95);
}


.tooltip-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.tooltip-hebrew {
    font-family: 'Arial Hebrew', Arial, sans-serif;
    direction: rtl;
    font-size: 14px;
    font-weight: bold;
}

.tooltip-english {
    font-size: 12px;
    color: #e2e8f0;
}

.tooltip-year {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
}

.tooltip-link {
    margin-top: 4px;
}

.tooltip-link a {
    color: #3b82f6 !important;
    text-decoration: underline !important;
    font-size: 11px !important;
    transition: color 0.2s ease;
}

.tooltip-link a:hover {
    color: #1d4ed8 !important;
}

.custom-popup {
    direction: rtl;
}

.custom-popup .leaflet-popup-content-wrapper {
    border-radius: 8px;
}

.custom-popup .leaflet-popup-content {
    margin: 12px;
    min-width: 200px;
}

.floating-icon {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 80px;
    height: 80px;
    z-index: 4;
    filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.2));
    transition: transform 0.3s ease;
}

/* Responsive sizing for different screen sizes */
@media (max-width: 1400px) {
    .floating-icon {
        width: 70px;
        height: 70px;
        top: 18px;
        right: 18px;
    }
}

@media (max-width: 1200px) {
    .floating-icon {
        width: 60px;
        height: 60px;
        top: 15px;
        right: 15px;
    }
}

@media (max-width: 1024px) {
    .floating-icon {
        width: 50px;
        height: 50px;
        top: 12px;
        right: 12px;
    }
}

@media (max-width: 768px) {
    .floating-icon {
        width: 45px;
        height: 45px;
        top: 10px;
        right: 10px;
    }
}

@media (max-width: 640px) {
    .floating-icon {
        width: 40px;
        height: 40px;
        top: 8px;
        right: 8px;
    }
}

/* Specific adjustment for tablets in landscape mode */
@media (min-width: 1024px) and (max-width: 1400px) and (orientation: landscape) {
    .floating-icon {
        width: 55px;
        height: 55px;
        top: 12px;
        right: 12px;
    }
}

/* Additional safety margin for tablets to avoid header overlap */
@media (min-width: 768px) and (max-width: 1400px) {
    .floating-icon {
        top: 80px; /* Move below header area */
    }
}

/* Override for very small tablets to keep icon in corner */
@media (max-width: 900px) {
    .floating-icon {
        top: 12px;
    }
}

/* Historical Periods Timeline */
#historical-periods {
    margin: 12px 0 20px 0;
}

.period-bar {
    height: 100%;
    cursor: pointer;
    transition: all 0.2s ease;
    position: absolute;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.period-text {
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.7);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    padding: 0 2px;
}

/* Year labels container */
#historical-periods .relative {
    height: 20px;
    margin-bottom: 8px;
}

.period-bar:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
}

.period-bar::after {
    content: attr(data-period);
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 20;
}

.period-bar:hover::after {
    opacity: 1;
}

/* Responsive adjustments for historical periods */
@media (max-width: 768px) {
    #historical-periods .relative {
        height: 12px;
    }
    
    .period-text {
        font-size: 8px;
    }
    
    .period-bar::after {
        font-size: 9px;
        top: -18px;
    }
    
    #historical-periods .flex.justify-between {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    #historical-periods .relative {
        height: 10px;
    }
    
    .period-text {
        font-size: 7px;
    }
    
    .period-bar::after {
        font-size: 8px;
        top: -16px;
    }
    
    #historical-periods .flex.justify-between {
        font-size: 9px;
    }
}

/* Hide text on very small periods */
@media (max-width: 640px) {
    .period-bar[data-period="Early Modern"] .period-text,
    .period-bar[data-period="Modern"] .period-text {
        display: none;
    }
}

.floating-icon:hover {
    transform: scale(1.1);
    /* cursor: pointer; */
}

.floating-icon svg {
    width: 100%;
    height: 100%;
}

.map-container {
    position: relative;
    height: calc(100vh - 150px);
    background-color: #f8fafc;
}

/* Arrow styling */
.historical-arrow {
    stroke-dasharray: 5, 5;
    animation: dash 2s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: -10;
    }
}

.arrowhead-marker {
    transition: all 0.3s ease;
}

.arrowhead-marker:hover {
    transform: scale(1.2);
}

/* Speed control styling */
#speedControl {
    -webkit-appearance: none;
    appearance: none;
    background: #e5e7eb;
    outline: none;
    border-radius: 8px;
}

#speedControl::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
}

#speedControl::-webkit-slider-thumb:hover {
    background: #2563eb;
    transform: scale(1.1);
}

#speedControl::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

#speedControl::-moz-range-thumb:hover {
    background: #2563eb;
    transform: scale(1.1);
}

/* Map center selector styling */
#mapCenterSelector {
    transition: all 0.2s ease;
}

#mapCenterSelector:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px #3b82f6;
}

#mapCenterSelector:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Tile selector styling */
#tileSelector {
    transition: all 0.2s ease;
}

/* Clustering control slider styling */
.slider {
    -webkit-appearance: none;
    appearance: none;
    background: #d1d5db;
    outline: none;
    border-radius: 5px;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: #3b82f6;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #3b82f6;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.slider:hover::-webkit-slider-thumb {
    background: #2563eb;
    transform: scale(1.1);
}

.slider:hover::-moz-range-thumb {
    background: #2563eb;
    transform: scale(1.1);
}

#tileSelector:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px #3b82f6;
}

#tileSelector:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Extended container for timeline and controls */
.timeline-section {
    max-width: none;
    width: 100%;
    padding: 0 5%;
}

/* Responsive padding for different screen sizes */
@media (min-width: 640px) {
    .timeline-section {
        padding: 0 10%;
    }
}

@media (max-width: 640px) {
    .timeline-section {
        padding: 0 2%;
    }
}

/* Laptop display optimizations (1920x1080) */
@media (min-width: 1024px) and (max-width: 1920px) and (max-height: 1200px) {
    .timeline-section {
        padding: 0 3%;
    }
    
    #year-display {
        font-size: 0.875rem;
        min-width: 200px;
    }
    
    .controls .flex {
        gap: 0.2rem;
    }
    
    .controls input[type="range"] {
        width: 40px;
        height: 3px;
    }
    
    /* Make clustering slider more compact on FHD */
    #clusterRadius {
        width: 80px !important;
        height: 3px !important;
    }
    
    #clusterValue {
        width: 20px !important;
        font-size: 0.7rem !important;
    }
    
    label[for="clusterRadius"] {
        font-size: 0.8rem !important;
    }
    
    .controls select {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
        min-width: 70px;
    }
    
    .controls input[type="text"] {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
        width: 60px;
    }
    
    .controls button {
        font-size: 0.7rem;
        padding: 0.2rem 0.4rem;
    }
    
    /* Make year step buttons more compact */
    #year-steps button {
        padding: 0.1rem 0.2rem;
        font-size: 0.6rem;
    }
    
    /* Make speed control more compact */
    #speedControl {
        width: 35px !important;
    }
    
    #speedDisplay {
        width: 15px !important;
        font-size: 0.7rem !important;
    }
    
    label[for="speedControl"] {
        font-size: 0.8rem !important;
    }
    
    /* Header optimizations for FHD displays */
    header {
        padding: 0.25rem 0;
    }
    
    header h1 {
        font-size: 1rem;
        line-height: 1.1;
    }
    
    header button {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    header .flex {
        gap: 0.25rem;
    }
    
    /* Year display optimization for FHD */
    #year-display {
        min-width: 145px;
        max-width: 145px;
        font-size: 0.85rem;
    }
    
    /* Fixed width for 4K displays to prevent shaking */
    @media (min-width: 1920px) {
        #year-display {
            width: 300px !important;
            min-width: 300px !important;
            max-width: 300px !important;
            font-size: 0.85rem;
        }
    }
}

/* Custom cluster icon styling */
.custom-cluster-icon {
    background: transparent !important;
    border: none !important;
}

.custom-cluster-icon div {
    transition: all 0.3s ease;
}

.custom-cluster-icon:hover div {
    transform: scale(1.1);
    background-color: #2563eb !important;
}

/* Community marker styles */
.custom-marker {
    transition: all 0.3s ease;
}

.custom-marker:hover {
    transform: scale(1.15);
    z-index: 1000;
}

.custom-marker div {
    transition: all 0.3s ease;
}

.custom-marker:hover div {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

/* Population marker specific styles */
.population-marker {
    font-family: 'Arial', sans-serif;
    font-weight: bold;
    text-align: center;
    line-height: 1;
}

.population-marker-small {
    font-size: 8px;
}

.population-marker-medium {
    font-size: 10px;
}

.population-marker-large {
    font-size: 12px;
}

.info-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
}

/* Search marker animation */
@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Search marker styles */
.search-marker {
    transition: all 0.3s ease;
}

.search-marker:hover {
    transform: scale(1.1);
    z-index: 1000;
}

/* Play Button Arrow */
#playButtonArrow {
    animation: blink 1.5s infinite;
    z-index: 1000;
    pointer-events: none; /* Prevent interference with button clicks */
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* Hide arrow on small screens to avoid layout issues */
@media (max-width: 640px) {
    #playButtonArrow {
        display: none;
    }
}

/* RTL Language Support */
.rtl {
    direction: rtl;
}

.rtl .floating-icon {
    left: 20px;
    right: auto;
}

.rtl .timeline-section {
    text-align: right;
}

.rtl .period-text {
    text-align: center;
}

.rtl .tooltip-hebrew {
    direction: rtl;
    text-align: right;
}

.rtl .custom-popup {
    direction: rtl;
    text-align: right;
}

.rtl .custom-popup .leaflet-popup-content {
    text-align: right;
}

/* RTL adjustments for header */
.rtl header .flex {
    flex-direction: row-reverse;
}

.rtl header .flex .flex {
    flex-direction: row-reverse;
}

/* RTL adjustments for controls */
.rtl .timeline-section .flex {
    flex-direction: row-reverse;
}

.rtl .timeline-section .flex > div {
    flex-direction: row-reverse;
}

/* RTL adjustments for control labels and inputs */
.rtl .timeline-section .flex > div.flex {
    flex-direction: row-reverse;
}

/* RTL adjustments for control groups */
.rtl .timeline-section .flex > div.flex.items-center {
    flex-direction: row-reverse;
}

/* Ensure labels appear on the right side of controls in RTL */
.rtl .timeline-section label {
    order: 3;
    margin-left: 0.5rem;
    margin-right: 0;
}

.rtl .timeline-section input,
.rtl .timeline-section select,
.rtl .timeline-section button {
    order: 2;
}

.rtl .timeline-section span {
    order: 1;
    margin-left: 0;
    margin-right: 0.5rem;
}

/* RTL adjustments for year display */
.rtl .timeline-section #year-display {
    text-align: right;
}

/* RTL adjustments for year step buttons */
.rtl .timeline-section #year-steps {
    flex-direction: row-reverse;
}

/* RTL adjustments for historical periods timeline */
.rtl .timeline-section #historical-periods .relative {
    text-align: right;
}

/* RTL adjustments for search control group - specific ordering */
.rtl .timeline-section #citySearch {
    order: 2;
}

.rtl .timeline-section #clearSearch {
    order: 1;
    margin-right: 0.5rem;
    margin-left: 0;
}

.rtl .timeline-section label[for="citySearch"] {
    order: 3;
}

/* RTL layout for search control group - using more compatible selectors */
.rtl .timeline-section .flex > div.flex.items-center {
    flex-direction: row-reverse;
}

/* RTL adjustments for modals */
.rtl .modal-content {
    text-align: right;
}

.rtl .modal-content ul {
    text-align: right;
}

.rtl .modal-content .flex {
    flex-direction: row-reverse;
}

/* RTL adjustments for tour modal */
.rtl #tourContent {
    text-align: right;
}

.rtl #tourContent h3,
.rtl #tourContent p {
    text-align: right;
}

/* RTL adjustments for language switcher */
.rtl #languageSwitcher {
    flex-direction: row-reverse;
}

/* Print styles */
@media print {
    .controls {
        display: none !important;
    }
    
    #timeline {
        display: none !important;
    }
    
    #year-steps {
        display: none !important;
    }
    
    /* Hide historical periods timeline from print */
    #historical-periods {
        display: none !important;
    }
    
    /* Hide historical period bars and labels */
    .period-bar {
        display: none !important;
    }
    
    /* Hide year labels below historical periods */
    #historical-periods .flex.justify-between {
        display: none !important;
    }
    
    /* Hide clustering control from print */
    #clusterRadius {
        display: none !important;
    }
    
    #clusterValue {
        display: none !important;
    }
    
    /* Hide clustering label from print */
    label[for="clusterRadius"] {
        display: none !important;
    }
    
    /* Hide work in progress message from print */
    .bg-yellow-50 {
        display: none !important;
    }
    
    .leaflet-control-container {
        display: none !important;
    }
    
    #map {
        height: 90vh !important;
        width: 100% !important;
        max-width: 100% !important;
        position: relative !important;
    }
    
    .leaflet-container {
        height: 90vh !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .leaflet-map-pane {
        height: 90vh !important;
        width: 100% !important;
    }
    
    .leaflet-tile-pane {
        height: 90vh !important;
        width: 100% !important;
    }
    
    body {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }
    
    .print-header {
        margin-bottom: 10px !important;
    }
    
    /* Ensure the map takes full width and height */
    .map-container {
        width: 100% !important;
        height: 90vh !important;
    }
    
    /* Edge-specific print fixes - more aggressive approach */
    @supports (-ms-ime-align: auto) {
        #map {
            height: 100vh !important;
            width: 100vw !important;
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            z-index: 1 !important;
        }
        
        .leaflet-container {
            height: 100vh !important;
            width: 100vw !important;
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
        }
        
        .leaflet-map-pane {
            transform: none !important;
            position: relative !important;
        }
        
        .leaflet-tile-pane {
            transform: none !important;
            position: relative !important;
        }
        
        .leaflet-marker-pane {
            transform: none !important;
            position: relative !important;
        }
        
        .leaflet-popup-pane {
            transform: none !important;
            position: relative !important;
        }
        
        .leaflet-shadow-pane {
            transform: none !important;
            position: relative !important;
        }
        
        .leaflet-overlay-pane {
            transform: none !important;
            position: relative !important;
        }
    }
    
    /* Additional Edge print compatibility */
    @media print and (-ms-high-contrast: none), (-ms-high-contrast: active) {
        #map {
            height: 100vh !important;
            width: 100vw !important;
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
            z-index: 1 !important;
        }
        
        .leaflet-container {
            height: 100vh !important;
            width: 100vw !important;
            position: fixed !important;
            top: 0 !important;
            left: 0 !important;
        }
        
        .leaflet-map-pane {
            transform: none !important;
            position: relative !important;
        }
        
        .leaflet-tile-pane {
            transform: none !important;
            position: relative !important;
        }
    }
    
    /* Modern Edge (Chromium-based) print fixes */
    @media print {
        .leaflet-container {
            transform: none !important;
        }
        
        .leaflet-map-pane {
            transform: none !important;
        }
        
        .leaflet-tile-pane {
            transform: none !important;
        }
        
        .leaflet-marker-pane {
            transform: none !important;
        }
        
        .leaflet-popup-pane {
            transform: none !important;
        }
        
        .leaflet-shadow-pane {
            transform: none !important;
        }
        
        .leaflet-overlay-pane {
            transform: none !important;
        }
    }
}