:root {
  color-scheme: light dark;
  --bg: #fcfcfb;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --border: #d8d7d2;
  --surface: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a19;
    --text: #ffffff;
    --text-secondary: #c3c2b7;
    --border: #3a3a38;
    --surface: #232322;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 16px;
  margin: 0;
}

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

.case-picker select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  min-width: 220px;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

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

.tab:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#cy {
  position: absolute;
  inset: 0;
}

.legend {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 190px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 60vh;
  overflow-y: auto;
  /* Sem largura fixa, uma caixa overflow:auto com largura "shrink-to-fit"
     pode entrar num ciclo: a barra de rolagem (que ocupa espaço de verdade
     no Windows, ao contrário do macOS) estreita o conteúdo, o texto quebra
     diferente, a altura muda, e isso liga/desliga a rolagem repetidamente —
     visto como um "piscar". scrollbar-gutter reserva o espaço da barra
     sempre, mesmo sem overflow, então a largura útil do conteúdo nunca
     muda — o ciclo não tem como começar.
   */
  scrollbar-gutter: stable;
  font-size: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: none;
  color: var(--text);
  cursor: pointer;
  padding: 2px 4px;
  text-align: left;
}

.legend-item[aria-pressed="false"] {
  opacity: 0.35;
}

.swatch {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
}

.swatch.shape-ellipse { border-radius: 50%; }
.swatch.shape-rectangle { border-radius: 2px; }
.swatch.shape-diamond { transform: rotate(45deg); }

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  margin: 0;
  padding: 0 24px;
  text-align: center;
}

/* Sem isso, o display:flex acima vence o "display:none" padrão do atributo
   hidden (CSS de autor tem prioridade sobre CSS de user-agent, mesmo com
   especificidade "igual") — o elemento fica sempre visível e cobrindo #cy
   inteiro, interceptando todo clique destinado ao grafo. */
.empty-state[hidden] {
  display: none;
}

.drawer {
  border-top: 1px solid var(--border);
  min-height: 120px;
  max-height: 70vh;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 4px 16px 12px;
  background: var(--surface);
}

.drawer-handle {
  height: 14px;
  margin: 0 -16px 4px;
  cursor: ns-resize;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.drawer-handle::before {
  content: "";
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.drawer-close {
  float: right;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
}

.drawer-label {
  color: var(--text-secondary);
  margin: 0 0 8px 0;
  font-size: 14px;
}

.attr-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  margin: 8px 0;
}

.attr-table th, .attr-table td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}

.attr-table th {
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}

.case-text {
  line-height: 1.6;
  white-space: pre-wrap;
}

.case-text mark, .evidence-snippet {
  background: #eda100;
  color: #1a1a1a;
  padding: 0 2px;
}
