/* ============================================================
   Subscription Autopsy — clinical / pathology-report styling
   ============================================================ */

:root {
  --paper: #f4f1ea;
  --paper-2: #faf8f3;
  --ink: #1a1a1a;
  --ink-soft: #4a4a48;
  --ink-faint: #8a8780;
  --line: #d8d3c7;
  --line-strong: #b8b2a3;
  --card: #fffefb;
  --accent: #c1272d;       /* pathology red */
  --accent-dark: #8e1a1f;
  --accent-soft: #f6e3e3;
  --green: #2f7d52;
  --amber: #b6822a;
  --shadow: 0 1px 2px rgba(40, 35, 25, .06), 0 4px 16px rgba(40, 35, 25, .05);
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* the [hidden] attribute must win over author display rules (e.g. display:flex) */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(184,178,163,.18) 31px, rgba(184,178,163,.18) 32px),
    var(--paper);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding: 16px;
}

.report {
  max-width: 600px;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- Masthead ---------- */
.masthead {
  padding: 22px 22px 24px;
  border-bottom: 2px solid var(--ink);
  background:
    linear-gradient(180deg, #fffefb 0%, var(--paper) 100%);
}
.masthead-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .08em;
  color: var(--ink-faint);
  text-transform: uppercase;
  margin-bottom: 14px;
}
.case-no { font-weight: 600; color: var(--ink-soft); }
.title {
  font-size: clamp(28px, 8vw, 38px);
  font-weight: 900;
  letter-spacing: -.03em;
  display: flex;
  align-items: center;
  gap: 10px;
  line-height: 1;
}
.title-icon { width: 30px; height: 30px; color: var(--accent); stroke-width: 2.4; }
.subtitle {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 15px;
  max-width: 42ch;
}

/* currency switch */
.currency-switch {
  display: flex; width: 100%; margin-top: 18px;
  border: 1.5px solid var(--line-strong); border-radius: 11px; overflow: hidden;
}
.cur-opt {
  flex: 1; background: var(--card); border: none; padding: 12px 8px;
  font-family: var(--mono); font-size: 14px; font-weight: 600; cursor: pointer;
  color: var(--ink-soft); transition: background .12s, color .12s; white-space: nowrap;
}
.cur-opt + .cur-opt { border-left: 1.5px solid var(--line-strong); }
.cur-opt:hover:not(.is-active) { background: var(--paper-2); }
.cur-opt.is-active { background: var(--ink); color: var(--paper); }

/* ---------- Panels ---------- */
.panel { padding: 20px 22px; border-bottom: 1px solid var(--line); }
.panel-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 16px;
}
.panel-heading svg { width: 16px; height: 16px; color: var(--accent); }
.count-badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 20px;
  padding: 2px 9px;
  min-width: 24px;
  text-align: center;
}

/* ---------- Search ---------- */
.search-wrap { position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute; left: 14px; width: 18px; height: 18px;
  color: var(--ink-faint); pointer-events: none;
}
.search-input {
  width: 100%;
  font-family: var(--sans);
  font-size: 16px;
  padding: 13px 42px 13px 42px;
  border: 1.5px solid var(--line-strong);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-clear {
  position: absolute; right: 8px;
  background: none; border: none; cursor: pointer;
  padding: 6px; border-radius: 8px; color: var(--ink-faint);
  display: flex;
}
.search-clear:hover { background: var(--line); color: var(--ink); }
.search-clear svg { width: 18px; height: 18px; }

/* ---------- Catalog results ---------- */
.catalog { margin-top: 8px; }
.catalog:empty { margin-top: 0; }

.cat-row { border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: none; }

.cat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: none;
  border: none;
  padding: 11px 4px;
  cursor: pointer;
  text-align: left;
  font-family: var(--sans);
  color: var(--ink);
}
.cat-head:hover { background: rgba(0,0,0,.02); }
.cat-name { font-weight: 600; font-size: 15px; flex: 1; }
.cat-cat { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }
.chevron { width: 18px; height: 18px; color: var(--ink-faint); transition: transform .2s; }
.cat-row.open .chevron { transform: rotate(180deg); }

.tier-list { display: none; padding: 0 4px 10px 52px; }
.cat-row.open .tier-list { display: block; }
.tier-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  font-family: var(--sans);
  color: var(--ink);
  transition: border-color .12s, background .12s;
}
.tier-btn:hover { border-color: var(--accent); background: #fff; }
.tier-btn.added { opacity: .5; pointer-events: none; }
.tier-name { flex: 1; text-align: left; font-size: 14px; }
.tier-price { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.tier-cycle { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }
.tier-add-icon { width: 16px; height: 16px; color: var(--accent); }

.no-results {
  font-size: 14px; color: var(--ink-faint);
  padding: 14px 4px; text-align: center; font-style: italic;
}

/* ---------- Logos ---------- */
.logo {
  width: 30px; height: 30px; border-radius: 7px;
  object-fit: cover; background: #fff; flex-shrink: 0;
  border: 1px solid var(--line);
}
.logo-fallback {
  width: 30px; height: 30px; border-radius: 7px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
  font-family: var(--sans);
}

/* ---------- Add custom ---------- */
.add-custom-btn {
  margin-top: 14px;
  display: flex; align-items: center; gap: 7px;
  background: none; border: 1.5px dashed var(--line-strong);
  border-radius: 9px; padding: 11px 14px; width: 100%;
  cursor: pointer; font-family: var(--sans); font-size: 14px;
  font-weight: 500; color: var(--ink-soft);
  transition: border-color .12s, color .12s;
}
.add-custom-btn:hover { border-color: var(--accent); color: var(--accent); }
.add-custom-btn svg { width: 18px; height: 18px; }
.add-custom-btn span { flex: 1; text-align: left; }
.add-custom-chevron { transition: transform .2s; }
.add-custom-btn[aria-expanded="true"] .add-custom-chevron { transform: rotate(180deg); }

.custom-form { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.custom-row { display: flex; gap: 10px; }
.custom-row.split { flex-wrap: wrap; }
.custom-form input[type=text],
.custom-form input[type=number] {
  font-family: var(--sans); font-size: 15px;
  padding: 11px 12px; border: 1.5px solid var(--line-strong);
  border-radius: 9px; background: var(--card); color: var(--ink); width: 100%;
}
.custom-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.price-field { position: relative; flex: 1; min-width: 130px; display: flex; align-items: center; }
.price-field .dollar { position: absolute; left: 12px; font-family: var(--mono); color: var(--ink-faint); }
.price-field input { padding-left: 26px !important; }

/* segmented cycle toggle */
.cycle-seg {
  display: inline-flex; border: 1.5px solid var(--line-strong);
  border-radius: 9px; overflow: hidden; flex-shrink: 0;
}
.cycle-opt {
  background: var(--card); border: none; padding: 11px 14px;
  font-family: var(--mono); font-size: 12px; cursor: pointer;
  color: var(--ink-soft); transition: background .12s, color .12s;
}
.cycle-opt.is-active { background: var(--ink); color: var(--paper); }

.custom-submit {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent); color: #fff; border: none;
  border-radius: 9px; padding: 12px; font-family: var(--sans);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background .12s;
}
.custom-submit:hover { background: var(--accent-dark); }
.custom-submit svg { width: 17px; height: 17px; }

/* ---------- Subs list (on the table) ---------- */
.empty-state {
  text-align: center; padding: 18px 10px; color: var(--ink-faint);
}
.empty-state svg { width: 32px; height: 32px; margin-bottom: 8px; opacity: .6; }
.empty-state p { font-size: 14px; }

.sub-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.sub-top { display: flex; align-items: center; gap: 11px; }
.sub-id { flex: 1; min-width: 0; }
.sub-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-tier { font-size: 12px; color: var(--ink-faint); font-family: var(--mono); }
.sub-remove {
  background: none; border: none; cursor: pointer; color: var(--ink-faint);
  padding: 6px; border-radius: 7px; display: flex; flex-shrink: 0;
}
.sub-remove:hover { background: var(--accent-soft); color: var(--accent); }
.sub-remove svg { width: 18px; height: 18px; }

.sub-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 11px; padding-top: 11px; border-top: 1px dashed var(--line);
}
.inline-price { position: relative; display: flex; align-items: center; width: 110px; }
.inline-price .dollar { position: absolute; left: 10px; font-family: var(--mono); font-size: 13px; color: var(--ink-faint); }
.inline-price input {
  width: 100%; font-family: var(--mono); font-size: 14px; font-weight: 600;
  padding: 8px 8px 8px 22px; border: 1.5px solid var(--line-strong);
  border-radius: 8px; background: var(--paper-2); color: var(--ink);
}
.inline-price input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.cycle-seg.sm .cycle-opt { padding: 8px 11px; font-size: 11px; }

.uses-field {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--ink-faint); font-family: var(--mono);
  margin-left: auto;
}
.uses-field input {
  width: 46px; font-family: var(--mono); font-size: 13px; text-align: center;
  padding: 7px 4px; border: 1.5px solid var(--line-strong); border-radius: 8px;
  background: var(--paper-2); color: var(--ink);
}
.uses-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.uses-field svg { width: 14px; height: 14px; }

.per-use {
  width: 100%; margin-top: 8px; font-family: var(--mono); font-size: 12px;
  display: none; align-items: center; gap: 6px;
}
.per-use.show { display: flex; }
.per-use .pu-val { font-weight: 700; }
.per-use.warn { color: var(--accent); }
.per-use.warn svg { width: 14px; height: 14px; }
.per-use.ok { color: var(--green); }

/* ---------- Autopsy ---------- */
.autopsy { padding: 6px 22px 22px; }

.toe-tag {
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 22px 20px 24px;
  text-align: center;
  margin: 14px 0;
  position: relative;
  overflow: hidden;
}
.toe-tag::before {
  content: ""; position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(244,241,234,.35);
}
.toe-tag-label {
  display: block; font-family: var(--mono); font-size: 11px; letter-spacing: .25em;
  color: var(--accent); font-weight: 700; margin-top: 16px;
}
.toe-tag-sub { display: block; font-size: 12px; color: rgba(244,241,234,.6); margin-top: 4px; }
.headline-number {
  font-family: var(--mono); font-weight: 700;
  font-size: clamp(46px, 15vw, 76px);
  letter-spacing: -.03em; line-height: 1; margin: 10px 0 6px;
  color: #fff;
  text-shadow: 0 2px 30px rgba(193,39,45,.5);
}
.headline-sub { font-family: var(--mono); font-size: 13px; color: rgba(244,241,234,.75); }

.verdict {
  background: var(--accent-soft);
  border: 1px solid #e8c9c9;
  border-radius: 9px;
  padding: 14px 16px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--accent-dark);
  margin-bottom: 18px;
}
.verdict strong { font-weight: 700; }

/* multi-year projection */
.projection {
  border: 1px dashed var(--line-strong);
  border-radius: 9px;
  padding: 14px 16px;
  margin-bottom: 18px;
  background: var(--paper-2);
}
.proj-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 10px;
}
.proj-label svg { width: 14px; height: 14px; color: var(--accent); }
.proj-grid { display: flex; gap: 14px; }
.proj-cell { flex: 1; text-align: center; }
.proj-num {
  display: block; font-family: var(--mono); font-weight: 700;
  font-size: clamp(22px, 6vw, 30px); color: var(--ink); letter-spacing: -.02em;
}
.proj-cap { display: block; font-size: 11px; color: var(--ink-faint); font-family: var(--mono); margin-top: 2px; }

.section-label {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-soft); margin: 18px 0 10px;
}
.section-label svg { width: 15px; height: 15px; color: var(--accent); }

/* offenders */
.offender {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.offender:last-child { border-bottom: none; }
.off-rank { font-family: var(--mono); font-size: 13px; color: var(--ink-faint); width: 20px; }
.off-id { flex: 1; min-width: 0; }
.off-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.off-meta { font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }
.off-amt { text-align: right; }
.off-year { font-family: var(--mono); font-weight: 700; font-size: 15px; }
.off-month { font-family: var(--mono); font-size: 11px; color: var(--ink-faint); }
.off-flag {
  font-family: var(--mono); font-size: 10px; color: var(--accent);
  background: var(--accent-soft); border-radius: 5px; padding: 1px 6px; margin-top: 2px; display: inline-block;
}

/* categories */
.cat-bar-row { margin-bottom: 12px; }
.cat-bar-top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; margin-bottom: 4px;
}
.cat-bar-name { font-weight: 500; }
.cat-bar-val { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.cat-bar-track { height: 8px; background: var(--line); border-radius: 5px; overflow: hidden; }
.cat-bar-fill { height: 100%; background: var(--accent); border-radius: 5px; transition: width .5s ease; }

/* share */
.share-row { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.share-btn {
  flex: 1; min-width: 150px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--ink); color: var(--paper); border: none;
  border-radius: 10px; padding: 14px; font-family: var(--sans);
  font-size: 15px; font-weight: 600; cursor: pointer; transition: opacity .12s, background .12s;
}
.share-btn:hover { opacity: .88; }
.share-btn.ghost { background: var(--card); color: var(--ink); border: 1.5px solid var(--line-strong); }
.share-btn.ghost:hover { border-color: var(--ink); opacity: 1; }
.share-btn svg { width: 18px; height: 18px; }

/* footer */
.footer { padding: 22px; text-align: center; }
.footer p { font-size: 13px; color: var(--ink-faint); }
.footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
.footer .dot { margin: 0 6px; }
.disclaimer { margin-top: 8px; font-size: 11px; line-height: 1.5; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper);
  font-size: 14px; font-weight: 500;
  padding: 12px 20px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
  display: flex; align-items: center; gap: 8px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  body { padding: 8px; }
  .panel, .autopsy { padding-left: 16px; padding-right: 16px; }
  .masthead { padding: 18px 16px 20px; }
  .uses-field { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
