/* Styles specific to the letter communications view */

#legal-fight .communications-container,
.communications-container {
    isolation: isolate;
    overflow: visible;
}

/* Cumulative time slider */
.flow-time-slider-container {
    position: relative;
    z-index: 1000;
    width: 90%;
    max-width: 1200px;
    margin: 0 auto 15px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(255,255,255,0.9) 0%, rgba(245,245,245,0.9) 100%);
    border: 1px solid var(--accent, #a67b5b);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    font-family: 'Inter', sans-serif;
}

.flow-time-slider-container.hidden {
    display: none;
}

.flow-time-slider-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary, #1a2a40);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.flow-time-slider-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.flow-time-slider {
    flex: 1;
    min-width: 120px;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    background: linear-gradient(to right, var(--accent, #a67b5b) 0%, var(--accent, #a67b5b) var(--slider-pct, 100%), #e0e0e0 var(--slider-pct, 100%), #e0e0e0 100%);
    border-radius: 4px;
    outline: none;
}

.flow-time-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary, #1a2a40);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.flow-time-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary, #1a2a40);
    cursor: pointer;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.flow-time-display {
    min-width: 100px;
    font-size: 13px;
    font-weight: 500;
    color: var(--neutral-dark, #333);
}

/* Map container styling - overflow hidden so panels don't persist when scrolling */
.map-container-communications {
    position: relative;
    width: 90vw;
    height: calc(100vh - 150px);
    overflow: hidden;
    margin: 0 auto;
    max-width: 1200px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    isolation: isolate;
}

#communications-map {
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

/* Section header to contain title and selector stacked vertically */
.section-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-bottom: 15px;
}

.section-header .section-subtitle-wrapper {
    width: 100%;
    text-align: center;
    margin-bottom: 10px;
}

#diplomat-selector-container {
    width: 90%; /* Set width to 90% */
    overflow: visible; /* Changed from hidden to visible */
    margin: 5px auto; /* Center the selector container */
    padding: 10px 0;
    font-family: 'Inter', sans-serif;
    z-index: 1000;
    display: flex;
    align-items: center;
    box-sizing: border-box;
    max-width: 1200px; /* Set a max-width for larger screens */
}

#diplomat-selector-heading {
    font-size: 1.6rem;
    margin-top: 20px;
    margin-bottom: 20px;
    color: var(--primary);
    position: relative;
    padding: 0;
    font-family: 'Playfair Display', serif;
    text-align: center; /* Center the text */
    display: inline-block; /* Keep as inline-block */
}

#diplomat-selector-heading::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%); /* Center the underline */
    width: 80px;
    height: 2px;
    background-color: var(--accent);
    border-radius: 2px;
}

/* Custom styling for the dropdown */
#diplomat-selector {
    width: 100%;
    padding: 12px 15px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    color: var(--neutral-dark);
    background-color: var(--neutral-light);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    margin-top: 5px;
    max-width: none; /* Ensure no max-width restriction */
    font-weight: 500; /* Slightly bolder text */
    cursor: pointer;
    
    padding-right: 40px; /* Make room for the custom arrow */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
}

/* Remove default arrow in IE */
#diplomat-selector::-ms-expand {
    display: none;
}

/* Style the dropdown options */
#diplomat-selector option {
    padding: 8px;
    background-color: var(--neutral-light);
    color: var(--neutral-dark);
    font-family: 'Inter', sans-serif;
}

/* Limit dropdown height in Chrome/Safari */
select#diplomat-selector {
    background-color: var(--neutral-light);
}

/* This is a hack to limit dropdown height in modern browsers */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    select#diplomat-selector {
        height: 40px; /* Height of the select element */
    }

    select#diplomat-selector[size]:focus {
        height: 200px; /* Height of the dropdown when open */
    }
}

/* For Firefox */
@-moz-document url-prefix() {
    #diplomat-selector {
        overflow-y: auto;
        max-height: 200px; /* Reduced from 300px */
        scrollbar-width: thin;
        scrollbar-color: var(--accent) #f1f1f1;
    }
}

/* For Chrome and other browsers that support these properties */
#diplomat-selector::-webkit-scrollbar {
    width: 6px; /* Thinner scrollbar */
}

#diplomat-selector::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#diplomat-selector::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 4px;
}

#diplomat-selector::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}

#diplomat-selector:focus {
    border-color: var(--secondary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(166, 123, 91, 0.25);
}

/* Diplomat description box below the selector */
#diplomat-description {
    width: 90%;
    overflow: hidden;
    margin: 0 auto; /* Center the map container */
    max-width: 1200px; /* Set a max-width for larger screens */
    padding: 15px 20px;
    background-color: var(--mint-beige);
    border-radius: 6px;
    font-family: 'Inter', sans-serif;
    line-height: 1.5;
    color: var(--neutral-dark);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    margin-top: 15px;
    margin-bottom: 20px;
}

#diplomat-description .initial-message {
    color: #888;
    font-style: italic;
    text-align: center;
    padding: 10px 0;
    font-size: 16px;
}

/* Selected diplomat portrait card (portrait + bio side by side) */
.diplomat-selected-card {
    display: flex;
    gap: 18px;
    align-items: flex-start;
}

.diplomat-selected-portrait {
    width: 120px;
    height: 150px;
    object-fit: cover;
    object-position: top;
    border-radius: 6px;
    border: 1px solid var(--accent);
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.diplomat-selected-info {
    flex: 1;
    min-width: 0;
}

.diplomat-selected-name {
    font-family: 'Playfair Display', serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 4px;
    line-height: 1.3;
}

.diplomat-selected-title {
    font-size: 13px;
    color: var(--secondary);
    font-style: italic;
    margin-bottom: 8px;
}

.diplomat-selected-bio {
    font-size: 13px;
    line-height: 1.5;
    color: var(--neutral-dark);
    margin: 0 0 8px 0;
}

.diplomat-selected-source {
    font-size: 11px;
    color: #888;
}

/* Portrait shown inside the popup, below the name */
.popup-portrait-img {
    display: block;
    width: 90px;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid var(--accent, #8B4513);
    margin: 6px auto 8px;
    cursor: zoom-in;
    transition: opacity 0.15s;
}
.popup-portrait-img:hover {
    opacity: 0.85;
}

/* Portrait lightbox */
#portrait-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
    z-index: 99999;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    cursor: zoom-out;
}
#portrait-lightbox.open {
    display: flex;
}
#portrait-lightbox-img {
    max-width: min(480px, 90vw);
    max-height: 75vh;
    object-fit: contain;
    border-radius: 6px;
    border: 2px solid var(--accent, #8B4513);
    box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}
#portrait-lightbox-caption {
    margin-top: 12px;
    color: #e8d8c0;
    font-family: Georgia, serif;
    font-size: 14px;
    text-align: center;
    max-width: 420px;
    opacity: 0.9;
}

/* Circular portrait marker pin */
.marker-portrait-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid #fff;
    box-shadow: 0 0 0 2px var(--accent, #8B4513), 0 2px 8px rgba(0,0,0,0.5);
    background: #ccc;
}

.marker-portrait-icon.marker-portrait-fallback {
    background-color: var(--accent, #8B4513);
}

/* Responsive: stack portrait card vertically on small screens */
@media screen and (max-width: 480px) {
    .diplomat-selected-card {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    .diplomat-selected-portrait {
        width: 100px;
        height: 125px;
    }
}
#diplomat-selector:-ms-expand {
    display: none;
}
/* Smooth rendering for animated dash-flow edges */
#communications-map .leaflet-overlay-pane svg path {
    will-change: stroke-dashoffset;
}

/* ── Proportional flow map styles ── */

.flow-count-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    font-family: 'Inter', sans-serif;
    line-height: 1.4;
    text-align: center;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0,0,0,0.35);
    pointer-events: none;
}

.flow-count-badge-wrapper {
    background: transparent !important;
    border: none !important;
    pointer-events: none !important;
}

.flow-city-popup {
    font-family: 'Inter', sans-serif;
    min-width: 140px;
}

.flow-city-popup h4 {
    margin: 0 0 6px;
    font-family: 'Playfair Display', serif;
    color: var(--primary, #1a2a40);
    font-size: 15px;
    border-bottom: 1px solid var(--accent, #a67b5b);
    padding-bottom: 4px;
}

.flow-city-popup p {
    margin: 3px 0;
    font-size: 13px;
    color: var(--neutral-dark, #333);
}

.flow-city-popup .flow-click-hint {
    margin-top: 8px;
    font-size: 11px;
    color: var(--accent, #a67b5b);
    font-style: italic;
}

/* City markers are clickable to focus on connections */
#communications-map .flow-city-marker {
    cursor: pointer;
}

/* Flow arrows are clickable to drill into route letters */
#communications-map .leaflet-interactive {
    cursor: pointer;
}

.flow-edge-tooltip {
    background: rgba(26, 42, 64, 0.95) !important;
    border: 1px solid var(--accent, #a67b5b) !important;
    color: #fff !important;
    padding: 6px 12px !important;
    font-size: 12px !important;
    white-space: nowrap;
}

.flow-city-label {
    background: rgba(255,255,255,0.92) !important;
    border: 1px solid var(--accent, #a67b5b) !important;
    border-radius: 4px !important;
    padding: 2px 8px !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    color: var(--primary, #1a2a40) !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.15) !important;
}

/* Popup sizing overrides for the communications map */
#communications-map .leaflet-popup-content-wrapper {
    min-width: 260px;
}

#communications-map .leaflet-popup-content {
    min-width: 240px;
    width: auto !important;
}

#communications-map .marker-popup {
    min-width: 220px;
    width: 100%;
    box-sizing: border-box;
}

/* Communications info panel */
#communications-info {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background-color: var(--neutral-light);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 3px 15px rgba(0, 0, 0, 0.25);
    max-width: 300px;
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid var(--accent);
    font-family: 'Inter', sans-serif;
    background-image: linear-gradient(135deg, rgba(255,255,255,0.8) 0%, rgba(245,245,245,0.8) 100%);
    border-top-right-radius: 0;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    pointer-events: auto;
}

#communications-info::before {
    content: '';
    position: absolute;
    top: -10px;
    right: 0;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 0 solid transparent;
    border-bottom: 10px solid var(--accent);
    z-index: -1;
}

#communications-info h3 {
    margin-top: 0;
    margin-bottom: 12px;
    font-family: 'Playfair Display', serif;
    color: var(--primary);
    font-size: 18px;
    letter-spacing: 0.5px;
    position: relative;
    padding-bottom: 8px;
}

#communications-info h3::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 50px;
    height: 2px;
    background: linear-gradient(to right, var(--accent), var(--primary));
    border-radius: 2px;
}

/* Style the event items to look like letter entries */
.event-item {
    padding: 8px;
    margin-bottom: 8px;
    border-bottom: 1px dashed var(--accent);
    background-color: rgba(255, 255, 255, 0.6);
    border-radius: 4px;
}

.event-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.event-date {
    font-weight: bold;
    font-size: 14px;
    color: var(--primary);
    margin-bottom: 4px;
}

.event-content {
    font-size: 13px;
    line-height: 1.4;
}

.event-content p {
    margin: 4px 0;
}

/* Clickable route items in the general panel view */
.event-item.route-item {
    cursor: pointer;
    transition: background-color 0.18s ease, transform 0.12s ease;
}

.event-item.route-item:hover {
    background-color: rgba(212, 196, 168, 0.35);
    transform: translateX(2px);
}

.event-item.route-item:hover .event-content p {
    color: var(--primary);
    font-weight: 600;
}

/* Individual letter items in the drill-down view */
.event-item.letter-item {
    border-left: 3px solid var(--accent);
    padding-left: 10px;
}

/* Header shown above the letters list when a route is selected */
.route-letters-header {
    font-family: 'Playfair Display', serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--accent);
}

.route-letters-count {
    font-weight: 400;
    color: #888;
    font-size: 12px;
}

/* Back button inside the panel */
#panel-back-btn {
    display: none;
    background: none;
    border: none;
    padding: 0 0 10px 0;
    margin: 0 0 8px 0;
    font-family: 'Playfair Display', serif;
    font-size: 13px;
    color: var(--secondary);
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: color 0.18s ease;
    border-bottom: 1px dashed var(--accent);
    width: 100%;
    text-align: left;
}

#panel-back-btn:hover {
    color: var(--primary);
}

/* Responsive adjustments */
@media screen and (max-width: 768px) {
    #communications-info {
        max-width: 260px;
        max-height: 340px;
    }
}

@media screen and (max-width: 480px) {
    #communications-info {
        max-width: 210px;
        max-height: 260px;
        padding: 10px;
        top: 10px;
        left: 10px;
    }
    
    .event-item {
        padding: 6px;
        margin-bottom: 6px;
    }
    
    .event-date {
        font-size: 12px;
    }
    
    .event-content {
        font-size: 11px;
    }
}

/* Responsive styles */
@media screen and (max-width: 768px) {
    .section-container {
        padding: 0 20px;
    }

    .section-header {
        flex-direction: column;
        align-items: center;
    }

    #diplomat-selector-container {
        width: 100%;
        margin-top: 10px;
        padding: 5px 0;
    }

    #diplomat-selector-heading {
        font-size: 1.4rem;
        margin-top: 15px;
        margin-bottom: 15px;
    }

    #diplomat-selector {
        width: 100%;
    }

    #diplomat-description {
        padding: 12px 15px;
        margin-top: 10px;
        margin-bottom: 15px;
    }

    #communications-info {
        max-width: 290px;
        max-height: 360px;
        top: 60px;
        left: 15px;
    }

    .map-container-communications {
        height: calc(100vh - 220px); /* Adjust for taller selector container */
    }
}

@media screen and (max-width: 480px) {
    .section-container {
        padding: 0 15px;
    }

    #diplomat-selector-heading {
        font-size: 1.3rem;
        margin-top: 12px;
        margin-bottom: 12px;
    }

    .section-header {
        flex-direction: column;
        align-items: center;
        gap: 5px;
    }

    #diplomat-selector-container {
        padding: 5px 0;
        width: 100%;
    }

    #diplomat-selector {
        font-size: 14px;
        padding: 6px;
        width: 100%;
    }

    #diplomat-description {
        padding: 10px 12px;
        font-size: 14px;
        width: 100%;
        margin-top: 8px;
        margin-bottom: 12px;
    }

    #communications-info {
        max-width: 210px;
        max-height: 220px;
        padding: 10px;
    }

    .map-container-communications {
        height: calc(100vh - 180px);
    }
}

/* Diplomat Gallery Slider Styles */
.diplomat-gallery-section {
    margin: 30px 0;
    padding: 20px 0;
}

.diplomat-gallery-container {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    overflow: hidden;
}

.diplomat-gallery {
    display: flex;
    transition: transform 0.5s ease-in-out;
    gap: 20px;
    padding: 20px 0;
}

.diplomat-slide {
    min-width: 250px;
    max-width: 250px;
    background: var(--neutral-light);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.diplomat-slide:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.diplomat-image {
    width: 100%;
    height: 300px;
    object-fit: cover;
    border-bottom: 2px solid var(--accent);
}

.diplomat-info {
    padding: 15px;
    text-align: center;
}

.diplomat-name {
    font-family: 'Playfair Display', serif;
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 5px;
    line-height: 1.3;
}

.diplomat-title {
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    color: var(--neutral-dark);
    font-style: italic;
    line-height: 1.4;
}

.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 10;
}

.gallery-nav:hover {
    background: var(--accent);
    color: white;
    transform: translateY(-50%) scale(1.1);
}

.gallery-nav.prev {
    left: 10px;
}

.gallery-nav.next {
    right: 10px;
}

.gallery-nav i {
    font-size: 18px;
    color: var(--primary);
}

.gallery-nav:hover i {
    color: white;
}

.gallery-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.gallery-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.3;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

.gallery-dot.active {
    opacity: 1;
}

/* Responsive gallery styles */
@media screen and (max-width: 768px) {
    .diplomat-slide {
        min-width: 200px;
        max-width: 200px;
    }
    
    .diplomat-image {
        height: 250px;
    }
    
    .diplomat-name {
        font-size: 14px;
    }
    
    .diplomat-title {
        font-size: 11px;
    }
    
    .gallery-nav {
        width: 40px;
        height: 40px;
    }
    
    .gallery-nav i {
        font-size: 16px;
    }
}

@media screen and (max-width: 480px) {
    .diplomat-slide {
        min-width: 180px;
        max-width: 180px;
    }
    
    .diplomat-image {
        height: 220px;
    }
    
    .diplomat-info {
        padding: 12px;
    }
    
    .diplomat-name {
        font-size: 13px;
    }
    
    .diplomat-title {
        font-size: 10px;
    }
    
    .gallery-nav {
        width: 35px;
        height: 35px;
    }
    
    .gallery-nav i {
        font-size: 14px;
    }
}
