/* SaaS Survival Scorecard — Convequity preview
   Visual tokens copied from the Convequity app family (DCF / Live Portfolio). */

:root {
  --accent: #5B47FB;
  --accent-2: #7c6bfa;
  --bg: #f5f7fa;
  --elevated: #ffffff;
  --secondary: #f8fafc;
  --text: #0f172a;
  --muted: #475569;
  --dim: #64748b;
  --border: rgba(0, 0, 0, 0.06);
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.10);
  --gold: #d9a40b;
  --gold-tint: rgba(217, 164, 11, 0.10);
  --nav-h: 64px;
}

html[data-theme="dark"] {
  --bg: #000000;
  --elevated: #1C1C1E;
  --secondary: #2C2C2E;
  --tertiary: #3A3A3C;
  --text: #F5F5F7;
  --muted: #A1A1A6;
  --dim: #8E8E93;
  --border: #38383A;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.55);
  --gold: #e5b52a;
  --gold-tint: rgba(229, 181, 42, 0.12);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ---------- Top nav ---------- */

.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  background: color-mix(in srgb, var(--elevated) 82%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topnav-inner {
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  object-fit: cover;
  flex: none;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  padding: 2px 8px;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--dim);
  white-space: nowrap;
}

.appnav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
  font-size: 13px;
}

.appnav a {
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.appnav a:hover { color: var(--accent); }

.appnav-current {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 2px;
}

.theme-toggle {
  display: flex;
  gap: 2px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  flex: none;
}

.theme-toggle button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
}
.theme-toggle button:hover { color: var(--text); }
.theme-toggle button[aria-pressed="true"] {
  background: var(--elevated);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ---------- Page layout ---------- */

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: clamp(24px, 3.4vw, 34px);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0;
  max-width: 860px;
  color: var(--muted);
  font-size: 15px;
}
.hero strong { color: var(--text); }

/* ---------- Related research (Taste note-item / track-report) ---------- */

.related-lede {
  margin: -4px 0 16px;
  font-size: 14px;
  color: var(--muted);
}

.related-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.note-item {
  padding: 20px;
  border-radius: var(--r-md);
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 20px;
  align-items: start;
  background: var(--elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
.note-item:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}
.note-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.note-img-wrap {
  width: 100%;
  height: 120px;
  border-radius: 12px;
  overflow: hidden;
}
.note-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s ease;
}
.note-item:hover .note-img-wrap img { transform: scale(1.05); }

.note-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.note-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.note-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.note-item:hover .note-title { color: var(--accent); }
.note-desc {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-item .seg {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: 3px 9px;
  border-radius: 6px;
  letter-spacing: 0.02em;
  flex: none;
}

h2 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ---------- Legend ---------- */

.legend {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}

.legend ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13.5px;
  color: var(--muted);
}
.legend strong { color: var(--text); }

.swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 14px;
  border-radius: 4px;
  margin-right: 8px;
  vertical-align: -2px;
  font-size: 9px;
  font-weight: 700;
}
.swatch-gold { background: var(--gold-tint); border-left: 3px solid var(--gold); }
.swatch-dash { color: var(--dim); }
.swatch-half {
  width: auto;
  padding: 0 5px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

/* ---------- Bucket strip ---------- */

.bucket-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.bucket-card {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
}

.bucket-card .bucket-name {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.bucket-card .bucket-meta {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 8px;
}

.bucket-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--secondary);
  overflow: hidden;
}
html[data-theme="dark"] .bucket-bar { background: var(--tertiary); }

.bucket-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ---------- Filters ---------- */

.scorecard-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.row-count { font-size: 12.5px; color: var(--dim); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 14px;
}

.chip {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border);
  margin: 2px 4px;
}

/* ---------- Heatmap table ---------- */

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--elevated);
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - var(--nav-h) - 24px);
}

.score-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 1180px;
  font-size: 13px;
}

.score-table th,
.score-table td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.score-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--elevated);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--dim);
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
.score-table thead th:hover { color: var(--accent); }
.score-table thead th .sort-arrow { font-size: 9px; margin-left: 3px; }

.score-table thead th.col-company,
.score-table tbody td.col-company,
.score-table tbody th.col-company {
  position: sticky;
  left: 0;
  z-index: 2;
  text-align: left;
  background: var(--elevated);
  box-shadow: 1px 0 0 var(--border);
  min-width: 190px;
}
.score-table thead th.col-company { z-index: 4; }

.score-table tbody tr { cursor: pointer; }
.score-table tbody tr:hover td,
.score-table tbody tr:hover th.col-company { filter: brightness(0.97); }
html[data-theme="dark"] .score-table tbody tr:hover td,
html[data-theme="dark"] .score-table tbody tr:hover th.col-company { filter: brightness(1.18); }
.score-table tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.score-table tbody tr.deep-dive th.col-company {
  box-shadow: inset 3px 0 0 var(--gold), 1px 0 0 var(--border);
}
.score-table tbody tr.deep-dive td,
.score-table tbody tr.deep-dive th.col-company {
  background-image: linear-gradient(var(--gold-tint), var(--gold-tint));
}

.cell-company-name { font-weight: 700; font-size: 13.5px; }
.cell-company-meta { font-size: 11px; color: var(--dim); font-weight: 500; }
.cell-company-meta .gold-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  margin-right: 4px;
  vertical-align: 1px;
}

.score-cell {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: 0;
}
.score-empty { color: var(--dim); font-weight: 400; }

.cell-bucket { font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; }

.table-note {
  margin: 10px 2px 0;
  font-size: 12px;
  color: var(--dim);
}

/* ---------- Factor criteria ---------- */

.criteria-lede {
  margin: 0 0 18px;
  max-width: 860px;
  color: var(--muted);
  font-size: 14.5px;
}

.criteria-pillar { margin-bottom: 28px; }

.criteria-pillar h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.criteria-card {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px 14px;
  margin-bottom: 12px;
  scroll-margin-top: calc(var(--nav-h) + 12px);
}

.criteria-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.criteria-id {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.04em;
}

.criteria-name {
  font-size: 15px;
  font-weight: 700;
}

.criteria-q {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
}

.ladder {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ladder li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
}

.ladder-n {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
}

.ladder li[data-rung="1"] .ladder-n { background: #94a3b8; }
.ladder li[data-rung="2"] .ladder-n { background: #7c8db0; }
.ladder li[data-rung="3"] .ladder-n { background: #6b6fd4; }
.ladder li[data-rung="4"] .ladder-n { background: #5B47FB; }
.ladder li[data-rung="5"] .ladder-n { background: #4c2fe0; }
html[data-theme="dark"] .ladder li[data-rung="1"] .ladder-n { background: #5c5c62; }

.criteria-notes {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--dim);
  line-height: 1.45;
}

.legend a { color: var(--accent); font-weight: 600; text-decoration: none; }
.legend a:hover { text-decoration: underline; }

/* ---------- Drawer ---------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.2s;
}
.drawer-backdrop.open { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  width: min(440px, 100vw);
  background: var(--elevated);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transform: translateX(100%);
  transition: transform 0.24s ease;
  overflow-y: auto;
}
.drawer.open { transform: translateX(0); }

.drawer-inner { padding: 20px 22px 32px; }

.drawer-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-left: auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--secondary);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.drawer-close:hover { color: var(--accent); border-color: var(--accent); }

.drawer h3 {
  margin: 4px 0 2px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.drawer-ticker { font-size: 13px; color: var(--dim); font-weight: 600; }

.drawer-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 18px; }
.drawer-tag {
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--secondary);
  border: 1px solid var(--border);
  color: var(--muted);
}
.drawer-tag.tag-accent { color: #fff; background: var(--accent); border-color: var(--accent); }
.drawer-tag.tag-gold { color: var(--gold); border-color: var(--gold); background: var(--gold-tint); }

.drawer h4 {
  margin: 20px 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--dim);
}

.pillar-bars { display: flex; flex-direction: column; gap: 10px; }
.pillar-bar-row { display: grid; grid-template-columns: 150px 1fr 42px; align-items: center; gap: 10px; font-size: 12.5px; }
.pillar-bar-row .pbar-label { color: var(--muted); font-weight: 600; }
.pillar-bar-track { height: 8px; border-radius: 999px; background: var(--secondary); overflow: hidden; }
html[data-theme="dark"] .pillar-bar-track { background: var(--tertiary); }
.pillar-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.pillar-bar-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

.factor-list { display: flex; flex-direction: column; gap: 8px; }
.factor-row {
  display: grid;
  grid-template-columns: 34px 1fr 40px;
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  background: var(--secondary);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 12.5px;
}
html[data-theme="dark"] .factor-row { background: var(--secondary); }
.factor-id { font-weight: 800; color: var(--accent); }
.factor-name { font-weight: 600; color: var(--text); line-height: 1.35; }
.factor-def { color: var(--dim); font-size: 12px; margin-top: 2px; line-height: 1.4; }
.factor-score { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 14px; }
.factor-score.empty { color: var(--dim); font-weight: 500; }

.factor-row.expanded {
  grid-template-columns: 34px 1fr 40px;
}

.factor-ladder {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}

.factor-ladder .rung {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--dim);
  padding: 4px 6px;
  border-radius: 6px;
}

.factor-ladder .rung.active {
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  font-weight: 600;
}

.factor-ladder .rung-n {
  font-weight: 800;
  color: var(--accent);
}

/* ---------- Footer ---------- */

.footer {
  border-top: 1px solid var(--border);
  padding: 24px 20px 40px;
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
}
.footer p { margin: 0 0 6px; }
.footer-dim { color: var(--dim); }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .appnav a { display: none; }
  .related-list { grid-template-columns: 1fr; }
  .note-item { grid-template-columns: 1fr; }
  .note-img-wrap { height: 160px; }
}

@media (max-width: 640px) {
  :root { --nav-h: 58px; }
  .brand-subtitle { display: none; }
  .brand-title { font-size: 13.5px; }
  .topnav-inner { gap: 12px; padding: 0 14px; }
  .page { padding: 22px 14px 48px; }
  .note-item { padding: 16px; gap: 14px; }
  .note-img-wrap { height: 140px; }
  .note-title { font-size: 15px; }
  .drawer {
    width: 100vw;
    border-left: 0;
  }
  .table-wrap { max-height: none; }
  .score-table thead th { top: 0; }
  .pillar-bar-row { grid-template-columns: 110px 1fr 40px; }
}
