/* ============ AI Stock Research Analyst — global styles ============ */
:root {
  --bg: #f5f7fb;
  --bg-card: #ffffff;
  --bg-sunken: #eef1f7;
  --text: #0f172a;
  --text-soft: #475569;
  --muted: #64748b;
  --border: #dbe3ef;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --pos: #16a34a;
  --pos-soft: #e7f6ec;
  --neg: #dc2626;
  --neg-soft: #fdeaea;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --neutral: #64748b;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.12);
  --radius: 12px;
  --font: "Segoe UI", "Tahoma", system-ui, -apple-system, sans-serif;
  --mono: "Consolas", "Menlo", monospace;
}
[data-theme="dark"] {
  --bg: #0b1220;
  --bg-card: #111a2c;
  --bg-sunken: #0e1626;
  --text: #e6edf7;
  --text-soft: #b3c2d9;
  --muted: #8494ad;
  --border: #223149;
  --accent: #5b8def;
  --accent-soft: #1a2740;
  --pos: #34d399;
  --pos-soft: #0d2b1f;
  --neg: #f87171;
  --neg-soft: #35151b;
  --warn: #fbbf24;
  --warn-soft: #3a2a10;
  --neutral: #8ea0ba;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 16px;
  transition: background 0.2s, color 0.2s;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -60px;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 8px 8px;
  z-index: 2000;
  text-decoration: none;
  transition: top 0.15s;
}
.skip-link:focus { top: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- layout ---------- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c3aed);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 18px;
}
.brand h1 { font-size: 17px; margin: 0; font-weight: 700; }
.brand small { display: block; color: var(--muted); font-size: 11px; }

.header-controls { display: flex; align-items: center; gap: 10px; margin-right: auto; flex-wrap: wrap; }
.last-update { color: var(--muted); font-size: 13px; }
.freshness { font-size: 12px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-soft); }

select, button, input {
  font: inherit;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff; border: 1px solid transparent;
  font-weight: 600; padding: 8px 16px; border-radius: 8px;
}
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.main { max-width: 1200px; margin: 0 auto; padding: 20px 20px 60px; }

/* ---------- loading ---------- */
.loading-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-steps { margin: 16px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.progress-steps li { color: var(--text-soft); display: flex; gap: 8px; align-items: center; }
.progress-steps li::before { content: "○"; color: var(--muted); }
.progress-steps li.active { color: var(--accent); font-weight: 600; }
.progress-steps li.active::before { content: "◉"; }
.progress-steps li.done::before { content: "✓"; color: var(--pos); }

/* ---------- market status ---------- */
.section-title { font-size: 20px; font-weight: 700; margin: 28px 0 12px; }
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.card.focused-stock {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--accent-soft);
}
.card-breakdown { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 8px; }
.card-breakdown summary { cursor: pointer; font-size: 12px; font-weight: 700; color: var(--accent); }
.comp-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin-top: 8px;
}
.comp-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; padding: 2px 0; border-bottom: 1px dotted var(--border);
}
.comp-label { color: var(--muted); }
.comp-val { font-weight: 800; }
.comp-na { font-size: 11px; }
.big-value { font-size: 26px; font-weight: 800; line-height: 1.2; }
.bullish { color: var(--pos); }
.bearish { color: var(--neg); }
.neutral { color: var(--neutral); }

.chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
}
.chip-pos { background: var(--pos-soft); color: var(--pos); }
.chip-neg { background: var(--neg-soft); color: var(--neg); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-neu { background: var(--bg-sunken); color: var(--text-soft); }
.chip-accent { background: var(--accent-soft); color: var(--accent); }

.sectors-list { display: flex; flex-direction: column; gap: 6px; }
.sector-row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }

/* ---------- top 10 ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--bg-card); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
caption { text-align: right; padding: 10px 14px; font-weight: 700; color: var(--text); }
th, td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--bg-sunken); color: var(--text-soft); font-size: 12px; white-space: nowrap; }
tbody tr:hover { background: var(--bg-sunken); }
tr:last-child td { border-bottom: none; }
.rank-badge {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-sunken); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px;
}
.rank-badge.top1 { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; }
.rank-badge.top2 { background: linear-gradient(135deg, #94a3b8, #64748b); color: #fff; }
.rank-badge.top3 { background: linear-gradient(135deg, #b45309, #92400e); color: #fff; }
.stock-link { font-weight: 700; color: var(--text); text-decoration: none; }
.stock-link:hover { color: var(--accent); text-decoration: underline; }
.ticker { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.num { font-family: var(--mono); }
.up { color: var(--pos); }
.down { color: var(--neg); }
.score-cell { font-weight: 800; font-size: 18px; }
.score-bar {
  width: 100%; height: 6px; background: var(--bg-sunken);
  border-radius: 3px; margin-top: 4px; overflow: hidden;
}
.score-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.reason-cell { font-size: 13px; color: var(--text-soft); max-width: 260px; }

/* score ring */
.score-ring { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.score-num { font-weight: 800; font-size: 18px; }
.score-label { font-size: 11px; color: var(--muted); }

/* ---------- cards grid (stock detail) ---------- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; font-family: var(--mono); }
ul.clean { margin: 8px 0 0; padding-right: 18px; }
ul.clean li { margin-bottom: 6px; }

.verdict-box {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-right: 5px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 20px;
  font-size: 16px;
}
.verdict-box strong { color: var(--accent); }

/* ---------- news ---------- */
.news-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--bg-card);
}
.news-item h4 { margin: 0 0 4px; font-size: 14px; }
.news-meta { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- charts ---------- */
.chart-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.chart-box h3 { margin: 0 0 10px; font-size: 14px; color: var(--text-soft); }
.chart-box canvas { width: 100%; display: block; border-radius: 6px; }
.chart-summary { margin-top: 8px; font-size: 13px; color: var(--text-soft); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 500; overflow-y: auto;
}
.modal {
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 720px; width: 100%; padding: 22px;
  box-shadow: var(--shadow-lg);
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal .close-x { float: left; }

/* ---------- footer / disclaimer ---------- */
.site-footer { border-top: 1px solid var(--border); margin-top: 40px; padding: 20px; background: var(--bg-card); }
.site-footer-inner { max-width: 1200px; margin: 0 auto; }
.disclaimer { font-size: 13px; color: var(--muted); background: var(--warn-soft); border-radius: 8px; padding: 10px 14px; margin: 0 0 10px; }
.develop-credit { margin-top: 10px; color: var(--accent); font-weight: 600; font-size: 14px; }

/* ---------- search ---------- */
.search-wrap { position: relative; min-width: 220px; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-lg);
  max-height: 320px; overflow-y: auto; z-index: 300;
}
.search-results button {
  display: block; width: 100%; text-align: right;
  border: none; border-bottom: 1px solid var(--border);
  background: transparent; padding: 10px 12px; border-radius: 0;
}
.search-results button:hover, .search-results button:focus-visible { background: var(--accent-soft); }
.search-head {
  margin: 0; padding: 8px 12px; font-size: 12px; font-weight: 700;
  color: var(--accent); background: var(--accent-soft); border-bottom: 1px solid var(--border);
}
.search-sep {
  padding: 8px 12px 4px; font-size: 11px; font-weight: 600;
  color: var(--muted); border-top: 1px dashed var(--border);
}

/* ---------- misc ---------- */
.error-box {
  background: var(--neg-soft); color: var(--neg);
  border: 1px solid var(--neg); border-radius: var(--radius);
  padding: 14px 18px; font-weight: 600;
}
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: var(--mono); }
.flex-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.pill-group { display: flex; gap: 8px; flex-wrap: wrap; }

.hidden { display: none !important; }
[aria-hidden="true"] { display: none !important; }

/* score component bars */
.comp-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.comp-row:last-child { border-bottom: none; }
.comp-label { width: 110px; font-size: 13px; color: var(--text-soft); }
.comp-track { flex: 1; height: 10px; background: var(--bg-sunken); border-radius: 5px; overflow: hidden; }
.comp-fill { height: 100%; border-radius: 5px; background: var(--accent); }
.comp-value { width: 60px; text-align: left; font-weight: 700; font-family: var(--mono); font-size: 14px; }

/* print-friendly, reduce motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto; }
}

@media (max-width: 720px) {
  .header-inner { gap: 8px; }
  .brand h1 { font-size: 15px; }
  .main { padding: 14px 12px 40px; }
  .big-value { font-size: 22px; }
}
