:root {
    --font-ui: 'Manrope', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;

    /* DC Colors (Vibrant) */
    --dc1: #FF3B30;
    --dc2: #007AFF;
    --dc3: #34C759;
    --dc4: #FFCC00;
    --dc5: #AF52DE;
}

[data-theme="light"] {
    --bg-app: #F5F5F7;
    --bg-card: #FFFFFF;
    --bg-sidebar: #FFFFFF;
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --border: #E5E5EA;
    --accent: #0071E3;
    --accent-hover: #0077ED;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
    --bg-app: #000000;
    --bg-card: #1C1C1E;
    --bg-sidebar: #1C1C1E;
    --text-primary: #F5F5F7;
    --text-secondary: #86868B;
    --border: #38383A;
    --accent: #0A84FF;
    --accent-hover: #409CFF;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-ui);
    background-color: var(--bg-app);
    color: var(--text-primary);
    transition: background 0.3s, color 0.3s;
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, use container scroll */
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 10;
    overflow-y: auto;
}

.sidebar-header {
    margin-bottom: 2rem;
}

.logo-box {
    width: 40px;
    height: 40px;
    background: var(--text-primary);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.pulse-dot {
    width: 12px;
    height: 12px;
    background: var(--bg-card);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 0.5;
        transform: scale(0.8);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }

    100% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1.1;
    margin: 0;
    letter-spacing: -0.02em;
}

.control-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.status-badge-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-app);
    border-radius: var(--radius-sm);
}

.mono-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.status-pill {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
}

.info-grid {
    display: grid;
    gap: 1rem;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.mono-val {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 700;
}

.primary-btn {
    width: 100%;
    background: var(--accent);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 0.95rem;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(0, 113, 227, 0.2);
}

.primary-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.primary-btn:disabled {
    opacity: 0.6;
    cursor: wait;
    transform: none;
    box-shadow: none;
}

.btn-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}


.theme-switcher {
    display: flex;
    gap: 0.5rem;
    margin-top: 2rem;
    padding: 0.25rem;
    background: var(--bg-app);
    border-radius: var(--radius-lg);
    width: fit-content;
}

.theme-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
}

.theme-btn.active {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}


.side-footer {
    margin-top: 2rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.side-footer p {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.mono-xs {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Main Content */
.main-view {
    flex: 1;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    overflow-y: auto;
    /* Enable scroll */
    height: 100%;
}

/* DC Grid */
.dc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    flex-shrink: 0;
}

.rec-box {
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 4px 12px rgba(var(--accent-rgb), 0.1);
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.rec-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    font-weight: 700;
}

.rec-val {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

#best-dc-id {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--accent);
}

#best-dc-ms {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.rank-badge {
    font-size: 0.8rem;
    font-weight: 800;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: var(--bg-app);
    color: var(--text-secondary);
    font-family: var(--font-mono);
}

.rank-badge.rank-1 {
    background: #FFD700;
    color: #000;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
    border: 1px solid #FFD700;
}

.rank-badge.rank-2 {
    background: #C0C0C0;
    color: #000;
    border: 1px solid #C0C0C0;
}

.rank-badge.rank-3 {
    background: #CD7F32;
    color: #fff;
    border: 1px solid #CD7F32;
}

.dc-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 180px;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid transparent;
}

.dc-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.08);
}

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.dc-badge {
    font-size: 0.75rem;
    font-weight: 800;
    color: #fff;
    padding: 0.3rem 0.6rem;
    border-radius: 99px;
    font-family: var(--font-mono);
}

.badge-dc1 {
    background: var(--dc1);
}

.badge-dc2 {
    background: var(--dc2);
}

.badge-dc3 {
    background: var(--dc3);
}

.badge-dc4 {
    background: var(--dc4);
}

.badge-dc5 {
    background: var(--dc5);
}

.dc-region {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.card-main {
    margin-bottom: auto;
}

.latency-value {
    font-family: var(--font-ui);
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.05em;
    display: block;
    line-height: 1;
}

.latency-unit {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.card-bottom {
    margin-top: 1.5rem;
}

.status-text {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    display: block;
    margin-bottom: 0.5rem;
}

.mini-progress-track {
    height: 6px;
    background: var(--bg-app);
    border-radius: 99px;
    overflow: hidden;
}

.mini-progress-bar {
    height: 100%;
    width: 0%;
    transition: width 0.3s ease;
}

.badge-dc1-bg {
    background-color: var(--dc1);
}

.badge-dc2-bg {
    background-color: var(--dc2);
}

.badge-dc3-bg {
    background-color: var(--dc3);
}

.badge-dc4-bg {
    background-color: var(--dc4);
}

.badge-dc5-bg {
    background-color: var(--dc5);
}


/* Graph Section */
.visualizer-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    height: 400px;
    /* Fixed robust height */
    min-height: 400px;
    margin-bottom: 2rem;
    /* Add margin at bottom for scroll space */
    position: relative;
    flex-shrink: 0;
}

.vis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.vis-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-secondary);
}

.vis-legend {
    display: flex;
    gap: 1.5rem;
}

.v-tag {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.chart-container {
    flex: 1;
    width: 100%;
    height: 100%;
    /* Fill the section */
    position: relative;
    overflow: hidden;
}

canvas {
    width: 100%;
    height: 100%;
}

/* Mobile Refinements - Compact Mode */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: auto;
        flex-shrink: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 0.5rem 0.75rem;
        /* Super compact padding */
        background: var(--bg-sidebar);
        overflow-y: visible;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        /* Reduced gap */
    }

    .sidebar-header {
        margin: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        position: relative;
    }

    .header-left {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .logo-box {
        width: 24px;
        height: 24px;
        margin: 0;
    }

    .sidebar-header h1 {
        font-size: 0.9rem;
        line-height: 1;
    }

    .theme-switcher {
        position: static;
        background: var(--bg-app);
        padding: 0.1rem;
        margin: 0;
        transform: scale(0.9);
    }

    .theme-btn {
        padding: 0.25rem;
    }

    .control-box {
        display: flex;
        flex-direction: row;
        width: 100%;
        gap: 0.5rem;
        margin: 0;
        align-items: center;
    }

    .primary-btn {
        flex: 1;
        padding: 0.5rem;
        font-size: 0.8rem;
        border-radius: var(--radius-sm);
        height: 36px;
    }

    /* Main View Compact */
    .main-view {
        padding: 0.5rem;
        height: 100%;
        overflow-y: auto;
        gap: 0.75rem;
    }

    .dc-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .dc-card {
        min-height: 90px;
        padding: 0.75rem;
        border-radius: var(--radius-md);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    }

    .card-top {
        margin-bottom: 0.25rem;
    }

    .dc-badge {
        font-size: 0.6rem;
        padding: 0.15rem 0.4rem;
    }

    .dc-region {
        font-size: 0.6rem;
    }

    .latency-value {
        font-size: 1.5rem;
        letter-spacing: -0.05em;
    }

    .latency-unit {
        font-size: 0.7rem;
    }

    .card-bottom {
        margin-top: 0.5rem;
    }

    .status-text {
        font-size: 0.6rem;
        margin-bottom: 0.2rem;
    }

    .mini-progress-track {
        height: 3px;
    }

    /* Compact Graph */
    .visualizer-section {
        height: 200px;
        min-height: 200px;
        padding: 0.5rem;
        border-radius: var(--radius-md);
        margin-bottom: 0.5rem;
        /* Tiny margin */
    }

    .vis-header {
        margin-bottom: 0.25rem;
    }

    .vis-header h3 {
        font-size: 0.75rem;
    }

    .vis-legend {
        display: none;
    }

    /* Hide non-essentials */
    .status-badge-row,
    .info-grid,
    .side-footer {
        display: none;
    }
}