/**
 * 2-LAYOUT.CSS
 * 
 * All layout structures: header, sidebar, main content, panels.
 * Uses SIMPLE class-based approach for panel scaling.
 */

/* ============================================
   HEADER - FIXED FULL WIDTH
   ============================================ */

.unified-header-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--header-height);
    z-index: var(--z-header);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-lg);
    gap: var(--spacing-lg);
}

/* Header Logo */
.header-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    transition: all var(--transition-base);
    cursor: pointer;
    border: none;
    background: transparent;
}

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

.logo-image {
    width: 28px;
    height: 28px;
    object-fit: contain;
    display: block;
}

/* ============================================
   HEADER - MARKET DATA (INVISIBLE CARDS)
   ============================================ */

/* Container - inline layout */
.header-market-cards {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    flex: 1;
    justify-content: center;
    font-size: var(--font-size-small);
}

/* Individual Cards - INVISIBLE containers (no background, no border) */
.header-market-card {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    color: var(--text-secondary);
    /* NO background */
    /* NO border */
    /* NO padding */
    /* Just a container for scoping */
}

/* Separators between cards using ::after */
.header-market-card:not(:last-child)::after {
    content: "•";
    color: var(--text-muted);
    margin-left: var(--spacing-md);
}

/* BTC Price */
.btc-card {
    font-weight: var(--font-weight-medium);
}

#btcPrice {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

.btc-change {
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-semibold);
}

.btc-change.positive { color: var(--success); }
.btc-change.negative { color: var(--danger); }
.btc-change.neutral { color: var(--text-secondary); }

.btc-change-minimal.positive { color: var(--success); }
.btc-change-minimal.negative { color: var(--danger); }

/* 24H Stats - Progressive Disclosure */
.stats-card {
    font-weight: var(--font-weight-medium);
}

.stats-card span {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

/* Desktop: Show full */
.stats-full {
    display: inline-flex;
    gap: var(--spacing-sm);
}

.stats-condensed,
.stats-minimal {
    display: none;
}

/* Funding Rate */
.funding-card {
    font-weight: var(--font-weight-medium);
}

#fundingRate {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

#fundingRate.positive { color: var(--danger); }
#fundingRate.negative { color: var(--success); }
#fundingRate.neutral { color: var(--text-primary); }

.funding-countdown {
    color: var(--text-muted);
    font-size: var(--font-size-small);
}

/* Fear & Greed */
.fng-card {
    font-weight: var(--font-weight-medium);
}

#fgValue {
    font-weight: var(--font-weight-semibold);
}

#fgValue[data-value="extreme-fear"] { color: var(--danger); }
#fgValue[data-value="fear"] { color: #e89b6f; }
#fgValue[data-value="neutral"] { color: var(--text-secondary); }
#fgValue[data-value="greed"] { color: #8dbd7f; }
#fgValue[data-value="extreme-greed"] { color: var(--success); }

.fng-classification {
    color: var(--text-muted);
    font-size: var(--font-size-small);
}

/* ============================================
   PROGRESSIVE DISCLOSURE - RESPONSIVE
   ============================================ */

/* Laptop (1024px - 1919px) */
@media (max-width: 1919px) {
    .stats-full {
        display: none;
    }
    
    .stats-condensed {
        display: inline-flex;
        gap: var(--spacing-xs);
    }
    
    .funding-countdown {
        display: none;
    }
    
    .fng-classification {
        display: none;
    }
}

/* Tablet (768px - 1023px) */
@media (max-width: 1023px) {
    .stats-condensed {
        display: none;
    }
    
    .stats-minimal {
        display: inline-flex;
        gap: var(--spacing-xs);
    }
    
    .btc-card {
        display: none;
    }
    
    /* Hide separator after hidden card */
    .btc-card::after {
        display: none;
    }
}

/* Mobile (≤767px) */
@media (max-width: 767px) {
    .btc-card,
    .stats-card,
    .funding-card {
        display: none;
    }
    
    /* Hide separators for hidden cards */
    .btc-card::after,
    .stats-card::after,
    .funding-card::after {
        display: none;
    }
    
    /* Show F&G classification on mobile */
    .fng-classification {
        display: inline;
    }
}

/* ============================================
   HEADER CONTROLS
   ============================================ */

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.header-btn {
    position: relative;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-base);
    cursor: pointer;
    border: none;
    background: transparent;
}

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

.header-btn svg {
    width: 18px;
    height: 18px;
}

.alert-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: var(--font-weight-bold);
    padding: 2px 5px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
}

.header-last-updated {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: var(--font-size-small);
    color: var(--text-secondary);
}

.freshness-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.freshness-indicator.fresh {
    background: var(--success);
    animation: pulse 2s infinite;
}

.freshness-indicator.stale {
    background: var(--warning);
}

.freshness-indicator.error {
    background: var(--danger);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

/* ============================================
   SIDEBAR - FIXED LEFT
   ============================================ */

.sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    width: var(--sidebar-width-collapsed);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: var(--z-sidebar);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-slow);
    overflow: hidden;
}

.sidebar.expanded {
    width: var(--sidebar-width-expanded);
}

/* Sidebar items */
.sidebar-item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
    min-height: 48px;
}

.sidebar.expanded .sidebar-item {
    justify-content: flex-start;
    padding-left: var(--spacing-lg);
    gap: var(--spacing-md);
}

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

.sidebar-item.active {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    border-left: 3px solid var(--accent-primary);
}

.sidebar-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-label {
    display: none;
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-medium);
}

.sidebar.expanded .sidebar-label {
    display: block;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto; /* Push to bottom of sidebar */
    border-top: 1px solid var(--border);
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.last-updated-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
    font-size: var(--font-size-tiny);
    color: var(--text-muted);
}

.last-updated-label {
    font-size: var(--font-size-tiny);
    color: var(--text-muted);
}

.last-updated-time {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
}

.refresh-btn,
.pause-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-base);
    font-size: 16px;
}

.refresh-btn:hover,
.pause-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-status {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.status-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    justify-content: center;  /* ADD THIS - centers dots when collapsed */
}

.sidebar.expanded .status-item {
    justify-content: flex-start;  /* ADD THIS RULE - left-aligns when expanded */
}

.status-label {
    display: none;
    font-size: var(--font-size-tiny);
    color: var(--text-muted);
}

.sidebar.expanded .status-label {
    display: block;
}

.status-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.connected {
    background: var(--success);
    animation: pulse 2s infinite;
}

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

.status-dot.connecting {
    background: var(--warning);
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(0.95);
    }
}

/* Sidebar Backdrop for Mobile */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-sidebar) - 1);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-slow);
}

.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

/* Sidebar Mobile Behavior */
@media (max-width: 768px) {
    .sidebar {
        left: calc(-1 * var(--sidebar-width-collapsed));
        width: var(--sidebar-width-collapsed);
        transition: left var(--transition-slow);
    }
    
    .sidebar.mobile-open {
        left: 0;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* ============================================
   MAIN CONTENT AREA
   ============================================ */

.main-content {
    margin-left: var(--sidebar-width-collapsed);
    margin-right: var(--panel-push-margin);
    padding-top: var(--header-height);
    min-height: 100vh;
    transition: margin-left var(--transition-slow), 
                margin-right var(--transition-slow);
}

.sidebar.expanded ~ .main-content {
    margin-left: var(--sidebar-width-expanded);
}

/* Content container */
.content-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-lg);
    width: 100%;
}

/* ============================================
   UNIFIED PANEL SYSTEM - Simple & DRY
   All panels share SAME width and properties
   ============================================ */

/* -----------------------------------------
   BASE PANEL CLASS
   Everything is here, no variants needed
   ----------------------------------------- */

.panel {
    /* Positioning */
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    
    /* Width - SAME for ALL panels */
    width: 35%;
    min-width: 375px;
    max-width: 800px;
    
    /* Appearance */
    background: var(--bg-primary);
    border-left: 1px solid var(--border);
    
    /* Animation */
    transform: translateX(100%);
    transition: transform var(--transition-slow);
    
    /* Stacking */
    z-index: var(--z-modal);
    
    /* Scrolling */
    overflow: hidden;
    
    /* Layout */
    display: flex;
    flex-direction: column;
}

/* Universal Open State - ONE rule for ALL panels */
.panel.active {
    transform: translateX(0);
}

/* -----------------------------------------
   SPECIFIC OVERRIDES (minimal)
   Only if truly needed
   ----------------------------------------- */

/* Detail Panel & Settings Panel - Different background */
.detail-panel,
.settings-panel {
    background: var(--bg-secondary);
}

/* Settings Panel Structure */
.settings-tabs {
    display: flex;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none; /* Firefox */
}

.settings-tabs::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.settings-tab {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-small);
    font-weight: var(--font-weight-medium);
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
}

.settings-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.settings-tab.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

.settings-content {
    flex: 1;
    padding: var(--spacing-md);
    overflow-y: auto;
}

/* -----------------------------------------
   PANEL HEADER - Shared Component
   ----------------------------------------- */

.panel-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: var(--spacing-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: var(--header-height);
    flex-shrink: 0;
}

.panel-title {
    font-size: var(--font-size-h2);
    font-weight: var(--font-weight-semibold);
    margin: 0;
    color: var(--text-primary);
}

.panel-actions {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

/* -----------------------------------------
   PANEL CONTENT - Shared Component
   ----------------------------------------- */

.panel-content {
    flex: 1;
    padding: var(--spacing-lg);
    overflow-y: auto;
}

/* Settings Panel Structure */
.settings-tabs {
    flex-shrink: 0;
}

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--spacing-lg);
}

/* -----------------------------------------
   PANEL BACKDROPS - Shared Component
   ----------------------------------------- */

.panel-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, var(--backdrop-opacity, 0.5));
    z-index: var(--z-backdrop);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-slow);
}

.panel-backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

/* ============================================
   DESKTOP BEHAVIOR (>1024px)
   ============================================ */

@media (min-width: 1025px) {
    /* Hide all backdrops on desktop */
    .panel-backdrop {
        display: none !important;
    }
    
    /* Content push when ANY panel opens */
    body.panel-open-desktop .main-content {
        width: calc(65% - var(--sidebar-width-collapsed));
        transition: width var(--transition-slow);
    }
}

/* ============================================
   TABLET BEHAVIOR (769px - 1024px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    /* Panels full width minus sidebar */
    .panel {
        width: calc(100vw - var(--sidebar-width-collapsed)) !important;
        max-width: calc(100vw - var(--sidebar-width-collapsed)) !important;
        min-width: 0 !important;
        left: var(--sidebar-width-collapsed);
    }
}

/* ============================================
   MOBILE BEHAVIOR (≤768px)
   ============================================ */

@media (max-width: 768px) {
    /* Panels full width (sidebar hidden) */
    .panel {
        width: 100vw !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        left: 0;
    }
}

/* ============================================
   GRID SYSTEMS
   ============================================ */

/* Bots grid */
.bots-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--spacing-lg);
    transition: gap var(--transition-base);
}

@media (max-width: 768px) {
    .bots-grid {
        grid-template-columns: 1fr;
    }
}

/* Metrics grid (4 columns default) */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-md);
    transition: gap var(--transition-base);
}

@media (max-width: 600px) {
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   BOT-SPECIFIC PANELS (Detail, Settings, Backups)
   ============================================ */


/* ============================================
   RESPONSIVE HELPERS
   ============================================ */

/* Mobile-only visibility */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }
    
    .desktop-only {
        display: none;
    }
}


/* ========================================
   SIDEBAR USER SECTION (AUTH)
   ======================================== */

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md) var(--spacing-md);
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.sidebar-item {
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.user-info .sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex: 1;
    min-width: 0;

}

.user-icon {
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.user-name {
    font-size: var(--font-small);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logout-btn {
    width: 32px;
    height: 32px;
    padding: 6px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logout-btn svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.logout-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-red);
}

.logout-btn:hover svg {
    color: var(--accent-red);
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .sidebar-user {
        padding: var(--spacing-sm) var(--spacing-md);
    }
}

/* Collapsed Sidebar State */
.sidebar.collapsed .sidebar-user {
    flex-direction: column;
    gap: var(--spacing-sm);
}

.sidebar.collapsed .user-info {
    display: none;
}

.sidebar.collapsed .logout-btn {
    width: 100%;
}


