:root {
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --paper: #fbfcfe;
  --panel: #ffffff;
  --accent: #0f6b6e;
  --accent-2: #b45f06;
  --accent-soft: #e8f4f4;
  --focus: #214e8a;
  --danger: #a73737;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

.topbar {
  min-height: 92px;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

.status {
  max-width: 360px;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.app-shell {
  padding: 18px 28px 28px;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 14px 18px;
  align-items: end;
  padding-bottom: 18px;
}

.search-box label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input[type="search"] {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}

input[type="search"]:focus,
button:focus-visible,
.index-tree-row:focus-visible {
  outline: 3px solid rgba(33, 78, 138, 0.24);
  outline-offset: 2px;
}

.filters,
.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.quick-row {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 14px;
}

button {
  font: inherit;
  cursor: pointer;
}

.seg,
.ghost {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 650;
}

.seg.active,
.ghost[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.content-grid {
  display: grid;
  grid-template-columns: 260px minmax(340px, 1fr) minmax(320px, 420px);
  gap: 18px;
  min-height: calc(100vh - 210px);
}

.browse,
.results,
.detail {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.browse,
.detail {
  padding: 16px;
}

.chapter-list {
  display: grid;
  gap: 8px;
}

.chapter-button {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  text-align: left;
  color: var(--ink);
}

.chapter-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.results {
  padding: 10px;
}

#results {
  display: grid;
  gap: 8px;
}

.result-card {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.result-card:hover,
.result-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.index-tree-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.index-tree-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.index-tree {
  display: grid;
  gap: 2px;
}

.index-tree-row {
  width: 100%;
  min-height: 36px;
  display: grid;
  grid-template-columns: 20px minmax(120px, auto) auto 1fr;
  gap: 8px;
  align-items: baseline;
  padding: 5px 8px 5px calc(8px + (var(--level) * 28px));
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-family: Consolas, "SFMono-Regular", "Segoe UI", monospace;
  font-size: 14px;
  text-align: left;
  animation: tree-row-in 140ms ease-out;
}

.index-tree-row:hover,
.index-tree-row.active {
  background: var(--accent-soft);
}

.tree-toggle {
  color: var(--ink);
  font-weight: 850;
  text-align: center;
  border-radius: 3px;
}

.tree-label {
  color: #004c73;
  font-weight: 750;
  text-decoration: underline;
}

.tree-code {
  color: var(--ink);
  font-weight: 800;
}

.code-chip-group {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.icd-code-button {
  min-height: 24px;
  padding: 1px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: #eef6f7;
  color: #004c73;
  font-family: inherit;
  font-size: 13px;
  font-weight: 850;
  line-height: 1.3;
  cursor: pointer;
}

.icd-code-button:hover {
  border-color: var(--accent);
  background: #dff0f1;
}

.bracket-code {
  color: var(--accent-2);
  background: #fff4e6;
}

.risk-bubble {
  align-self: center;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 850;
  line-height: 1.3;
}

.hcc-v28 {
  background: #e8f2ff;
  color: #0b5cad;
}

.hcc-v24 {
  background: #e8f7ef;
  color: #176a3a;
}

.hcc-both {
  background: #f1e8ff;
  color: #6731a4;
}

.rx-bubble {
  background: #fff1df;
  color: #a45200;
}

.tree-see {
  color: var(--muted);
}

@keyframes tree-row-in {
  from {
    opacity: 0;
    transform: translateY(-3px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-kind,
.pill {
  width: fit-content;
  padding: 2px 7px;
  border-radius: 999px;
  background: #edf0f4;
  color: #3c4758;
  font-size: 12px;
  font-weight: 750;
}

.result-title {
  font-size: 16px;
  line-height: 1.35;
}

.index-path {
  display: grid;
  gap: 6px;
}

.index-path.compact {
  gap: 3px;
}

.index-level {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding-left: calc(var(--level) * 18px);
  line-height: 1.35;
}

.index-path.compact .index-level {
  padding-left: calc(var(--level) * 14px);
}

.index-branch {
  width: 10px;
  height: 10px;
  border-left: 1px solid #98a2b3;
  border-bottom: 1px solid #98a2b3;
  flex: 0 0 10px;
  transform: translateY(-2px);
}

.result-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.code-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.code {
  font-size: 28px;
  font-weight: 800;
}

.desc {
  margin-bottom: 16px;
  font-size: 17px;
  line-height: 1.4;
}

.code-details-card {
  display: grid;
  gap: 14px;
}

.code-details-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.source-pill {
  background: #fff4e6;
  color: var(--accent-2);
}

.billable-pill {
  background: #e8f7ef;
  color: #176a3a;
}

.nonbillable-pill {
  background: #fff4e6;
  color: var(--accent-2);
}

.code-details-header h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1;
}

.panel-kicker {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.detail-summary {
  display: grid;
  gap: 7px;
}

.detail-summary h3,
.detail-section h3 {
  margin: 0;
  color: var(--accent);
  font-size: 14px;
}

.detail-summary p {
  margin: 0;
  font-size: 17px;
  line-height: 1.42;
}

.source-term {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9fb;
  font-size: 13px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.code-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.coding-guidance {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 8px;
}

.coding-guidance ul {
  margin: 0;
  padding-left: 20px;
}

.billable-guidance {
  border-color: #9dd6b2;
  background: #f2fbf5;
}

.nonbillable-guidance {
  border-color: #f2c078;
  background: #fffaf1;
}

.child-code-grid {
  display: grid;
  gap: 8px;
}

.child-code-grid .ghost {
  justify-content: flex-start;
  text-align: left;
  height: auto;
  min-height: 34px;
}

.detail-section {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-section ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.detail-section li {
  margin-bottom: 6px;
  line-height: 1.4;
}

.note-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.note-block h3 {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 14px;
}

.note-block ul {
  padding-left: 20px;
  margin: 0;
}

.note-block li {
  margin-bottom: 6px;
  line-height: 1.35;
}

.matrix {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.matrix-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.matrix-row span:first-child {
  color: var(--muted);
}

.selected-table-code {
  border-color: var(--accent);
  background: #eef7fb;
}

.table-context-term {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.risk-detail-list {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.risk-detail-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.risk-category {
  font-weight: 700;
}

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

.empty-state h2 {
  color: var(--ink);
}

.warning {
  color: var(--danger);
  font-weight: 700;
}

@media (max-width: 1100px) {
  .content-grid {
    grid-template-columns: 220px minmax(300px, 1fr);
  }

  .detail {
    grid-column: 1 / -1;
    min-height: 280px;
  }
}

@media (max-width: 760px) {
  .topbar,
  .search-panel {
    display: block;
  }

  .status {
    margin-top: 10px;
    text-align: left;
  }

  .filters,
  .quick-row {
    margin-top: 12px;
  }

  .app-shell,
  .topbar {
    padding-left: 14px;
    padding-right: 14px;
  }

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

  .browse {
    max-height: 260px;
  }
}
