/* ============================================================
   CorePool AI — Trading Terminal (Light)
   Full rewrite · Professional light terminal design system
   ============================================================ */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-sunken: #f7f8fa;
    --border: #e3e6eb;
    --border-strong: #d3d7de;
    --text-primary: #16181d;
    --text-secondary: #4b5563;
    --text-muted: #9aa2af;

    --accent: #2f54eb;
    --accent-soft: rgba(47, 84, 235, 0.07);
    --up: #0f9960;
    --down: #d64541;
    --warn: #d97706;

    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --radius: 10px;
    --radius-sm: 6px;
    --space-lg: 20px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccd2db; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #b4bcc8; }

.num, .symbol-price, .symbol-change, .kpi-value,
.grid-table td:not(:first-child), .trades-table td {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
}

.positive, .pos { color: var(--up) !important; }
.negative, .neg { color: var(--down) !important; }
.neutral { color: var(--text-secondary) !important; }
.bullish { color: var(--up); }

/* ============ COMMAND BAR ============ */
.cmd-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.cmd-bar-inner {
    max-width: 1560px;
    margin: 0 auto;
    padding: 0 24px;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.brand-logo { height: 30px; width: auto; display: block; }

.brand-tag {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.18em;
    color: var(--accent);
    border: 1px solid rgba(47, 84, 235, 0.25);
    border-radius: 4px;
    padding: 2px 7px;
    background: var(--accent-soft);
}

.cmd-status {
    display: flex;
    align-items: center;
    gap: 12px;
}

.feed-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: default;
}
.feed-dot i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: block;
}
.feed-dot.ok i { background: var(--up); box-shadow: 0 0 0 3px rgba(15, 153, 96, 0.15); }
.feed-dot.degraded i { background: var(--warn); box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15); }
.feed-dot.err i, .feed-dot.unhealthy i { background: var(--down); box-shadow: 0 0 0 3px rgba(214, 69, 65, 0.15); }

.price-health-dot { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; }
.health-dot-inner { width: 8px; height: 8px; border-radius: 50%; display: block; }
.price-health-dot.healthy .health-dot-inner { background: var(--up); box-shadow: 0 0 0 3px rgba(15, 153, 96, 0.15); }

.ghost-btn {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12.5px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.lang-select {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 6px 26px 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234b5563' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
}
.lang-select:hover { border-color: var(--accent); }

.filter-select {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 12px;
    padding: 5px 26px 5px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234b5563' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
}

/* ============ MARKET TAPE ============ */
.tape {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.tape::-webkit-scrollbar { display: none; }

.tape-track {
    max-width: 1560px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: stretch;
    gap: 0;
    min-width: min-content;
}

.symbol-price-item.tape-cell, .symbol-price-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 18px;
    border-right: 1px solid var(--border);
    white-space: nowrap;
    cursor: default;
    transition: background 0.15s;
}
.symbol-price-item:first-child { padding-left: 0; }
.symbol-price-item:last-child { border-right: none; }
.symbol-price-item:hover { background: var(--accent-soft); }

.coin-icon { flex-shrink: 0; }

.symbol-name {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.symbol-price { font-size: 12.5px; font-weight: 600; color: var(--text-primary); }

.symbol-change { font-size: 11.5px; font-weight: 500; }
.symbol-change.up, .symbol-change.positive { color: var(--up); }
.symbol-change.down, .symbol-change.negative { color: var(--down); }

/* ============ KPI DECK (side rail) ============ */
.app-shell {
    flex: 1;
    display: flex;
    min-height: 0;
}

.side-rail {
    width: 236px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 14px 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: width 0.2s ease, opacity 0.15s;
}
body.rail-collapsed .side-rail {
    width: 0;
    padding-left: 0;
    padding-right: 0;
    border-right: none;
    overflow: hidden;
    opacity: 0;
}

.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 6px 9px; }

.side-caption {
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.18em;
    color: var(--text-muted);
    margin-top: 10px;
}
.side-caption:first-child { margin-top: 0; }

.kpi-deck {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kpi-tile {
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.kpi-tile.kpi-accent {
    border-color: rgba(47, 84, 235, 0.3);
    background: linear-gradient(180deg, var(--accent-soft), var(--surface-sunken) 70%);
}

.kpi-label {
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
}

.kpi-value {
    font-size: 15.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-teams-v {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.team-performance-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 110px;
    flex-shrink: 0;
}

.team-performance-card .team-name {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.team-pnl { font-family: var(--mono); font-size: 13px; font-weight: 600; white-space: nowrap; }
.team-pct { font-family: var(--mono); font-size: 11px; color: var(--text-muted); white-space: nowrap; }

/* ============ FLOW RAIL (Agent Pipeline, vertical in side rail) ============ */
.flow-rail {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rail-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.rail-group-name {
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.16em;
    color: var(--text-muted);
}

.rail-chips { display: flex; gap: 6px; }

.rail-sep {
    width: 1px;
    height: 18px;
    background: var(--border-strong);
    flex-shrink: 0;
}

.pipeline-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 99px;
    padding: 4px 11px 4px 8px;
    transition: all 0.2s;
}

.dot-indicator {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #cbd2dc;
    flex-shrink: 0;
    transition: all 0.2s;
}

.dot-text {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
}

/* pipeline states (set by app.js) */
.pipeline-dot.running .dot-indicator,
.dot-running .dot-indicator {
    background: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 84, 235, 0.15);
    animation: pulse 1.4s ease-in-out infinite;
}
.pipeline-dot.completed .dot-indicator,
.dot-completed .dot-indicator {
    background: var(--up);
    box-shadow: 0 0 0 3px rgba(15, 153, 96, 0.12);
}
.pipeline-dot.error .dot-indicator, .pipeline-dot.failed .dot-indicator {
    background: var(--down);
    box-shadow: 0 0 0 3px rgba(214, 69, 65, 0.12);
}
.pipeline-dot.active .dot-indicator { background: var(--accent); box-shadow: 0 0 0 3px rgba(47,84,235,.15); }

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

.agent-status-group { display: inline-flex; align-items: center; gap: 6px; }
.agent-status-sep { width: 1px; height: 16px; background: var(--border); }
.agent-badge {
    font-family: var(--mono);
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-radius: 4px;
    padding: 1.5px 6px;
}
.agent-badge.idle { background: var(--surface-sunken); color: var(--text-muted); }
.agent-badge.running, .agent-badge.success { background: rgba(15, 153, 96, 0.1); color: var(--up); }
.agent-badge.error { background: rgba(214, 69, 65, 0.1); color: var(--down); }

/* ============ MAIN TERMINAL GRID (one screen) ============ */
.main-area {
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr) clamp(300px, 24vw, 380px);
    grid-template-rows: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-areas:
        "chart trades chat"
        "data  trades chat";
    gap: 12px;
    padding: 12px;
}

.workspace { display: contents; }

.stage-chart   { grid-area: chart;  min-height: 0; }
.stage-data    { grid-area: data;   min-height: 0; }
.dock-chatroom { grid-area: chat;   display: flex; flex-direction: column; }
.exec-log      { grid-area: trades; margin: 0; min-height: 0; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    flex-wrap: wrap;
}

.panel-heading {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.panel-heading h2 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--text-primary);
    white-space: nowrap;
}

.panel-glyph {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
}
.glyph-indigo { background: var(--accent); }
.glyph-cyan { background: #0891b2; }
.glyph-amber { background: var(--warn); }
.glyph-green { background: var(--up); }
.glyph-red { background: var(--down); }

/* Timeframe selector */
.timeframe-selector.tf-rail {
    display: inline-flex;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.tf-btn, .tf-tab {
    appearance: none;
    border: none;
    background: transparent;
    font-family: var(--mono);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 4px 11px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.tf-btn:hover, .tf-tab:hover { color: var(--text-primary); }
.tf-btn.active, .tf-tab.active {
    background: var(--text-primary);
    color: #fff;
}

/* Chart */
.chart-container {
    position: relative;
    flex: 1;
    padding: 12px 16px;
    min-height: 0;
}
.chart-container canvas { max-height: 100%; }

.empty-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    background: var(--surface);
}
.empty-overlay p { margin: 0; font-size: 13px; }

/* ============ CHATROOM DOCK ============ */
.chatroom-tabs {
    display: flex;
    gap: 6px;
    padding: 10px 14px 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.chatroom-tabs::-webkit-scrollbar { display: none; }

.chatroom-tab {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-sunken);
    border-radius: var(--radius-sm);
    padding: 5px 13px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.chatroom-tab:hover { border-color: var(--accent); color: var(--accent); }
.chatroom-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.chatroom-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.chatroom-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 14px 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 260px;
    max-height: 720px;
    position: relative;
}

/* discussion timeline rail */
.chatroom-messages::before {
    content: '';
    position: absolute;
    left: 26px;
    top: 18px;
    bottom: 18px;
    width: 2px;
    background: linear-gradient(180deg, var(--border), transparent);
}

.chatroom-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-muted);
    min-height: 200px;
}
.chatroom-empty p { margin: 0; font-size: 13px; }

.chat-bubble {
    position: relative;
    flex-shrink: 0; /* never compress cards inside fixed-height flex container */
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr);
    grid-template-areas:
        "av   head"
        "av   body";
    grid-column-gap: 10px;
    align-items: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    transition: background 0.15s, border-color 0.15s;
}
.chat-bubble:hover { background: #f6f8fc; border-color: var(--border-strong); }

.chat-avatar {
    grid-area: av;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--av-bg, var(--accent));
    color: #fff;
    font-family: var(--mono);
    font-size: 9.5px;
    font-weight: 700;
    letter-spacing: 0.04em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--border);
}

.chat-header {
    grid-area: head;
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.chat-agent-name {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.chat-timestamp {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-muted);
}

.chat-content {
    grid-area: body;
    font-size: 12.5px;
    line-height: 1.62;
    color: var(--text-primary);
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

/* readable structure inside messages */
.chat-content b, .chat-content strong {
    color: var(--text-primary);
    font-weight: 700;
}
.chat-bubble.is-verdict .chat-content b,
.chat-bubble.is-verdict .chat-content strong { color: #92400e; }
.chat-content ul, .chat-content ol {
    margin: 6px 0;
    padding-left: 18px;
}
.chat-content li { margin: 3px 0; }
.chat-content br + br { display: none; }
.chat-content code {
    font-family: var(--mono);
    font-size: 11.5px;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
}

/* debate stances */
.chat-bubble.is-bull { background: rgba(22, 163, 74, 0.05); border-color: rgba(22, 163, 74, 0.25); }
.chat-bubble.is-bull .chat-agent-name { color: #15803d; }
.chat-bubble.is-bear { background: rgba(220, 38, 38, 0.04); border-color: rgba(220, 38, 38, 0.22); }
.chat-bubble.is-bear .chat-agent-name { color: #b91c1c; }
.chat-bubble.is-risk { background: rgba(185, 28, 28, 0.05); border-color: rgba(185, 28, 28, 0.3); }
.chat-bubble.is-risk .chat-agent-name::after {
    content: '⚠';
    margin-left: 5px;
    font-size: 10px;
}

/* final verdict card */
.chat-bubble.is-verdict {
    background: linear-gradient(135deg, rgba(217, 119, 6, 0.08), rgba(47, 84, 235, 0.05));
    border: 1px solid rgba(217, 119, 6, 0.4);
    box-shadow: 0 2px 10px rgba(217, 119, 6, 0.08);
}
.chat-bubble.is-verdict .chat-agent-name { color: #b45309; }

/* ============ HIGH-TECH MESSAGE EFFECTS ============ */
/* newest message: entrance + light sweep + avatar glow */
.chat-bubble.is-latest {
    animation: bubbleIn 0.5s cubic-bezier(0.22, 0.9, 0.34, 1) both;
}
.chat-bubble.is-latest::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(105deg, transparent 42%, rgba(255, 255, 255, 0.45) 50%, transparent 58%);
    background-size: 220% 100%;
    animation: sweep 1.6s ease 0.2s 2 both;
}
.chat-bubble.is-latest .chat-avatar { animation: avPulse 2.2s ease-in-out infinite; }

@keyframes bubbleIn {
    from { opacity: 0; transform: translateY(14px) scale(0.98); filter: blur(3px); }
    to   { opacity: 1; transform: none; filter: none; }
}
@keyframes sweep {
    from { background-position: 130% 0; }
    to   { background-position: -130% 0; }
}
@keyframes avPulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--border); }
    50%      { box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--av-bg, var(--accent)), 0 0 14px 2px var(--av-bg, var(--accent)); }
}

/* verdict card: persistent subtle amber breathing glow */
.chat-bubble.is-verdict:not(.is-latest) {
    animation: verdictGlow 3.4s ease-in-out infinite;
}
.chat-bubble.is-latest.is-verdict {
    animation:
        bubbleIn 0.5s cubic-bezier(0.22, 0.9, 0.34, 1) both,
        verdictGlow 3.4s ease-in-out 0.6s infinite;
}
@keyframes verdictGlow {
    0%, 100% { box-shadow: 0 2px 10px rgba(217, 119, 6, 0.10); }
    50%      { box-shadow: 0 4px 24px rgba(217, 119, 6, 0.28); }
}

@media (prefers-reduced-motion: reduce) {
    .chat-bubble.is-latest,
    .chat-bubble.is-latest::after,
    .chat-bubble.is-latest .chat-avatar,
    .chat-bubble.is-verdict,
    .chat-bubble.is-verdict:not(.is-latest) { animation: none !important; }
}
.verdict-badge {
    margin-left: auto;
    font-family: var(--mono);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #fff;
    background: var(--warn);
    border-radius: 99px;
    padding: 2px 9px;
    white-space: nowrap;
}

/* Agent identity now carried by chat-avatar color (see AGENT_META in viz.js) */

.final-action {
    display: inline-block;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    border-radius: 4px;
    padding: 2px 8px;
    background: var(--text-primary);
    color: #fff;
}
.final-action.long, .final-action.buy { background: var(--up); }
.final-action.short, .final-action.sell { background: var(--down); }

/* ============ DATA WORKBENCH ============ */
.workbench-tabs {
    display: flex;
    gap: 2px;
    align-items: center;
}

.tab-btn {
    appearance: none;
    border: none;
    background: transparent;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: all 0.15s;
}
.tab-btn:hover { color: var(--text-primary); background: var(--surface-sunken); }
.tab-btn.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.badge {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    background: var(--accent);
    color: #fff;
    border-radius: 99px;
    padding: 1px 6px;
}

.panel-filters { display: flex; gap: 8px; }

.panel-body { flex: 1; min-height: 0; padding: 0; }

.tab-content { padding: 0; }
.tab-content[style*="none"] { display: none !important; }

.positions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
    padding: 14px;
}

.position-item {
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    transition: all 0.15s;
}
.position-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.position-item.long { border-left: 3px solid var(--up); }
.position-item.short { border-left: 3px solid var(--down); }

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

.position-symbol { font-family: var(--mono); font-size: 13px; font-weight: 600; }

.position-detail {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    padding: 2px 0;
}
.position-details { font-size: 12px; color: var(--text-secondary); }

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 13px;
    width: 100%;
}
.empty-state-icon { opacity: 0.4; }

/* Terminal data grids */
.table-scroll {
    overflow: auto;
    max-height: 340px;
}

.grid-table, .data-table, .trades-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.grid-table th, .data-table th, .trades-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-sunken);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
}

.grid-table td, .data-table td, .trades-table td {
    padding: 7px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
}

.grid-table tbody tr:nth-child(even), .data-table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.014);
}
.grid-table tbody tr:hover, .data-table tbody tr:hover, .trades-table tbody tr:hover {
    background: var(--accent-soft);
}

.text-right { text-align: right !important; }
.text-center { text-align: center !important; }
.empty-cell { text-align: center; color: var(--text-muted); padding: 24px !important; }
.cell-na { color: var(--text-muted); }

.decision-action {
    display: inline-block;
    font-family: var(--mono);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    border-radius: 4px;
    padding: 2px 7px;
}
.decision-action.long, .decision-action.buy, .decision-action.open_long { background: rgba(15, 153, 96, 0.1); color: var(--up); }
.decision-action.short, .decision-action.sell, .decision-action.open_short { background: rgba(214, 69, 65, 0.1); color: var(--down); }
.decision-action.wait, .decision-action.hold, .decision-action.close { background: var(--surface-sunken); color: var(--text-muted); }

.decision-conf { font-family: var(--mono); font-weight: 500; }

.table-summary {
    padding: 8px 14px;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    background: var(--surface-sunken);
}
.table-summary:empty { display: none; }

/* ============ EXECUTION LOG (Trade History) ============ */
.exec-log {
    padding: 0;
}

.exec-log .panel-body { padding-bottom: 6px; }

.side-long, .side-buy { color: var(--up) !important; font-weight: 600; }
.side-short, .side-sell { color: var(--down) !important; font-weight: 600; }

/* ============ PILLS ============ */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-radius: 99px;
    padding: 3px 11px;
}
.pill-mode.online { background: rgba(15, 153, 96, 0.1); color: var(--up); }
.pill-mode.offline { background: var(--surface-sunken); color: var(--text-muted); }
.pill-mode.warning { background: rgba(217, 119, 6, 0.1); color: var(--warn); }
.pill-env.online { background: rgba(47, 84, 235, 0.08); color: var(--accent); }
.pill-env.warning { background: rgba(217, 119, 6, 0.1); color: var(--warn); }
.pill-env.live { background: rgba(214, 69, 65, 0.1); color: var(--down); }

/* ============ MODALS ============ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(22, 24, 29, 0.35);
    backdrop-filter: blur(3px);
}

.modal-container {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 100%;
    max-width: 960px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(22, 24, 29, 0.18);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: 15px; font-weight: 600; }

.modal-close {
    appearance: none;
    border: none;
    background: var(--surface-sunken);
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text-primary); }

.modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 22px;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    background: var(--surface-sunken);
    border-radius: 0 0 14px 14px;
    flex-shrink: 0;
}

/* Settings tabs rail */
.settings-body { display: flex; flex-direction: column; gap: 16px; }

.settings-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
}
.settings-tabs::-webkit-scrollbar { display: none; }

.settings-tab {
    appearance: none;
    border: none;
    background: transparent;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 9px 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    transition: all 0.15s;
}
.settings-tab svg { opacity: 0.75; }
.settings-tab:hover { color: var(--text-primary); }
.settings-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.settings-content { display: none; }
.settings-content.active { display: block; }

.bottom-tab-content { padding: 14px; }

.settings-section { margin-bottom: 22px; }
.settings-section:last-child { margin-bottom: 0; }

.section-title {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 14px;
}

.control-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 16px;
    background: var(--surface);
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 11px 0;
}
.control-row + .control-row { border-top: 1px solid var(--border); }

.control-label { font-size: 13px; font-weight: 500; color: var(--text-primary); }

.toggle-group {
    display: inline-flex;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.toggle-btn {
    appearance: none;
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 5px 16px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s;
}
.toggle-btn.active { background: var(--text-primary); color: #fff; font-weight: 600; }

.button-group { display: inline-flex; gap: 8px; flex-wrap: wrap; }

.btn-action {
    appearance: none;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s;
}
.btn-action:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-start { background: var(--up); color: #fff; }
.btn-start:hover:not(:disabled) { background: #0c7f4f; }
.btn-pause { background: var(--warn); color: #fff; }
.btn-pause:hover:not(:disabled) { background: #b8620a; }
.btn-stop { background: var(--down); color: #fff; }
.btn-stop:hover:not(:disabled) { background: #b93a36; }

.btn-primary {
    appearance: none;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 20px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.15s;
}
.btn-primary:hover { background: #2450d4; }

.btn-secondary {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 5px 13px; font-size: 12px; }

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.status-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.status-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.status-value { font-family: var(--mono); font-size: 14px; font-weight: 600; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group > label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input, .form-select, .form-control {
    width: 100%;
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--sans);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%234b5563' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
    cursor: pointer;
}
.form-input:focus, .form-select:focus, .form-control:focus, input[data-field]:focus, textarea[data-field]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(47, 84, 235, 0.12);
}

input[data-field], select[data-field], textarea[data-field], .strategy-input {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-primary);
    font-family: var(--mono);
    font-size: 12.5px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    outline: none;
}

.form-control-sm { padding: 4px 8px; font-size: 12px; width: auto; }

.form-hint { margin: 6px 0 0; font-size: 11.5px; color: var(--text-muted); }

.loading-text { color: var(--text-muted); font-size: 12.5px; padding: 12px 0; }

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* LLM info bar */
.llm-info-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 22px;
    background: var(--accent-soft);
    border: 1px solid rgba(47, 84, 235, 0.2);
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    margin-bottom: 16px;
}
.llm-info-item { display: flex; align-items: baseline; gap: 8px; }
.llm-info-label { font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.llm-info-value { font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--text-primary); }
.llm-badge {
    display: inline-flex;
    background: var(--accent);
    color: #fff;
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    padding: 2px 9px;
}

/* Agent config */
.agent-config-wrapper { display: flex; flex-direction: column; gap: 12px; }
.agent-config-tabs { display: flex; flex-wrap: wrap; gap: 6px; }

.agent-tab-label {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-sunken);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    padding: 5px 13px;
    border-radius: 99px;
    cursor: pointer;
    transition: all 0.15s;
}
.agent-tab-label.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.agent-config-panel { min-height: 120px; }

.agent-config-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 10px;
    background: var(--surface);
}

.agent-config-section-title, .strategy-section-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.agent-config-desc { font-size: 12px; color: var(--text-secondary); margin: 4px 0 8px; }

.agent-config-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.agent-config-count { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

.agent-config-row-prompt textarea, textarea.strategy-input {
    width: 100%;
    min-height: 64px;
    resize: vertical;
    font-family: var(--sans);
    font-size: 12.5px;
}

.agent-config-param-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.agent-config-param-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}
.agent-config-param-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.agent-config-param-name { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); }
.agent-config-param-value { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.agent-config-param-controls { display: flex; align-items: center; gap: 8px; }
.agent-config-param-inline { display: flex; align-items: center; gap: 8px; }
.agent-config-param-empty { font-size: 12px; color: var(--text-muted); font-style: italic; }

.agent-box {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: var(--surface-sunken);
    margin-bottom: 8px;
}

.strategy-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.strategy-label { font-size: 12.5px; color: var(--text-secondary); }
.strategy-default { font-size: 11px; color: var(--text-muted); font-style: italic; }
.strategy-reset-btn {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 11px;
    border-radius: 4px;
    padding: 2px 8px;
    cursor: pointer;
}
.strategy-reset-btn:hover { color: var(--accent); border-color: var(--accent); }
.strategy-section { margin-bottom: 16px; }
.strategy-weights-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.strategy-weights-sum { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); padding-top: 8px; }

.agent-config-footer { display: flex; justify-content: flex-end; padding-top: 12px; border-top: 1px solid var(--border); }

/* Teams settings */
.teams-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.teams-header h4 { margin: 0; font-size: 13.5px; font-weight: 600; }

.team-card, .account-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 10px;
    background: var(--surface);
}

.team-card-header, .team-card-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.team-card-name { font-size: 13px; font-weight: 600; }
.team-card-status { font-size: 11px; color: var(--text-muted); }
.team-card-stats, .team-card-values { display: flex; gap: 18px; margin-top: 8px; flex-wrap: wrap; }
.team-stat { display: flex; flex-direction: column; gap: 2px; }
.team-stat-label { font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.team-stat-value { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }

.teams-summary { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); padding-top: 10px; }

.demo-team-row {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Backtest */
.live-status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.stopped { background: #cbd2dc; }
.status-dot.running { background: var(--up); box-shadow: 0 0 0 3px rgba(15, 153, 96, 0.15); animation: pulse 1.4s ease-in-out infinite; }

.backtest-tabs {
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    margin-bottom: 14px;
    overflow-x: auto;
}

.backtest-tab {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-sunken);
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 6px 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}
.backtest-tab:hover { border-color: var(--accent); }
.backtest-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab-icon .icon, .icon { width: 13px; height: 13px; vertical-align: -2px; }

.add-tab-btn {
    appearance: none;
    border: 1px dashed var(--border-strong);
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-muted);
    padding: 6px 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.add-tab-btn:hover { color: var(--accent); border-color: var(--accent); }

.tab-status { font-size: 10px; font-family: var(--mono); color: var(--text-muted); }
.tab-indicator { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.tab-close {
    appearance: none;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 13px;
    padding: 0 2px;
}

.backtest-form { display: flex; flex-direction: column; gap: 16px; }

.form-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

.quick-select-btns { display: flex; gap: 8px; }

.quick-btn {
    appearance: none;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 500;
    padding: 4px 12px;
    border-radius: 99px;
    cursor: pointer;
    transition: all 0.15s;
}
.quick-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.symbol-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-family: var(--mono);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 9px;
    cursor: pointer;
}
.symbol-checkbox.major { border-left: 3px solid var(--accent); }
.symbol-checkbox.ai500 { border-left: 3px solid #8b5cf6; }
.symbol-checkbox.alts { border-left: 3px solid #0d9488; }

.backtest-config-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.backtest-config-field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.progress-section {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    background: var(--surface-sunken);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.progress-bar-container {
    height: 6px;
    background: var(--border);
    border-radius: 99px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 99px;
    transition: width 0.3s ease;
}

.progress-text { font-size: 12.5px; color: var(--text-secondary); }

.realtime-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}
.metric-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.metric-row .metric-label { font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }
.metric-row .metric-value, .metric-item .metric-value { font-family: var(--mono); font-size: 13.5px; font-weight: 600; }

.metric-item { display: flex; flex-direction: column; gap: 2px; padding: 6px 0; }
.metric-item .metric-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }

.live-chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
}
.live-chart-container h4 { margin: 0 0 10px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.live-trades-container { max-height: 300px; overflow: auto; }

.results-section { display: flex; flex-direction: column; gap: 16px; }
.result-header h2 { font-size: 16px; font-weight: 700; }

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
}

.metric-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    background: var(--surface);
}
.metric-card h3 { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); }

.chart-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    background: var(--surface);
}
.chart-card h3 { margin: 0 0 10px; font-size: 12.5px; font-weight: 600; }
.chart-wrapper { position: relative; height: 260px; }

.trades-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}
.trades-card h3 {
    margin: 0;
    padding: 12px 16px;
    font-size: 12.5px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}
.trades-table tbody { display: block; max-height: 300px; overflow-y: auto; }
.trades-table thead, .trades-table tbody tr { display: table; width: 100%; table-layout: fixed; }

.history-section { border-top: 1px solid var(--border); padding-top: 14px; }
.history-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.history-list { display: flex; flex-direction: column; gap: 8px; }

.history-main-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.history-info { font-size: 12.5px; }
.history-stats { display: flex; gap: 16px; font-family: var(--mono); font-size: 11.5px; color: var(--text-secondary); }
.history-stat { display: inline-flex; gap: 5px; }
.history-detail-row { padding-top: 6px; font-size: 11.5px; color: var(--text-muted); }
.run-time { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

.icon-success { color: var(--up); }
.icon-danger { color: var(--down); }
.icon-warning { color: var(--warn); }

/* Login / misc */
.login-error {
    background: rgba(214, 69, 65, 0.08);
    border: 1px solid rgba(214, 69, 65, 0.25);
    color: var(--down);
    font-size: 12.5px;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-top: 10px;
}

.toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: var(--text-primary);
    color: #fff;
    font-size: 13px;
    padding: 10px 22px;
    border-radius: 99px;
    box-shadow: 0 8px 28px rgba(22, 24, 29, 0.25);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
}
.toast.visible, .toast[style*="block"] { opacity: 1; transform: translateX(-50%) translateY(0); }

.period { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.log-time { font-family: var(--mono); font-size: 11px; color: var(--text-muted); }

.paused { opacity: 0.55; }
.settings-tab-content { padding: 4px 0; }
.tab-label, .tab-name { white-space: nowrap; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.hidden { display: none !important; }

#logs-container { font-family: var(--mono); font-size: 12px; }

/* ============ SINGLE-AI MODE ============ */
/* One main AI playing multiple debate roles: no team tabs, no Teams panel */
.chatroom-tabs { display: none !important; }
#data-tabs [data-tab="teams"] { display: none !important; }
#tab-teams:not(.settings-content) { display: none !important; }
.side-hidden { display: none !important; }

/* safety: never clip message cards */
.chat-bubble, .chat-content, .chatroom-messages .chat-bubble * { min-height: 0; }
.chat-content { max-height: none; }

/* ============ VIZ LAYER (chart-first panels) ============ */
.viz-cards {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 12px;
    padding: 14px;
}

.viz-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

.viz-title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.viz-box { position: relative; height: 200px; }
.viz-box.viz-sm { height: 170px; }
.viz-card.viz-grow { grid-column: span 1; }

.raw-toggle {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 6px 16px;
    cursor: pointer;
    text-align: left;
    transition: color 0.15s;
}
.raw-toggle:hover { color: var(--accent); }

/* narrow trades column: stack viz cards vertically */
.exec-log .viz-cards { grid-template-columns: 1fr; }
.exec-log .viz-box { height: 150px; }
.exec-log .viz-box.viz-sm { height: 130px; }

.raw-wrap[hidden] { display: none; }
.raw-wrap .table-scroll { max-height: 320px; }

@media (max-width: 900px) {
    .viz-cards { grid-template-columns: 1fr; }
}

/* ============ RESPONSIVE ============ */
.side-backdrop { display: none; }

/* Tablet & below: side rail becomes an off-canvas drawer, main stacks */
@media (max-width: 1180px) {
    body { height: auto; min-height: 100vh; overflow: auto; }
    .app-shell { display: block; position: relative; }

    .side-rail {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(320px, 86vw);
        z-index: 400;
        transform: translateX(-105%);
        transition: transform 0.25s ease;
        box-shadow: 8px 0 32px rgba(22, 24, 29, 0.16);
        opacity: 1;
        border-right: 1px solid var(--border);
    }
    body.rail-open .side-rail { transform: translateX(0); }
    /* desktop collapse state must not fight the drawer on small screens */
    body.rail-collapsed .side-rail {
        width: min(320px, 86vw);
        padding: 14px 14px 20px;
        overflow-y: auto;
        opacity: 1;
        border-right: 1px solid var(--border);
    }

    .side-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(22, 24, 29, 0.42);
        z-index: 390;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }
    body.rail-open .side-backdrop { opacity: 1; pointer-events: auto; }

    .main-area {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        grid-template-areas:
            "chart"
            "chat"
            "data"
            "trades";
        padding: 12px;
    }
    .stage-chart { min-height: 340px; }
    .dock-chatroom { min-height: 460px; }
    .stage-data { min-height: 380px; }
    .exec-log { min-height: 320px; }
}
@media (max-width: 720px) {
    .cmd-bar-inner { height: 48px; padding: 0 12px; gap: 8px; }
    .brand-logo { height: 24px; }
    .brand-tag { display: none; }
    .ghost-btn, .lang-select { font-size: 11.5px; padding: 7px 9px; }
    .icon-btn { padding: 7px 8px; }
    .feed-dot { width: 18px; height: 18px; }
    .feed-dot i { width: 7px; height: 7px; }

    .tape-track { padding: 0 12px; }
    .symbol-price-item.tape-cell { padding: 7px 13px; }

    .main-area { padding: 10px; gap: 10px; }
    .panel-head { padding: 10px 13px; }
    .workbench-tabs { flex-wrap: wrap; }
    .tab-btn { padding: 8px 11px; font-size: 12px; }

    .viz-cards { grid-template-columns: 1fr; gap: 10px; padding: 12px; }
    .viz-box { height: 190px; }
    .viz-box.viz-sm { height: 165px; }

    .chatroom-messages { max-height: none; min-height: 0; }
    /* phone: fixed-height chat window ≈ 8 bubbles, internal auto-scroll */
    .dock-chatroom { min-height: 0; height: 540px; max-height: 72vh; }
    .chat-bubble { grid-template-columns: 24px minmax(0, 1fr); padding: 9px 10px; }
    .chat-avatar { width: 24px; height: 24px; font-size: 9px; }
    .chat-content { font-size: 12px; line-height: 1.6; }

    /* modals become full-screen sheets */
    .modal { padding: 0; }
    .modal-container {
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }
    .modal-header { position: sticky; top: 0; background: var(--surface); z-index: 3; }
    .modal-footer {
        position: sticky;
        bottom: 0;
        border-radius: 0;
    }
    .settings-tabs {
        position: sticky;
        top: 53px;
        background: var(--surface);
        z-index: 2;
    }

    .form-grid { grid-template-columns: 1fr; }
    .backtest-config-row { grid-template-columns: 1fr 1fr; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .positions-grid { grid-template-columns: 1fr; }
    .status-grid { grid-template-columns: 1fr 1fr; }
}
