:root {
  --bg-base: #090d16;
  --bg-panel: #111827;
  --bg-card: #161f33;
  --bg-card-hover: #1e2942;
  --border: #26334d;
  --text-main: #f3f6fc;
  --text-muted: #94a3b8;
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --blue: #3b82f6;
  --blue-soft: rgba(59, 130, 246, 0.15);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.15);
  --purple: #8b5cf6;
}

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

body {
  background-color: var(--bg-base);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Desktop Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  padding: 1.25rem 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.5rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #10b981, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.2rem;
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.16s ease;
}

.nav-btn:hover {
  background: var(--bg-card);
  color: var(--text-main);
}

.nav-btn.active {
  background: var(--accent-soft);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.32);
  font-weight: 600;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Main Content Area */
.main-area {
  flex: 1;
  margin-left: 260px;
  padding: 1.5rem 2rem 5rem;
  max-width: 1600px;
}

/* Topbar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.topbar-title h1 {
  font-size: 1.45rem;
  font-weight: 700;
}

.topbar-title p {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 0.95rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--bg-card-hover);
}

.btn-primary {
  background: linear-gradient(135deg, #10b981, #059669);
  border-color: #059669;
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-blue {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  border-color: #2563eb;
  color: #fff;
}

.input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 0.55rem 0.85rem;
  border-radius: 8px;
  font-size: 0.88rem;
  outline: none;
}

.input:focus {
  border-color: var(--accent);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-opportunity {
  background: var(--accent-soft);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-bullish {
  background: var(--blue-soft);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.badge-dca {
  background: rgba(139, 92, 246, 0.16);
  color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, 0.35);
}

.badge-neutral {
  background: rgba(148, 163, 184, 0.14);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.badge-overbought,
.badge-caution {
  background: var(--amber-soft);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* Grid Layouts */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem;
}

.kpi-card {
  background: linear-gradient(180deg, var(--bg-card) 0%, var(--bg-panel) 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.15rem;
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.35rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.kpi-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.desktop-two-col {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

/* AI Briefing Card */
.briefing-box {
  background: linear-gradient(145deg, rgba(16, 185, 129, 0.08), rgba(37, 99, 235, 0.07));
  border: 1px solid rgba(16, 185, 129, 0.32);
  border-radius: 14px;
  padding: 1.3rem;
  margin-bottom: 1.5rem;
}

.briefing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.briefing-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.9rem;
  margin-top: 1rem;
}

.briefing-mini {
  background: rgba(17, 24, 39, 0.78);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  font-size: 0.85rem;
}

.briefing-mini h4 {
  font-size: 0.82rem;
  color: #34d399;
  margin-bottom: 0.35rem;
}

/* Opportunity Cards */
.opp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1rem;
}

.opp-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.05rem;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.opp-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.score-pill {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
}

.score-high {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.score-mid {
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.score-low {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

/* Filter Tabs */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  align-items: center;
  justify-content: space-between;
}

.pill-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill-tab {
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
}

.pill-tab.active {
  background: var(--accent);
  color: #06281e;
  border-color: var(--accent);
}

/* Table (Desktop Scanner) */
.table-wrap {
  overflow-x: auto;
}

.scanner-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.scanner-table th,
.scanner-table td {
  padding: 0.8rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.scanner-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.77rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.scanner-table tr:hover td {
  background: rgba(30, 41, 66, 0.55);
  cursor: pointer;
}

/* Chart Container */
.chart-box {
  background: #0b111e;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  position: relative;
}

.chart-canvas {
  width: 100%;
  height: 320px;
  display: block;
}

.rsi-canvas {
  width: 100%;
  height: 110px;
  display: block;
  margin-top: 0.5rem;
  border-top: 1px dashed var(--border);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}

/* Positive / Negative colors */
.pos {
  color: #34d399;
}
.neg {
  color: #f87171;
}

/* News List */
.news-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.news-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.95rem;
}

.news-item h4 {
  font-size: 0.93rem;
  margin-bottom: 0.35rem;
}

/* Chat Box */
.chat-messages {
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.5rem 0;
  margin-bottom: 1rem;
}

.chat-bubble {
  padding: 0.95rem 1.1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.chat-user {
  background: var(--blue-soft);
  border: 1px solid rgba(59, 130, 246, 0.35);
  align-self: flex-end;
  max-width: 85%;
}

.chat-agent {
  background: var(--bg-card);
  border: 1px solid var(--border);
  align-self: flex-start;
  width: 100%;
}

/* Mobile Bottom Nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(17, 24, 39, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  z-index: 50;
  justify-content: space-around;
  padding: 0.45rem 0.25rem;
}

.mobile-nav-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
}

.mobile-nav-btn.active {
  color: #34d399;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

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

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 520px;
  width: 100%;
  padding: 1.4rem;
}

/* Responsive Breakpoints */
@media (max-width: 1100px) {
  .desktop-two-col {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .briefing-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .sidebar {
    display: none;
  }
  .main-area {
    margin-left: 0;
    padding: 1rem 0.9rem 5.5rem;
  }
  .mobile-nav {
    display: flex;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
  }
  .topbar-title h1 {
    font-size: 1.2rem;
  }
}
