/* ==========================================================================
   DER Builder — Esquema Lógico Relacional (Formato Clássico Elmasri & Navathe)
   Tabelas em Faixas Horizontais de Células com Setas Orientadas FK -> PK
   ========================================================================== */

/* Container de Tabelas Relacionais no Canvas */
.schema-tables-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Card / Bloco de Tabela Relacional */
.relational-table-card {
  position: absolute;
  background: transparent;
  pointer-events: auto;
  user-select: none;
  z-index: 10;
  transition: opacity 0.3s ease, filter 0.3s ease;
}

.relational-table-card.selected {
  z-index: 30;
}

.relational-table-card.dimmed {
  opacity: 0.2;
  filter: grayscale(0.7);
}

.relational-table-card.highlighted {
  z-index: 40;
  opacity: 1;
}

/* Nome da Tabela */
.rel-table-title-area {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.rel-table-name {
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-light);
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.rel-table-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-strong {
  background: rgba(2, 132, 199, 0.2);
  color: var(--accent);
  border: 1px solid rgba(0, 240, 255, 0.4);
}

.badge-weak {
  background: rgba(168, 85, 247, 0.2);
  color: var(--accent-purple);
  border: 1px solid rgba(168, 85, 247, 0.4);
}

.badge-assoc {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.4);
}

/* Faixa Horizontal de Células de Atributos */
.rel-strip-row {
  display: inline-flex;
  align-items: stretch;
  background: rgba(8, 13, 26, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(0, 240, 255, 0.35);
  border-radius: 8px;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.7), 0 0 15px rgba(0, 240, 255, 0.08);
  overflow: hidden;
}

.relational-table-card.highlighted .rel-strip-row {
  border-color: #f43f5e;
  box-shadow: 0 0 30px rgba(244, 63, 94, 0.5);
}

/* Célula de Atributo Individual */
.rel-cell {
  position: relative;
  padding: 9px 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1.5px solid rgba(0, 240, 255, 0.2);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
  background: rgba(13, 20, 36, 0.6);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.rel-cell:last-child {
  border-right: none;
}

.rel-cell:hover {
  background: rgba(0, 240, 255, 0.15);
}

/* Célula PK (Chave Primária) */
.rel-cell.is-pk {
  background: rgba(234, 179, 8, 0.12);
}

.rel-cell.is-pk .cell-text {
  font-weight: 800;
  color: #fde047;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}

/* Célula FK (Chave Estrangeira) */
.rel-cell.is-fk {
  background: rgba(0, 240, 255, 0.12);
  cursor: pointer;
}

.rel-cell.is-fk .cell-text {
  font-weight: 700;
  color: var(--accent-light);
}

.rel-cell.fk-hovered {
  background: rgba(244, 63, 94, 0.35) !important;
  color: #ffffff;
  box-shadow: inset 0 0 12px rgba(244, 63, 94, 0.8);
}

/* Conectores de Origem e Destino nas Bordas Superior e Inferior */
.cell-bottom-anchor,
.cell-top-anchor {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  background: var(--accent);
  border-radius: 50%;
  opacity: 0.5;
  transition: opacity 0.2s ease, background-color 0.2s ease;
  pointer-events: none;
}

.cell-bottom-anchor {
  bottom: -3px;
}

.cell-top-anchor {
  top: -3px;
}

.rel-cell[data-has-top="false"] .cell-top-anchor {
  display: none; /* Desativa âncora superior quando o título da tabela está em cima */
}

.rel-cell:hover .cell-bottom-anchor,
.rel-cell:hover .cell-top-anchor,
.rel-cell.is-fk .cell-bottom-anchor,
.rel-cell.is-fk .cell-top-anchor,
.rel-cell.is-pk .cell-bottom-anchor,
.rel-cell.is-pk .cell-top-anchor {
  opacity: 1;
}

/* Setas de Referência FK em SVG */
.fk-arrow-path {
  fill: none;
  stroke: rgba(0, 240, 255, 0.75);
  stroke-width: 2.5px;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 0.25s ease, stroke-width 0.25s ease, filter 0.25s ease, opacity 0.3s ease;
  cursor: pointer;
}

.fk-arrow-path.highlighted {
  stroke-width: 4px !important;
  filter: drop-shadow(0 0 10px rgba(244, 63, 94, 0.9));
}

.fk-arrow-path.dimmed {
  opacity: 0.15;
}

.fk-arrow-path.selected-line {
  stroke-width: 4.5px !important;
  filter: drop-shadow(0 0 12px #00f0ff);
  stroke-dasharray: 6 3;
  animation: dashMove 0.8s linear infinite;
}

@keyframes dashMove {
  to {
    stroke-dashoffset: -18;
  }
}

/* ===== MODO MANUAL & LOGISIM CORREDOR DE CORES ===== */

/* Célula em Seleção para Conectar Linha */
.rel-cell.connecting-source {
  background: rgba(0, 240, 255, 0.35) !important;
  border-color: #00f0ff !important;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.8), inset 0 0 8px #00f0ff;
  animation: pulseConnect 1s infinite alternate;
}

@keyframes pulseConnect {
  from { box-shadow: 0 0 8px rgba(0, 240, 255, 0.5); }
  to { box-shadow: 0 0 20px rgba(0, 240, 255, 1); }
}

.manual-mode-active .rel-cell {
  cursor: crosshair;
}

.manual-mode-active .rel-cell:hover {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Swatches de Cores para Linhas estilo Logisim */
.color-swatch-picker {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(8, 13, 26, 0.9);
  padding: 4px 8px;
  border-radius: 20px;
  border: 1px solid rgba(0, 240, 255, 0.25);
}

.color-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-swatch:hover {
  transform: scale(1.25);
}

.color-swatch.active {
  border-color: #ffffff;
  transform: scale(1.3);
  box-shadow: 0 0 8px currentColor;
}

/* Ações no Título da Tabela em Modo Manual */
.table-actions-menu {
  display: none;
  margin-left: auto;
  gap: 4px;
}

.manual-mode-active .table-actions-menu {
  display: flex;
}

.tbl-action-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.tbl-action-btn:hover {
  color: var(--accent-light);
  background: rgba(0, 240, 255, 0.2);
}

.tbl-action-btn.delete:hover {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.2);
}

/* Popup Flutuante de Edição de Linha */
.line-edit-popover {
  position: absolute;
  z-index: 1000;
  background: rgba(10, 16, 32, 0.95);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.8), 0 0 20px rgba(0,240,255,0.15);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-family: var(--font-sans);
}

.line-edit-popover header {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Banner de Instrução em Modo Ponto a Ponto */
.freeline-drawing-banner {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  background: rgba(8, 13, 26, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-radius: 30px;
  padding: 8px 20px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-light);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8), 0 0 15px rgba(0, 240, 255, 0.2);
  animation: bannerSlideUp 0.3s ease-out;
}

@keyframes bannerSlideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.freeline-drawing-banner button {
  background: rgba(244, 63, 94, 0.25);
  border: 1px solid #f43f5e;
  color: #f43f5e;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}


