/* ─── Design Tokens ──────────────────────────────────────────────────────── */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-card-hover: rgba(26, 34, 52, 0.9);
    --border: rgba(99, 102, 241, 0.15);
    --border-accent: rgba(99, 102, 241, 0.3);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --green: #22c55e;
    --green-glow: rgba(34, 197, 94, 0.2);
    --red: #ef4444;
    --red-glow: rgba(239, 68, 68, 0.2);
    --amber: #f59e0b;
    --amber-glow: rgba(245, 158, 11, 0.15);
    --cyan: #06b6d4;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(6, 182, 212, 0.05) 0%, transparent 50%);
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: rgba(10, 14, 23, 0.95);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left, .header-right { display: flex; align-items: center; gap: 16px; }

.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 24px; color: var(--accent); }
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.5px; }

.status-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    animation: none;
}
.status-running { background: var(--green-glow); color: var(--green); border: 1px solid rgba(34, 197, 94, 0.3); }
.status-running .status-dot { background: var(--green); animation: pulse 1.5s infinite; }
.status-stopped { background: var(--red-glow); color: var(--red); border: 1px solid rgba(239, 68, 68, 0.2); }
.status-stopped .status-dot { background: var(--red); }

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

.market-info { display: flex; flex-direction: column; gap: 2px; }
.market-info .label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.market-info .value { font-size: 12px; color: var(--text-secondary); }
.slug-link { text-decoration: none; cursor: pointer; }
.slug-link:hover { text-decoration: underline; color: var(--accent); }

.header-actions { display: flex; gap: 8px; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.5px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-start {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    box-shadow: 0 2px 12px var(--green-glow);
}
.btn-start:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 20px var(--green-glow); }
.btn-stop {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 2px 12px var(--red-glow);
}
.btn-stop:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 20px var(--red-glow); }

/* ─── Main Grid ──────────────────────────────────────────────────────────── */
#main-grid {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 1600px;
    margin: 0 auto;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    backdrop-filter: blur(12px);
    transition: all var(--transition);
}
.card:hover { border-color: var(--border-accent); }

.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.card-icon { font-size: 16px; }
.card-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

/* ─── Metrics Row ────────────────────────────────────────────────────────── */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.metric-value {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -1px;
    margin-bottom: 4px;
}

.metric-sub {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-secondary);
}
.metric-sub .label { color: var(--text-muted); }
.metric-sub .sep { color: var(--text-muted); }

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

.pnl-positive { color: var(--green); }
.pnl-negative { color: var(--red); }
.pnl-neutral { color: var(--text-secondary); }

/* Progress bar */
.progress-bar {
    height: 4px;
    background: rgba(255,255,255,0.05);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--cyan));
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* Signal card states */
.card-signal.signal-active {
    border-color: var(--green);
    box-shadow: 0 0 30px var(--green-glow);
}
.card-signal.signal-active .metric-value { color: var(--green); }

/* ─── Data Row ───────────────────────────────────────────────────────────── */
.data-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
}

/* Prices */
.price-grid {
    display: flex;
    align-items: center;
    gap: 16px;
}
.price-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(255,255,255,0.02);
}
.price-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.price-up .price-label { color: var(--green); }
.price-down .price-label { color: var(--red); }

.price-value {
    font-size: 32px;
    font-weight: 800;
    font-family: var(--font-mono);
    letter-spacing: -1px;
}
.price-up .price-value { color: var(--green); }
.price-down .price-value { color: var(--red); }

.price-token {
    font-size: 10px;
    color: var(--text-muted);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.price-bid-label {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0.7;
}

.price-total-badge {
    margin-left: auto;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.price-total-badge.total-ok {
    background: var(--green-glow);
    color: var(--green);
    border-color: rgba(34, 197, 94, 0.3);
}
.price-total-badge.total-high {
    background: var(--amber-glow);
    color: var(--amber);
    border-color: rgba(245, 158, 11, 0.3);
}
.price-total-badge.total-low {
    background: var(--red-glow);
    color: var(--red);
    border-color: rgba(239, 68, 68, 0.2);
}

.price-divider {
    width: 1px;
    height: 60px;
    background: var(--border);
}

/* Binance */
.binance-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.binance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.binance-item:last-child { border-bottom: none; }
.binance-item .label { font-size: 13px; color: var(--text-muted); }
.binance-item .value { font-size: 18px; font-weight: 700; }

.binance-gap .value { color: var(--amber); font-size: 22px; }
.binance-gap.gap-high .value { color: var(--green); }
.binance-gap.gap-low .value { color: var(--text-muted); }

/* Active Trade */
.trade-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    color: var(--text-muted);
    font-size: 14px;
}

.trade-active {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.trade-active .trade-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
}
.trade-active .trade-dir {
    font-size: 24px;
    font-weight: 800;
    text-align: center;
    padding: 8px;
    border-radius: var(--radius-sm);
}
.trade-dir.dir-up { color: var(--green); background: var(--green-glow); }
.trade-dir.dir-down { color: var(--red); background: var(--red-glow); }

/* ─── Bottom Row ─────────────────────────────────────────────────────────── */
.bottom-row {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 16px;
}

/* Table */
.table-container {
    max-height: 300px;
    overflow-y: auto;
}
.table-container::-webkit-scrollbar { width: 4px; }
.table-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#trades-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
#trades-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 10px;
    border-bottom: 1px solid var(--border);
}
#trades-table tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
}
#trades-table tbody tr:hover { background: rgba(255,255,255,0.02); }

.empty-row td { text-align: center; color: var(--text-muted); padding: 30px !important; }

.td-win { color: var(--green) !important; }
.td-loss { color: var(--red) !important; }
.td-up { color: var(--green) !important; font-weight: 600; }
.td-down { color: var(--red) !important; font-weight: 600; }

/* Logs */
.log-container {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.log-container::-webkit-scrollbar { width: 4px; }
.log-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.log-entry {
    display: flex;
    gap: 10px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-family: var(--font-mono);
    line-height: 1.5;
}
.log-ts { color: var(--text-muted); white-space: nowrap; min-width: 55px; }
.log-msg { color: var(--text-secondary); word-break: break-word; }

.log-info .log-msg { color: var(--text-secondary); }
.log-ok .log-msg { color: var(--green); }
.log-warn .log-msg { color: var(--amber); }
.log-err .log-msg { color: var(--red); }

.log-entry:nth-child(even) { background: rgba(255,255,255,0.01); }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
}
.modal.hidden { display: none; }
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius);
    padding: 24px 32px;
    min-width: 400px;
    box-shadow: var(--shadow);
}
.modal-content h2 {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--text-primary);
}
.config-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}
.config-form label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
}
.config-form input {
    width: 120px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
}
.config-form input:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .metrics-row { grid-template-columns: repeat(2, 1fr); }
    .data-row { grid-template-columns: 1fr; }
    .bottom-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .metrics-row { grid-template-columns: 1fr; }
    #header { flex-direction: column; gap: 12px; }
    .header-right { flex-direction: column; align-items: flex-start; gap: 8px; }
    #main-grid { padding: 12px; }
}

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
.card { animation: fadeIn 0.4s ease-out both; }
.card:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4) { animation-delay: 0.15s; }

@keyframes glow {
    0%, 100% { box-shadow: 0 0 20px var(--green-glow); }
    50% { box-shadow: 0 0 40px var(--green-glow), 0 0 60px rgba(34, 197, 94, 0.1); }
}
.card-signal.signal-active { animation: glow 2s ease-in-out infinite; }

/* Price flash animation */
.price-flash { animation: flash 0.3s ease; }
@keyframes flash {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}
