/* Layout: a top bar with nav on wide screens, a bottom tab bar on phones; each page
   is one working column, summary first and detail below. */
:root {
  --bg: #f4f7f6; --surface: #ffffff; --ink: #15221e; --muted: #5b6a65; --line: #dbe3e0;
  --accent: #0d5f70; --on-accent: #ffffff;
  --buy: #1b7c45; --sell: #b6392a; --avoid: #9c6410; --hold: #5f6e78;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Public Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0e1412; --surface: #151d1a; --ink: #e3ebe7; --muted: #92a29b; --line: #25302c;
  --accent: #62b6c6; --on-accent: #08262c;
  --buy: #4ec381; --sell: #f07b69; --avoid: #e2a74c; --hold: #9ba9b2; color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #0e1412; --surface: #151d1a; --ink: #e3ebe7; --muted: #92a29b; --line: #25302c;
  --accent: #62b6c6; --on-accent: #08262c;
  --buy: #4ec381; --sell: #f07b69; --avoid: #e2a74c; --hold: #9ba9b2; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--body); -webkit-text-size-adjust: 100%; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; letter-spacing: -0.01em; line-height: 1.15; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
.num, td.n, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.up { color: var(--buy); } .down { color: var(--sell); }
.error { color: var(--sell); font-size: 0.9rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* shell */
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 24px; height: 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 21; background: var(--surface); }
.brand { font: 700 1.1rem var(--display); color: var(--ink); text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 6px; color: var(--muted);
  text-decoration: none; font-weight: 500; }
.nav a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav a.active { color: var(--ink); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.wrap { max-width: 1160px; margin: 0 auto; padding-block: 24px 48px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid; gap: 24px; }
@media (max-width: 760px) {
  .topbar { justify-content: center; }
  .nav { position: fixed; z-index: 20; inset: auto 0 0 0; background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around; gap: 0; padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px)); }
  .nav a { flex-direction: column; gap: 2px; font-size: 0.7rem; padding: 4px 8px; }
  .wrap { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  h1 { font-size: 1.45rem; }
}

/* login */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 10px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 28px; }
.login-card h1 { font-size: 1.5rem; }

/* controls */
.btn { font: 600 0.9rem var(--body); padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--sell); }
.btn.small { padding: 4px 10px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.field { display: grid; gap: 4px; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { width: auto; }

/* layout pieces */
.page-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: end; justify-content: space-between; }
.page-head .meta { display: grid; gap: 2px; font-size: 0.88rem; }
section { display: grid; gap: 12px; min-width: 0; align-content: start; }
.sec-head { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; justify-content: space-between; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.panel.pad { padding: 16px 18px; display: grid; gap: 14px; }
.scroll { overflow-x: auto; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.split.wide-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 860px) { .split, .split.wide-left { grid-template-columns: minmax(0, 1fr); } }
.stats { display: flex; flex-wrap: wrap; gap: 12px 32px; }
.stat { display: grid; gap: 2px; }
.stat b { font: 500 1.25rem var(--mono); font-variant-numeric: tabular-nums; }
.empty { padding: 22px 18px; color: var(--muted); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { text-align: left; font: 600 0.7rem/1.2 var(--body); text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); padding: 12px 12px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.wrap-cell { white-space: normal; min-width: 120px; max-width: 220px; }
th.n, td.n { text-align: right; }
tr.row { cursor: pointer; }
tr.row:hover td, tr.hover:hover td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.stock a { color: var(--ink); text-decoration: none; font-weight: 600; }
.stock a:hover { text-decoration: underline; }
.stock span { display: block; font-size: 0.8rem; color: var(--muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); display: inline-block; transition: transform 0.15s; }
tr.open .chev { transform: rotate(90deg); }
tr.detail > td { white-space: normal; background: color-mix(in srgb, var(--accent) 4%, var(--surface)); padding: 16px 20px 20px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px 32px; }
.detail-grid p { margin-top: 4px; max-width: 68ch; }
.detail-grid ul { margin: 4px 0 0; padding-left: 18px; display: grid; gap: 3px; }
@media (max-width: 860px) { .detail-grid { grid-template-columns: minmax(0, 1fr); } }
.sources a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }

/* state markers */
.pill { display: inline-block; min-width: 58px; text-align: center; padding: 2px 8px; border-radius: 4px;
  font: 600 0.74rem/1.5 var(--body); letter-spacing: 0.06em; color: var(--c, var(--muted));
  background: color-mix(in srgb, var(--c, var(--muted)) 13%, transparent); }
.BUY, .COMPLIANT { --c: var(--buy); } .SELL, .NON-COMPLIANT { --c: var(--sell); }
.AVOID, .UNRATED, .UNKNOWN { --c: var(--avoid); } .HOLD { --c: var(--hold); }
.pill.sh { min-width: 0; font-size: 0.68rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); display: inline-block; }
.conf { display: inline-flex; gap: 2px; vertical-align: middle; }
.conf i { width: 6px; height: 12px; border-radius: 1px; background: var(--line); }
.conf i.on { background: var(--ink); }
.tag { font-size: 0.68rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }
.tally { display: flex; flex-wrap: wrap; gap: 8px; }
.tally button { font: inherit; display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink); cursor: pointer; }
.tally button[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.tally b { font-family: var(--mono); font-weight: 500; }
.ladder text { font: 10px var(--mono); fill: var(--muted); }

/* run panel */
.run-buttons { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.run-buttons input { width: 64px; }
.progress { display: grid; gap: 6px; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width 0.4s; }
.bar.indeterminate i { width: 30%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .bar i, .chev { transition: none; } .bar.indeterminate i { animation: none; width: 100%; opacity: 0.5; } }

/* autocomplete */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; box-shadow: 0 8px 24px color-mix(in srgb, var(--ink) 14%, transparent);
  max-height: 300px; overflow-y: auto; }
.ac-list button { display: flex; width: 100%; gap: 10px; align-items: center; justify-content: space-between; text-align: left;
  font: inherit; padding: 8px 10px; border: 0; background: none; color: var(--ink); cursor: pointer; }
.ac-list button:hover, .ac-list button:focus { background: color-mix(in srgb, var(--accent) 8%, transparent); outline: none; }
.ac-list small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* stock page */
.chart { height: 340px; }
@media (max-width: 760px) { .chart { height: 260px; } }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.8rem; color: var(--muted); padding: 0 18px 14px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.news { display: grid; }
.news a { display: block; padding: 10px 18px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.news a:last-child { border-bottom: 0; }
.news a:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.news small { color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 0.9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }

#toast { position: fixed; z-index: 40; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px;
  border-radius: 6px; font-size: 0.9rem; max-width: calc(100% - 32px); }
@media (max-width: 760px) { #toast { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); } }
footer.disclaimer { font-size: 0.8rem; color: var(--muted); max-width: 80ch; }

details summary { list-style-position: inside; }

/* beginner plan */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px; display: grid; gap: 12px; align-content: start; min-width: 0; }
.card.attention { border-color: color-mix(in srgb, var(--sell) 45%, var(--line)); }
.card-head { display: flex; gap: 12px; justify-content: space-between; align-items: start; }
.card-head h3 a { color: var(--ink); text-decoration: none; } .card-head h3 a:hover { text-decoration: underline; }
.card-head .muted { font-size: 0.85rem; display: block; margin-top: 2px; }
.card details summary, details.panel > summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.card details[open] summary { margin-bottom: 6px; }
.card ul { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 3px; }
.numbers { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px 20px; margin: 0;
  padding: 12px 14px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.numbers dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 600; display: flex; gap: 6px; align-items: center; }
.numbers dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; }
.howto { margin: 6px 0 0; padding-left: 20px; display: grid; gap: 8px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps li > span::before { content: counter(s); display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  margin-right: 10px; font: 600 0.75rem var(--mono); background: var(--line); color: var(--ink); }
.steps li.done > span { color: var(--muted); } .steps li.done > span::before { background: var(--buy); color: var(--surface); content: "✓"; }
.callout { padding: 10px 14px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line)); }
.callout.warn { background: color-mix(in srgb, var(--avoid) 10%, var(--surface)); border-color: color-mix(in srgb, var(--avoid) 35%, var(--line)); }
.help { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; font: 600 0.68rem var(--body);
  text-decoration: none; color: var(--accent); border: 1px solid currentColor; vertical-align: middle; flex: none; }
.help:hover { background: var(--accent); color: var(--on-accent); }
.empty-state p { max-width: 70ch; }
/* learn */
.learn { scroll-margin-top: 72px; } .learn p, .learn li { max-width: 72ch; }
.learn ul, .learn ol { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.toc { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.gloss { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; align-items: baseline; }
.gloss dd { margin: 0; }
#confidence { scroll-margin-top: 72px; }
@media (max-width: 760px) { .nav a { padding: 4px 4px; } }
