:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --paper: #ffffff;
  --ink: #1f2933;
  --muted: #64748b;
  --line: #dde4ea;
  --nav: #243447;
  --nav-2: #1b2a3a;
  --blue: #2b6cb0;
  --blue-soft: #eaf2fb;
  --green: #25856f;
  --green-soft: #e9f6f2;
  --red: #b42318;
  --red-soft: #fff1f0;
  --amber: #a15c07;
  --amber-soft: #fff7e6;
  --shadow: 0 10px 28px rgba(20, 35, 52, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 18px;
  background: linear-gradient(180deg, var(--nav), var(--nav-2));
  color: #f8fafc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #f8fafc;
  color: var(--blue);
  font-size: 26px;
  font-weight: 800;
}

.brand p,
.brand h1 {
  margin: 0;
}

.brand p {
  color: #b8c7d6;
  font-size: 12px;
  text-transform: uppercase;
}

.brand h1 {
  font-size: 20px;
  line-height: 1.1;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  margin-bottom: 12px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #cfe0ee;
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: #ffffff;
}

.search input::placeholder {
  color: #a9bdcf;
}

.progress {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 18px;
  padding: 11px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.progress.loading {
  align-items: center;
}

.progress strong {
  font-size: 24px;
}

.progress.loading strong {
  font-size: 14px;
}

.progress.error {
  background: rgba(180, 35, 24, 0.16);
}

.progress span {
  color: #cfe0ee;
  font-size: 13px;
}

.filters {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.filters select {
  width: 100%;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 0 9px;
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.filters option {
  color: var(--ink);
}

.filter-check,
.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-check {
  color: #cfe0ee;
  font-size: 13px;
}

.topic-group {
  margin-bottom: 18px;
}

.topic-group h2 {
  margin: 0 0 8px;
  color: #d6e5f2;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topic {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 48px;
  margin-bottom: 6px;
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  background: transparent;
  color: #f8fafc;
  text-align: left;
  cursor: pointer;
}

.topic:hover,
.topic.active {
  background: rgba(255, 255, 255, 0.12);
}

.topic.reviewed .topic-title::after {
  content: " visto";
  color: #9fd8c8;
  font-size: 11px;
  font-weight: 700;
}

.topic.locked {
  opacity: 0.68;
}

.topic-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 700;
}

.topic-mode {
  color: #cfe0ee;
  font-size: 12px;
}

.topic-badge {
  border-radius: 999px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #d6e5f2;
  font-size: 11px;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 58px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 248, 0.9);
  backdrop-filter: blur(10px);
  color: var(--muted);
  font-weight: 700;
}

#crumbs {
  flex: 1 1 auto;
  min-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu {
  display: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.actions {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  max-width: 100%;
}

.actions button {
  min-height: 36px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
}

.actions button:hover {
  border-color: #b9c8d6;
  color: var(--blue);
}

.intro {
  max-width: 1060px;
  margin: 14px auto 10px;
  padding: 0 24px;
}

.intro p,
.intro h2 {
  margin: 0;
}

#kicker {
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.intro h2 {
  margin-top: 4px;
  font-size: clamp(24px, 3.4vw, 36px);
  line-height: 1.08;
  letter-spacing: 0;
}

#chapterSubtitle {
  max-width: 760px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

#chapterSubtitle:empty {
  display: none;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 58px;
  margin-top: 8px;
  overflow: hidden;
}

.tags span {
  border: 1px solid #cbd8e3;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--paper);
  color: #334155;
  font-size: 12px;
  font-weight: 700;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 66px;
  margin-top: 8px;
  overflow: hidden;
}

.meta-pill {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 9px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-row {
  margin-top: 8px;
}

.clinical-review-card {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: baseline;
  max-width: 840px;
  border: 1px solid #f3d49b;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 13px;
  line-height: 1.35;
}

.clinical-review-card strong {
  color: #7c4300;
}

.clinical-review-card span {
  color: var(--amber);
}

.meta-pill.warning {
  border-color: #f3d49b;
  background: var(--amber-soft);
  color: var(--amber);
}

.source-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.source-list h3 {
  margin: 8px 0 0;
  color: #334155;
  font-size: 15px;
}

.source-list ul {
  margin: 0;
  padding-left: 20px;
}

.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4 {
  color: var(--ink);
}

.markdown-section h3 {
  margin: 18px 0 8px;
  font-size: 17px;
}

#preguntas-clave h3,
#medicion-y-examen h3,
#ges h3 {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  color: #475569;
  font-size: 15px;
}

#ges {
  border-color: #e6edf3;
  box-shadow: none;
}

.markdown-section h4 {
  margin: 14px 0 8px;
  font-size: 15px;
}

.markdown-section p,
.markdown-section li {
  color: #334155;
  line-height: 1.55;
}

.markdown-section ol,
.markdown-section ul {
  padding-left: 22px;
}

.markdown-section blockquote {
  margin: 0;
}

.medication-card {
  border-left: 5px solid var(--green);
}

.empty-state {
  border: 1px dashed #cbd8e3;
  border-radius: 8px;
  padding: 18px;
  background: #f8fafc;
  color: var(--muted);
}

.page-grid {
  display: grid;
  grid-template-columns: 224px minmax(0, 840px);
  gap: 14px;
  align-items: start;
  max-width: 1060px;
  margin: 0 auto;
  padding: 0 24px 42px;
}

.toc {
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.toc a {
  display: block;
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.25;
}

.toc a:hover {
  background: var(--blue-soft);
  color: var(--blue);
}

.toc a.active {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 800;
}

.toc-subitem {
  margin-left: 10px;
  padding-left: 16px !important;
  font-size: 12px !important;
}

.content {
  min-width: 0;
}

.section-anchor,
.markdown-section,
.calculator-panel,
.evolution-panel,
.box {
  scroll-margin-top: 86px;
}

.context {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  padding: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.context p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.station {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.letter {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 20px;
  font-weight: 900;
}

.station h2,
.box h2 {
  margin: 0 0 10px;
  font-size: 21px;
  line-height: 1.2;
}

.station h3 {
  margin: 16px 0 8px;
  color: #334155;
  font-size: 16px;
}

.station p,
.box p,
.station li,
.box li {
  color: #334155;
  line-height: 1.52;
}

.station ul,
.box ul {
  margin: 0;
  padding-left: 20px;
}

.station li,
.box li {
  margin: 5px 0;
}

.mini-table {
  width: 100%;
  margin: 12px 0;
  border-collapse: collapse;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.mini-table th,
.mini-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  line-height: 1.45;
}

.mini-table th {
  background: #f0f5f9;
  color: #334155;
}

.pharmacology-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.mini-table tr:last-child td {
  border-bottom: 0;
}

.summary-card-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 2px 0 12px;
}

.summary-card {
  min-width: 0;
  border: 1px solid #cbd8e3;
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.summary-card strong,
.summary-card span {
  display: block;
}

.summary-card strong {
  color: #334155;
  font-size: 12px;
  line-height: 1.2;
}

.summary-card span {
  margin-top: 4px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
}

.pharmacology-table {
  font-size: 13px;
}

.pharmacology-table th,
.pharmacology-table td {
  padding: 8px;
}

.pharmacology-card-view {
  display: none;
}

.medication-accordion {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 8px 0;
  background: #f8fafc;
  overflow: hidden;
}

.medication-accordion summary {
  display: grid;
  gap: 4px;
  padding: 12px;
  cursor: pointer;
  font-weight: 800;
}

.medication-accordion summary small {
  color: var(--muted);
  font-weight: 600;
  line-height: 1.35;
}

.medication-detail-row {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.medication-detail-row span {
  color: #334155;
  line-height: 1.45;
}

.callout {
  margin-top: 10px;
  border-radius: 8px;
  padding: 11px 12px;
  line-height: 1.5;
}

.callout.ok {
  background: var(--green-soft);
  color: #145c4c;
}

.callout.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.callout.danger {
  background: var(--red-soft);
  color: var(--red);
}

.box {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.box.warning {
  border-left: 5px solid var(--amber);
}

.box.danger {
  border-left: 5px solid var(--red);
}

.collapsible-section {
  overflow: hidden;
}

.section-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -4px -4px 10px;
  border-radius: 8px;
  padding: 4px;
  cursor: pointer;
  list-style: none;
}

.section-summary::-webkit-details-marker {
  display: none;
}

.section-summary::marker {
  content: "";
}

.section-summary:hover {
  background: #f8fafc;
}

.section-summary h2,
.section-summary h3 {
  margin: 0;
}

.section-toggle {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.section-toggle::before {
  content: "Cerrar";
}

.collapsible-section:not([open]) .section-toggle::before {
  content: "Abrir";
}

.collapsible-section:not([open]) {
  padding-bottom: 12px;
}

.collapsible-section:not([open]) .section-summary {
  margin-bottom: -4px;
}

.section-body {
  min-width: 0;
}

.copy-block {
  white-space: pre-wrap;
  border: 1px solid #cbd8e3;
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
  color: #243447;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.55;
}

.calculator-panel > p {
  margin-top: 0;
  color: var(--muted);
}

.calculator-grid {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.calculator-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
  overflow: hidden;
}

.calculator-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.pending-tool {
  border-style: dashed;
  color: var(--muted);
}

.calculator-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.calculator-card label {
  display: grid;
  gap: 5px;
  color: #334155;
  font-weight: 700;
}

.calculator-card input,
.calculator-card select {
  min-height: 34px;
  border: 1px solid #cbd8e3;
  border-radius: 8px;
  padding: 0 8px;
  background: #ffffff;
  color: var(--ink);
}

.calculator-table input {
  width: 76px;
  margin: 2px;
}

.ortho-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.ortho-grid fieldset {
  display: grid;
  gap: 6px;
  margin: 0;
  border: 1px solid #cbd8e3;
  border-radius: 8px;
  padding: 10px;
}

.ortho-grid legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.formula-note {
  margin: 10px 0;
  color: var(--muted);
  font-size: 13px;
}

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

.calculator-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.calculator-result {
  margin-top: 10px;
}

.calculator-result p {
  margin: 5px 0;
}

.fixed-alerts {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: 78px;
  z-index: 28;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  max-width: calc(100vw - 36px);
  border: 1px solid #f0c4bd;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.hta-mode-switch {
  position: sticky;
  top: 58px;
  z-index: 7;
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.hta-mode-switch button {
  flex: 1;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.hta-mode-switch button.active {
  border-color: #b7d0eb;
  background: var(--blue-soft);
  color: var(--blue);
}

.guided-launch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  border: 1px solid #b7d0eb;
  border-radius: 8px;
  padding: 12px;
  background: var(--blue-soft);
}

.guided-launch p {
  margin: 0;
}

.guided-launch button {
  min-height: 36px;
  border: 1px solid #b7d0eb;
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--blue);
  font-weight: 800;
  cursor: pointer;
}

.control-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.72fr);
  gap: 14px;
  align-items: start;
}

.control-interview {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.tool-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.tool-card h3,
.tool-card p {
  margin: 0;
}

.tool-card p {
  margin-top: 6px;
  color: var(--muted);
}

.tool-card button,
.tool-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.evolution-workspace {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.sticky-actions {
  position: sticky;
  top: 58px;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.evolution-section {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #ffffff;
}

.evolution-section h3 {
  margin: 0;
}

.section-note {
  margin: -2px 0 12px;
  color: var(--muted);
}

.evolution-builder {
  position: sticky;
  top: 122px;
  display: grid;
  gap: 10px;
  max-height: calc(100vh - 138px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.builder-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.builder-head h3,
.builder-head p {
  margin: 0;
}

.builder-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.builder-close {
  display: none;
}

.builder-actions {
  position: static;
  padding: 0;
  border: 0;
  background: transparent;
  backdrop-filter: none;
}

.builder-actions [data-ai-improve] {
  opacity: 0.62;
  cursor: not-allowed;
}

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

.check-grid {
  display: grid;
  gap: 8px;
}

.quick-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-buttons button,
.secondary-action {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #f8fafc;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.row-list {
  display: grid;
  gap: 10px;
}

.dynamic-row,
.preview-block {
  display: grid;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.row-head,
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row-head button,
.preview-head button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.medication-fields-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.preview-blocks {
  display: grid;
  gap: 10px;
}

.checklist-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.checklist-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

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

.checklist-table thead th {
  background: #f8fafc;
  color: #334155;
  font-size: 13px;
}

.checklist-table tbody th {
  width: 28%;
  color: var(--ink);
  font-weight: 800;
}

.checklist-table tbody td:nth-child(2) {
  width: 170px;
}

.checklist-table tbody tr:last-child th,
.checklist-table tbody tr:last-child td {
  border-bottom: 0;
}

.symptom-details {
  display: grid;
  gap: 8px;
}

.choice-cell {
  display: grid;
  gap: 6px;
}

.compact-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  white-space: nowrap;
}

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

.preview-block textarea {
  min-height: 88px;
  background: #ffffff;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fixed-evolution-button {
  display: none;
}

.system-card,
.finding-row,
.edema-fields {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.edema-fields {
  grid-template-columns: minmax(150px, 1fr) repeat(3, minmax(0, 1fr));
}

.confirm-line {
  display: flex;
  align-items: start;
  gap: 8px;
  border: 1px solid #f3d49b;
  border-radius: 8px;
  padding: 10px;
  background: var(--amber-soft);
}

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

.evolution-section input,
.evolution-section select,
.evolution-section textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid #cbd8e3;
  border-radius: 8px;
  padding: 7px 9px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
}

.evolution-section input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.evolution-section label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-weight: 700;
}

.evolution-section label:has(input[type="checkbox"]),
.confirm-line {
  display: flex;
}

.evolution-section textarea {
  resize: vertical;
  line-height: 1.45;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  padding: 12px 14px;
  background: #1b2a3a;
  color: #ffffff;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.backdrop {
  display: none;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 88vw);
    transform: translateX(-100%);
    transition: transform 160ms ease;
    z-index: 12;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .backdrop.show {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 11;
    background: rgba(16, 24, 39, 0.45);
  }

  .menu {
    display: block;
  }

  .page-grid {
    grid-template-columns: 1fr;
  }

  .toc {
    position: static;
    display: flex;
    gap: 6px;
    max-height: none;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .toc a {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .pharmacology-table-view {
    display: none;
  }

  .pharmacology-card-view {
    display: block;
  }

  .control-shell {
    grid-template-columns: 1fr;
  }

  .evolution-builder {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: none;
    max-height: none;
    border-radius: 0;
    padding: 14px;
    overflow: auto;
  }

  .evolution-builder.open {
    display: grid;
  }

  .builder-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0 10px;
    background: var(--paper);
    color: var(--ink);
    font-weight: 800;
  }

  .fixed-evolution-button {
    display: block;
    position: fixed;
    right: 14px;
    bottom: 116px;
    z-index: 18;
    min-height: 36px;
    border: 1px solid #b7d0eb;
    border-radius: 8px;
    padding: 0 12px;
    background: var(--blue);
    color: #ffffff;
    font-weight: 800;
    box-shadow: var(--shadow);
  }
}

@media (max-width: 680px) {
  .topbar {
    height: auto;
    min-height: 58px;
    gap: 8px;
    padding: 8px 12px;
  }

  #crumbs {
    flex: 1 1 calc(100% - 54px);
    min-width: 0;
  }

  .actions {
    flex: 1 1 100%;
    justify-content: flex-start;
  }

  .actions button {
    max-width: none;
    min-height: 34px;
    padding: 6px 8px;
    font-size: 12px;
    white-space: normal;
  }

  .intro {
    margin-top: 10px;
    padding: 0 14px;
  }

  .intro h2 {
    font-size: clamp(23px, 7vw, 30px);
  }

  .tags,
  .meta-row {
    gap: 6px;
  }

  .page-grid {
    padding: 0 14px 28px;
  }

  .station {
    grid-template-columns: 1fr;
  }

  .ortho-grid {
    grid-template-columns: 1fr;
  }

  .calculator-table input {
    width: 68px;
  }

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

  .clinical-review-card {
    font-size: 12px;
  }

  .form-grid,
  .system-grid,
  .edema-fields,
  .medication-fields-grid {
    grid-template-columns: 1fr;
  }

  .checklist-table {
    min-width: 620px;
  }

  .compact-details {
    grid-template-columns: 1fr;
  }

  .row-head,
  .preview-head {
    align-items: stretch;
    flex-direction: column;
  }

  .row-head button,
  .preview-head button {
    width: 100%;
  }

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

  .tool-card button {
    width: 100%;
  }

  .guided-launch,
  .builder-head,
  .preview-head {
    align-items: stretch;
    flex-direction: column;
  }

  .guided-launch button,
  .preview-actions,
  .preview-actions button {
    width: 100%;
  }

  .fixed-alerts {
    right: 12px;
    bottom: 68px;
    max-width: calc(100vw - 24px);
  }

  .letter {
    width: 34px;
    height: 34px;
  }
}

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