:root {
    --bg-color: #000000;
    --sidebar-width: 260px; /* Adjusted width */
    --card-bg: #16181c; /* X dark mode card */
    --text-primary: #e7e9ea;
    --text-secondary: #71767b;
    --accent-blue: #1d9bf0; /* X blue */
    --border-color: #2f3336;
    
    --dex-color: #f91880;   /* X pink */
    --news-color: #00ba7c;  /* X green */
    --pred-color: #1d9bf0;  /* X blue */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Ubuntu, sans-serif;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    height: 100vh;
    display: flex;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100%;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    transition: width 0.3s ease;
    overflow: hidden; /* Hide overflow content when collapsed */
}

.sidebar.collapsed {
    width: 80px;
    padding: 12px 8px;
}

.logo {
    font-size: 20px;
    font-weight: 800;
    padding: 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    white-space: nowrap;
}

.sidebar.collapsed .logo {
    flex-direction: column;
    gap: 16px;
    padding-bottom: 0;
}

.sidebar.collapsed .logo-text {
    display: none;
}

.toggle-btn {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    border-radius: 50%;
}

.toggle-btn:hover {
    background: rgba(239, 243, 244, 0.1);
    color: var(--text-primary);
}

.sidebar.collapsed .toggle-btn {
    margin-left: 0;
    position: static; /* Changed from absolute to static */
    transform: none;
    /* top: 60px; Removed */
}

/* Fix toggle button in collapsed mode */
.sidebar.collapsed .toggle-btn svg {
    transform: rotate(180deg);
}

.logo-box {
    width: 28px;
    height: 28px;
    background: var(--text-primary);
    color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 16px;
    border-radius: 4px;
    flex-shrink: 0;
}

.nav-item {
    padding: 12px 24px 12px 16px; /* Increased right padding for balance */
    font-size: 18px; /* Increased font size */
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 30px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 16px; /* Increased gap */
    margin-bottom: 16px; /* Increased margin-bottom */
    white-space: nowrap;
    overflow: hidden;
    margin-right: 20px; /* Make background narrower */
    width: fit-content; /* Only wrap content */
}

.mobile-nav-item {
    display: none !important;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px; /* Uniform padding for icon */
    margin-right: 0;
    width: auto; /* Let it flow */
    aspect-ratio: 1; /* Make it square/circle */
    border-radius: 50%; /* Fully round */
    margin-left: auto;
    margin-right: auto;
}

.sidebar.collapsed .nav-text {
    display: none;
}

.nav-item:hover {
    background: rgba(231, 233, 234, 0.1);
}

.nav-item.active {
    font-weight: 700;
    background-color: rgb(24, 24, 24);
}

.nav-icon {
    width: 26px; /* Slightly larger */
    height: 26px;
    flex-shrink: 0;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* User Profile */
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 30px;
    cursor: pointer;
    margin-top: auto;
    transition: background 0.2s;
}

.user-profile:hover {
    background: rgba(231, 233, 234, 0.1);
}

.profile-avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #333;
}

.profile-info {
    flex: 1;
    overflow: hidden;
}

.profile-name {
    font-weight: 700;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-handle {
    color: var(--text-secondary);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-more {
    color: var(--text-primary);
    width: 20px;
    height: 20px;
}

.sidebar.collapsed .profile-info,
.sidebar.collapsed .profile-more {
    display: none;
}

.sidebar.collapsed .user-profile {
    justify-content: center;
    padding: 12px 0;
}

/* Main Content */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    /* max-width: 900px; Remove max-width to use full screen space */
    border-right: 1px solid var(--border-color);
}

.header {
    height: 48px; /* Reduced */
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    background: rgba(0, 0, 0, 0.65);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-title {
    font-size: 18px; /* Reduced */
    font-weight: 700;
}

/* Scrollable Feed */
.feed {
    flex: 1;
    overflow-y: auto;
    padding: 24px; /* Increased padding */
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px; /* Increased gap */
    align-content: start;
}

/* Controls inside header */
.controls {
    display: flex;
    gap: 12px;
}

select {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

select:hover {
    background: rgba(239, 243, 244, 0.1);
}

.time-selector {
    display: flex;
    gap: 4px;
    background: transparent;
}

.time-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.time-btn:hover {
    background: rgba(29, 155, 240, 0.1);
    color: var(--accent-blue);
}

.time-btn.active {
    background: var(--accent-blue);
    color: #fff;
}

/* Cards */
.chart-card {
    background: transparent; /* Seamless timeline look */
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 12px; /* Reduced */
    position: relative;
    /* margin-bottom: 12px; Removed for grid gap */
    height: fit-content;
    min-width: 0; /* Fix for grid item overflow */
}

.chart-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px; /* Reduced */
    position: relative;
}

.fullscreen-btn {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s;
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center; /* Center icon horizontally */
    height: 32px; /* Match select height */
    width: 32px; /* Square button */
}

.fullscreen-btn:hover {
    color: var(--text-primary);
    background: transparent; /* Ensure no background on hover */
}

.user-icon {
    width: 32px; /* Reduced */
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-icon svg {
    width: 24px;
    height: 24px;
    stroke: #fff;
    fill: none;
    stroke-width: 2;
}

/* Fullscreen Mode */
.chart-card.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1000;
    background: var(--bg-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0;
}

.chart-card.fullscreen .chart-body {
    flex: 1;
    height: auto; /* Fill available space */
}

    display: flex;
    flex-direction: column;
}

.name {
    font-weight: 700;
    font-size: 14px; /* Reduced */
    display: flex;
    align-items: center;
}

.handle {
    color: var(--text-secondary);
    font-size: 13px; /* Reduced */
}

.chart-body {
    height: 390px; /* Increased height */
    width: 100%;
    margin-top: 8px;
    border: none; /* Removed border */
    border-radius: 12px;
    overflow: hidden;
    /* 
       touch-action: none is REQUIRED for ECharts to handle horizontal panning correctly on mobile.
       If set to pan-y, the browser often interprets diagonal swipes as vertical page scrolls and consumes the event.
       User must scroll the page by touching outside the chart (e.g. card header/padding).
    */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Dropdown Styles */
.custom-select-wrapper {
    position: relative;
    margin-left: auto;
    width: auto;
    min-width: 50px;
    user-select: none;
    height: 32px; /* Fixed height for alignment */
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 0 4px 0 6px;
    height: 100%;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 16px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
    transition: all 0.2s ease;
}

.custom-select-trigger:hover,
.custom-select-wrapper.open .custom-select-trigger {
    color: var(--text-primary);
    background: transparent;
}

/* Icon rotation */
.custom-select-icon {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.custom-select-wrapper.open .custom-select-icon {
    transform: rotate(180deg);
}

/* Dropdown Options */
.custom-select-options {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #000000; /* Pure black to match card bg or theme */
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 6px;
    list-style: none;
    width: max-content;
    min-width: 60px; /* Reduced from 90px */
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    z-index: 1000;
    
    /* Animation Variables */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px) scale(0.95);
    transform-origin: top right;
    transition: 
        opacity 0.2s ease,
        transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
        visibility 0.2s;
}

.custom-select-wrapper.open .custom-select-options {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.custom-option {
    padding: 8px 10px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    margin-bottom: 2px;
    outline: none; /* Focus handled by style below */
}

.custom-option:last-child {
    margin-bottom: 0;
}

.custom-option:hover,
.custom-option:focus,
.custom-option.highlight {
    background: rgba(239, 243, 244, 0.1);
}

.custom-option.selected {
    color: rgb(231, 233, 234);
    background: rgba(239, 243, 244, 0.1);
}

/* Checkmark logic removed */
.custom-option.selected::after {
    display: none;
}

/* Focus styles for accessibility */
.custom-select-trigger:focus-visible,
.custom-option:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: -2px;
}

/* Alignment with fullscreen button */
.custom-select-wrapper + .fullscreen-btn {
    margin-left: 2px;
}

.metric-value {
    font-size: 14px;
    font-weight: 600;
    margin-left: 12px;
}

/* Specific Chart Colors */
/* .dex-card .user-avatar { background: var(--dex-color); }
.news-card .user-avatar { background: var(--news-color); }
.pred-card .user-avatar { background: var(--pred-color); } */

.loader {
    text-align: center;
    padding: 20px;
    color: var(--accent-blue);
    font-weight: bold;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    /* Sidebar transforms into Bottom Navigation */
    .sidebar {
        width: 100% !important; /* Override collapsed width */
        height: 60px;
        position: fixed;
        bottom: 0;
        left: 0;
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        border-right: none;
        border-top: 1px solid var(--border-color);
        padding: 0;
        z-index: 1000;
        background-color: var(--bg-color);
    }

    /* Hide non-nav elements in mobile sidebar */
    .sidebar .logo,
    .sidebar .spacer,
    .sidebar .user-profile,
    .sidebar .toggle-btn {
        display: none !important;
    }

    .mobile-nav-item {
        display: flex !important;
    }

    /* Adjust nav items for bottom bar */
    .nav-item {
        padding: 6px 8px;
        margin-bottom: 0;
        flex-direction: column;
        gap: 2px;
        border-radius: 8px;
        font-size: 10px;
        height: auto;
        justify-content: center;
        flex: 1; /* Distribute space evenly */
    }

    /* Ensure text shows even if collapsed class is present */
    .sidebar.collapsed .nav-text {
        display: block !important;
    }

    .nav-icon {
        width: 20px;
        height: 20px;
    }

    /* Main Content adjustments */
    .main {
        width: 100%;
        height: 100%;
        border-right: none;
        padding-bottom: 60px; /* Space for bottom nav */
    }

    /* Header adjustments */
    .header {
        padding: 0 12px;
    }

    .header-title {
        font-size: 16px;
    }

    /* Feed Layout - Single Column */
    .feed {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }

    /* Chart Card adjustments */
    .chart-body {
        height: 280px; /* Smaller height for mobile */
    }

    /* Hide fullscreen button on mobile if needed, or adjust it */
    .fullscreen-btn {
        /* Optional: increase touch target */
        padding: 8px;
    }
    
    .module-section {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Mobile Tooltip Centering - Handled by JS for horizontal, CSS for width/z-index */
    .glass-tooltip {
        /* Reset positioning to be controlled by JS/default */
        position: absolute !important;
        left: 0; /* JS will override this if needed */
        top: 100% !important;
        width: 80vw;
        max-width: 320px;
        margin-top: 10px;
        z-index: 2000;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
        /* Ensure transform origin is suitable if we animate scale */
        transform-origin: top center;
    }
    
    .glass-tooltip.active {
        animation: fadeInMobileTooltip 0.2s ease-out !important;
    }

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


/* Coin Selector Dropdown */
.coin-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 20px;
    font-weight: bold;
    color: #e7e9ea;
    cursor: pointer;
    user-select: none;
    transition: opacity 0.2s;
}

.coin-selector:hover {
    opacity: 0.8;
}

.coin-dropdown-list {
    position: absolute;
    top: 100%;
    left: 40px; /* Align with text */
    margin-top: 8px;
    background: transparent; /* No background color */
    backdrop-filter: blur(20px); /* Stronger glass effect */
    -webkit-backdrop-filter: blur(20px);
    border: none;
    border-radius: 8px;
    padding: 8px 0;
    width: 140px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

/* Custom Scrollbar for Dropdown */
.coin-dropdown-list::-webkit-scrollbar {
    width: 4px; /* Thin scrollbar */
}

.coin-dropdown-list::-webkit-scrollbar-track {
    background: transparent; /* Transparent track */
}

.coin-dropdown-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2); /* Subtle thumb */
    border-radius: 4px;
}

.coin-dropdown-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.coin-dropdown-list.show {
    display: block;
}

.coin-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    cursor: pointer;
    color: #e7e9ea;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.coin-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.coin-option img {
    width: 20px;
    height: 20px;
}
.module-tabs {
    grid-column: 1 / -1;
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 4px 12px 4px;
    margin-bottom: 24px; /* Increased bottom margin */
    margin-top: 12px; /* Added top margin */
    scrollbar-width: none; /* Hide scrollbar for cleaner look */
    -ms-overflow-style: none; /* IE and Edge */
    align-items: center;
    min-height: 50px; /* Ensure enough height to prevent clipping */
}
.module-tabs::-webkit-scrollbar {
    display: none;
}

.module-tab {
    padding: 8px 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px; /* Match module title size */
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0; /* Prevent shrinking */
    height: auto;
    opacity: 0.6;
}

.module-tab:hover {
    background: transparent;
    color: var(--text-primary);
    opacity: 0.8;
}

.module-tab.active {
    background: transparent;
    color: var(--text-primary);
    border: none;
    opacity: 1;
}

.module-tab svg {
    width: 24px;
    height: 24px;
}

/* Module Section */
.module-section {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    width: 100%;
    animation: fadeIn 0.3s ease-in-out;
}

/* Market Section Titles */
.market-title {
    grid-column: 1 / -1;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 24px;
    margin-bottom: 0;
    padding-left: 0;
    border-left: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.market-title:first-child {
    margin-top: 0;
}

.market-title.global {
    margin-top: 32px; /* Extra spacing before Global section */
}

/* Info Tooltip Styles */
.info-tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    margin-left: 6px; /* Reduced from 8px for tighter grouping */
    z-index: 100;
}

.info-tooltip-container.z-active {
    z-index: 2001;
}

.info-icon {
    width: 14px; /* Reduced from 18px */
    height: 14px; /* Reduced from 18px */
    color: var(--text-secondary);
    transition: color 0.2s;
    vertical-align: middle; /* Ensure vertical alignment */
}

.info-icon:hover {
    color: var(--accent-blue);
}

.glass-tooltip {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 10px;
    width: 320px;
    padding: 16px;
    
    /* Glassmorphism - Transparent Frosted Glass */
    background: rgba(255, 255, 255, 0.01);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    
    color: var(--text-primary);
    font-size: 12px; /* Reduced from 14px */
    line-height: 1.6;
    z-index: 1000;
    text-align: left;
    font-weight: 400; /* Regular weight */
    font-family: -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Ubuntu, sans-serif; /* Inherit global font */
}

.glass-tooltip.active {
    display: block;
    animation: fadeInTooltip 0.2s ease-out;
}

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

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Drag and Drop Styles */
.sortable-ghost {
    opacity: 0.4;
    border: 2px dashed var(--accent-blue) !important;
    background: rgba(29, 155, 240, 0.1);
}

.sortable-drag {
    cursor: grabbing;
}

.chart-header {
    cursor: grab;
}

.chart-header:active {
    cursor: grabbing;
}

/* Tooltip Scrollbar Styles */
.tooltip-scroll-container::-webkit-scrollbar {
    width: 4px; /* Thin scrollbar */
}

.tooltip-scroll-container::-webkit-scrollbar-track {
    background: transparent; /* Transparent track */
}

.tooltip-scroll-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2); /* Subtle thumb */
    border-radius: 4px;
}

.tooltip-scroll-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}