/* World Atlas Styles - Compact Design */

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
                 "Oxygen", "Ubuntu", "Cantarell", "Fira Sans",
                 "Droid Sans", "Helvetica Neue", sans-serif;
    color: #12162D;
    background: #fff;
    line-height: 1.4;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 0.75rem;
}

/* Logo */
.site-logo {
    display: inline-block;
    background: #12162D;
    color: #fff;
    font-size: 1.1rem;
    font-weight: 500;
    padding: 0.25rem 0.6rem;
    text-decoration: none;
    letter-spacing: 0.5px;
}

.site-logo:hover {
    background: #1a1f3d;
}

.logo-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.logo-row h1 {
    font-size: 1.1rem;
    margin: 0;
}

.home-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0.5rem 0;
    flex-wrap: wrap;
}

.home-header .header-intro {
    flex: 1;
    margin: 0;
    color: #666;
    font-size: 0.9rem;
    white-space: nowrap;
}

.home-header .search-input {
    width: auto;
    min-width: 180px;
    max-width: 280px;
    padding: 0.4rem 0.75rem;
}

@media (max-width: 768px) {
    .home-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .home-header .header-intro {
        white-space: normal;
        font-size: 0.85rem;
    }

    .home-header .search-input {
        max-width: 100%;
    }
}

.header-flag {
    height: calc(1.1rem * 1.4 + 0.5rem);  /* Match logo: font-size * line-height + padding */
    width: auto;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Intro text */
.intro-text {
    font-size: 0.9rem;
    color: #666;
    margin: 0 0 0.75rem;
}

/* Footer */
.site-footer {
    background: #f6f6f6;
    padding: 1rem 0;
    margin-top: 2rem;
    text-align: center;
    color: #666;
    font-size: 0.85rem;
}

.site-footer a {
    color: #2563eb;
}

/* Search */
.search-input {
    width: 100%;
    max-width: 350px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: #2563eb;
}

/* World Map Section */
.world-map-section {
    margin-bottom: 1.5rem;
    position: relative;
}

.world-map {
    width: 100%;
    aspect-ratio: 1.92 / 1;
    background: #171c3b;
    border-radius: 6px;
    overflow: hidden;
}

.world-map svg {
    display: block;
}

.map-country {
    stroke: #fff;
    stroke-width: 1px;
    cursor: pointer;
    transition: fill 0.15s;
}

.map-country:hover,
.map-country.hover {
    fill: #ffd700;
}

.map-borders {
    fill: none;
    stroke: #fff;
    stroke-width: 0.5px;
    pointer-events: none;
}

.map-tooltip {
    display: none;
    position: absolute;
    background: #12162D;
    color: #fff;
    padding: 0.35rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
}

.map-hint {
    text-align: left;
    color: #666;
    font-size: 0.85rem;
    margin: 0.5rem 0 0;
}

/* Country Grid */
.country-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.5rem;
    padding-bottom: 1rem;
}

.country-card {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s;
}

.country-card:hover {
    border-color: #2563eb;
}

.country-flag {
    flex-shrink: 0;
    margin-right: 0.5rem;
}

.country-flag img {
    display: block;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    width: 48px;
    height: auto;
}

.country-info {
    min-width: 0;
}

.country-name {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.15rem;
    color: #12162D;
}

.country-stats {
    display: flex;
    gap: 0.75rem;
    font-size: 0.75rem;
    color: #666;
}

.stat-label {
    color: #999;
}

.stat-value {
    font-weight: 500;
}

/* Metrics Section */
.metrics-section,
.health-section,
.charts-section {
    margin-bottom: 1.5rem;
}

.metrics-section h2,
.health-section h2,
.charts-section h2 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
    padding-bottom: 0.25rem;
    color: #12162D;
    border-bottom: 2px solid #2563eb;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.5rem;
}

.metrics-grid-3 {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.metric-card {
    background: #f8f8f8;
    padding: 0.6rem;
    border-radius: 4px;
    text-align: center;
}

.metric-label {
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 0.2rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.metric-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #12162D;
}

.metric-subtext {
    font-size: 0.65rem;
    color: #999;
    margin-top: 0.1rem;
}

.metric-rank {
    font-size: 0.65rem;
    color: #2563eb;
    font-weight: 600;
    margin-top: 0.15rem;
    background: rgba(70, 130, 180, 0.1);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    display: inline-block;
    text-decoration: none;
    cursor: pointer;
}

a.metric-rank:hover {
    background: rgba(70, 130, 180, 0.2);
    text-decoration: none;
}

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.75rem;
}

.chart-container {
    background: #f8f8f8;
    padding: 0.75rem;
    border-radius: 4px;
}

.chart-container h3 {
    font-size: 0.85rem;
    margin: 0 0 0.5rem;
    color: #12162D;
}

.chart {
    width: 100%;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.line-chart {
    min-height: 150px;
}

.chart-legend {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.legend-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.no-data {
    color: #999;
    font-style: italic;
    text-align: center;
    font-size: 0.85rem;
}

/* D3 Chart Styles */
.chart svg {
    overflow: visible;
}

.axis path,
.axis line {
    stroke: #ccc;
}

.axis text {
    fill: #666;
    font-size: 10px;
}

.grid line {
    stroke: #e0e0e0;
    stroke-dasharray: 2, 2;
}

.grid path {
    stroke-width: 0;
}

.tooltip {
    position: absolute;
    background: #12162D;
    color: #fff;
    padding: 0.3rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    pointer-events: none;
    z-index: 1000;
}

/* Map Section */
.map-section {
    margin-bottom: 1.5rem;
}

.map-section h2 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
    padding-bottom: 0.25rem;
    color: #12162D;
    border-bottom: 2px solid #2563eb;
}

.relief-map-container {
    background: #f8f8f8;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.75rem;
}

.maps-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.map-container {
    background: #f8f8f8;
    border-radius: 4px;
    overflow: hidden;
}

.map-container h3 {
    font-size: 0.85rem;
    margin: 0;
    padding: 0.5rem 0.75rem;
    color: #12162D;
    background: #f0f0f0;
}

.relief-map {
    width: 100%;
    height: 350px;
}

@media (max-width: 768px) {
    .maps-grid {
        grid-template-columns: 1fr;
    }
}

.country-map-label {
    background: transparent !important;
    border: none !important;
}

.map-label-inner {
    background: rgba(18, 22, 45, 0.85);
    color: #fff;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
    text-align: center;
}

.iso-codes {
    text-align: center;
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.5rem;
    padding: 0.3rem;
    background: #f8f8f8;
    border-radius: 3px;
}

/* Leaflet overrides */
.leaflet-container {
    font-family: inherit;
}

.leaflet-control-attribution {
    font-size: 9px;
}

/* Health Layout */
.health-layout {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.health-metrics {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    flex: 1;
    min-width: 280px;
}

/* Population Pyramid */
.pyramid-container {
    flex-shrink: 0;
}

.pyramid-image {
    width: 100%;
    max-width: 350px;
    height: auto;
    display: block;
    border-radius: 4px;
}

@media (max-width: 768px) {
    .health-layout {
        flex-direction: column;
    }

    .health-metrics {
        width: 100%;
    }

    .pyramid-container {
        width: 100%;
    }

    .pyramid-image {
        max-width: 100%;
    }
}

/* Trade Treemaps */
.trade-treemaps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 0.75rem;
}

.treemap-container {
    background: #f8f8f8;
    padding: 0.75rem;
    border-radius: 4px;
}

.treemap-container h3 {
    font-size: 0.85rem;
    margin: 0 0 0.5rem;
    color: #12162D;
}

.oec-treemap {
    width: 100%;
    height: 350px;
    border: none;
    border-radius: 4px;
}

.treemap-source {
    font-size: 0.7rem;
    color: #999;
    margin: 0.3rem 0 0;
    text-align: right;
}

.treemap-source a {
    color: #2563eb;
}

@media (max-width: 768px) {
    .trade-treemaps {
        grid-template-columns: 1fr;
    }

    .oec-treemap {
        height: 300px;
    }
}

/* Responsive */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

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

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

    .relief-map {
        height: 300px;
    }

    .logo-row h1 {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }

    .metric-card {
        padding: 0.5rem 0.3rem;
    }

    .metric-value {
        font-size: 1rem;
    }

    .country-stats {
        flex-direction: column;
        gap: 0.1rem;
    }
}

/* Ranking Page */
.filter-sort-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    align-items: center;
}

.filter-controls,
.sort-controls {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.filter-label,
.sort-label {
    color: #666;
    font-size: 0.8rem;
    margin-right: 0.2rem;
}

.filter-btn,
.sort-btn {
    padding: 0.25rem 0.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 3px;
    text-decoration: none;
    color: #12162D;
    font-size: 0.8rem;
    transition: border-color 0.2s, background 0.2s;
}

.filter-btn:hover,
.sort-btn:hover {
    border-color: #2563eb;
}

.filter-btn.active {
    background: #12162D;
    border-color: #12162D;
    color: #fff;
}

.sort-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.ranking-table-container {
    overflow-x: auto;
    margin-bottom: 1rem;
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.ranking-table th,
.ranking-table td {
    padding: 0.4rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid #e0e0e0;
}

.ranking-table th {
    background: #f6f6f6;
    font-weight: 600;
    color: #12162D;
    font-size: 0.8rem;
}

.ranking-table tbody tr:hover {
    background: #f9f9f9;
}

.ranking-table .col-rank {
    width: 50px;
    text-align: center;
}

.ranking-table .col-value {
    font-weight: 500;
}

.ranking-table .col-year {
    color: #666;
    width: 60px;
}

.ranking-table .col-continent {
    color: #666;
    width: 120px;
}

.ranking-table .col-country a {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: #12162D;
    text-decoration: none;
}

.ranking-table .col-country a:hover {
    color: #2563eb;
}

.table-flag {
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.other-rankings {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

/* Metric links in country page */
.metric-label a {
    color: #2563eb;
    text-decoration: none;
    cursor: pointer;
    display: inline-block;
}

.metric-label a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .filter-sort-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .filter-controls,
    .sort-controls {
        width: 100%;
    }

    .ranking-table .col-year,
    .ranking-table .col-continent {
        display: none;
    }
}

/* About Section */
.about-section {
    margin-bottom: 1.5rem;
}

.about-section h2 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
    padding-bottom: 0.25rem;
    color: #12162D;
    border-bottom: 2px solid #2563eb;
}

.about-text {
    font-size: 0.9rem;
    line-height: 1.6;
    color: #333;
    margin: 0 0 0.5rem;
}

.about-source {
    font-size: 0.75rem;
    color: #666;
    margin: 0;
}

.about-source a {
    color: #2563eb;
}

/* Rankings Link Button */
.rankings-link-btn {
    padding: 0.4rem 0.75rem;
    background: #2563eb;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.2s;
}

.rankings-link-btn:hover {
    background: #1d4ed8;
}

/* Rankings Index Page */
.rankings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
    padding-bottom: 1rem;
}

.ranking-card {
    display: block;
    padding: 1rem;
    background: #f8f8f8;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, background 0.2s;
}

.ranking-card:hover {
    border-color: #2563eb;
    background: #fff;
}

.ranking-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.25rem;
    color: #12162D;
}

.ranking-card-unit {
    font-size: 0.8rem;
    color: #666;
    margin: 0;
}

/* Ranking Select Dropdown */
.ranking-select {
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fff;
    color: #12162D;
    cursor: pointer;
    margin-left: auto;
}

.ranking-select:focus {
    outline: none;
    border-color: #2563eb;
}

/* All Rankings Link */
.all-rankings-link {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    background: #f6f6f6;
    border-radius: 4px;
    text-decoration: none;
    color: #12162D;
    font-size: 0.85rem;
    transition: background 0.2s;
}

.all-rankings-link:hover {
    background: #e0e0e0;
}

/* About Page */
.about-page {
    max-width: 720px;
}

.about-intro {
    margin-bottom: 1.5rem;
}

.lead-text {
    font-size: 1.1rem;
    line-height: 1.6;
    color: #333;
    margin: 0;
}

.about-block {
    margin-bottom: 1.5rem;
}

.about-block h2 {
    font-size: 1.1rem;
    margin: 0 0 0.5rem;
    padding-bottom: 0.25rem;
    color: #12162D;
    border-bottom: 2px solid #2563eb;
}

.about-block p {
    font-size: 0.9rem;
    line-height: 1.6;
    color: #333;
    margin: 0 0 0.5rem;
}

.about-block ul {
    margin: 0.5rem 0;
    padding-left: 1.25rem;
    font-size: 0.9rem;
    line-height: 1.6;
    color: #333;
}

.about-block li {
    margin-bottom: 0.25rem;
}

.about-block a {
    color: #2563eb;
}

.about-cta {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e0e0e0;
}

.cta-btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    background: #2563eb;
    color: #fff;
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.2s;
}

.cta-btn:hover {
    background: #1d4ed8;
}

.cta-btn.cta-secondary {
    background: #f6f6f6;
    color: #12162D;
}

.cta-btn.cta-secondary:hover {
    background: #e0e0e0;
}

/* Country Selector Dropdown */
.country-selector {
    position: relative;
    margin-left: auto;
}

.country-selector-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #12162D;
    cursor: pointer;
    transition: border-color 0.2s;
}

.country-selector-btn:hover {
    border-color: #2563eb;
}

.country-selector-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.25rem;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    width: 280px;
    max-height: 400px;
    overflow: hidden;
}

.country-selector-dropdown.open {
    display: block;
}

.country-search-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: none;
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.9rem;
    outline: none;
}

.country-search-input:focus {
    background: #f9f9f9;
}

.country-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 340px;
    overflow-y: auto;
}

.country-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}

.country-option:hover {
    background: #f0f0f0;
}

.country-option.current {
    background: #e8f0fe;
    font-weight: 500;
}

.country-option.hidden {
    display: none;
}

.country-option-flag {
    width: 24px;
    height: auto;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
    .country-selector-dropdown {
        width: 260px;
        right: -0.5rem;
    }

    .country-selector-btn span {
        display: none;
    }

    .country-selector-btn::before {
        content: "...";
    }
}
