/* ============================================
   PERSISTENT WATCHLIST SIDEBAR
   TradingView-inspired docked sidebar design
   ============================================ */

/* Body modifier when sidebar is active */
body.watchlist-sidebar-active {
    --sidebar-width: 280px;
}

body.watchlist-sidebar-active .dashboard,
body.watchlist-sidebar-active .details-page,
body.watchlist-sidebar-active .heatmap-page,
body.watchlist-sidebar-active .cpi-dashboard-page,
body.watchlist-sidebar-active .screener-page,
body.watchlist-sidebar-active .news-page,
body.watchlist-sidebar-active main:not(.watchlist-sidebar) {
    margin-right: var(--sidebar-width);
    transition: margin-right 0.3s ease;
}

body.watchlist-sidebar-active .header {
    right: var(--sidebar-width);
    transition: right 0.3s ease;
}

/* Shrink search bar when sidebar is active */
body.watchlist-sidebar-active .search-container {
    max-width: 280px;
    transition: max-width 0.3s ease;
}

/* Dashboard heatmap specific adjustment */
body.watchlist-sidebar-active .dashboard-heatmap,
body.watchlist-sidebar-active .heatmap-container,
body.watchlist-sidebar-active #heatmap-container {
    width: 100% !important;
    max-width: 100% !important;
}

/* TradingView widget containers adjustment */
body.watchlist-sidebar-active .tradingview-widget-container {
    width: 100% !important;
}

/* Sidebar Container */
.watchlist-sidebar {
    position: fixed;
    top: 0;
    right: -320px;
    width: var(--sidebar-width, 280px);
    height: 100vh;
    background: var(--bg-primary);
    border-left: 1px solid var(--border-primary);
    z-index: 900;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
    overflow: hidden;
}

.watchlist-sidebar.active {
    right: 0;
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    min-height: 48px;
    flex-shrink: 0;
}

.sidebar-header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-title-dropdown {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.15s;
}

.sidebar-title-dropdown:hover {
    background: var(--bg-tertiary);
}

.sidebar-title-dropdown i {
    font-size: 10px;
    color: var(--text-tertiary);
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.sidebar-action-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 14px;
}

.sidebar-action-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Table Header */
.sidebar-table-header {
    display: grid;
    grid-template-columns: 1fr 70px 60px 60px;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.sidebar-table-header span {
    cursor: pointer;
    transition: color 0.15s;
}

.sidebar-table-header span:hover {
    color: var(--text-secondary);
}

.sidebar-table-header span:nth-child(2),
.sidebar-table-header span:nth-child(3),
.sidebar-table-header span:nth-child(4) {
    text-align: right;
}

/* Sidebar Content */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border-secondary);
    border-radius: 3px;
}

/* Category Section */
.sidebar-category {
    border-bottom: 1px solid var(--border-primary);
}

.sidebar-category:last-child {
    border-bottom: none;
}

.sidebar-category-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.sidebar-category-header:hover {
    background: var(--bg-hover);
}

.sidebar-category-toggle {
    color: var(--text-tertiary);
    font-size: 10px;
    transition: transform 0.2s;
}

.sidebar-category.collapsed .sidebar-category-toggle {
    transform: rotate(-90deg);
}

.sidebar-category-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 10px;
}

.sidebar-category-icon.indices {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
}

.sidebar-category-icon.crypto {
    background: rgba(139, 92, 246, 0.15);
    color: #8B5CF6;
}

.sidebar-category-icon.equity {
    background: rgba(0, 212, 255, 0.15);
    color: #00D4FF;
}

.sidebar-category-icon.etf {
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
}

.sidebar-category-icon.futures {
    background: rgba(236, 72, 153, 0.15);
    color: #EC4899;
}

.sidebar-category-name {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sidebar-category-count {
    margin-left: auto;
    background: var(--bg-surface-2);
    color: var(--text-tertiary);
    font-size: 10px;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
}

.sidebar-category-items {
    display: block;
}

.sidebar-category.collapsed .sidebar-category-items {
    display: none;
}

/* Watchlist Item Row */
.sidebar-item {
    display: grid;
    grid-template-columns: 1fr 70px 60px 60px;
    padding: 0.5rem 1rem;
    align-items: center;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid var(--border-primary);
}

.sidebar-item:last-child {
    border-bottom: none;
}

.sidebar-item:hover {
    background: var(--bg-tertiary);
}

.sidebar-item-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.sidebar-item-logo {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-item-logo.stock {
    background: rgba(0, 212, 255, 0.15);
    color: #00D4FF;
}

.sidebar-item-logo.crypto {
    background: rgba(247, 147, 26, 0.15);
    color: #F7931A;
}

.sidebar-item-logo.index {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
}

.sidebar-item-details {
    min-width: 0;
    flex: 1;
}

.sidebar-item-symbol {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-white);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.sidebar-item-symbol .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
}

.sidebar-item-symbol .status-dot.delayed {
    background: var(--yellow);
}

.sidebar-item-name {
    font-size: 10px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-item-price {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-white);
    text-align: right;
    font-family: 'SF Mono', 'Monaco', monospace;
}

.sidebar-item-change {
    font-size: 11px;
    font-weight: 500;
    text-align: right;
    font-family: 'SF Mono', 'Monaco', monospace;
}

.sidebar-item-change.positive {
    color: var(--green);
}

.sidebar-item-change.negative {
    color: var(--red);
}

.sidebar-item-pct {
    font-size: 11px;
    font-weight: 500;
    text-align: right;
    font-family: 'SF Mono', 'Monaco', monospace;
}

.sidebar-item-pct.positive {
    color: var(--green);
}

.sidebar-item-pct.negative {
    color: var(--red);
}

/* Empty State */
.sidebar-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
}

.sidebar-empty i {
    font-size: 32px;
    color: var(--text-tertiary);
    opacity: 0.3;
    margin-bottom: 1rem;
}

.sidebar-empty h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.sidebar-empty p {
    font-size: 12px;
    color: var(--text-tertiary);
    line-height: 1.5;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.sidebar-add-btn {
    width: 100%;
    padding: 0.625rem;
    background: var(--bg-surface-2);
    border: 1px dashed var(--border-secondary);
    border-radius: 6px;
    color: var(--text-tertiary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.sidebar-add-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Resize Handle */
.sidebar-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    cursor: ew-resize;
    background: transparent;
    transition: background 0.15s;
}

.sidebar-resize-handle:hover {
    background: var(--accent-primary);
}

/* Mobile Responsive */
@media (max-width: 1024px) {
    body.watchlist-sidebar-active .dashboard,
    body.watchlist-sidebar-active .details-page,
    body.watchlist-sidebar-active main:not(.watchlist-sidebar) {
        margin-right: 0;
    }

    body.watchlist-sidebar-active .header {
        right: 0;
    }

    .watchlist-sidebar {
        width: 100%;
        max-width: 360px;
        right: -400px;
        z-index: 1100;
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
    }

    .watchlist-sidebar.active {
        right: 0;
    }
}

@media (max-width: 480px) {
    .watchlist-sidebar {
        max-width: 100%;
    }

    .sidebar-table-header {
        grid-template-columns: 1fr 60px 50px;
    }

    .sidebar-table-header span:nth-child(3) {
        display: none;
    }

    .sidebar-item {
        grid-template-columns: 1fr 60px 50px;
    }

    .sidebar-item-change {
        display: none;
    }
}

/* Collapse button for sidebar */
.sidebar-collapse-btn {
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 48px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 6px 0 0 6px;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    z-index: 10;
}

.sidebar-collapse-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-collapse-btn i {
    font-size: 10px;
    transition: transform 0.3s;
}

.watchlist-sidebar:not(.active) .sidebar-collapse-btn i {
    transform: rotate(180deg);
}
