/* CSS Custom Properties for theming */
:root {
    --color-primary: #232F3E;      /* AWS dark blue */
    --color-secondary: #FF9900;    /* AWS orange */
    --color-background: #F5F7FA;
    --color-surface: #FFFFFF;
    --color-text: #16191F;
    --color-text-muted: #687078;
    --color-border: #D5DBDB;
    --color-source: #166534;
    --color-dest: #0969DA;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --radius-sm: 4px;
    --radius-md: 8px;
}

/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-background);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Header */
.header {
    background: var(--color-primary);
    color: white;
    padding: 24px;
    box-shadow: var(--shadow-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 100%;
}

.header-content {
    flex: 1;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.subtitle {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

/* Header Meta (version selector, about link) */
.header-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}

.version-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.9);
}

.version-selector label {
    font-weight: 500;
}

.version-selector select {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-sm);
    color: white;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    min-width: 180px;
}

.version-selector select:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.version-selector select:focus {
    outline: none;
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 2px rgba(255, 153, 0, 0.3);
}

.version-selector select option {
    background: var(--color-primary);
    color: white;
}

.header-meta .about-link {
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    font-size: 13px;
}

.header-meta .about-link:hover {
    color: var(--color-secondary);
    text-decoration: underline;
}

/* Historical data indicator */
.historical-banner {
    background: #FEF3C7;
    border-bottom: 1px solid #FCD34D;
    padding: 8px 24px;
    text-align: center;
    font-size: 13px;
    color: #92400E;
}

.historical-banner strong {
    font-weight: 600;
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 24px;
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px;
}

/* Filters Panel */
.filters-panel {
    background: var(--color-surface);
    padding: 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    height: fit-content;
    position: sticky;
    top: 24px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--color-text);
}

.filter-group input[type="text"],
.filter-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-group input[type="text"]:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--color-secondary);
    box-shadow: 0 0 0 3px rgba(255, 153, 0, 0.15);
}

.filter-help {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* Checkbox group for providers */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
    padding-right: 4px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 14px;
}

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.provider-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

.filter-stats {
    padding: 12px;
    background: var(--color-background);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 14px;
    color: var(--color-text-muted);
    margin-bottom: 16px;
}

.filter-stats span {
    font-weight: 600;
    color: var(--color-text);
}

.btn-secondary {
    width: 100%;
    padding: 10px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-secondary:hover {
    background: var(--color-background);
    border-color: var(--color-text-muted);
}

/* Results Section */
.results-section {
    min-width: 0; /* Prevent grid blowout */
}

/* Map Container */
.map-container {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    margin-bottom: 24px;
}

#map {
    height: 400px;
    width: 100%;
}

.map-legend {
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    border-top: 1px solid var(--color-border);
    font-size: 13px;
    color: var(--color-text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.legend-marker--source {
    background: var(--color-source);
}

.legend-marker--dest {
    background: var(--color-dest);
}

.legend-line {
    width: 24px;
    height: 3px;
    background: var(--color-secondary);
    border-radius: 2px;
}

/* Profile Cards Grid */
.profiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.profile-card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
    border-left: 4px solid var(--provider-color, var(--color-secondary));
}

.profile-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.profile-card__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
}

.profile-card__name {
    font-weight: 600;
    font-size: 15px;
    color: var(--color-text);
    flex: 1;
}

.profile-card__provider {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    color: white;
    font-weight: 500;
    white-space: nowrap;
}

.profile-card__id {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 12px;
    color: var(--color-text-muted);
    word-break: break-all;
    margin-bottom: 12px;
    padding: 6px 8px;
    background: var(--color-background);
    border-radius: var(--radius-sm);
}

.profile-card__description {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.profile-card__regions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.region-tag {
    font-size: 11px;
    padding: 2px 6px;
    background: #E8F4FD;
    color: var(--color-dest);
    border-radius: 4px;
    font-weight: 500;
}

.region-tag--source {
    background: #DCFCE7;
    color: var(--color-source);
}

.region-tag--more {
    background: var(--color-background);
    color: var(--color-text-muted);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--color-text-muted);
    line-height: 1;
    padding: 4px;
    transition: color 0.2s;
}

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

/* Modal Content Styles */
.profile-detail__header {
    margin-bottom: 20px;
}

.profile-detail__header h2 {
    font-size: 1.25rem;
    margin-bottom: 8px;
}

.profile-detail__meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    padding: 16px;
    background: var(--color-background);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.meta-item {
    font-size: 14px;
}

.meta-item strong {
    display: block;
    font-size: 12px;
    color: var(--color-text-muted);
    margin-bottom: 2px;
    font-weight: 500;
}

.meta-item code {
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 12px;
    background: var(--color-surface);
    padding: 2px 6px;
    border-radius: 3px;
    word-break: break-all;
}

.routing-section {
    margin-bottom: 20px;
}

.routing-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.routing-section h3 .count {
    font-weight: 400;
    color: var(--color-text-muted);
}

.region-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.region-chip {
    display: inline-flex;
    flex-direction: column;
    padding: 8px 12px;
    background: var(--color-background);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.region-chip__id {
    font-weight: 600;
    font-family: monospace;
}

.region-chip__name {
    font-size: 11px;
    color: var(--color-text-muted);
}

.region-chip--source {
    background: #DCFCE7;
    border: 1px solid #BBF7D0;
}

.region-chip--dest {
    background: #E8F4FD;
    border: 1px solid #BFDBFE;
}

#detail-map {
    height: 300px;
    border-radius: var(--radius-sm);
    margin-top: 16px;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--color-text);
}

/* Loading state */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--color-text-muted);
}

/* Error state */
.error-message {
    text-align: center;
    padding: 40px 20px;
    background: #FEF2F2;
    color: #991B1B;
    border-radius: var(--radius-md);
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px;
    color: var(--color-text-muted);
    font-size: 13px;
    border-top: 1px solid var(--color-border);
    margin-top: 24px;
}

.footer a {
    color: var(--color-dest);
    text-decoration: none;
}

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

.footer p {
    margin-bottom: 4px;
}

/* Responsive Design */
@media (max-width: 900px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .filters-panel {
        position: static;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }

    .filter-group:first-child {
        grid-column: 1 / -1;
    }

    .filter-stats {
        grid-column: 1 / -1;
        margin-bottom: 0;
    }

    #clear-filters {
        grid-column: 1 / -1;
    }

    .checkbox-group {
        max-height: 150px;
    }

    #map {
        height: 300px;
    }

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

@media (max-width: 600px) {
    .header {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .header-meta {
        width: 100%;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .main-content {
        padding: 16px;
    }

    .filters-panel {
        grid-template-columns: 1fr;
    }

    .modal-content {
        padding: 16px;
        width: 95%;
    }

    .profile-detail__meta {
        grid-template-columns: 1fr;
    }
}

/* Custom scrollbar */
.checkbox-group::-webkit-scrollbar {
    width: 6px;
}

.checkbox-group::-webkit-scrollbar-track {
    background: var(--color-background);
    border-radius: 3px;
}

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

.checkbox-group::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* Leaflet popup overrides */
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm);
}

.leaflet-popup-content {
    margin: 10px 12px;
    font-size: 13px;
}

/* Latency Test Section */
.latency-section {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    border-radius: var(--radius-md);
    padding: 20px;
}

.latency-summary {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
}

.latency-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.latency-stat__value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-text);
}

.latency-stat--best .latency-stat__value {
    color: #166534;
}

.latency-stat__label {
    font-size: 12px;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.latency-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.latency-bar-row {
    display: grid;
    grid-template-columns: 140px 1fr 80px;
    gap: 12px;
    align-items: center;
}

.latency-bar-row--fastest .latency-bar__fill {
    background: linear-gradient(90deg, #22c55e, #16a34a);
}

.latency-bar__region {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.latency-bar__region-id {
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text);
}

.latency-bar__region-name {
    font-size: 11px;
    color: var(--color-text-muted);
}

.latency-bar__container {
    height: 24px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.latency-bar__fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.latency-bar__value {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.latency-bar__error {
    font-size: 11px;
    color: #dc2626;
    font-weight: 500;
}

@media (max-width: 600px) {
    .latency-bar-row {
        grid-template-columns: 100px 1fr 60px;
    }

    .latency-summary {
        flex-direction: column;
        gap: 12px;
    }
}

/* About Link in Footer */
.footer-sep {
    margin: 0 8px;
    color: var(--color-text-muted);
}

.about-link {
    background: none;
    border: none;
    color: var(--color-secondary);
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
    text-decoration: underline;
    padding: 0;
}

.about-link:hover {
    color: #CC7A00;
}

/* About Modal Content */
.modal-content--about {
    max-width: 700px;
}

.about-content {
    padding: 8px 0;
}

.about-content h2 {
    font-size: 1.5rem;
    margin-bottom: 12px;
    color: var(--color-text);
}

.about-intro {
    font-size: 15px;
    color: var(--color-text-muted);
    margin-bottom: 24px;
    line-height: 1.6;
}

.about-section {
    margin-bottom: 24px;
}

.about-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 2px solid var(--color-secondary);
    display: inline-block;
}

.about-section p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--color-text);
    margin-bottom: 8px;
}

.about-section ul {
    margin: 8px 0;
    padding-left: 20px;
}

.about-section li {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 6px;
    color: var(--color-text);
}

.about-section code {
    background: var(--color-background);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 13px;
    color: var(--color-primary);
}

.about-links {
    list-style: none;
    padding-left: 0;
}

.about-links li {
    margin-bottom: 8px;
}

.about-links a {
    color: var(--color-dest);
    text-decoration: none;
}

.about-links a:hover {
    text-decoration: underline;
}

/* Changelog Styles */
.changelog-entry {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--color-border);
}

.changelog-entry:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.changelog-date {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin-bottom: 4px;
}

.changelog-entry h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 12px 0;
    color: var(--color-primary);
}

.changelog-entry ul {
    margin: 0;
    padding-left: 20px;
}

.changelog-entry li {
    margin-bottom: 6px;
    line-height: 1.5;
}
