/* ===== algebra.css — Estilos específicos de la vista Álgebra Relacional ===== */

/* Layout: 3 columnas (panel DB + workspace + snippets) */
body.design-index3 .algebra-layout {
  grid-template-columns: var(--db-panel-width) minmax(430px, 1fr) 318px;
  gap: 8px;
  padding: 0 12px 0 0;
  min-height: calc(100dvh - 78px);
  height: calc(100dvh - 78px);
  align-items: stretch;
  overflow: hidden;
  transition: grid-template-columns 180ms ease;
}

/* Workspace */
body.design-index3 .algebra-workspace {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 0 12px;
  min-height: 0;
  min-width: 0;
  overflow: visible;
  max-height: none;
}

body.design-index3 .algebra-workspace > * {
  width: 100%;
  flex-shrink: 0;
}

/* ===== Toolbar ===== */
.algebra-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.algebra-direction-toggle {
  display: flex;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.direction-button {
  border: 0;
  background: var(--surface-2);
  color: var(--muted);
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  transition: background 160ms ease, color 160ms ease;
}

.direction-button.is-active {
  background: var(--green);
  color: #ffffff;
}

.direction-button:hover:not(.is-active) {
  background: var(--surface-3);
  color: var(--text);
}

/* ===== Barra de operadores ===== */
.operator-bar {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--algebra) 22%, var(--line));
  border-radius: 0;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.operator-hint {
  font-size: 10px;
  color: var(--muted);
  font-style: italic;
}

.operator-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.op-button {
  width: 36px;
  height: 36px;
  border: 1px solid color-mix(in srgb, var(--algebra) 30%, var(--line));
  border-radius: 5px;
  background: color-mix(in srgb, var(--algebra) 8%, var(--surface));
  color: var(--algebra);
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 140ms ease, border-color 140ms ease, transform 120ms ease;
}

.op-button:hover {
  background: color-mix(in srgb, var(--algebra) 18%, var(--surface));
  border-color: var(--algebra);
  transform: translateY(-1px);
}

.op-button:active {
  transform: translateY(0);
}

body.design-index3.theme-dark .op-button {
  background: color-mix(in srgb, var(--algebra) 12%, var(--surface-2));
  border-color: color-mix(in srgb, var(--algebra) 40%, var(--line));
}

body.design-index3.theme-dark .op-button:hover {
  background: color-mix(in srgb, var(--algebra) 25%, var(--surface-2));
}

/* ===== Editor de expresión ===== */
.algebra-editor-shell {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--algebra) 22%, var(--line));
  border-radius: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.algebra-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  padding: 9px 12px 4px;
  background: transparent;
}

#sqlEditorSection .algebra-editor-header {
  border-bottom: 1px solid var(--line);
}

.editor-label {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.ar-editor-controls {
  position: absolute;
  right: 8px;
  top: 38px;
  z-index: 5;
  display: flex;
  gap: 0;
}

.ar-editor-canvas {
  position: relative;
  min-height: 120px;
  height: 160px;
  overflow: hidden;
}

.ar-highlight,
#algebraEditor {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 12px 60px 12px 14px;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  box-sizing: border-box;
}

.ar-highlight {
  z-index: 3;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  pointer-events: none;
  user-select: none;
}

#algebraEditor {
  z-index: 2;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--sql);
  resize: none;
  background: var(--surface);
}

#algebraEditor::placeholder {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  opacity: 0.7;
  font-family: var(--font-ui);
  font-size: 14px;
}

.ar-highlight .hl-operator {
  color: var(--algebra);
  -webkit-text-fill-color: currentColor;
  font-weight: bold;
}

.ar-highlight .hl-operator-info {
  color: var(--green);
  -webkit-text-fill-color: currentColor;
  font-weight: bold;
  cursor: default;
}

.ar-highlight .hl-placeholder {
  border-radius: 3px;
  background: color-mix(in srgb, var(--yellow) 38%, transparent);
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  cursor: pointer;
  animation: placeholderPulse 1.05s ease-in-out infinite;
}

.ar-highlight .hl-subscript {
  color: var(--muted);
  -webkit-text-fill-color: currentColor;
}

.ar-highlight .hl-table {
  color: var(--sql);
  -webkit-text-fill-color: currentColor;
}

/* Autocompletado */
.autocomplete-panel {
  position: fixed;
  z-index: 50;
  width: 320px;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid color-mix(in srgb, var(--algebra) 72%, var(--line));
  background: var(--surface);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--text) 18%, transparent);
  font-family: var(--font-mono);
  font-size: 12px;
}

.autocomplete-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.autocomplete-list li {
  display: grid;
  grid-template-columns: minmax(95px, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  padding: 2px 7px;
  cursor: pointer;
}

.autocomplete-list li:hover,
.autocomplete-list li.is-selected {
  background: var(--algebra);
  color: #fff;
}

.autocomplete-list .ac-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.autocomplete-list .ac-kind {
  color: var(--muted);
  font-size: 10px;
  text-align: right;
  text-transform: uppercase;
}

.autocomplete-list li:hover .ac-kind,
.autocomplete-list li.is-selected .ac-kind {
  color: color-mix(in srgb, #fff 82%, var(--algebra));
}

/* ===== Panel de resultado SQL ===== */
.translation-result,
.execution-result,
.equivalence-panel {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--algebra) 22%, var(--line));
  border-radius: 0;
  overflow: hidden;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
  padding: 9px 12px 4px;
  background: transparent;
}

.result-label {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.translation-output {
  padding: 10px 14px;
  overflow-x: auto;
}

.sql-output {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.sql-output code {
  color: inherit;
}

/* Ejecución */
.execution-output {
  padding: 10px 14px;
  max-height: 300px;
  overflow: auto;
}

/* Equivalencia didáctica */
.equivalence-content {
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
}

.equivalence-content .step {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.equivalence-content .step-number {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--algebra);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Tooltip de operador ===== */
.operator-tooltip {
  position: fixed;
  z-index: 1000;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--sql);
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.4;
  max-width: 280px;
  pointer-events: auto;
}

.tooltip-header {
  font-size: 11px;
  font-weight: 700;
  color: var(--sql);
  margin-bottom: 4px;
}

.tooltip-template {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
  background: var(--surface-2);
  padding: 4px 8px;
}

.tooltip-insert {
  font-size: 10px;
}

/* ===== Editor SQL en modo SQL→AR (hereda todo de index3.css .editor-shell) ===== */

/* Tooltip didáctico override para algebra */
#arDidacticTooltip {
  border: 1px solid var(--sql);
}

/* Snippets AR — hereda estilos de .snippets-panel de index3.css */
body.design-index3 .algebra-layout .snippets-panel {
  border-color: color-mix(in srgb, var(--algebra) 22%, var(--line));
  height: calc(100dvh - 136px);
  max-height: calc(100dvh - 136px);
  min-height: 0;
  overflow-y: auto;
}

body.design-index3 .algebra-layout #arSystemSnippets {
  min-height: 0;
  overflow: initial;
}

body.design-index3 .algebra-layout .snippet-card {
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

body.design-index3 .algebra-layout .snippet-card header {
  padding: 4px 12px 5px;
}

body.design-index3 .algebra-layout .snippet-card h3 {
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  margin: 0;
}

body.design-index3 .algebra-layout .snippet-actions {
  display: flex;
  gap: 8px;
  padding: 0 12px 9px;
}

body.design-index3 .algebra-layout .editor-shell {
  border: 1px solid color-mix(in srgb, var(--algebra) 22%, var(--line));
  box-shadow: none;
  clip-path: none;
  border-radius: 0;
  grid-template-rows: 38px 28px minmax(0, 1fr) 28px;
}

body.design-index3 .algebra-layout .editor-body {
  grid-template-columns: 58px minmax(0, 1fr) 14px;
  border-left: 0;
}

body.design-index3 .algebra-layout .editor-controls {
  border-left: 0;
}

body.design-index3 .algebra-layout #sqlEditor {
  overflow: hidden;
}

body.design-index3 .algebra-layout #sqlEditor::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

body.design-index3 .algebra-layout .algebra-sql-scroll-actions {
  border-left: 0;
}

body.design-index3 .algebra-layout .line-number-text {
  width: 100%;
  text-align: right;
  padding-right: 2px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 1100;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  min-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  text-align: center;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

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