:root {
  --bg: #0a0b0f;
  --surface: #13151c;
  --surface2: #1c1f2e;
  --border: #2a2d3e;
  --accent: #6c63ff;
  --accent-glow: rgba(108, 99, 255, 0.3);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

/* Views */
.view { display: none; }
.view.active, .view:not(.hidden) { display: flex; }
.view.hidden { display: none !important; }

/* Login / Input card */
#view-login, #view-menu, #view-spell, #view-input {
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #fff;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 32px;
}

.field {
  margin-bottom: 20px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  margin-top: 8px;
  font-size: 15px;
  padding: 14px;
}

.btn-primary:hover { background: #5a52d5; box-shadow: 0 4px 20px var(--accent-glow); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 13px;
}

.btn-outline:hover { border-color: var(--accent); color: var(--accent); }

.btn-translate {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 13px;
  transition: all 0.2s;
}

.btn-translate:hover { border-color: #60a5fa; color: #60a5fa; }
.btn-translate.active { background: rgba(96,165,250,0.15); border-color: #60a5fa; color: #60a5fa; }
.btn-translate.loading { opacity: 0.6; cursor: not-allowed; }

.header-actions { display: flex; gap: 10px; align-items: center; }

.error {
  color: var(--red);
  font-size: 13px;
  margin-top: 12px;
  text-align: center;
}

/* Results view */
#view-results {
  flex-direction: column;
  min-height: 100vh;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo-sm { font-size: 16px; font-weight: 700; }

.results-body {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  width: 100%;
}

.company-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 40px;
}

.company-banner h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.ticker-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: monospace;
}

/* Progress */
.progress-track {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  position: relative;
}

.progress-track::before {
  content: '';
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  position: relative;
  z-index: 1;
}

.step-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--border);
  transition: all 0.3s;
}

.progress-step span {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

.progress-step.active .step-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
  animation: pulse 1.5s infinite;
}

.progress-step.done .step-dot {
  background: var(--green);
  border-color: var(--green);
}

.progress-step.done span,
.progress-step.active span { color: var(--text); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 8px var(--accent-glow); }
  50% { box-shadow: 0 0 20px var(--accent-glow); }
}

.progress-msg {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* Result sections */
.result-section { margin-top: 48px; }

.result-section h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  color: #fff;
}

.verdict-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.verdict-top {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 28px 32px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.verdict-rating {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  padding: 12px 24px;
  border-radius: 10px;
  white-space: nowrap;
}

.verdict-rating.strong-buy { background: rgba(34,197,94,0.15); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.verdict-rating.buy { background: rgba(34,197,94,0.1); color: #4ade80; border: 1px solid rgba(74,222,128,0.2); }
.verdict-rating.hold { background: rgba(234,179,8,0.1); color: var(--yellow); border: 1px solid rgba(234,179,8,0.2); }
.verdict-rating.sell { background: rgba(239,68,68,0.1); color: #f87171; border: 1px solid rgba(239,68,68,0.2); }
.verdict-rating.strong-sell { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }

.verdict-stats { display: flex; gap: 32px; flex-wrap: wrap; }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.stat-value { font-size: 20px; font-weight: 700; color: #fff; }

.verdict-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.case-block { padding: 24px 32px; border-bottom: 1px solid var(--border); }
.case-block:first-child { border-right: 1px solid var(--border); }

.case-block h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.case-block.bull h4 { color: var(--green); }
.case-block.bear h4 { color: var(--red); }

.case-block p { font-size: 14px; line-height: 1.7; color: var(--text); }

.verdict-report { padding: 24px 32px; border-bottom: 1px solid var(--border); }
.verdict-report h4 { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.verdict-report p { font-size: 14px; line-height: 1.8; color: var(--text); }

.risk-list { padding: 20px 32px; display: flex; gap: 8px; flex-wrap: wrap; }
.risk-tag {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  color: #f87171;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
}

/* Debate rounds */
.debate-round { margin-bottom: 32px; }

.round-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.round-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.round-header hr {
  flex: 1;
  border: none;
  border-top: 1px solid var(--border);
}

.opinions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.opinion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  animation: fadeInUp 0.4s ease forwards;
  opacity: 0;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.opinion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.agent-name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.agent-name.quant_analyst { color: #818cf8; }
.agent-name.strategy_analyst { color: #34d399; }
.agent-name.finance_analyst { color: #fb923c; }
.agent-name.cro_analyst { color: #e879f9; }

.rating-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}

.rating-chip.buy, .rating-chip.strong\ buy { background: rgba(34,197,94,0.15); color: var(--green); }
.rating-chip.hold { background: rgba(234,179,8,0.1); color: var(--yellow); }
.rating-chip.sell, .rating-chip.strong\ sell { background: rgba(239,68,68,0.1); color: var(--red); }

.opinion-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
  font-size: 13px;
}

.opinion-stats span { color: var(--text-muted); }
.opinion-stats strong { color: var(--text); }

.opinion-text {
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.opinion-card.expanded .opinion-text { -webkit-line-clamp: unset; }

.toggle-expand {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

.key-points { list-style: none; padding: 0; margin-top: 10px; }
.key-points li {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 0;
  padding-left: 14px;
  position: relative;
  line-height: 1.5;
}

.key-points li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--accent);
}

/* ─── Banner with price ──────────────────────────────────────────────────── */
.company-banner {
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-end;
}

.banner-left { display: flex; flex-direction: column; gap: 10px; }
.banner-chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.banner-price {
  text-align: right;
  padding: 12px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 160px;
}

.price-current {
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
}

.price-range {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* stat-value color classes (used in verdict upside) */
.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

/* ─── Margin of Safety on opinion cards ──────────────────────────────────── */
.margin-of-safety {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}

.margin-of-safety.upside-positive {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.2);
}

.margin-of-safety.upside-negative {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
}

.margin-of-safety:not(.upside-positive):not(.upside-negative) {
  background: var(--surface2);
  border: 1px solid var(--border);
}

.mos-label { color: var(--text-muted); font-size: 12px; }

.mos-value {
  font-weight: 700;
  font-size: 14px;
}

.upside-positive .mos-value { color: var(--green); }
.upside-negative .mos-value { color: var(--red); }

/* ─── Company Overview ──────────────────────────────────────────────────── */

.overview-card {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px;
}

.overview-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

.meta-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.meta-chip:empty { display: none; }

.overview-text-col p { font-size: 14px; line-height: 1.85; color: var(--text); }

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding: 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.kpi-item { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.kpi-value { font-size: 18px; font-weight: 700; color: #fff; }

@media (max-width: 720px) { .overview-card { grid-template-columns: 1fr; } }

/* ─── Financial Summary ──────────────────────────────────────────────────── */
.fin-summary-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}

.fin-group {
  padding: 24px 24px;
  border-right: 1px solid var(--border);
}

.fin-group:last-child { border-right: none; }

.fin-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--accent);
  margin-bottom: 16px;
}

.fin-table { width: 100%; border-collapse: collapse; }
.fin-table tr { border-bottom: 1px solid var(--border); }
.fin-table tr:last-child { border-bottom: none; }

.fin-label {
  font-size: 12px;
  color: var(--text-muted);
  padding: 7px 0;
  width: 58%;
}

.fin-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  padding: 7px 0;
}

.fin-value.positive { color: var(--green); }
.fin-value.negative { color: var(--red); }

@media (max-width: 900px) {
  .fin-summary-card { grid-template-columns: 1fr 1fr; }
  .fin-group { border-right: none; border-bottom: 1px solid var(--border); }
  .fin-group:nth-child(odd) { border-right: 1px solid var(--border); }
  .fin-group:last-child { border-bottom: none; }
}

/* ─── Collapsible Debate Rounds ──────────────────────────────────────────── */
.debate-round-collapsible {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 12px;
  overflow: hidden;
}

.debate-round-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  background: var(--surface2);
  transition: background 0.15s;
}

.debate-round-toggle:hover { background: var(--border); }

.debate-round-toggle .round-label {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.toggle-chevron { font-size: 11px; color: var(--text-muted); transition: transform 0.2s; }
.debate-round-collapsible.open .toggle-chevron { transform: rotate(180deg); }

.debate-round-body { display: none; padding: 20px; }
.debate-round-collapsible.open .debate-round-body { display: block; }

/* ─── Former Papers ──────────────────────────────────────────────────────── */
.progress-elapsed { text-align: center; font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.label-optional { font-size: 12px; color: var(--text-muted); font-weight: 400; }

#view-papers { justify-content: center; align-items: flex-start; min-height: 100vh; padding: 40px 24px; }
.papers-container { width: 100%; max-width: 640px; }
.papers-header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.papers-header h2 { font-size: 20px; font-weight: 700; }
.papers-loading, .papers-empty { color: var(--text-muted); padding: 24px 0; text-align: center; }

.paper-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 10px; cursor: pointer; transition: border-color .15s;
}
.paper-item:hover { border-color: var(--accent); }
.paper-left { display: flex; align-items: center; gap: 12px; }
.paper-ticker { font-weight: 700; font-size: 15px; color: var(--accent); }
.paper-name { color: var(--text); font-size: 14px; }
.paper-date { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.btn-delete-paper {
  background: none; border: none; color: var(--text-muted); font-size: 14px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px; line-height: 1;
  transition: background .15s, color .15s; flex-shrink: 0;
}
.btn-delete-paper:hover { background: rgba(239,68,68,.15); color: #ef4444; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn .15s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px 28px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 0;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
  animation: slideUp .2s ease;
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-icon {
  width: 44px; height: 44px;
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin: 0 auto 16px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  color: #fff;
  margin-bottom: 6px;
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-card input {
  width: 100%;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  box-sizing: border-box;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  margin-bottom: 8px;
}

.modal-card input:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(239,68,68,.15);
}

.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }
.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
}
.btn-danger:hover { background: #dc2626; box-shadow: 0 4px 16px rgba(239,68,68,.3); }
.btn-danger:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.rounds-picker {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}
.rounds-btn {
  flex: 1;
  padding: 9px 8px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.rounds-btn:hover { background: var(--surface2); color: var(--text); }
.rounds-btn.active {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 10px rgba(108,99,255,.35);
}

/* ─── Ticker Preview ──────────────────────────────────────────────────────── */
.ticker-preview {
  margin-top: 8px;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  line-height: 1.4;
}
.ticker-preview.validating { color: var(--text-muted); background: rgba(255,255,255,0.04); }
.ticker-preview.valid      { color: #4caf82; background: rgba(76,175,130,0.1); border: 1px solid rgba(76,175,130,0.25); }
.ticker-preview.invalid    { color: var(--red); background: rgba(239,83,80,0.08); border: 1px solid rgba(239,83,80,0.2); }

/* ─── Error Section ───────────────────────────────────────────────────────── */
.error-section {
  text-align: center;
  padding: 32px 24px;
  background: rgba(239,83,80,0.06);
  border: 1px solid rgba(239,83,80,0.2);
  border-radius: 12px;
}
.error-msg {
  color: var(--red);
  font-size: 15px;
  margin: 0;
}

/* ─── Ticker History View ─────────────────────────────────────────────────── */
#view-history { justify-content: center; align-items: flex-start; min-height: 100vh; padding: 40px 24px; }

.btn-back {
  padding: 6px 12px;
  font-size: 16px;
  line-height: 1;
  min-width: 36px;
}

.ticker-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.ticker-price {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  font-family: monospace;
}

.ticker-count {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
}

.history-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.history-price {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  font-family: monospace;
}

.history-rating {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}

.history-rating.strong-buy { background: rgba(34,197,94,0.15); color: var(--green); }
.history-rating.buy { background: rgba(34,197,94,0.1); color: #4ade80; }
.history-rating.hold { background: rgba(234,179,8,0.1); color: var(--yellow); }
.history-rating.sell { background: rgba(239,68,68,0.1); color: #f87171; }
.history-rating.strong-sell { background: rgba(239,68,68,0.15); color: var(--red); }

/* ─── Utilities ───────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
