:root {
    --bg-color: #0b0d14;
    --panel-bg: #141722;
    --card-bg: #1b1f2e;
    --border-color: #262b3e;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    
    --accent-blue: #3b82f6;
    --accent-blue-hover: #2563eb;
    --accent-emerald: #10b981;
    --accent-red: #ef4444;
    --accent-amber: #f59e0b;
    --accent-purple: #8b5cf6;
    --accent-cyan: #06b6d4;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-sans);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Mobile viewport height fix */
}

/* Header */
.app-header {
    background: rgba(20, 23, 34, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.brand-title {
    font-size: 1.15rem;
    font-weight: 700;
    background: linear-gradient(135deg, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    border: none;
    outline: none;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    min-height: 40px; /* Touch friendly minimum height */
    user-select: none;
}

.btn-primary {
    background-color: var(--accent-blue);
    color: white;
}
.btn-primary:hover {
    background-color: var(--accent-blue-hover);
    transform: translateY(-1px);
}
.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background-color: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover {
    background-color: #22273a;
    border-color: #3b425b;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
}
.btn-outline:hover {
    color: var(--text-main);
    border-color: var(--accent-blue);
}

.file-btn-wrapper {
    position: relative;
    overflow: hidden;
}

.file-btn-wrapper input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* Control Bar */
.control-bar {
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.stats-group {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.stat-item span {
    color: var(--text-main);
    font-weight: 600;
}

.channel-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
}
.channel-pills::-webkit-scrollbar {
    display: none;
}

.pill {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.pill.active {
    color: white;
    border-color: transparent;
}
.pill-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.perf-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
    user-select: none;
}

.switch {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #2a2f45;
    transition: .3s;
    border-radius: 22px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--accent-emerald);
}
input:checked + .slider:before {
    transform: translateX(16);
}

/* Main Display */
.main-content {
    flex: 1;
    position: relative;
    padding: 16px;
    display: flex;
    flex-direction: column;
}

.chart-card {
    flex: 1;
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#chart {
    width: 100%;
    height: 100%;
    min-height: 250px;
    touch-action: none; /* Let ECharts handle touch gestures smoothly */
}

/* Empty State & Overlays */
.empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    background-color: var(--panel-bg);
    z-index: 20;
}
.empty-icon {
    width: 64px;
    height: 64px;
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--accent-blue);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}
.empty-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.empty-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    max-width: 360px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 13, 20, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.loading-text {
    margin-top: 14px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-main);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .app-header {
        padding: 10px 14px;
    }
    .brand-title {
        font-size: 1rem;
    }
    .control-bar {
        padding: 8px 14px;
        gap: 8px;
    }
    .main-content {
        padding: 10px;
    }
    .btn {
        padding: 8px 12px;
        font-size: 0.82rem;
    }
    .stats-group {
        width: 100%;
        justify-content: space-between;
        font-size: 0.78rem;
    }
}
