/* ── Variables ────────────────────────────────────────── */
:root {
    --bg:      #080808;
    --surface: #111111;
    --border:  #1c1c1c;
    --text:    #f0f0f0;
    --muted:   #555;
    --accent:  #3B82F6;
    --up:      #10B981;
    --down:    #EF4444;
    --amber:   #F59E0B;
    --teal:    #06B6D4;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.up   { color: var(--up); }
.down { color: var(--down); }

/* ── Login overlay ────────────────────────────────────── */
#login-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    transition: opacity 0.4s ease-out;
}

.floating-bitcoins {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.floating-btc {
    position: absolute;
    color: rgba(59, 130, 246, 0.1);
    font-weight: 900;
    font-size: 2rem;
    user-select: none;
    animation: float linear infinite;
}

@keyframes float {
    from { transform: translateY(110vh) rotate(0deg); }
    to   { transform: translateY(-20vh) rotate(360deg); }
}

.login-box {
    text-align: center;
    background: var(--surface);
    padding: 40px;
    border-radius: 12px;
    border: 1px solid var(--border);
    width: 320px;
    z-index: 10;
}

.login-logo {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 24px;
}

#password-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 11px 16px;
    border-radius: 6px;
    outline: none;
    text-align: center;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

#password-input:focus { border-color: var(--accent); }

#login-error {
    color: var(--down);
    font-size: 12px;
    margin-top: 10px;
    display: none;
}

@keyframes shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}
.shake { animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both; }

/* ── Header ───────────────────────────────────────────── */
.app-header {
    flex-shrink: 0;
    height: 48px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 100;
}

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

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

.header-logo {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text);
    text-decoration: none;
}

.header-sep {
    color: var(--border);
    font-size: 16px;
}

.ticker {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.price {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.change {
    font-size: 13px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.change.up   { color: var(--up); }
.change.down { color: var(--down); }

.sync-status {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    transition: color 0.3s;
}
.sync-status.synced  { color: var(--up); }
.sync-status.error   { color: var(--down); }
.sync-status.loading { color: var(--accent); }

.btn-reset {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.btn-reset:hover { border-color: var(--down); color: var(--down); }

/* ── Main layout ──────────────────────────────────────── */
.app-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 340px;
    overflow: hidden;
    min-height: 0;
}

/* ── Chart ────────────────────────────────────────────── */
.chart-container {
    position: relative;
    background: var(--bg);
    border-right: 1px solid var(--border);
    min-width: 0;
}

#chart-overlay {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 10;
    pointer-events: none;
}

.trades-badge {
    background: rgba(17,17,17,0.85);
    backdrop-filter: blur(4px);
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    border: 1px solid var(--border);
    color: var(--muted);
}

/* ── Notifications ────────────────────────────────────── */
#notification-container {
    position: absolute;
    top: 50%;
    left: 16px;
    transform: translateY(-50%);
    z-index: 50;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notification-toast {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: 8px;
    width: 230px;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease-out forwards;
    transition: opacity 0.4s, transform 0.4s;
}

@keyframes slideIn {
    from { transform: translateX(-120%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

.notification-toast.buy  { border-left: 3px solid var(--up); }
.notification-toast.sell { border-left: 3px solid var(--down); }

.notif-header {
    font-size: 12px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    margin-bottom: 3px;
}

.notif-msg {
    font-size: 11px;
    color: var(--muted);
}

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow: hidden;    /* critical: never let sidebar itself scroll */
    height: 100%;
}

/* ── Section label ────────────────────────────────────── */
.section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ── Spotlight card ───────────────────────────────────── */
.spotlight-card {
    flex-shrink: 0;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.spotlight-card:hover { background: var(--surface); }

.loading-text {
    font-size: 12px;
    color: var(--muted);
    margin-top: 8px;
}

/* ── Arena section ────────────────────────────────────── */
.arena-section {
    flex: 1;
    min-height: 0;       /* must have this so flex-1 can actually shrink */
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--border);
}

.arena-label {
    flex-shrink: 0;
    padding: 10px 16px 6px;
}

.agent-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 8px 8px;
}

.agent-list::-webkit-scrollbar { width: 3px; }
.agent-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.agent-list::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Agent cards ──────────────────────────────────────── */
.agent-card {
    padding: 9px 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.agent-card:hover { background: var(--surface); }

.agent-card.fast   { border-left: 3px solid var(--amber); }
.agent-card.medium { border-left: 3px solid var(--accent); }
.agent-card.slow   { border-left: 3px solid var(--teal); }
.agent-card.fast:hover   { border-color: var(--amber); background: var(--surface); }
.agent-card.medium:hover { border-color: var(--accent); background: var(--surface); }
.agent-card.slow:hover   { border-color: var(--teal); background: var(--surface); }

.agent-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 3px;
}

.agent-name {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}

.agent-roi {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.agent-stats {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--muted);
}

/* ── Trade log section ────────────────────────────────── */
.trade-log-container {
    flex-shrink: 0;
    height: 240px;       /* fixed — never steals space from the arena */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.log-tabs {
    flex-shrink: 0;
    display: flex;
    border-bottom: 1px solid var(--border);
}

.log-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    font-family: inherit;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 8px 0;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}
.log-tab:hover { color: var(--text); }
.log-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.tab-badge {
    background: var(--accent);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 10px;
    min-width: 16px;
    text-align: center;
    display: inline-block;
}
.tab-badge:empty { display: none; }

.log-panel {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px;
}

.log-panel::-webkit-scrollbar { width: 3px; }
.log-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ── Log entries ──────────────────────────────────────── */
.log-entry {
    padding: 8px 6px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.log-entry:last-child { border-bottom: none; }
.log-entry:hover { background: var(--surface); border-radius: 4px; }

.log-empty {
    font-size: 12px;
    color: var(--muted);
    padding: 16px 6px;
    text-align: center;
}

.side-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}
.side-badge.buy  { background: rgba(16,185,129,0.15); color: var(--up); }
.side-badge.sell { background: rgba(239,68,68,0.15);  color: var(--down); }

.leverage-badge {
    display: inline-block;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    background: rgba(245,158,11,0.12);
    color: var(--amber);
    flex-shrink: 0;
}

/* ── DNA hover card ───────────────────────────────────── */
.dna-hover-card {
    position: fixed;
    z-index: 9999;
    background: var(--surface);
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
    width: 250px;
    border: 1px solid var(--border);
    pointer-events: none;
}

/* ── Modal ────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    backdrop-filter: blur(6px);
}

.modal {
    background: var(--surface);
    width: 90%;
    max-width: 580px;
    max-height: 80vh;
    border-radius: 10px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 15px;
    font-weight: 600;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

.close-modal {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.15s;
}
.close-modal:hover { color: var(--text); }

/* ── Stats grid (modal) ───────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat-item {
    background: var(--bg);
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.stat-label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

h3 {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.10em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}

/* ── Mobile ───────────────────────────────────────────── */
@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
        overflow-y: auto;
    }

    .chart-container {
        height: 360px;
        flex-shrink: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar {
        height: auto;
        overflow: visible;
    }

    .arena-section {
        height: auto;
        flex: none;
        overflow: visible;
    }

    .agent-list {
        height: auto;
        overflow: visible;
        max-height: none;
    }

    .trade-log-container {
        height: auto;
        max-height: 320px;
    }
}

@media (max-width: 540px) {
    .ticker { display: none; }
    .header-sep { display: none; }
    .price { font-size: 13px; }
    #notification-container { left: 8px; }
    .notification-toast { width: 200px; }
}
