:root {
  --bg: #0b1220;
  --surface: #121b2e;
  --surface-2: #182338;
  --border: #223049;
  --text: #e7ecf5;
  --text-dim: #8a95ab;
  --blue: #3b82f6;
  --green: #22c55e;
  --red: #ef4444;
  --gray: #64748b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  background: var(--bg);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--blue); display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.brand-tagline { font-size: 11px; color: var(--text-dim); }
.status-pill {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 999px;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }

/* ---------- Main / screens ---------- */
main#screen {
  flex: 1;
  padding: 16px;
  padding-bottom: 90px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

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

.hero h1 { font-size: 19px; margin: 0 0 4px; }
.hero p { font-size: 13px; color: var(--text-dim); margin: 0 0 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 10px; padding: 13px 18px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:disabled { opacity: 0.6; }
.btn-secondary { background: transparent; color: var(--text-dim); border: 1px solid var(--border); margin-top: 8px; }

.meta-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  margin-top: 4px;
}
.meta-item { font-size: 12px; }
.meta-item .label { color: var(--text-dim); display: block; margin-bottom: 2px; }
.meta-item .value { font-weight: 600; }

.section-title { font-size: 14px; font-weight: 700; margin: 4px 0 10px; }

/* ---------- Provider cards ---------- */
.provider-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.provider-chip {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 6px; text-align: center; font-size: 11px;
}
.provider-chip .icon { font-size: 18px; display: block; margin-bottom: 4px; }
.provider-chip .name { color: var(--text-dim); }

.provider-list { display: flex; flex-direction: column; gap: 10px; }
.provider-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px;
}
.provider-row .left { display: flex; align-items: center; gap: 10px; }
.provider-row .name { font-weight: 600; font-size: 13px; }
.provider-row .reason { font-size: 11px; color: var(--text-dim); margin-top: 2px; max-width: 220px; }
.signal-badge {
  font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  white-space: nowrap;
}
.signal-buy { background: rgba(34,197,94,0.15); color: var(--green); }
.signal-sell { background: rgba(239,68,68,0.15); color: var(--red); }
.signal-no_trade { background: rgba(100,116,139,0.2); color: var(--gray); }
.signal-error { background: rgba(239,68,68,0.1); color: var(--red); }

/* ---------- Voting summary ---------- */
.vote-summary { display: flex; align-items: center; gap: 18px; }
.donut {
  width: 92px; height: 92px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.donut-inner {
  width: 66px; height: 66px; border-radius: 50%; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-inner .num { font-size: 18px; font-weight: 800; line-height: 1; }
.donut-inner .lbl { font-size: 9px; color: var(--text-dim); }
.vote-legend { flex: 1; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.vote-legend .row { display: flex; align-items: center; justify-content: space-between; }
.vote-legend .row .left { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }

.majority-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px; border-radius: 10px; margin-bottom: 14px;
}
.majority-banner.buy { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.35); }
.majority-banner.sell { background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.35); }
.majority-banner.tie { background: rgba(100,116,139,0.1); border: 1px solid var(--border); }
.majority-banner .title { font-weight: 700; font-size: 14px; }
.majority-banner .sub { font-size: 11px; color: var(--text-dim); }

/* ---------- Loading steps ---------- */
.steps { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.step { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-dim); }
.step .mark { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; }
.step.done .mark { background: var(--green); border-color: var(--green); }
.step.done { color: var(--text); }
.step.active .mark { border-color: var(--blue); }
.step.active { color: var(--text); }

.spinner {
  width: 48px; height: 48px; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: var(--blue);
  margin: 8px auto 18px; animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; color: var(--text-dim); font-size: 13px; padding: 30px 10px; }
.error-box {
  background: rgba(239,68,68,0.1); border: 1px solid rgba(239,68,68,0.35);
  color: var(--red); border-radius: 10px; padding: 12px; font-size: 13px; margin-bottom: 14px;
}

/* ---------- History list ---------- */
.history-item {
  display: flex; align-items: center; justify-content: between; flex-direction: column;
  align-items: stretch; gap: 4px;
}
.history-item .row1 { display: flex; justify-content: space-between; align-items: center; }
.history-item .time { font-weight: 600; font-size: 13px; }
.history-item .votes { font-size: 11px; color: var(--text-dim); }
.history-item .exchange { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.history-item.clickable { cursor: pointer; transition: border-color 0.15s; }
.history-item.clickable:hover,
.history-item.clickable:focus-visible { border-color: var(--blue); outline: none; }

/* ---------- Detail Analisa (P5) ---------- */
.detail-back { width: auto; margin: 0 0 14px; padding: 8px 12px; }
.value.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; word-break: break-all; }

.ai-result-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; margin-bottom: 10px;
}
.ai-result-meta {
  display: flex; flex-wrap: wrap; gap: 10px;
  font-size: 11px; color: var(--text-dim); margin-top: 8px;
}

.raw-toggle-btn { font-size: 12px; padding: 8px 12px; }
.raw-answer {
  display: none;
  white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; margin-top: 8px; font-size: 11px; color: var(--text-dim);
  max-height: 280px; overflow-y: auto;
}
.raw-answer.open { display: block; }

/* ---------- Settings ---------- */
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row .label { color: var(--text-dim); }
.settings-row .value { font-weight: 600; }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 10;
}
.nav-btn {
  flex: 1; background: none; border: none; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 10px 0 8px; font-size: 11px; cursor: pointer;
}
.nav-btn.active { color: var(--blue); }
.nav-icon { font-size: 17px; }

@media (min-width: 640px) {
  .provider-grid { grid-template-columns: repeat(6, 1fr); }
}
