/* ─────────────────────────────────────────────────────
   Grid Live Trading — Dark Theme
   Aesthetic: Industrial terminal + crypto trading desk
   Font: JetBrains Mono (mono) + Sora (UI)
───────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@300;400;500;700&family=Sora:wght@300;400;500;600;700&display=swap');

/* ─── CSS Variables ───────────────────────────────── */
:root {
    --bg-primary:    #08080e;
    --bg-secondary:  #0e0e17;
    --bg-tertiary:   #15151f;
    --bg-card:       #111119;
    --bg-hover:      #1a1a26;
    --bg-active:     #1e1e2d;

    --accent:        #f0b90b;
    --accent-dim:    #a87d08;
    --accent-glow:   rgba(240, 185, 11, 0.15);
    --accent-subtle: rgba(240, 185, 11, 0.07);

    --text-primary:  #e2e2ec;
    --text-secondary:#7a7a9a;
    --text-dim:      #4a4a6a;

    --success:       #00d67a;
    --success-dim:   rgba(0, 214, 122, 0.12);
    --danger:        #ff3d5a;
    --danger-dim:    rgba(255, 61, 90, 0.12);
    --warning:       #ffab00;
    --warning-dim:   rgba(255, 171, 0, 0.12);

    --border:        #1e1e2e;
    --border-bright: #2e2e42;

    --sidebar-w: 200px;
    --header-h:  52px;

    --font-ui:   'Sora', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --shadow-card: 0 2px 16px rgba(0,0,0,0.4);
    --shadow-glow: 0 0 20px rgba(240, 185, 11, 0.08);
}

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

html { font-size: 14px; }

body {
    font-family: var(--font-ui);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; color: inherit; }

/* ─── Layout ──────────────────────────────────────── */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ─── Header ──────────────────────────────────────── */
.app-header {
    height: var(--header-h);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    flex-shrink: 0;
    z-index: 100;
}

.header-logo {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.12em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-logo::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--accent); }
    50% { opacity: 0.6; box-shadow: 0 0 3px var(--accent); }
}

.header-spacer { flex: 1; }

.header-meta {
    display: flex;
    align-items: center;
    gap: 20px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.meta-label {
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 10px;
}

.ping-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
    transition: background 0.3s, box-shadow 0.3s;
}

.ping-dot.ok           { background: var(--success); box-shadow: 0 0 6px var(--success); }
.ping-dot.high         { background: var(--warning); box-shadow: 0 0 6px var(--warning); }
.ping-dot.disconnected { background: var(--danger);  box-shadow: 0 0 6px var(--danger); }

.btn-logout {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 500;
    background: transparent;
    border: 1px solid var(--border-bright);
    color: var(--text-secondary);
    padding: 5px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: all 0.15s;
}

.btn-logout:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ─── Sidebar ─────────────────────────────────────── */
.app-sidebar {
    width: var(--sidebar-w);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    flex-shrink: 0;
    overflow-y: auto;
}

.nav-section { padding: 0 12px; }

.nav-label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 0 8px 8px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    font-size: 12.5px;
    font-weight: 400;
    color: var(--text-secondary);
    transition: all 0.15s;
    margin-bottom: 2px;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-link.active {
    background: var(--accent-subtle);
    color: var(--accent);
    font-weight: 500;
    border-left: 2px solid var(--accent);
    padding-left: 8px;
}

.nav-icon {
    font-size: 14px;
    width: 18px;
    text-align: center;
    color: inherit;
}

/* ─── Main Content ────────────────────────────────── */
.app-content {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-primary);
    padding: 20px;
}

/* ─── Page header ─────────────────────────────────── */
.page-header {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.02em;
}

.page-subtitle {
    font-size: 11px;
    color: var(--text-dim);
    font-family: var(--font-mono);
    margin-top: 2px;
}

/* ─── Instance Cards Grid ─────────────────────────── */
.instance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.instance-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.instance-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--accent-subtle) 0%, transparent 60%);
    opacity: 0;
    transition: opacity 0.2s;
}

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

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

.instance-card.selected {
    border-color: var(--accent-dim);
    box-shadow: var(--shadow-glow), 0 0 0 1px var(--accent-dim);
}

.instance-card.selected::before { opacity: 1; }

/* Card header */
.card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.inst-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    letter-spacing: 0.03em;
}

.inst-badge {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.1em;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
}

.inst-badge.usdm {
    background: rgba(0, 214, 122, 0.1);
    color: var(--success);
    border: 1px solid rgba(0, 214, 122, 0.25);
}

.inst-badge.coinm {
    background: rgba(240, 185, 11, 0.1);
    color: var(--accent);
    border: 1px solid rgba(240, 185, 11, 0.25);
}

/* Status dot */
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: all 0.3s;
}

.status-dot.running  { background: var(--success); box-shadow: 0 0 8px var(--success); animation: pulse-dot 2s infinite; }
.status-dot.stopped  { background: var(--text-dim); }
.status-dot.error    { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* Card price */
.card-price {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    letter-spacing: -0.02em;
}

/* Card stats */
.card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.stat label {
    display: block;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 2px;
}

.stat span {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
}

/* PnL */
.pnl-value.positive { color: var(--success) !important; }
.pnl-value.negative { color: var(--danger)  !important; }
.pnl-value.neutral  { color: var(--text-secondary) !important; }

/* Mode badge */
.card-mode {
    display: inline-flex;
    align-items: center;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.12em;
    padding: 2px 8px;
    border-radius: 3px;
    text-transform: uppercase;
}

.card-mode.demo {
    color: var(--warning);
    background: var(--warning-dim);
    border: 1px solid rgba(255,171,0,0.2);
}

.card-mode.live {
    color: var(--success);
    background: var(--success-dim);
    border: 1px solid rgba(0,214,122,0.2);
}

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    color: var(--text-dim);
    font-size: 12px;
}

.empty-state .empty-icon {
    font-size: 32px;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* ─── Detail Panel ────────────────────────────────── */
.detail-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 360px;
    display: flex;
    flex-direction: column;
}

.detail-panel-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 12px;
    flex-direction: column;
    gap: 8px;
}

.detail-panel-placeholder .placeholder-icon {
    font-size: 28px;
    opacity: 0.25;
}

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

.panel-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.04em;
}

.panel-subtitle {
    font-size: 10px;
    color: var(--text-dim);
    font-family: var(--font-mono);
}

/* Tab bar */
.tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.tab-btn {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    letter-spacing: 0.04em;
    font-family: var(--font-ui);
    transition: all 0.15s;
    white-space: nowrap;
}

.tab-btn:hover { color: var(--text-primary); }

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background: var(--accent-subtle);
}

.tab-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.tab-pane {
    display: none;
    flex: 1;
    overflow: auto;
}

.tab-pane.active { display: flex; flex-direction: column; }

/* ─── Stats Tab ──────────────────────────────────── */
.stats-container {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.stats-section {
    background: var(--bg-card, var(--bg-secondary));
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
}

.stats-section-title {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 12px;
}

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

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-item label {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-dim, var(--text-muted));
}

.stat-item span {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ─── Tables ──────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11.5px;
}

.data-table th {
    text-align: left;
    padding: 8px 12px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

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

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

.data-table tr:last-child td { border-bottom: none; }

/* Active zone highlight */
.row-active-zone td {
    background: rgba(240, 185, 11, 0.04);
}

.row-active-zone { border-left: 2px solid var(--accent); }

.row-active-zone td:first-child {
    color: var(--accent);
    font-weight: 700;
}

.empty-table-msg {
    padding: 32px;
    text-align: center;
    color: var(--text-dim);
    font-size: 11px;
    font-family: var(--font-mono);
}

/* Side badges */
.side-long  { color: var(--success); font-weight: 600; }
.side-short { color: var(--danger);  font-weight: 600; }

/* ─── Log Container ───────────────────────────────── */
.log-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.7;
    background: var(--bg-primary);
    min-height: 200px;
}

.log-line {
    display: flex;
    gap: 10px;
    padding: 1px 0;
    animation: log-in 0.15s ease;
}

@keyframes log-in {
    from { opacity: 0; transform: translateX(-4px); }
    to   { opacity: 1; transform: translateX(0); }
}

.log-time   { color: var(--text-dim); flex-shrink: 0; }
.log-level  { min-width: 52px; font-weight: 700; flex-shrink: 0; }
.log-msg    { color: var(--text-secondary); word-break: break-all; }

.log-line.info .log-level    { color: var(--text-dim); }
.log-line.warning .log-level { color: var(--warning); }
.log-line.error .log-level   { color: var(--danger); }
.log-line.error .log-msg     { color: rgba(255, 61, 90, 0.8); }

/* Log filter */
.log-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.log-filter-btn {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.08em;
    padding: 3px 8px;
    border-radius: 3px;
    border: 1px solid var(--border-bright);
    background: none;
    color: var(--text-dim);
    cursor: pointer;
    font-family: var(--font-ui);
    transition: all 0.15s;
}

.log-filter-btn.active,
.log-filter-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-bright);
}

.log-spacer { flex: 1; }

.log-clear-btn {
    font-size: 9px;
    padding: 3px 8px;
    background: none;
    border: 1px solid var(--border-bright);
    color: var(--text-dim);
    border-radius: 3px;
    cursor: pointer;
    font-family: var(--font-ui);
    transition: all 0.15s;
}

.log-clear-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* ─── Mono utility ────────────────────────────────── */
.mono { font-family: var(--font-mono); }

/* ─── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ─── Login Page ──────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(240,185,11,0.04) 0%, transparent 70%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 360px;
    position: relative;
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .logo-symbol {
    font-size: 28px;
    color: var(--accent);
    display: block;
    margin-bottom: 8px;
}

.login-logo .logo-title {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--text-primary);
}

.login-logo .logo-sub {
    font-size: 10px;
    color: var(--text-dim);
    letter-spacing: 0.06em;
    margin-top: 2px;
}

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
    transition: border-color 0.15s;
    outline: none;
}

.form-input:focus { border-color: var(--accent-dim); }
.form-input::placeholder { color: var(--text-dim); }

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: #000;
    border: none;
    padding: 11px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.06em;
    cursor: pointer;
    transition: background 0.15s;
    margin-top: 8px;
}

.btn-primary:hover { background: #ffc93a; }

.flash-msg {
    font-size: 11px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    background: var(--danger-dim);
    border: 1px solid rgba(255,61,90,0.25);
    color: var(--danger);
}

/* ─── History page ────────────────────────────────── */
.history-filters {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}

.filter-select, .filter-input {
    background: var(--bg-card);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 6px 10px;
    font-family: var(--font-ui);
    font-size: 12px;
    outline: none;
    transition: border-color 0.15s;
}

.filter-select:focus, .filter-input:focus {
    border-color: var(--accent-dim);
}

.btn-secondary {
    background: var(--bg-hover);
    border: 1px solid var(--border-bright);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-secondary:hover { border-color: var(--accent-dim); color: var(--accent); }

.btn-danger {
    background: var(--danger-dim);
    border: 1px solid rgba(255,61,90,0.3);
    color: var(--danger);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-danger:hover { background: rgba(255,61,90,0.2); }

/* ─── Instances page ──────────────────────────────── */
.instances-table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* ─── Misc ────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.1em;
    padding: 2px 7px;
    border-radius: 3px;
    text-transform: uppercase;
}

.badge-running  { background: var(--success-dim); color: var(--success); border: 1px solid rgba(0,214,122,0.25); }
.badge-stopped  { background: rgba(74,74,106,0.2); color: var(--text-dim); border: 1px solid var(--border-bright); }
.badge-error    { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(255,61,90,0.25); }
.badge-demo     { background: var(--warning-dim); color: var(--warning); border: 1px solid rgba(255,171,0,0.25); }
.badge-live     { background: var(--success-dim); color: var(--success); border: 1px solid rgba(0,214,122,0.25); }
.badge-usdm     { background: rgba(0,214,122,0.08); color: var(--success); border: 1px solid rgba(0,214,122,0.2); }
.badge-coinm    { background: var(--accent-subtle); color: var(--accent); border: 1px solid rgba(240,185,11,0.2); }

/* ─── Tooltip ─────────────────────────────────────── */
[data-tooltip] { position: relative; cursor: help; }

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-active);
    border: 1px solid var(--border-bright);
    color: var(--text-primary);
    font-size: 10px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 999;
    font-family: var(--font-mono);
}

[data-tooltip]:hover::after { opacity: 1; }

/* ─── Responsive tweaks ───────────────────────────── */
@media (max-width: 768px) {
    .app-sidebar { display: none; }
    .app-content { padding: 12px; }
    .instance-grid { grid-template-columns: 1fr; }
}
