/* ============================================================
   Theme tokens — dark (default) + light override.
   Every color in the app resolves through these variables so the
   light/dark toggle in the topbar recolors everything, charts
   included (app.js reads these same vars at chart-render time).
   ============================================================ */
:root {
  color-scheme: dark;
  --bg: #0e0f13;
  --panel: #16181f;
  --panel-2: #1c1f28;      /* slightly elevated surface: inputs, bubbles, code */
  --panel-border: #262b38;
  --input-bg: #0f1117;
  --input-border: #313747;
  --text: #e6e8ee;
  --muted: #8a90a2;
  /* Brand accent -- SalsaTrade's gradient runs red -> orange -> gold; orange
     is the color the logo itself uses for "salsa" against a dark background
     (see brand/salsatrade-logo-full-dark.svg), so the app's accent mirrors it
     exactly rather than picking a different shade. */
  --accent: #F2762E;
  --accent-2: #F7B733;     /* gold -- gradient's warm end, used sparingly for highlights */
  --accent-contrast: #ffffff;
  --success: #3ecf8e;
  --danger: #ff5c5c;
  --warn: #ffb057;
  --chart-grid: #21252f;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.30);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #e7ebf1;            /* clearly grey so white cards stand out */
  --panel: #ffffff;
  --panel-2: #eef1f6;
  --panel-border: #c3ccda;  /* strong enough to actually see card/section edges */
  --input-bg: #ffffff;
  --input-border: #aab4c6;  /* dark enough that empty fields are obvious */
  --text: #12151d;
  --muted: #55607a;
  /* A touch deeper than the dark-theme orange -- better contrast against a
     white background, and stays visually distinct from --danger's reds. */
  --accent: #d9691e;
  --accent-2: #b8790a;
  --accent-contrast: #ffffff;
  --success: #0d8f52;
  --danger: #cf3030;
  --warn: #a5650a;
  --chart-grid: #d6dbe4;
  --shadow: 0 12px 32px rgba(20,30,60,0.14);
  --shadow-sm: 0 1px 3px rgba(20,30,60,0.10);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

/* -------------------------------------------------- Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--panel-border);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  margin-right: auto;
}
/* Two logo variants swap via the same [data-theme] attribute the rest of the
   palette uses -- "for-dark" (light text) shows on the dark theme, "for-light"
   (dark text) shows once [data-theme="light"] is set on <html>. */
.brand-logo { height: 24px; width: auto; display: block; }
.brand-logo.for-light { display: none; }
[data-theme="light"] .brand-logo.for-dark { display: none; }
[data-theme="light"] .brand-logo.for-light { display: block; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: 1px solid var(--panel-border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: border-color 0.15s ease, transform 0.05s ease;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn:active { transform: translateY(1px); }

select, input, textarea {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* -------------------------------------------------- Tabs */
.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 24px 0;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
  overflow-x: auto;
  scrollbar-width: thin;
}
.tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: color 0.15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

#content { padding: 24px; max-width: 1120px; margin: 0 auto; }

.tab-panel { display: none; animation: fadeIn 0.18s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

/* -------------------------------------------------- Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.card h3 {
  margin-top: 0;
  margin-bottom: 14px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

/* -------------------------------------------------- Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: filter 0.15s ease, transform 0.05s ease, border-color 0.15s ease;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-secondary { background: var(--panel-2); color: var(--text); border-color: var(--panel-border); }
.btn-success { background: var(--success); color: #06231a; }
.btn-danger { background: var(--danger); color: #2a0a0a; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

.control-row { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.bot-status { font-weight: 600; margin-right: auto; }

/* -------------------------------------------------- Dashboard hero + quick actions */
.dashboard-hero {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent), var(--accent-2, var(--accent)));
  border-radius: 20px;
  padding: 26px 28px;
  margin-bottom: 16px;
  color: #ffffff;
  box-shadow: 0 14px 34px color-mix(in srgb, var(--accent) 32%, transparent);
  animation: heroIn 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
/* Soft diagonal shine so the flat gradient reads richer, plus a faint radial
   glow in the corner -- gives the card depth without any hard edges. */
.dashboard-hero::after {
  content: "";
  position: absolute;
  top: -60%; right: -20%;
  width: 60%; height: 220%;
  background: radial-gradient(closest-side, rgba(255,255,255,0.22), transparent 70%);
  transform: rotate(18deg);
  pointer-events: none;
}
.dashboard-hero > * { position: relative; z-index: 1; }
.dashboard-hero .hero-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em;
  opacity: 0.85; font-weight: 600;
}
.dashboard-hero .hero-value {
  font-size: 42px; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px;
  font-variant-numeric: tabular-nums;  /* digits don't jitter width during count-up */
}
.dashboard-hero .hero-sub { font-size: 14px; opacity: 0.92; margin-top: 6px; min-height: 20px; }
.dashboard-hero .bot-status {
  display: inline-flex; align-items: center; gap: 7px;
  margin: 14px 0 0; padding: 5px 13px;
  background: rgba(255,255,255,0.18); border-radius: 999px; font-size: 12px; font-weight: 600;
}
.dashboard-hero .bot-status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,0.75); flex: none;
}
.dashboard-hero .bot-status.positive { background: rgba(255,255,255,0.28); }
.dashboard-hero .bot-status.positive::before {
  background: #ffffff; box-shadow: 0 0 0 0 rgba(255,255,255,0.7);
  animation: livePulse 1.8s ease-out infinite;
}
@keyframes heroIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.55); }
  70% { box-shadow: 0 0 0 7px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.quick-action {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 16px 10px; border-radius: 16px; font-size: 12.5px;
  transition: transform 0.12s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.quick-action:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.quick-action:active { transform: translateY(0); }
.quick-action .qa-icon { font-size: 20px; line-height: 1; }
.quick-action .qa-label { font-weight: 600; }

@media (max-width: 640px) {
  .dashboard-hero { padding: 20px 20px; border-radius: 18px; }
  .dashboard-hero .hero-value { font-size: 32px; }
  .quick-actions { grid-template-columns: repeat(2, 1fr); }
}

/* -------------------------------------------------- Summary cards */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.summary-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.14s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.summary-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: color-mix(in srgb, var(--accent) 40%, var(--panel-border)); }
.summary-card .label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
/* A small colored dot per metric instead of an edge stripe -- gives each card
   its own identity while staying clean. Color is set inline per card in JS. */
.summary-card .label .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.summary-card .value { font-size: 23px; font-weight: 700; margin-top: 8px; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.positive { color: var(--success); }
.negative { color: var(--danger); }

/* Subtle staggered entrance for the persistent cards in whichever panel is
   active (NOT the summary cards -- those re-render on the 12s live refresh and
   would replay the animation each time). Fires once when a tab is shown. */
.tab-panel.active > .card,
.tab-panel.active > .dash-charts,
.tab-panel.active > .summary-cards { animation: cardIn 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
.tab-panel.active > .quick-actions { animation: cardIn 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both; animation-delay: 0.04s; }
.tab-panel.active > .card:nth-of-type(2) { animation-delay: 0.06s; }
.tab-panel.active > .card:nth-of-type(3) { animation-delay: 0.1s; }
.tab-panel.active > .card:nth-of-type(4) { animation-delay: 0.14s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.card { transition: box-shadow 0.18s ease, border-color 0.18s ease; }

/* -------------------------------------------------- Dashboard charts row */
.dash-charts { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; margin-bottom: 18px; }
/* min-width:0 lets the fr ratio hold -- without it a grid item's min-content
   (a chart canvas) can blow the column out to thousands of px. */
.dash-charts .dash-chart-card { margin-bottom: 0; min-width: 0; }
.allocation-wrap { display: flex; align-items: center; gap: 18px; }
.chart-box-donut { position: relative; width: 200px; height: 200px; flex: none; }
.allocation-legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 9px; }
.alloc-legend-item { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.alloc-legend-item .swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.alloc-legend-item .sym { font-weight: 600; }
.alloc-legend-item .pct { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
@media (max-width: 900px) {
  .dash-charts { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .allocation-wrap { flex-direction: column; gap: 14px; }
  .chart-box-donut { width: 190px; height: 190px; }
  .allocation-legend { width: 100%; }
}

/* -------------------------------------------------- Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--panel-border); }
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.12s ease; }
.data-table tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }

/* -------------------------------------------------- Forms */
.inline-form { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

.muted { color: var(--muted); font-size: 13px; }
p.muted { margin: 10px 0; line-height: 1.6; }
.inline-form + .muted, .muted.inline { margin-left: 6px; }

/* Code / preformatted blocks (Help + Strategy Guide) — theme-aware */
.code-block, pre.code-block {
  background: var(--panel-2);
  border: 1px solid var(--panel-border);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 12px;
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}
code { font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace; font-size: 0.92em; }

/* -------------------------------------------------- Modal */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
  backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 24px; width: 360px;
  box-shadow: var(--shadow);
}
.modal-content label { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.remove-link { color: var(--danger); cursor: pointer; font-size: 13px; font-weight: 500; }
.remove-link:hover { text-decoration: underline; }

.conn-status { font-size: 12px; font-weight: 600; margin-left: 8px; text-transform: none; letter-spacing: 0; }
.conn-status.ok { color: var(--success); }
.conn-status.off { color: var(--muted); }

/* -------------------------------------------------- Subtabs */
.subtabs { display: flex; gap: 2px; margin: 4px 0 16px; border-bottom: 1px solid var(--panel-border); }
.subtab {
  background: transparent; border: none; color: var(--muted);
  padding: 8px 14px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 13px; font-weight: 500;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--text); border-bottom-color: var(--accent); }
.subtab-panel { display: none; }
.subtab-panel.active { display: block; }

/* Range / segmented buttons on the chart */
.range-btn { padding: 7px 13px; }
.range-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

/* -------------------------------------------------- Autocomplete */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm); margin-top: 4px; max-height: 220px; overflow-y: auto;
  box-shadow: var(--shadow);
}
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-size: 14px; }
.autocomplete-item:hover, .autocomplete-item.highlighted { background: var(--panel-2); }
.autocomplete-item .symbol { font-weight: 600; margin-right: 8px; }
.autocomplete-item .name { color: var(--muted); font-size: 13px; }
.autocomplete-empty { padding: 8px 12px; color: var(--muted); font-size: 13px; }

/* -------------------------------------------------- SEC action badges */
.action-badge { padding: 2px 8px; border-radius: 4px; font-size: 12px; display: inline-block; }
.action-executed { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.action-ignored { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--muted); }
.action-failed { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.action-backfill { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }

/* ============================================================
   SEC monitor per-stock progress
   ============================================================ */
.sec-progress-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.sec-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  font-size: 13px;
}
.sec-chip .tk { font-weight: 600; }
.sec-chip .st { margin-left: auto; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.sec-chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.sec-chip.processing .dot { background: var(--accent); animation: pulse 1s infinite ease-in-out; }
.sec-chip.done .dot { background: var(--success); }
.sec-chip.pending .dot { background: var(--muted); opacity: 0.5; }
.sec-chip.error .dot, .sec-chip.no_cik .dot { background: var(--danger); }
.sec-chip .mini-spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--panel-border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite; flex: none;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ============================================================
   Charts tab: loading overlay + chart surfaces
   ============================================================ */
.chart-host { position: relative; }

/* Chart.js needs an explicitly-sized, positioned parent when
   maintainAspectRatio:false (see app.js) -- otherwise it falls back to a
   width/2 aspect ratio, which on a narrow phone viewport produces a chart
   barely 150-170px tall. These give every chart a real, legible height on
   any screen size instead of shrinking proportionally with width. */
.chart-box { position: relative; width: 100%; height: 320px; }
.chart-box-sm { height: 100px; }
.chart-box-md { height: 220px; }

@media (max-width: 640px) {
  .chart-box { height: 240px; }
  .chart-box-sm { height: 80px; }
  .chart-box-md { height: 180px; }
}

/* chartjs-plugin-zoom's pinch/pan needs to see the raw touch events itself --
   otherwise the browser's default touch handling (page scroll/native pinch-
   zoom) claims the gesture first and the plugin never gets a chance to
   interpret it, so pinch-to-zoom silently does nothing on a touchscreen.
   Only the three charts with zoom/pan enabled (see app.js) need this --
   the plain dashboard equity chart still scrolls normally with the page. */
#ticker-chart, #volume-chart, #comparison-chart { touch-action: none; }
.chart-loading {
  position: absolute; inset: 0; z-index: 15;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  background: color-mix(in srgb, var(--panel) 72%, transparent);
  backdrop-filter: blur(2px);
  border-radius: var(--radius);
  cursor: progress;
}
.chart-loading.hidden { display: none; }
.chart-loading .spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--panel-border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
.chart-loading .loading-text { color: var(--muted); font-size: 13px; font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }

.chart-controls-disabled { opacity: 0.55; pointer-events: none; }

.chart-caption {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  color: var(--muted); font-size: 12px; margin: 8px 2px 2px;
}
.legend-dot { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot::before {
  content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--muted);
}
.legend-dot.up::before { background: var(--success); }
.legend-dot.down::before { background: var(--danger); }

/* ============================================================
   Strategy assistant (Charts tab)
   ============================================================ */
.assistant-panel { display: flex; flex-direction: column; }
.assistant-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.assistant-head .assistant-title {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 600; margin-right: auto;
}
.assistant-head select { min-width: 240px; }

.assistant-messages {
  display: flex; flex-direction: column; gap: 12px;
  min-height: 300px; max-height: 58vh; overflow-y: auto;
  padding: 6px 4px 6px 0;
}
.assistant-empty {
  margin: auto; text-align: center; color: var(--muted); font-size: 13.5px;
  max-width: 460px; line-height: 1.6;
}
.chat-msg { display: flex; }
.chat-msg .bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg.user { justify-content: flex-end; }
.chat-msg.user .bubble {
  background: var(--accent); color: var(--accent-contrast);
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .bubble {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--panel-border);
  border-bottom-left-radius: 4px;
}
.chat-msg.error .bubble {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--text);
}
.bubble code { background: color-mix(in srgb, var(--muted) 18%, transparent); padding: 1px 5px; border-radius: 4px; }

.typing-dots { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.assistant-input-row {
  display: flex; gap: 10px; align-items: flex-end; margin-top: 14px;
  border-top: 1px solid var(--panel-border); padding-top: 14px;
}
.assistant-input-row textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 160px; line-height: 1.5;
}
.assistant-hint { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* -------------------------------------------------- Responsive */
@media (max-width: 640px) {
  html, body { overflow-x: hidden; }   /* belt-and-suspenders: never let a stray wide child force page-level horizontal scroll */

  #content { padding: 12px; }

  /* Topbar: wrap onto a second line instead of clipping/overflowing.
     Less-essential text (the email address) hides -- Log out stays reachable. */
  .topbar { padding: 8px 12px; gap: 8px; flex-wrap: wrap; row-gap: 8px; }
  .brand { margin-right: 0; }
  .brand-logo { height: 19px; }
  #project-select { flex: 1 1 auto; min-width: 0; }
  #new-project-btn { padding: 8px 10px; font-size: 13px; }
  .user-email {
    max-width: 140px; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; margin-left: 0;   /* truncate rather than hide -- still glanceable, never forces overflow */
  }
  .plan-badge { order: 1; }
  #upgrade-btn, #logout-btn, #theme-toggle { padding: 8px 10px; font-size: 13px; }

  /* Nav: horizontally scrollable (see the non-mobile .tabs rule above --
     overflow-x:auto is preserved at all sizes, this just tunes touch sizing). */
  .tabs { padding: 6px 10px 0; -webkit-overflow-scrolling: touch; }
  .tab, .navgroup-label { padding: 9px 11px; font-size: 13px; }

  /* Grids collapse to one column naturally (auto-fit/minmax), but drop the
     minmax floor so a 320-375px viewport doesn't still force a scrollbar. */
  .summary-cards { grid-template-columns: 1fr; gap: 10px; }
  .form-grid { grid-template-columns: 1fr; }
  .control-row { gap: 8px; }

  /* Tables: the row of columns becomes horizontally scrollable rather than
     squeezing text unreadably small or blowing out the page width. */
  .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table thead, .data-table tbody { display: table; width: 100%; }

  /* News items: stack the thumbnail above the text instead of side-by-side. */
  .news-item { flex-direction: column; }
  .news-thumb { width: 100%; height: 160px; }

  /* Auth page */
  .auth-card { padding: 24px 20px; max-width: 100%; }
  .auth-theme-toggle { top: 12px; right: 12px; }

  .assistant-head select { min-width: 0; flex: 1; }
  .chat-msg .bubble { max-width: 90%; }
}

/* ============================================================
   Auth overlay (login / signup gate)
   ============================================================ */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.auth-candles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth-password-wrap { position: relative; display: block; margin-top: 6px; }
.auth-password-wrap input {
  margin-top: 0 !important;
  padding-right: 40px !important;
  width: 100%;
  box-sizing: border-box;
}
.auth-password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 6px 8px;
  line-height: 1;
  color: var(--muted);
  opacity: 0.75;
}
.auth-password-toggle:hover { opacity: 1; color: var(--text); }
.auth-logo { display: flex; justify-content: center; margin: 0 0 18px; }
.auth-logo .brand-logo { height: 34px; }
.auth-sub { margin: 0 0 20px; color: var(--muted); text-align: center; }
.auth-label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}
.auth-label input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  box-sizing: border-box;
}
.auth-submit { width: 100%; margin-top: 6px; padding: 11px; font-size: 15px; }
.auth-switch { margin: 18px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.auth-switch a { color: var(--accent); text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-error {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 14px;
}
.user-email { margin-left: auto; font-size: 13px; }
.topbar .user-email + #logout-btn { margin-left: 0; }

/* ============================================================
   News + Insider tabs
   ============================================================ */
.news-item {
  display: flex;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  text-decoration: none;
  color: inherit;
  background: var(--panel-2);
}
.news-item:hover { border-color: var(--accent); }
.news-thumb { width: 104px; height: 76px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.news-headline { font-weight: 600; margin-bottom: 4px; }
.news-summary { font-size: 13px; line-height: 1.45; }
.news-meta { font-size: 12px; margin-top: 6px; }
.raw-text {
  white-space: pre-wrap;
  max-height: 360px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.5;
  background: var(--input-bg);
  padding: 12px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
}
.ai-summary { line-height: 1.65; }

/* ============================================================
   Grouped dropdown nav (Trade / Research / Strategy / …)
   ============================================================ */
.tabs { overflow-x: auto; align-items: stretch; }
.navgroup { position: relative; display: inline-flex; }
.navgroup-label {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 15px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
}
.navgroup-label:hover { color: var(--text); }
.navgroup-label.has-active { color: var(--text); border-bottom-color: var(--accent); }
/* Always viewport-fixed (top/left computed in JS from the trigger's own
   position -- see bindTabs()), never CSS-anchored/absolute under .navgroup.
   Two independent reasons this has to be fixed, not absolute:
     1. .tabs needs overflow-x:auto for horizontal scroll (many nav groups on
        a narrow screen) -- but per the CSS overflow spec, if overflow-x is
        anything other than visible, a sibling overflow-y:visible is silently
        computed as auto instead. There is no way to keep overflow-x:auto AND
        have overflow-y truly stay visible, so an absolutely-positioned
        dropdown gets clipped by .tabs' own box and never renders at all.
     2. Only .open (a click-driven class, not :hover) controls visibility --
        a :hover-based reveal looks fine on a mouse, but a tap "sticks" the
        hover state on touch devices, and even on desktop, clicking a tab
        inside the dropdown leaves the cursor sitting over the still-hovered
        parent, so :hover alone would keep it open until the mouse moves
        away -- exactly the "have to click elsewhere" bug this replaces. */
.navgroup-menu {
  display: none;
  position: fixed;
  z-index: 50;
  min-width: 190px;
  padding: 6px;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.navgroup.open .navgroup-menu { display: flex; }
.navgroup-menu .tab {
  width: 100%;
  text-align: left;
  border-bottom: none;
  border-radius: 6px;
  padding: 9px 12px;
}
.navgroup-menu .tab:hover { background: var(--panel-2); }
.navgroup-menu .tab.active { background: var(--panel-2); color: var(--accent); }

@media (max-width: 640px) {
  /* Full-bleed rather than anchored to the trigger's (possibly narrow, possibly
     scrolled-off-partway) left edge -- JS only sets `top` at this width, not `left`. */
  .navgroup-menu {
    left: 12px;
    right: 12px;
    width: auto;
    min-width: 0;
  }
}

/* Plan badge (free / premium) */
.plan-badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  border: 1px solid var(--panel-border);
  white-space: nowrap;
}
.plan-badge.premium { color: var(--accent); border-color: var(--accent); font-weight: 600; }

.auth-theme-toggle {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 2;
}

/* ============================================================
   Pagination bar (News / SEC Filings / Insider Activity)
   ============================================================ */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
}
.pagination-bar .pg-indicator { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ============================================================
   App-style bottom navigation (mobile only)
   ============================================================ */
.bottom-nav { display: none; }

@media (max-width: 640px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 45;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--panel-border);
  }
  .bnav-btn {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; cursor: pointer;
    color: var(--muted); font-size: 10.5px; font-weight: 600;
    padding: 4px 2px; border-radius: 10px;
    transition: color 0.15s ease, background 0.15s ease;
  }
  .bnav-btn svg { width: 22px; height: 22px; transition: transform 0.15s ease; }
  .bnav-btn.active { color: var(--accent); }
  .bnav-btn.active svg { transform: translateY(-1px); }
  .bnav-btn:active { background: color-mix(in srgb, var(--accent) 10%, transparent); }

  /* Clear the fixed bar so the last of the page content is never hidden. */
  #content { padding-bottom: 76px; }
}
