/* ==========================================
   ANALYTICS DASHBOARD
   ========================================== */

:root {
    --bg-primary: #0F172A;
    --bg-secondary: #1E293B;
    --bg-tertiary: #334155;
    --text-primary: #F8FAFC;
    --text-secondary: #CBD5E1;
    --text-muted: #94A3B8;
    --border-color: #334155;
    --accent-primary: #667eea;
    --accent-secondary: #764ba2;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-width: 260px;
    --header-height: 80px;
    --transition: 200ms ease;
}

[data-theme="light"] {
    --bg-primary: #F8FAFC;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F1F5F9;
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #64748B;
    --border-color: #E2E8F0;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    min-height: 100vh;
    transition: var(--transition);
}

/* ==========================================
   SIDEBAR
   ========================================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    transition: var(--transition);
}

.sidebar-header {
    margin-bottom: 2rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    margin-bottom: 1.5rem;
    transition: var(--transition);
}

.back-link:hover {
    color: var(--text-primary);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 0.5rem;
    transition: var(--transition);
}

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

.nav-item.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

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

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 0.5rem;
    transition: var(--transition);
    margin-right: 1rem;
}

.menu-toggle:hover {
    background: var(--bg-tertiary);
}

.header-left {
    display: flex;
    align-items: center;
}

.header-left h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    gap: 0.75rem;
}

.theme-toggle,
.refresh-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.theme-toggle:hover,
.refresh-btn:hover {
    color: var(--text-primary);
    background: var(--border-color);
}

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

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

/* ==========================================
   STATS GRID
   ========================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    transition: var(--transition);
}

.stat-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.stat-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.stat-badge.positive {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.stat-badge.negative {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.stat-badge.neutral {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    margin-bottom: 1rem;
}

.stat-info {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.stat-chart {
    height: 60px;
    margin-top: 1rem;
}

/* ==========================================
   CHARTS GRID
   ========================================== */

.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    padding: 0 2rem 2rem;
}

.chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
}

.chart-card.large {
    min-height: 400px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.chart-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.chart-controls {
    display: flex;
    gap: 0.5rem;
}

.chart-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 0.375rem;
    font-weight: 600;
    font-size: 0.875rem;
    transition: var(--transition);
}

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

.chart-btn.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border-color: transparent;
}

.chart-body {
    position: relative;
    height: 300px;
}

/* ==========================================
   TABLE
   ========================================== */

.table-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    margin: 0 2rem 2rem;
    overflow: hidden;
}

.table-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.search-input {
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.9375rem;
    width: 250px;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.table-container {
    overflow-x: auto;
}

.crypto-table {
    width: 100%;
    border-collapse: collapse;
}

.crypto-table thead {
    background: var(--bg-tertiary);
}

.crypto-table th {
    padding: 1rem 1.5rem;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.crypto-table td {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

.crypto-table tbody tr {
    transition: var(--transition);
}

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

.crypto-name {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.crypto-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.crypto-info {
    display: flex;
    flex-direction: column;
}

.crypto-symbol {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.price-change {
    font-weight: 600;
}

.price-change.positive {
    color: var(--success);
}

.price-change.negative {
    color: var(--danger);
}

.trend-sparkline {
    width: 80px;
    height: 30px;
}

.loading-cell {
    text-align: center;
    padding: 3rem !important;
    color: var(--text-muted);
}

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

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: -var(--sidebar-width);
        top: 0;
        bottom: 0;
        z-index: 1000;
    }

    .sidebar.open {
        left: 0;
    }

    .menu-toggle {
        display: flex;
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }
}

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

    .charts-grid {
        padding: 0 1rem 1rem;
    }

    .table-card {
        margin: 0 1rem 1rem;
    }

    .header {
        padding: 0 1rem;
    }

    .header-left h1 {
        font-size: 1.125rem;
    }

    .subtitle {
        display: none;
    }

    .search-input {
        width: 150px;
    }

    .crypto-table th,
    .crypto-table td {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }

    .crypto-table th:nth-child(6),
    .crypto-table td:nth-child(6),
    .crypto-table th:nth-child(7),
    .crypto-table td:nth-child(7) {
        display: none;
    }
}

@media (max-width: 480px) {
    .stat-value {
        font-size: 1.5rem;
    }

    .chart-body {
        height: 200px;
    }
}

/* ==========================================
   UTILITIES
   ========================================== */

.hidden {
    display: none !important;
}

/* ==========================================
   ANALYTICS TAB
   ========================================== */

.analytics-content {
    padding: 2rem;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.analytics-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    min-height: 300px;
}

.analytics-card h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.trend-analysis {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.trend-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.trend-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 1rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 1rem;
    transition: width 0.3s ease;
}

.progress-fill.positive {
    background: var(--success);
}

.progress-fill.warning {
    background: var(--warning);
}

.trend-value {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.insights-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
}

.insights-panel h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.insight-item {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 0.75rem;
    margin-bottom: 1rem;
}

.insight-item:last-child {
    margin-bottom: 0;
}

.insight-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.insight-icon.positive {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.insight-icon.warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.insight-icon.info {
    background: rgba(102, 126, 234, 0.1);
    color: var(--accent-primary);
}

.insight-content h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.insight-content p {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ==========================================
   REALTIME TAB
   ========================================== */

.realtime-content {
    padding: 2rem;
}

.live-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 0.5rem;
    color: var(--success);
    font-weight: 600;
    font-size: 0.875rem;
}

.pulse {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

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

.realtime-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.realtime-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.25rem;
    transition: all 0.3s ease;
}

.realtime-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.realtime-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.realtime-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.realtime-change {
    font-size: 0.875rem;
    font-weight: 600;
}

.realtime-change.positive {
    color: var(--success);
}

.realtime-change.negative {
    color: var(--danger);
}

.realtime-price {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
}

.realtime-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.order-book {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.order-book h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.order-book-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.order-book h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 1rem;
}

.order-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.order-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 0.375rem;
    font-size: 0.875rem;
}

.order-item.bid .order-price {
    color: var(--success);
}

.order-item.ask .order-price {
    color: var(--danger);
}

.order-amount {
    color: var(--text-secondary);
}

/* ==========================================
   SETTINGS TAB
   ========================================== */

.settings-content {
    max-width: 800px;
    padding: 2rem;
}

.settings-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.settings-section h3 {
    font-size: 1.125rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.setting-item:first-child {
    padding-top: 0;
}

.setting-item label {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--text-primary);
}

.setting-select,
.setting-input {
    padding: 0.625rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-size: 0.9375rem;
    min-width: 200px;
}

.setting-input {
    min-width: 100px;
}

.setting-select:focus,
.setting-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    transition: 0.3s;
    border-radius: 26px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .slider {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

input:checked + .slider:before {
    transform: translateX(24px);
}

.settings-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9375rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* ==========================================
   RESPONSIVE - TAB SPECIFIC
   ========================================== */

@media (max-width: 768px) {
    .analytics-content,
    .realtime-content,
    .settings-content {
        padding: 1rem;
    }

    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .realtime-grid {
        grid-template-columns: 1fr;
    }

    .order-book-content {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .setting-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .setting-select,
    .setting-input {
        width: 100%;
    }

    .settings-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}
