/* =================================================================
   FinIntel Engine — Design System v2
   ================================================================= */

/* ── Google Font ── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ── */
:root {
  --bg-base:        #09090b;
  --bg-surface:     #0f0f12;
  --bg-card:        #18181b;
  --bg-card-alt:    #1c1c20;
  --bg-hover:       #27272a;
  --border:         #27272a;
  --border-light:   #3f3f46;
  --accent-cyan:    #06b6d4;
  --accent-blue:    #3b82f6;
  --accent-purple:  #8b5cf6;
  --accent-green:   #10b981;
  --accent-red:     #ef4444;
  --accent-yellow:  #f59e0b;
  --accent-pink:    #ec4899;
  --text-primary:   #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted:     #52525b;
  --sidebar-w:      228px;
  --topbar-h:       56px;
  --radius:         12px;
  --radius-sm:      8px;
  --shadow-card:    0 2px 12px rgba(0,0,0,0.4);
  --shadow-glow-c:  0 0 16px rgba(6,182,212,0.08);
  --shadow-glow-b:  0 0 16px rgba(59,130,246,0.08);
  --transition:     0.2s ease;
}

/* ── Light Mode ── */
[data-theme="light"] {
  --bg-base:        #f8f9fa;
  --bg-surface:     #ffffff;
  --bg-card:        #ffffff;
  --bg-card-alt:    #f4f4f5;
  --bg-hover:       #f0f0f2;
  --border:         #e4e4e7;
  --border-light:   #d4d4d8;
  --accent-cyan:    #0891b2;
  --accent-blue:    #2563eb;
  --accent-purple:  #7c3aed;
  --accent-green:   #059669;
  --accent-red:     #dc2626;
  --accent-yellow:  #d97706;
  --accent-pink:    #db2777;
  --text-primary:   #18181b;
  --text-secondary: #52525b;
  --text-muted:     #a1a1aa;
  --shadow-card:    0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-glow-c:  none;
  --shadow-glow-b:  none;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-blue); }

/* ── Theme Toggle ── */
.theme-toggle {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-secondary); padding: 5px 8px; cursor: pointer;
  font-size: 0.9rem; display: flex; align-items: center; gap: 4px;
  transition: border-color var(--transition), color var(--transition);
}
.theme-toggle:hover { border-color: var(--accent-cyan); color: var(--accent-cyan); }

/* =================================================================
   PAGE LOADER
   ================================================================= */
#page-loader {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-base);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
#page-loader.hidden { opacity: 0; visibility: hidden; }
.loader-ring {
  width: 48px; height: 48px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent-cyan);
  animation: spin 0.8s linear infinite;
}
.loader-text { font-size: 0.8rem; color: var(--text-secondary); letter-spacing: 0.1em; text-transform: uppercase; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =================================================================
   SIDEBAR
   ================================================================= */
#sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 1000;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
}
.sidebar-logo-icon {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent-cyan);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: #fff; flex-shrink: 0;
}
.sidebar-logo-text { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.sidebar-logo-sub  { font-size: 0.62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

.sidebar-section-label {
  font-size: 0.62rem; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.1em;
  padding: 16px 20px 6px;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 4px 10px; }

.nav-item-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.84rem; font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item-link i { font-size: 1rem; flex-shrink: 0; width: 20px; }
.nav-item-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item-link.active {
  background: var(--bg-hover);
  color: var(--accent-cyan);
  border-left: 2px solid var(--accent-cyan);
}
.nav-item-link .nav-badge {
  margin-left: auto; font-size: 0.62rem; font-weight: 600;
  background: var(--accent-red); color: #fff;
  padding: 1px 6px; border-radius: 999px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.sys-status { display: flex; flex-direction: column; gap: 6px; }
.sys-status-item { display: flex; align-items: center; gap: 8px; font-size: 0.72rem; color: var(--text-secondary); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-dot.online  { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); animation: pulse-dot 2s infinite; }
.status-dot.offline { background: var(--text-muted); }
.status-dot.warn    { background: var(--accent-yellow); box-shadow: 0 0 6px var(--accent-yellow); }
@keyframes pulse-dot { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* =================================================================
   MAIN WRAPPER
   ================================================================= */
#main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* =================================================================
   TOPBAR
   ================================================================= */
#topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
  position: sticky; top: 0; z-index: 100;
}

.topbar-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; }

.live-badge {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.68rem; font-weight: 600;
  color: var(--accent-green); text-transform: uppercase; letter-spacing: 0.06em;
  background: rgba(16,185,129,0.1); padding: 3px 8px; border-radius: 999px;
  border: 1px solid rgba(16,185,129,0.2);
  white-space: nowrap;
}
.live-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-green); animation: pulse-dot 1.5s infinite; }

/* ── Ticker tape ── */
.ticker-wrapper {
  flex: 1; overflow: hidden; position: relative;
  mask-image: linear-gradient(90deg, transparent 0%, black 5%, black 95%, transparent 100%);
}
.ticker-track {
  display: flex; gap: 32px; white-space: nowrap;
  animation: ticker-scroll 35s linear infinite;
}
.ticker-track:hover { animation-play-state: paused; }
.ticker-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; }
.ticker-symbol { font-weight: 700; color: var(--text-primary); }
.ticker-price  { color: var(--text-secondary); }
.ticker-change.up   { color: var(--accent-green); }
.ticker-change.down { color: var(--accent-red); }
@keyframes ticker-scroll { from{transform:translateX(0)} to{transform:translateX(-50%)} }

.topbar-time { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.topbar-refresh {
  background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-secondary); padding: 5px 8px; cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  font-size: 0.85rem; display: flex; align-items: center; gap: 5px;
}
.topbar-refresh:hover { border-color: var(--accent-cyan); color: var(--accent-cyan); }
.topbar-refresh.spinning i { animation: spin 0.6s linear infinite; }

/* =================================================================
   PAGE CONTENT
   ================================================================= */
#page-content { padding: 20px; flex: 1; }

/* =================================================================
   GLASS CARDS
   ================================================================= */
.g-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  overflow: hidden;
}
.g-card:hover { border-color: var(--border-light); }

.g-card-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.84rem; font-weight: 600; color: var(--text-primary);
}
.g-card-header .header-icon {
  width: 28px; height: 28px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; flex-shrink: 0;
}
.g-card-header .ms-auto { margin-left: auto; }
.g-card-body { padding: 16px 18px; }
.g-card-footer { padding: 12px 18px; border-top: 1px solid var(--border); }

/* Header icon variants */
.hi-cyan   { background: rgba(0,212,255,0.12);  color: var(--accent-cyan); }
.hi-blue   { background: rgba(59,130,246,0.12); color: var(--accent-blue); }
.hi-green  { background: rgba(16,185,129,0.12); color: var(--accent-green); }
.hi-red    { background: rgba(239,68,68,0.12);  color: var(--accent-red); }
.hi-yellow { background: rgba(245,158,11,0.12); color: var(--accent-yellow); }
.hi-purple { background: rgba(139,92,246,0.12); color: var(--accent-purple); }

/* =================================================================
   KPI CARDS
   ================================================================= */
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  position: relative; overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.kpi-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: var(--kpi-accent, var(--accent-cyan));
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card), 0 0 24px rgba(0,0,0,0.3); border-color: var(--border-light); }
.kpi-card .kpi-icon {
  width: 36px; height: 36px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; margin-bottom: 10px;
  background: rgba(255,255,255,0.05);
}
.kpi-card .kpi-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 4px; }
.kpi-card .kpi-value { font-size: 1.8rem; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.kpi-card .kpi-sub   { font-size: 0.72rem; color: var(--text-muted); margin-top: 6px; }
.kpi-card .kpi-bg-icon {
  position: absolute; bottom: -4px; right: 6px;
  font-size: 3.2rem; color: var(--kpi-accent, var(--accent-cyan));
  opacity: 0.06; pointer-events: none;
}
.kpi-clickable {
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.kpi-clickable:hover {
  transform: translateY(-3px);
  border-color: var(--kpi-accent, var(--accent-cyan));
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.kpi-clickable:active { transform: translateY(0); }

/* =================================================================
   MARKET PRICES TABLE
   ================================================================= */
.prices-table { width: 100%; border-collapse: collapse; }
.prices-table thead th {
  font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-muted); padding: 8px 14px; border-bottom: 1px solid var(--border);
}
.prices-table tbody tr {
  border-bottom: 1px solid rgba(22,44,74,0.5);
  transition: background var(--transition);
  cursor: default;
}
.prices-table tbody tr:hover { background: var(--bg-hover); }
.prices-table tbody tr:last-child { border-bottom: none; }
.prices-table td { padding: 10px 14px; font-size: 0.83rem; vertical-align: middle; }
.ticker-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 0.83rem;
}
.ticker-chip .t-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-cyan); }
.price-up   { color: var(--accent-green); font-weight: 600; }
.price-down { color: var(--accent-red);   font-weight: 600; }
.change-pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
}
.change-pill.up   { background: rgba(16,185,129,0.12); color: var(--accent-green); }
.change-pill.down { background: rgba(239,68,68,0.12);  color: var(--accent-red); }
.vol-bar { height: 4px; border-radius: 2px; background: rgba(59,130,246,0.2); margin-top: 3px; }
.vol-bar-fill { height: 100%; border-radius: 2px; background: var(--accent-blue); min-width: 2px; }

/* =================================================================
   SENTIMENT DONUT CHART
   ================================================================= */
.donut-wrap { position: relative; display: flex; align-items: center; justify-content: center; }
.donut-center {
  position: absolute; text-align: center; pointer-events: none;
}
.donut-center .dc-value { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); }
.donut-center .dc-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.sentiment-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.legend-item .l-label { color: var(--text-secondary); flex: 1; }
.legend-item .l-value { font-weight: 600; color: var(--text-primary); }

/* =================================================================
   RISK ALERTS
   ================================================================= */
.risk-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(22,44,74,0.5);
  transition: background var(--transition);
}
.risk-item:last-child { border-bottom: none; padding-bottom: 0; }
.risk-level-icon {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 0.75rem;
}
.risk-level-icon.high   { background: rgba(239,68,68,0.15);  color: var(--accent-red); }
.risk-level-icon.medium { background: rgba(245,158,11,0.15); color: var(--accent-yellow); }
.risk-level-icon.low    { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.risk-ticker { font-weight: 700; font-size: 0.78rem; color: var(--text-primary); }
.risk-signal { font-size: 0.76rem; color: var(--text-secondary); }
.risk-detail { font-size: 0.71rem; color: var(--text-muted); margin-top: 2px; line-height: 1.3; }
.risk-time   { font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; margin-left: auto; flex-shrink: 0; }

/* =================================================================
   NEWS FEED
   ================================================================= */
.news-tabs .nav-link {
  font-size: 0.75rem; font-weight: 500; padding: 5px 12px; border-radius: 999px;
  color: var(--text-secondary); border: 1px solid transparent;
  transition: all var(--transition); cursor: pointer;
}
.news-tabs .nav-link:hover { color: var(--text-primary); border-color: var(--border-light); }
.news-tabs .nav-link.active {
  background: rgba(0,212,255,0.1); color: var(--accent-cyan);
  border-color: rgba(0,212,255,0.3);
}

.news-item {
  padding: 12px 0;
  border-bottom: 1px solid rgba(22,44,74,0.5);
  transition: opacity var(--transition);
}
.news-item:last-child { border-bottom: none; }
.news-item-title {
  font-size: 0.83rem; font-weight: 500; color: var(--text-primary);
  text-decoration: none; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  transition: color var(--transition);
}
.news-item-title:hover { color: var(--accent-cyan); }
.news-item-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; flex-wrap: wrap; }
.news-source { font-size: 0.68rem; color: var(--text-muted); font-weight: 500; }
.news-time   { font-size: 0.66rem; color: var(--text-muted); }
.news-summary { font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sent-badge {
  font-size: 0.63rem; font-weight: 600; padding: 2px 7px; border-radius: 999px; text-transform: capitalize;
}
.sent-badge.positive { background: rgba(16,185,129,0.12); color: var(--accent-green); }
.sent-badge.negative { background: rgba(239,68,68,0.12);  color: var(--accent-red); }
.sent-badge.neutral  { background: rgba(59,130,246,0.10); color: var(--accent-blue); }

/* =================================================================
   CHAT
   ================================================================= */
#chat-messages {
  scroll-behavior: smooth;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-msg { display: flex; gap: 8px; align-items: flex-end; max-width: 90%; animation: msg-in 0.2s ease; }
@keyframes msg-in { from{opacity:0;transform:translateY(8px)} to{opacity:1;transform:none} }
.chat-msg.user-msg { margin-left: auto; flex-direction: row-reverse; }

.chat-avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 0.75rem;
}
.chat-avatar.agent-av { background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple)); color: #fff; }
.chat-avatar.user-av  { background: var(--bg-hover); color: var(--text-secondary); border: 1px solid var(--border-light); }

.chat-bubble {
  padding: 9px 13px; border-radius: 12px; font-size: 0.82rem; line-height: 1.5;
  max-width: 100%;
}
.agent-bubble { background: var(--bg-card-alt); border: 1px solid var(--border-light); color: var(--text-primary); border-bottom-left-radius: 3px; }
.user-bubble  { background: rgba(59,130,246,0.18); border: 1px solid rgba(59,130,246,0.3); color: var(--text-primary); border-bottom-right-radius: 3px; }

.agent-cards { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.agent-card-mini {
  background: rgba(5,16,31,0.6); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 7px 10px; font-size: 0.74rem;
}
.agent-card-mini .ac-name { color: var(--accent-cyan); font-weight: 600; font-size: 0.7rem; margin-bottom: 2px; }
.agent-card-mini .ac-text { color: var(--text-secondary); }

.typing-dots span {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-secondary); animation: typing 1.2s infinite;
  margin: 0 1px;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-5px)} }

.quick-chip {
  font-size: 0.71rem; padding: 4px 10px; border-radius: 999px; cursor: pointer;
  background: rgba(255,255,255,0.03); border: 1px solid var(--border-light);
  color: var(--text-secondary); transition: all var(--transition); white-space: nowrap;
}
.quick-chip:hover { background: rgba(0,212,255,0.08); border-color: rgba(0,212,255,0.3); color: var(--accent-cyan); }

.chat-input-wrap {
  display: flex; gap: 8px; align-items: center;
  background: var(--bg-card-alt); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 6px 6px 12px;
  transition: border-color var(--transition);
}
.chat-input-wrap:focus-within { border-color: rgba(0,212,255,0.4); box-shadow: 0 0 0 3px rgba(0,212,255,0.05); }
.chat-input-wrap input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 0.83rem;
  font-family: inherit;
}
.chat-input-wrap input::placeholder { color: var(--text-muted); }
.chat-send-btn {
  width: 32px; height: 32px; border-radius: 7px; border: none;
  background: var(--accent-cyan);
  color: #fff; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; font-size: 0.8rem;
  transition: opacity var(--transition), transform var(--transition);
}
.chat-send-btn:hover { opacity: 0.88; transform: scale(1.05); }
.chat-send-btn:disabled { opacity: 0.4; cursor: default; transform: none; }

/* =================================================================
   SENTIMENT TREND CHART
   ================================================================= */
.chart-container { position: relative; }

/* =================================================================
   NEWS DETAIL MODAL
   ================================================================= */
.news-modal-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.35);
  display: flex; align-items: stretch; justify-content: flex-end;
  animation: modal-fade-in 0.2s ease;
}
@keyframes modal-fade-in { from{opacity:0} to{opacity:1} }
.news-modal {
  background: var(--bg-surface);
  border-left: 1px solid var(--border-light);
  box-shadow: -8px 0 40px rgba(0,0,0,0.45);
  width: 440px; max-width: 92vw;
  height: 100vh; overflow-y: auto;
  position: relative; flex-shrink: 0;
  animation: modal-slide-in 0.25s cubic-bezier(0.16,1,0.3,1);
}
@keyframes modal-slide-in { from{opacity:0;transform:translateX(40px)} to{opacity:1;transform:none} }
.news-modal-close {
  position: absolute; top: 12px; right: 12px;
  background: var(--bg-hover); border: 1px solid var(--border);
  border-radius: 8px; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); cursor: pointer; font-size: 0.85rem;
  transition: all var(--transition); z-index: 1;
}
.news-modal-close:hover { background: var(--accent-red); color: #fff; border-color: var(--accent-red); }
.news-modal-body { padding: 28px; }
.news-item-clickable { cursor: pointer; }
.news-item-clickable:hover { background: var(--bg-hover); margin: 0 -18px; padding: 12px 18px; border-radius: var(--radius-sm); }

/* =================================================================
   STOCK SEARCH BAR
   ================================================================= */
.stock-search-wrap {
  position: relative;
  display: flex; align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  gap: 6px;
  min-width: 200px; max-width: 280px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.stock-search-wrap.focused {
  border-color: rgba(0,212,255,0.5);
  box-shadow: 0 0 0 3px rgba(0,212,255,0.08);
}
.stock-search-icon { color: var(--text-muted); font-size: 0.82rem; flex-shrink: 0; }
.stock-search-input {
  background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 0.8rem; font-family: inherit;
  width: 100%;
}
.stock-search-input::placeholder { color: var(--text-muted); }

.search-dropdown {
  display: none;
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  max-height: 320px; overflow-y: auto;
  z-index: 200;
}
.search-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid rgba(22,44,74,0.4);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.highlighted {
  background: var(--bg-hover);
}
.search-item-sym {
  font-weight: 700; font-size: 0.82rem; color: var(--accent-cyan);
  min-width: 60px;
}
.search-item-desc {
  font-size: 0.75rem; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* =================================================================
   STOCK DETAIL PAGE
   ================================================================= */
.sd-range-btn {
  font-size: 0.7rem; font-weight: 600; padding: 4px 10px;
  border-radius: 999px; cursor: pointer;
  background: none; border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all var(--transition);
}
.sd-range-btn:hover { border-color: var(--border-light); color: var(--text-primary); }
.sd-range-btn.active {
  background: rgba(0,212,255,0.12); color: var(--accent-cyan);
  border-color: rgba(0,212,255,0.3);
}

.sd-financials-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
}
.sd-fin-item {
  background: var(--bg-card-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  transition: border-color var(--transition), transform var(--transition);
}
.sd-fin-item:hover { border-color: var(--border-light); transform: translateY(-2px); }
.sd-fin-icon {
  font-size: 1rem; color: var(--accent-cyan);
  margin-bottom: 6px;
}
.sd-fin-label {
  font-size: 0.65rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 4px;
}
.sd-fin-value {
  font-size: 1.1rem; font-weight: 700; color: var(--text-primary);
}

/* =================================================================
   RESPONSIVE
   ================================================================= */
@media (max-width: 991.98px) {
  #sidebar { transform: translateX(calc(-1 * var(--sidebar-w))); }
  #sidebar.open { transform: translateX(0); }
  #main-wrapper { margin-left: 0; }
  #topbar { padding: 0 14px; }
  #page-content { padding: 14px; }
  .stock-search-wrap { min-width: 140px; max-width: 200px; }
  .sd-financials-grid { grid-template-columns: repeat(2, 1fr); }
}

/* =================================================================
   FULL-PAGE CHAT LAYOUT
   ================================================================= */
#sec-chat { padding: 0 !important; height: calc(100vh - var(--topbar-h)); display: none; }
#sec-chat.active-section { display: flex !important; flex-direction: column; }

.chat-fullpage {
  display: flex; flex-direction: column;
  height: calc(100vh - var(--topbar-h));
  background: var(--bg-main);
  overflow: hidden;
}

/* Header */
.cfp-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  padding: 14px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg-card); flex-shrink: 0;
}
.cfp-badge-rag {
  font-size: 0.62rem; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: rgba(139,92,246,0.15); color: var(--accent-purple);
  border: 1px solid rgba(139,92,246,0.3);
}
.cfp-agent-pill {
  font-size: 0.7rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  border: 1px solid; display: flex; align-items: center; gap: 5px;
}

/* Pipeline visualization */
.cfp-pipeline {
  display: none; align-items: center; justify-content: center;
  padding: 18px 24px; gap: 0;
  background: linear-gradient(180deg, var(--bg-card) 0%, transparent 100%);
  border-bottom: 1px solid var(--border); flex-shrink: 0; flex-wrap: nowrap; overflow-x: auto;
}

.pipeline-node {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 12px 16px; border-radius: 12px; min-width: 110px;
  background: var(--bg-card); border: 2px solid var(--border);
  transition: all 0.4s ease; position: relative; flex-shrink: 0;
}
.pipeline-node.pn-active {
  border-color: var(--accent-cyan);
  background: rgba(6,182,212,0.08);
  box-shadow: 0 0 20px rgba(6,182,212,0.25), 0 0 40px rgba(6,182,212,0.1);
  animation: node-pulse 1.4s ease-in-out infinite;
}
.pipeline-node.pn-done {
  border-color: rgba(16,185,129,0.5);
  background: rgba(16,185,129,0.06);
}
.pipeline-node.pn-done::after {
  content: '✓'; position: absolute; top: -8px; right: -8px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-green); color: #000; font-size: 0.65rem;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  display: flex;
}
@keyframes node-pulse {
  0%, 100% { box-shadow: 0 0 15px rgba(6,182,212,0.2); }
  50%       { box-shadow: 0 0 30px rgba(6,182,212,0.5), 0 0 60px rgba(6,182,212,0.15); }
}

.pn-icon { font-size: 1.4rem; color: var(--text-muted); transition: color 0.3s; }
.pipeline-node.pn-active .pn-icon { color: var(--accent-cyan); }
.pipeline-node.pn-done  .pn-icon  { color: var(--accent-green); }
.pn-label { font-size: 0.72rem; font-weight: 700; color: var(--text-secondary); text-align: center; }
.pn-sub   { font-size: 0.62rem; color: var(--text-muted); text-align: center; white-space: nowrap; }
.pipeline-node.pn-active .pn-sub { color: var(--accent-cyan); }

.pipeline-connector {
  display: flex; align-items: center; gap: 0; flex-shrink: 0; padding: 0 4px;
}
.pc-line {
  display: block; height: 2px; width: 28px;
  background: var(--border); border-radius: 2px;
  transition: background 0.4s;
}
.pc-arrow { color: var(--text-muted); font-size: 0.7rem; transition: color 0.4s; }
.pipeline-connector.pc-done .pc-line  { background: var(--accent-green); }
.pipeline-connector.pc-done .pc-arrow { color: var(--accent-green); }

/* Messages area */
.cfp-messages {
  flex: 1; overflow-y: auto; padding: 24px 32px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}
.cfp-messages::-webkit-scrollbar { width: 5px; }
.cfp-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Welcome state */
.cfp-welcome {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; flex: 1; padding: 40px 20px;
}
.cfp-welcome-icon {
  font-size: 3.5rem; color: var(--accent-purple); margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%,100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
.cfp-welcome-title { font-size: 1.3rem; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
.cfp-welcome-sub   { font-size: 0.85rem; color: var(--text-muted); max-width: 420px; }

/* Chat message bubbles */
.chat-msg        { display: flex; gap: 10px; align-items: flex-start; max-width: 85%; }
.user-msg        { align-self: flex-end; flex-direction: row-reverse; max-width: 60%; }
.chat-avatar     { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; flex-shrink: 0; }
.agent-av        { background: rgba(139,92,246,0.15); color: var(--accent-purple); border: 1px solid rgba(139,92,246,0.3); }
.user-av         { background: rgba(6,182,212,0.15); color: var(--accent-cyan); border: 1px solid rgba(6,182,212,0.3); }
.chat-bubble     { padding: 12px 16px; border-radius: 14px; font-size: 0.82rem; line-height: 1.65; }
.agent-bubble    { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary); border-radius: 4px 14px 14px 14px; width: 100%; }
.user-bubble     { background: rgba(6,182,212,0.12); border: 1px solid rgba(6,182,212,0.25); color: var(--text-primary); border-radius: 14px 4px 14px 14px; }

/* Input bar */
.cfp-input-bar {
  padding: 14px 24px 18px; border-top: 1px solid var(--border);
  background: var(--bg-card); flex-shrink: 0;
}

/* =================================================================
   MULTI-AGENT CHAT RESPONSE
   ================================================================= */
.agent-direct {
  font-size: 0.82rem; color: var(--text-secondary); line-height: 1.72;
  white-space: pre-wrap;
}
.agent-greeting {
  padding: 14px 16px; background: rgba(139,92,246,0.07);
  border: 1px solid rgba(139,92,246,0.2); border-radius: 12px;
  font-size: 0.82rem; color: var(--text-secondary); line-height: 1.7;
}
.agent-response { width: 100%; }
.agent-tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); margin-bottom: 12px; padding-bottom: 0;
}
.agent-tab-btn {
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 7px 12px; margin-bottom: -1px;
  font-size: 0.72rem; font-weight: 600; cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition), border-color var(--transition);
  display: flex; align-items: center; gap: 5px;
}
.agent-tab-btn:hover  { color: var(--text-secondary); }
.agent-tab-btn.active { color: var(--accent-cyan); }
.agent-tab-panel { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.65; }
.agent-summary {
  margin-top: 10px; padding: 10px 12px;
  background: rgba(255,221,51,0.06); border-left: 3px solid var(--accent-yellow);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.78rem; color: var(--text-secondary); line-height: 1.6;
}
.agent-sources {
  margin-top: 8px; font-size: 0.72rem; color: var(--text-muted);
}
.agent-sources summary {
  cursor: pointer; padding: 4px 0; font-weight: 600; color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px;
}
.agent-sources ul { margin: 6px 0 0 12px; padding: 0; list-style: disc; }
.agent-sources li { margin: 3px 0; }
.agent-sources a  { color: var(--accent-cyan); text-decoration: none; }
.agent-sources a:hover { text-decoration: underline; }
.sent-badge {
  display: inline-block; font-size: 0.62rem; padding: 1px 6px; border-radius: 999px; font-weight: 600; margin-left: 4px;
}
.sent-badge.positive { background: rgba(0,230,118,0.15); color: var(--accent-green); }
.sent-badge.negative { background: rgba(255,77,77,0.15);  color: var(--accent-red); }
.sent-badge.neutral  { background: rgba(122,154,191,0.12); color: var(--text-muted); }

/* =================================================================
   UTILITY
   ================================================================= */
.text-cyan   { color: var(--accent-cyan) !important; }
.text-green  { color: var(--accent-green) !important; }
.text-red    { color: var(--accent-red) !important; }
.text-yellow { color: var(--accent-yellow) !important; }
.text-purple { color: var(--accent-purple) !important; }
.text-blue   { color: var(--accent-blue) !important; }
.text-sec    { color: var(--text-secondary) !important; }
.text-dim    { color: var(--text-muted) !important; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.gap-6  { gap: 6px !important; }
.gap-8  { gap: 8px !important; }
.fs-11  { font-size: 0.68rem; }
.fs-12  { font-size: 0.75rem; }
.fs-13  { font-size: 0.81rem; }
