/* =============================================================================
   HLBot Trading Dashboard - Professional Dark Theme
   Mobile-first, optimized for trading metrics display
   ============================================================================= */

:root {
    /* Core colors */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-elevated: #1c2128;
    
    /* Text */
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    
    /* Accent colors */
    --accent-blue: #58a6ff;
    --accent-purple: #a371f7;
    
    /* Trading colors */
    --profit: #3fb950;
    --profit-bg: rgba(63, 185, 80, 0.15);
    --loss: #f85149;
    --loss-bg: rgba(248, 81, 73, 0.15);
    --neutral: #8b949e;
    --warning: #d29922;
    --warning-bg: rgba(210, 153, 34, 0.15);
    
    /* Borders */
    --border-primary: #30363d;
    --border-secondary: #21262d;
    
    /* Status colors */
    --status-online: #3fb950;
    --status-offline: #f85149;
    --status-warning: #d29922;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    
    /* Typography */
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* Sizing */
    --header-height: 48px;
    --status-bar-height: 32px;
}

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

html {
    font-size: 14px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* =============================================================================
   Status Bar - Always Visible
   ============================================================================= */

.status-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--status-bar-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    z-index: 1000;
    font-size: 11px;
    gap: var(--space-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.status-bar::-webkit-scrollbar {
    display: none;
}

.status-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    white-space: nowrap;
    color: var(--text-secondary);
}

.status-item.clickable {
    cursor: pointer;
}

.status-item.clickable:hover {
    color: var(--text-primary);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.online { background: var(--status-online); box-shadow: 0 0 6px var(--status-online); }
.status-dot.offline { background: var(--status-offline); box-shadow: 0 0 6px var(--status-offline); }
.status-dot.warning { background: var(--status-warning); box-shadow: 0 0 6px var(--status-warning); }

.status-separator {
    width: 1px;
    height: 16px;
    background: var(--border-primary);
    flex-shrink: 0;
}

.status-value {
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.status-label {
    color: var(--text-muted);
}

/* =============================================================================
   Header
   ============================================================================= */

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

.header-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.header-title .logo {
    width: 24px;
    height: 24px;
}

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

.period-selector {
    display: flex;
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 2px;
}

.period-btn {
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}

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

.period-btn.active {
    background: var(--accent-blue);
    color: white;
}

.refresh-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

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

.refresh-btn.loading {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* =============================================================================
   Main Content Area
   ============================================================================= */

.main-content {
    padding-top: calc(var(--status-bar-height) + var(--header-height) + var(--space-lg));
    padding-bottom: var(--space-xl);
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    max-width: 1400px;
    margin: 0 auto;
}

/* =============================================================================
   Comparison Panel - Main View
   ============================================================================= */

.comparison-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    margin-bottom: var(--space-lg);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-primary);
    background: var(--bg-tertiary);
}

.panel-title {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.panel-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.panel-badge.best {
    background: var(--profit-bg);
    color: var(--profit);
}

/* Comparison Table */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.comparison-table th {
    text-align: left;
    padding: var(--space-sm) var(--space-md);
    font-weight: 500;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
}

.comparison-table th.numeric {
    text-align: right;
}

.comparison-table td {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-secondary);
    vertical-align: middle;
}

.comparison-table td.numeric {
    text-align: right;
    font-family: var(--font-mono);
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

.comparison-table tr:hover {
    background: var(--bg-tertiary);
}

.comparison-table tr.best-row {
    background: var(--profit-bg);
}

/* Wallet Cell */
.wallet-cell {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.wallet-badge {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    flex-shrink: 0;
}

.wallet-badge.w1 { background: #3b82f6; color: white; }
.wallet-badge.w2 { background: #8b5cf6; color: white; }
.wallet-badge.w3 { background: #ec4899; color: white; }
.wallet-badge.w4 { background: #f59e0b; color: white; }
.wallet-badge.w5 { background: #10b981; color: white; }

.wallet-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.wallet-name {
    font-weight: 600;
    color: var(--text-primary);
}

.wallet-tp {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Value Display */
.value-positive { color: var(--profit); }
.value-negative { color: var(--loss); }
.value-neutral { color: var(--text-secondary); }
.value-muted { color: var(--text-muted); }

.value-with-sub {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
}

.value-main {
    font-weight: 600;
}

.value-sub {
    font-size: 10px;
    color: var(--text-muted);
}

/* Rate Bar */
.rate-bar-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 80px;
}

.rate-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.rate-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

.rate-bar-fill.good { background: var(--profit); }
.rate-bar-fill.warning { background: var(--warning); }
.rate-bar-fill.bad { background: var(--loss); }

.rate-value {
    font-size: 12px;
    font-family: var(--font-mono);
    font-weight: 600;
}

/* =============================================================================
   Live Positions Grid
   ============================================================================= */

.positions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.position-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    overflow: hidden;
}

.position-card.has-position {
    border-color: var(--accent-blue);
}

.position-card.has-position.profit {
    border-color: var(--profit);
}

.position-card.has-position.loss {
    border-color: var(--loss);
}

.position-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-secondary);
}

.position-wallet {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.position-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: 500;
    text-transform: uppercase;
}

.position-status.long {
    background: var(--profit-bg);
    color: var(--profit);
}

.position-status.short {
    background: var(--loss-bg);
    color: var(--loss);
}

.position-status.flat {
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.position-body {
    padding: var(--space-md);
}

.position-empty {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}

/* ROI Display */
.roi-display {
    text-align: center;
    margin-bottom: var(--space-md);
}

.roi-current {
    font-size: 32px;
    font-weight: 700;
    font-family: var(--font-mono);
    line-height: 1;
}

.roi-current.positive { color: var(--profit); }
.roi-current.negative { color: var(--loss); }

.roi-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Progress to TP */
.tp-progress {
    margin-bottom: var(--space-md);
}

.tp-progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    margin-bottom: 6px;
}

.tp-progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.tp-progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
    position: relative;
}

.tp-progress-fill.positive {
    background: linear-gradient(90deg, var(--profit) 0%, #22c55e 100%);
}

.tp-progress-fill.negative {
    background: linear-gradient(90deg, var(--loss) 0%, #dc2626 100%);
}

.tp-progress-marker {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    background: var(--text-primary);
    border-radius: 1px;
}

/* Position Stats Grid */
.position-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
}

.position-stat {
    background: var(--bg-tertiary);
    padding: var(--space-sm);
    border-radius: 6px;
}

.position-stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 2px;
}

.position-stat-value {
    font-size: 14px;
    font-family: var(--font-mono);
    font-weight: 600;
}

/* =============================================================================
   Activity Feed
   ============================================================================= */

.activity-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--space-md);
}

.activity-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    overflow: hidden;
    max-height: 400px;
    display: flex;
    flex-direction: column;
}

.activity-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: 6px;
    margin-bottom: var(--space-xs);
}

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

.activity-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
}

.activity-icon.webhook {
    background: var(--accent-blue);
    background: rgba(88, 166, 255, 0.2);
    color: var(--accent-blue);
}

.activity-icon.trade {
    background: rgba(163, 113, 247, 0.2);
    color: var(--accent-purple);
}

.activity-icon.tp {
    background: var(--profit-bg);
    color: var(--profit);
}

.activity-icon.error {
    background: var(--loss-bg);
    color: var(--loss);
}

.activity-content {
    flex: 1;
    min-width: 0;
}

.activity-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    gap: var(--space-sm);
    margin-top: 2px;
}

.activity-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 32px;
    margin-bottom: var(--space-sm);
    opacity: 0.5;
}

/* =============================================================================
   Metrics Summary Row
   ============================================================================= */

.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.metric-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    padding: var(--space-md);
}

.metric-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-xs);
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.metric-change {
    font-size: 11px;
    margin-top: var(--space-xs);
}

.metric-change.positive { color: var(--profit); }
.metric-change.negative { color: var(--loss); }

/* =============================================================================
   Error Banner
   ============================================================================= */

.error-banner {
    background: var(--loss-bg);
    border: 1px solid var(--loss);
    border-radius: 8px;
    padding: var(--space-md);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.error-banner-icon {
    color: var(--loss);
    font-size: 20px;
}

.error-banner-content {
    flex: 1;
}

.error-banner-title {
    font-weight: 600;
    color: var(--loss);
}

.error-banner-message {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.error-banner-action {
    padding: 6px 12px;
    background: var(--loss);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
}

/* =============================================================================
   Mobile Responsive
   ============================================================================= */

@media (max-width: 768px) {
    :root {
        --space-md: 10px;
        --space-lg: 14px;
    }
    
    html {
        font-size: 13px;
    }
    
    /* Status bar - horizontal scroll on mobile */
    .status-bar {
        gap: var(--space-sm);
        padding: 0 var(--space-sm);
    }
    
    .status-item {
        font-size: 10px;
    }
    
    .status-separator {
        display: none;
    }
    
    /* Header */
    .header {
        padding: 0 var(--space-md);
    }
    
    .header-title {
        font-size: 14px;
    }
    
    .period-btn {
        padding: 4px 8px;
        font-size: 11px;
    }
    
    /* Main content */
    .main-content {
        padding-left: var(--space-sm);
        padding-right: var(--space-sm);
    }
    
    /* Comparison table - horizontal scroll */
    .comparison-panel {
        overflow-x: auto;
    }
    
    .comparison-table {
        min-width: 600px;
    }
    
    .comparison-table th,
    .comparison-table td {
        padding: var(--space-sm);
    }
    
    /* Positions - single column */
    .positions-grid {
        grid-template-columns: 1fr;
    }
    
    .roi-current {
        font-size: 28px;
    }
    
    /* Activity - single column */
    .activity-section {
        grid-template-columns: 1fr;
    }
    
    .activity-panel {
        max-height: 300px;
    }
    
    /* Metrics */
    .metrics-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .metric-value {
        font-size: 20px;
    }
}

@media (max-width: 480px) {
    .header-title span:not(.logo) {
        display: none;
    }
    
    .wallet-info {
        display: none;
    }
    
    .comparison-table {
        font-size: 11px;
    }
    
    .metrics-row {
        grid-template-columns: 1fr 1fr;
        gap: var(--space-sm);
    }
    
    .metric-card {
        padding: var(--space-sm);
    }
    
    .metric-value {
        font-size: 18px;
    }
}

/* =============================================================================
   Utility Classes
   ============================================================================= */

.hidden { display: none !important; }
.text-profit { color: var(--profit); }
.text-loss { color: var(--loss); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-muted); }
.text-mono { font-family: var(--font-mono); }
.font-bold { font-weight: 600; }

/* Loading skeleton */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-elevated) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Tooltip */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 100;
}

[data-tooltip]:hover::after {
    opacity: 1;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-primary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
