/**
 * CryptoLiqMap — Design System
 * Professional dark theme with glassmorphism, gradients, and micro-animations.
 */

/* ─── Google Fonts Import ──────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ─── CSS Custom Properties ────────────────────────────────────── */
:root {
    /* Colors */
    --bg-primary: #0a0a1a;
    --bg-secondary: #0f0f23;
    --bg-tertiary: #141428;
    --bg-panel: rgba(15, 15, 35, 0.85);
    --bg-panel-hover: rgba(20, 20, 45, 0.9);
    --bg-card: rgba(20, 20, 40, 0.6);

    --border-color: rgba(139, 92, 246, 0.15);
    --border-hover: rgba(139, 92, 246, 0.35);
    --border-active: rgba(139, 92, 246, 0.6);

    --accent-primary: #8b5cf6;
    --accent-primary-rgb: 139, 92, 246;
    --accent-secondary: #06b6d4;
    --accent-secondary-rgb: 6, 182, 212;
    --accent-warm: #f59e0b;

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-dimmed: #475569;

    --long-color: #22c55e;
    --long-color-rgb: 34, 197, 94;
    --long-bg: rgba(34, 197, 94, 0.1);
    --long-bg-solid: #0a2a1a;

    --short-color: #ef4444;
    --short-color-rgb: 239, 68, 68;
    --short-bg: rgba(239, 68, 68, 0.1);
    --short-bg-solid: #2a0a0a;

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    --gradient-header: linear-gradient(90deg, rgba(139, 92, 246, 0.1), rgba(6, 182, 212, 0.05), transparent);
    --gradient-glow: radial-gradient(ellipse at center, rgba(139, 92, 246, 0.15) 0%, transparent 70%);

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.15);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

    /* Sizing */
    --header-height: 52px;
    --sidebar-width: 300px;
    --controls-height: 44px;
    --border-radius: 8px;
    --border-radius-sm: 5px;
    --border-radius-lg: 12px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
    --transition-slow: 0.4s ease;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Custom Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.25);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.4);
}

/* ─── App Layout ───────────────────────────────────────────────── */
#app {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
}

/* Background glow effect */
#app::before {
    content: '';
    position: fixed;
    top: -200px;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 500px;
    background: var(--gradient-glow);
    pointer-events: none;
    z-index: 0;
    opacity: 0.6;
}

/* ─── Header ───────────────────────────────────────────────────── */
.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--bg-panel);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    position: relative;
    gap: 12px;
    flex-shrink: 0;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), var(--accent-secondary), transparent);
    opacity: 0.4;
}

/* Logo */
.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 16px;
    color: var(--text-primary);
    user-select: none;
    flex-shrink: 0;
}

.logo-icon {
    font-size: 22px;
    filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.5));
    animation: fireGlow 2s ease-in-out infinite;
}

@keyframes fireGlow {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.5)); }
    50% { filter: drop-shadow(0 0 12px rgba(234, 88, 12, 0.7)); }
}

.logo-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.3px;
}

.header-divider {
    width: 1px;
    height: 28px;
    background: var(--border-color);
    flex-shrink: 0;
}

/* ─── Symbol Selector ──────────────────────────────────────────── */
.symbol-selector {
    position: relative;
    flex-shrink: 0;
}

.symbol-select {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.symbol-select:hover {
    border-color: var(--border-hover);
    background: var(--bg-panel-hover);
}

.symbol-icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.symbol-name {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -0.2px;
}

.symbol-arrow {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.symbol-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 200px;
    max-height: 360px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: none;
    backdrop-filter: blur(16px);
}

.symbol-dropdown.active {
    display: block;
    animation: dropdownIn 0.2s ease;
}

@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 13px;
}

.dropdown-item:hover {
    background: rgba(139, 92, 246, 0.1);
}

.dropdown-item.active {
    background: rgba(139, 92, 246, 0.15);
    color: var(--accent-primary);
}

.dropdown-item-icon {
    width: 22px;
    text-align: center;
    font-size: 15px;
}

/* ─── Timeframe Bar ────────────────────────────────────────────── */
.timeframe-bar {
    display: flex;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 3px;
    flex-shrink: 0;
}

.tf-btn {
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    letter-spacing: 0.2px;
}

.tf-btn:hover {
    color: var(--text-primary);
    background: rgba(139, 92, 246, 0.1);
}

.tf-btn.active {
    color: #fff;
    background: var(--accent-primary);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.3);
}

/* ─── Leverage Bar ─────────────────────────────────────────────── */
.leverage-section {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.leverage-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
}

.leverage-bar {
    display: flex;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 3px;
}

.lev-btn {
    padding: 4px 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.lev-btn:hover {
    color: var(--text-primary);
    background: rgba(139, 92, 246, 0.1);
}

.lev-btn.active {
    color: #fff;
    background: rgba(139, 92, 246, 0.35);
    border: 1px solid rgba(139, 92, 246, 0.5);
}

/* ─── Header Right ─────────────────────────────────────────────── */
.header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.fullscreen-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 16px;
}

.fullscreen-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
    background: var(--bg-panel-hover);
}

/* ─── Main Layout ──────────────────────────────────────────────── */
.main-layout {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* ─── Chart Area ───────────────────────────────────────────────── */
.chart-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chart-container {
    flex: 1;
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
}

.chart-container canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#heatmap-canvas {
    z-index: 1;
}

#chart-canvas {
    z-index: 2;
}

/* ─── Bottom Controls ──────────────────────────────────────────── */
.bottom-controls {
    height: var(--controls-height);
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    gap: 16px;
    flex-shrink: 0;
}

/* Exchange toggles */
.exchange-toggles {
    display: flex;
    gap: 6px;
}

.exchange-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

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

.exchange-btn.active {
    border-color: var(--accent-primary);
    color: var(--text-primary);
    background: rgba(139, 92, 246, 0.1);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-dimmed);
    flex-shrink: 0;
    transition: background var(--transition-base);
}

.status-dot.connected {
    background: var(--long-color);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
    animation: statusPulse 2s ease-in-out infinite;
}

.status-dot.connecting {
    background: var(--accent-warm);
    animation: statusBlink 1s ease infinite;
}

.status-dot.error {
    background: var(--short-color);
}

.status-dot.disconnected {
    background: var(--text-dimmed);
}

@keyframes statusPulse {
    0%, 100% { box-shadow: 0 0 4px rgba(34, 197, 94, 0.3); }
    50% { box-shadow: 0 0 8px rgba(34, 197, 94, 0.6); }
}

@keyframes statusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Long/Short ratio bar */
.ratio-bar-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 400px;
}

.ratio-label {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.ratio-label.long {
    color: var(--long-color);
}

.ratio-label.short {
    color: var(--short-color);
}

.ratio-bar {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    background: var(--bg-tertiary);
}

.ratio-bar-long {
    height: 100%;
    background: linear-gradient(90deg, var(--long-color), rgba(34, 197, 94, 0.6));
    transition: width var(--transition-slow);
    border-radius: 3px 0 0 3px;
    width: 50%;
}

.ratio-bar-short {
    height: 100%;
    background: linear-gradient(90deg, rgba(239, 68, 68, 0.6), var(--short-color));
    transition: width var(--transition-slow);
    border-radius: 0 3px 3px 0;
    width: 50%;
}

/* ─── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    border-left: 1px solid var(--border-color);
    overflow: hidden;
    flex-shrink: 0;
}

/* ─── Stats Panel ──────────────────────────────────────────────── */
.stats-panel {
    padding: 14px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.stats-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.stats-header-icon {
    font-size: 14px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.stat-label {
    color: var(--text-muted);
    font-size: 12px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.stat-value.positive {
    color: var(--long-color);
}

.stat-value.negative {
    color: var(--short-color);
}

.stat-value.highlight {
    color: var(--accent-warm);
}

.stat-value.accent {
    color: var(--accent-primary);
}

.stat-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0;
}

/* Liquidation stat boxes */
.liq-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.liq-stat-box {
    padding: 10px;
    border-radius: var(--border-radius);
    text-align: center;
}

.liq-stat-box.long {
    background: var(--long-bg);
    border: 1px solid rgba(34, 197, 94, 0.15);
}

.liq-stat-box.short {
    background: var(--short-bg);
    border: 1px solid rgba(239, 68, 68, 0.15);
}

.liq-stat-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 4px;
}

.liq-stat-box.long .liq-stat-label {
    color: var(--long-color);
}

.liq-stat-box.short .liq-stat-label {
    color: var(--short-color);
}

.liq-stat-value {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.liq-stat-count {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Feed Panel ───────────────────────────────────────────────── */
.feed-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.feed-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 14px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.feed-header-icon {
    font-size: 14px;
    animation: feedPulse 1.5s ease infinite;
}

@keyframes feedPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.feed-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}

.feed-item {
    padding: 8px 10px;
    border-radius: var(--border-radius-sm);
    margin-bottom: 4px;
    border-left: 3px solid transparent;
    transition: all var(--transition-fast);
}

.feed-item.long {
    background: rgba(34, 197, 94, 0.04);
    border-left-color: var(--long-color);
}

.feed-item.short {
    background: rgba(239, 68, 68, 0.04);
    border-left-color: var(--short-color);
}

.feed-item:hover {
    background: rgba(139, 92, 246, 0.08);
}

.feed-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px;
}

.feed-side {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.feed-side.long { color: var(--long-color); }
.feed-side.short { color: var(--short-color); }

.feed-exchange {
    font-size: 10px;
    color: var(--text-dimmed);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.feed-item-body {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 12px;
}

.feed-symbol {
    font-weight: 600;
    color: var(--text-primary);
}

.feed-value {
    font-weight: 700;
    color: var(--accent-warm);
}

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

.feed-time {
    font-size: 10px;
    color: var(--text-dimmed);
    margin-top: 2px;
}

/* Feed empty state */
.feed-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    color: var(--text-dimmed);
    text-align: center;
    gap: 8px;
}

.feed-empty-icon {
    font-size: 28px;
    opacity: 0.5;
}

.feed-empty-text {
    font-size: 12px;
}

/* ─── Gradient Legend ──────────────────────────────────────────── */
.gradient-legend {
    padding: 12px 14px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.gradient-legend-label {
    font-size: 10px;
    color: var(--text-dimmed);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 6px;
}

.gradient-bar {
    height: 10px;
    border-radius: 5px;
    background: linear-gradient(90deg,
        #0a0a1a 0%,
        #14123700 5%,
        #1e1b4b 12%,
        #3730a3 22%,
        #2563eb 35%,
        #0891b2 45%,
        #16a34a 55%,
        #ca8a04 68%,
        #ea580c 82%,
        #dc2626 92%,
        #ffff64 100%
    );
    margin-bottom: 4px;
}

.gradient-labels {
    display: flex;
    justify-content: space-between;
    font-size: 9px;
    color: var(--text-dimmed);
    font-family: var(--font-mono);
}

/* ─── Responsive ───────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .sidebar {
        width: 260px;
    }
    .leverage-section {
        display: none;
    }
}

@media (max-width: 900px) {
    .sidebar {
        display: none;
    }
    .header {
        padding: 0 10px;
        gap: 8px;
    }
    .logo-text {
        display: none;
    }
    .timeframe-bar {
        gap: 1px;
    }
    .tf-btn {
        padding: 4px 7px;
        font-size: 11px;
    }
}

@media (max-width: 600px) {
    .header {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 10px;
        gap: 6px;
    }
    .bottom-controls {
        flex-wrap: wrap;
        height: auto;
        padding: 8px;
        gap: 8px;
    }
    .ratio-bar-container {
        max-width: 100%;
        width: 100%;
    }
}

/* ─── Fullscreen ───────────────────────────────────────────────── */
#app:fullscreen {
    background: var(--bg-primary);
}

#app:fullscreen .header {
    background: var(--bg-secondary);
}
