/* ========================================================
   퀀트리 Portfolio — Main Stylesheet
   Dark/Light theme support
   ======================================================== */

/* ======================== RESET & BASE ======================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* — Dark Theme (default) — */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(17, 24, 39, 0.9);
    --bg-surface: #1a2035;
    --bg-toolbar: rgba(15, 20, 35, 0.85);
    --bg-header: rgba(10, 14, 23, 0.85);
    --bg-body-gradient1: rgba(99, 102, 241, 0.08);
    --bg-body-gradient2: rgba(139, 92, 246, 0.04);

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-accent: #f8fafc;

    --accent-primary: #6366f1;
    --accent-primary-glow: rgba(99, 102, 241, 0.3);
    --accent-purple: #8b5cf6;

    --color-total: #a78bfa;
    --color-total-glow: rgba(167, 139, 250, 0.25);
    --color-bybit: #f59e0b;
    --color-bybit-glow: rgba(245, 158, 11, 0.25);
    --color-mt5: #3b82f6;
    --color-mt5-glow: rgba(59, 130, 246, 0.25);
    --candle-up: #00d4aa;
    --candle-down: #ff4757;

    --border-color: rgba(148, 163, 184, 0.1);
    --border-glow: rgba(99, 102, 241, 0.4);

    --chart-bg: #0d1117;
    --chart-grid: rgba(148, 163, 184, 0.04);
    --chart-border: rgba(148, 163, 184, 0.08);
    --chart-text: #64748b;
    --chart-crosshair: #94a3b8;
    --chart-label-bg: #1e293b;

    --scrollbar-thumb: rgba(148, 163, 184, 0.15);
    --scrollbar-hover: rgba(148, 163, 184, 0.25);
    --source-selector-bg: rgba(15, 20, 35, 0.6);
    --chat-msg-bg: rgba(148, 163, 184, 0.04);

    --header-height: 60px;
    --content-padding: 20px;
    --card-radius: 14px;
    --btn-radius: 8px;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* — Light Theme — */
[data-theme="light"] {
    --bg-primary: #f1f5f9;
    --bg-secondary: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-hover: rgba(255, 255, 255, 0.95);
    --bg-surface: #e2e8f0;
    --bg-toolbar: rgba(248, 250, 252, 0.9);
    --bg-header: rgba(255, 255, 255, 0.88);
    --bg-body-gradient1: rgba(99, 102, 241, 0.04);
    --bg-body-gradient2: rgba(139, 92, 246, 0.02);

    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-accent: #0f172a;

    --border-color: rgba(148, 163, 184, 0.2);
    --border-glow: rgba(99, 102, 241, 0.3);

    --chart-bg: #ffffff;
    --chart-grid: rgba(148, 163, 184, 0.08);
    --chart-border: rgba(148, 163, 184, 0.15);
    --chart-text: #94a3b8;
    --chart-crosshair: #64748b;
    --chart-label-bg: #f1f5f9;

    --scrollbar-thumb: rgba(148, 163, 184, 0.25);
    --scrollbar-hover: rgba(148, 163, 184, 0.4);
    --source-selector-bg: rgba(241, 245, 249, 0.8);
    --chat-msg-bg: rgba(148, 163, 184, 0.06);
}

[data-theme="light"] .logo-text {
    background: linear-gradient(135deg, #1e293b, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(ellipse 80% 50% at 50% -20%, var(--bg-body-gradient1), transparent),
        radial-gradient(ellipse 60% 40% at 80% 60%, var(--bg-body-gradient2), transparent);
    pointer-events: none;
    z-index: 0;
}

/* Dashboard shifts left when chat sidebar is open */
body.chat-sidebar-open #dashboard,
body.chat-sidebar-open #main-footer {
    margin-right: 340px;
    transition: margin-right var(--transition-slow);
}

/* ======================== HEADER ======================== */
#main-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 var(--content-padding);
    background: var(--bg-header);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    transition: background 0.3s ease;
}

.header-left {
    display: flex;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid rgba(99, 102, 241, 0.3);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.2);
}

.logo-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #e2e8f0, #a5b4fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-subtitle {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.06em;
    margin-left: 2px;
}


.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Header Toggle Buttons (shared style) */
.header-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    font-size: 1.1rem;
    color: var(--text-secondary);
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.header-toggle-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--text-primary);
}

/* Live Indicator */
.live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: rgba(0, 212, 170, 0.08);
    border: 1px solid rgba(0, 212, 170, 0.2);
    border-radius: 20px;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--candle-up);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(0, 212, 170, 0.4);
    }

    50% {
        opacity: 0.7;
        box-shadow: 0 0 0 6px rgba(0, 212, 170, 0);
    }
}

.live-text {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--candle-up);
    letter-spacing: 0.02em;
}

/* Currency Toggle Button */
.currency-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 20px;
    cursor: pointer;
    transition: all var(--transition-fast);
    letter-spacing: 0.04em;
}

.currency-toggle:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.35);
    color: var(--text-primary);
}

.currency-toggle.active-krw {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.3);
    color: #f59e0b;
}

.last-updated {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.visitor-stats {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}
.visitor-stats svg {
    opacity: 0.5;
    flex-shrink: 0;
}
.visitor-label {
    opacity: 0.7;
}
.visitor-num {
    font-weight: 600;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
}
.visitor-sep {
    opacity: 0.3;
    margin: 0 1px;
}

/* ======================== MAIN DASHBOARD ======================== */
#dashboard {
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 0 auto;
    padding: var(--content-padding);
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: margin-right var(--transition-slow);
}

/* ======================== BALANCE CARDS ======================== */
.balance-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    align-items: stretch;
}

.card-allocation .card-accent {
    background: linear-gradient(90deg, #f59e0b, #3b82f6, #10b981);
}
.alloc-bars {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}
.alloc-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.alloc-row .legend-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.alloc-name {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    width: 52px;
    flex-shrink: 0;
}
.alloc-bar-track {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}
.alloc-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
}
.bar-bybit { background: #f59e0b; }
.bar-mt5 { background: #3b82f6; }
.alloc-pct {
    font-size: 0.72rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-primary);
    width: 36px;
    text-align: right;
    flex-shrink: 0;
}

.balance-card {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--card-radius);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-normal);
    animation: cardFadeIn 0.6s ease forwards;
    opacity: 0;
    transform: translateY(16px);
}

.balance-card:nth-child(1) {
    animation-delay: 0.05s;
}

.balance-card:nth-child(2) {
    animation-delay: 0.12s;
}

.balance-card:nth-child(3) {
    animation-delay: 0.19s;
}

.balance-card:nth-child(4) {
    animation-delay: 0.26s;
}

@keyframes cardFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.balance-card:hover {
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    border-color: rgba(148, 163, 184, 0.18);
}

.balance-card.active {
    border-color: var(--accent-primary);
    box-shadow: 0 0 20px var(--accent-primary-glow);
}

.card-accent {
    height: 3px;
    width: 100%;
    border-radius: 3px 3px 0 0;
}

.card-total .card-accent {
    background: linear-gradient(90deg, #8b5cf6, #a78bfa, #c4b5fd);
}

.card-bybit .card-accent {
    background: linear-gradient(90deg, #d97706, #f59e0b, #fbbf24);
}

.card-mt5 .card-accent {
    background: linear-gradient(90deg, #2563eb, #3b82f6, #60a5fa);
}

.card-total:hover {
    box-shadow: 0 4px 24px var(--color-total-glow);
}

.card-bybit:hover {
    box-shadow: 0 4px 24px var(--color-bybit-glow);
}

.card-mt5:hover {
    box-shadow: 0 4px 24px var(--color-mt5-glow);
}

.card-content {
    padding: 16px 18px 14px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.card-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6b7280;
    flex-shrink: 0;
    transition: background 0.3s;
}
.status-dot.online {
    background: #10b981;
    box-shadow: 0 0 6px rgba(16,185,129,0.5);
}
.status-dot.offline {
    background: #ef4444;
    box-shadow: 0 0 6px rgba(239,68,68,0.5);
}
.status-time {
    font-size: 0.55rem;
    color: #6b7280;
    font-family: 'JetBrains Mono', monospace;
    margin: -1px 0 0 0;
    letter-spacing: 0.02em;
    line-height: 1;
}

.card-badge {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 2px 7px;
    border-radius: 4px;
    background: rgba(148, 163, 184, 0.08);
    color: var(--text-muted);
    border: 1px solid rgba(148, 163, 184, 0.1);
}

.card-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--text-accent);
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

.card-change {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

.card-change.positive {
    color: var(--candle-up);
}

.card-change.negative {
    color: var(--candle-down);
}

.change-icon {
    font-size: 0.65rem;
}

.card-sparkline {
    margin-top: 10px;
    height: 32px;
    opacity: 0.6;
}

/* ======================== CHART SECTION ======================== */
.chart-section {
    background: var(--bg-card);
    border-radius: var(--card-radius);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
    animation: cardFadeIn 0.7s ease 0.3s forwards;
    opacity: 0;
    transform: translateY(16px);
}

.chart-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-toolbar);
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.source-selector {
    display: flex;
    gap: 4px;
    padding: 3px;
    background: var(--source-selector-bg);
    border-radius: var(--btn-radius);
    border: 1px solid var(--border-color);
}

.source-btn {
    padding: 6px 14px;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
    letter-spacing: 0.01em;
}

.source-btn:hover {
    color: var(--text-secondary);
    background: rgba(99, 102, 241, 0.08);
}

.source-btn.active {
    color: #fff;
    background: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.timeframe-selector {
    display: flex;
    gap: 2px;
}

.ct-btn {
    padding: 6px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
    letter-spacing: 0.02em;
}

.ct-btn:hover {
    color: var(--text-secondary);
    background: rgba(0, 212, 170, 0.06);
}

.ct-btn.active {
    color: #00d4aa;
    background: rgba(0, 212, 170, 0.1);
    border-color: rgba(0, 212, 170, 0.3);
}

.chart-type-selector {
    display: flex;
    gap: 2px;
}

.tf-btn {
    padding: 6px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
    letter-spacing: 0.02em;
}

.tf-btn:hover {
    color: var(--text-secondary);
    background: rgba(99, 102, 241, 0.06);
}

.tf-btn.active {
    color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
    border-color: rgba(99, 102, 241, 0.3);
}

.chart-container {
    position: relative;
    width: 100%;
    height: 480px;
}

.chart-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
    z-index: 10;
}

.chart-loading.hidden {
    display: none;
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(99, 102, 241, 0.15);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ======================== BOTTOM SECTION ======================== */
.bottom-section {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 16px;
    animation: cardFadeIn 0.7s ease 0.45s forwards;
    opacity: 0;
    transform: translateY(16px);
}

.mini-charts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.mini-chart-card {
    background: var(--bg-card);
    border-radius: var(--card-radius);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 14px 16px 10px;
    transition: all var(--transition-normal);
}

.mini-chart-card:hover {
    background: var(--bg-card-hover);
    border-color: rgba(148, 163, 184, 0.18);
}

.mini-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.mini-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot-bybit {
    background: var(--color-bybit);
}

.dot-mt5 {
    background: var(--color-mt5);
}

.mini-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex: 1;
}

.mini-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.mini-chart-area {
    height: 90px;
}

/* ======================== ALLOCATION CARD ======================== */
.allocation-card {
    background: var(--bg-card);
    border-radius: var(--card-radius);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all var(--transition-normal);
}

.allocation-card:hover {
    background: var(--bg-card-hover);
}

.allocation-header {
    width: 100%;
    margin-bottom: 14px;
}

.allocation-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.03em;
}

.donut-container {
    position: relative;
    width: 160px;
    height: 160px;
    margin-bottom: 16px;
}

#donut-canvas {
    width: 160px;
    height: 160px;
}

.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.donut-total-label {
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.donut-total-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-accent);
}

.allocation-legend {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.legend-label {
    flex: 1;
    color: var(--text-secondary);
    font-weight: 500;
}

.legend-pct {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--text-primary);
}

/* ======================== FOOTER ======================== */
#main-footer {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 20px var(--content-padding);
    font-size: 0.72rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    margin-top: 8px;
    transition: margin-right var(--transition-slow);
}

.footer-divider {
    opacity: 0.4;
}

/* ======================== SCROLLBAR ======================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}

/* ======================== RESPONSIVE ======================== */

@media (max-width: 1024px) {
    .balance-cards {
        grid-template-columns: repeat(3, 1fr);
    }

    .bottom-section {
        grid-template-columns: 1fr;
    }

    .mini-charts {
        grid-template-columns: repeat(3, 1fr);
    }

    .chart-container {
        height: 400px;
    }

    body.chat-sidebar-open #dashboard,
    body.chat-sidebar-open #main-footer {
        margin-right: 0;
    }
}

@media (max-width: 640px) {
    :root {
        --content-padding: 12px;
        --header-height: 52px;
    }

    .balance-cards {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .card-value {
        font-size: 1.2rem;
    }

    .chart-toolbar {
        flex-direction: column;
        gap: 10px;
        padding: 10px 12px;
    }

    .chart-container {
        height: 320px;
    }

    .mini-charts {
        grid-template-columns: 1fr;
    }

    .bottom-section {
        grid-template-columns: 1fr;
    }

    .logo-text {
        font-size: 1rem;
    }

    .last-updated {
        display: none;
    }

    .logo-subtitle {
        display: none;
    }

    .share-wrapper {
        display: none;
    }

    .visitor-stats {
        display: none;
    }

    .header-right {
        gap: 6px;
    }

    .lang-toggle, .currency-toggle {
        font-size: 0.65rem;
        padding: 4px 6px;
    }

    .header-toggle-btn {
        width: 28px;
        height: 28px;
    }

    .live-indicator .live-text {
        display: none;
    }

    .source-selector {
        flex-wrap: wrap;
    }
}

@media (max-width: 400px) {
    .balance-cards {
        grid-template-columns: 1fr;
    }
}

/* ======================== CHAT PANEL ======================== */

/* Toggle Button (fixed bottom-right) — only visible when chat is closed */
.chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 200;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(99, 102, 241, 0.3);
    background: var(--bg-secondary);
    color: var(--accent-primary);
    cursor: pointer;
    display: none;
    /* hidden by default (chat opens by default) */
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4), 0 0 15px var(--accent-primary-glow);
    transition: all var(--transition-normal);
}

.chat-toggle-btn.visible {
    display: flex;
}

.chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 20px var(--accent-primary-glow);
    border-color: var(--accent-primary);
}

.chat-badge {
    display: none;
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--candle-down);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    padding: 0 4px;
}

.chat-badge.visible {
    display: block;
}

/* Chat Panel — Sidebar mode (default) */
.chat-panel {
    position: fixed;
    top: var(--header-height);
    right: -360px;
    width: 340px;
    height: calc(100vh - var(--header-height));
    z-index: 150;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: right var(--transition-slow);
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.15);
}

.chat-panel.open {
    right: 0;
}

/* Chat Panel — Popup mode */
.chat-panel.popup-mode {
    top: auto;
    bottom: 80px;
    right: -400px;
    width: 360px;
    height: 500px;
    border-radius: var(--card-radius);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

.chat-panel.popup-mode.open {
    right: 24px;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-toolbar);
    flex-shrink: 0;
}

.chat-panel.popup-mode .chat-header {
    border-radius: var(--card-radius) var(--card-radius) 0 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chat-online {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--candle-up);
    padding: 2px 8px;
    background: rgba(0, 212, 170, 0.08);
    border-radius: 10px;
    border: 1px solid rgba(0, 212, 170, 0.15);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-mode-btn,
.chat-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-mode-btn:hover,
.chat-close-btn:hover {
    color: var(--text-primary);
    background: rgba(148, 163, 184, 0.1);
}

/* Nickname Form */
.chat-nickname-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    gap: 16px;
}

.chat-nickname-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.chat-nickname-input-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--btn-radius);
    outline: none;
    transition: border-color var(--transition-fast);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-primary-glow);
}

.chat-join-btn {
    padding: 10px 20px;
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent-primary);
    border: none;
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.chat-join-btn:hover {
    background: var(--accent-purple);
}

/* Chat Body */
.chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-body.hidden {
    display: none;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-msg {
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--chat-msg-bg);
    animation: msgFadeIn 0.2s ease;
}

@keyframes msgFadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}

.chat-msg-nick {
    font-size: 0.75rem;
    font-weight: 600;
}

.chat-msg-time {
    font-size: 0.62rem;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.chat-msg-text {
    font-size: 0.82rem;
    color: var(--text-primary);
    line-height: 1.4;
    word-break: break-word;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-toolbar);
    flex-shrink: 0;
}

.chat-panel.popup-mode .chat-input-area {
    border-radius: 0 0 var(--card-radius) var(--card-radius);
}

.chat-send-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: var(--btn-radius);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: var(--accent-purple);
}

/* ======================== LANGUAGE TOGGLE ======================== */
.lang-toggle {
    display: flex; align-items: center; gap: 4px;
    padding: 5px 14px; font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem; font-weight: 600; color: var(--text-secondary);
    background: rgba(99, 102, 241, 0.08); border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 20px; cursor: pointer; transition: all var(--transition-fast);
    letter-spacing: 0.04em;
}
.lang-toggle:hover { background: rgba(99, 102, 241, 0.15); border-color: rgba(99, 102, 241, 0.35); color: var(--text-primary); }

/* ======================== SHARE WRAPPER ======================== */
.share-wrapper { position: relative; }
.share-dropdown {
    position: absolute; top: 100%; right: 0; margin-top: 8px;
    background: var(--bg-secondary); border: 1px solid var(--border-color);
    border-radius: var(--btn-radius); padding: 6px; min-width: 140px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3); z-index: 200;
}
.share-dropdown.hidden { display: none; }
.share-item {
    display: flex; align-items: center; gap: 8px; width: 100%;
    padding: 8px 10px; font-family: 'Inter', sans-serif; font-size: 0.8rem;
    color: var(--text-secondary); background: none; border: none;
    border-radius: 6px; cursor: pointer; transition: all var(--transition-fast);
}
.share-item:hover { background: rgba(99,102,241,0.08); color: var(--text-primary); }
.share-icon { font-size: 1rem; width: 20px; text-align: center; }

/* ======================== OHLC OVERLAY ======================== */
.chart-ohlc-overlay {
    position: absolute; top: 8px; left: 12px; z-index: 5;
    display: flex; align-items: center; gap: 6px;
    font-family: 'JetBrains Mono', monospace; font-size: 0.72rem;
    pointer-events: none;
}
.ohlc-label { color: var(--text-muted); font-weight: 500; }
.ohlc-val { color: var(--text-secondary); font-weight: 600; margin-right: 4px; }
.ohlc-change { font-weight: 600; margin-left: 4px; }
.ohlc-change.positive { color: var(--candle-up); }
.ohlc-change.negative { color: var(--candle-down); }

/* ======================== STATS SECTION ======================== */
.stats-section {
    animation: cardFadeIn 0.7s ease 0.5s forwards;
    opacity: 0; transform: translateY(16px);
}
.stats-card {
    background: var(--bg-card); border-radius: var(--card-radius);
    border: 1px solid var(--border-color); backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px); padding: 20px;
    transition: all var(--transition-normal);
}
.stats-card:hover { background: var(--bg-card-hover); }
.stats-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.stats-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.stats-source-selector { display: flex; gap: 4px; }
.stats-src-btn {
    padding: 5px 12px; font-family: 'Inter', sans-serif; font-size: 0.72rem;
    font-weight: 500; color: var(--text-muted); background: transparent;
    border: 1px solid transparent; border-radius: 6px; cursor: pointer;
    transition: all var(--transition-fast);
}
.stats-src-btn:hover { color: var(--text-secondary); background: rgba(99,102,241,0.06); }
.stats-src-btn.active { color: var(--accent-primary); background: rgba(99,102,241,0.1); border-color: rgba(99,102,241,0.3); }
.stats-grid {
    display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
}
.stat-item {
    display: flex; flex-direction: column; gap: 4px;
    padding: 12px; background: var(--bg-surface); border-radius: 10px;
    border: 1px solid var(--border-color);
}
.stat-label { font-size: 0.7rem; font-weight: 500; color: var(--text-muted); letter-spacing: 0.02em; }
.stat-value { font-family: 'JetBrains Mono', monospace; font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.stat-value.positive { color: var(--candle-up); }
.stat-value.negative { color: var(--candle-down); }
.stat-item.stat-danger .stat-value { color: var(--candle-down); }

/* ======================== COMPARE SECTION ======================== */
.compare-section {
    animation: cardFadeIn 0.7s ease 0.55s forwards;
    opacity: 0; transform: translateY(16px);
}
.compare-card {
    background: var(--bg-card); border-radius: var(--card-radius);
    border: 1px solid var(--border-color); backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px); padding: 20px;
    transition: all var(--transition-normal);
}
.compare-card:hover { background: var(--bg-card-hover); }
.compare-header { margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.compare-header .compare-tabs { flex-shrink: 0; }
.compare-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.compare-tabs { display: flex; gap: 4px; background: var(--border-color); border-radius: 6px; padding: 2px; }
.compare-tab { padding: 4px 14px; border: none; border-radius: 4px; background: transparent; color: var(--text-secondary); font-size: 0.78rem; font-weight: 600; font-family: 'JetBrains Mono', monospace; cursor: pointer; transition: all 0.2s; }
.compare-tab.active { background: var(--accent-primary); color: #fff; }
.compare-tab:hover:not(.active) { color: var(--text-primary); }
.compare-sub-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.compare-legend { display: flex; gap: 16px; }
.pnl-period-tabs { margin-left: auto; }
.compare-legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--text-secondary); font-weight: 500; }
.compare-legend-item .legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.compare-chart-area { height: 300px; position: relative; }
.compare-tooltip { display: none; gap: 14px; padding: 6px 10px; font-size: 0.78rem; font-family: 'JetBrains Mono', monospace; background: transparent; position: absolute; top: 6px; left: 6px; z-index: 10; pointer-events: none; }
.compare-tooltip .ct-item { white-space: nowrap; }
.compare-tooltip .positive { color: var(--candle-up); }
.compare-tooltip .negative { color: var(--candle-down); }

/* ======================== POSITIONS ======================== */
.positions-section { animation: cardFadeIn 0.7s ease 0.4s forwards; opacity: 0; transform: translateY(16px); }
.positions-card { background: var(--bg-card); border-radius: var(--card-radius); border: 1px solid var(--border-color); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 20px; }
.positions-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.positions-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.positions-total-holding { font-size: 0.78rem; font-weight: 700; color: var(--text-primary); background: rgba(255,255,255,0.06); padding: 2px 10px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; margin-left: auto; margin-right: 12px; }
.positions-total-pnl { font-size: 0.78rem; font-weight: 700; padding: 2px 10px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; margin-right: 12px; }
.positions-total-pnl.positive { color: var(--candle-up); background: rgba(0,212,170,0.1); }
.positions-total-pnl.negative { color: var(--candle-down); background: rgba(255,71,87,0.1); }
.positions-leverage { font-size: 0.75rem; font-weight: 700; color: #f5a623; background: rgba(245,166,35,0.12); padding: 2px 8px; border-radius: 4px; font-family: 'JetBrains Mono', monospace; margin-right: 12px; }
.positions-count { font-size: 0.78rem; font-weight: 600; color: var(--text-secondary); font-family: 'JetBrains Mono', monospace; }
.positions-table-wrap { overflow-x: auto; }
.positions-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.positions-table th { padding: 8px 12px; text-align: right; font-weight: 600; color: var(--text-secondary); border-bottom: 2px solid var(--border-color); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; }
.positions-table th:first-child, .positions-table th:nth-child(3), .positions-table th:nth-child(4) { text-align: left; }
.positions-table th:nth-child(2) { text-align: left; }
.positions-table td { padding: 7px 12px; text-align: right; border-bottom: 1px solid var(--border-color); font-family: 'JetBrains Mono', monospace; color: var(--text-primary); }
.positions-table td:first-child, .positions-table td:nth-child(3), .positions-table td:nth-child(4) { text-align: left; }
.positions-table td:nth-child(2) { text-align: left; white-space: nowrap; letter-spacing: -0.5px; padding-left: 0; }
.positions-table tr:hover { background: var(--bg-card-hover); }
.positions-table .positive { color: var(--candle-up); }
.positions-table .negative { color: var(--candle-down); }
.positions-table .side-long { color: var(--candle-up); font-weight: 600; }
.positions-table .side-short { color: var(--candle-down); font-weight: 600; }
.positions-empty { text-align: center !important; color: var(--text-secondary); padding: 20px !important; }
.positions-source { font-size: 0.68rem; padding: 2px 6px; border-radius: 4px; font-weight: 600; }
.positions-source.src-bybit { background: rgba(245,158,11,0.15); color: #f59e0b; }
.positions-source.src-mt5 { background: rgba(59,130,246,0.15); color: #3b82f6; }

/* ======================== REBALANCE ======================== */
.rebalance-section { animation: cardFadeIn 0.7s ease 0.55s forwards; opacity: 0; transform: translateY(16px); }
.rebalance-card { background: var(--bg-card); border-radius: var(--card-radius); border: 1px solid var(--border-color); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 20px; }
.rebalance-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.rebalance-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.rebalance-header-right { display: flex; align-items: center; gap: 12px; }
.rebalance-action { font-size: 0.75rem; font-weight: 700; padding: 4px 12px; border-radius: 6px; font-family: 'JetBrains Mono', monospace; letter-spacing: 0.5px; }
.rebalance-action.hold { background: rgba(16,185,129,0.15); color: #10b981; }
.rebalance-action.rebalance { background: rgba(255,71,87,0.15); color: #ff4757; animation: rebalancePulse 2s ease-in-out infinite; }
@keyframes rebalancePulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
.rebalance-countdown { font-size: 0.75rem; color: var(--text-secondary); font-family: 'JetBrains Mono', monospace; }
.rebalance-body { display: flex; gap: 24px; align-items: flex-start; }
.rebalance-donut-area { display: flex; flex-direction: column; align-items: center; gap: 12px; flex-shrink: 0; }
.rebalance-donut-legend { display: flex; flex-direction: column; gap: 6px; font-size: 0.72rem; color: var(--text-secondary); }
.rebalance-legend-item { display: flex; align-items: center; gap: 6px; }
.rebalance-legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.rebalance-legend-pct { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--text-primary); min-width: 42px; text-align: right; }
.rebalance-bands { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.band-row { background: var(--bg-surface); border-radius: 8px; padding: 12px 14px; border: 1px solid var(--border-color); }
.band-row.out-of-band { background: rgba(255,71,87,0.06); border-color: rgba(255,71,87,0.3); }
.band-row-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.band-source-name { font-size: 0.78rem; font-weight: 600; color: var(--text-primary); }
.band-weight-label { font-size: 0.75rem; font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.band-weight-label.in-band { color: var(--candle-up); }
.band-weight-label.out-of-band { color: #ff4757; }
.band-track { position: relative; height: 10px; background: var(--border-color); border-radius: 5px; }
.band-allowed { position: absolute; top: 0; height: 100%; border-radius: 5px; opacity: 0.2; }
.band-target-line { position: absolute; top: -3px; width: 2px; height: 16px; border-radius: 1px; opacity: 0.5; transform: translateX(-1px); }
.band-current-dot { position: absolute; top: -3px; width: 16px; height: 16px; border-radius: 50%; transform: translateX(-8px); box-shadow: 0 0 6px rgba(0,0,0,0.3); }
.band-labels { position: relative; height: 16px; margin-top: 4px; font-size: 0.65rem; color: var(--text-secondary); font-family: 'JetBrains Mono', monospace; }
.rebalance-transfers { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border-color); }
.rebalance-transfers-title { font-size: 0.78rem; font-weight: 600; color: var(--text-primary); margin-bottom: 12px; }
.rebalance-transfers-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.transfer-card { background: var(--bg-surface); border-radius: 8px; padding: 10px 14px; border: 1px solid var(--border-color); text-align: center; }
.transfer-card-name { font-size: 0.72rem; color: var(--text-secondary); margin-bottom: 4px; font-weight: 600; }
.transfer-card-amount { font-size: 0.88rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.transfer-card-amount.add { color: var(--candle-up); }
.transfer-card-amount.reduce { color: var(--candle-down); }
@media (max-width: 768px) {
    .rebalance-body { flex-direction: column; align-items: center; }
    .rebalance-bands { width: 100%; }
    .rebalance-transfers-grid { grid-template-columns: 1fr; }
}

/* ======================== PNL TABLE ======================== */
.pnl-section { animation: cardFadeIn 0.7s ease 0.7s forwards; opacity: 0; transform: translateY(16px); }
.pnl-card { background: var(--bg-card); border-radius: var(--card-radius); border: 1px solid var(--border-color); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); padding: 20px; }
.pnl-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.pnl-header-tabs { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pnl-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.pnl-tabs { display: flex; gap: 4px; background: var(--border-color); border-radius: 6px; padding: 2px; }
.pnl-tab { padding: 4px 14px; border: none; border-radius: 4px; background: transparent; color: var(--text-secondary); font-size: 0.78rem; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.pnl-tab.active { background: var(--accent-primary); color: #fff; }
.pnl-tab:hover:not(.active) { color: var(--text-primary); }

.pnl-summary { display: flex; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.pnl-stat { flex: 1; min-width: 120px; background: var(--bg-surface); border-radius: 8px; padding: 10px 14px; border: 1px solid var(--border-color); }
.pnl-stat-label { display: block; font-size: 0.7rem; color: var(--text-secondary); margin-bottom: 4px; }
.pnl-stat-value { font-size: 0.9rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--text-primary); }

.pnl-table-wrap { overflow-x: auto; max-height: 400px; overflow-y: auto; }
.pnl-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.pnl-table thead { position: sticky; top: 0; z-index: 1; }
.pnl-table th { padding: 8px 12px; text-align: right; font-weight: 600; color: var(--text-secondary); background: var(--bg-card); border-bottom: 2px solid var(--border-color); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.5px; }
.pnl-table th:first-child { text-align: left; }
.pnl-table td { padding: 7px 12px; text-align: right; border-bottom: 1px solid var(--border-color); font-family: 'JetBrains Mono', monospace; color: var(--text-primary); }
.pnl-table td:first-child { text-align: left; color: var(--text-secondary); }
.pnl-table tr:hover { background: var(--bg-card-hover); }
.pnl-table .positive { color: var(--candle-up); }
.pnl-table .negative { color: var(--candle-down); }

/* ======================== HEATMAP SECTION ======================== */
.heatmap-section {
    animation: cardFadeIn 0.7s ease 0.6s forwards;
    opacity: 0; transform: translateY(16px);
}
.heatmap-card {
    background: var(--bg-card); border-radius: var(--card-radius);
    border: 1px solid var(--border-color); backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px); padding: 20px;
    transition: all var(--transition-normal);
}
.heatmap-card:hover { background: var(--bg-card-hover); }
.heatmap-header { margin-bottom: 12px; }
.heatmap-title { font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.heatmap-container { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.heatmap-cell {
    width: 28px; height: 28px; border-radius: 4px;
    cursor: pointer; transition: all var(--transition-fast);
    position: relative;
}
.heatmap-cell:hover { transform: scale(1.2); z-index: 1; }
.heatmap-legend { display: flex; align-items: center; justify-content: center; gap: 8px; }
.heatmap-legend-label { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; }
.heatmap-scale { display: flex; gap: 3px; }
.heatmap-scale .heatmap-cell { width: 16px; height: 16px; cursor: default; }
.heatmap-scale .heatmap-cell:hover { transform: none; }

/* ======================== VOTE SECTION ======================== */
.vote-section { padding: 0 12px; flex-shrink: 0; }
.vote-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.vote-tab {
    flex: 1; padding: 6px; font-family: 'Inter', sans-serif; font-size: 0.75rem;
    font-weight: 500; color: var(--text-muted); background: transparent;
    border: 1px solid var(--border-color); border-radius: 6px; cursor: pointer;
    transition: all var(--transition-fast); text-align: center;
}
.vote-tab.active { color: var(--accent-primary); background: rgba(99,102,241,0.1); border-color: rgba(99,102,241,0.3); }
.vote-panel { margin-bottom: 8px; }
.vote-question { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px; text-align: center; }
.vote-buttons { display: flex; gap: 8px; margin-bottom: 8px; }
.vote-btn {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 8px; border-radius: 8px; border: 1px solid var(--border-color);
    background: transparent; cursor: pointer; transition: all var(--transition-fast);
}
.vote-btn:hover { border-color: rgba(99,102,241,0.3); }
.vote-btn.voted { opacity: 0.5; cursor: default; }
.vote-up:hover, .vote-up.selected { border-color: var(--candle-up); background: rgba(0,212,170,0.08); }
.vote-down:hover, .vote-down.selected { border-color: var(--candle-down); background: rgba(255,71,87,0.08); }
.vote-emoji { font-size: 1.2rem; }
.vote-label { font-size: 0.7rem; color: var(--text-muted); }
.vote-count { font-family: 'JetBrains Mono', monospace; font-size: 0.75rem; font-weight: 600; color: var(--text-primary); }
.vote-bar-container { height: 6px; background: var(--bg-surface); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.vote-bar-fill { height: 100%; background: linear-gradient(90deg, var(--candle-up), var(--accent-primary)); border-radius: 3px; transition: width 0.5s ease; width: 50%; }
.vote-info { font-size: 0.68rem; color: var(--text-muted); text-align: center; }
.my-prediction-stats { font-size: 0.7rem; color: var(--text-secondary); text-align: center; margin-top: 4px; }
.ranking-panel { max-height: 200px; overflow-y: auto; }
.ranking-panel.hidden { display: none; }
.ranking-list { display: flex; flex-direction: column; gap: 4px; }

/* ======================== EMOJI REACTION ======================== */
.emoji-reaction-bar {
    display: flex; gap: 4px; padding: 6px 12px;
    border-top: 1px solid var(--border-color); flex-shrink: 0;
    overflow-x: auto;
}
.emoji-btn {
    padding: 4px 6px; font-size: 1rem; background: none; border: 1px solid transparent;
    border-radius: 6px; cursor: pointer; transition: all var(--transition-fast);
}
.emoji-btn:hover { background: rgba(99,102,241,0.08); border-color: rgba(99,102,241,0.2); transform: scale(1.15); }
.floating-emoji-container { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 9999; }
.floating-emoji {
    position: absolute; font-size: 1.5rem; animation: floatUp 2s ease forwards; pointer-events: none;
}
@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-200px) scale(1.5); }
}

/* ======================== CHAT USER BAR / LOGOUT ======================== */
.chat-user-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 12px; border-bottom: 1px solid var(--border-color);
    background: var(--bg-toolbar); flex-shrink: 0;
}
.chat-user-nick { font-size: 0.78rem; font-weight: 600; color: var(--text-primary); }
.chat-logout-btn {
    padding: 3px 10px; font-family: 'Inter', sans-serif; font-size: 0.68rem;
    color: var(--text-muted); background: none; border: 1px solid var(--border-color);
    border-radius: 4px; cursor: pointer; transition: all var(--transition-fast);
}
.chat-logout-btn:hover { color: var(--candle-down); border-color: var(--candle-down); }
.chat-register-hint { font-size: 0.72rem; color: var(--text-muted); text-align: center; min-height: 1em; }

/* ======================== STATS/COMPARE/HEATMAP RESPONSIVE ======================== */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(3, 1fr); }
    .compare-chart-area { height: 250px; }
}
@media (max-width: 640px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .compare-chart-area { height: 200px; }
    .heatmap-cell { width: 22px; height: 22px; }
    .compare-tab { padding: 4px 8px; font-size: 0.7rem; }
    .compare-title { font-size: 0.8rem; }
    .compare-legend { gap: 8px; }
    .compare-legend-item { font-size: 0.7rem; }
}

/* Mobile chat */
@media (max-width: 640px) {
    .chat-panel {
        width: 100%;
        right: -100%;
    }

    .chat-panel.popup-mode {
        width: 100%;
        right: -100%;
        bottom: 0;
        height: 60vh;
        border-radius: var(--card-radius) var(--card-radius) 0 0;
    }

    .chat-panel.popup-mode.open {
        right: 0;
    }

    .chat-toggle-btn {
        bottom: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
    }
}

/* ======================== ANONYMOUS CHAT ======================== */
.chat-toggle-btn {
    position: fixed; bottom: 24px; right: 24px; z-index: 1000;
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--accent-primary); color: #fff; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 16px rgba(99,102,241,0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}
.chat-toggle-btn:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(99,102,241,0.5); }
.chat-badge {
    position: absolute; top: -4px; right: -4px;
    background: #ef4444; color: #fff; font-size: 0.65rem; font-weight: 700;
    min-width: 18px; height: 18px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 4px;
}
.chat-panel {
    position: fixed; bottom: 88px; right: 24px; z-index: 1001;
    width: 360px; max-height: 500px;
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: 16px; backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
    display: flex; flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: cardFadeIn 0.3s ease forwards;
}
.chat-header {
    display: flex; align-items: center; padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}
.chat-title { font-size: 0.9rem; font-weight: 700; color: var(--text-primary); flex: 1; }
.chat-online {
    font-size: 0.72rem; font-weight: 600; color: var(--candle-up);
    margin-right: 12px; font-family: 'JetBrains Mono', monospace;
}
.chat-online::before { content: '● '; font-size: 0.6rem; }
.chat-close-btn {
    background: none; border: none; color: var(--text-secondary);
    font-size: 1.3rem; cursor: pointer; padding: 0 4px; line-height: 1;
}
.chat-close-btn:hover { color: var(--text-primary); }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 12px 16px;
    min-height: 280px; max-height: 360px;
    display: flex; flex-direction: column; gap: 6px;
}
.chat-msg {
    font-size: 0.78rem; line-height: 1.5; color: var(--text-primary);
    word-break: break-word;
}
.chat-msg-nick {
    font-weight: 700; margin-right: 6px; font-size: 0.75rem;
}
.chat-msg-time {
    font-size: 0.65rem; color: var(--text-secondary);
    margin-left: 4px; font-family: 'JetBrains Mono', monospace;
}
.chat-msg-text { color: var(--text-primary); }
.chat-input-area {
    display: flex; align-items: center; padding: 10px 12px;
    border-top: 1px solid var(--border-color); gap: 8px;
}
.chat-input {
    flex: 1; background: var(--bg-main); border: 1px solid var(--border-color);
    border-radius: 8px; padding: 8px 12px; color: var(--text-primary);
    font-size: 0.8rem; outline: none; font-family: inherit;
}
.chat-input:focus { border-color: var(--accent-primary); }
.chat-input::placeholder { color: var(--text-secondary); }
.chat-send-btn {
    background: var(--accent-primary); border: none; border-radius: 8px;
    width: 36px; height: 36px; cursor: pointer; color: #fff;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.chat-send-btn:hover { background: var(--accent-secondary); }

@media (max-width: 640px) {
    .chat-panel { right: 8px; left: 8px; width: auto; bottom: 80px; }
    .chat-toggle-btn { bottom: 16px; right: 16px; width: 46px; height: 46px; }
}