/* Lung-RADS v2026 calculator
   Dark is the default (reading-room friendly); light is available from the header. */

:root {
  --bg: #0e1218;
  --surface: #151b23;
  --surface-2: #1b222c;
  --surface-3: #222b37;
  --line: #29323e;
  --line-strong: #3a4554;
  --text: #e6ebf1;
  --text-2: #a9b4c2;
  --text-3: #7c8898;
  --accent: #6ea8fe;
  --accent-ink: #0b1524;
  --accent-weak: rgba(110, 168, 254, 0.12);
  --focus: rgba(110, 168, 254, 0.55);
  --warn: #f0b429;
  --warn-bg: rgba(240, 180, 41, 0.1);
  --warn-line: rgba(240, 180, 41, 0.38);
  --danger: #f07167;

  --cat-0: #9aa5b4;
  --cat-1: #3fb67b;
  --cat-2: #2fa6a0;
  --cat-3: #e0a030;
  --cat-4a: #e8743b;
  --cat-4b: #e5484d;
  --cat-4x: #c2255c;
  --cat-s: #9b7ede;

  --radius: 8px;
  --radius-lg: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

[data-theme="light"] {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --surface-3: #eceff3;
  --line: #dde2e8;
  --line-strong: #c3cbd5;
  --text: #17202b;
  --text-2: #4b5766;
  --text-3: #6b7685;
  --accent: #1f5fcc;
  --accent-ink: #ffffff;
  --accent-weak: rgba(31, 95, 204, 0.08);
  --focus: rgba(31, 95, 204, 0.45);
  --warn: #9a6200;
  --warn-bg: #fff6e0;
  --warn-line: #f0d48a;
  --danger: #c62f37;

  --cat-0: #6b7685;
  --cat-1: #1f8a54;
  --cat-2: #1b7f7a;
  --cat-3: #b07300;
  --cat-4a: #c4561d;
  --cat-4b: #c62f37;
  --cat-4x: #a1194b;
  --cat-s: #6d4fc2;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

a {
  color: var(--accent);
}

.tabular,
input[type="number"] {
  font-variant-numeric: tabular-nums;
}

.view-hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  height: 52px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.brand-mark {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.brand-title {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-version {
  font-size: 13px;
  color: var(--text-3);
}

.nav-tabs {
  display: flex;
  align-self: stretch;
  gap: 4px;
}

.nav-tab {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0 10px;
  margin-bottom: -1px;
  color: var(--text-2);
  font-weight: 550;
  cursor: pointer;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.icon-btn {
  appearance: none;
  margin-left: auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.icon-moon {
  display: none;
}

[data-theme="light"] .icon-sun {
  display: none;
}

[data-theme="light"] .icon-moon {
  display: block;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
}

.calc-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 420px);
  gap: 20px;
  align-items: start;
}

.result-sticky {
  position: sticky;
  top: 72px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px 20px;
}

.panel + .panel {
  margin-top: 12px;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 30px;
}

.panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -0.005em;
}

.panel-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
}

.divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-3);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:hover {
  background: var(--accent);
  filter: brightness(1.07);
}

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}

.btn-quiet:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.link-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 550;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

/* ---------- Segmented controls & option lists ---------- */
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg {
  appearance: none;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 520;
  text-align: left;
  cursor: pointer;
  line-height: 1.3;
}

.seg:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.seg[aria-pressed="true"] {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: var(--text);
}

.seg small {
  display: block;
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 450;
}

.seg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 6px;
}

.seg-grid .seg {
  width: 100%;
}

.seg-full {
  display: grid;
  grid-auto-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg-full .seg {
  border: 0;
  border-radius: 0;
  border-left: 1px solid var(--line);
  text-align: center;
  background: var(--surface-2);
}

.seg-full .seg:first-child {
  border-left: 0;
}

.seg-full .seg[aria-pressed="true"] {
  background: var(--accent-weak);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.option-list {
  display: grid;
  gap: 6px;
}

.option {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
}

.option:hover {
  border-color: var(--line-strong);
}

.option.is-selected {
  border-color: var(--accent);
  background: var(--accent-weak);
}

.option input {
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.option-title {
  font-weight: 550;
  font-size: 13.5px;
}

.option-desc {
  font-size: 12.5px;
  color: var(--text-3);
}

.option-cat {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.group-label {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
}

.group-label:first-child {
  margin-top: 0;
}

/* ---------- Finding type picker ---------- */
.finding-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.finding-card {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 6px 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  color: var(--text);
}

.finding-card:hover {
  border-color: var(--line-strong);
}

.finding-card[aria-pressed="true"] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.finding-card-title {
  padding: 0 3px;
  font-size: 12.5px;
  font-weight: 580;
  line-height: 1.3;
}

.ct-svg {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 5px;
}

.finding-card .ct-svg {
  height: 76px;
}

/* ---------- Nodule tabs ---------- */
.nodule-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.nodule-tab {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow: hidden;
}

.nodule-tab.is-active {
  border-color: var(--accent);
}

.nodule-tab-main {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px 5px 10px;
  border: 0;
  background: none;
  font-size: 12.5px;
  color: var(--text-2);
  cursor: pointer;
}

.nodule-tab.is-active .nodule-tab-main {
  color: var(--text);
}

.nodule-tab-remove {
  appearance: none;
  border: 0;
  border-left: 1px solid var(--line);
  background: none;
  width: 28px;
  color: var(--text-3);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.nodule-tab-remove:hover {
  color: var(--danger);
}

.mini-cat {
  min-width: 24px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 650;
  text-align: center;
  color: #fff;
  background: var(--text-3);
}

.mini-cat.is-pending {
  background: transparent;
  color: var(--warn);
  border: 1px solid var(--warn-line);
}

/* ---------- Fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field + .field {
  margin-top: 16px;
}

.field-label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 10px;
  font-size: 13px;
  font-weight: 580;
  color: var(--text);
}

.field-hint {
  font-size: 12.5px;
  color: var(--text-3);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field-grid > .field + .field {
  margin-top: 0;
}

.input,
.select {
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

[data-theme="light"] .input,
[data-theme="light"] .select {
  background: #fff;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.select-inline {
  width: auto;
  height: 30px;
  font-size: 13px;
}

.input-unit {
  position: relative;
  max-width: 180px;
}

.input-unit .input {
  padding-right: 38px;
}

.input-unit::after {
  content: "mm";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12.5px;
  color: var(--text-3);
  pointer-events: none;
}

.input-unit.unit-mo::after {
  content: "months";
}

.input-unit.unit-mo .input {
  padding-right: 62px;
}

.measure-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.measure-row .times {
  color: var(--text-3);
}

.computed {
  font-size: 12.5px;
  color: var(--text-2);
}

.computed strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.subbox {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.subbox .field-grid {
  gap: 12px;
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
}

.check + .check {
  margin-top: 6px;
}

.check input {
  margin: 3px 0 0;
  accent-color: var(--accent);
}

.check-title {
  font-weight: 550;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.check-grid .check + .check {
  margin-top: 0;
}

.requires {
  border-color: var(--warn-line);
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-2);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
}

.dot.ok {
  background: var(--cat-1);
}

.dot.no {
  background: var(--warn);
}

/* ---------- Notices ---------- */
.notice {
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13px;
  color: var(--text-2);
}

.notice + .notice {
  margin-top: 8px;
}

.notice strong {
  color: var(--text);
}

.notice-warn {
  border-color: var(--warn-line);
  background: var(--warn-bg);
  color: var(--text);
}

.notice-warn::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 8px;
  vertical-align: 2px;
  border-radius: 50%;
  background: var(--warn);
}

/* ---------- Result ---------- */
.result {
  padding: 0;
  overflow: hidden;
}

.result-head {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  border-left: 4px solid var(--cat-color, var(--line));
}

.result-body {
  padding: 16px 20px 20px;
}

.cat-badge {
  flex-shrink: 0;
  min-width: 64px;
  height: 64px;
  padding: 0 8px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--cat-color);
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.cat-badge.is-long {
  font-size: 24px;
}

.result-label {
  margin: 0;
  font-size: 12px;
  color: var(--text-3);
}

.result-desc {
  margin: 1px 0 2px;
  font-size: 17px;
  font-weight: 620;
  line-height: 1.3;
}

.result-screen {
  font-size: 12.5px;
  color: var(--text-2);
}

.cat-0 { --cat-color: var(--cat-0); }
.cat-1 { --cat-color: var(--cat-1); }
.cat-2 { --cat-color: var(--cat-2); }
.cat-3 { --cat-color: var(--cat-3); }
.cat-4a { --cat-color: var(--cat-4a); }
.cat-4b { --cat-color: var(--cat-4b); }
.cat-4x { --cat-color: var(--cat-4x); }

.mini-cat.cat-0,
.mini-cat.cat-1,
.mini-cat.cat-2,
.mini-cat.cat-3,
.mini-cat.cat-4a,
.mini-cat.cat-4b,
.mini-cat.cat-4x {
  background: var(--cat-color);
}

.result-section + .result-section {
  margin-top: 16px;
}

.result-section h3 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
}

.mgmt-list {
  margin: 0;
  padding-left: 18px;
}

.mgmt-list li {
  margin: 2px 0;
  font-weight: 550;
}

.mgmt-list li::marker {
  color: var(--text-3);
}

.result-text {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
}

.note-refs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-3);
}

.changed-line {
  margin-top: 10px;
  padding-left: 10px;
  border-left: 2px solid var(--line-strong);
  font-size: 12.5px;
  color: var(--text-2);
}

.report-box {
  margin: 0;
  padding: 12px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

[data-theme="light"] .report-box {
  background: var(--surface-2);
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.result-empty {
  padding: 28px 22px;
}

.result-empty h2 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 620;
}

.result-empty p {
  margin: 0;
  color: var(--text-3);
  font-size: 13px;
}

.todo-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.todo-list button {
  appearance: none;
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 11px;
  border: 1px solid var(--warn-line);
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--text);
  text-align: left;
  font-size: 13px;
  cursor: pointer;
}

.todo-list .todo-n {
  flex-shrink: 0;
  font-weight: 650;
  color: var(--warn);
}

/* ---------- Mobile score bar ---------- */
#mobileScoreBar {
  display: none;
}

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

  .result-sticky {
    position: static;
  }

  #mobileScoreBar {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    transition: transform 0.15s ease;
  }

  #mobileScoreBar.is-hidden {
    transform: translateY(110%);
  }

  .score-bar {
    appearance: none;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    text-align: left;
    cursor: pointer;
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.18);
  }

  .score-bar .cat-badge {
    min-width: 42px;
    height: 42px;
    font-size: 19px;
  }

  .score-bar-text {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    line-height: 1.35;
  }

  .score-bar-text span {
    display: block;
    color: var(--text-3);
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .score-bar-go {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--accent);
  }

  body {
    padding-bottom: 72px;
  }
}

@media (max-width: 760px) {
  .finding-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-grid,
  .check-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .topbar {
    position: static;
  }

  .topbar-inner {
    gap: 14px;
    padding: 0 16px;
  }

  .brand-version {
    display: none;
  }

  .container {
    padding: 12px 16px;
  }

  .panel {
    padding: 16px;
  }

  .result-head,
  .result-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .seg-full {
    grid-auto-flow: row;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .seg-full .seg {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .seg-full .seg:nth-child(-n + 2) {
    border-top: 0;
  }

  .seg-full .seg:nth-child(even) {
    border-left: 1px solid var(--line);
  }

  .seg-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .input-unit {
    max-width: none;
  }
}

@media (max-width: 380px) {
  .brand-text {
    display: none;
  }

  .nav-tab {
    padding: 0 8px;
  }

  .finding-card .ct-svg {
    height: 60px;
  }
}

/* ---------- Reference (atlas) ---------- */
.ref-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 20px;
  margin-bottom: 16px;
}

.ref-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.ref-head p {
  margin: 2px 0 0;
  color: var(--text-3);
}

.ref-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.ref-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.ref-card h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 620;
}

.ref-visuals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 260px));
  gap: 10px;
}

.ref-visuals figure {
  margin: 0;
}

.ref-visuals figcaption {
  margin-top: 5px;
  font-size: 12px;
  color: var(--text-3);
}

.ref-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-2);
  font-size: 13px;
  display: grid;
  gap: 4px;
}

.threshold-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.threshold-table th,
.threshold-table td {
  padding: 7px 8px;
  border-top: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
}

.threshold-table tr:first-child th,
.threshold-table tr:first-child td {
  border-top: 0;
}

.threshold-table th {
  width: 48px;
}

.threshold-table .mini-cat {
  display: inline-block;
}

.ref-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-top: auto;
}

.ref-card-foot .changed-line {
  margin-top: 0;
}

.ref-card-foot .btn {
  flex-shrink: 0;
}

.diff-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.diff-card {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.diff-card h2 {
  margin: 0 0 10px;
  font-size: 14.5px;
  font-weight: 620;
}

.diff-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 8px;
  font-size: 13px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
}

.diff-row:first-of-type {
  border-top: 0;
}

.diff-row span {
  color: var(--text-3);
  font-size: 12px;
  padding-top: 1px;
}

.diff-row.is-new p {
  color: var(--text);
}

.diff-row p {
  margin: 0;
  color: var(--text-2);
}

.notes-search {
  max-width: 420px;
  margin-bottom: 14px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.note-card {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.note-card h2 {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin: 0 0 8px;
  font-size: 14.5px;
  font-weight: 620;
}

.note-num {
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.note-section {
  margin-left: auto;
  font-size: 12px;
  font-weight: 450;
  color: var(--text-3);
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--text-3);
}

@media (max-width: 900px) {
  .ref-grid,
  .diff-grid,
  .notes-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .ref-card {
    padding: 16px;
  }

  .ref-card-foot {
    flex-direction: column;
    align-items: stretch;
  }
}

/* ---------- Modal & toast ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 8, 12, 0.6);
}

.modal-box {
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 620;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translate(-50%, 12px);
  padding: 9px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1023px) {
  .toast {
    bottom: 88px;
  }
}

/* ---------- Footer ---------- */
.site-footer {
  max-width: 1320px;
  margin: 8px auto 0;
  padding: 16px 20px 28px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--text-3);
}

.site-footer p {
  margin: 0 0 6px;
}

.site-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-2);
}

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

/* ---------- Text pages (terms) ---------- */
a.nav-tab {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.doc {
  max-width: 720px;
  margin: 8px auto 40px;
  padding: 28px 32px 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  line-height: 1.65;
}

.doc h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.doc-meta {
  margin: 4px 0 20px;
  font-size: 13px;
  color: var(--text-3);
}

.doc h2 {
  margin: 26px 0 8px;
  font-size: 16px;
  font-weight: 620;
}

.doc p,
.doc li {
  color: var(--text-2);
}

.doc ul {
  padding-left: 20px;
}

.doc li + li {
  margin-top: 4px;
}

.doc-back {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

@media (max-width: 600px) {
  .doc {
    padding: 20px 18px 24px;
  }
}

.report-problem {
  margin: 12px 0 0;
  font-size: 12.5px;
  color: var(--text-3);
}

/* ---------- 1-click lobe chips ---------- */
.lobe-field {
  margin-top: 16px;
}

.lobe-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.lobe-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.lobe-sep {
  width: 1px;
  height: 16px;
  background: var(--line-strong);
  margin: 0 2px;
}

.lobe-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.lobe-chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
  background: var(--surface-3);
}

.lobe-chip[aria-pressed="true"] {
  background: var(--accent-weak);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 480px) {
  .lobe-sep {
    display: none;
  }
  .lobe-chip {
    padding: 6px 8px;
    font-size: 12px;
  }
}

/* ---------- 2D radiologic lung location map ---------- */
.lung-map-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.lung-map-head h3 {
  margin: 0;
}

.lung-map-frame {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px 6px;
}

.lung-map-svg {
  display: block;
  width: 100%;
  max-width: 264px;
  height: auto;
  margin: 0 auto;
}

.lung-side-marker {
  font-size: 10px;
  font-weight: 700;
  fill: var(--text-3);
  letter-spacing: 0.04em;
  user-select: none;
}

.lung-region {
  cursor: pointer;
  outline: none;
}

.lung-region-shape {
  fill: var(--surface);
  stroke: var(--line-strong);
  stroke-width: 1.25;
  stroke-linejoin: round;
  transition: fill 0.14s ease, stroke 0.14s ease, opacity 0.14s ease;
}

.lung-region:hover .lung-region-shape,
.lung-region:focus-visible .lung-region-shape {
  stroke: var(--accent);
  stroke-width: 1.6;
}

.lung-trachea-rings line {
  stroke: var(--line-strong);
  stroke-width: 1;
  opacity: 0.7;
}

.lung-lobe-label {
  font-size: 9px;
  font-weight: 600;
  fill: var(--text-3);
  pointer-events: none;
  user-select: none;
}

.lung-lobe-sub {
  font-size: 7.5px;
  font-weight: 600;
  fill: var(--text-2);
  pointer-events: none;
  user-select: none;
}

.lung-badge-bg {
  fill: var(--region-color, var(--accent));
}

.lung-badge-text {
  font-size: 9.5px;
  font-weight: 700;
  fill: #ffffff;
  pointer-events: none;
  user-select: none;
}

.lung-region.cat-3 .lung-badge-text {
  fill: #171200;
}

.lung-region.is-pending { --region-color: var(--accent); }
.lung-region.cat-0 { --region-color: var(--cat-0); }
.lung-region.cat-1 { --region-color: var(--cat-1); }
.lung-region.cat-2 { --region-color: var(--cat-2); }
.lung-region.cat-3 { --region-color: var(--cat-3); }
.lung-region.cat-4a { --region-color: var(--cat-4a); }
.lung-region.cat-4b { --region-color: var(--cat-4b); }
.lung-region.cat-4x { --region-color: var(--cat-4x); }

.lung-region.is-involved .lung-region-shape {
  fill: color-mix(in srgb, var(--region-color, var(--accent)) 20%, var(--surface));
  stroke: var(--region-color, var(--accent));
  stroke-width: 1.6;
}

.lung-region.is-involved.is-active .lung-region-shape {
  fill: color-mix(in srgb, var(--region-color, var(--accent)) 28%, var(--surface));
  stroke-width: 2.1;
}
