:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hi: #21262d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --primary: #0a84ff;
  --buy: #2ea043;
  --sell: #f85149;
  --warn: #d29922;
  --border: #30363d;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1rem 0.75rem;
  padding-top: calc(1rem + env(safe-area-inset-top));
}

header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.online { background: var(--buy); }
.status-dot.offline { background: var(--sell); }

#status-text {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.filter-btn {
  background: var(--surface-hi);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.filter-btn:active { background: var(--primary); }
.filter-btn[hidden] { display: none; }
.filter-btn.on { background: var(--buy); border-color: var(--buy); color: white; }
.filter-btn.needs-https { background: transparent; color: var(--warn); border-color: var(--warn); }

.scheduler-row {
  margin-top: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.scheduler-row.warn { color: var(--warn); }

main {
  padding: 1rem;
  max-width: 700px;
  margin: 0 auto;
}

.proposals {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.proposal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.proposal-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
}

.action-tag {
  font-weight: 700;
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  letter-spacing: 0.05em;
}
.action-tag.BUY  { background: var(--buy);  color: white; }
.action-tag.SELL { background: var(--sell); color: white; }

.symbol {
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.spacer { flex: 1; }

.proposal-meta {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.75rem;
  row-gap: 0.25rem;
  font-size: 0.9rem;
}
.proposal-meta dt { color: var(--text-dim); }
.proposal-meta dd { margin: 0; font-variant-numeric: tabular-nums; }

.reasoning {
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-hi);
  padding: 0.75rem;
  border-radius: 8px;
  border-left: 3px solid var(--primary);
}

.risk-violations {
  font-size: 0.85rem;
  color: var(--sell);
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--sell);
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
}
.risk-violations ul { margin: 0.25rem 0 0 1rem; padding: 0; }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.actions.one { grid-template-columns: 1fr; }

.btn {
  font-size: 1rem;
  font-weight: 600;
  padding: 0.85rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-approve { background: var(--buy); color: white; }
.btn-reject  { background: var(--sell); color: white; }

.proposal.decided {
  opacity: 0.65;
}
.decided-banner {
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  padding: 0.5rem;
  border-radius: 6px;
}
.decided-banner.APPROVED { background: rgba(46, 160, 67, 0.15); color: var(--buy); }
.decided-banner.REJECTED { background: rgba(248, 81, 73, 0.15); color: var(--sell); }
.decided-banner.EXECUTED { background: rgba(46, 160, 67, 0.18); color: var(--buy); }
.decided-banner.FAILED   { background: rgba(248, 81, 73, 0.15); color: var(--sell); }
.decided-banner.EXPIRED  { background: rgba(210, 153, 34, 0.15); color: var(--warn); }

.mode-badge {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  vertical-align: middle;
}
.mode-badge.dry { background: var(--surface-hi); color: var(--text-dim); border: 1px solid var(--border); }
.mode-badge.paper { background: var(--primary); color: white; }
.mode-badge.live { background: var(--sell); color: white; }

.proposal-meta.exec {
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
}
.empty-state .subtle { font-size: 0.85rem; opacity: 0.7; }

.hidden { display: none !important; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0.25rem;
  margin-top: 0.6rem;
}
.tab {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--primary); }

/* Security banner */
.security-banner {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--warn);
  background: rgba(210, 153, 34, 0.12);
  border: 1px solid var(--warn);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
}

/* Portfolio */
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
}
.account-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.25rem 0;
  font-size: 0.95rem;
}
.account-row span:first-child { color: var(--text-dim); }
.account-row strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.account-meta { margin-top: 0.5rem; font-size: 0.75rem; color: var(--text-dim); }
.gain { color: var(--buy); }
.loss { color: var(--sell); }

.holding {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.holding .sym { font-size: 1.1rem; font-weight: 600; min-width: 3.5rem; }
.holding .qty { color: var(--text-dim); font-size: 0.85rem; }
.holding .vals { margin-left: auto; text-align: right; }
.holding .mv { font-variant-numeric: tabular-nums; }
.holding .pl { font-size: 0.8rem; font-variant-numeric: tabular-nums; }

/* Login overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.login-card h2 { margin: 0; }
.login-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  color: var(--text);
  font-size: 1rem;
}
.login-error { color: var(--sell); font-size: 0.85rem; margin: 0; }

.timestamp {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ---- Momentum view ---- */
.section-label {
  margin: 1.25rem 0 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.section-hint { font-weight: 400; font-size: 0.8rem; color: var(--text-dim); }

.mom-summary-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}
.mom-summary-label { font-size: 0.8rem; color: var(--text-dim); }
.mom-summary-held strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.mom-summary-held span { color: var(--text-dim); font-size: 0.9rem; }

.mom-position {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.mom-position.mom-ok { border-left-color: var(--buy); }
.mom-position.mom-warn { border-left-color: var(--warn); }
.mom-position.mom-danger { border-left-color: var(--sell); }

.mom-pos-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}
.mom-price { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.mom-badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
}
.mom-badge.ok { background: rgba(46, 160, 67, 0.18); color: var(--buy); }
.mom-badge.warn { background: rgba(210, 153, 34, 0.18); color: var(--warn); }
.mom-badge.danger { background: rgba(248, 81, 73, 0.18); color: var(--sell); }

.mom-pos-sub {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}
.mom-pos-sub .qty { color: var(--text-dim); }
.mom-pos-sub .pl { font-variant-numeric: tabular-nums; }

/* Trailing-stop gauge: current price between stop (left) and peak (right) */
.stop-gauge {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-hi);
  overflow: hidden;
}
.stop-gauge-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--buy);
  opacity: 0.35;
}
.stop-gauge.warn .stop-gauge-fill { background: var(--warn); }
.stop-gauge.danger .stop-gauge-fill { background: var(--sell); }
.stop-gauge-marker {
  position: absolute;
  top: -2px;
  width: 3px;
  height: 12px;
  border-radius: 2px;
  background: var(--text);
  transform: translateX(-1px);
}
.stop-gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin-top: -0.2rem;
}

/* Watch list */
.watch-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.watch-row {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.85rem;
}
.watch-sym { font-weight: 600; min-width: 3.5rem; }
.watch-price { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 0.85rem; }
.watch-note { margin-left: auto; font-size: 0.8rem; }
.watch-note.dim { color: var(--text-dim); }
