/* ============================================================
   Kalshi Crypto Arbitrage Dashboard — Style
   Bloomberg Terminal meets Modern Fintech
   ============================================================ */

:root {
    /* Backgrounds */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --bg-card: #161b22;
    --bg-card-hover: #1c2128;
    --bg-header: #0d1117ee;

    /* Accents */
    --green: #00ff88;
    --green-dim: #00ff8833;
    --green-glow: #00ff8822;
    --red: #ff4444;
    --red-dim: #ff444433;
    --red-glow: #ff444422;
    --blue: #4da6ff;
    --blue-dim: #4da6ff33;
    --yellow: #ffd866;
    --yellow-dim: #ffd86633;

    /* Text */
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-tertiary: #484f58;
    --text-muted: #30363d;

    /* Borders */
    --border: #21262d;
    --border-light: #30363d;
    --border-glow: #00ff8815;

    /* Fonts */
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Sizing */
    --header-height: 64px;
    --radius: 8px;
    --radius-sm: 6px;
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

.mono {
    font-family: var(--font-mono);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

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

.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: var(--header-height);
    background: var(--bg-header);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

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

.logo-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--green-dim);
    border-radius: var(--radius-sm);
    border: 1px solid var(--green-dim);
}

.header-title h1 {
    font-size: 1.14rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.header-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 400;
}

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

.header-meta {
    display: flex;
    align-items: center;
    gap: 24px;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    font-size: 0.78rem;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.status-dot.green {
    background: var(--green);
    box-shadow: 0 0 8px var(--green), 0 0 16px var(--green-glow);
    animation: pulse-green 2s ease-in-out infinite;
}

.status-dot.yellow {
    background: var(--yellow);
    box-shadow: 0 0 8px var(--yellow);
}

.status-dot.grey {
    background: var(--text-tertiary);
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.meta-label {
    display: block;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

.meta-value {
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.last-updated, .uptime {
    text-align: right;
}

/* ============================================================
   DASHBOARD MAIN
   ============================================================ */

.dashboard {
    padding: 20px 24px;
    max-width: 1600px;
    margin: 0 auto;
    overflow-x: hidden;
}

/* ============================================================
   TOP STATS ROW
   ============================================================ */

.stats-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    position: relative;
    overflow: hidden;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    min-width: 0;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--green-dim), transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.stat-card:hover {
    border-color: var(--border-light);
    box-shadow: 0 0 20px var(--border-glow);
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-label {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
    margin-bottom: 4px;
    white-space: nowrap;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    white-space: nowrap;
}

.stat-sub {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 2px;
    white-space: nowrap;
}

.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-sub.positive { color: var(--green); }
.stat-sub.negative { color: var(--red); }

/* Kill Switch */
.kill-badge {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 700;
    font-family: var(--font-mono);
    letter-spacing: 0.05em;
}

.kill-badge.off {
    background: var(--green-dim);
    color: var(--green);
    border: 1px solid var(--green-dim);
}

.kill-badge.on {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid var(--red-dim);
    animation: kill-pulse 1s ease-in-out infinite;
}

@keyframes kill-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

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

.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    overflow: hidden;
}

.chart-card.chart-wide {
    grid-column: 1 / -1;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-header h3 {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: -0.01em;
}

.card-badge {
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 3px 10px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.card-badge.positive { color: var(--green); border-color: var(--green-dim); background: var(--green-glow); }
.card-badge.negative { color: var(--red); border-color: var(--red-dim); background: var(--red-glow); }

.chart-container {
    position: relative;
    height: 55px;
}

.chart-wide .chart-container {
    height: 65px;
}

/* ============================================================
   CRYPTO SECTION
   ============================================================ */

.crypto-section {
    margin-bottom: 20px;
}

.section-title {
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: -0.01em;
}

.crypto-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.crypto-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
    transition: border-color 0.3s ease;
}

.crypto-card:hover {
    border-color: var(--border-light);
}

.crypto-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 700;
    flex-shrink: 0;
}

.crypto-icon.btc {
    background: #f7931a22;
    color: #f7931a;
    border: 1px solid #f7931a33;
}

.crypto-icon.eth {
    background: #627eea22;
    color: #627eea;
    border: 1px solid #627eea33;
}

.crypto-icon.xrp {
    background: #00aae422;
    color: #00aae4;
    border: 1px solid #00aae433;
}

/* Sports icons */
.crypto-icon.nba {
    background: #c9082a22;
    color: #c9082a;
    border: 1px solid #c9082a33;
}

.crypto-icon.nfl {
    background: #01352422;
    color: #4caf50;
    border: 1px solid #4caf5033;
}

.crypto-icon.mlb {
    background: #bf003522;
    color: #bf0035;
    border: 1px solid #bf003533;
}

.crypto-icon.nhl {
    background: #00000022;
    color: #adb5bd;
    border: 1px solid #adb5bd33;
}

.crypto-icon.ncaab {
    background: #ff6f0022;
    color: #ff6f00;
    border: 1px solid #ff6f0033;
}

.crypto-icon.ncaaf {
    background: #1b5e2022;
    color: #66bb6a;
    border: 1px solid #66bb6a33;
}

.crypto-icon.mma {
    background: #d5001022;
    color: #d50010;
    border: 1px solid #d5001033;
}

.crypto-icon.wnba {
    background: #ff620022;
    color: #ff6200;
    border: 1px solid #ff620033;
}

.crypto-icon.sport-default {
    background: #7c4dff22;
    color: #7c4dff;
    border: 1px solid #7c4dff33;
}

.crypto-info {
    flex: 1;
    min-width: 0;
}

.crypto-name {
    font-size: 0.86rem;
    font-weight: 500;
    color: var(--text-primary);
}

.crypto-ticker {
    color: var(--text-tertiary);
    font-size: 0.72rem;
    font-weight: 400;
}

.crypto-pnl {
    font-size: 1.28rem;
    font-weight: 600;
}

.crypto-pnl.positive { color: var(--green); }
.crypto-pnl.negative { color: var(--red); }

.crypto-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 0.72rem;
    color: var(--text-secondary);
}

/* ============================================================
   CONTENT GRID (Tables + Sidebar)
   ============================================================ */

.content-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 12px;
    margin-bottom: 20px;
}

.tables-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 300px;
}

.table-wrapper-tall {
    max-height: 460px;
}

/* ============================================================
   DATA TABLES
   ============================================================ */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.data-table thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.data-table th {
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}

.data-table th.sortable {
    cursor: pointer;
    transition: color 0.2s;
}

.data-table th.sortable:hover {
    color: var(--blue);
}

.data-table th.sort-active {
    color: var(--blue);
}

.data-table td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 0.74rem;
    white-space: nowrap;
    color: var(--text-secondary);
}

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

.data-table tr.empty-row td {
    text-align: center;
    color: var(--text-tertiary);
    font-family: var(--font-sans);
    font-style: italic;
    padding: 30px;
}

.data-table tr.empty-row:hover td {
    background: transparent;
}

.data-table .cell-positive { color: var(--green); }
.data-table .cell-negative { color: var(--red); }
.data-table .cell-blue { color: var(--blue); }
.data-table .cell-yellow { color: var(--yellow); }

.side-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
}

.side-badge.yes {
    background: var(--green-dim);
    color: var(--green);
}

.side-badge.no {
    background: var(--red-dim);
    color: var(--red);
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 500;
}

.status-badge.placed { background: var(--blue-dim); color: var(--blue); }
.status-badge.filled { background: var(--green-dim); color: var(--green); }
.status-badge.cancelled { background: var(--red-dim); color: var(--red); }
.status-badge.pending { background: var(--yellow-dim); color: var(--yellow); }

/* Pagination */
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-btn {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    color: var(--text-primary);
    border-color: var(--border-light);
}

.page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-info {
    font-size: 0.72rem;
    color: var(--text-tertiary);
}

/* ============================================================
   STATUS PANEL (Sidebar)
   ============================================================ */

.status-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.panel-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.panel-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.panel-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.panel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-label {
    font-size: 0.74rem;
    color: var(--text-tertiary);
}

.panel-value {
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.daily-pnl-display {
    text-align: center;
    padding: 12px 0;
}

.daily-pnl-value {
    font-size: 2rem;
    font-weight: 700;
}

.daily-pnl-value.positive { color: var(--green); }
.daily-pnl-value.negative { color: var(--red); }

/* ============================================================
   FOOTER
   ============================================================ */

.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    color: var(--text-tertiary);
    font-size: 0.72rem;
}

.footer-sep {
    opacity: 0.3;
}

/* ============================================================
   TRANSITIONS / ANIMATIONS
   ============================================================ */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.stat-card, .chart-card, .crypto-card, .table-card, .panel-card {
    animation: fadeIn 0.4s ease-out both;
}

.stats-row .stat-card:nth-child(1) { animation-delay: 0.02s; }
.stats-row .stat-card:nth-child(2) { animation-delay: 0.04s; }
.stats-row .stat-card:nth-child(3) { animation-delay: 0.06s; }
.stats-row .stat-card:nth-child(4) { animation-delay: 0.08s; }
.stats-row .stat-card:nth-child(5) { animation-delay: 0.10s; }
.stats-row .stat-card:nth-child(6) { animation-delay: 0.12s; }

/* Number transition */
.value-updated {
    animation: flashGreen 0.6s ease-out;
}

@keyframes flashGreen {
    0% { text-shadow: 0 0 8px var(--green); }
    100% { text-shadow: none; }
}

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

@media (max-width: 900px) {
    .stats-row {
        grid-template-columns: repeat(3, 1fr);
    }
    .content-grid {
        grid-template-columns: 1fr;
    }
    .status-panel {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 1000px) {
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .crypto-cards {
        grid-template-columns: 1fr;
    }
    .status-panel {
        grid-template-columns: 1fr;
    }
    .header {
        flex-direction: column;
        height: auto;
        padding: 12px 16px;
        gap: 10px;
    }
    .header-meta {
        flex-wrap: wrap;
        gap: 12px;
    }
    .dashboard {
        padding: 12px 14px;
    }
}

/* Subtle grid background on body */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: 60px 60px;
    opacity: 0.15;
    pointer-events: none;
    z-index: -1;
}
