/* Import Design Tokens */
@import url('tokens.css');
@import url('components.css');

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

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-base);
    font-size: var(--font-size-base);
    color: var(--text-main);
    background: var(--bg-body);
    line-height: 1.6;
    padding-top: var(--navbar-height);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-headings);
    color: var(--color-primary);
}

/* Global Card Style - Border-based design */
.card {
    background: var(--bg-card);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-xl);
    transition: border-color var(--transition-fast);
}

.card:hover {
    border-color: var(--color-primary);
}

/* stat-card styles moved to components.css for consistency */

/* Global Button Style */
button, .btn {
    font-family: var(--font-base);
}

/* Global Secondary Navigation (Top Right) */
.landing-nav {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-xl);
    display: flex;
    gap: var(--space-md);
    z-index: 100;
}

.landing-nav a {
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--font-size-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    background: var(--color-bg-light);
    border: 1px solid var(--color-border-light);
}

.landing-nav a:hover {
    color: var(--color-primary);
    border-color: var(--color-primary);
}

/* Navbar - Border-based design */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: var(--color-bg);
    border-bottom: 2px solid var(--color-border);
    color: var(--color-primary);
    display: flex;
    align-items: center;
    padding: 0 var(--space-xl);
    z-index: 1000;
}

/* Scrolled state logic can be added later via JS for even more transparency at top */

/* Burger Menu Button */
.nav-burger {
    display: none;
    background: none;
    border: none;
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    padding: 10px;
    cursor: pointer;
    margin-right: var(--space-sm);
    border-radius: var(--radius-md);
    transition: background 0.2s;
    flex-shrink: 0;
}

.nav-burger:hover {
    background: rgba(0, 0, 0, 0.05);
}

.nav-burger-icon {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--color-primary);
    position: relative;
    transition: background 0.2s;
}

.nav-burger-icon::before,
.nav-burger-icon::after {
    content: '';
    position: absolute;
    left: 0;
    width: 22px;
    height: 2px;
    background: var(--color-primary);
    transition: transform 0.2s, top 0.2s;
}

.nav-burger-icon::before {
    top: -7px;
}

.nav-burger-icon::after {
    top: 7px;
}

.nav-burger.active .nav-burger-icon {
    background: transparent;
}

.nav-burger.active .nav-burger-icon::before {
    top: 0;
    transform: rotate(45deg);
}

.nav-burger.active .nav-burger-icon::after {
    top: 0;
    transform: rotate(-45deg);
}

.nav-brand {
    font-size: var(--font-size-xl);
    font-family: var(--font-headings);
    font-weight: 700;
    margin-right: var(--space-xl);
    color: var(--color-primary);
    letter-spacing: -0.5px;
}

/* Data Source Switcher */
.data-source-switcher {
    margin-right: var(--space-xl);
}

.data-source-switcher select {
    background: var(--color-primary);
    color: white;
    border: 1px solid var(--color-primary);
    border-radius: 4px;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-base);
    cursor: pointer;
    transition: all 0.2s;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
}

.data-source-switcher select:hover {
    background-color: var(--color-primary-dark, #1a252f);
}

.data-source-switcher select:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.data-source-switcher select option {
    background: var(--color-primary);
    color: white;
}

.nav-links {
    display: flex;
    gap: var(--space-lg);
    margin-right: var(--space-xl);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--font-size-sm);
    font-weight: 500;
    padding: var(--space-sm) var(--space-md);
    border-radius: 20px; /* Pill shape */
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--color-primary);
    background: rgba(44, 62, 80, 0.05);
}

.nav-link.active {
    background: var(--color-primary);
    color: white;
}

.nav-link.active:hover {
    background: var(--color-primary);
    color: white;
}

/* Basket badge in navbar */
.nav-link-basket {
    position: relative;
}

.nav-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--color-accent, #e74c3c);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 5px;
    border-radius: 10px;
    line-height: 1;
    min-width: 16px;
    text-align: center;
    border: 2px solid white; /* Cutout effect */
}

/* Navbar Dropdown */
.nav-dropdown {
    position: relative;
}

.nav-dropdown-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.9);
    font-family: inherit;
    font-size: inherit;
}

.nav-dropdown-arrow {
    font-size: 8px;
    margin-left: 6px;
    opacity: 0.8;
    transition: transform 0.2s;
    display: inline-block;
    vertical-align: middle;
}

.nav-dropdown.active .nav-dropdown-arrow {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    min-width: 200px;
    margin-top: 8px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.nav-dropdown.active .nav-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.nav-dropdown-item {
    display: block;
    padding: var(--space-sm) var(--space-md);
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--font-size-base);
    transition: background 0.2s;
}

.nav-dropdown-item:first-child {
    border-radius: 6px 6px 0 0;
}

.nav-dropdown-item:last-child {
    border-radius: 0 0 6px 6px;
}

.nav-dropdown-item:hover {
    background: var(--color-bg-secondary);
}

.nav-dropdown-item i {
    width: 20px;
    margin-right: var(--space-sm);
    color: var(--color-text-light);
}

.nav-dropdown-item:hover i {
    color: var(--color-primary);
}

.nav-dropdown-divider {
    height: 1px;
    background: var(--color-border-light);
    margin: var(--space-xs) 0;
}

/* Container */
.container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--navbar-height));
}

/* Content Wrapper - holds sidebar and main content */
.content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--color-bg-light);
    padding: var(--space-xl) var(--space-lg);
    border-right: 2px solid var(--color-border);
    overflow-y: auto;
    overflow-x: hidden;
    height: calc(100vh - var(--navbar-height));
    position: sticky;
    top: var(--navbar-height);
}

.sidebar h3 {
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-lg); /* Slightly reduced spacing */
    color: var(--color-text);
    font-weight: 700;
}

/* .filter-group base styles now in components.css */

.filter-group-row {
    margin-bottom: var(--space-lg);
}

/* Override for index.html sidebar - uses h4 instead of h3 */
.filter-group h4 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Year Range Filter with noUiSlider */
#year-range-slider {
    margin: var(--space-md) 0;
    height: 8px;
}

/* year-range-display - Moved to components.css for consistency */

/* noUiSlider customization */
#year-range-slider .noUi-base {
    height: 8px;
}

#year-range-slider .noUi-connects {
    border-radius: var(--radius-sm);
}

#year-range-slider .noUi-connect {
    background: var(--color-accent);
}

#year-range-slider .noUi-handle {
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-accent);
    border-radius: 50%;
    background: var(--color-bg);
    box-shadow: var(--shadow-sm);
    top: -6px;
    right: -10px;
}

#year-range-slider .noUi-handle:hover {
    background: var(--color-bg-light);
}

#year-range-slider .noUi-handle:before,
#year-range-slider .noUi-handle:after {
    display: none;
}

#year-range-slider .noUi-tooltip {
    display: none;
}

/* Filter buttons */
.filter-buttons {
    margin-top: var(--space-lg);
}

/* Reset button uses unified .btn-reset from components.css */

/* Topics Quick Filter */
.topics-quick-search {
    width: 100%;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-sm);
    background: var(--color-bg);
}

.topics-quick-search:focus {
    outline: none;
    border-color: var(--color-primary);
}

.topics-quick-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    max-height: 280px;
    overflow-y: auto;
}

.topics-no-results {
    color: var(--color-text-light);
    font-size: var(--font-size-sm);
    padding: var(--space-sm);
    text-align: center;
}

.topics-more-info {
    color: var(--color-text-light);
    font-size: var(--font-size-xs);
    padding: var(--space-xs) var(--space-sm);
    text-align: center;
    font-style: italic;
}

#topics-quick-filter {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.topic-quick-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--font-size-sm);
}

.topic-quick-item:hover {
    border-color: var(--color-primary);
    background: rgba(166, 75, 63, 0.05);
}

.topic-quick-item.active {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: white;
}

.topic-quick-item .topic-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topic-quick-item .topic-count {
    color: var(--color-text-light);
    font-size: var(--font-size-xs);
}

.topic-quick-item.active .topic-count {
    color: rgba(255, 255, 255, 0.8);
}

.show-all-link {
    display: block;
    margin-top: var(--space-sm);
    font-size: var(--font-size-xs);
    color: var(--color-primary);
    text-decoration: none;
}

.show-all-link:hover {
    text-decoration: underline;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);  /* Cream - contrasts with Manila sidebar */
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-light);
    padding: 0 var(--space-xl);
}

.tab {
    padding: var(--space-lg) var(--space-2xl);
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-base);
    color: var(--color-text-light);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab:hover {
    color: var(--color-text);
}

.tab.active {
    color: var(--color-secondary);
    border-bottom-color: var(--color-secondary);
    font-weight: 500;
}

/* Tab Content */
.tab-content {
    flex: 1;
    display: none;
    position: relative;
}

.tab-content.active {
    display: block;
}

/* Map */
#map {
    width: 100%;
    height: 100%;
}

#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: var(--space-xl) var(--space-3xl);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    font-size: var(--font-size-md);
    color: var(--color-text-light);
}

#loading.hidden {
    display: none;
}

/* Placeholder content for timeline/network */
#timeline-view p,
#network-view p {
    padding: var(--space-3xl);
    text-align: center;
    color: var(--color-text-light);
    font-size: var(--font-size-md);
}

/* Responsive Design */

/* Tablet (≤1024px) */
@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }

    
}

/* Mobile Navigation Overlay */
.nav-overlay {
    display: none;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s;
}

.nav-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile Navigation Menu */
.nav-mobile-menu {
    display: none;
    position: fixed;
    top: var(--navbar-height);
    right: -100%;
    width: 280px;
    max-width: 80vw;
    height: calc(100vh - var(--navbar-height));
    background: var(--color-bg);
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    z-index: 999;
    transition: right 0.3s;
    overflow-y: auto;
}

.nav-mobile-menu.active {
    right: 0;
}

.nav-mobile-content {
    padding: var(--space-xl);
}

.nav-mobile-section {
    margin-bottom: var(--space-2xl);
}

.nav-mobile-heading {
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-light);
    margin-bottom: var(--space-md);
    font-weight: 600;
}

.nav-mobile-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    color: var(--color-text);
    text-decoration: none;
    border-radius: 4px;
    transition: background 0.2s;
    font-size: var(--font-size-base);
    margin-bottom: var(--space-xs);
    position: relative;
}

.nav-mobile-link:hover {
    background: var(--color-bg-secondary);
}

.nav-mobile-link i {
    width: 20px;
    text-align: center;
}

/* Mobile Source Switcher */
.nav-mobile-source-switcher select {
    width: 100%;
    padding: var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: var(--font-size-base);
    background: var(--color-bg);
    color: var(--color-text);
    cursor: pointer;
}

.nav-mobile-source-switcher select:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Mobile (≤768px) */
@media (max-width: 768px) {
    .nav-burger {
        display: block;
    }

    .nav-brand {
        font-size: var(--font-size-base);
        margin-right: var(--space-sm);
    }

    .view-switcher {
        display: flex;
        flex: 1;
        background: var(--bg-subtle, #f5f5f5);
        border: 1px solid var(--border-color, #e0e0e0);
        border-radius: var(--radius-md);
        padding: 3px;
        gap: 2px;
        margin-right: var(--space-sm);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .view-btn {
        flex: 0 0 auto;
        min-height: 40px;
        min-width: 40px;
        padding: 6px 8px;
        font-size: 11px;
        text-align: center;
        border: none;
        border-radius: 4px;
        white-space: nowrap;
        overflow: visible;
        line-height: 1.2;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        color: var(--text-muted, #666);
        background: transparent;
    }

    .view-btn .view-btn-text {
        display: none;
    }

    .view-btn i {
        font-size: 16px;
    }

    .view-btn.active,
    .view-btn[aria-pressed="true"] {
        background: var(--color-primary, #2c3e50);
        color: white;
        font-weight: 600;
    }

    .nav-search {
        display: none;
    }

    .nav-links {
        display: flex;
        gap: var(--space-xs);
        flex-shrink: 0;
    }

    .nav-links .nav-link-text {
        display: none;
    }

    .nav-links .nav-link {
        padding: var(--space-xs);
        min-width: 36px;
        min-height: 36px;
        justify-content: center;
    }

    .data-source-switcher {
        display: none;
    }

    .nav-mobile-menu {
        display: block;
    }

    .sidebar {
        position: fixed;
        left: -280px;
        top: var(--navbar-height);
        height: calc(100vh - var(--navbar-height));
        z-index: 999;
        transition: left 0.3s;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        width: 100%;
    }

    .content-wrapper {
        overflow: visible;
        flex-direction: column;
    }
}

/* Mobile (≤480px) */
@media (max-width: 480px) {
    .navbar {
        padding: 0 var(--space-xs);
        background: rgba(255, 255, 255, 0.98);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .nav-brand {
        font-size: var(--font-size-sm);
        margin-right: var(--space-xs);
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .nav-burger {
        margin-right: var(--space-xs);
        min-width: 32px;
        min-height: 32px;
    }

    .view-switcher {
        margin-right: var(--space-xs);
        padding: 2px;
        gap: 1px;
        flex: 1;
        max-width: none;
    }

    .view-btn {
        min-height: 36px;
        min-width: 36px;
        padding: 4px;
        font-size: 0; /* Hide text */
    }

    /* Show only icons on small screens */
    .view-btn .view-btn-text {
        display: none;
    }

    .view-btn i {
        font-size: 14px;
    }

    /* Nav links - only essential buttons */
    .nav-links {
        gap: 2px;
    }

    .nav-links .nav-link {
        min-width: 32px;
        min-height: 32px;
        padding: 4px;
    }

    .nav-links .nav-link i {
        font-size: 14px;
    }

    .tabs {
        padding: 0 var(--space-md);
    }

    .tab {
        padding: var(--space-sm) var(--space-md);
        font-size: var(--font-size-sm);
    }
}

/* Landscape orientation on small screens */
@media (max-width: 768px) and (orientation: landscape) {
    .navbar {
        height: 50px;  /* Reduce navbar height in landscape */
    }

    body {
        padding-top: 50px;
    }

    .nav-brand {
        font-size: var(--font-size-sm);
    }

    .view-btn {
        padding: 4px 6px;
        font-size: var(--font-size-xs);
        min-height: 40px;  /* Slightly smaller for landscape */
    }

    .nav-burger {
        min-width: 40px;
        min-height: 40px;
        width: 40px;
        height: 40px;
    }

    .sidebar {
        top: 50px;
        height: calc(100vh - 50px);
    }

    .nav-mobile-menu {
        top: 50px;
        height: calc(100vh - 50px);
    }
}

/* MapLibre Popup Customization */
.maplibregl-popup-content {
    padding: 0;
    font-size: var(--font-size-base);
}

.maplibregl-popup-close-button {
    font-size: 20px;
    padding: 4px;
    color: var(--color-text-light);
}

.maplibregl-popup-close-button:hover {
    color: var(--color-text);
}

.popup {
    padding: var(--space-md);
    min-width: 200px;
}

.popup h3 {
    font-size: var(--font-size-md);
    margin-bottom: var(--space-sm);
    color: var(--color-text);
}

.popup-badges {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.badge {
    padding: 2px var(--space-sm);
    border-radius: 3px;
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.badge-gnd {
    background: var(--color-badge-gnd-bg);
    color: var(--color-badge-gnd);
}

.badge-sndb {
    background: var(--color-badge-sndb-bg);
    color: var(--color-badge-sndb);
}

.badge-relation {
    background: rgba(255, 0, 102, 0.1);
    color: #ff0066;
    font-weight: 600;
}

.popup-stats p {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    margin: var(--space-xs) 0;
}

.popup-location {
    font-style: italic;
    color: var(--color-text-light);
}

.popup a {
    display: inline-block;
    margin-top: var(--space-md);
    color: var(--color-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
}

.popup a:hover {
    text-decoration: underline;
}

/* Multi-Person Popup */
.multi-person-popup {
    padding: var(--space-md);
    min-width: 300px;
    max-width: 400px;
}

.multi-person-popup h3 {
    font-size: var(--font-size-md);
    margin-bottom: var(--space-xs);
    color: var(--color-text);
}

.location-info {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
}

.person-list {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: var(--space-md);
}

.person-item {
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--color-bg-light);
    cursor: pointer;
    transition: background-color 0.2s;
}

.person-item:hover {
    background-color: var(--color-bg-light);
    padding-left: var(--space-xs);
    padding-right: var(--space-xs);
    border-radius: 4px;
}

.person-item:last-child {
    border-bottom: none;
}

.person-item.has-relations {
    border-left: 3px solid #ff0066;
    padding-left: var(--space-xs);
    background-color: rgba(255, 0, 102, 0.05);
}

.person-item.has-relations:hover {
    background-color: rgba(255, 0, 102, 0.1);
}

.person-name {
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-xs);
}

.person-name strong {
    color: var(--color-text);
}

.person-meta {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
    flex-wrap: wrap;
}

.person-stats {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
}

.show-more-btn {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-secondary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

.show-more-btn:hover {
    background: var(--color-primary);
}

/* Basket buttons in popups */
.btn-basket-toggle {
    padding: 6px 12px;
    background: white;
    color: var(--color-secondary);
    border: 2px solid var(--color-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-basket-toggle:hover {
    background: var(--color-secondary);
    color: white;
}

.btn-basket-toggle.in-basket {
    background: var(--color-secondary);
    color: white;
    border-color: var(--color-secondary);
}

.btn-basket-toggle.in-basket:hover {
    background: #c9423a;
    border-color: #c9423a;
}

/* Mini basket button for multi-person list */
.person-item {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.person-item-content {
    flex: 1;
    cursor: pointer;
}

/* Person item buttons container */
.person-item-buttons {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-basket-mini {
    padding: 4px 8px;
    background: white;
    color: var(--color-secondary);
    border: 1px solid var(--color-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.btn-basket-mini:hover {
    background: var(--color-secondary);
    color: white;
}

.btn-basket-mini.in-basket {
    background: var(--color-secondary);
    color: white;
}

.btn-basket-mini.in-basket:hover {
    background: #c9423a;
}

/* Custom scrollbar for person list */
.person-list::-webkit-scrollbar {
    width: 6px;
}

.person-list::-webkit-scrollbar-track {
    background: var(--color-bg-light);
    border-radius: 3px;
}

.person-list::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.person-list::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-light);
}

/* MapLibre Map Container */
#map {
    position: relative;
}

.maplibregl-canvas {
    outline: none;
    filter: saturate(0.7) brightness(1.05);  /* Desaturate basemap to make network lines more visible */
}

/* Attribution */
.maplibregl-ctrl-attrib {
    font-size: 11px;
    background-color: rgba(255, 255, 255, 0.8);
}

/* Hover Tooltips */
.hover-tooltip-popup .maplibregl-popup-content {
    background: rgba(30, 58, 95, 0.95);
    color: white;
    padding: var(--space-sm) var(--space-md);
    border-radius: 4px;
    font-size: var(--font-size-sm);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    max-width: 250px;
}

.hover-tooltip-popup .maplibregl-popup-tip {
    border-top-color: rgba(30, 58, 95, 0.95);
}

.hover-tooltip {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 250px;
}

.hover-tooltip strong {
    font-weight: 600;
}

/* JSON Hover Tooltips */
.hover-json-popup .maplibregl-popup-content {
    background: #ffffff;
    color: #2d3748;
    padding: var(--space-md);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    max-width: 500px;
    max-height: 500px;
    overflow-y: auto;
    pointer-events: auto;  /* Allow interaction with popup content */
}

.hover-json-popup .maplibregl-popup-tip {
    border-top-color: #ffffff;
}

/* Sticky JSON popup with close button */
.json-popup-sticky .maplibregl-popup-close-button {
    font-size: 20px;
    padding: 4px 8px;
    color: var(--color-text-light);
    background: transparent;
    right: 8px;
    top: 8px;
}

.json-popup-sticky .maplibregl-popup-close-button:hover {
    color: var(--color-text);
    background: var(--color-bg-light);
}

.hover-tooltip-json {
    font-family: var(--font-base);
}

.hover-tooltip-header {
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border);
}

.hover-tooltip-header strong {
    font-size: var(--font-size-md);
    color: var(--color-primary);
}

.hover-json-display {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: var(--space-sm);
    font-family: 'Courier New', monospace;
    font-size: 11px;
    line-height: 1.4;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    margin: 0;
}

/* JSON Syntax Highlighting (also for tooltips) */
.json-key { color: #0066cc; font-weight: 600; }
.json-string { color: #008000; }
.json-number { color: #ff6600; }
.json-boolean { color: #cc0000; }
.json-null { color: #999999; }

/* Person Detail Page */
.person-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-xl);
}

/* Person Header */
.person-header {
    padding: var(--space-2xl) 0;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: var(--space-xl);
}

.person-header h1 {
    font-size: var(--font-size-3xl);
    color: var(--color-text);
    margin-bottom: var(--space-sm);
}

.person-dates {
    font-size: var(--font-size-lg);
    color: var(--color-text-light);
    margin-bottom: var(--space-md);
}

.person-badges {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.badge-role-sender {
    background: var(--color-role-sender);
    color: white;
    padding: var(--space-xs) var(--space-md);
    border-radius: 4px;
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.badge-role-mentioned {
    background: var(--color-role-mentioned);
    color: white;
    padding: var(--space-xs) var(--space-md);
    border-radius: 4px;
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.badge-role-both {
    background: var(--color-role-both);
    color: white;
    padding: var(--space-xs) var(--space-md);
    border-radius: 4px;
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.badge-role-indirect {
    background: var(--color-role-indirect);
    color: white;
    padding: var(--space-xs) var(--space-md);
    border-radius: 4px;
    font-size: var(--font-size-sm);
    font-weight: 500;
}

/* Tab Panels */
.tab-panel {
    display: none;
    padding: var(--space-xl) 0;
    animation: fadeIn 0.3s;
}

.tab-panel.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.tab-panel h2 {
    font-size: var(--font-size-xl);
    color: var(--color-text);
    margin-bottom: var(--space-lg);
}

.tab-panel h3 {
    font-size: var(--font-size-lg);
    color: var(--color-text);
    margin-bottom: var(--space-md);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-2xl);
}

/* stat-card, stat-value, stat-label moved to components.css */

/* Biography Section */
.biography-section {
    margin-top: var(--space-2xl);
}

.biography-content {
    font-size: var(--font-size-md);
    line-height: 1.8;
    color: var(--color-text);
}

/* Content Sections */
.content-section {
    font-size: var(--font-size-md);
    line-height: 1.6;
}

.placeholder-text {
    color: var(--color-text-light);
    font-style: italic;
}

.placeholder-content {
    background: var(--color-bg-light);
    padding: var(--space-xl);
    border-radius: 8px;
    border-left: 4px solid var(--color-secondary);
}

.placeholder-content ul {
    margin-left: var(--space-xl);
    margin-top: var(--space-md);
}

.placeholder-content li {
    margin-bottom: var(--space-sm);
}

/* Places */
.places-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.place-card {
    background: var(--color-bg-light);
    padding: var(--space-lg);
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.place-card h3 {
    font-size: var(--font-size-md);
    color: var(--color-text);
    margin-bottom: var(--space-xs);
}

.place-type {
    font-size: var(--font-size-sm);
    color: var(--color-secondary);
    font-weight: 500;
    margin-bottom: var(--space-xs);
}

.place-coords {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    font-family: monospace;
}

/* Mini Map */
.mini-map {
    width: 100%;
    height: 400px;
    border-radius: 8px;
    border: 1px solid var(--color-border);
    margin-top: var(--space-lg);
}

/* Occupations */
.occupations-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
}

.occupation-item {
    background: var(--color-bg-light);
    padding: var(--space-md) var(--space-lg);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.occupation-name {
    font-size: var(--font-size-md);
    font-weight: 500;
    color: var(--color-text);
}

.occupation-type {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
}

/* Letters */
.letters-summary {
    font-size: var(--font-size-md);
}

.letters-summary p {
    margin-bottom: var(--space-md);
}

.note {
    background: var(--color-bg-light);
    padding: var(--space-md);
    border-radius: 4px;
    border-left: 3px solid var(--color-info);
    margin-top: var(--space-lg);
}

/* Sources */
.sources-links {
    display: flex;
    flex-direction: column;
    gap: var(--space-xl);
    margin-bottom: var(--space-2xl);
}

.source-link h3 {
    font-size: var(--font-size-md);
    margin-bottom: var(--space-sm);
}

.source-link a {
    color: var(--color-secondary);
    text-decoration: none;
    word-break: break-all;
}

.source-link a:hover {
    text-decoration: underline;
}

.data-quality-section,
.citation-section {
    margin-top: var(--space-2xl);
    padding-top: var(--space-2xl);
    border-top: 1px solid var(--color-border);
}

.data-quality-list {
    list-style: none;
    padding: 0;
}

.data-quality-list li {
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--color-bg-light);
}

.citation-text {
    background: var(--color-bg-light);
    padding: var(--space-lg);
    border-radius: 4px;
    font-family: monospace;
    font-size: var(--font-size-sm);
    line-height: 1.8;
    border-left: 3px solid var(--color-secondary);
}

/* Loading and Error States */
.loading-message,
.error-message {
    margin-top: calc(var(--navbar-height) + var(--space-2xl));
    padding: var(--space-2xl);
    text-align: center;
}

.error-message h2 {
    font-size: var(--font-size-2xl);
    color: var(--color-text);
    margin-bottom: var(--space-md);
}

.error-message a {
    color: var(--color-secondary);
    text-decoration: none;
    font-size: var(--font-size-lg);
    display: inline-block;
    margin-top: var(--space-lg);
}

.error-message a:hover {
    text-decoration: underline;
}

/* Map Header */
.map-header {
    background: var(--color-primary);
    color: white;
    padding: var(--space-md) var(--space-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    z-index: 100;
}

.map-header h1 {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

/* View Switcher - Updated for light navbar */
.view-switcher {
    display: flex;
    background: var(--bg-subtle, #f5f5f5);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-color, #e0e0e0);
}

.view-btn {
    padding: var(--space-sm) var(--space-md);
    border: none;
    background: transparent;
    color: var(--text-muted, #666);
    font-size: var(--font-size-sm);
    font-family: var(--font-base);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-block;
    border-right: 1px solid var(--border-color, #e0e0e0);
}

.view-btn:last-child {
    border-right: none;
}

.view-btn:hover {
    background: var(--bg-hover, #e8e8e8);
    color: var(--color-primary, #2c3e50);
}

.view-btn.active,
.view-btn.view-btn-active {
    background: var(--color-primary, #2c3e50);
    color: white;
    cursor: default;
}

.view-btn.active:hover,
.view-btn.view-btn-active:hover {
    background: var(--color-primary, #2c3e50);
}

/* Map Legend */
/* Map legend removed - now in sidebar */

.legend-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
    font-size: var(--font-size-sm);
}

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

.legend-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.legend-line {
    width: 30px;
    height: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Legend in Sidebar */
.legend-section {
    margin-top: var(--space-md);
}

.legend-section:first-child {
    margin-top: 0;
}

.legend-section h5 {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin-bottom: var(--space-sm);
    color: var(--color-text);
}

.legend-hint {
    font-size: 11px;
    margin-top: var(--space-sm);
    color: var(--color-text-light);
    font-style: italic;
}

/* Timeline Styles */
.timeline-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: var(--space-lg);
    box-sizing: border-box;
}

#timeline-chart {
    flex: 1;
    min-height: 400px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

/* D3 Timeline Elements */
.timeline-bar {
    fill: var(--color-accent);
    cursor: pointer;
}

.timeline-bar:hover {
    opacity: 0.7;
}

.timeline-axis text {
    font-size: var(--font-size-xs);
    fill: var(--color-text-secondary);
}

.timeline-axis path,
.timeline-axis line {
    stroke: var(--color-border);
}

.timeline-tooltip {
    position: absolute;
    text-align: center;
    padding: 10px 14px;
    font-size: 13px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    border-radius: 6px;
    pointer-events: none;
    z-index: 10000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Responsive Design */
@media (max-width: 768px) {
    .person-page {
        padding: var(--space-md);
    }

    .person-header h1 {
        font-size: var(--font-size-2xl);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .places-grid {
        grid-template-columns: 1fr;
    }

    .mini-map {
        height: 300px;
    }

    .legend-color {
        width: 16px;
        height: 16px;
    }
}

/* Stats Cards in Sidebar */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 24px;
}

/* .stat-card is defined globally at the top */

.stat-value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: var(--space-xs);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.stat-label {
    font-size: var(--font-size-xs);
    color: var(--color-text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.4;
}

/* Clickable Stat Cards */
.stat-card-clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.stat-card-clickable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    border-color: var(--color-primary);
}

/* Export Actions */
.export-actions {
    margin-top: var(--space-xl);
    padding-top: var(--space-xl);
    border-top: 1px solid var(--color-border);
}

.btn-export {
    width: 100%;
    padding: 10px 16px;
    background: var(--color-primary); /* Updated to primary */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: var(--font-size-sm);
    font-weight: 500;
    transition: all 0.2s;
}

.btn-export:hover {
    background: var(--color-primary-dark); /* Use existing token */
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-export:active {
    transform: translateY(0);
}

/* Time Filter Tabs - Moved to components.css for consistency */

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-body); /* Paper white background */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.5s ease-out, visibility 0.5s ease-out;
}

#loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner {
    font-size: 4rem; /* Large icon size */
    color: var(--primary-color);
    animation: pulse 1.5s infinite ease-in-out;
    margin-bottom: var(--space-xl);
}

.loading-text {
    font-family: var(--font-headings); /* Merriweather */
    font-size: var(--font-size-2xl);
    color: var(--text-main);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Map Layer Switcher Button */
.map-control-btn {
    position: absolute;
    bottom: 20px;
    right: 10px;
    background-color: var(--bg-card);
    color: var(--primary-color);
    border: none;
    border-radius: 4px;
    padding: 10px 12px;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 10; /* Above the map */
    font-size: 1.2rem;
    transition: background-color 0.2s, transform 0.2s;
}

.map-control-btn:hover {
    background-color: var(--color-bg-light);
    transform: translateY(-1px);
}


/* Data Context Box for Person Page */
.data-context-box {
    background: var(--color-bg-light);
    border-left: 4px solid var(--color-info);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xl);
}

.data-context-box .context-info-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-light);
    line-height: 1.6;
    margin: 0;
}

/* Modal Base Styles (General-Proofed) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.6); /* Light overlay */
    backdrop-filter: blur(8px); /* Strong blur for focus */
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-xl);
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content { /* Generic modal content */
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px; /* Default max-width, can be overridden */
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.05);
}

/* Specific styles for the onboarding modal (animations) */
.modal-content.onboarding-card {
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); /* Elegant spring */
}

@keyframes slideUp {
    from { transform: translateY(40px) scale(0.98); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

/* Clean Header - Now part of generic modal-header */
.modal-header {
    background: white; /* Always white for consistency */
    color: var(--color-primary);
    padding: var(--space-2xl) var(--space-2xl) 0 var(--space-2xl); /* Adjust padding */
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.modal-header h2 {
    color: var(--color-primary);
    font-size: 1.75rem;
    margin: 0;
    font-weight: 800;
    letter-spacing: -0.02em;
    font-family: var(--font-headings);
}

.modal-close-btn {
    background: var(--color-bg-light);
    border: none;
    color: var(--color-text);
    font-size: 1.2rem;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close-btn:hover {
    background: #e0e0e0;
    transform: rotate(90deg);
}

.modal-body {
    padding: var(--space-2xl);
}

.onboarding-step {
    display: flex;
    gap: 20px;
    margin-bottom: 32px;
    align-items: flex-start;
}

.onboarding-step:last-child {
    margin-bottom: 0;
}

.step-icon {
    width: 48px;
    height: 48px;
    background: #f0f4f8; /* Subtle blue-grey */
    border-radius: 16px; /* Squircle */
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--color-secondary);
}

.step-icon i {
    font-size: 1.25rem;
}

.warning-step .step-icon {
    background: #fff8e1; /* Subtle yellow */
    color: #b7791f;
}

.step-text h3 {
    font-size: 1.1rem;
    margin: 0 0 6px 0;
    color: var(--color-text);
    font-weight: 700;
}

.step-text p {
    font-size: 0.95rem;
    color: var(--color-text-light);
    margin: 0;
    line-height: 1.6;
}

.modal-footer {
    padding: 24px 32px;
    background: white; /* Seamless continuation */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: none; /* Removed border for cleaner look */
    padding-top: 0; /* Closer to content */
}

.dont-show-again {
    font-size: 0.9rem;
    color: var(--color-text-light);
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.dont-show-again:hover {
    background: var(--color-bg-light);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 30px; /* Pill button */
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(44, 62, 80, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(44, 62, 80, 0.3);
    background: var(--color-primary-dark);
}
