/*
 * SIGTAP Explorador — ficha legível.
 * Single light theme. Every size derives from --base (14 / 15 / 17 px,
 * set by the "Tamanho do texto" control); nothing renders below 12px.
 */

/* ------------------------------------------------------------------ */
/* Tokens                                                              */
/* ------------------------------------------------------------------ */

:root {
  color-scheme: light;

  --base: 15px;

  /* Type */
  --font-text: "Atkinson Hyperlegible Next", system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: "Atkinson Hyperlegible Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --font-brand: Georgia, "Times New Roman", serif;
  --fs-xs: max(12px, 0.8rem);       /* 12 at base 15: notes, counts */
  --fs-label: max(12px, 0.8667rem); /* 13: labels, table headers */
  --fs-row: max(12px, 0.9333rem);   /* 14: tables, list names */
  --fs-value: 1rem;                 /* 15: ficha values */
  --fs-name: 1.3333rem;             /* 20: procedure name */
  --fs-code: 1.4667rem;             /* 22: procedure code */

  /* Colour */
  --bg: #f6f4ee;             /* warm off-white (cream), less green */
  --paper: #ffffff;
  --ink: #1b2e29;
  --label: #545454;          /* neutral grey: 7.6:1 on white, 6.9:1 on zebra */
  --value: #0c4a3d;          /* deep green ink: 10.2:1 on white, 9.2:1 on zebra */
  --muted: #56635e;          /* 6.3:1 on white */
  --link: #0b57a4;           /* 7.2:1, links only */
  --link-hover: #083f78;
  --brand: #185c4f;
  --brand-dark: #124a40;
  --brand-soft: #e2f1e9;     /* mint */
  --brand-line: #a9cbbb;
  --line: #dcd8ce;
  --line-soft: #ebe7de;
  --th-bg: #f1e9da;          /* sand header */
  --zebra: #f8f5ef;
  --box-bg: #fffefb;
  --disabled-bg: #efede8;
  --disabled-text: #66655f; /* 4.9:1 on --disabled-bg */
  --focus: #0b57a4;
  --note-bg: #fbf6e9;
  --note-line: #e8dcbc;
  --note-ink: #5c4a1c;

  --nohab: #b42318;          /* 6.0:1 on white: the "sem habilitação" mark */

  /* Pastel accents: one per role, always with a dark ink of the same hue (>= 6:1). */
  --mint-bg: #eef8f2;   --mint-line: #bfe0cf;   --mint-ink: #1f5a45;
  --peach-bg: #fdf3ec;  --peach-line: #f2cfba;  --peach-ink: #8a3b1e;
  --sand-bg: #f7f0e2;   --sand-line: #e4d4b4;   --sand-ink: #5e4a1c;
  --sky-bg: #edf1f8;    --sky-line: #c9d4e8;    --sky-ink: #2c3f66;
  --rose-bg: #fcefee;   --rose-line: #efc7c4;   --rose-ink: #8a3530;
  --butter-bg: #fcf4dc; --butter-line: #ecd79a; --butter-ink: #634a0c;
  --lilac-bg: #f2eef8;  --lilac-line: #d6cbe8;  --lilac-ink: #4a3a6b;
  --aqua-bg: #e8f5f5;   --aqua-line: #b9dfe0;   --aqua-ink: #1d5a60;
  --sage-bg: #eef2ea;   --sage-line: #cbd8c2;   --sage-ink: #3f5a3a;

  /* Layout */
  --sidebar-w: 216px;
  --label-col: 13.5rem;      /* shared by every ficha box (11.75rem in the two-column ficha) */
  --row-h: 2.1333rem;        /* ≈32px table rows */
  --radius: 8px;
  --workspace-top: 300px;    /* measured by app.js */
}

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

html {
  font-size: var(--base);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--fs-value);
  line-height: 1.45;
}

h1, h2, h3, h4, p, dl, dd, ul {
  margin: 0;
}

ul {
  padding: 0;
  list-style: none;
}

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

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

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

svg {
  width: 1.1em;
  height: 1.1em;
  display: block;
  flex-shrink: 0;
}

button svg {
  pointer-events: none;
}

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

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

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  padding: 10px 14px;
  background: var(--paper);
  z-index: 100;
}

.skip-link:focus {
  top: 10px;
}

/* ------------------------------------------------------------------ */
/* Shell: sidebar + main                                               */
/* ------------------------------------------------------------------ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 6px 20px;
  color: var(--brand-dark);
  text-decoration: none;
  font: 700 22px/1.1 var(--font-brand);
  letter-spacing: -0.5px;
}

.brand small {
  display: block;
  margin-top: 3px;
  font: 600 12px/1.2 var(--font-text);
  letter-spacing: 1.5px;
  color: var(--muted);
}

.brand-icon {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--brand-dark);
  color: #fff;
  text-align: center;
  font: italic 30px/40px var(--font-brand);
}

.brand-icon span {
  position: absolute;
  right: 3px;
  top: -8px;
  color: #acd3c2;
  font: 20px/1 var(--font-text);
}

.nav-main {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 8px;
  margin-bottom: 16px;
  border-radius: 7px;
  font-size: var(--fs-label);
  font-weight: 600;
  text-align: left;
  color: var(--label);
}

.nav-main:hover,
.group-button:hover {
  background: var(--zebra);
}

.nav-main.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.group-label {
  display: flex;
  justify-content: space-between;
  padding: 0 8px;
  margin-bottom: 6px;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--muted);
}

#group-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.group-button {
  display: grid;
  grid-template-columns: 2em 1fr auto;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: var(--fs-label);
  line-height: 1.35;
  text-align: left;
  color: var(--ink);
}

.group-code {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--label);
  border: 1px solid var(--line);
  border-radius: 4px;
  text-align: center;
}

.group-count {
  font-size: var(--fs-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.group-button.active {
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--brand);
}

.group-button.active .group-code {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.loading-small {
  padding: 10px 8px;
  font-size: var(--fs-xs);
  color: var(--muted);
}

.main {
  min-width: 0;
  padding: 0 20px 10px;
  display: flex;
  flex-direction: column;
}

/* --- Top bar: title + competência + reading controls + source --- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 20px;
  min-height: 44px;
  padding: 4px 0;
}

.topbar-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-right: auto;
}

.topbar h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--brand-dark);
}

.edition-chip {
  font-size: var(--fs-label);
  color: var(--label);
}

.edition-chip strong {
  font-family: var(--font-mono);
  color: var(--value);
}

.reading-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-label {
  font-size: var(--fs-xs);
  color: var(--label);
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: var(--paper);
}

.segmented button {
  min-width: 2.2rem;
  min-height: 30px;
  padding: 2px 10px;
  font-size: var(--fs-label);
  color: var(--label);
}

.segmented button + button {
  border-left: 1px solid var(--line);
}

/* The group clips its children (overflow: hidden), so draw the ring inside. */
.segmented button:focus-visible {
  outline-offset: -3px;
}

.segmented button[aria-pressed="true"] {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.segmented button:hover:not([aria-pressed="true"]) {
  background: var(--zebra);
}

.source-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 2px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  font-size: var(--fs-label);
  color: var(--label);
}

.source-button:hover {
  color: var(--brand-dark);
  border-color: var(--brand-line);
}

/* ------------------------------------------------------------------ */
/* Explorer card: filters, results bar, workspace                       */
/* ------------------------------------------------------------------ */

.explorer {
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: clip;   /* clips the rounded corners without becoming a scroll container */
}

.filters {
  padding: 8px 14px;
}

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

.search-wrap {
  flex: 1 1 12rem;
  min-width: 0;   /* shrink instead of pushing Limpar off a narrow screen */
  display: flex;
  align-items: center;
  gap: 10px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--box-bg);
  color: var(--muted);
}

/* The input draws no outline of its own: the same 3px ring as every other control goes around the box. */
.search-wrap:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.search-wrap input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: var(--fs-value);
  color: var(--ink);
}

.search-wrap input::placeholder {
  color: #66726d;
}

.search-wrap kbd {
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--label);
}

.reset-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: var(--fs-label);
  white-space: nowrap;
  color: var(--label);
}

.reset-button:hover {
  background: var(--zebra);
  color: var(--brand-dark);
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) repeat(2, minmax(0, 1.15fr));
  gap: 8px 10px;
  margin-top: 8px;
}

.field {
  position: relative;   /* anchors the CID/CBO note */
  min-width: 0;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.field label {
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--label);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field select,
.field input {
  width: 100%;
  height: 34px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font-size: var(--fs-row);
  color: var(--ink);
  text-overflow: ellipsis;
}

.field select:disabled {
  opacity: 1;   /* the UA's 0.7 would take the hint text below 3:1 */
  background: var(--disabled-bg);
  color: var(--disabled-text);
}

.browse-relations {
  font-size: var(--fs-xs);
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

.label-help {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

/* "?" next to the CID filter: opens the note on how CID and CBO combine. */
.info-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--label);
  border-radius: 50%;
  font-size: var(--fs-xs);
  font-weight: 700;
  line-height: 1;
  color: var(--label);
}

.info-button:hover,
.info-button[aria-expanded="true"] {
  background: var(--label);
  color: #fff;
}

.info-popover {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10;
  width: max(100%, min(22rem, 100vw - 64px));
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 6px 24px #1e3e3326;
  font-size: var(--fs-label);
  color: var(--ink);
}

.workspace {
  display: grid;
  /* The ficha gets the larger share: at 1440 px its two columns fit the 13 attributes. */
  grid-template-columns: minmax(300px, 32%) minmax(0, 1fr);
  border-top: 1px solid var(--line);
  /* Fill the window below the filters; the low minimum keeps the page itself
     from scrolling at 1280×720 or 1526×726 (125% zoom). */
  height: max(380px, calc(100vh - var(--workspace-top) - 12px));
}

/* ------------------------------------------------------------------ */
/* List                                                                */
/* ------------------------------------------------------------------ */

.list-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}

/* Result count (+ "na base completa" / "com os filtros atuais") and the page's range. */
.list-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0 12px;
  padding: 6px 14px;
  background: var(--th-bg);
  font-size: var(--fs-label);
  color: var(--ink);
}

#result-count {
  color: var(--brand-dark);
}

#result-context {
  color: var(--label);
}

#list-range {
  color: var(--label);
  font-variant-numeric: tabular-nums;
}

.results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.proc-row {
  position: relative;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);   /* every masked code has the same width */
  gap: 12px;
  align-items: baseline;
  width: 100%;
  min-height: 52px;
  padding: 7px 14px 7px 16px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  background: var(--paper);
}

.proc-row:hover {
  background: var(--zebra);
}

/* #results clips overflow and the next row paints over the bottom edge, so draw the ring inside. */
.proc-row:focus-visible {
  outline-offset: -3px;
}

.proc-code {
  font-family: var(--font-mono);
  font-size: max(12px, 0.8667rem);
  font-variant-numeric: tabular-nums;
  color: #23413a; /* 11:1 */
  white-space: nowrap;
}

.proc-name {
  font-size: var(--fs-row);
  line-height: 1.35;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Whole name: on the selected row, and when another name on the page starts
   the same way (app.js), so the part that tells them apart is visible. */
.proc-name.full,
.proc-row.selected .proc-name {
  display: block;
  overflow: visible;
}

.proc-row.selected {
  background: var(--brand-soft);
}

.proc-row.selected::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--brand);
}

.proc-row.selected .proc-name,
.proc-row.selected .proc-code {
  font-weight: 700;
  color: var(--brand-dark);
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-xs);
  color: var(--label);
}

.pagination > div {
  display: flex;
  gap: 6px;
}

.pagination button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.empty-detail,
.empty-results,
.loading-state {
  padding: 48px 28px;
  text-align: center;
  color: var(--muted);
}

.empty-detail > svg,
.empty-results > svg {
  width: 32px;
  height: 32px;
  margin: 0 auto 14px;
}

.empty-detail h2 {
  font-size: 1.2rem;
  color: var(--brand-dark);
}

.empty-detail p,
.empty-results p {
  margin-top: 8px;
  font-size: var(--fs-row);
}

.empty-results button,
.text-button {
  margin-top: 14px;
  color: var(--link);
  text-decoration: underline;
  font-size: var(--fs-row);
}

/* ------------------------------------------------------------------ */
/* Ficha                                                               */
/* ------------------------------------------------------------------ */

.detail-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  /* Keep keyboard focus out from under the sticky tab bar (height set by app.js). */
  scroll-padding-top: calc(var(--tabbar-h, 5rem) + 8px);
  background: var(--paper);
}

.ficha {
  container: ficha / inline-size;
  padding: 10px 16px 18px;
}

/*
 * Header (full width): code, Copiar código and competência on one line, the
 * name below. Body: Classificação, Valores, Atributos (DOM order, the order of
 * the one-column ficha). When the ficha content is at least 720px wide (a
 * container query: the width depends on the list beside it, not on the
 * window) Valores becomes a right-hand column that stays in view while the
 * attributes scroll by (container rules after the Valores section).
 */
.ficha-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.back-list {
  display: none;
}

.ficha-code-row {
  display: flex;
  flex-wrap: wrap;   /* the copy button and competência drop below the code when space is short */
  align-items: center;
  gap: 4px 14px;
}

.ficha-code {
  flex: none;
  white-space: nowrap;   /* never split a code before its check digit */
  font-family: var(--font-mono);
  font-size: var(--fs-code);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--value);
}

.copy-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: var(--fs-xs);
  color: var(--label);
  white-space: nowrap;
}

.copy-button:hover {
  border-color: var(--brand-line);
  color: var(--brand-dark);
}

.ficha-name {
  margin-top: 2px;
  font-size: var(--fs-name);
  font-weight: 700;
  line-height: 1.25;
  color: var(--value);
}

.ficha-meta {
  margin-left: auto;
  font-size: var(--fs-label);
  color: var(--label);
  white-space: nowrap;
}

.box {
  position: relative;
  padding: 6px 12px 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--box-bg);
}

.box-title {
  margin-bottom: 2px;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--brand);
}

.fields {
  display: grid;
}

.field-row {
  display: grid;
  grid-template-columns: var(--label-col) minmax(0, 1fr);
  gap: 12px;
  padding: 1px 0;
  align-items: baseline;
}

.field-row dt {
  font-size: var(--fs-label);
  color: var(--label);
}

.field-row dd {
  font-size: var(--fs-value);
  font-weight: 500;
  color: var(--value);
  min-width: 0;
  overflow-wrap: break-word;   /* "Atendimento/Acompanhamento" on a phone */
}

/* Two or more items: a marker on each, and a gap, so a wrapped line never reads as another item. */
.value-list.multi li {
  position: relative;
  padding-left: 0.9em;
}

.value-list.multi li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--label);
}

.value-list li + li {
  margin-top: 6px;
}

.value-list .has-tip {
  text-decoration: underline dotted var(--brand-line);
  text-underline-offset: 3px;
  cursor: help;
}

.empty {
  color: var(--muted);
  font-weight: 400;
  cursor: help;
}

/* --- Valores --- */

.valores {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 36px;
}

.money-col {
  display: grid;
  grid-template-columns: var(--label-col) minmax(6.5em, max-content);
  align-content: start;
}

.money-col + .money-col {
  grid-template-columns: max-content minmax(6.5em, max-content);
}

.money-row {
  display: contents;
}

.money-row dt {
  padding: 2px 0;
  font-size: var(--fs-label);
  color: var(--label);
}

.money-row dd {
  padding: 2px 0 2px 12px;
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--value);
  white-space: nowrap;
}

.money-row.total dt,
.money-row.total dd {
  border-top: 1px solid var(--line);
  font-weight: 700;
  color: var(--value);
}

.money-row.total dt {
  font-size: var(--fs-value);
}

.money-row small {
  margin-left: 4px;
  white-space: nowrap;
  font-size: var(--fs-xs);
  font-weight: 400;
  color: var(--muted);
}

/* Two-column ficha (see .ficha-body). After the base Valores rules, which it overrides. */
@container ficha (min-width: 720px) {
  .ficha-body {
    --label-col: 11.75rem;
    grid-template-columns: minmax(0, 1fr) clamp(300px, 36%, 340px);
    grid-template-areas:
      "classificacao valores"
      "atributos valores";
    grid-template-rows: auto 1fr;
    align-items: start;
  }

  .box-classificacao { grid-area: classificacao; }
  .box-atributos { grid-area: atributos; }

  .box-valores {
    grid-area: valores;
    position: sticky;
    top: 8px;
  }

  /* One column of amounts on a shared grid, so every amount ends on the same edge. */
  .box-valores .valores {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    gap: 0;
  }

  .box-valores .money-col,
  .box-valores .money-col + .money-col {
    grid-column: 1 / -1;
    grid-template-columns: subgrid;
  }

  .box-valores .money-col + .money-col {
    margin-top: 6px;
  }
}

/* Narrow fichas: Ambulatorial above Hospitalar, amounts on one edge;
   competência on its own line under the code. */
@container ficha (max-width: 659px) {
  .ficha-meta {
    flex-basis: 100%;
    margin-left: 0;
  }

  .valores {
    display: grid;
    gap: 6px;
  }

  .money-col,
  .money-col + .money-col {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

/* ------------------------------------------------------------------ */
/* Relation tabs                                                       */
/* ------------------------------------------------------------------ */

.relations {
  margin-top: 14px;
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  padding: 6px 0 0;
  background: var(--paper);
  border-bottom: 2px solid var(--brand);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  padding: 4px 8px;
  margin-bottom: -2px;
  border: 1px solid var(--line);
  border-bottom: 2px solid var(--brand);
  border-radius: 7px 7px 0 0;
  background: var(--paper);
  font-size: var(--fs-row);
  color: var(--ink);
}

.tab:hover:not(.is-empty):not([aria-selected="true"]) {
  background: var(--zebra);
}

.tab .count {
  min-width: 1.5em;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--brand-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--brand-dark);
}

.tab[aria-selected="true"] {
  border-color: var(--brand);
  border-bottom-color: var(--paper);
  background: var(--paper);
  font-weight: 700;
  color: var(--value);
  box-shadow: inset 0 3px 0 var(--brand);
}

.tab.is-empty {
  cursor: not-allowed;
  background: var(--disabled-bg);
  border-color: var(--line-soft);
  border-bottom-color: var(--brand);
  color: var(--disabled-text);
}

.tab.is-empty .count {
  background: transparent;
  color: var(--disabled-text);
}

.tabpanel {
  padding: 12px 0 4px;
}

.tabpanel:focus-visible {
  outline-offset: -3px;
}

.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.subtabs .tab {
  min-height: 30px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: var(--fs-label);
}

.subtabs .tab[aria-selected="true"] {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  box-shadow: none;
}

.subtabs .tab[aria-selected="true"] .count {
  background: #fff;
  color: var(--brand-dark);
}

.subtabs .tab.is-empty {
  border-color: var(--line-soft);
}

/* --- Tables --- */

.table-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.table-filter {
  flex: 0 1 22rem;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: var(--fs-row);
}

.table-count {
  font-size: var(--fs-xs);
  color: var(--label);
  font-variant-numeric: tabular-nums;  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-row);
}

.data-table th {
  padding: 6px 10px;
  background: var(--th-bg);
  font-size: var(--fs-label);
  font-weight: 700;
  text-align: left;
  color: var(--ink);
  white-space: nowrap;
}

.data-table td {
  height: var(--row-h);
  padding: 5px 10px;
  border-top: 1px solid var(--line-soft);
  vertical-align: top;
  color: var(--ink);
}

.data-table tr.alt td {
  background: var(--zebra);
}

.data-table .num {
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table th.num {
  font-family: var(--font-text);
}

.data-table .col-code,
.data-table .col-short,
.data-table .col-proc {
  width: 1%;
  white-space: nowrap;
}

.data-table .col-group {
  width: 22%;
}

.data-table .col-name {
  width: 32%;
}

.data-table .col-procname {
  width: 40%;
}

.data-table.compact td {
  height: auto;
  padding: 4px 8px;
}

.sub-line {
  display: block;
  font-size: var(--fs-label);
  color: var(--muted);
}

.sub-line.strong {
  font-size: var(--fs-row);
  color: var(--ink);
}

.cell-list li + li {
  margin-top: 2px;
}

.proc-link {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
  white-space: nowrap;   /* never split a code before its check digit */
}

.data-table .mono {
  white-space: nowrap;
}

.proc-link:hover {
  color: var(--link-hover);
}

.badge {
  display: inline-block;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--zebra);
  font-size: var(--fs-xs);
  color: var(--label);
  white-space: nowrap;
}

.badge-ok {
  border-color: var(--brand-line);
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 700;
}

.table-caption {
  margin-bottom: 8px;
  font-size: var(--fs-label);
  color: var(--label);
}

.no-match,
.empty-note {
  padding: 10px 0;
  font-size: var(--fs-row);
  color: var(--muted);
}

.footnote {
  margin-top: 8px;
  font-size: var(--fs-xs);
  color: var(--muted);
}

.description {
  max-width: 72ch;
  font-size: var(--fs-value);
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-line;
  text-align: left;
}

/* --- CBO families --- */

.families {
  display: grid;
  gap: 6px;
}

.family {
  border: 1px solid var(--line);
  border-radius: 6px;
}

.family summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 10px;
  padding: 7px 10px;
  cursor: pointer;
  background: var(--th-bg);
  border-radius: 6px;
  font-size: var(--fs-row);
}

.family[open] summary {
  border-radius: 6px 6px 0 0;
}

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

.family-chevron {
  display: grid;
  place-items: center;
  width: 1.4em;
  height: 1.4em;
  border: 1px solid var(--brand-line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--brand-dark);
}

.family[open] .family-chevron svg {
  transform: rotate(90deg);
}

.family summary:hover .family-title {
  text-decoration: underline;
}

.family-title {
  font-weight: 700;
  color: var(--value);
}

.family-preview {
  font-size: var(--fs-label);
  color: var(--muted);
}

.family .filterable {
  padding: 8px;
}

.legal-note {
  margin-top: 14px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: var(--fs-xs);
  color: var(--muted);
}

/* ------------------------------------------------------------------ */
/* Dialogs + toast                                                     */
/* ------------------------------------------------------------------ */

dialog {
  width: calc(100% - 32px);
  max-width: 640px;
  max-height: 88vh;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 80px #1e3e3330;
}

dialog::backdrop {
  background: #152f2866;
}

#relation-browser {
  max-width: 780px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.dialog-header h2 {
  font-size: 1.5rem;
  color: var(--brand-dark);
}

.eyebrow {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--brand);
}

.icon-button {
  padding: 6px;
  border-radius: 6px;
  color: var(--label);
}

.icon-button:hover {
  background: var(--zebra);
}

#source-content p {
  margin-top: 10px;
  font-size: var(--fs-row);
  line-height: 1.6;
  color: var(--ink);
}

#source-content h3 {
  margin: 18px 0 8px;
  font-size: var(--fs-value);
  color: var(--brand-dark);
}

.source-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0;
}

.source-stats > div {
  padding: 12px;
  border-radius: 8px;
  background: var(--brand-soft);
}

.source-stats strong {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.4rem;
  color: var(--value);
}

.source-stats span {
  font-size: var(--fs-label);
  color: var(--label);
}

#source-content .validation-note {
  padding: 10px 12px;
  border: 1px solid var(--note-line);
  border-radius: 6px;
  background: var(--note-bg);
  color: var(--note-ink);
}

.row-counts {
  margin-top: 12px;
  font-size: var(--fs-row);
}

.row-counts summary {
  cursor: pointer;
  color: var(--link);
  margin-bottom: 8px;
}

.hash {
  display: block;
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--label);
  overflow-wrap: anywhere;
}

.browser-controls {
  display: grid;
  grid-template-columns: 1fr 130px;
  gap: 14px;
}

.browser-controls label {
  display: grid;
  gap: 5px;
  font-size: var(--fs-label);
  color: var(--label);
}

.browser-controls input,
.browser-controls select {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font-size: var(--fs-row);
}

#browser-count {
  margin: 12px 0;
  font-size: var(--fs-label);
  color: var(--label);
}

#browser-results {
  max-height: 45vh;
  overflow: auto;
  border-top: 1px solid var(--line);
}

.browser-result {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 2px 12px;
  width: 100%;
  padding: 9px 8px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
}

.browser-result:hover,
.browser-result:focus-visible {
  background: var(--zebra);
}

.browser-result code {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--value);
}

.browser-result span {
  font-size: var(--fs-row);
  overflow-wrap: anywhere;
}

.browser-result small {
  grid-column: 2;
  font-size: var(--fs-xs);
  color: var(--muted);
}

.browser-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: var(--fs-label);
}

.browser-pagination button {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 20;
  padding: 10px 18px;
  border-radius: 8px;
  background: var(--brand-dark);
  color: #fff;
  font-size: var(--fs-row);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 0.2s, transform 0.2s;
}

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

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 1180px) {
  :root {
    --sidebar-w: 190px;
  }

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

  .filter-grid .field:nth-child(4) {
    grid-column: 1 / span 2;
  }

  .control-label {
    display: none;
  }
}

@media (max-width: 950px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding: 0 14px 10px;
  }
}

@media (max-width: 760px) {
  :root {
    --label-col: 9.5rem;
  }

  .topbar {
    gap: 8px 12px;
  }

  .source-button span:last-child {
    display: none;
  }

  .filters {
    padding: 10px 12px;
  }

  .search-wrap kbd {
    display: none;
  }

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

  .filter-grid .field:nth-child(1),
  .filter-grid .field:nth-child(4),
  .filter-grid .field:nth-child(5) {
    grid-column: 1 / -1;
  }

  #result-context {
    display: none;
  }

  .workspace {
    display: block;
    height: auto;
  }

  /* The list flows in the page: one scroll on touch screens, not a box inside a page. */
  .list-panel {
    height: auto;
    border-right: 0;
  }

  .results {
    overflow: visible;
  }

  .detail-panel {
    display: none;
    overflow: visible;
  }

  .workspace.mobile-detail .list-panel {
    display: none;
  }

  .workspace.mobile-detail .detail-panel {
    display: block;
  }

  .ficha {
    padding: 12px;
  }

  .back-list {
    display: flex;
    width: fit-content;
    align-items: center;
    gap: 4px;
    min-height: 34px;
    margin-bottom: 6px;
    font-size: var(--fs-row);
    color: var(--link);
    text-decoration: underline;
  }

  .proc-row {
    grid-template-columns: 1fr;
    gap: 1px;
  }

  /* Touch screens have no hover tooltip: show every name whole. */
  .proc-name {
    display: block;
    overflow: visible;
  }

  /* The 3–4 line tab strip would cover too much of a phone screen if it stuck. */
  .tabbar {
    position: static;
  }

  /* Tables with three or more text columns as stacked rows: first cell on
     top, the others below with their column name (Compatibilidades, Regra,
     Origem SIA/SIH, Grupos de habilitação, Serviço/Classificação). */
  .stack-table thead {
    display: none;
  }

  .stack-table tr {
    display: block;
    padding: 6px 10px;
    border-top: 1px solid var(--line-soft);
  }

  .stack-table tr.alt {
    background: var(--zebra);
  }

  .data-table.stack-table td,
  .data-table.stack-table tr.alt td {
    display: block;
    width: auto;
    height: auto;
    padding: 1px 0;
    border: 0;
    background: none;
    text-align: left;
    white-space: normal;
  }

  .stack-table td + td::before {
    content: attr(data-label) ": ";
    font-family: var(--font-text);
    font-size: var(--fs-label);
    color: var(--label);
  }

  /* Anything else that is still too wide breaks inside words, never off-screen. */
  .data-table td {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  :root {
    --label-col: 8.4rem;
  }

  .field-row {
    gap: 10px;
  }

  .box {
    padding: 6px 10px 7px;
  }

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

  .browser-result {
    grid-template-columns: 56px 1fr;
  }

  .tab {
    padding: 4px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}

/* ------------------------------------------------------------------ */
/* Pastel accents (v2): colour marks roles, never decorates            */
/* ------------------------------------------------------------------ */

.sidebar { background: #fbfaf6; }

/* One pastel per SIGTAP group, used only on the small group-code chips. */
[data-group="01"] { --gc-bg: var(--mint-bg);   --gc-line: var(--mint-line);   --gc-ink: var(--mint-ink); }
[data-group="02"] { --gc-bg: var(--sky-bg);    --gc-line: var(--sky-line);    --gc-ink: var(--sky-ink); }
[data-group="03"] { --gc-bg: var(--sage-bg);   --gc-line: var(--sage-line);   --gc-ink: var(--sage-ink); }
[data-group="04"] { --gc-bg: var(--peach-bg);  --gc-line: var(--peach-line);  --gc-ink: var(--peach-ink); }
[data-group="05"] { --gc-bg: var(--rose-bg);   --gc-line: var(--rose-line);   --gc-ink: var(--rose-ink); }
[data-group="06"] { --gc-bg: var(--butter-bg); --gc-line: var(--butter-line); --gc-ink: var(--butter-ink); }
[data-group="07"] { --gc-bg: var(--lilac-bg);  --gc-line: var(--lilac-line);  --gc-ink: var(--lilac-ink); }
[data-group="08"] { --gc-bg: var(--sand-bg);   --gc-line: var(--sand-line);   --gc-ink: var(--sand-ink); }
[data-group="09"] { --gc-bg: var(--aqua-bg);   --gc-line: var(--aqua-line);   --gc-ink: var(--aqua-ink); }

.group-button .group-code {
  background: var(--gc-bg, var(--paper));
  border-color: var(--gc-line, var(--line));
  color: var(--gc-ink, var(--label));
  font-weight: 700;
}

.group-button.active .group-code {
  background: var(--gc-ink, var(--brand));
  border-color: var(--gc-ink, var(--brand));
  color: #fff;
}

.group-chip {
  display: inline-block;
  min-width: 2.1em;
  margin-right: 4px;
  padding: 0 4px;
  border: 1px solid var(--gc-line, var(--line));
  border-radius: 4px;
  background: var(--gc-bg, var(--paper));
  color: var(--gc-ink, var(--label));
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  text-align: center;
}

/* Ficha boxes: Classificação mint, Valores peach, Atributos white. */
.box-classificacao {
  background: var(--mint-bg);
  border-color: var(--mint-line);
}
.box-classificacao .box-title { color: var(--mint-ink); }

.box-valores {
  background: var(--peach-bg);
  border-color: var(--peach-line);
}
.box-valores .box-title { color: var(--peach-ink); }
.box-valores .money-row.total { border-color: var(--peach-line); }

.box-atributos { background: var(--paper); }

/* Tab counts in butter; empty tabs stay neutral grey. */
.tab .count {
  background: var(--butter-bg);
  color: var(--butter-ink);
  box-shadow: inset 0 0 0 1px var(--butter-line);
}
.tab.is-empty .count { box-shadow: none; }

.badge-ok {
  border-color: var(--mint-line);
  background: var(--mint-bg);
  color: var(--mint-ink);
}
.badge:not(.badge-ok) {
  border-color: var(--sand-line);
  background: var(--sand-bg);
  color: var(--sand-ink);
}

.edition-chip {
  background: var(--sky-bg);
  border: 1px solid var(--sky-line);
  color: var(--sky-ink);
  border-radius: 999px;
  padding: 1px 10px;
}

.proc-row.selected { background: var(--mint-bg); }

/* ------------------------------------------------------------------ */
/* Collapsible sidebar sections                                        */
/* ------------------------------------------------------------------ */

.nav-section + .nav-section { margin-top: 14px; }

.section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 4px;
  border-radius: 6px;
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--ink);
  text-align: left;
}

.section-toggle:hover { background: var(--zebra); }

.section-chevron,
.section-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 0.15s ease;
}

.nav-section.collapsed .section-toggle svg { transform: rotate(-90deg); }

.section-title { flex: 1; }

.section-meta {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#report-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.report-button {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  width: 100%;
  padding: 6px 8px 6px 30px;
  border-radius: 7px;
  font-size: var(--fs-label);
  line-height: 1.35;
  text-align: left;
  color: var(--ink);
}

.report-button.report-all {
  padding-left: 8px;
  font-weight: 600;
}

.report-button svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }

.report-button:hover { background: var(--zebra); }

.report-button.active {
  background: var(--lilac-bg);
  color: var(--lilac-ink);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--lilac-ink);
}

@media (prefers-reduced-motion: reduce) {
  .section-toggle svg { transition: none; }
}

/* ------------------------------------------------------------------ */
/* Reports view                                                         */
/* ------------------------------------------------------------------ */

.reports-view {
  padding: 16px 18px 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.report-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.report-head h2 {
  margin-top: 2px;
  font-size: var(--fs-name);
  color: var(--value);
}

.report-head h2:focus { outline: none; }

.report-desc {
  max-width: 72ch;
  margin-top: 4px;
  font-size: var(--fs-row);
  color: var(--muted);
}

.report-back,
.report-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.report-back:hover,
.report-copy:hover:not(:disabled) { background: var(--zebra); }

.report-back svg,
.report-copy svg { width: 16px; height: 16px; }

.report-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 10px;
}

.report-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--box-bg);
  text-align: left;
  color: var(--ink);
}

.report-card:first-child {
  border-color: var(--lilac-line);
  background: var(--lilac-bg);
}

.report-card:hover { border-color: var(--brand-line); background: var(--mint-bg); }

.report-card strong { font-size: var(--fs-value); color: var(--value); }

.report-card span { font-size: var(--fs-label); color: var(--muted); }

.report-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
  padding: 10px 12px;
  border: 1px solid var(--sand-line);
  border-radius: 10px;
  background: var(--sand-bg);
}

.report-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 12px 0 8px;
}

#report-summary {
  font-size: var(--fs-row);
  font-weight: 600;
  color: var(--value);
}

.report-table .table-wrap { max-height: calc(100vh - 400px); min-height: 260px; overflow: auto; }

.report-data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.report-data .group-row th {
  padding: 7px 10px;
  border-top: 1px solid var(--mint-line);
  background: var(--mint-bg);
  font-size: var(--fs-row);
  font-weight: 700;
  text-align: left;
  color: var(--mint-ink);
  white-space: normal;
}

.group-row-name { margin-left: 6px; color: var(--ink); }

.group-row-count {
  margin-left: 8px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
}

.report-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: var(--fs-label);
  color: var(--muted);
}

.report-pager > div { display: flex; gap: 8px; }

.report-pager button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.report-pager svg { width: 16px; height: 16px; }

@media (max-width: 1100px) {
  .report-controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .reports-view { padding: 12px; }
  .report-controls { grid-template-columns: 1fr; }
  .report-table .table-wrap { max-height: none; }
}

/* Relatórios: a single sidebar button (v3) */
.reports-button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 14px;
  padding: 8px;
  border-radius: 7px;
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--ink);
  text-align: left;
}

.reports-button svg { width: 18px; height: 18px; }
.reports-button:hover { background: var(--zebra); }

.reports-button.active {
  background: var(--lilac-bg);
  color: var(--lilac-ink);
  box-shadow: inset 3px 0 0 var(--lilac-ink);
}

.report-head-actions,
.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.report-copy:disabled { opacity: 0.55; cursor: not-allowed; }

/* CBO categories as a table (v4): Código | Categoria | Ocupações, rows expand */
.families {
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.families-head,
.family summary {
  display: grid;
  grid-template-columns: 1.6em 4.5em minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.families-head {
  padding: 6px 10px;
  background: var(--th-bg);
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--ink);
}

.families .family {
  border: 0;
  border-top: 1px solid var(--line-soft);
  border-radius: 0;
}

.families .family summary {
  padding: 6px 10px;
  background: var(--paper);
  border-radius: 0;
}

.families .family.alt summary { background: var(--zebra); }

.families .family[open] summary { background: var(--mint-bg); }

.family-code { font-size: var(--fs-row); color: var(--value); font-weight: 600; }

.family-name { font-size: var(--fs-row); color: var(--ink); font-weight: 600; min-width: 0; }

.family-count {
  font-size: var(--fs-xs);
  color: var(--muted);
  white-space: nowrap;
}

.families .family .filterable {
  padding: 8px 10px 10px 2.9em;
  border-top: 1px solid var(--mint-line);
}

/* Reports: Assunto field + matched units (v4) */
.report-controls {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.report-controls .field[hidden] { display: none; }

.topic-matches {
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid var(--sky-line);
  border-radius: 10px;
  background: var(--sky-bg);
  font-size: var(--fs-label);
  color: var(--sky-ink);
}

.topic-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.topic-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--gc-line, var(--line));
  border-radius: 999px;
  background: var(--paper);
  font-size: var(--fs-label);
  color: var(--ink);
  text-align: left;
}

.topic-chip .mono { color: var(--gc-ink, var(--label)); font-weight: 700; }

.topic-chip:hover { background: var(--gc-bg, var(--zebra)); }

.topic-count {
  font-size: var(--fs-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

@media (max-width: 640px) {
  .report-controls { grid-template-columns: 1fr; }
}
.topic-chip.is-empty { opacity: 0.7; cursor: default; background: var(--disabled-bg); }

/* v5: classification finder + clearer money columns */
.topic-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.topic-head + .topic-chips { margin-bottom: 8px; }
.topic-chips + .topic-head { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--sky-line); }
.link-button { color: var(--link); text-decoration: underline; font-size: var(--fs-label); }
.topic-chip[aria-pressed="false"] { background: var(--paper); }
.topic-chip.selected { background: var(--gc-bg, var(--mint-bg)); border-color: var(--gc-ink, var(--brand)); box-shadow: inset 0 0 0 1px var(--gc-ink, var(--brand)); }
.topic-chip[aria-pressed="true"]::before { content: "✓"; font-weight: 700; color: var(--gc-ink, var(--brand)); }
.topic-level { font-size: var(--fs-xs); color: var(--muted); }
.topic-x { margin-left: 2px; font-weight: 700; color: var(--muted); }

.report-data th.band { text-align: center; font-size: var(--fs-label); border-bottom: 1px solid var(--line); }
.report-data th.band-amb, .report-data td.band-amb { background: var(--sky-bg); }
.report-data th.band-hosp, .report-data td.band-hosp { background: var(--peach-bg); }
.report-data tr.alt td.band-amb { background: #e4e9f3; }
.report-data tr.alt td.band-hosp { background: #f9eadf; }
.report-data td.money { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); }
.report-data td.money-total { font-weight: 700; color: var(--value); }
.report-data td.money-zero { color: var(--muted); font-weight: 400; }
.report-data thead tr:nth-child(2) th { top: 2.1em; }
.report-data .facet-row td { padding: 4px 6px; background: var(--paper); border-top: 1px solid var(--line-soft); }
.report-data .facet-hint { font-size: var(--fs-xs); color: var(--muted); text-align: right; }
.report-data select.facet { width: 100%; min-width: 7em; padding: 3px 4px; font-size: var(--fs-label); border: 1px solid var(--line); border-radius: 5px; background: var(--paper); }
.report-data thead { position: sticky; top: 0; z-index: 1; }
.report-data thead th { position: static; }
.report-data thead tr:nth-child(2) th { top: auto; }
.report-legend { margin: -2px 0 8px; font-size: var(--fs-xs); color: var(--muted); }

/* v6: Categoria as in the SIGTAP screen: one column "2231 - Médicos" */
.families-head,
.family summary { grid-template-columns: 1.6em minmax(0, 1fr) auto; }
.families-head { text-align: left; }
.family-name { font-weight: 500; color: var(--value); }

/* Compatibilidade tipo 2 (Excludente) */
.badge.badge-excl { border-color: var(--rose-line); background: var(--rose-bg); color: var(--rose-ink); font-weight: 700; }

/* Novidades da competência (diff between bases + portarias from the Nota Técnica) */
.news-button + .reports-button { margin-top: 2px; }

.news-button.active {
  background: var(--sky-bg);
  color: var(--sky-ink);
  box-shadow: inset 3px 0 0 var(--sky-ink);
}

.news-select-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--muted);
}

.news-select-label select {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
}

.news-note {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--sky-line);
  border-radius: 10px;
  background: var(--sky-bg);
  font-size: var(--fs-row);
  color: var(--sky-ink);
}

.news-note > div { display: flex; flex-direction: column; gap: 2px; flex: 1 1 280px; }
.news-note > div span { font-size: var(--fs-label); color: var(--muted); }
.news-note a { text-decoration: none; }

.news-check {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--mint-line);
  border-radius: 999px;
  background: var(--mint-bg);
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--mint-ink);
  white-space: nowrap;
}

.news-check.warn { border-color: var(--rose-line); background: var(--rose-bg); color: var(--rose-ink); }

.news-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.news-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--ink);
}

.news-tab:hover { background: var(--zebra); }

.news-tab[aria-selected="true"] {
  border-color: var(--sky-ink);
  background: var(--sky-bg);
  color: var(--sky-ink);
}

.news-tab .count {
  padding: 0 6px;
  border-radius: 999px;
  background: var(--zebra);
  font-size: var(--fs-xs);
  color: var(--muted);
}

.news-tab[aria-selected="true"] .count { background: var(--paper); color: var(--sky-ink); }

.news-data td { vertical-align: top; }

.portaria {
  display: block;
  font-size: var(--fs-label);
  white-space: nowrap;
}

.news-data .empty { font-size: var(--fs-label); font-style: italic; color: var(--muted); }

.news-changes,
.news-diff {
  margin: 0;
  padding: 0;
  list-style: none;
}

.news-changes > li + li { margin-top: 4px; }

.news-diff { margin: 2px 0 0 2px; }
.news-diff li { font-size: var(--fs-label); }
.news-diff li > span { display: inline-block; width: 1em; font-weight: 700; }
.news-diff li.add { color: var(--mint-ink); }
.news-diff li.del { color: var(--rose-ink); }

.news-changes .before { color: var(--rose-ink); text-decoration: line-through; text-decoration-thickness: 1px; }
.news-changes .after { color: var(--mint-ink); font-weight: 600; }

.news-desc summary { cursor: pointer; font-size: var(--fs-label); color: var(--brand-dark); }
.news-desc p { max-width: 80ch; margin: 4px 0 0; font-size: var(--fs-label); }

@media (max-width: 640px) {
  .portaria { white-space: normal; }
}

/* Sem habilitação (CNES): a small red ⊗ next to the name */
.nohab {
  display: inline-flex;
  vertical-align: -0.15em;
  margin-right: 5px;
  color: var(--nohab);
}

.nohab svg { width: 1em; height: 1em; stroke-width: 2; }

.nohab-button {
  margin: 0 0 0 4px;
  padding: 2px;
  border-radius: 50%;
  vertical-align: -0.1em;
}

.nohab-button svg { width: 0.8em; height: 0.8em; }
.nohab-button:hover,
.nohab-button[aria-expanded="true"] { background: var(--rose-bg); }

.nohab-note {
  margin-top: 6px;
  padding: 8px 12px;
  border: 1px solid var(--rose-line);
  border-radius: 8px;
  background: var(--rose-bg);
  font-size: var(--fs-row);
  color: var(--rose-ink);
}

.nohab-note ul { margin: 4px 0 4px 18px; padding: 0; }
.nohab-note .sub-line { display: block; color: var(--muted); }

/* "Voltar" to where a linked procedure was opened from */
.back-trail {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  padding: 3px 10px 3px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--brand-dark);
}

.back-trail svg { width: 16px; height: 16px; }
.back-trail:hover { background: var(--zebra); border-color: var(--brand-line); }
