:root {
  --bg: #071018;
  --bg-soft: #0c1722;
  --panel: rgba(13, 26, 39, .82);
  --panel-strong: rgba(17, 34, 49, .96);
  --text: #edf7ff;
  --muted: #88a1b5;
  --line: rgba(148, 183, 210, .16);
  --green: #19d37e;
  --red: #ff5470;
  --amber: #ffbf47;
  --cyan: #2dd4ff;
  --blue: #5d8cff;
  --shadow: 0 22px 70px rgba(0, 0, 0, .34);
  --radius: 8px;
  color-scheme: dark;
}

.theme-light {
  --bg: #eef4f8;
  --bg-soft: #ffffff;
  --panel: rgba(255, 255, 255, .86);
  --panel-strong: rgba(255, 255, 255, .98);
  --text: #0b1720;
  --muted: #526574;
  --line: rgba(17, 34, 49, .14);
  --shadow: 0 20px 60px rgba(28, 45, 64, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(45, 212, 255, .12), transparent 28%),
    radial-gradient(circle at 90% 12%, rgba(25, 211, 126, .12), transparent 24%),
    linear-gradient(135deg, var(--bg), var(--bg-soft));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }

.preloader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  gap: 14px;
  background: var(--bg);
  transition: opacity .35s ease, visibility .35s ease;
}
.preloader.hidden { opacity: 0; visibility: hidden; }
.preloader > div:last-child { display: grid; text-align: center; color: var(--muted); }
.preloader strong { color: var(--text); font-size: 1.2rem; }
.loader-ring {
  width: 62px;
  height: 62px;
  border: 3px solid rgba(45, 212, 255, .18);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: 260px;
  padding: 20px;
  background: rgba(4, 12, 20, .76);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(22px);
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.theme-light .sidebar { background: rgba(255, 255, 255, .74); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #061017;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  border-radius: var(--radius);
  box-shadow: 0 12px 34px rgba(45, 212, 255, .22);
}
.brand b, .brand small { display: block; }
.brand small { color: var(--muted); font-size: .72rem; }
.nav-stack { display: grid; gap: 8px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--muted);
  transition: all .2s ease;
}
.nav-link i { width: 18px; text-align: center; }
.nav-link:hover, .nav-link.active {
  color: var(--text);
  background: rgba(45, 212, 255, .1);
  border-color: rgba(45, 212, 255, .18);
}
.sidebar-card {
  margin-top: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
}
.sidebar-card small { display: block; color: var(--muted); }
.pulse-dot {
  width: 10px;
  height: 10px;
  background: var(--green);
  border-radius: 99px;
  box-shadow: 0 0 0 rgba(25, 211, 126, .7);
  animation: pulse 1.8s infinite;
}

.app-shell {
  min-height: 100vh;
  margin-left: 260px;
  padding: 16px 20px 88px;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  min-height: 70px;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  backdrop-filter: blur(18px);
}
.search-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0 14px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.search-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 80;
  display: none;
  max-height: 310px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}
.search-result {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.search-result:hover { background: rgba(45, 212, 255, .08); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn, .primary-btn, .ghost-btn, .trade-btn {
  border: 0;
  border-radius: var(--radius);
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.icon-btn {
  width: 42px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
}
.primary-btn {
  color: #041019;
  padding: 0 16px;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  font-weight: 800;
}
.ghost-btn {
  color: var(--text);
  padding: 0 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
}
.trade-btn {
  color: #061017;
  padding: 0 18px;
  background: linear-gradient(135deg, var(--amber), var(--green));
  font-weight: 800;
}
.icon-btn:hover, .primary-btn:hover, .ghost-btn:hover, .trade-btn:hover { transform: translateY(-2px); }

.ticker-tape {
  position: relative;
  overflow: hidden;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  margin-bottom: 18px;
}
.ticker-track {
  display: inline-flex;
  align-items: center;
  gap: 18px;
  min-width: 100%;
  height: 100%;
  white-space: nowrap;
  animation: ticker 34s linear infinite;
}
.ticker-item { display: inline-flex; align-items: center; gap: 7px; padding-left: 18px; font-size: .9rem; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.neutral { color: var(--muted); }

.view { display: none; }
.active-view { display: block; }
.hero-grid, .dashboard-grid, .stock-layout, .portfolio-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  gap: 18px;
}
.real-data-notice {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, .9fr);
  gap: 16px;
  margin-bottom: 18px;
  border-color: rgba(255, 191, 71, .35);
}
.real-data-notice p { color: var(--muted); margin-top: 4px; }
.data-settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: min(620px, 100%);
}
.data-diagnostics {
  grid-column: 1 / -1;
  max-height: 150px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, .18);
  white-space: pre-wrap;
  font-size: .82rem;
}
.dashboard-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 18px; }
.stock-layout, .portfolio-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.glass-panel, .panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}
.market-hero {
  min-height: 360px;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, .75fr);
  gap: 22px;
  align-items: stretch;
  overflow: hidden;
}
.hero-copy { display: flex; flex-direction: column; justify-content: center; }
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .72rem;
  font-weight: 800;
}
h1, h2, h3, p { margin: 0; }
h1 { max-width: 760px; font-size: clamp(2.15rem, 4.6vw, 5.4rem); line-height: .94; letter-spacing: 0; }
h2 { font-size: 1.08rem; font-weight: 850; }
.hero-copy p { max-width: 650px; margin-top: 18px; color: var(--muted); font-size: 1.02rem; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 26px; }
.index-card {
  display: grid;
  align-content: space-between;
  min-height: 300px;
  padding: 20px;
  border: 1px solid rgba(45, 212, 255, .18);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(45, 212, 255, .1), rgba(25, 211, 126, .05));
}
.index-card strong { font-size: 2.6rem; }
.index-card small, .index-card span { color: var(--muted); }
.ai-orbit { min-height: 360px; padding: 24px; display: grid; align-content: center; gap: 18px; }
.meter {
  width: 174px;
  height: 174px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--green) calc(var(--score) * 1%), rgba(255,255,255,.08) 0);
  position: relative;
}
.meter:after {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: inherit;
  background: var(--panel-strong);
}
.meter span, .meter small { position: relative; z-index: 1; display: block; text-align: center; }
.meter span { font-size: 2.5rem; font-weight: 900; }
.meter small { color: var(--muted); margin-top: 48px; position: absolute; }
.mini-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mini-stats span { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); }
.mini-stats b { display: block; color: var(--text); font-size: 1.3rem; }
.data-freshness {
  color: var(--muted);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.035);
}
.data-freshness.stale {
  color: var(--amber);
  border-color: rgba(255, 191, 71, .4);
}

.panel { padding: 18px; min-width: 0; }
.source-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: .85rem;
}
.real-board-panel { margin-bottom: 18px; }
.panel-head, .stock-head, .section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.section-title { margin: 10px 0 18px; }
.section-title h2 { font-size: 1.8rem; }
.chart-shell, .candle-chart { min-height: 390px; }
.candle-chart { height: 500px; }
.market-list { display: grid; gap: 10px; }
.market-row, .alert-row, .journal-entry, .news-item, .prediction-card, .indicator-card, .screener-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.035);
}
.market-row strong, .prediction-card strong { display: block; }
.market-row small, .news-item small, .prediction-card small, .indicator-card small { color: var(--muted); }
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 800;
}
.chip.pos { background: rgba(25, 211, 126, .12); }
.chip.neg { background: rgba(255, 84, 112, .12); }
.chip.neutral { background: rgba(148, 163, 184, .12); }
.prediction-list, .indicator-grid { display: grid; gap: 10px; }
.indicator-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.heatmap {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}
.heat-tile {
  min-height: 108px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.12);
  transition: transform .18s ease;
}
.heat-tile:hover { transform: translateY(-3px) scale(1.01); }
.news-feed, .alerts-list, .journal-entries { display: grid; gap: 10px; max-height: 330px; overflow: auto; }
.news-item { align-items: flex-start; flex-direction: column; }
.alert-form, .portfolio-form, .journal-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  margin-bottom: 14px;
}
.journal-form { grid-template-columns: 1fr 160px; }
.journal-form textarea { grid-column: 1 / -1; min-height: 130px; }
.journal-form button { justify-self: start; }
.form-control, .form-select {
  color: var(--text);
  border-color: var(--line);
  background-color: rgba(255,255,255,.04);
}
.form-control:focus, .form-select:focus {
  color: var(--text);
  background-color: rgba(255,255,255,.07);
  border-color: rgba(45, 212, 255, .5);
  box-shadow: 0 0 0 .2rem rgba(45, 212, 255, .12);
}
.theme-light .form-control, .theme-light .form-select { color: var(--text); background-color: #fff; }
.table-panel { overflow: auto; padding: 0; }
.market-table { width: 100%; border-collapse: collapse; min-width: 860px; }
.market-table th, .market-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.market-table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.market-table tr:hover td { background: rgba(45, 212, 255, .06); }
.ai-signal-table { overflow: auto; }
.ai-brief-panel {
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid rgba(45, 212, 255, .2);
  border-radius: var(--radius);
  background: rgba(45, 212, 255, .06);
}
.ai-brief-panel h3 { margin: 0 0 6px; font-size: 1rem; }
.ai-brief-panel p { color: var(--muted); margin-bottom: 8px; }
.ai-brief-panel ul { margin: 0; padding-left: 18px; color: var(--muted); }
.ai-signal-table table { width: 100%; min-width: 1080px; border-collapse: collapse; }
.ai-signal-table th, .ai-signal-table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ai-signal-table th { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; }
.signal-action {
  display: inline-flex;
  min-width: 86px;
  justify-content: center;
  padding: 7px 10px;
  border-radius: var(--radius);
  font-weight: 900;
  font-size: .78rem;
}
.signal-buy { color: #041019; background: var(--green); }
.signal-sell { color: #fff; background: var(--red); }
.signal-hold { color: var(--text); background: rgba(148, 163, 184, .18); }
.why-list { margin: 0; padding-left: 16px; color: var(--muted); }
.live-refresh { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .86rem; }
.ai-signal-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.summary-tile {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,.035);
}
.summary-tile small { color: var(--muted); display: block; }
.stock-actions { display: flex; gap: 10px; align-items: center; }
.stock-ai-panel { display: grid; gap: 12px; }
.prob-bar { height: 10px; overflow: hidden; border-radius: 999px; background: rgba(255,255,255,.08); }
.prob-bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--green), var(--cyan)); }
.filter-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; align-items: end; }
.filter-grid label { color: var(--muted); font-size: .85rem; display: grid; gap: 8px; }
.screener-results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.portfolio-grid { align-items: start; }

.ai-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 70;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  color: #061017;
  background: linear-gradient(135deg, var(--green), var(--cyan));
  box-shadow: 0 18px 44px rgba(45, 212, 255, .28);
}
.ai-chat {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 75;
  width: min(390px, calc(100vw - 32px));
  height: 540px;
  display: none;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.ai-chat.open { display: flex; animation: floatIn .22s ease; }
.ai-chat header, .chat-form { padding: 12px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.ai-chat header { justify-content: space-between; }
.ai-chat small { display: block; color: var(--muted); }
.chat-messages { flex: 1; padding: 12px; overflow: auto; display: grid; align-content: start; gap: 10px; }
.msg { max-width: 86%; padding: 10px 12px; border-radius: var(--radius); background: rgba(255,255,255,.06); }
.msg.user { justify-self: end; color: #061017; background: linear-gradient(135deg, var(--green), var(--cyan)); }
.msg.bot.rich,
.msg.bot:has(.assistant-table) {
  max-width: min(720px, calc(100vw - 34px));
  overflow-x: auto;
}
.assistant-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12px;
}
.assistant-table th,
.assistant-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.assistant-table th { color: var(--muted); font-weight: 700; }
.chat-form { border-top: 1px solid var(--line); border-bottom: 0; }
.chat-form input { flex: 1; border: 0; outline: 0; color: var(--text); background: transparent; }
.chat-form button { width: 42px; height: 42px; border: 0; border-radius: var(--radius); color: #061017; background: var(--cyan); }

.skeleton-line, .skeleton-text {
  background: linear-gradient(90deg, rgba(255,255,255,.06), rgba(255,255,255,.16), rgba(255,255,255,.06));
  background-size: 220% 100%;
  animation: shimmer 1.2s infinite;
  color: transparent !important;
}
