/* ============================================================
   HyperFlow Dashboard - Futuristic Dark Theme (GameFi / TradeFi)
   ============================================================ */

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

/* Force dark main background everywhere */
html {
    background: #05080c;
}

:root {
    --bg-deep: #05080c;
    --bg-surface: #0b0f18;
    --bg-card: rgba(12, 16, 28, 0.85);
    --bg-card-hover: rgba(18, 24, 42, 0.9);
    --border-subtle: rgba(0, 212, 255, 0.15);
    --border-glow: rgba(0, 212, 255, 0.4);
    --accent-cyan: #00d4ff;
    --accent-cyan-dim: #00d4ff99;
    --accent-purple: #a855f7;
    --accent-purple-dim: #a855f799;
    --profit: #00ff88;
    --profit-dim: #00ff8899;
    --loss: #ff4757;
    --loss-dim: #ff475799;
    --warn: #fbbf24;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --font-display: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-body: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --shadow-glow: 0 0 20px rgba(0, 212, 255, 0.08);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
}

body,
body.dashboard-body {
    font-family: var(--font-body);
    background: var(--bg-deep) !important;
    color: var(--text-primary);
    padding: 20px;
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0, 212, 255, 0.06), transparent),
        radial-gradient(ellipse 60% 40% at 100% 100%, rgba(168, 85, 247, 0.05), transparent),
        linear-gradient(180deg, #05080c 0%, #0a0e17 50%, #05080c 100%) !important;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
    min-width: 0;
}

/* Table wrappers: constrain width and allow horizontal scroll so tables don't stretch the page */
#positions-container,
#trades-container {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.positions-table,
.trades-table {
    width: 100%;
    min-width: 0;
}

/* ----- Header ----- */
.header {
    background: var(--bg-card);
    padding: 20px 24px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-cyan-dim), var(--accent-purple-dim), transparent);
    opacity: 0.6;
}

.header h1 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 0.35em;
}

/* Emoji in true color (not overridden by gradient) */
.header h1 .header-emoji {
    line-height: 1;
}

.header h1 .header-title-gradient {
    background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header > div {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-badge {
    padding: 8px 16px;
    border-radius: 20px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.status-running {
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.2), rgba(0, 212, 255, 0.15));
    color: var(--profit);
    border: 1px solid var(--profit-dim);
    box-shadow: 0 0 12px rgba(0, 255, 136, 0.2);
}

.status-stopped {
    background: rgba(255, 71, 87, 0.15);
    color: var(--loss);
    border: 1px solid var(--loss-dim);
}

/* ----- Stats grid ----- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-card);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}

.stat-card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.stat-card h3 {
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.stat-value {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.stat-value.positive {
    color: var(--profit);
    text-shadow: 0 0 20px rgba(0, 255, 136, 0.3);
}

.stat-value.negative {
    color: var(--loss);
}

.stat-subvalue {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.stat-subvalue.positive { color: var(--profit); }
.stat-subvalue.negative { color: var(--loss); }

/* ----- Main grid & cards ----- */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-card);
    transition: border-color 0.2s, box-shadow 0.2s;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

.card:hover {
    border-color: var(--border-glow);
    box-shadow: var(--shadow-glow);
}

.card h2 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--accent-cyan);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-subtle);
}

/* ----- Tables ----- */
.positions-table, .trades-table {
    width: 100%;
    border-collapse: collapse;
}

.positions-table th, .trades-table th {
    background: rgba(0, 212, 255, 0.06);
    padding: 12px 14px;
    text-align: left;
    font-family: var(--font-display);
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.positions-table td, .trades-table td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.875rem;
    color: var(--text-primary);
}

.positions-table tbody tr:hover, .trades-table tbody tr:hover {
    background: var(--bg-card-hover);
}

/* Placeholder rows (no data) stay dark */
.positions-table td[colspan], .trades-table td[colspan] {
    background: transparent !important;
    color: var(--text-secondary);
}

/* Winning / losing colors - positions and Recent Trades */
.profit-positive,
.trades-table td.profit-positive,
.positions-table td.profit-positive {
    color: #10b981 !important;
    font-weight: 600;
}

.profit-negative,
.trades-table td.profit-negative,
.positions-table td.profit-negative {
    color: #ef4444 !important;
    font-weight: 600;
}

/* ----- Best performer (24h) - when no open positions ----- */
.best-performer-box {
    margin-top: 12px;
    padding: 16px;
    border-radius: 10px;
    border: 1px solid var(--border-subtle);
    background: rgba(11, 15, 24, 0.5);
}

.best-performer-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-cyan);
    margin-bottom: 4px;
}

.best-performer-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.best-performer-stats {
    margin-bottom: 14px;
}

.best-performer-stats .best-performer-token {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.best-performer-stats .best-performer-pair {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.best-performer-stats .best-performer-prices {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.best-performer-stats .best-performer-profit {
    font-size: 1.1rem;
    font-weight: 600;
}

.best-performer-stats .best-performer-profit.positive {
    color: var(--profit);
}

.best-performer-stats .best-performer-profit.negative {
    color: var(--loss);
}

.best-performer-chart-wrap {
    width: 100%;
    height: 360px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.best-performer-chart-wrap .tradingview-chart {
    width: 100%;
    height: 100%;
    border: 0;
}

.best-performer-empty {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ----- Wallet info ----- */
.wallet-info {
    background: rgba(0, 212, 255, 0.05);
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.8rem;
    word-break: break-all;
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}

.wallet-info strong {
    color: var(--accent-cyan);
    margin-right: 6px;
}

/* ----- Logs ----- */
.logs-container {
    background: rgba(6, 9, 15, 0.95);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    max-height: 400px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.8rem;
    line-height: 1.5;
}

.logs-container::-webkit-scrollbar {
    width: 8px;
}

.logs-container::-webkit-scrollbar-track {
    background: var(--bg-surface);
    border-radius: 4px;
}

.logs-container::-webkit-scrollbar-thumb {
    background: var(--accent-cyan-dim);
    border-radius: 4px;
}

.log-entry {
    padding: 6px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    border-left: 3px solid transparent;
}

.log-entry.error {
    background: rgba(255, 71, 87, 0.08);
    border-left-color: var(--loss);
    color: #ff8a9a;
}

.log-entry.warning {
    background: rgba(251, 191, 36, 0.06);
    border-left-color: var(--warn);
    color: #fcd34d;
}

.log-entry.info {
    background: rgba(0, 212, 255, 0.04);
    border-left-color: var(--accent-cyan);
    color: var(--text-secondary);
}

.log-entry.success {
    background: rgba(0, 255, 136, 0.06);
    border-left-color: var(--profit);
    color: var(--profit-dim);
}

.log-entry.trade {
    background: rgba(168, 85, 247, 0.06);
    border-left-color: var(--accent-purple);
    color: var(--accent-purple-dim);
}

.log-timestamp {
    color: var(--text-muted);
    margin-right: 10px;
}

/* ----- Refresh indicator (live pulse) ----- */
.refresh-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--profit);
    margin-right: 8px;
    box-shadow: 0 0 10px var(--profit), 0 0 20px rgba(0, 255, 136, 0.4);
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0%, 100% { opacity: 1; box-shadow: 0 0 10px var(--profit), 0 0 20px rgba(0, 255, 136, 0.4); }
    50% { opacity: 0.7; box-shadow: 0 0 16px var(--profit), 0 0 32px rgba(0, 255, 136, 0.5); }
}

/* ----- Responsive: Tablet ----- */
@media (max-width: 768px) {
    body.dashboard-body,
    body {
        padding: 12px;
    }

    .header {
        padding: 14px 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .header h1 {
        font-size: 1.1rem;
        flex: 1 1 auto;
        min-width: 0;
    }

    .header > div {
        flex-shrink: 0;
    }

    .main-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-card h3 {
        font-size: 0.65rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .card {
        padding: 16px;
    }

    .card h2 {
        font-size: 0.95rem;
    }

    /* Tables: fixed min-width so they scroll inside the card; container already has overflow-x: auto */
    .positions-table {
        min-width: 520px;
    }

    .trades-table {
        min-width: 460px;
    }

    .positions-table th,
    .positions-table td,
    .trades-table th,
    .trades-table td {
        padding: 10px 8px;
        font-size: 0.8rem;
    }

    .logs-container {
        max-height: 280px;
        font-size: 0.75rem;
        padding: 12px;
    }
}

/* ----- Responsive: Mobile ----- */
@media (max-width: 480px) {
    body.dashboard-body,
    body {
        padding: 10px;
    }

    .container {
        width: 100%;
        min-width: 0;
    }

    .header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        padding: 12px;
    }

    .header h1 {
        font-size: 1rem;
        margin-bottom: 4px;
    }

    .header > div {
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 14px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-card h3 {
        font-size: 0.6rem;
        letter-spacing: 0.08em;
    }

    .stat-value {
        font-size: 1.1rem;
    }

    .stat-subvalue {
        font-size: 0.65rem;
    }

    .main-grid {
        gap: 14px;
        margin-bottom: 14px;
    }

    .card {
        padding: 12px;
    }

    .card h2 {
        font-size: 0.9rem;
        margin-bottom: 12px;
    }

    .wallet-info {
        padding: 10px;
        font-size: 0.75rem;
    }

    #positions-container,
    #trades-container {
        margin: 0 -12px;
        padding: 0 12px;
    }

    .positions-table,
    .trades-table {
        min-width: 420px;
    }

    .positions-table th,
    .positions-table td,
    .trades-table th,
    .trades-table td {
        padding: 8px 6px;
        font-size: 0.75rem;
    }

    .status-badge {
        padding: 6px 12px;
        font-size: 0.7rem;
    }

    .logs-container {
        max-height: 220px;
        font-size: 0.7rem;
        padding: 10px;
    }
}

/* ----- Responsive: Small mobile ----- */
@media (max-width: 360px) {
    body.dashboard-body,
    body {
        padding: 8px;
    }

    .header h1 {
        font-size: 0.9rem;
    }

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

    .stat-value {
        font-size: 1.25rem;
    }

    .positions-table,
    .trades-table {
        min-width: 360px;
    }

    .positions-table th,
    .positions-table td,
    .trades-table th,
    .trades-table td {
        font-size: 0.7rem;
        padding: 6px 4px;
    }
}
