:root {
  --blue: #008cff;
  --blue-dark: #0070cc;
  --blue-soft: #e8f4ff;
  --ink: #14171a;
  --ink-2: #4a5056;
  --ink-3: #7b8288;
  --line: #e3e6e9;
  --bg: #f6f7f8;
  --card: #ffffff;
  --good: #1a7f4b;
  --good-soft: #e6f5ec;
  --warn: #b4540a;
  --warn-soft: #fdf0e3;
  --bad: #c0292b;
  --bad-soft: #fbe9e9;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: clamp(15px, 0.9rem + 0.15vw, 16px);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--blue-dark); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.4rem, 1.1rem + 1vw, 1.9rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.8em; }
.muted { color: var(--ink-3); }
.small { font-size: 0.87em; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.7rem clamp(1rem, 3vw, 2rem);
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--blue); color: #fff; font-size: 0.75rem; }
.topbar-note { color: var(--ink-3); font-size: 0.85rem; }
@media (max-width: 640px) { .topbar-note { display: none; } }

main { max-width: 1240px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }

/* Cards and buttons */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1rem, 2vw, 1.4rem); margin-bottom: 1rem; }
.btn {
  appearance: none; border: 1px solid var(--blue); background: var(--blue); color: #fff;
  padding: 0.55rem 1rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  text-decoration: none; display: inline-block;
}
.btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn.secondary { background: #fff; color: var(--blue-dark); }
.btn.secondary:hover { background: var(--blue); color: #fff; }
.btn.danger { background: #fff; color: var(--bad); border-color: var(--bad-soft); }
.btn.danger:hover { background: var(--bad); color: #fff; }
.btn.small { padding: 0.3rem 0.65rem; font-size: 0.85rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

input[type=text], input[type=number], select, textarea {
  font: inherit; color: var(--ink); background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.65rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
textarea { min-height: 150px; resize: vertical; line-height: 1.5; }
label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 0.25rem; }

/* Home */
.new-review { display: grid; grid-template-columns: 1fr auto auto; gap: 0.75rem; align-items: end; }
@media (max-width: 640px) { .new-review { grid-template-columns: 1fr; } }
.review-list { display: grid; gap: 0.6rem; }
.review-item {
  display: grid; grid-template-columns: 90px 1fr auto; gap: 1rem; align-items: center;
  padding: 0.85rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: inherit;
}
.review-item:hover { border-color: var(--blue); }
.ticker { font-family: var(--mono); font-weight: 700; font-size: 1.05rem; color: var(--blue-dark); }
.pill { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); }
.pill.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.blue { background: var(--blue-soft); color: var(--blue-dark); border-color: transparent; }

/* Review layout */
.review-head { display: flex; gap: 1rem; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 1rem; }
.review-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.review-layout > * { min-width: 0; }
.sidenav { position: sticky; top: 72px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem; }
.sidenav a {
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  padding: 0.55rem 0.7rem; border-radius: 7px; text-decoration: none; color: var(--ink-2); font-weight: 500;
}
.sidenav a:hover { background: var(--bg); color: var(--ink); }
.sidenav a.active { background: var(--blue); color: #fff; }
.sidenav a.active .pill { background: rgba(255,255,255,0.2); color: #fff; }
@media (max-width: 860px) {
  .review-layout { grid-template-columns: 1fr; }
  .sidenav { position: static; display: flex; overflow-x: auto; gap: 0.25rem; }
  .sidenav a { white-space: nowrap; }
}

/* Data */
.flags { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.4rem; }
.flags li { padding: 0.45rem 0.7rem; border-radius: 7px; border-left: 4px solid var(--line); background: var(--bg); }
.flags li.good { border-left-color: var(--good); }
.flags li.warn { border-left-color: var(--warn); }
.flags li.neutral { border-left-color: var(--ink-3); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table.fin { border-collapse: collapse; width: 100%; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
table.fin th, table.fin td { padding: 0.4rem 0.6rem; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.fin th:first-child, table.fin td:first-child { text-align: left; position: sticky; left: 0; background: #fff; font-weight: 500; }
table.fin thead th { background: var(--bg); font-weight: 600; }
table.fin thead th:first-child { background: var(--bg); }
table.fin tr.group td { background: var(--bg); font-weight: 700; color: var(--ink-2); text-align: left; }
.neg { color: var(--bad); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.6rem; }
.kpi { background: var(--bg); border-radius: 8px; padding: 0.6rem 0.75rem; }
.kpi .k { font-size: 0.78rem; color: var(--ink-3); }
.kpi .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.filings { list-style: none; padding: 0; margin: 0; columns: 2 280px; }
.filings li { break-inside: avoid; padding: 0.2rem 0; }
.filings .form { font-family: var(--mono); font-weight: 700; display: inline-block; min-width: 64px; }

/* Questions and grades */
.question .q-prompt { font-weight: 600; font-size: 1.02rem; margin-bottom: 0.3rem; }
.question .q-help { color: var(--ink-3); font-size: 0.88rem; margin-bottom: 0.7rem; }
.question .q-actions { margin-top: 0.6rem; }
.save-state { font-size: 0.8rem; color: var(--ink-3); }
.grade { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.score { display: inline-grid; place-items: center; width: 54px; height: 54px; border-radius: 50%; font-size: 1.2rem; font-weight: 800; color: #fff; }
.score.weak { background: var(--bad); }
.score.adequate { background: var(--warn); }
.score.strong { background: var(--good); }
.grade-head { display: flex; gap: 0.9rem; align-items: center; margin-bottom: 0.75rem; }
.criteria { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.5rem; margin: 0.75rem 0; }
.criterion { background: var(--bg); border-radius: 8px; padding: 0.5rem 0.7rem; font-size: 0.87rem; }
.criterion b { display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-2); }
.grade-block { margin-top: 0.8rem; }
.grade-block h4 { margin: 0 0 0.3rem; font-size: 0.9rem; }
.grade-block ul { margin: 0; padding-left: 1.2rem; }
.challenges { background: var(--blue-soft); border-radius: 8px; padding: 0.75rem 0.9rem; }
.challenges li { margin-bottom: 0.3rem; }
.conflicts { background: var(--bad-soft); border-radius: 8px; padding: 0.75rem 0.9rem; }
.history { font-size: 0.82rem; color: var(--ink-3); margin-top: 0.6rem; }

/* Valuation */
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0.75rem; }
.calc-grid .hint { font-size: 0.78rem; color: var(--ink-3); margin-top: 0.15rem; }
.check { display: flex; gap: 0.5rem; align-items: center; font-weight: 500; }
.check input { width: auto; }
.results { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.6rem; margin-top: 1rem; }
.result { border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.75rem; }
.result.hl { border-color: var(--blue); background: var(--blue-soft); }
.result .k { font-size: 0.78rem; color: var(--ink-3); }
.result .v { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Memo */
.memo { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 1.2rem 1.4rem; }
.memo h1, .memo h2, .memo h3 { margin-top: 1rem; }
.memo h1:first-child, .memo h2:first-child { margin-top: 0; }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--ink-3); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 0.4rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 0.65rem 1rem; border-radius: 8px; max-width: min(92vw, 560px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.18); z-index: 50; font-size: 0.92rem;
}
.toast.error { background: var(--bad); }
