/* ═══════════════════════════════════════════════════════════════════════
   TradeSense — Blue & White Theme  |  Light & Dark Mode
   ═══════════════════════════════════════════════════════════════════════ */

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

/* ── CSS Variables — Light Mode (Default) ─────────────────────────── */
:root {
  --bg-base:        #f0f4ff;
  --bg-surface:     #ffffff;
  --bg-card:        #ffffff;
  --bg-elevated:    #e8edf8;
  --bg-input:       #f5f7ff;
  --bg-hover:       #eef2ff;
  --bg-sidebar:     #0d2160;
  --bg-sidebar-hover: #1a3580;
  --bg-sidebar-active: #2148c0;

  --text-primary:   #0d1640;
  --text-secondary: #4b5a8a;
  --text-muted:     #8494b8;
  --text-sidebar:   #c8d4f0;
  --text-sidebar-active: #ffffff;

  --accent-blue:    #2563eb;
  --accent-blue-hover: #1d4ed8;
  --accent-light:   #dbeafe;
  --accent-teal:    #0891b2;
  --accent-green:   #16a34a;
  --accent-red:     #dc2626;
  --accent-orange:  #d97706;
  --accent-purple:  #7c3aed;

  --border:         #d4daf0;
  --border-focus:   #2563eb;
  --shadow-sm:      0 1px 3px rgba(13,22,64,0.08);
  --shadow-md:      0 4px 16px rgba(13,22,64,0.12);
  --shadow-lg:      0 8px 32px rgba(13,22,64,0.16);
  --shadow-card:    0 2px 8px rgba(37,99,235,0.08);

  --pnl-pos:        #16a34a;
  --pnl-neg:        #dc2626;
  --pnl-pos-bg:     #dcfce7;
  --pnl-neg-bg:     #fee2e2;

  --radius-sm:      6px;
  --radius-md:      10px;
  --radius-lg:      14px;
  --radius-xl:      20px;

  --sidebar-width:  240px;
  --topbar-height:  64px;
  --transition:     0.2s ease;

  color-scheme: light;
}

/* ── Dark Mode Variables ──────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-base:        #080e24;
  --bg-surface:     #0f1a35;
  --bg-card:        #111d3d;
  --bg-elevated:    #182246;
  --bg-input:       #0f1a35;
  --bg-hover:       #1a2a50;
  --bg-sidebar:     #060e22;
  --bg-sidebar-hover: #0f1a38;
  --bg-sidebar-active: #1a3580;

  --text-primary:   #e4ecff;
  --text-secondary: #8ea4d4;
  --text-muted:     #4d6290;
  --text-sidebar:   #7a96cc;
  --text-sidebar-active: #ffffff;

  --accent-blue:    #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-light:   #1e3a8a;

  --border:         #1e2e55;
  --border-focus:   #3b82f6;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:      0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg:      0 8px 32px rgba(0,0,0,0.5);
  --shadow-card:    0 2px 12px rgba(0,0,0,0.3);

  --pnl-pos-bg:     #14532d;
  --pnl-neg-bg:     #7f1d1d;

  color-scheme: dark;
}

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

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  height: 100vh;
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ══════════════════════════════════════════════════════════════════════
   LOGIN SCREEN
   ══════════════════════════════════════════════════════════════════════ */
#loginScreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d2160 0%, #1a3a8f 40%, #0d6efd 80%, #38bdf8 100%);
  overflow: hidden;
}

#loginScreen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(59,130,246,0.25) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(14,165,233,0.2) 0%, transparent 50%);
  pointer-events: none;
}

.login-card {
  position: relative;
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(24px);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-xl);
  padding: 48px 48px 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.4);
  animation: loginSlideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginSlideIn {
  from { opacity: 0; transform: translateY(32px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

.login-logo-icon {
  font-size: 52px;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 4px 16px rgba(255,255,255,0.3));
}

.login-logo h1 {
  font-size: 28px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.5px;
}

.login-logo p {
  font-size: 13px;
  color: rgba(255,255,255,0.65);
  margin-top: 4px;
}

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

.login-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  margin-bottom: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius-md);
  color: #ffffff;
  font-size: 14px;
  font-family: inherit;
  transition: all var(--transition);
  outline: none;
}

.login-input::placeholder { color: rgba(255,255,255,0.4); }

.login-input:focus {
  border-color: rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.15);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 24px;
}

.login-remember input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: #60a5fa;
  cursor: pointer;
}

.login-remember label {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
}

.login-remember .token-note {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  margin-left: 2px;
}

.btn-login {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 16px rgba(37,99,235,0.4);
}

.btn-login:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(37,99,235,0.5); }
.btn-login:active { transform: translateY(0); }

.login-divider {
  text-align: center;
  margin: 20px 0;
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  position: relative;
}

.login-divider::before, .login-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 38%;
  height: 1px;
  background: rgba(255,255,255,0.15);
}

.login-divider::before { left: 0; }
.login-divider::after { right: 0; }

.login-alt-steps {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-md);
  padding: 16px;
}

.login-alt-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12px;
  color: rgba(255,255,255,0.65);
}

.login-alt-step:last-child { margin-bottom: 0; }

.login-step-num {
  width: 20px;
  height: 20px;
  background: rgba(59,130,246,0.5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
  margin-top: 1px;
}

.login-status-banner {
  margin-top: 16px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.login-status-banner.success {
  background: rgba(22,163,74,0.2);
  border: 1px solid rgba(22,163,74,0.4);
  color: #86efac;
}

.login-status-banner.error {
  background: rgba(220,38,38,0.2);
  border: 1px solid rgba(220,38,38,0.4);
  color: #fca5a5;
}

.login-status-banner.info {
  background: rgba(37,99,235,0.2);
  border: 1px solid rgba(37,99,235,0.4);
  color: #93c5fd;
}

/* ══════════════════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: fixed;
  left: 0; top: 0;
  z-index: 100;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background var(--transition);
  overflow: hidden;
  box-shadow: 2px 0 16px rgba(0,0,0,0.2);
}

.sidebar.collapsed { width: 64px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.logo-icon { font-size: 24px; flex-shrink: 0; }
.logo-text {
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  white-space: nowrap;
  letter-spacing: -0.3px;
}

.sidebar.collapsed .logo-text { opacity: 0; width: 0; }

.sidebar-toggle {
  background: rgba(255,255,255,0.08);
  border: none;
  color: rgba(255,255,255,0.6);
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.15); color: white; }

/* Kite Connection Banner in Sidebar */
.sidebar-kite-badge {
  margin: 12px 12px 4px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
}

.sidebar-kite-badge.connected {
  background: rgba(22,163,74,0.15);
  border-color: rgba(22,163,74,0.3);
  color: #86efac;
}

.sidebar-kite-badge.disconnected {
  background: rgba(234,179,8,0.1);
  border-color: rgba(234,179,8,0.25);
  color: #fde68a;
}

.sidebar-kite-badge .kite-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.connected .kite-dot { background: #22c55e; box-shadow: 0 0 6px #22c55e; animation: pulse-green 2s infinite; }
.disconnected .kite-dot { background: #eab308; }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 4px #22c55e; }
  50% { box-shadow: 0 0 10px #22c55e; }
}

.sidebar.collapsed .sidebar-kite-badge span:not(.kite-dot) { display: none; }
.sidebar.collapsed .sidebar-kite-badge { justify-content: center; padding: 8px; }

.sidebar-nav {
  flex: 1;
  padding: 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sidebar);
  transition: all var(--transition);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #ffffff;
}

.nav-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}

.nav-icon { font-size: 18px; flex-shrink: 0; }
.nav-label { flex: 1; }
.sidebar.collapsed .nav-label { display: none; }

.nav-badge {
  background: var(--accent-red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scanner-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-sidebar);
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar.collapsed .scanner-status span:not(.status-dot) { display: none; }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: all var(--transition);
}
.status-dot.online { background: #22c55e; box-shadow: 0 0 8px rgba(34,197,94,0.6); animation: pulseDot 2s infinite; }
.status-dot.offline { background: #6b7280; }

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 4px rgba(34,197,94,0.4); }
  50% { box-shadow: 0 0 12px rgba(34,197,94,0.8); }
}

.btn-scanner-toggle {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.7);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-scanner-toggle:hover { background: rgba(255,255,255,0.12); color: white; }
.btn-scanner-toggle.running { background: rgba(220,38,38,0.2); border-color: rgba(220,38,38,0.4); color: #fca5a5; }
.sidebar.collapsed .btn-scanner-toggle { font-size: 16px; padding: 8px; text-align: center; }

.btn-logout-sidebar {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(220,38,38,0.35);
  background: rgba(220,38,38,0.1);
  color: #fca5a5;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
.btn-logout-sidebar:hover { background: rgba(220,38,38,0.25); color: #fecaca; border-color: rgba(220,38,38,0.6); }
.sidebar.collapsed .btn-logout-sidebar { font-size: 14px; padding: 8px; text-align: center; }

/* ══════════════════════════════════════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════════════════════════════════════ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content.expanded { margin-left: 64px; }

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  z-index: 50;
  transition: background var(--transition), border-color var(--transition);
}

.topbar-left { display: flex; flex-direction: column; gap: 2px; }

.page-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  line-height: 1;
}

.page-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.market-time {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
  padding: 6px 12px;
  background: var(--bg-elevated);
  border-radius: 999px;
  border: 1px solid var(--border);
}

.market-status { font-size: 11px; font-weight: 600; color: var(--text-muted); }

/* Theme Toggle */
.theme-toggle {
  width: 36px; height: 36px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
}
.theme-toggle:hover { background: var(--bg-hover); border-color: var(--accent-blue); }

/* Kite Status in Topbar */
.kite-topbar-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid var(--border);
}

.kite-topbar-badge.connected {
  background: rgba(22,163,74,0.1);
  border-color: rgba(22,163,74,0.3);
  color: var(--accent-green);
}

.kite-topbar-badge.disconnected {
  background: rgba(234,179,8,0.1);
  border-color: rgba(234,179,8,0.3);
  color: var(--accent-orange);
}

.kite-topbar-badge:hover { opacity: 0.8; }

/* ── Index Ticker Bar ─────────────────────────────────────────────── */
.ticker-bar {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 24px;
  height: 40px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}

.ticker-bar::-webkit-scrollbar { display: none; }

.ticker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  white-space: nowrap;
  border-right: 1px solid var(--border);
}

.ticker-item:last-child { border-right: none; }
.ticker-name { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.ticker-value { font-size: 13px; font-weight: 700; color: var(--text-primary); font-family: 'JetBrains Mono', monospace; }
.ticker-change { font-size: 11px; font-weight: 600; font-family: 'JetBrains Mono', monospace; }
.ticker-change.up { color: var(--accent-green); }
.ticker-change.down { color: var(--accent-red); }
.ticker-loading { font-size: 12px; color: var(--text-muted); padding: 0 8px; }

/* ── Page Content ─────────────────────────────────────────────────── */
.pages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.page { display: none; }
.page.active { display: block; animation: pageIn 0.2s ease; }

@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════════════════════════════════ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  overflow: hidden;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.card-header h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 20px; }

/* ══════════════════════════════════════════════════════════════════════
   STATS GRID — Dashboard
   ══════════════════════════════════════════════════════════════════════ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-card);
  transition: all var(--transition);
  cursor: default;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--accent-blue); }

.stat-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent-light), rgba(37,99,235,0.1));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.stat-info { flex: 1; min-width: 0; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--text-primary); line-height: 1; white-space: nowrap; }
.stat-label { font-size: 11px; color: var(--text-muted); font-weight: 500; margin-top: 3px; white-space: nowrap; }

/* ── Dashboard Grid ──────────────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 1100px) { .dashboard-grid { grid-template-columns: 1fr; } }

/* ── Active Strategies mini grid ────────────────────────────────── */
.dash-strategies-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  padding: 16px;
}

.dash-strategy-pill {
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-hover));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: all var(--transition);
}

.dash-strategy-pill:hover { border-color: var(--accent-blue); }

.dsp-name { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
.dsp-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.dsp-meta span { font-size: 11px; color: var(--text-muted); background: var(--bg-surface); padding: 2px 6px; border-radius: 999px; border: 1px solid var(--border); }

/* ══════════════════════════════════════════════════════════════════════
   TABLES
   ══════════════════════════════════════════════════════════════════════ */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  transition: background var(--transition);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

.loading-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px !important;
  font-size: 13px;
}

.mono { font-family: 'JetBrains Mono', monospace; }
.bold { font-weight: 700; }

/* ── P&L Colors ──────────────────────────────────────────────────── */
.pnl-positive { color: var(--pnl-pos); font-weight: 600; }
.pnl-negative { color: var(--pnl-neg); font-weight: 600; }
.pnl-neutral  { color: var(--text-muted); }
.up { color: var(--accent-green); }
.down { color: var(--accent-red); }

/* ══════════════════════════════════════════════════════════════════════
   PORTFOLIO SUMMARY
   ══════════════════════════════════════════════════════════════════════ */
.portfolio-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.portfolio-stat {
  padding: 16px 20px;
  border-right: 1px solid var(--border);
}
.portfolio-stat:last-child { border-right: none; }
.portfolio-stat-label { font-size: 11px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.portfolio-stat-value { font-size: 20px; font-weight: 800; color: var(--text-primary); margin-top: 4px; font-family: 'JetBrains Mono', monospace; }

/* ══════════════════════════════════════════════════════════════════════
   STRATEGIES
   ══════════════════════════════════════════════════════════════════════ */
.strategy-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 12px;
  background: var(--bg-card);
  transition: all var(--transition);
  box-shadow: var(--shadow-sm);
}

.strategy-card:hover { border-color: var(--accent-blue); box-shadow: var(--shadow-md); }
.strategy-card.inactive { opacity: 0.65; }

.strategy-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.strategy-name { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.strategy-desc { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.strategy-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.strategy-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.strategy-tag {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

.active-tag { background: rgba(22,163,74,0.1); border-color: rgba(22,163,74,0.3); color: var(--accent-green); }
.inactive-tag { background: rgba(220,38,38,0.1); border-color: rgba(220,38,38,0.3); color: var(--accent-red); }
.channel-tag { background: rgba(37,99,235,0.1); border-color: rgba(37,99,235,0.3); color: var(--accent-blue); }

.strategy-conditions { display: flex; gap: 6px; flex-wrap: wrap; }

.cond-badge {
  background: linear-gradient(135deg, var(--accent-light), rgba(37,99,235,0.08));
  border: 1px solid rgba(37,99,235,0.2);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--accent-blue);
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
}

/* Indicators grid */
.indicators-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 20px;
}

.indicator-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  cursor: pointer;
  transition: all var(--transition);
}

.indicator-card:hover {
  border-color: var(--accent-blue);
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.ind-name { font-size: 13px; font-weight: 700; color: var(--text-primary); margin-bottom: 4px; }
.ind-badge { display: inline-block; font-size: 10px; font-weight: 700; background: var(--accent-blue); color: white; padding: 2px 8px; border-radius: 999px; margin-bottom: 6px; }
.ind-desc { font-size: 11px; color: var(--text-muted); line-height: 1.4; }

/* ══════════════════════════════════════════════════════════════════════
   ALERTS
   ══════════════════════════════════════════════════════════════════════ */
.alert-item {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

.alert-item:last-child { border-bottom: none; }
.alert-item:hover { background: var(--bg-hover); }

.alert-icon {
  width: 36px; height: 36px;
  background: rgba(220,38,38,0.1);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.alert-content { flex: 1; min-width: 0; }
.alert-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.alert-subtitle { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.alert-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.empty-state { text-align: center; padding: 40px 20px; font-size: 13px; color: var(--text-muted); }

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

.settings-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-input {
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  transition: all var(--transition);
  outline: none;
  width: 100%;
}

.form-input:focus {
  border-color: var(--border-focus);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.form-input::placeholder { color: var(--text-muted); }

select.form-input { cursor: pointer; }

textarea.form-input { resize: vertical; min-height: 70px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.form-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.help-link { font-size: 11px; color: var(--accent-blue); text-decoration: none; margin-left: 6px; }
.help-link:hover { text-decoration: underline; }

/* Toggle Switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: all 0.3s;
}

.slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle input:checked + .slider { background: var(--accent-blue); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* Kite Connect Section */
.kite-status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.poller-indicator { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text-primary); }

.kite-steps { display: flex; flex-direction: column; gap: 16px; }

.kite-step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition);
}
.kite-step:hover { border-color: var(--accent-blue); }

.step-num {
  width: 28px; height: 28px;
  background: var(--accent-blue);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

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

.info-box {
  background: linear-gradient(135deg, rgba(37,99,235,0.06), rgba(14,165,233,0.04));
  border: 1px solid rgba(37,99,235,0.15);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.info-box a { color: var(--accent-blue); }

.poller-status-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

/* Badge */
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.badge-active { background: rgba(22,163,74,0.12); border-color: rgba(22,163,74,0.3); color: var(--accent-green); }
.badge-inactive { background: var(--bg-elevated); }

.badge-exchange { padding: 3px 7px; font-size: 10px; font-weight: 700; border-radius: 4px; }
.badge-nse { background: rgba(37,99,235,0.1); color: var(--accent-blue); }
.badge-bse { background: rgba(234,179,8,0.1); color: var(--accent-orange); }

/* ══════════════════════════════════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════════════════════════════════ */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: none;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #1e40af);
  color: white;
  box-shadow: 0 2px 8px rgba(37,99,235,0.25);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--accent-blue-hover), #1e3a8a); box-shadow: 0 4px 12px rgba(37,99,235,0.35); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent-blue); }

.btn-accent {
  background: linear-gradient(135deg, var(--accent-teal), #0369a1);
  color: white;
}
.btn-accent:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-danger {
  background: rgba(220,38,38,0.1);
  color: var(--accent-red);
  border: 1px solid rgba(220,38,38,0.25);
}
.btn-danger:hover { background: rgba(220,38,38,0.15); }

.btn-success {
  background: rgba(22,163,74,0.12);
  color: var(--accent-green);
  border: 1px solid rgba(22,163,74,0.3);
}
.btn-success:hover { background: rgba(22,163,74,0.2); }

.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-large { padding: 12px 24px; font-size: 15px; }

.btn-icon {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  color: var(--text-muted);
}

.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-icon.danger:hover { background: rgba(220,38,38,0.1); color: var(--accent-red); }

#refreshIcon.spinning { display: inline-block; animation: spin 1s linear infinite; }

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════════════
   MODALS
   ══════════════════════════════════════════════════════════════════════ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.modal-overlay.open { display: flex; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-xl { max-width: 760px; }

@keyframes slideUp { from { opacity: 0; transform: translateY(20px) scale(0.97); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 17px; font-weight: 700; color: var(--text-primary); }

.modal-close {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  font-family: inherit;
}

.modal-close:hover { background: rgba(220,38,38,0.1); color: var(--accent-red); border-color: rgba(220,38,38,0.3); }

.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Strategy Condition Builder ──────────────────────────────────── */
.condition-builder-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.condition-rows { display: flex; flex-direction: column; gap: 10px; }

.condition-row {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: all var(--transition);
}
.condition-row:hover { border-color: var(--accent-blue); }

.cond-row-inner { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.cond-indicator { flex: 0 0 220px; }
.cond-params { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.cond-param { display: flex; flex-direction: column; gap: 4px; min-width: 120px; }
.cond-param label { font-size: 10px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; }

/* ── Channel Checkboxes ─────────────────────────────────────────── */
.channel-checkboxes {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.channel-check {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition);
  user-select: none;
}

.channel-check input { display: none; }
.channel-check:has(input:checked) {
  background: var(--accent-light);
  border-color: var(--accent-blue);
  color: var(--accent-blue);
}

/* ── Watchlist ─────────────────────────────────────────────────── */
.strategies-info { padding: 0 20px; margin-bottom: 8px; }
.scanner-info { font-size: 12px; color: var(--text-muted); line-height: 1.7; }
.scanner-info p { margin-bottom: 4px; }

/* ══════════════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════════════════════════════════════ */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  max-width: 360px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.3s, transform 0.3s;
  border: 1px solid transparent;
  backdrop-filter: blur(8px);
}

@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }

.toast.success { background: #dcfce7; border-color: #86efac; color: #14532d; }
.toast.error   { background: #fee2e2; border-color: #fca5a5; color: #7f1d1d; }
.toast.info    { background: #dbeafe; border-color: #93c5fd; color: #1e3a8a; }
.toast.warning { background: #fef9c3; border-color: #fde047; color: #713f12; }

[data-theme="dark"] .toast.success { background: #14532d; border-color: #22c55e; color: #86efac; }
[data-theme="dark"] .toast.error   { background: #7f1d1d; border-color: #ef4444; color: #fca5a5; }
[data-theme="dark"] .toast.info    { background: #1e3a8a; border-color: #3b82f6; color: #93c5fd; }
[data-theme="dark"] .toast.warning { background: #713f12; border-color: #f59e0b; color: #fde68a; }

/* ══════════════════════════════════════════════════════════════════════
   POSITIONS MODAL TABLE
   ══════════════════════════════════════════════════════════════════════ */
#positionsTable td, #positionsTable th { padding: 10px 12px; }

/* ══════════════════════════════════════════════════════════════════════
   REQUIRED / OPTIONAL LABELS
   ══════════════════════════════════════════════════════════════════════ */
.required { color: var(--accent-red); font-weight: 700; }
.optional  { font-size: 11px; color: var(--text-muted); font-weight: 400; }

/* ══════════════════════════════════════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .sidebar .logo-text, .sidebar .nav-label, .sidebar .scanner-status span:not(.status-dot) { display: none; }
  .main-content { margin-left: 64px; }
  .pages-container { padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}

/* ── Positions Modal ────────────────────────────────────────────── */
.positions-content { padding: 16px; }