:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-input: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-sidebar: #cbd5e1;
    --text-sidebar-active: #ffffff;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
    --sidebar-width: 220px;
    --header-height: 56px;
}

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

body {
    font-family: var(--font-family);
    background: var(--bg-page);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    z-index: 100;
    display: flex; flex-direction: column;
    overflow-y: auto;
}
.sidebar-brand {
    padding: 20px 20px 16px;
    font-size: 18px; font-weight: 700;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .logo { width: 32px; height: 32px; background: var(--primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 20px;
    color: var(--text-sidebar);
    text-decoration: none;
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active { background: rgba(79,70,229,0.2); color: #fff; border-left-color: var(--primary); }
.sidebar-nav a .icon { width: 20px; text-align: center; font-size: 16px; }
.sidebar-divider { margin: 8px 20px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-user {
    padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08);
    display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.sidebar-user .avatar { width: 32px; height: 32px; background: var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 14px; }

/* Main content */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}
.header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 50;
}
.header h1 { font-size: 18px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.content { padding: 24px; }

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}
.card-header { font-size: 15px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; color: var(--text-primary); }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px;
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; }
.stat-card .stat-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th {
    background: var(--bg-input); padding: 10px 14px;
    text-align: left; font-size: 12px; font-weight: 600;
    color: var(--text-secondary); text-transform: uppercase;
    letter-spacing: 0.5px;
}
table td { padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
table tr:hover td { background: var(--primary-light); }

/* Badges */
.badge { display: inline-block; padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-neutral { background: #f1f5f9; color: #475569; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; cursor: pointer;
    border: none; transition: all 0.15s; text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-primary); }
.btn-outline:hover { background: var(--bg-input); }
.btn-lg { padding: 12px 24px; font-size: 15px; border-radius: var(--radius-md); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-primary); }
.form-input {
    width: 100%; padding: 10px 14px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--bg-input);
    font-size: 14px; font-family: var(--font-family);
    color: var(--text-primary); outline: none; transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background: #cbd5e1; border-radius: 24px; transition: 0.2s; }
.toggle .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s; }
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider:before { transform: translateX(20px); }

/* Filter bar */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filter-bar select, .filter-bar input { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; font-size: 13px; min-width: 120px; }
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 16px; align-items: center; }
.pagination button { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: #fff; cursor: pointer; font-size: 13px; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Signal card */
.signal-card {
    padding: 14px; border-radius: var(--radius-md);
    background: var(--bg-card); border: 2px solid var(--border);
    margin-bottom: 10px; display: flex; align-items: center; gap: 14px;
    animation: signalSlideIn 0.35s ease-out;
}
.signal-card.buy { border-color: var(--success); background: #f0fdf4; }
.signal-card.sell { border-color: var(--danger); background: #fef2f2; }
.signal-card.hold { border-color: var(--border); background: var(--bg-card); }
.signal-icon { font-size: 28px; }
.signal-info { flex: 1; }
.signal-info .signal-type { font-size: 16px; font-weight: 700; }
.signal-info .signal-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

@keyframes signalSlideIn {
    from { transform: translateY(-20px); opacity: 0; max-height: 0; margin-bottom: 0; padding: 0 14px; }
    to   { transform: translateY(0);    opacity: 1; max-height: 80px; margin-bottom: 10px; padding: 14px; }
}

/* New signals floating badge */
.signal-new-badge {
    position: sticky; top: 8px; z-index: 10;
    text-align: center; margin-bottom: 10px;
}
.signal-new-badge span {
    display: inline-block; padding: 6px 16px; border-radius: 20px;
    background: var(--primary); color: #fff; font-size: 13px; font-weight: 600;
    cursor: pointer; box-shadow: 0 2px 8px rgba(79,70,229,0.3);
    animation: badgePop 0.3s ease;
}
@keyframes badgePop {
    from { transform: scale(0.8); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

/* Bot status */
.bot-status { display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: var(--radius-lg); margin-bottom: 20px; }
.bot-status.running { background: #f0fdf4; border: 1px solid #bbf7d0; }
.bot-status.stopped { background: #fef2f2; border: 1px solid #fecaca; }
.bot-dot { width: 12px; height: 12px; border-radius: 50%; animation: pulse 2s infinite; }
.bot-dot.on { background: var(--success); }
.bot-dot.off { background: #94a3b8; animation: none; }
@keyframes pulse {
    0%,100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Toast */
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 20px; border-radius: var(--radius-md); color: #fff; font-size: 14px; z-index: 9999; animation: slideIn 0.3s ease; box-shadow: var(--shadow-lg); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Login page */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 40px; width: 400px; box-shadow: var(--shadow-lg); }
.login-card h2 { text-align: center; font-size: 22px; margin-bottom: 8px; color: var(--text-primary); }
.login-card .subtitle { text-align: center; color: var(--text-secondary); font-size: 13px; margin-bottom: 28px; }
.login-error { background: #fef2f2; color: #991b1b; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; display: none; }
.login-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-secondary); }
.login-footer a { color: var(--primary); cursor: pointer; text-decoration: none; font-weight: 600; }

/* Loading spinner */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid #e2e8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* SSE status */
.sse-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 4px 10px; border-radius: 20px; }
.sse-status.connected { background: #d1fae5; color: #065f46; }
.sse-status.disconnected { background: #fee2e2; color: #991b1b; }
.sse-dot { width: 6px; height: 6px; border-radius: 50%; }
.sse-status.connected .sse-dot { background: var(--success); }
.sse-status.disconnected .sse-dot { background: var(--danger); }

/* Log viewer */
.log-table td { font-size: 12px; font-family: var(--font-mono); }
.log-level { display: inline-block; padding: 2px 6px; border-radius: 3px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.level-INFO { background: #dbeafe; color: #1e40af; }
.level-WARN { background: #fef3c7; color: #92400e; }
.level-ERROR { background: #fee2e2; color: #991b1b; }
.level-SUCCESS { background: #d1fae5; color: #065f46; }

/* Empty state */
.empty-state { text-align: center; padding: 40px; color: var(--text-secondary); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }

/* Trade direction colors (Chinese convention: red up, green down) */
.up { color: var(--danger); }     /* Red for increase */
.down { color: var(--success); }  /* Green for decrease */

/* Utility */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: 13px; }
.text-secondary { color: var(--text-secondary); }
.font-bold { font-weight: 700; }
