:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1e252e;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --up: #3fb950;
  --down: #f85149;
  --grey: #6e7681;
  --yellow: #d29922;
  --orange: #f0883e;
  --red: #f85149;
  --radius: 10px;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }

/* --- layout --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px var(--gutter);
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(14, 17, 22, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { color: var(--text); font-weight: 700; letter-spacing: -.01em; }
nav { display: flex; gap: 14px; align-items: center; font-size: 14px; }
nav[hidden] { display: none; }
nav a { color: var(--muted); }
nav a.active { color: var(--text); }
main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: var(--gutter); }
.footer { padding: 20px var(--gutter) 28px; text-align: center; color: var(--muted); font-size: 12px; }

/* --- controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0b1220; font-weight: 600; }
.btn.danger { color: var(--down); }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* --- cards --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; }

.banner {
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
  background: rgba(210, 153, 34, .12); border: 1px solid rgba(210, 153, 34, .4); color: #f2cc60;
}
.banner.error { background: rgba(248, 81, 73, .1); border-color: rgba(248, 81, 73, .4); color: #ffa198; }

/* --- market strip --- */
.market {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 6px;
}
.market .tile { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.market .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.market .v { font-weight: 600; font-size: 15px; }
.market .d { font-size: 12px; }
.updated { font-size: 12px; color: var(--muted); margin-bottom: 14px; }

/* --- watchlist --- */
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters input { flex: 2; }
.filters select { flex: 1; }

.ticker {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "name badge" "meta spark";
  gap: 4px 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 8px; color: var(--text);
}
.ticker:active { background: var(--surface-2); }
.ticker .name { grid-area: name; min-width: 0; }
.ticker .sym { font-weight: 700; }
.ticker .full { color: var(--muted); font-size: 13px; margin-left: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticker .meta { grid-area: meta; font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.ticker .meta b { color: var(--text); font-weight: 600; }
.ticker .badge { grid-area: badge; justify-self: end; }
.ticker .spark { grid-area: spark; justify-self: end; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.badge.grey { background: rgba(110, 118, 129, .2); color: #adbac7; }
.badge.yellow { background: rgba(210, 153, 34, .2); color: #f2cc60; }
.badge.orange { background: rgba(240, 136, 62, .22); color: #ffa657; }
.badge.red { background: rgba(248, 81, 73, .22); color: #ff7b72; }
.badge.none { background: var(--surface-2); color: var(--muted); font-weight: 500; }

/* --- detail --- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.detail-head h1 { margin: 0; font-size: 22px; }
.price { font-size: 20px; font-weight: 600; }
.signals { list-style: none; margin: 0; padding: 0; }
.signals li { display: grid; grid-template-columns: 28px 1fr; gap: 4px 6px; padding: 10px 0; border-top: 1px solid var(--border); }
.signals li:first-child { border-top: 0; }
.signals .icon { font-size: 16px; line-height: 1.3; }
.signals .sname { font-weight: 600; }
.signals .sdetail { grid-column: 2; font-size: 13px; color: var(--muted); }
.chart { height: 420px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; font-size: 14px; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd { margin: 0 0 4px; }

/* --- health / tables --- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 12px; border-top: 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.green { background: var(--up); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }

/* --- help --- */
.gloss h3 { margin: 0 0 6px; font-size: 15px; }
.gloss p { margin: 4px 0; font-size: 14px; }
.gloss p b { color: var(--muted); font-weight: 500; }

/* --- login --- */
.login { max-width: 380px; margin: 10vh auto 0; }

details summary { cursor: pointer; color: var(--accent); margin-bottom: 10px; }

@media (max-width: 420px) {
  .market { grid-template-columns: repeat(2, 1fr); }
  nav { gap: 10px; font-size: 13px; }
  .chart { height: 360px; }
}
