/* ═══════════════════════════════════════════════════════
   Argus — Dark Trading Dashboard
   ═══════════════════════════════════════════════════════ */

:root {
  --bg: #0a0e17;
  --bg2: #0f1420;
  --surface: #131929;
  --surface2: #1a2035;
  --border: #1e2d45;
  --border2: #253350;
  --text: #e2e8f5;
  --muted: #5a7399;
  --muted2: #3d5475;
  --green: #00d68f;
  --green-bg: rgba(0,214,143,0.08);
  --red: #ff4d6a;
  --red-bg: rgba(255,77,106,0.08);
  --blue: #4d9fff;
  --blue-bg: rgba(77,159,255,0.08);
  --purple: #9b59f5;
  --purple-bg: rgba(155,89,245,0.08);
  --yellow: #ffc744;
  --accent: #2563eb;
  --accent-hover: #3b72f2;
  --sidebar-w: 240px;
  --radius: 10px;
  --font: 'Sora', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; scroll-behavior: smooth; }
body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; display: flex; overflow-x: hidden; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
  transition: transform 0.3s ease;
}
.sidebar-brand { padding: 24px 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.brand-icon { width: 36px; height: 36px; background: linear-gradient(135deg, var(--accent), var(--purple)); border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 16px; color: #fff; }
.brand-text { font-size: 17px; font-weight: 700; background: linear-gradient(135deg, var(--blue), var(--purple)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; letter-spacing: -0.3px; }
.sidebar-nav { padding: 12px 10px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--radius); color: var(--muted); text-decoration: none; font-size: 13.5px; font-weight: 500; transition: all 0.2s; position: relative; margin-bottom: 2px; }
.nav-item i { width: 18px; text-align: center; font-size: 14px; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: linear-gradient(135deg, rgba(37,99,235,0.2), rgba(155,89,245,0.1)); color: var(--blue); border: 1px solid rgba(37,99,235,0.25); }
.badge { margin-left: auto; background: var(--red); color: #fff; border-radius: 50px; font-size: 10px; font-weight: 700; padding: 2px 6px; min-width: 18px; text-align: center; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); }
.ws-status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted2); transition: background 0.3s; }
.status-dot.connected { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.error { background: var(--red); }

/* ── Mobile Header ───────────────────────────────── */
.mobile-header { display: none; position: fixed; top: 0; left: 0; right: 0; height: 56px; background: var(--bg2); border-bottom: 1px solid var(--border); align-items: center; justify-content: space-between; padding: 0 16px; z-index: 200; }
.menu-btn { background: none; border: none; color: var(--text); font-size: 18px; cursor: pointer; padding: 8px; }
.mobile-brand { font-weight: 700; font-size: 16px; color: var(--blue); }
.ws-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted2); }

/* ── Main ────────────────────────────────────────── */
.main { margin-left: var(--sidebar-w); flex: 1; padding: 32px; min-height: 100vh; max-width: calc(100vw - var(--sidebar-w)); }
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Page Header ─────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 28px; gap: 16px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -0.5px; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin-bottom: 14px; margin-top: 28px; }

/* ── Buttons ─────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px; border-radius: 8px; border: 1px solid transparent; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(37,99,235,0.35); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border2); }
.btn-outline:hover { background: var(--surface); border-color: var(--muted); }
.btn-danger-outline { color: var(--red); border-color: var(--red); }
.btn-danger-outline:hover { background: rgba(239,68,68,0.08); border-color: var(--red); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── Stats Grid ──────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 8px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.stat-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.stat-icon.green { background: var(--green-bg); color: var(--green); }
.stat-icon.red { background: var(--red-bg); color: var(--red); }
.stat-icon.blue { background: var(--blue-bg); color: var(--blue); }
.stat-icon.purple { background: var(--purple-bg); color: var(--purple); }
.stat-val { font-size: 28px; font-weight: 700; font-family: var(--mono); }
.stat-label { font-size: 12px; color: var(--muted); }

/* ── Stock Grid ──────────────────────────────────── */
.stock-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.stock-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: all 0.2s; position: relative; overflow: hidden; }
.stock-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--border2); transition: background 0.3s; }
.stock-card.signal-long::before { background: var(--green); }
.stock-card.signal-short::before { background: var(--red); }
.stock-card:hover { border-color: var(--border2); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.stock-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.stock-symbol { font-size: 18px; font-weight: 700; font-family: var(--mono); }
.stock-name { font-size: 12px; color: var(--muted); margin-top: 2px; }
.signal-badge { padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; font-family: var(--mono); letter-spacing: 0.5px; }
.signal-badge.LONG { background: var(--green-bg); color: var(--green); border: 1px solid rgba(0,214,143,0.2); }
.signal-badge.SHORT { background: var(--red-bg); color: var(--red); border: 1px solid rgba(255,77,106,0.2); }
.signal-badge.NONE { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.signal-badge.SURGE { background: rgba(255,199,68,0.12); color: #ffc744; border: 1px solid rgba(255,199,68,0.25); }
.stock-price { font-size: 26px; font-weight: 700; font-family: var(--mono); letter-spacing: -0.5px; }
.stock-change { font-size: 13px; font-weight: 600; font-family: var(--mono); margin-top: 4px; }
.stock-change.positive { color: var(--green); }
.stock-change.negative { color: var(--red); }
.stock-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.stock-meta-item { font-size: 11px; color: var(--muted); }
.stock-meta-item strong { color: var(--text); }

/* ── Table ───────────────────────────────────────── */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { background: var(--bg2); color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.7px; padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg2); }
.empty-row { text-align: center; color: var(--muted); padding: 32px; }
.positive { color: var(--green); }
.negative { color: var(--red); }

/* ── Card ────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.card-header i { color: var(--blue); }
.card-body { padding: 20px; }

/* ── Strategies ──────────────────────────────────── */
.strategies-grid { display: block; }
.strategy-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; transition: all 0.2s; }
.strategy-card:hover { border-color: var(--border2); }
.strategy-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.strategy-name { font-size: 15px; font-weight: 600; }
.strategy-desc { font-size: 12px; color: var(--muted); margin-top: 4px; }
.strategy-actions { display: flex; gap: 6px; }
.icon-btn { width: 30px; height: 30px; background: none; border: 1px solid var(--border2); border-radius: 6px; color: var(--muted); cursor: pointer; transition: all 0.2s; display: flex; align-items: center; justify-content: center; font-size: 12px; }
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn.danger:hover { background: var(--red-bg); color: var(--red); border-color: rgba(255,77,106,0.3); }
.strategy-code-preview { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; font-family: var(--mono); font-size: 11px; color: var(--muted2); overflow: hidden; max-height: 60px; white-space: pre; }
.strategy-meta { margin-top: 12px; font-size: 11px; color: var(--muted); }

/* ── Alerts ──────────────────────────────────────── */
.alerts-list { display: flex; flex-direction: column; gap: 10px; }
.alert-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; display: flex; align-items: center; gap: 16px; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; } }
.alert-signal-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.alert-signal-icon.LONG { background: var(--green-bg); color: var(--green); }
.alert-signal-icon.SHORT { background: var(--red-bg); color: var(--red); }
.alert-signal-icon.SURGE { background: rgba(255,199,68,0.12); color: #ffc744; }
.alert-info { flex: 1; }
.alert-title { font-size: 14px; font-weight: 600; }
.alert-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.alert-price { font-family: var(--mono); font-size: 16px; font-weight: 700; text-align: right; }
.alert-time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 4px; }

/* ── Settings ────────────────────────────────────── */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 20px; }

/* ── Forms ───────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.form-hint { font-size: 11px; color: var(--muted2); margin-top: 5px; }
.form-input { width: 100%; background: var(--bg); border: 1px solid var(--border2); border-radius: 8px; color: var(--text); font-family: var(--font); font-size: 13px; padding: 10px 12px; transition: border-color 0.2s; outline: none; }
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.form-input::placeholder { color: var(--muted2); }
select.form-input { cursor: pointer; }

/* ── Toggle ──────────────────────────────────────── */
.toggle-label { display: flex !important; align-items: center; gap: 10px; cursor: pointer; text-transform: none !important; letter-spacing: 0 !important; font-size: 13px !important; font-weight: 500 !important; color: var(--text) !important; }
.toggle-label input[type="checkbox"] { display: none; }
.toggle { width: 40px; height: 22px; border-radius: 11px; background: var(--border2); position: relative; transition: background 0.2s; flex-shrink: 0; }
.toggle::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform 0.2s; }
.toggle-label input:checked + .toggle { background: var(--accent); }
.toggle-label input:checked + .toggle::after { transform: translateX(18px); }

/* ── Code Editor ─────────────────────────────────── */
.editor-wrap { border: 1px solid var(--border2); border-radius: 8px; overflow: hidden; }
.code-editor { width: 100%; min-height: 320px; background: var(--bg); color: #a8d9ff; font-family: var(--mono); font-size: 13px; line-height: 1.7; border: none; outline: none; resize: vertical; padding: 16px; }
.editor-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.editor-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.test-result { margin-top: 10px; padding: 12px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.test-result.success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(0,214,143,0.2); }
.test-result.error { background: var(--red-bg); color: var(--red); border: 1px solid rgba(255,77,106,0.2); }
.code-example { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 14px; margin-top: 10px; overflow-x: auto; }
.code-example pre { font-family: var(--mono); font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ── Modals ──────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); z-index: 300; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease; }
.modal { background: var(--surface); border: 1px solid var(--border2); border-radius: 14px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; animation: scaleIn 0.2s ease; }
.modal-xl { max-width: 860px; }
@keyframes scaleIn { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px; transition: color 0.2s; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Search Modal ────────────────────────────────── */
.modal-search { max-width: 560px; }

.search-box {
  position: relative; display: flex; align-items: center;
}
.search-box-icon {
  position: absolute; left: 14px; color: var(--muted); font-size: 15px; pointer-events: none; z-index: 1;
}
.search-box-input {
  width: 100%; background: var(--bg); border: 2px solid var(--border2);
  border-radius: 10px; color: var(--text); font-family: var(--font); font-size: 15px;
  padding: 13px 42px 13px 44px; outline: none; transition: border-color 0.2s;
}
.search-box-input:focus { border-color: var(--accent); }
.search-box-input::placeholder { color: var(--muted2); }
.search-box-clear {
  position: absolute; right: 12px; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 14px; padding: 6px;
  display: flex; align-items: center; transition: color 0.2s;
}
.search-box-clear:hover { color: var(--text); }

/* Results container */
.search-results {
  display: flex; flex-direction: column; gap: 5px;
  min-height: 80px; max-height: 340px; overflow-y: auto;
}

/* Placeholder / empty / loading states */
.search-placeholder, .search-loading, .search-no-results {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 36px 20px; color: var(--muted); font-size: 13px;
}
.search-placeholder i, .search-no-results i { font-size: 20px; opacity: 0.4; }
.search-no-results { flex-direction: column; gap: 8px; text-align: center; }
.search-no-results i { font-size: 28px; }
.search-no-results small { color: var(--muted2); font-size: 11px; }

/* Individual result row */
.result-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface2);
  cursor: pointer; transition: all 0.15s; position: relative;
  user-select: none;
}
.result-row:hover { border-color: var(--accent); background: var(--bg2); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.result-row.selected { border-color: var(--accent); background: rgba(37,99,235,0.1); box-shadow: 0 0 0 3px rgba(37,99,235,0.2); }
.result-row.selected::after { content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900; position: absolute; right: 14px; color: var(--accent); font-size: 13px; }
.result-symbol { font-family: var(--mono); font-weight: 700; font-size: 14px; min-width: 80px; }
.result-info { flex: 1; min-width: 0; }
.result-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-exchange { font-size: 11px; color: var(--muted); margin-top: 2px; }
.result-type { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; padding: 2px 7px; border-radius: 4px; white-space: nowrap; flex-shrink: 0; background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(77,159,255,0.2); }
.result-type.etf { background: var(--purple-bg); color: var(--purple); border-color: rgba(155,89,245,0.2); }
.result-type.fonds { background: var(--green-bg); color: var(--green); border-color: rgba(0,214,143,0.2); }

/* Selected preview */
.selected-preview-card {
  background: rgba(37,99,235,0.08); border: 1px solid rgba(37,99,235,0.25);
  border-radius: 9px; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}

/* ── Toast ───────────────────────────────────────── */
#toastContainer { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 999; }
.toast { background: var(--surface); border: 1px solid var(--border2); border-radius: 10px; padding: 14px 18px; min-width: 260px; max-width: 380px; display: flex; align-items: center; gap: 12px; animation: toastIn 0.3s ease; box-shadow: 0 8px 32px rgba(0,0,0,0.4); font-size: 13px; }
@keyframes toastIn { from { transform: translateX(40px); opacity: 0; } to { opacity: 1; } }
@keyframes toastOut { to { transform: translateX(40px); opacity: 0; } }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast.success .toast-icon { color: var(--green); }
.toast.error .toast-icon { color: var(--red); }
.toast.info .toast-icon { color: var(--blue); }

/* ── Spinner ─────────────────────────────────────── */
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty State ─────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); grid-column: 1/-1; }
.empty-state i { font-size: 40px; margin-bottom: 16px; opacity: 0.3; display: block; }
.empty-state p { margin-bottom: 20px; font-size: 14px; }

code { font-family: var(--mono); font-size: 12px; background: var(--bg2); border: 1px solid var(--border); border-radius: 4px; padding: 2px 6px; color: var(--blue); }

/* ── Sidebar overlay (mobile) ────────────────────── */
#sidebarOverlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 99; }

/* ─── Bottom Navigation (Mobile) ────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 150;
  background: var(--bg2); border-top: 1px solid var(--border);
  height: 60px; padding-bottom: env(safe-area-inset-bottom, 0px);
  flex-direction: row;
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; color: var(--muted); text-decoration: none;
  font-size: 10px; font-weight: 600; border: none; background: none;
  cursor: pointer; position: relative; padding: 8px 0 4px;
  transition: color 0.2s; letter-spacing: 0.3px;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.bottom-nav-item i { font-size: 19px; line-height: 1; }
.bottom-nav-item.active { color: var(--blue); }
.bottom-badge {
  position: absolute; top: 5px; right: calc(50% - 20px);
  background: var(--red); color: #fff; border-radius: 50px;
  font-size: 9px; font-weight: 700; padding: 1px 5px;
  min-width: 16px; text-align: center; line-height: 1.4;
  pointer-events: none;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0.7; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Responsive (tablet + mobile) ───────────────── */
@media (max-width: 768px) {
  /* Sidebar */
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  #sidebarOverlay.open { display: block; }
  .mobile-header { display: flex; }

  /* Bottom nav visible */
  .bottom-nav { display: flex; }

  /* Main: leave room for mobile-header top + bottom-nav bottom */
  .main {
    margin-left: 0; max-width: 100vw;
    padding: 72px 16px calc(68px + env(safe-area-inset-bottom, 0px));
  }

  /* Layout */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stock-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .strategies-section { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }

  /* Page header stacks vertically */
  .page-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-header > *:last-child { width: 100%; }
  /* Direct btn children of page-header become full-width */
  .page-header > .btn { width: 100%; justify-content: center; }
  /* Search inside header fills available width */
  .inline-search-wrap { flex: 1; min-width: 0; }
  .inline-search, .inline-search:focus { width: 100%; }

  /* Tables scroll horizontally */
  .table-card { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); }
  .data-table { min-width: 520px; }
  .data-table th, .data-table td { padding: 10px 12px; white-space: nowrap; }
  .col-hide { display: none; }

  /* Icon buttons: comfortable touch target */
  .icon-btn { width: 36px; height: 36px; font-size: 13px; }

  /* Modals: slide up from bottom as bottom-sheet */
  .modal-overlay { align-items: flex-end !important; padding: 0; }
  .modal {
    border-radius: 18px 18px 0 0 !important; max-width: 100% !important; width: 100%;
    max-height: 92vh; animation: slideUp 0.25s ease !important;
  }
  .modal-xl { max-height: 96vh; height: 96vh; }
  .modal-xl .code-editor { min-height: 28vh; }

  /* Editor */
  .editor-header { flex-direction: column; align-items: flex-start; }

  /* Toast: above bottom nav */
  #toastContainer { right: 12px; left: 12px; bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .toast { min-width: unset; max-width: 100%; width: 100%; }
}

/* ── Responsive (small phones only) ─────────────── */
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-title { font-size: 20px; }
  .stock-price { font-size: 22px; }

  /* Alert items: stack price below info */
  .alert-item { flex-wrap: wrap; padding: 12px 14px; gap: 8px; }
  .alert-price { flex-basis: 100%; text-align: left; font-size: 14px; margin-top: 0; }
  .alert-time { display: none; }

  /* Params grid single column */
  .params-grid { grid-template-columns: 1fr; }

  /* Chart container height on small phones */
  #chartContainer { height: 280px !important; }

  /* Backtesting table scrolls, results collapse nicely */
  .bt-chart-svg { height: 160px; }

  /* Strategy code preview shorter */
  .strategy-code-preview { max-height: 40px; }
}

/* ── Manual stock tag ────────────────────────────── */
.manual-tag {
  display: inline-block; font-size: 9px; font-weight: 700;
  background: var(--yellow); color: #000; border-radius: 3px;
  padding: 1px 4px; vertical-align: middle; margin-left: 4px; letter-spacing: 0.3px;
}
.manual-hint {
  background: rgba(255,199,68,0.08); border: 1px solid rgba(255,199,68,0.25);
  color: var(--yellow); border-radius: 8px; padding: 10px 14px;
  font-size: 12px; display: flex; align-items: center; gap: 8px;
}

/* ─── Pine Script Import UI ─────────────────────────────────────────────── */
.strat-tabs {
  display: flex; gap: 4px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border); padding-bottom: 0;
}
.strat-tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font-size: 13px; font-weight: 500;
  padding: 8px 14px; cursor: pointer; display: flex; align-items: center;
  gap: 6px; margin-bottom: -1px; transition: color 0.15s, border-color 0.15s;
}
.strat-tab:hover { color: var(--text); }
.strat-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.strat-panel { animation: fadeIn 0.15s; }

.pine-hint {
  background: rgba(41,182,246,0.08); border: 1px solid rgba(41,182,246,0.2);
  color: #7ecbf5; border-radius: 8px; padding: 10px 14px;
  font-size: 12px; display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
}

.params-header {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.6px;
  display: flex; align-items: center; gap: 8px;
  margin: 16px 0 10px;
}
.params-badge {
  background: var(--accent); color: #000;
  border-radius: 20px; font-size: 10px; padding: 1px 7px;
  font-weight: 700; letter-spacing: 0;
}

.params-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}
.param-item {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.param-item label {
  display: block; font-size: 11px; color: var(--muted);
  margin-bottom: 4px; font-weight: 500;
}
.param-item .param-name {
  font-size: 10px; color: var(--accent); font-family: monospace;
  margin-bottom: 6px; display: block;
}
.param-item input[type="number"],
.param-item input[type="text"],
.param-item select {
  width: 100%; background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 13px;
  padding: 5px 8px; box-sizing: border-box;
}
.param-item input[type="checkbox"] { width: 16px; height: 16px; margin-top: 2px; }
.param-item .param-default {
  font-size: 10px; color: var(--muted); margin-top: 4px;
}
.param-item .param-range {
  font-size: 10px; color: var(--muted);
}

/* ─── Inline Stock Filter / Search ──────────────────────────────────────── */
.inline-search-wrap {
  position: relative; display: flex; align-items: center;
}
.inline-search-icon {
  position: absolute; left: 9px; font-size: 12px; color: var(--muted); pointer-events: none;
}
.inline-search {
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text); font-size: 13px;
  padding: 5px 28px 5px 28px; width: 180px; outline: none;
  transition: border-color 0.15s, width 0.2s;
}
.inline-search:focus { border-color: var(--accent); width: 220px; }
.inline-search-clear {
  position: absolute; right: 8px; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 4px;
  line-height: 1; transition: color 0.15s;
}
.inline-search-clear:hover { color: var(--text); }

/* ─── Alert Grouping ─────────────────────────────────────────────────────── */
.alert-grouped {
  border-left: 3px solid var(--accent);
}
.alert-count-badge {
  display: inline-block; background: var(--accent); color: #000;
  border-radius: 20px; font-size: 10px; font-weight: 700;
  padding: 1px 7px; margin-left: 6px; vertical-align: middle; letter-spacing: 0;
}
.alert-history-toggle {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 11px; padding: 4px 0 0;
  display: flex; align-items: center; gap: 5px;
  transition: color 0.15s;
}
.alert-history-toggle:hover { color: var(--text); }
.alert-history {
  margin-top: 8px; border-top: 1px solid var(--border);
  padding-top: 8px; display: flex; flex-direction: column; gap: 4px;
}
.alert-history-row {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted); padding: 2px 0;
}
.alert-history-price { font-family: var(--mono); font-weight: 600; color: var(--text); }
.alert-history-time { color: var(--muted); }

/* ─── Backtesting ────────────────────────────────────────────────────────── */
.bt-strategy-checks {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px;
}
.bt-strat-check {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 12px;
  cursor: pointer; font-size: 13px; font-weight: 500;
  transition: border-color 0.15s; user-select: none;
}
.bt-strat-check:hover { border-color: var(--border2); }
.bt-strat-check input { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }

.bt-color-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block;
}

.bt-best-row > td {
  background: rgba(0, 214, 143, 0.04);
}
.bt-best-row > td:first-child {
  border-left: 2px solid var(--green);
}

.bt-chart-wrap {
  overflow-x: auto; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); margin-top: 10px;
}
.bt-chart-svg {
  width: 100%; min-width: 360px; height: 200px; display: block;
}

.bt-chart-legend {
  display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted);
}
.bt-legend-item {
  display: flex; align-items: center; gap: 6px;
}
.bt-legend-dot {
  width: 10px; height: 3px; border-radius: 2px; flex-shrink: 0; display: inline-block;
}
.bt-legend-dashed .bt-legend-dot-dash {
  width: 14px; height: 0; border-top: 2px dashed #5a7399; display: inline-block; flex-shrink: 0;
}

/* ─── Alerts Toggle Label ────────────────────────────────────────────────── */
.toggle-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); cursor: pointer; user-select: none;
}
.toggle-label input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); }
.toggle-label span { white-space: nowrap; }

/* ─── Impersonation Banner ───────────────────────────────────────────────── */
.impersonate-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 8000;
  background: #92400e; border-bottom: 1px solid #d97706;
  color: #fde68a; padding: 0 20px; height: 40px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px;
}
.impersonate-back-btn {
  background: rgba(0,0,0,0.25); border: 1px solid rgba(253,230,138,0.3);
  color: #fde68a; padding: 4px 12px; border-radius: 6px;
  cursor: pointer; font-size: 12px; transition: background 0.2s;
}
.impersonate-back-btn:hover { background: rgba(0,0,0,0.4); }
body.impersonating { padding-top: 40px; }
body.impersonating .sidebar { top: 40px; }
body.impersonating .mobile-header { top: 40px; }

/* ─── User Management Table ──────────────────────────────────────────────── */
.user-role-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
}
.user-role-badge.admin { background: var(--purple-bg); color: var(--purple); }
.user-role-badge.user  { background: var(--blue-bg);   color: var(--blue); }

/* ─── Strategy Sharing ───────────────────────────────────────────────────── */
.strategies-section-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--muted); margin-bottom: 14px;
}
.strategies-section { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.strategy-shared-own { border-color: var(--green) !important; }
.strategy-shared-foreign { border-color: var(--blue) !important; opacity: 0.92; }
.shared-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: 4px;
  background: var(--green-bg); color: var(--green); margin-left: 8px; vertical-align: middle;
}
.share-active { color: var(--green) !important; }
.icon-btn.share-active { color: var(--green) !important; }
