.phylo-app {
  --phylo-bg: var(--sl-color-bg, #ffffff);
  --phylo-bg-soft: var(--sl-color-gray-6, #f4f4f5);
  --phylo-bg-panel: color-mix(in srgb, var(--phylo-bg) 94%, var(--sl-color-accent, #9f1d26));
  --phylo-border: var(--sl-color-gray-5, #d4d4d8);
  --phylo-text: var(--sl-color-text, #18181b);
  --phylo-muted: var(--sl-color-gray-2, #61616b);
  --phylo-accent: var(--sl-color-accent, #a51d2a);
  --phylo-danger: #b4232d;
  color: var(--phylo-text);
  width: 100%;
  max-width: 1900px;
  margin: 0 auto;
}

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

/* V16: o atributo hidden deve sempre retirar o elemento do layout. */
.phylo-app [hidden] {
  display: none !important;
}

.phylo-loading,
.phylo-error {
  min-height: 22rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--phylo-border);
  border-radius: 1rem;
  background: var(--phylo-bg-soft);
  padding: 2rem;
  text-align: center;
}

.phylo-error {
  color: var(--phylo-danger);
}

.phylo-toolbar {
  display: grid;
  gap: 0;
  padding: 0;
  border: 1px solid var(--phylo-border);
  border-bottom: 0;
  border-radius: 0;
  background: var(--phylo-bg-panel);
  position: sticky;
  top: var(--sl-nav-height, 0);
  z-index: 8;
}

.phylo-toolbar-row {
  min-width: 0;
  display: grid;
  align-items: end;
  gap: .65rem;
  padding: .72rem .8rem;
  border-bottom: 1px solid var(--phylo-border);
}

.phylo-toolbar-row-primary {
  grid-template-columns: minmax(18rem, 1fr) minmax(11rem, 13rem);
}

.phylo-toolbar-row-actions {
  grid-template-columns: minmax(18rem, .8fr) minmax(30rem, 1.2fr);
}

.phylo-toolbar-row-tools {
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
}

.phylo-toggle-group {
  display: flex;
  align-items: center;
  gap: .4rem;
  white-space: nowrap;
}

.phylo-clade-actions,
.phylo-data-actions {
  justify-content: flex-end;
}

.phylo-data-actions {
  min-width: 0;
}

.phylo-field {
  display: grid;
  gap: .25rem;
  min-width: 10rem;
}

.phylo-field.is-search {
  flex: 1 1 16rem;
  min-width: 13rem;
}

.phylo-field > span,
.phylo-checkbox > span {
  font-size: .73rem;
  font-weight: 750;
  letter-spacing: .035em;
  text-transform: uppercase;
  color: var(--phylo-muted);
}

.phylo-field select,
.phylo-field input,
.phylo-matrix-controls select,
.phylo-matrix-controls input {
  width: 100%;
  min-height: 2.35rem;
  padding: .45rem .6rem;
  border: 1px solid var(--phylo-border);
  border-radius: .25rem;
  color: var(--phylo-text);
  background: var(--phylo-bg);
  font: inherit;
}

.phylo-search-row {
  display: flex;
  gap: .35rem;
}

.phylo-search-count {
  min-height: 1em;
  font-size: .72rem;
  color: var(--phylo-muted);
}

.phylo-button-group {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
}

.phylo-button,
.phylo-icon-button,
.phylo-code-button {
  border: 1px solid var(--phylo-border);
  border-radius: .25rem;
  color: var(--phylo-text);
  background: var(--phylo-bg);
  font: inherit;
  cursor: pointer;
}

.phylo-button {
  min-height: 2.35rem;
  padding: .42rem .7rem;
  font-size: .84rem;
  font-weight: 680;
}

.phylo-button:hover,
.phylo-icon-button:hover,
.phylo-code-button:hover {
  border-color: var(--phylo-accent);
  color: var(--phylo-accent);
}

.phylo-button.is-secondary {
  min-height: 2rem;
  padding: .3rem .55rem;
  font-size: .76rem;
}

.phylo-icon-button {
  width: 2.35rem;
  height: 2.35rem;
  display: inline-grid;
  place-items: center;
  font-size: 1.05rem;
  font-weight: 800;
}

.phylo-checkbox {
  display: flex;
  align-items: center;
  gap: .42rem;
  min-height: 2.35rem;
  padding: .35rem .55rem;
  border: 1px solid var(--phylo-border);
  border-radius: .25rem;
  background: var(--phylo-bg);
  cursor: pointer;
}

.phylo-checkbox input {
  width: 1rem;
  height: 1rem;
}

.phylo-warning {
  margin: 0;
  padding: .65rem .9rem;
  border-inline: 1px solid var(--phylo-border);
  background: color-mix(in srgb, #c98a00 13%, var(--phylo-bg));
  color: var(--phylo-text);
  font-size: .84rem;
}

.phylo-main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(17rem, 24rem);
  min-height: 74vh;
  max-height: calc(100vh - 9rem);
  border: 1px solid var(--phylo-border);
  background: var(--phylo-bg);
}

.phylo-canvas-column {
  min-width: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  overflow: hidden;
}

.phylo-svg-wrap {
  min-height: 38rem;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(color-mix(in srgb, var(--phylo-border) 18%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--phylo-border) 18%, transparent) 1px, transparent 1px),
    var(--phylo-bg);
  background-size: 26px 26px;
  touch-action: none;
  cursor: grab;
}

.phylo-svg-wrap:active {
  cursor: grabbing;
}

.phylo-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 38rem;
  user-select: none;
}

.phylo-edge {
  fill: none;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: stroke-width .12s ease, opacity .12s ease;
}

.phylo-edge:hover {
  stroke-width: 3.2;
}

.phylo-edge.is-path {
  stroke-width: 3.25;
  filter: drop-shadow(0 0 1.5px color-mix(in srgb, var(--phylo-accent) 70%, transparent));
}

.phylo-edge.is-character-hit {
  stroke: var(--phylo-danger) !important;
  stroke-width: 4.4;
  filter: drop-shadow(0 0 2px color-mix(in srgb, var(--phylo-danger) 65%, transparent));
}

.phylo-node {
  cursor: pointer;
  outline: none;
}

.phylo-node-dot,
.phylo-collapse-marker {
  stroke: var(--phylo-bg);
  stroke-width: 1.3;
  vector-effect: non-scaling-stroke;
}

.phylo-node.is-selected .phylo-node-dot,
.phylo-node.is-selected .phylo-collapse-marker,
.phylo-node:focus .phylo-node-dot,
.phylo-node:focus .phylo-collapse-marker {
  stroke: var(--phylo-accent);
  stroke-width: 3;
}

.phylo-label {
  fill: var(--phylo-text);
  cursor: pointer;
  paint-order: stroke;
  stroke: var(--phylo-bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.phylo-label:hover,
.phylo-label.is-path {
  fill: var(--phylo-accent);
}

.phylo-label.is-terminal {
  font-size: 12px;
  font-style: italic;
}

.phylo-label.is-internal {
  font-size: 11px;
  font-weight: 760;
}

.phylo-branch-id {
  fill: var(--phylo-muted);
  font-size: 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  paint-order: stroke;
  stroke: var(--phylo-bg);
  stroke-width: 2px;
}

.phylo-canvas-footer {
  min-height: 2.3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .45rem .75rem;
  border-top: 1px solid var(--phylo-border);
  background: var(--phylo-bg-panel);
  color: var(--phylo-muted);
  font-size: .75rem;
}

.phylo-details {
  overflow: auto;
  border-left: 1px solid var(--phylo-border);
  padding: 1rem;
  background: var(--phylo-bg-panel);
}

.phylo-details-empty {
  min-height: 18rem;
  display: grid;
  align-content: center;
  gap: .4rem;
  color: var(--phylo-muted);
}

.phylo-details-empty h3,
.phylo-details-empty p,
.phylo-details-header h3,
.phylo-details-subtitle,
.phylo-method-note,
.phylo-muted {
  margin: 0;
}

.phylo-details-header h3 {
  font-size: 1.25rem;
  overflow-wrap: anywhere;
}

.phylo-kicker {
  color: var(--phylo-accent);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.phylo-detail-list {
  display: grid;
  gap: .3rem;
  margin: .85rem 0;
}

.phylo-detail-row {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) auto;
  gap: .75rem;
  border-bottom: 1px dashed var(--phylo-border);
  padding: .3rem 0;
  font-size: .78rem;
}

.phylo-detail-row dt {
  color: var(--phylo-muted);
}

.phylo-detail-row dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.phylo-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin: .7rem 0 1rem;
}

.phylo-details-subtitle {
  margin-top: 1rem;
  margin-bottom: .55rem;
  font-size: .92rem;
}

.phylo-character-list,
.phylo-profile-list {
  display: grid;
  gap: .42rem;
}

.phylo-character-item,
.phylo-profile-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: .18rem .55rem;
  align-items: start;
  padding: .52rem;
  border: 1px solid var(--phylo-border);
  border-radius: .25rem;
  background: var(--phylo-bg);
  color: var(--phylo-text);
  text-align: left;
  cursor: pointer;
}

.phylo-character-item:hover,
.phylo-profile-item:hover {
  border-color: var(--phylo-accent);
}

.phylo-character-code {
  color: var(--phylo-accent);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .72rem;
  font-weight: 800;
}

.phylo-character-description {
  min-width: 0;
  font-size: .76rem;
  line-height: 1.3;
}

.phylo-character-transition {
  grid-column: 2;
  color: var(--phylo-muted);
  font-size: .72rem;
}

.phylo-badge {
  grid-column: 2;
  justify-self: start;
  border-radius: .25rem;
  padding: .1rem .35rem;
  background: color-mix(in srgb, #c98a00 18%, var(--phylo-bg));
  color: var(--phylo-muted);
  font-size: .62rem;
  font-weight: 700;
}

.phylo-profile-item {
  grid-template-columns: auto minmax(0, 1fr) auto;
  font-size: .73rem;
}

.phylo-profile-item strong {
  color: var(--phylo-accent);
  text-align: right;
}

.phylo-muted,
.phylo-method-note {
  color: var(--phylo-muted);
  font-size: .74rem;
  line-height: 1.45;
}

.phylo-method-note {
  margin-top: 1.2rem;
  padding-top: .8rem;
  border-top: 1px solid var(--phylo-border);
}

.phylo-data-note {
  padding: .85rem 1rem;
  border: 1px solid var(--phylo-border);
  border-top: 0;
  border-radius: 0 0 1rem 1rem;
  background: var(--phylo-bg-panel);
  color: var(--phylo-muted);
  font-size: .8rem;
  line-height: 1.5;
}

.phylo-data-note p {
  margin: 0;
}

.phylo-data-note p + p {
  margin-top: .35rem;
}

.phylo-data-note a {
  color: var(--phylo-accent);
  font-weight: 700;
}

.phylo-matrix-dialog {
  width: min(96vw, 92rem);
  height: min(90vh, 58rem);
  border: 1px solid var(--phylo-border);
  border-radius: .85rem;
  padding: 0;
  color: var(--phylo-text);
  background: var(--phylo-bg);
  box-shadow: 0 1.2rem 5rem rgb(0 0 0 / .28);
}

.phylo-matrix-dialog::backdrop {
  background: rgb(0 0 0 / .55);
}

.phylo-matrix-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.phylo-matrix-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--phylo-border);
  background: var(--phylo-bg-panel);
}

.phylo-matrix-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.phylo-matrix-controls {
  display: grid;
  grid-template-columns: minmax(12rem, 1.3fr) minmax(10rem, 1fr) minmax(12rem, 1fr);
  gap: .6rem;
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--phylo-border);
}

.phylo-table-wrap {
  overflow: auto;
  padding: 0 1rem 1rem;
}

.phylo-matrix-count {
  position: sticky;
  top: 0;
  margin: 0;
  padding: .55rem 0;
  background: var(--phylo-bg);
  color: var(--phylo-muted);
  font-size: .75rem;
  z-index: 2;
}

.phylo-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .76rem;
}

.phylo-table th,
.phylo-table td {
  padding: .45rem .5rem;
  border: 1px solid var(--phylo-border);
  vertical-align: top;
  text-align: left;
}

.phylo-table th {
  position: sticky;
  top: 2.1rem;
  background: var(--phylo-bg-panel);
  z-index: 1;
}

.phylo-code-button {
  padding: .2rem .35rem;
  color: var(--phylo-accent);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: .72rem;
  font-weight: 800;
}

.phylo-app:fullscreen {
  padding: 1rem;
  overflow: auto;
  background: var(--phylo-bg);
}

.phylo-app:fullscreen .phylo-main-grid {
  max-height: calc(100vh - 8rem);
}

@media (max-width: 900px) {
  .phylo-toolbar {
    position: static;
  }

  .phylo-main-grid {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .phylo-svg-wrap,
  .phylo-svg {
    min-height: 65vh;
  }

  .phylo-details {
    max-height: 36rem;
    border-left: 0;
    border-top: 1px solid var(--phylo-border);
  }

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


/* Explorador V15: modos, colapso evidente, progresso e novidades */
.phylo-loading-shell {
  width: min(34rem, 92%);
  display: grid;
  gap: .8rem;
  justify-items: stretch;
}
.phylo-loading-shell strong,
.phylo-loading-shell small { text-align: center; }
.phylo-loading-track {
  height: .55rem;
  overflow: hidden;
  border-radius: .25rem;
  background: color-mix(in srgb, var(--phylo-border) 70%, transparent);
}
.phylo-loading-track > span {
  display: block;
  width: 6%;
  height: 100%;
  border-radius: inherit;
  background: var(--phylo-accent);
  transition: width .25s ease;
}
.phylo-error { gap: .8rem; align-content: center; }
.phylo-error-source { max-width: 100%; overflow-wrap: anywhere; }
.phylo-error-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; }
.phylo-button.is-link { display: inline-flex; align-items: center; text-decoration: none; }

.phylo-modebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding: .7rem .85rem;
  border: 1px solid var(--phylo-border);
  border-bottom: 0;
  border-radius: 0;
  background: color-mix(in srgb, var(--phylo-accent) 9%, var(--phylo-bg));
}
.phylo-mode-buttons { display: flex; flex-wrap: wrap; gap: .4rem; }
.phylo-mode-button {
  border: 1px solid var(--phylo-border);
  border-radius: .25rem;
  padding: .48rem .8rem;
  color: var(--phylo-text);
  background: var(--phylo-bg);
  font: inherit;
  font-weight: 720;
  cursor: pointer;
}
.phylo-mode-button:hover,
.phylo-mode-button.is-active {
  border-color: var(--phylo-accent);
  color: var(--phylo-bg);
  background: var(--phylo-accent);
}
.phylo-current-mode { font-size: .78rem; color: var(--phylo-muted); }
.phylo-modebar + .phylo-toolbar { border-radius: 0; }
.phylo-instruction {
  margin: 0;
  padding: .55rem .9rem;
  border-inline: 1px solid var(--phylo-border);
  border-top: 1px solid var(--phylo-border);
  background: var(--phylo-bg-panel);
  color: var(--phylo-muted);
  font-size: .82rem;
}
.phylo-node-toggle-symbol {
  fill: #fff;
  stroke: none;
  font-size: 9px;
  font-family: Arial, sans-serif;
  font-weight: 900;
  pointer-events: none;
}
.phylo-node:not(.is-selected):hover .phylo-node-dot,
.phylo-node:not(.is-selected):hover .phylo-collapse-marker {
  stroke: var(--phylo-accent);
  stroke-width: 3;
}
.phylo-innovation-marker { cursor: pointer; }
.phylo-innovation-diamond {
  fill: #d22730;
  stroke: var(--phylo-bg);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.phylo-innovation-marker:hover .phylo-innovation-diamond {
  fill: #ff3b46;
  stroke: #fff;
  stroke-width: 2.5;
}
.phylo-innovation-count {
  fill: #fff;
  font-family: Arial, sans-serif;
  font-size: 6px;
  font-weight: 900;
  pointer-events: none;
}
.phylo-tooltip {
  position: fixed;
  z-index: 99999;
  width: min(19rem, calc(100vw - 28px));
  display: grid;
  gap: .25rem;
  padding: .65rem .75rem;
  border: 1px solid color-mix(in srgb, var(--phylo-accent) 55%, var(--phylo-border));
  border-radius: .65rem;
  background: color-mix(in srgb, var(--phylo-bg) 94%, #000);
  color: var(--phylo-text);
  box-shadow: 0 12px 35px rgba(0,0,0,.28);
  pointer-events: none;
  font-size: .78rem;
}
.phylo-tooltip[hidden] { display: none; }
.phylo-tooltip > span,
.phylo-tooltip > small { color: var(--phylo-muted); }
.phylo-tooltip .phylo-tooltip-accent { color: #ff5b64; font-weight: 750; }

@media (max-width: 900px) {
  .phylo-modebar { align-items: stretch; }
  .phylo-mode-buttons { width: 100%; }
  .phylo-mode-button { flex: 1 1 9rem; }
  .phylo-toolbar { position: relative; top: auto; }
  .phylo-main-grid { max-height: none; grid-template-columns: 1fr; }
  .phylo-details { border-left: 0; border-top: 1px solid var(--phylo-border); max-height: 28rem; }
  .phylo-svg-wrap, .phylo-svg { min-height: 32rem; }
}


@media (max-width: 1180px) {
  .phylo-toolbar-row-actions {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .phylo-clade-actions {
    justify-content: flex-start;
  }

  .phylo-toolbar-row-tools {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .phylo-toggle-group,
  .phylo-zoom-actions,
  .phylo-data-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

@media (max-width: 680px) {
  .phylo-toolbar-row-primary {
    grid-template-columns: 1fr;
  }

  .phylo-toolbar-row {
    padding: .65rem;
  }

  .phylo-button,
  .phylo-checkbox {
    width: 100%;
    justify-content: center;
  }

  .phylo-icon-button {
    flex: 0 0 2.35rem;
  }
}


/* ==========================================================================
   V17 — controles compactos, progressão taxonômica e matriz independente
   ========================================================================== */

.phylo-app[data-phylo-state="ready"] > .phylo-loading,
.phylo-app[data-phylo-state="ready"] .phylo-loading {
  display: none !important;
  visibility: hidden !important;
  min-height: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
}

.phylo-loading {
  min-height: 0;
  display: grid;
  grid-template-columns: auto minmax(8rem, 1fr) minmax(8rem, auto);
  align-items: center;
  gap: .65rem;
  padding: .55rem .75rem;
  border: 1px solid var(--phylo-border);
  border-radius: 0;
  background: var(--phylo-bg-panel);
  text-align: left;
}

.phylo-loading > strong,
.phylo-loading > small {
  white-space: nowrap;
}

.phylo-loading-track {
  min-width: 8rem;
}

.phylo-controls {
  border: 1px solid var(--phylo-border);
  background: var(--phylo-bg-panel);
}

.phylo-controls-row {
  display: grid;
  align-items: center;
  gap: .45rem;
  padding: .48rem .6rem;
}

.phylo-controls-row + .phylo-controls-row {
  border-top: 1px solid var(--phylo-border);
}

.phylo-controls-primary {
  grid-template-columns:
    max-content
    minmax(16rem, 1.4fr)
    minmax(8rem, .48fr)
    minmax(14rem, 1fr);
}

.phylo-controls-secondary {
  grid-template-columns: max-content max-content minmax(0, 1fr) max-content;
}

.phylo-compact-field {
  min-width: 0;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: .4rem;
}

.phylo-compact-field > span {
  color: var(--phylo-muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.phylo-compact-field select,
.phylo-compact-search input {
  width: 100%;
  min-width: 0;
  height: 2.05rem;
  min-height: 2.05rem;
  padding: .28rem .5rem;
  border: 1px solid var(--phylo-border);
  border-radius: 0;
  color: var(--phylo-text);
  background: var(--phylo-bg);
  font: inherit;
  font-size: .82rem;
}

.phylo-compact-search {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 2.05rem;
  align-items: center;
  gap: .3rem;
  position: relative;
}

.phylo-compact-search .phylo-search-count {
  position: absolute;
  right: 2.5rem;
  bottom: -1.05rem;
  z-index: 2;
  color: var(--phylo-muted);
  font-size: .62rem;
  pointer-events: none;
}

.phylo-controls .phylo-mode-buttons,
.phylo-controls .phylo-button-group,
.phylo-controls .phylo-toggle-group {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: .28rem;
}

.phylo-controls .phylo-button,
.phylo-controls .phylo-mode-button,
.phylo-controls .phylo-icon-button,
.phylo-controls .phylo-checkbox {
  height: 2.05rem;
  min-height: 2.05rem;
  border-radius: 0;
  white-space: nowrap;
}

.phylo-controls .phylo-button,
.phylo-controls .phylo-mode-button {
  padding: .25rem .52rem;
  font-size: .75rem;
}

.phylo-controls .phylo-icon-button {
  width: 2.05rem;
  font-size: .95rem;
}

.phylo-controls .phylo-checkbox {
  gap: .28rem;
  padding: .22rem .42rem;
}

.phylo-controls .phylo-checkbox > span {
  font-size: .68rem;
}

.phylo-tool-actions {
  justify-content: flex-end;
  min-width: 0;
}

.phylo-current-mode {
  min-width: 5.5rem;
  text-align: right;
  font-size: .67rem;
}

.phylo-instruction {
  padding: .34rem .62rem;
  font-size: .72rem;
  line-height: 1.25;
}

.phylo-main-grid {
  grid-template-columns: minmax(0, 1fr) minmax(15rem, 19rem);
  min-height: 66vh;
  max-height: calc(100vh - 7.5rem);
}

.phylo-svg-wrap,
.phylo-svg {
  min-height: 34rem;
}

.phylo-details {
  padding: .72rem;
}

.phylo-node-hitbox {
  fill: transparent;
  stroke: none;
  pointer-events: all;
  cursor: pointer;
}

.phylo-collapse-marker {
  cursor: pointer;
}

body.phylo-matrix-open {
  overflow: hidden !important;
}

.phylo-matrix-overlay {
  --phylo-bg: var(--sl-color-bg, #0b1520);
  --phylo-bg-soft: var(--sl-color-gray-6, #111c28);
  --phylo-bg-panel: color-mix(in srgb, var(--phylo-bg) 94%, var(--sl-color-accent, #b98a35));
  --phylo-border: var(--sl-color-gray-5, #405064);
  --phylo-text: var(--sl-color-text, #f4f6f8);
  --phylo-muted: var(--sl-color-gray-2, #aab4bf);
  --phylo-accent: var(--sl-color-accent, #c29138);
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: grid;
  place-items: center;
  padding: clamp(.5rem, 2vw, 1.4rem);
  color: var(--phylo-text);
}

.phylo-matrix-overlay[hidden] {
  display: none !important;
}

.phylo-matrix-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgb(0 0 0 / .72);
  cursor: default;
}

.phylo-matrix-panel {
  position: relative;
  z-index: 1;
  width: min(96vw, 94rem);
  height: min(92vh, 60rem);
  min-height: 28rem;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--phylo-border);
  border-radius: 0;
  background: var(--phylo-bg);
  box-shadow: 0 1.4rem 5rem rgb(0 0 0 / .55);
}

.phylo-matrix-panel .phylo-matrix-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .65rem .8rem;
}

.phylo-matrix-panel .phylo-matrix-controls {
  grid-template-columns: minmax(14rem, 1.4fr) minmax(11rem, 1fr) minmax(14rem, 1fr);
  padding: .55rem .8rem;
}

.phylo-matrix-panel .phylo-table-wrap {
  min-height: 0;
  overflow: auto;
  padding: 0 .8rem .8rem;
}

.phylo-matrix-panel .phylo-table {
  min-width: 64rem;
}

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

@media (max-width: 1180px) {
  .phylo-controls-primary {
    grid-template-columns: max-content minmax(15rem, 1fr) minmax(8rem, .5fr);
  }

  .phylo-compact-search {
    grid-column: 1 / -1;
  }

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

  .phylo-controls .phylo-button-group,
  .phylo-controls .phylo-toggle-group {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .phylo-current-mode {
    text-align: left;
  }
}

@media (max-width: 720px) {
  .phylo-loading {
    grid-template-columns: 1fr;
  }

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

  .phylo-compact-field {
    grid-template-columns: 4.3rem minmax(0, 1fr);
  }

  .phylo-compact-search {
    grid-column: auto;
  }

  .phylo-mode-buttons {
    overflow-x: auto;
  }

  .phylo-main-grid {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .phylo-matrix-panel .phylo-matrix-controls {
    grid-template-columns: 1fr;
  }
}


/* ==========================================================================
   V18 — controles fixos, árvore espaçada e transversalidade compacta
   ========================================================================== */

[data-phylo-contextual-hidden="true"] {
  display: none !important;
}

.phylo-controls-anchor {
  width: 100%;
  position: relative;
}

.phylo-controls {
  width: 100%;
  border: 1px solid var(--phylo-border);
  border-radius: 0;
  background: var(--phylo-bg-panel);
}

.phylo-controls.is-fixed {
  position: fixed !important;
  z-index: 100000;
  max-width: none;
  box-shadow: 0 .45rem 1.4rem rgb(0 0 0 / .28);
}

.phylo-controls-row {
  min-width: 0;
  min-height: 3rem;
  display: flex !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  gap: .45rem;
  padding: .42rem .55rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.phylo-controls-row + .phylo-controls-row {
  border-top: 1px solid var(--phylo-border);
}

.phylo-controls-primary .phylo-mode-buttons,
.phylo-controls-secondary .phylo-button-group,
.phylo-controls-secondary .phylo-toggle-group {
  display: inline-flex !important;
  flex: 0 0 auto;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: .3rem;
}

.phylo-inline-field {
  min-width: 0;
  display: inline-flex;
  flex: 1 1 16rem;
  align-items: center;
  gap: .35rem;
}

.phylo-tree-field {
  min-width: 17rem;
  max-width: 38rem;
}

.phylo-label-field {
  min-width: 9rem;
  max-width: 14rem;
}

.phylo-inline-field > span {
  flex: 0 0 auto;
  color: var(--phylo-muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .035em;
  text-transform: uppercase;
}

.phylo-inline-field select,
.phylo-inline-search input {
  min-width: 0;
  height: 2.18rem !important;
  min-height: 2.18rem !important;
  margin: 0 !important;
  padding: .28rem .5rem !important;
  border: 1px solid var(--phylo-border) !important;
  border-radius: 0 !important;
  color: var(--phylo-text);
  background: var(--phylo-bg);
  font: inherit;
  font-size: .8rem;
  line-height: 1;
}

.phylo-inline-field select {
  width: 100%;
}

.phylo-inline-search {
  min-width: 15rem;
  max-width: 30rem;
  flex: 1 1 18rem;
  display: inline-grid;
  grid-template-columns: minmax(0, 1fr) 2.18rem;
  align-items: center;
  gap: .28rem;
  position: relative;
}

.phylo-inline-search input {
  width: 100%;
}

.phylo-inline-search .phylo-search-count {
  position: absolute;
  right: 2.6rem;
  bottom: -1rem;
  color: var(--phylo-muted);
  font-size: .6rem;
  pointer-events: none;
}

.phylo-controls .phylo-button,
.phylo-controls .phylo-mode-button,
.phylo-controls .phylo-icon-button,
.phylo-controls .phylo-checkbox {
  box-sizing: border-box !important;
  height: 2.18rem !important;
  min-height: 2.18rem !important;
  margin: 0 !important;
  border-radius: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  vertical-align: middle !important;
}

.phylo-controls .phylo-button,
.phylo-controls .phylo-mode-button {
  padding: 0 .58rem !important;
  font-size: .73rem !important;
}

.phylo-controls .phylo-icon-button {
  width: 2.18rem !important;
  min-width: 2.18rem !important;
  padding: 0 !important;
  font-size: 1rem !important;
}

.phylo-controls .phylo-checkbox {
  padding: 0 .48rem !important;
  gap: .28rem;
}

.phylo-controls .phylo-checkbox input {
  margin: 0 !important;
}

.phylo-tool-actions {
  margin-left: auto;
}

.phylo-current-level {
  flex: 0 0 auto;
  min-width: 7rem;
  padding: 0 .45rem;
  color: var(--phylo-muted);
  font-size: .68rem;
  text-align: right;
  white-space: nowrap;
}

.phylo-transversal {
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 2.35rem;
  padding: .34rem .55rem;
  border: 1px solid var(--phylo-border);
  border-top: 0;
  background: color-mix(in srgb, var(--phylo-bg-panel) 88%, var(--phylo-accent) 12%);
  overflow-x: auto;
}

.phylo-transversal-title {
  flex: 0 0 auto;
  color: var(--phylo-muted);
  font-size: .67rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.phylo-transversal-links {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: nowrap;
}

.phylo-transversal-link {
  flex: 0 0 auto;
  padding: .28rem .48rem;
  border: 1px solid var(--phylo-border);
  color: var(--phylo-text);
  background: var(--phylo-bg);
  font-size: .72rem;
  text-decoration: none;
  white-space: nowrap;
}

.phylo-transversal-link:hover,
.phylo-transversal-link:focus-visible {
  border-color: var(--phylo-accent);
  color: var(--phylo-accent);
}

.phylo-instruction {
  margin: 0;
  padding: .38rem .58rem;
}

.phylo-main-grid {
  min-height: 74vh;
  max-height: none;
}

.phylo-svg-wrap,
.phylo-svg {
  min-height: 46rem;
}

.phylo-node-hitbox,
.phylo-node-dot,
.phylo-collapse-marker,
.phylo-node-toggle-symbol {
  pointer-events: all !important;
  cursor: pointer !important;
}

.phylo-node-hitbox {
  fill: transparent;
  stroke: transparent;
  stroke-width: 1;
}

.phylo-node:hover .phylo-node-hitbox {
  fill: color-mix(in srgb, var(--phylo-accent) 10%, transparent);
}

@media (max-width: 920px) {
  .phylo-controls-row {
    overflow-x: auto;
  }

  .phylo-tree-field {
    min-width: 15rem;
  }

  .phylo-main-grid {
    grid-template-columns: 1fr;
  }
}


/* ==========================================================================
   V18.8 — alinhamento rígido, matriz em portal e lateralidade preservada
   ========================================================================== */

.phylo-app {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

.phylo-controls-anchor {
  min-width: 0;
  width: 100%;
  height: auto !important;
  position: sticky;
  top: calc(var(--sl-nav-height, 4rem) + 4px);
  z-index: 80;
}

.phylo-controls,
.phylo-controls.is-fixed {
  position: relative !important;
  top: auto !important;
  left: auto !important;
  width: 100% !important;
  max-width: 100% !important;
  z-index: auto;
  box-sizing: border-box;
  box-shadow: 0 .35rem 1rem rgb(0 0 0 / .22);
}

.phylo-controls-row {
  width: 100%;
  min-width: 0;
  min-height: 3.1rem;
  display: grid !important;
  align-items: center !important;
  gap: .42rem;
  padding: .46rem .52rem;
  overflow: visible !important;
}

.phylo-controls-primary {
  grid-template-columns:
    max-content
    minmax(15rem, 1.45fr)
    minmax(8rem, .55fr)
    minmax(14rem, 1fr);
}

.phylo-controls-secondary {
  grid-template-columns: minmax(0, 1fr) max-content;
}

.phylo-secondary-left {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .38rem;
  flex-wrap: wrap;
}

.phylo-controls .phylo-mode-buttons,
.phylo-controls .phylo-button-group,
.phylo-controls .phylo-toggle-group {
  display: inline-flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: .28rem;
  min-width: 0;
}

.phylo-inline-field {
  min-width: 0;
  max-width: none;
}

.phylo-tree-field,
.phylo-label-field,
.phylo-inline-search {
  min-width: 0 !important;
  max-width: none !important;
}

.phylo-inline-field select,
.phylo-inline-search input,
.phylo-controls .phylo-button,
.phylo-controls .phylo-mode-button,
.phylo-controls .phylo-icon-button,
.phylo-controls .phylo-checkbox {
  height: 2.2rem !important;
  min-height: 2.2rem !important;
  max-height: 2.2rem !important;
  margin: 0 !important;
  border-radius: 0 !important;
  box-sizing: border-box !important;
  line-height: 1 !important;
  vertical-align: middle !important;
}

.phylo-controls .phylo-button,
.phylo-controls .phylo-mode-button,
.phylo-controls .phylo-icon-button,
.phylo-controls .phylo-checkbox {
  position: relative;
  top: 0 !important;
  transform: none !important;
}

.phylo-controls .phylo-checkbox {
  padding-block: 0 !important;
}

.phylo-controls .phylo-checkbox input {
  align-self: center;
}

.phylo-current-level {
  min-width: 0;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.phylo-tool-actions {
  justify-content: flex-end;
  margin-left: 0;
}

.phylo-matrix-button {
  border-color: color-mix(in srgb, var(--phylo-accent) 70%, var(--phylo-border)) !important;
}

.phylo-main-grid {
  width: 100%;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) clamp(16rem, 23vw, 21rem);
}

.phylo-canvas-column,
.phylo-svg-wrap,
.phylo-details {
  min-width: 0;
}

html.phylo-matrix-open,
body.phylo-matrix-open {
  overflow: hidden !important;
}

body > .phylo-matrix-overlay {
  position: fixed !important;
  inset: 0 !important;
  width: 100dvw !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: clamp(.5rem, 1.5vw, 1.2rem) !important;
  z-index: 2147483640 !important;
  place-items: center !important;
  box-sizing: border-box !important;
  isolation: isolate;
}

body > .phylo-matrix-overlay[hidden] {
  display: none !important;
}

body > .phylo-matrix-overlay[data-open="true"] {
  display: grid !important;
}

body > .phylo-matrix-overlay .phylo-matrix-panel {
  width: min(96dvw, 94rem) !important;
  height: min(92dvh, 60rem) !important;
  max-width: 96dvw !important;
  max-height: 92dvh !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

@media (max-width: 1120px) {
  .phylo-controls-primary {
    grid-template-columns: max-content minmax(14rem, 1fr) minmax(8rem, 11rem);
  }

  .phylo-inline-search {
    grid-column: 1 / -1;
  }

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

  .phylo-tool-actions {
    justify-content: flex-start;
    flex-wrap: wrap !important;
  }
}

@media (max-width: 760px) {
  .phylo-controls-anchor {
    position: relative !important;
    top: auto !important;
    z-index: auto;
  }

  .phylo-controls {
    position: relative !important;
    top: auto !important;
  }

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

  .phylo-controls-primary .phylo-mode-buttons {
    overflow-x: auto;
  }

  .phylo-inline-field {
    display: grid;
    grid-template-columns: 4.5rem minmax(0, 1fr);
  }

  .phylo-inline-search {
    grid-column: auto;
  }

  .phylo-secondary-left,
  .phylo-tool-actions {
    align-items: stretch;
    flex-wrap: wrap !important;
  }

  .phylo-main-grid {
    grid-template-columns: 1fr;
  }
}


/* ==========================================================================
   V18.10 — nenhum diagrama contextual pode existir dentro da matriz
   ========================================================================== */

.phylo-matrix-overlay [data-contextual-diagram],
.phylo-matrix-overlay .contextual-diagram,
.phylo-matrix-overlay .arquivo-contextual,
.phylo-matrix-overlay [class*="contextual-diagram"],
.phylo-matrix-overlay [class*="diagrama-contextual"],
.phylo-matrix-overlay [data-phylo-contextual-hidden="true"] {
  display: none !important;
  visibility: hidden !important;
  position: absolute !important;
  width: 0 !important;
  height: 0 !important;
  min-width: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
}

.phylo-matrix-overlay[data-contextual-disabled="true"] {
  contain: layout paint style;
}

.phylo-matrix-panel > :not(.phylo-matrix-header):not(.phylo-matrix-controls):not(.phylo-table-wrap) {
  display: none !important;
}
