:root {
  --font-display: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "Source Sans 3", "Trebuchet MS", sans-serif;

  --bg-page: #edf3fb;
  --bg-accent: #e7f0ff;
  --surface: #ffffff;
  --surface-muted: #f5f9ff;
  --surface-emphasis: #ecf3ff;
  --text: #12253b;
  --text-muted: #60748e;
  --text-soft: #415a78;
  --brand: #1f70bf;
  --brand-strong: #0f4f8b;
  --brand-soft: #d8e9ff;
  --border: #cfddee;
  --focus: #1e77d0;
  --error: #b13e3e;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --shadow-sm: 0 4px 12px rgba(18, 37, 59, 0.08);
  --shadow-md: 0 10px 24px rgba(18, 37, 59, 0.12);
  --shadow-lg: 0 18px 42px rgba(10, 24, 42, 0.2);

  --motion-fast: 0.15s;
  --motion-medium: 0.22s;

  --detail-width: 400px;
  --card-min-width: 248px;
}

[data-theme="dark"] {
  --bg-page: #0f1625;
  --bg-accent: #121f33;
  --surface: #17253b;
  --surface-muted: #1b2c45;
  --surface-emphasis: #20344f;
  --text: #e3edf9;
  --text-muted: #9cb1cb;
  --text-soft: #b6c7db;
  --brand: #5ca9ff;
  --brand-strong: #8ec5ff;
  --brand-soft: #263b59;
  --border: #2f4563;
  --focus: #6bb4ff;
  --error: #ff9898;

  --shadow-sm: 0 8px 18px rgba(1, 8, 18, 0.42);
  --shadow-md: 0 12px 26px rgba(1, 8, 18, 0.5);
  --shadow-lg: 0 22px 44px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(1150px 600px at -8% -10%, rgba(54, 138, 221, 0.2), transparent 56%),
    radial-gradient(920px 510px at 108% 8%, rgba(43, 179, 138, 0.14), transparent 56%),
    linear-gradient(180deg, var(--bg-accent) 0%, var(--bg-page) 62%);
}

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

.app-header {
  --brand-icon-size: 30px;
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3) clamp(12px, 3vw, 24px);
  border-bottom: 1px solid color-mix(in oklab, var(--border), transparent 20%);
  background: color-mix(in oklab, var(--surface) 84%, transparent);
  backdrop-filter: blur(8px);
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.brand {
  display: grid;
  gap: var(--space-1);
}

.brand__home {
  width: max-content;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--brand-strong);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.brand__home:hover {
  text-decoration: underline;
}

.brand__icon {
  width: auto;
  height: var(--brand-icon-size, 30px);
  max-height: 100%;
  aspect-ratio: 1 / 1;
  flex: 0 0 auto;
  border-radius: 0.35em;
  object-fit: contain;
}

.brand__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(22px, 3vw, 34px);
  letter-spacing: -0.02em;
  line-height: 1.12;
}

.brand__subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.controls {
  display: grid;
  gap: var(--space-3);
}

.controls--primary {
  grid-template-columns: minmax(300px, 1fr) auto;
  align-items: end;
}

.controls--secondary {
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 180px) minmax(260px, 340px) auto;
  align-items: end;
}

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

.control--class-tree {
  position: relative;
  isolation: isolate;
}

.control__label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.input,
.select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
}

.class-tree-trigger {
  width: 100%;
  min-height: 44px;
  border: 1px solid color-mix(in oklab, var(--border), var(--surface) 8%);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  background:
    linear-gradient(
      180deg,
      color-mix(in oklab, var(--surface), var(--brand-soft) 10%) 0%,
      var(--surface) 100%
    );
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 color-mix(in oklab, var(--surface), transparent 24%),
    0 1px 2px color-mix(in oklab, var(--text), transparent 92%);
  transition:
    border-color var(--motion-fast) ease,
    background-color var(--motion-fast) ease,
    box-shadow var(--motion-fast) ease,
    transform var(--motion-fast) ease;
}

.class-tree-trigger__text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.class-tree-trigger:hover {
  border-color: color-mix(in oklab, var(--brand), var(--border) 45%);
  box-shadow: 0 4px 16px color-mix(in oklab, var(--brand), transparent 90%);
}

.class-tree-trigger.is-filtered {
  border-color: color-mix(in oklab, var(--brand), var(--border) 35%);
  background:
    linear-gradient(
      180deg,
      color-mix(in oklab, var(--brand-soft), var(--surface) 64%) 0%,
      color-mix(in oklab, var(--brand-soft), var(--surface) 78%) 100%
    );
}

.control--class-tree.is-open .class-tree-trigger {
  border-color: color-mix(in oklab, var(--brand), var(--border) 32%);
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--brand), transparent 82%),
    0 8px 20px color-mix(in oklab, var(--brand), transparent 90%);
  transform: translateY(-1px);
}

.class-tree-trigger__caret {
  color: var(--text-muted);
  font-size: 14px;
  transition:
    transform var(--motion-fast) ease,
    color var(--motion-fast) ease;
}

.control--class-tree.is-open .class-tree-trigger__caret {
  color: var(--brand-strong);
  transform: rotate(90deg);
}

.class-tree-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 80;
  width: fit-content;
  max-width: calc(100vw - 24px);
  max-height: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.class-tree-columns {
  position: relative;
  display: block;
  padding: 0;
  min-width: 0;
  max-width: none;
  max-height: none;
  overflow-x: visible;
  overflow-y: visible;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  background: transparent;
}

.class-tree-column {
  width: clamp(320px, 34vw, 500px);
  max-width: min(500px, calc(100vw - 40px));
  max-height: min(64vh, 560px);
  border: 1px solid color-mix(in oklab, var(--brand), var(--border) 74%);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  gap: 8px;
  align-content: start;
  background: color-mix(in oklab, var(--surface), var(--surface-muted) 10%);
  position: relative;
  top: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  box-shadow: var(--shadow-md);
}

.class-tree-column[data-depth="0"] {
  z-index: 2;
  border-color: color-mix(in oklab, var(--brand), var(--border) 74%);
  background: color-mix(in oklab, var(--surface), var(--surface-muted) 10%);
}

.class-tree-column[data-depth]:not([data-depth="0"]) {
  position: absolute;
  left: var(--tree-column-left, calc(100% + 12px));
  top: var(--tree-column-offset, 0px);
  width: clamp(290px, 30vw, 420px);
  max-width: min(420px, calc(100vw - 28px));
  max-height: min(52vh, 390px);
  margin-left: 0;
  border-color: color-mix(in oklab, var(--brand), var(--border) 68%);
  background: color-mix(in oklab, var(--surface), transparent 1%);
  box-shadow: var(--shadow-lg);
  z-index: 6;
  animation: class-tree-branch-in var(--motion-fast) ease;
}

.class-tree-column[data-depth]:not([data-depth="0"])::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 24px;
  width: 10px;
  height: 2px;
  border-radius: 99px;
  background: color-mix(in oklab, var(--brand), var(--border) 64%);
}

@keyframes class-tree-branch-in {
  from {
    opacity: 0.72;
    transform: translateX(-6px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

.class-tree-column__title {
  margin: 0;
  padding: 2px 6px 7px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid color-mix(in oklab, var(--border), transparent 18%);
}

.class-tree-list {
  display: grid;
  gap: 3px;
  align-content: start;
}

.class-tree-column[data-depth]:not([data-depth="0"]) .class-tree-list {
  position: relative;
  padding-left: 12px;
}

.class-tree-column[data-depth]:not([data-depth="0"]) .class-tree-list::before {
  content: "";
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 2px;
  width: 1px;
  background: color-mix(in oklab, var(--brand), var(--border) 72%);
  opacity: 0.9;
}

.class-tree-option {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  cursor: pointer;
  transition:
    border-color var(--motion-fast) ease,
    background-color var(--motion-fast) ease,
    color var(--motion-fast) ease,
    transform var(--motion-fast) ease;
}

.class-tree-option:hover {
  background: color-mix(in oklab, var(--surface-muted), var(--surface) 34%);
  border-color: color-mix(in oklab, var(--brand), var(--border) 72%);
}

.class-tree-option.is-branch {
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 82%);
  border-color: color-mix(in oklab, var(--brand), var(--border) 76%);
}

.class-tree-option.is-primary.is-branch {
  background: transparent;
  border-color: transparent;
}

.class-tree-column[data-depth]:not([data-depth="0"]) .class-tree-option {
  position: relative;
}

.class-tree-column[data-depth]:not([data-depth="0"]) .class-tree-option::before {
  content: "";
  position: absolute;
  left: -11px;
  top: 50%;
  width: 9px;
  height: 1px;
  background: color-mix(in oklab, var(--brand), var(--border) 68%);
  transform: translateY(-50%);
}

.class-tree-column[data-depth]:not([data-depth="0"]) .class-tree-option.is-active,
.class-tree-column[data-depth]:not([data-depth="0"]) .class-tree-option.is-branch {
  transform: translateX(2px);
}

.class-tree-option.is-active {
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 66%);
  border-color: color-mix(in oklab, var(--brand), var(--border) 44%);
  color: var(--brand-strong);
}

.class-tree-option__label {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
}

.class-tree-option__meta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.class-tree-option__count {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid color-mix(in oklab, var(--border), transparent 10%);
  border-radius: var(--radius-pill);
  padding: 1px 6px;
  background: color-mix(in oklab, var(--surface-muted), transparent 4%);
}

.class-tree-option.is-active .class-tree-option__count {
  color: var(--brand-strong);
  border-color: color-mix(in oklab, var(--brand), var(--border) 46%);
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 72%);
}

.class-tree-option__caret {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
}

.class-tree-column[data-depth="0"] .class-tree-option__caret {
  display: none;
}

.class-tree-option:hover .class-tree-option__caret,
.class-tree-option.is-branch .class-tree-option__caret,
.class-tree-option.is-active .class-tree-option__caret {
  color: var(--brand-strong);
}

.input::placeholder {
  color: color-mix(in oklab, var(--text-muted), transparent 18%);
}

.input:focus-visible,
.select:focus-visible,
.class-tree-trigger:focus-visible,
.class-tree-option:focus-visible,
.btn:focus-visible,
.view-mode-btn:focus-visible,
.class-toggle:focus-visible,
.subclass-chip:focus-visible,
.med-card:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.control--result-meta {
  min-width: 190px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in oklab, var(--surface-muted), transparent 3%);
}

.result-count__label {
  margin: 0;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.result-count {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: -0.01em;
}

.control--actions {
  align-self: end;
  justify-items: end;
}

.control--view-mode {
  min-width: 0;
}

.class-type-toggle {
  display: inline-flex;
  align-items: center;
  width: max-content;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}

.class-type-btn {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  padding: 0 10px;
  cursor: pointer;
}

.class-type-btn:last-child {
  border-right: 0;
}

.class-type-btn.is-active {
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 65%);
  color: var(--brand-strong);
}

.class-type-select {
  display: none;
}

.view-mode-toggle {
  display: inline-flex;
  align-items: center;
  width: max-content;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
}

.view-mode-btn {
  min-height: 42px;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
}

.view-mode-btn:last-child {
  border-right: 0;
}

.view-mode-btn.is-active {
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 65%);
  color: var(--brand-strong);
}

.view-mode-select {
  display: none;
}

.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  min-height: 40px;
  padding: 10px 12px;
  cursor: pointer;
  transition:
    border-color var(--motion-fast) ease,
    background-color var(--motion-fast) ease,
    box-shadow var(--motion-fast) ease,
    transform var(--motion-fast) ease;
}

.btn:hover {
  border-color: color-mix(in oklab, var(--brand), var(--border) 55%);
  box-shadow: var(--shadow-sm);
}

.btn:active {
  transform: translateY(1px);
}

.btn.ghost {
  background: color-mix(in oklab, var(--surface-muted), transparent 8%);
}

.btn.icon {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
}

.btn--theme {
  min-width: 112px;
  border-color: color-mix(in oklab, var(--brand), var(--border) 42%);
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 58%);
  color: var(--brand-strong);
}

.app-main {
  padding: var(--space-4) clamp(12px, 3vw, 24px) 30px;
}

.app-footer {
  padding: 0 clamp(12px, 3vw, 24px) var(--space-4);
}

.footer-disclaimer {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid color-mix(in oklab, var(--brand), var(--border) 66%);
  border-left: 4px solid color-mix(in oklab, var(--brand), var(--border) 30%);
  border-radius: var(--radius-md);
  background: color-mix(in oklab, var(--surface-emphasis), transparent 5%);
  color: var(--text-soft);
  font-size: 13px;
}

.error {
  margin-bottom: var(--space-3);
  border: 1px solid color-mix(in oklab, var(--error), transparent 54%);
  border-left: 4px solid var(--error);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  background: color-mix(in oklab, var(--surface), var(--error) 10%);
  color: var(--error);
}

.layout-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--detail-width);
  gap: var(--space-4);
  align-items: start;
}

.results-region {
  min-width: 0;
}

.results-grid {
  display: grid;
  gap: var(--space-4);
}

.results-empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 18px 14px;
  color: var(--text-muted);
  background: color-mix(in oklab, var(--surface), transparent 10%);
}

.class-block {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in oklab, var(--surface), transparent 4%);
  box-shadow: var(--shadow-sm);
}

.class-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 12px 14px 4px;
}

.class-block__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 21px;
  letter-spacing: -0.015em;
}

.class-block__count {
  border: 1px solid color-mix(in oklab, var(--brand), var(--border) 52%);
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 72%);
}

.class-block__body {
  display: grid;
  gap: var(--space-3);
  padding: 10px 14px 14px;
}

.class-toggle {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: color-mix(in oklab, var(--surface-muted), transparent 10%);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 12px 14px;
  cursor: pointer;
}

.class-toggle:hover {
  background: color-mix(in oklab, var(--surface-emphasis), transparent 12%);
}

.class-toggle__title {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: -0.015em;
}

.class-toggle__count {
  border: 1px solid color-mix(in oklab, var(--brand), var(--border) 52%);
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
}

.subclass-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.subclass-chip {
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: color-mix(in oklab, var(--surface-muted), transparent 14%);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 10px;
  cursor: pointer;
}

.subclass-chip.is-active {
  border-color: color-mix(in oklab, var(--brand), var(--border) 42%);
  color: var(--brand-strong);
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 65%);
}

.subclass-heading {
  margin: 2px 0 0;
  font-size: 14px;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.045em;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min-width), 1fr));
  gap: var(--space-3);
}

.results-grid[data-view-mode="compact"] .class-block {
  background: color-mix(in oklab, var(--surface), transparent 8%);
}

.results-grid[data-view-mode="compact"] .class-block__body {
  padding-top: 8px;
}

.results-grid[data-view-mode="structured"] .class-block {
  overflow: hidden;
}

.med-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, color-mix(in oklab, var(--surface) 95%, transparent), var(--surface));
  text-align: left;
  padding: 12px;
  cursor: pointer;
  display: grid;
  gap: 9px;
  min-height: 176px;
  transition:
    border-color var(--motion-fast) ease,
    box-shadow var(--motion-medium) ease,
    transform var(--motion-fast) ease;
}

.med-card:hover {
  border-color: color-mix(in oklab, var(--brand), var(--border) 38%);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.med-card.is-selected {
  border-color: color-mix(in oklab, var(--brand), var(--border) 22%);
  box-shadow:
    0 0 0 2px color-mix(in oklab, var(--brand), transparent 74%),
    var(--shadow-md);
}

.med-card__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  line-height: 1.18;
  letter-spacing: -0.01em;
}

.med-card__class {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  border: 1px solid color-mix(in oklab, var(--brand), var(--border) 64%);
  border-radius: var(--radius-pill);
  padding: 3px 9px;
  background: color-mix(in oklab, var(--brand-soft), var(--surface) 62%);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  height: min-content;
}

.med-card__snippet {
  margin: 0;
  color: color-mix(in oklab, var(--text), transparent 14%);
  font-size: 14px;
}

.detail-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in oklab, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 188px;
  max-height: calc(100dvh - 204px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface-muted), transparent 8%);
}

.detail-panel__eyebrow {
  margin: 0 0 2px;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.09em;
  color: var(--text-muted);
}

.detail-panel__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.detail-panel__close {
  display: none;
}

.detail-panel__meta {
  margin: 0;
  padding: 10px 14px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
}

.detail-empty {
  padding: 14px;
  color: var(--text-muted);
}

.detail-empty p {
  margin: 0;
}

.detail-panel__body {
  overflow-y: auto;
  padding: 8px 14px 16px;
  display: grid;
  gap: var(--space-3);
}

.detail-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in oklab, var(--surface-muted), transparent 4%);
  padding: 10px 11px;
}

.detail-section__title {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--brand-strong);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-section__text {
  margin: 0;
  font-size: 14px;
}

.detail-section__list {
  margin: 0;
  padding-left: 18px;
  font-size: 14px;
}

.detail-section__list li + li {
  margin-top: 5px;
}

.detail-section--rxnorm {
  display: grid;
  gap: 8px;
}

.rxnorm-body {
  display: grid;
  gap: 10px;
}

.rxnorm-state {
  color: var(--text-muted);
}

.rxnorm-state--error {
  color: var(--error);
}

.rxnorm-field {
  display: grid;
  gap: 4px;
}

.rxnorm-field__label {
  margin: 0;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.rxnorm-field__value {
  margin: 0;
  font-size: 14px;
}

.rxnorm-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rxnorm-pill {
  font-size: 11px;
}

.rxnorm-class-list {
  margin-top: 0;
}

.detail-scrim {
  position: fixed;
  inset: 0;
  z-index: 48;
  background: rgba(8, 17, 30, 0.6);
}

body.detail-open {
  overflow: hidden;
}

@media (max-width: 1220px) {
  .controls--secondary {
    grid-template-columns: minmax(220px, 1fr) minmax(140px, 180px) minmax(220px, 1fr);
  }

  .control--actions {
    grid-column: 1 / -1;
    justify-items: start;
  }

  .detail-panel {
    top: 200px;
    max-height: calc(100dvh - 216px);
  }
}

@media (max-width: 1080px) {
  .controls--primary {
    grid-template-columns: 1fr;
  }

  .controls--secondary {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .control--actions {
    grid-column: 1 / -1;
  }

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

  .detail-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(440px, 92vw);
    max-height: 100dvh;
    border-radius: 16px 0 0 16px;
    z-index: 50;
    transform: translateX(104%);
    transition: transform var(--motion-medium) ease;
  }

  .detail-panel.open {
    transform: translateX(0);
  }

  .detail-panel__close {
    display: grid;
  }
}

@media (max-width: 760px) {
  .app-header {
    gap: var(--space-2);
  }

  .header-row--brand {
    align-items: center;
  }

  .brand__subtitle {
    font-size: 13px;
  }

  .controls--secondary {
    grid-template-columns: 1fr;
  }

  .class-tree-menu {
    width: 100%;
    max-width: 100%;
  }

  .class-tree-columns {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px;
    min-width: max-content;
    overflow-x: auto;
  }

  .class-tree-column,
  .class-tree-column[data-depth]:not([data-depth="0"]) {
    position: relative;
    left: auto;
    top: 0;
    width: auto;
    min-width: 228px;
    max-width: 86vw;
    max-height: min(52vh, 420px);
    animation: none;
  }

  .control--result-meta {
    min-width: 0;
  }

  .class-type-toggle {
    display: none;
  }

  .class-type-select {
    display: block;
  }

  .view-mode-toggle {
    display: none;
  }

  .view-mode-select {
    display: block;
  }

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

  .btn--theme {
    min-width: 96px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
