:root {
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #1a222e;
  --border: #233041;
  --text: #e8edf4;
  --text-dim: #8a97a8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f5a524;
  --blue: #3b82f6;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px calc(14px);
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 10px var(--green);
}

.status-pill {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 4px 9px;
  border-radius: 999px;
}

/* Main scroll area */
.screen {
  flex: 1;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  display: none;
}
.screen.active { display: block; }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin: 20px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.ticker-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.ticker-card:active { border-color: var(--blue); }

.ticker-left { display: flex; align-items: center; gap: 12px; }
.ticker-avatar {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  color: var(--text);
}
.ticker-name { font-weight: 600; font-size: 15px; }
.ticker-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.rating-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.rating-badge.buy { background: rgba(34,197,94,0.15); color: var(--green); }
.rating-badge.hold { background: rgba(245,165,36,0.15); color: var(--amber); }
.rating-badge.sell { background: rgba(239,68,68,0.15); color: var(--red); }

/* New analysis form */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  appearance: none;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--blue); }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.chip.selected { border-color: var(--blue); color: var(--text); background: rgba(59,130,246,0.12); }

.btn-primary {
  width: 100%;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; }

/* Report view */
.report-hero {
  text-align: center;
  padding: 22px 16px;
}
.report-hero .rating-badge { font-size: 13px; padding: 7px 16px; margin-bottom: 10px; display: inline-block; }
.report-hero h2 { margin: 6px 0 2px; font-size: 22px; }
.report-hero .meta { font-size: 12px; color: var(--text-dim); }

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.metric {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 12px;
}
.metric .label { font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.metric .value { font-size: 15px; font-weight: 600; }

.report-body {
  font-size: 14px;
  line-height: 1.55;
  color: #cdd6e2;
  white-space: pre-wrap;
}

/* Bottom nav */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  max-width: 480px;
  margin: 0 auto;
  background: rgba(18, 24, 33, 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}
.navbtn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  cursor: pointer;
}
.navbtn svg { width: 22px; height: 22px; }
.navbtn.active { color: var(--blue); }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 13px;
}

.loading-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px 0;
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.badge-dot { width: 8px; height: 8px; border-radius: 50%; }
.badge-dot.buy { background: var(--green); }
.badge-dot.hold { background: var(--amber); }
.badge-dot.sell { background: var(--red); }

/* top-right action */
.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}

.back-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.back-row .icon-btn { width: 30px; height: 30px; }
.back-row .title { font-size: 17px; font-weight: 700; }
