/* ─── CSS Variables ─────────────────────────────────────────────────────── */
:root {
    --primary: #6366F1;
    --primary-dark: #4F46E5;
    --secondary: #94A3B8;
    --accent: #22D3EE;
    --bg: #0F172A;
    --surface: #1E293B;
    --surface-light: #273449;
    --border: #2E3F5A;
    --text: #F1F5F9;
    --text-muted: #64748B;
    --radius: 12px;
    --excellent: #22C55E;
    --good: #EAB308;
    --fair: #F97316;
    --poor: #EF4444;
    --trans: 220ms ease;
}

/* ─── Reset ─────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
.header {
    border-bottom: 1px solid var(--border);
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-icon {
    font-size: 1.6rem;
}

.brand-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.brand-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* ─── Controls ───────────────────────────────────────────────────────────── */
.interval-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.select-sm {
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.3rem 0.6rem;
    border-radius: 8px;
    font-size: 0.75rem;
    cursor: pointer;
    outline: none;
    transition: border-color var(--trans);
}

.select-sm:focus {
    border-color: var(--primary);
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 1rem;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all var(--trans);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-ghost {
    background: var(--surface-light);
    color: var(--secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    border-color: var(--primary);
    color: var(--text);
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 1rem;
}

/* ─── Map ─────────────────────────────────────────────────────────────────── */
.map-section {}

.map-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.map-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-excellent {
    background: var(--excellent);
    box-shadow: 0 0 6px var(--excellent);
}

.dot-good {
    background: var(--good);
}

.dot-fair {
    background: var(--fair);
}

.dot-poor {
    background: var(--poor);
}

.map-container {
    position: relative;
    width: 100%;
    aspect-ratio: 2 / 1;
    border-radius: 10px;
    overflow: hidden;
    background: #0a1525;
}

.world-map-svg {
    width: 100%;
    height: 100%;
}

.continent {
    fill: #1a2f4a;
    stroke: #243a55;
    stroke-width: 1;
}

.pins-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.map-pin {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: all;
    cursor: pointer;
    z-index: 10;
}

.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    background: var(--text-muted);
    transition: all var(--trans);
    box-shadow: 0 0 8px transparent;
}

.map-pin:hover .pin-dot {
    transform: scale(1.4);
}

.map-pin.excellent .pin-dot {
    background: var(--excellent);
    box-shadow: 0 0 10px var(--excellent);
    border-color: rgba(34, 197, 94, 0.5);
}

.map-pin.good .pin-dot {
    background: var(--good);
    box-shadow: 0 0 8px var(--good);
}

.map-pin.fair .pin-dot {
    background: var(--fair);
    box-shadow: 0 0 8px var(--fair);
}

.map-pin.poor .pin-dot {
    background: var(--poor);
    box-shadow: 0 0 8px var(--poor);
}

.map-pin.testing .pin-dot {
    animation: pulse 1s infinite;
}

.pin-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
    font-size: 0.72rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--trans);
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.map-pin:hover .pin-tooltip {
    opacity: 1;
}

.pin-tooltip-name {
    font-weight: 600;
    color: var(--text);
}

.pin-tooltip-latency {
    color: var(--accent);
    margin-top: 2px;
}

/* ─── Results Grid ───────────────────────────────────────────────────────── */
.results-section {}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.provider-tabs {
    display: flex;
    gap: 0.5rem;
}

.tab-btn {
    padding: 0.3rem 0.8rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--trans);
}

.tab-btn.active,
.tab-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.75rem;
}

.region-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: all var(--trans);
    position: relative;
    overflow: hidden;
}

.region-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--text-muted);
    transition: background var(--trans);
}

.region-card.excellent::before {
    background: var(--excellent);
}

.region-card.good::before {
    background: var(--good);
}

.region-card.fair::before {
    background: var(--fair);
}

.region-card.poor::before {
    background: var(--poor);
}

.region-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.region-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.region-name {
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.3;
}

.provider-badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.badge-aws {
    background: rgb(255, 153, 0, 0.15);
    color: #FF9900;
}

.badge-gcp {
    background: rgb(66, 133, 244, 0.15);
    color: #4285F4;
}

.badge-azure {
    background: rgb(0, 164, 239, 0.15);
    color: #00A4EF;
}

.region-location {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.region-latency {
    font-size: 1.6rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.region-latency.testing {
    font-size: 0.8rem;
    color: var(--text-muted);
    animation: blink 1s infinite;
}

.latency-unit {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 2px;
}

.region-bar-wrap {
    margin-top: 0.6rem;
    height: 4px;
    background: var(--surface-light);
    border-radius: 2px;
    overflow: hidden;
}

.region-bar {
    height: 100%;
    width: 0;
    border-radius: 2px;
    transition: width 0.6s ease, background 0.4s;
}

.region-bar.excellent {
    background: var(--excellent);
}

.region-bar.good {
    background: var(--good);
}

.region-bar.fair {
    background: var(--fair);
}

.region-bar.poor {
    background: var(--poor);
}

.test-btn-row {
    margin-top: 0.75rem;
}

.btn-test {
    width: 100%;
    padding: 0.35rem;
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--trans);
}

.btn-test:hover {
    border-color: var(--primary);
    color: var(--text);
}

/* ─── Bottom Panels ──────────────────────────────────────────────────────── */
.bottom-panels {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 900px) {
    .bottom-panels {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.history-panel canvas {
    width: 100% !important;
    max-height: 180px;
}

.chart-sub {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.5rem;
}

.history-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.hist-leg-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.hist-leg-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Nearest / comparison */
.nearest-card {
    background: var(--surface-light);
    border-radius: 10px;
    padding: 1rem;
    min-height: 80px;
    display: flex;
    align-items: center;
}

.nearest-placeholder {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.nearest-region-name {
    font-size: 1rem;
    font-weight: 700;
}

.nearest-region-loc {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.nearest-region-ms {
    font-size: 2rem;
    font-weight: 700;
    color: var(--excellent);
    margin-top: 0.5rem;
}

.nearest-badge {
    margin-top: 0.25rem;
}

.comparison-bars {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.cmp-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.cmp-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
}

.cmp-bar-wrap {
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
}

.cmp-bar {
    height: 100%;
    border-radius: 4px;
    transition: width 0.7s ease;
}

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.5);
        opacity: 0.6;
    }
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-size: 0.82rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 999;
    animation: fadeIn 0.3s ease;
}

.toast.hidden {
    display: none;
}

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg);
}

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

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .header-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .legend {
        gap: 0.5rem;
    }

    .map-header {
        flex-direction: column;
    }
}