/* Unified Design System and Typography for Chrono-compass */

/* Import Google Font Inter */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* Base Layout & Typography */
body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #e5e5e5;
    overflow: hidden;
    color: #333;
}

/* ---------------------------------------------------- */
/* Typography Alignment Classes                         */
/* ---------------------------------------------------- */

/* Panel Headers and Titles */
.panel-header {
    background-color: #f8f9fa;
    /* bg-light */
    padding: 8px 12px;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    height: 40px;
    flex-shrink: 0;
    position: relative;
}

.panel-title {
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #333333;
    margin: 0;
    padding: 0;
    letter-spacing: -0.1px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    pointer-events: none;
    max-width: 65%;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

/* Panel Body Contents */
.panel-content-text {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 400;
    color: #333333;
    line-height: 1.4;
}

/* Year Labels */
.year-text {
    font-family: 'Inter', sans-serif;
    font-size: 10px;
    font-weight: 600;
    color: #555555;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Clickable Year Links */
.year-link {
    color: #0d6efd;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.15s ease;
}

.year-link:hover {
    color: #0a58ca;
}

/* ---------------------------------------------------- */
/* App Layout Elements                                  */
/* ---------------------------------------------------- */

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.4);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* 1. LEFT PANEL (Timeline, now on the right side) */
#left-panel {
    width: 380px;
    background: white;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 1000;
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
}

#left-panel.collapsed {
    width: 90px;
}

#left-panel.collapsed .panel-header {
    justify-content: center;
    padding: 8px 0;
}

#left-panel.collapsed .expanded-only {
    display: none !important;
}

/* Floating Time Controls (Map control, topright) */
.leaflet-style-control {
    background: #fff;
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    box-shadow: none;
    display: flex;
    align-items: center;
    padding: 0;
    width: 280px;
    justify-content: space-between;
}

.leaflet-style-control button {
    background: none;
    border: none;
    font-size: 14px;
    padding: 4px 8px;
    cursor: pointer;
    color: #444;
    border-right: 1px solid #ccc;
    transition: 0.2s;
}

.leaflet-style-control button:hover {
    background: #f4f4f4;
    color: #000;
}

.leaflet-style-control button:last-child {
    border-right: none;
}

.leaflet-style-control input {
    border: none;
    outline: none;
    text-align: center;
    font-weight: bold;
    width: 80px;
    font-size: 13px;
    color: #333;
    padding: 4px;
    border-right: 1px solid #ccc;
    background: #fff;
}

#map-bottom-left {
    position: absolute;
    bottom: 30px;
    left: 10px;
    z-index: 1000;
}

/* TIMELINE LAYOUT (Perfect alignment to slider) */
#timeline-wrapper {
    position: relative;
    flex-grow: 1;
    display: flex;
    margin: 15px 0;
}

#slider-container {
    width: 95px;
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    padding-right: 15px;
}

#year-slider {
    -webkit-appearance: slider-vertical;
    appearance: slider-vertical;
    width: 25px;
    height: 100%;
    margin: 0;
    cursor: pointer;
    position: relative;
    z-index: 5;
}

#year-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 16px;
    background-color: #0d6efd;
    border: none;
    border-radius: 0;
    cursor: pointer;
    -webkit-clip-path: polygon(100% 0, 100% 100%, 0 50%);
    clip-path: polygon(100% 0, 100% 100%, 0 50%);
}

#timeline-overlay {
    position: absolute;
    top: 12px;
    bottom: 12px;
    left: 0;
    right: 0;
    display: flex;
    pointer-events: none;
}

/* Left: Ticks & Years */
#timeline-left {
    width: 60px;
    position: relative;
    flex-shrink: 0;
}

.tick-container {
    position: absolute;
    right: 0;
    display: flex;
    align-items: center;
    transform: translateY(50%);
}

.tick-label {
    margin-right: 6px;
}

.tick-label.bound-label {
    font-weight: bold;
    color: #333;
}

.tick-line {
    width: 6px;
    height: 1px;
    background: #999;
}

/* Center spacer matching slider width */
#timeline-center-spacer {
    width: 20px;
    flex-shrink: 0;
    border-right: 1px solid transparent;
}

/* Right: Events */
#timeline-right {
    flex-grow: 1;
    position: relative;
    pointer-events: auto;
}

.event-point-container {
    position: absolute;
    left: 0;
    width: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
    transform: translateY(50%);
}

.event-dot {
    width: 6px;
    height: 6px;
    background: #0d6efd;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
    margin-left: -2px;
    flex-shrink: 0;
}

.event-period-container {
    position: absolute;
    left: 0;
    width: 100%;
    cursor: pointer;
}

.event-line {
    position: absolute;
    left: -2px;
    width: 6px;
    height: 100%;
    background: rgba(13, 110, 253, 0.6);
    border-radius: 2px;
}

/* Natural text wrap without truncation */
.event-title {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    color: #333;
    line-height: 1.15;
    padding: 2px 4px;
    border-radius: 3px;
}

.event-point-container .event-title {
    margin-left: 4px;
}

.event-period-container .event-title {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: calc(100% - 15px);
}

.event-point-container:hover .event-title,
.event-period-container:hover .event-title {
    background: #e9ecef;
    color: #0d6efd;
}

.event-popup-card {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 12px;
    width: 280px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1050;
    display: none;
    top: 60px;
    bottom: 130px;
    flex-direction: column;
}

/* MAP CONTAINER */
#map-container {
    flex-grow: 1;
    position: relative;
    height: 100%;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* 2. RIGHT PANEL (Polities, now on the left side) */
#right-panel {
    width: 250px;
    background: white;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    z-index: 1000;
    overflow: hidden;
    flex-shrink: 0;
}

#right-panel.collapsed {
    width: 60px;
}

#right-panel.collapsed .panel-header {
    justify-content: center;
    padding: 8px 0;
}

#right-panel.collapsed .panel-header .btn {
    margin-left: 0 !important;
}

#right-panel.collapsed .expanded-only {
    display: none !important;
}

#right-panel.collapsed #legend-content {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    padding: 5px;
    gap: 5px;
}

#right-panel.collapsed .legend-item {
    margin: 0;
    padding: 2px;
}

#right-panel.collapsed .legend-color {
    margin: 0;
    width: 22px;
    height: 22px;
}

#legend-content {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-grow: 1;
}

.legend-item {
    display: flex;
    align-items: center;
    padding: 6px;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 4px;
}

.legend-item:hover {
    background: #f0f0f0;
}

.legend-color {
    width: 16px;
    height: 16px;
    border: 1px solid #444;
    border-radius: 3px;
    margin-right: 10px;
    flex-shrink: 0;
}

/* Polity popup inside map */
.polity-popup h3 {
    margin: 0 0 5px 0;
    font-size: 16px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
}

.polity-popup p {
    margin: 0 0 5px 0;
    font-size: 13px;
    font-family: 'Inter', sans-serif;
}

.civ-tooltip {
    font-weight: bold;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #444;
    font-family: 'Inter', sans-serif;
}

/* City label tooltips: transparent background, pointer-events none (click-through) */
.city-label-tooltip {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    font-weight: 600;
    font-size: 12px;
    color: #333333 !important;
    pointer-events: none !important; /* click-through */
    text-shadow: 0 0 3px #ffffff, 0 0 3px #ffffff; /* text shadow for high map legibility */
    padding: 5px !important;
}

.city-label-tooltip::before {
    display: none !important;
}

/* Footer Styles */
.panel-footer {
    background-color: #f8f9fa;
    padding: 8px 12px;
    border-top: 1px solid #ddd;
    font-family: 'Inter', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #333333;
    text-align: center;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.footer-link {
    color: #0d6efd;
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease;
}

.footer-link:hover {
    text-decoration: underline;
    color: #0a58ca;
}

/* About Modal/Popup Styles */
.about-popup-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1999;
    display: none;
}

.about-popup-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 12px;
    width: 1000px;
    height: 800px;
    max-width: 95%;
    max-height: 90%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    display: none;
    flex-direction: column;
}

/* City event details hover and click effects */
.city-event-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    align-items: baseline;
    padding: 2px 6px;
    margin: 2px -6px;
}

.city-event-item {
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.15s;
}

.city-event-item:hover {
    background-color: #e9ecef;
}

.city-event-item:hover .city-event-info,
.city-event-item:hover .year-link {
    color: #0d6efd;
}