:root {
  --paper: #E7EDE1;
  --paper-line: #C4D0BB;
  --panel: #F1F5EC;
  --ink: #17231A;
  --ink-soft: #46543F;
  --rule: #AEBBA4;
  --stamp-red: #A23B2E;
  --stamp-blue: #2C4A6E;
  --gain: #3C7A4E;
  --loss: #A23B2E;
  --font-display: "Newsreader", Georgia, serif;
  --font-body: "IBM Plex Sans", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

/* The browser's default [hidden] { display: none } rule only wins when
   nothing else sets display on the same element. Several classes below
   (.auth-form, .ratios-export, ...) set display: flex directly, which
   silently overrides [hidden] and leaves the element visible even
   though els.someId.hidden = true in app.js. This one rule makes hidden
   actually mean hidden everywhere, present and future, instead of
   requiring every such class to be patched individually. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100vh;
  padding-bottom: 4rem;
}

/* faint ruled-ledger-paper backdrop */
.ruled-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 27px,
    var(--paper-line) 28px
  );
  opacity: 0.35;
}

a { color: var(--stamp-blue); }

.topbar {
  padding: 2.2rem 1.25rem 1.1rem;
  border-bottom: 1px solid var(--rule);
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: 0.01em;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.wordmark-spear {
  color: var(--stamp-red);
  font-size: 1rem;
  transform: rotate(45deg);
  display: inline-block;
}

.topbar-sub {
  margin-top: 0.3rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* ---------- header / auth ---------- */

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.auth-area {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.auth-signed-in {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.auth-tier-badge {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.65rem;
  background: var(--stamp-blue);
  color: var(--panel);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
}

.auth-link-btn {
  background: none;
  border: none;
  color: var(--stamp-blue);
  text-decoration: underline;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0;
}

/* ---------- auth panel ---------- */

.auth-panel {
  max-width: 340px;
  margin: 0 auto 2rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
  padding: 1.2rem;
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.auth-tab {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-body);
  font-size: 0.85rem;
  border-radius: 4px;
  cursor: pointer;
}

.auth-tab.on {
  border-color: var(--stamp-blue);
  color: var(--stamp-blue);
  font-weight: 600;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.auth-form input {
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 0.65rem 0.7rem;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
}

.auth-error {
  color: var(--stamp-red);
  font-size: 0.82rem;
}

.auth-status {
  color: var(--gain);
  font-size: 0.82rem;
}

.auth-help-text {
  font-size: 0.8rem;
  color: var(--ink-soft);
  margin: 0;
}

.auth-forgot-link {
  display: block;
  text-align: right;
  margin-top: 0.5rem;
  font-size: 0.78rem;
}

.auth-verify-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.auth-submit {
  padding: 0.65rem;
  border: none;
  border-radius: 4px;
  background: var(--stamp-blue);
  color: var(--panel);
  font-weight: 600;
  cursor: pointer;
}

.auth-close {
  width: 100%;
  margin-top: 0.6rem;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
}

/* ---------- pricing ---------- */

.pricing-panel { margin-bottom: 2rem; }

.pricing-panel h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin-bottom: 0.2rem;
}

.pricing-note {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-bottom: 1rem;
}

.checkout-status {
  font-size: 0.82rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  background: var(--panel);
  border: 1px solid var(--rule);
}

.checkout-status--success { color: var(--gain); border-color: var(--gain); }
.checkout-status--error { color: var(--loss); border-color: var(--loss); }
.checkout-status--info { color: var(--ink-soft); }

.account-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-bottom: 1rem;
}

.account-summary:empty { display: none; margin: 0; }

.pricing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.pricing-card {
  border: 1.5px solid var(--rule);
  border-radius: 6px;
  padding: 1rem;
  background: var(--panel);
}

.pricing-card.current { border-color: var(--stamp-blue); }

.pricing-card h3 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  margin: 0 0 0.4rem;
}

.pricing-card ul {
  margin: 0.5rem 0 0.8rem;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.pricing-btn {
  width: 100%;
  padding: 0.55rem;
  border: 1.5px solid var(--stamp-blue);
  border-radius: 4px;
  background: transparent;
  color: var(--stamp-blue);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  cursor: pointer;
}

.pricing-btn:disabled {
  border-color: var(--rule);
  color: var(--ink-soft);
  cursor: default;
}

/* ---------- ratios locked state ---------- */

.ratios-teaser {
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
  margin: 0.7rem 0 0;
}

.ratios-locked {
  border: 1px dashed var(--rule);
  border-radius: 6px;
  padding: 1.2rem;
  text-align: center;
}

.ratios-locked p {
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin: 0 0 0.8rem;
}

.unlock-btn {
  padding: 0.55rem 1.1rem;
  border: 1.5px solid var(--stamp-blue);
  border-radius: 4px;
  background: var(--stamp-blue);
  color: var(--panel);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  cursor: pointer;
}

/* ---------- watchlist ---------- */

.watchlist-panel {
  margin-bottom: 1.75rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
  padding: 1rem 1.1rem;
}

.watchlist-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.watchlist-head h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.watchlist-hint {
  font-size: 0.7rem;
  color: var(--ink-soft);
  text-align: right;
}

.watchlist-list { list-style: none; margin: 0; padding: 0; }

.watchlist-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--paper-line);
  cursor: pointer;
}

.watchlist-list li:last-child { border-bottom: none; }

.watchlist-list .wl-ticker {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--stamp-blue);
  width: 4.2rem;
  flex-shrink: 0;
}

.watchlist-list .wl-name {
  flex: 1;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
}

.wl-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  background: var(--stamp-red);
  color: var(--panel);
  padding: 0.2rem 0.45rem;
  border-radius: 3px;
  flex-shrink: 0;
}

.wl-remove {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.3rem;
  flex-shrink: 0;
}

.wl-remove:hover { color: var(--stamp-red); }

.watchlist-empty {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.watchlist-toggle {
  display: block;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 0.6rem;
  margin-bottom: 1.5rem;
  border: 1.5px solid var(--stamp-blue);
  border-radius: 4px;
  background: transparent;
  color: var(--stamp-blue);
  cursor: pointer;
}

.watchlist-toggle:active { background: rgba(44, 74, 110, 0.08); }
.watchlist-toggle.on {
  background: var(--stamp-blue);
  color: var(--panel);
}

/* ---------- ratios ---------- */

.ratios-block { margin-bottom: 2rem; }

.ratios-export {
  display: flex;
  gap: 1rem;
  margin: -0.3rem 0 1rem;
}

.ratios-export-teaser {
  text-align: left;
  margin: -0.3rem 0 1rem;
}

.ratios-tier { margin-bottom: 1.2rem; }
.ratios-tier:last-of-type { margin-bottom: 0; }

/* ---------- peer benchmark ---------- */

.ratios-benchmark {
  margin-top: 1.4rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
}

.benchmark-input-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.benchmark-input-row input {
  flex: 1 1 260px;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}

.benchmark-status {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0 0 0.6rem;
}

.benchmark-table-wrap {
  overflow-x: auto;
}

.benchmark-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.82rem;
}

.benchmark-table th,
.benchmark-table td {
  padding: 0.4rem 0.6rem;
  text-align: right;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}

.benchmark-table th:first-child,
.benchmark-table td:first-child {
  text-align: left;
  white-space: normal;
}

.benchmark-table thead th {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.ratios-tier-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--stamp-blue);
  margin: 0 0 0.5rem;
}

.ratios-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.ratio-card {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.8rem 0.9rem;
}

.ratio-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 0.3rem;
}

.ratio-value {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
}

.ratio-formula {
  font-size: 0.68rem;
  color: var(--ink-soft);
  margin-top: 0.25rem;
  line-height: 1.35;
}

@media (max-width: 420px) {
  .ratios-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- search ---------- */

.search-panel { margin-bottom: 1.5rem; position: relative; }

.search-label {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}

.search-row input {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 1rem;
  padding: 0.85rem 0.9rem;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.search-row input:focus {
  border-color: var(--stamp-blue);
  box-shadow: 0 0 0 3px rgba(44, 74, 110, 0.15);
}

.search-results {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--panel);
  max-height: 320px;
  overflow-y: auto;
  position: absolute;
  width: 100%;
  z-index: 5;
  box-shadow: 0 8px 20px rgba(23, 35, 26, 0.12);
}

.search-results li {
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--paper-line);
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: baseline;
}

.search-results li:last-child { border-bottom: none; }
.search-results li:hover, .search-results li:focus { background: var(--paper); }

.search-results .r-ticker {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--stamp-blue);
  flex-shrink: 0;
}

.search-results .r-name {
  color: var(--ink-soft);
  font-size: 0.9rem;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- states ---------- */

.empty-state, .loading-state, .error-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--ink-soft);
}

.empty-mark {
  font-size: 1.5rem;
  color: var(--stamp-red);
  transform: rotate(45deg);
  margin-bottom: 1rem;
}

.empty-state p, .error-state p {
  max-width: 34ch;
  margin: 0 auto;
  line-height: 1.5;
  font-size: 0.95rem;
}

.error-state p { color: var(--stamp-red); }

.stamp-spinner {
  width: 46px;
  height: 46px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  border: 3px solid var(--paper-line);
  border-top-color: var(--stamp-red);
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .stamp-spinner { animation: none; }
}

/* ---------- company header + stamp ---------- */

.company-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.company-id h1 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0 0 0.3rem;
  line-height: 1.2;
}

.company-meta {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.stamp { flex-shrink: 0; }

.stamp-ring {
  width: 92px;
  height: 92px;
  border: 2.5px solid var(--stamp-red);
  border-radius: 50%;
  color: var(--stamp-red);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform: rotate(-8deg);
  font-family: var(--font-mono);
  opacity: 0.85;
  position: relative;
}

.stamp-ring::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid var(--stamp-red);
  border-radius: 50%;
}

.stamp-ticker { font-weight: 600; font-size: 0.95rem; letter-spacing: 0.03em; }
.stamp-word { font-size: 0.55rem; letter-spacing: 0.15em; margin: 2px 0; }
.stamp-cik { font-size: 0.5rem; opacity: 0.85; }

/* ---------- snapshot cards ---------- */

.snapshot-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.snap-card {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.9rem 1rem;
}

.snap-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.snap-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 600;
}

.snap-change {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  margin-top: 0.3rem;
}

.snap-change.up { color: var(--gain); }
.snap-change.down { color: var(--loss); }
.snap-change.flat { color: var(--ink-soft); }

/* ---------- charts ---------- */

.chart-block, .balance-block, .filings-block { margin-bottom: 2rem; }

.chart-block h2, .balance-block h2, .filings-block h2 {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
  margin: 0 0 0.9rem;
}

.chart svg { width: 100%; height: auto; display: block; }
.chart .bar-label {
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--ink-soft);
}
.chart .bar-value {
  font-family: var(--font-mono);
  font-size: 9.5px;
  fill: var(--ink);
  font-weight: 600;
}
.chart .no-data { color: var(--ink-soft); font-size: 0.9rem; padding: 1rem 0; }

/* ---------- balance sheet ---------- */

.balance-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.92rem;
}

.balance-grid dt { color: var(--ink-soft); }
.balance-grid dd { margin: 0; text-align: right; font-weight: 600; }

/* ---------- filings ---------- */

.filings-list { list-style: none; margin: 0; padding: 0; }

.filings-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--paper-line);
}

.filings-list li:last-child { border-bottom: none; }

.filing-form {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--stamp-blue);
  flex-shrink: 0;
  width: 3.2rem;
}

.filing-date {
  flex: 1;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.filing-link {
  font-size: 0.85rem;
  text-decoration: none;
  border-bottom: 1px dotted var(--stamp-blue);
}

.data-note {
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.5;
  border-top: 1px solid var(--rule);
  padding-top: 1rem;
}

@media (max-width: 420px) {
  .snapshot-grid { grid-template-columns: 1fr 1fr; }
  .stamp-ring { width: 78px; height: 78px; }
}
