/**
 * Visual ASQL Editor v2 - CSS Styles
 * 
 * Two modes controlled by top-level class:
 * - .visual-style-text - Code-like, minimal, inline
 * - .visual-style-blocky - Visual blocks with backgrounds
 */

/* ============================================================================
   CSS Variables
   ============================================================================ */

:root {
  --asql-red: #c53030;
  --asql-string: #137333;
  --asql-number: #1967d2;
  --asql-variable: #333;
  --asql-function: #7c4dff;
  --asql-operator: #d63384;
  
  --bg-hover: rgba(0, 0, 0, 0.03);
  --border-color: #ddd;
  --border-radius: 4px;
}

/* ============================================================================
   BASE STYLES (shared between modes)
   ============================================================================ */

.visual-editor {
  padding: 12px;
  overflow-y: auto;
  overflow-x: visible;
  flex: 1;
  min-height: 0;
  font-family: 'Monaco', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
  font-size: 14px;
  line-height: 1.6;
}

/* Pipeline container */
.pipeline-block {
  margin-bottom: 16px;
  overflow: visible;
  position: relative;
}

.pipeline-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 4px 0;
}

.pipeline-name-label {
  font-size: 12px;
  color: #666;
}

.pipeline-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  padding: 2px 4px;
  font-family: inherit;
  font-size: 13px;
  color: var(--asql-variable);
  min-width: 150px;
}

.pipeline-name-input:focus {
  outline: none;
  border-bottom-color: var(--asql-red);
}

.pipeline-remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.pipeline-block:hover .pipeline-remove-btn {
  opacity: 1;
}

.pipeline-remove-btn:hover {
  color: #e53935;
}

/* Transforms list */
.transforms-list {
  min-height: 20px;
  overflow: visible;
}

/* Block base styles */
.block {
  display: flex;
  flex-direction: column;
  padding: 4px 8px 0 8px; /* No bottom padding - output columns go there */
  margin-bottom: 2px;
  position: relative;
  max-width: 100%;
}

.block:hover {
  background: var(--bg-hover);
}

.block-body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding-bottom: 4px; /* Space before output columns */
}

/* Drag handle - absolute top left, show on hover */
.block-drag-handle {
  position: absolute;
  top: 4px;
  left: 2px;
  cursor: grab;
  color: #ccc;
  font-size: 12px;
  padding: 2px;
  user-select: none;
  transition: opacity 0.15s, color 0.15s;
  opacity: 0;
}

.block:hover .block-drag-handle {
  opacity: 1;
}

.block-drag-handle:hover {
  color: #666;
}

.block-drag-handle:active {
  cursor: grabbing;
  color: #333;
}

/* Expression/list item drag handles - show on hover */
.expr-drag-handle {
  cursor: grab;
  color: #ccc;
  font-size: 10px;
  padding: 2px;
  user-select: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.expression-item:hover .expr-drag-handle,
.aggregate-item:hover .expr-drag-handle,
.order-item:hover .expr-drag-handle {
  opacity: 1;
}

.expr-drag-handle:active {
  cursor: grabbing;
}

/* Delete button - absolute top right, show on hover */
.block-delete,
.visual-style-blocky .block-delete {
  position: absolute !important;
  top: 4px !important;
  right: 4px !important;
  background: none !important;
  border: none !important;
  color: #ccc;
  cursor: pointer;
  padding: 2px 4px !important;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  border-radius: 0 !important;
}

.block:hover .block-delete,
.visual-style-blocky .block:hover .block-delete {
  opacity: 1;
}

.block-delete:hover,
.visual-style-blocky .block-delete:hover {
  color: #e53935;
  background: none !important;
}

/* SortableJS ghost states */
.block-ghost {
  opacity: 0.4;
  background: #f0f4f8;
}

.expr-ghost {
  opacity: 0.4;
}

/* Keywords (from, where, select, etc.) */
.value-operator {
  color: var(--asql-red);
  font-weight: 600;
  text-transform: lowercase;
}

/* Inline inputs */
.inline-input,
.inline-select {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  padding: 0 4px;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-variable);
  outline: none;
  field-sizing: content;
  min-width: 2ch;
}

.inline-input:focus,
.inline-select:focus {
  border-bottom-color: var(--asql-red);
  background: rgba(197, 48, 48, 0.03);
}

/* Select dropdowns */
.pipeline-from-select,
.add-step-dropdown {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  padding: 2px 4px;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-variable);
  cursor: pointer;
  outline: none;
}

.pipeline-from-select:focus,
.add-step-dropdown:focus {
  border-bottom-color: var(--asql-red);
}

/* Column autocomplete and column select */
.column-autocomplete,
.column-select {
  color: var(--asql-variable);
  field-sizing: content;
  min-width: 2ch;
}

.column-select {
  cursor: pointer;
}

.column-autocomplete::-webkit-calendar-picker-indicator {
  display: none !important;
}

/* Column input container with dropdown */
.column-input-container {
  position: relative;
  display: inline-block;
}

.column-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 10000;
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 180px;
  max-height: 250px;
  overflow-y: auto;
  margin-top: 4px;
}

.column-dropdown.visible {
  display: block;
}

/* Ensure blocks don't clip dropdown */
.block {
  overflow: visible !important;
}

.block-body {
  overflow: visible !important;
}

.expression-item,
.aggregate-item,
.order-item {
  overflow: visible;
}

.expression-list,
.aggregate-list,
.order-list {
  overflow: visible;
}

.expr-column-container {
  overflow: visible;
}

.column-dropdown-item {
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.column-dropdown-item:hover {
  background: #f0f4f8;
}

.column-dropdown-type {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
}

.column-dropdown-empty {
  padding: 8px 12px;
  color: #888;
  font-size: 12px;
  font-style: italic;
}

/* ============================================================================
   EXPRESSION COMPONENT
   ============================================================================ */

.expression {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  position: relative;
  flex-wrap: wrap;
  max-width: 100%;
}

.expr-node {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  position: relative;
}

.expr-column-container {
  display: inline;
}

.expr-column {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-variable);
  padding: 0 4px;
  field-sizing: content;
  min-width: 2ch;
}

.expr-column:focus {
  outline: none;
  border-bottom-color: var(--asql-variable);
}

.expr-literal {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  font-family: inherit;
  font-size: inherit;
  padding: 0 4px;
  field-sizing: content;
  min-width: 2ch;
}

.expr-literal-number {
  color: var(--asql-number);
}

.expr-literal-string {
  color: var(--asql-string);
}

.expr-literal-null {
  color: #888;
  font-style: italic;
}

.expr-literal:focus {
  outline: none;
  border-bottom-color: #666;
}

/* Function calls */
.expr-function-call {
  display: inline-flex;
  align-items: center;
}

.expr-func-select {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-function);
  cursor: pointer;
  padding: 0;
  field-sizing: content;
  min-width: 2ch;
}

.expr-func-select:focus {
  outline: none;
}

.expr-paren {
  color: #888;
}

.expr-args {
  display: inline-flex;
  align-items: center;
}

.expr-comma {
  color: #888;
  margin-right: 4px;
}

/* Binary operations */
.expr-binary {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.expr-op-select {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-operator);
  cursor: pointer;
  padding: 0 2px;
  field-sizing: content;
  min-width: 2ch;
}

.expr-op-select:focus {
  outline: none;
}

/* Unary operations */
.expr-unary {
  display: inline-flex;
  align-items: center;
}

.expr-unary-op {
  color: var(--asql-operator);
  margin-right: 4px;
}

/* Expand button (hover interaction) */
.expr-expand {
  display: none;
  background: #f0f4f8;
  border: 1px solid #ddd;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 0;
  margin-left: 4px;
}

.expr-node:hover > .expr-expand,
.expression.expr-hover .expr-expand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.expr-expand:hover {
  background: #e0e8f0;
  border-color: #ccc;
}

/* Remove button */
.expr-remove {
  background: none;
  border: none;
  color: transparent;
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
  transition: color 0.15s;
}

.expression:hover .expr-remove,
.expression-item:hover .expr-remove,
.aggregate-item:hover .expr-remove,
.order-item:hover .expr-remove {
  color: #aaa;
}

.expr-remove:hover {
  color: #e53935 !important;
}

/* Alias container */
.expr-alias-container {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.expr-as-toggle {
  color: #aaa;
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.expression:hover .expr-as-toggle,
.expression-item:hover .expr-as-toggle {
  opacity: 1;
}

.expr-alias-container.has-alias .expr-as-toggle {
  opacity: 1;
  color: var(--asql-red);
}

.expr-alias-input {
  display: none;
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-variable);
  padding: 0 4px;
  field-sizing: content;
  min-width: 2ch;
}

.expr-alias-container.has-alias .expr-alias-input {
  display: inline;
}

.expr-alias-input:focus {
  outline: none;
  border-bottom-color: var(--asql-variable);
}

/* Expression expand menu */
.expr-expand-menu {
  position: absolute;
  z-index: 1000;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 180px;
  max-height: 400px;
  overflow-y: auto;
}

.expr-menu-section {
  border-bottom: 1px solid #eee;
}

.expr-menu-section:last-child {
  border-bottom: none;
}

.expr-menu-section-header {
  padding: 8px 12px;
  font-weight: 500;
  cursor: pointer;
  color: #333;
}

.expr-menu-section-header:hover {
  background: #f8f8f8;
}

.expr-menu-submenu {
  padding-bottom: 4px;
}

.expr-menu-group-label {
  padding: 4px 12px;
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
}

.expr-menu-item {
  padding: 6px 16px;
  cursor: pointer;
  font-size: 13px;
}

.expr-menu-item:hover {
  background: #f0f4f8;
}

/* ============================================================================
   EXPRESSION LISTS
   ============================================================================ */

.expression-list,
.aggregate-list,
.order-list {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

/* Aggregate list gets parentheses wrapper in text mode */
.visual-style-text .aggregate-list::before {
  content: '(';
  color: #888;
}

.visual-style-text .aggregate-list::after {
  content: ')';
  color: #888;
}

.expression-item,
.aggregate-item,
.order-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 3px;
}

/* Text mode: no boxes around individual items */
.visual-style-text .expression-item,
.visual-style-text .aggregate-item,
.visual-style-text .order-item {
  padding: 0;
  background: transparent;
  border: none;
}

/* Text mode: each column/expression on its own line */
.visual-style-text .select-block .block-body,
.visual-style-text .order_by-block .block-body {
  flex-direction: column;
  align-items: flex-start;
}

.visual-style-text .expression-list,
.visual-style-text .order-list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding-left: 8px; /* Slight indent under keyword */
  width: 100%;
}

.visual-style-text .expression-item,
.visual-style-text .order-item {
  display: flex;
  align-items: center;
}

.visual-style-text .expression-item::after,
.visual-style-text .order-item::after {
  content: ',';
}

.visual-style-text .expression-item:last-of-type::after,
.visual-style-text .order-item:last-of-type::after {
  content: '';
}

/* Text mode: clean inline styling for aggregate inputs */
.visual-style-text .agg-function,
.visual-style-text .aggregate-item .column-autocomplete {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  border-radius: 0;
  padding: 0 4px;
}

.visual-style-text .aggregate-expr {
  background: transparent;
  border: none;
}

.expression-item::after,
.aggregate-item::after,
.order-item::after {
  content: ',';
  color: #666;
  margin-left: 2px;
}

.expression-item:last-of-type::after,
.aggregate-item:last-of-type::after,
.order-item:last-of-type::after {
  content: '';
}

/* Aggregate specific */
.aggregate-expr {
  display: inline-flex;
  align-items: center;
}

.agg-function {
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-function);
  cursor: pointer;
  field-sizing: content;
  min-width: 2ch;
}

.agg-paren {
  color: #888;
}

.agg-alias-container {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
}

.agg-as-toggle {
  color: #aaa;
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.aggregate-item:hover .agg-as-toggle {
  opacity: 1;
}

.aggregate-item.has-alias .agg-as-toggle {
  opacity: 1;
  color: var(--asql-red);
}

.agg-alias {
  display: none;
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  font-family: inherit;
  font-size: inherit;
  color: var(--asql-variable);
  padding: 0 4px;
  field-sizing: content;
  min-width: 2ch;
}

.aggregate-item.has-alias .agg-alias {
  display: inline;
}

/* Order specific */
.order-direction {
  background: #f0f4f8;
  border: 1px solid #ddd;
  border-radius: 3px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 12px;
}

.order-direction:hover {
  background: #e0e8f0;
}

.order-direction.desc {
  color: var(--asql-red);
}

/* Add buttons */
.list-add-btn,
.sortable-add-btn {
  background: none;
  border: 1px dashed #ccc;
  border-radius: 4px;
  color: #888;
  cursor: pointer;
  padding: 4px 12px;
  font-size: 12px;
  transition: all 0.15s;
}

.list-add-btn:hover,
.sortable-add-btn:hover {
  border-color: #888;
  color: #333;
  background: #f8f8f8;
}

/* ============================================================================
   OUTPUT COLUMNS
   ============================================================================ */

.output-columns {
  padding: 0;
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;
  font-size: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  /* Position at bottom of block, span full width */
  margin: 0;
  margin-top: auto;
  margin-left: -8px;
  margin-right: -8px;
  width: calc(100% + 16px);
  /* Hide scrollbar */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

.output-columns::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

.output-columns table {
  border-collapse: collapse;
  display: inline-flex;
}

.output-columns tr {
  display: inline-flex;
}

.output-columns th {
  padding: 6px 12px;
  font-weight: 500;
  color: var(--asql-variable);
  white-space: nowrap;
  text-align: left;
  border-right: 1px solid #e8e8e8;
  background: #f8f9fa;
}

.output-columns th:last-child {
  border-right: none;
}

.output-columns .col-type {
  font-weight: 400;
  color: #888;
  font-size: 10px;
  margin-left: 4px;
}

/* Hidden by default */
.output-columns {
  display: none;
}

.show-columns .output-columns {
  display: block;
}

/* ============================================================================
   SET OPERATIONS
   ============================================================================ */

.set-operation-selector {
  padding: 8px 0;
  text-align: center;
}

.set-op-select {
  background: #f0f4f8;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--asql-red);
  cursor: pointer;
}

.set-op-select:focus {
  outline: none;
  border-color: var(--asql-red);
}

.cte-indicator {
  padding: 8px 0;
  text-align: center;
  font-size: 12px;
  color: #888;
  font-style: italic;
}

/* ============================================================================
   ADD PIPELINE
   ============================================================================ */

.add-pipeline-container {
  padding: 12px 0;
}

.add-pipeline-btn {
  background: none;
  border: 1px dashed #ccc;
  border-radius: 4px;
  color: #888;
  cursor: pointer;
  padding: 8px 16px;
  font-size: 13px;
  width: 100%;
  transition: all 0.15s;
}

.add-pipeline-btn:hover {
  border-color: #888;
  color: #333;
  background: #f8f8f8;
}

/* ============================================================================
   ERROR STATES
   ============================================================================ */

.error-block {
  background: #fff0f0;
  border: 1px solid #f0d0d0;
}

.error {
  color: #c53030;
  font-size: 12px;
}

/* ============================================================================
   TEXT STYLE MODE (code-like, minimal)
   ============================================================================ */

.visual-style-text .visual-editor {
  background: #fafafa;
}

.visual-style-text .block {
  background: transparent;
}

/* ============================================================================
   BLOCKY STYLE MODE (visual blocks)
   ============================================================================ */

.visual-style-blocky .visual-editor {
  background: #f5f5f5;
}

.visual-style-blocky .pipeline-block {
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: visible;
}

.visual-style-blocky .block {
  background: #f8f9fa;
  border-radius: 6px;
  padding: 8px 24px 0 20px; /* No bottom padding - output columns go there */
  margin-bottom: 4px;
  border: 1px solid #eee;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

.visual-style-blocky .block-body {
  padding-bottom: 8px; /* Add padding here instead of block */
  overflow: visible;
}

.visual-style-blocky .block:hover {
  background: #f0f4f8;
  border-color: #ddd;
}

.visual-style-blocky .block-drag-handle {
  top: 8px;
  left: 6px;
}

.visual-style-blocky .block-delete {
  top: 6px !important;
  right: 6px !important;
}

.visual-style-blocky .from-block {
  background: #fff8f0;
  border-color: #f0e0d0;
}

.visual-style-blocky .value-operator {
  /* Override v1 CSS - just red text, no background box */
  display: inline;
  background: none;
  border: none;
  padding: 0;
  margin-right: 4px;
  text-transform: lowercase;
  font-size: inherit;
  letter-spacing: normal;
}

.visual-style-blocky .inline-input,
.visual-style-blocky .inline-select,
.visual-style-blocky .column-autocomplete,
.visual-style-blocky .expr-column {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 4px 8px;
}

.visual-style-blocky .inline-input:focus,
.visual-style-blocky .inline-select:focus,
.visual-style-blocky .column-autocomplete:focus,
.visual-style-blocky .expr-column:focus {
  border-color: var(--asql-variable);
  box-shadow: 0 0 0 2px rgba(51, 51, 51, 0.1);
}

/* Keep operator selects compact in blocky mode */
.visual-style-blocky .expr-op-select {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 2px 4px;
  min-width: 0;
}

.visual-style-blocky .expression-item,
.visual-style-blocky .order-item {
  background: #f8f9fa;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 4px 8px;
}

/* Aggregate items - no individual boxes, just clean inline */
.visual-style-blocky .aggregate-item {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 4px 0;
}

/* Aggregate inputs in blocky mode - transparent to blend with container */
.visual-style-blocky .agg-function {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  border-radius: 0;
  padding: 0 4px;
}

.visual-style-blocky .aggregate-item .column-autocomplete {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  border-radius: 0;
  padding: 0 4px;
}

.visual-style-blocky .agg-alias {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #ccc;
  border-radius: 0;
  padding: 0 4px;
}

/* Aggregate list container - left border to separate from dimensions */
.visual-style-blocky .aggregate-list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  padding-left: 16px;
  border-left: 3px solid #ddd;
  margin-left: 0;
  width: 100%;
}

.visual-style-blocky .expression-item::after,
.visual-style-blocky .aggregate-item::after,
.visual-style-blocky .order-item::after {
  content: '';
}

.visual-style-blocky .output-columns {
  background: white;
  border-radius: 0 0 5px 5px;
  border-top: 1px solid #e0e0e0;
  padding: 0;
  margin: 0;
  margin-left: -20px; /* Counteract block padding */
  margin-right: -24px;
  width: calc(100% + 44px);
  overflow-x: auto;
  overflow-y: hidden;
  /* Hide scrollbar */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.visual-style-blocky .output-columns::-webkit-scrollbar {
  display: none;
}

.visual-style-blocky .output-columns table {
  display: inline-flex;
  min-width: 100%;
}

.visual-style-blocky .output-columns tr {
  display: inline-flex;
}

.visual-style-blocky .output-columns th {
  background: white;
  border: none;
  border-right: 1px solid #eee;
  border-radius: 0;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  color: #555;
  font-size: 12px;
}

.visual-style-blocky .output-columns th:last-child {
  border-right: none;
}

.visual-style-blocky .add-step-dropdown {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px 12px;
  margin-top: 8px;
}

.visual-style-blocky .set-op-select {
  background: white;
}

.visual-style-blocky .list-add-btn,
.visual-style-blocky .sortable-add-btn {
  background: white;
}

/* ============================================================================
   SORTABLE COMPONENT
   ============================================================================ */

.sortable-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sortable-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sortable-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
}

.sortable-handle {
  cursor: grab;
  color: #ccc;
  font-size: 10px;
  user-select: none;
}

.sortable-handle:active {
  cursor: grabbing;
}

.sortable-content {
  flex: 1;
}

.sortable-remove {
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
}

.sortable-remove:hover {
  color: #e53935;
}

.sortable-ghost {
  opacity: 0.4;
  background: #f0f4f8;
}

.sortable-chosen {
  background: #f0f8ff;
}

/* ============================================================================
   PIPES STYLE MODE (Yahoo Pipes-like node graph)
   ============================================================================ */

.visual-style-pipes .visual-editor {
  background: #f0f2f5;
  min-height: 400px;
  position: relative;
  padding: 24px;
}

/* Pipes canvas container for SVG wires */
.pipes-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.pipes-canvas svg {
  width: 100%;
  height: 100%;
}

/* Connector wires between nodes */
.pipe-wire {
  fill: none;
  stroke: #90a4ae;
  stroke-width: 3;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
  transition: stroke 0.2s, stroke-width 0.2s;
}

.pipe-wire:hover {
  stroke: #607d8b;
  stroke-width: 4;
}

.pipe-wire.highlighted {
  stroke: var(--asql-red);
  stroke-width: 4;
  filter: drop-shadow(0 0 4px rgba(197, 48, 48, 0.4));
}

/* Nodes container - horizontal flow layout */
.pipes-nodes-container {
  display: flex;
  flex-wrap: wrap;
  gap: 32px;
  position: relative;
  z-index: 1;
  align-items: flex-start;
}

/* CTE connection lines SVG overlay */
.cte-connections-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: visible;
}

/* Individual pipeline/CTE node */
.pipe-node {
  background: white;
  border: 1px solid #d0d7de;
  border-radius: 12px;
  min-width: 280px;
  max-width: 380px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08),
              0 1px 2px rgba(0, 0, 0, 0.04);
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
}

.pipe-node:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12),
              0 2px 4px rgba(0, 0, 0, 0.08);
  border-color: var(--asql-red);
}

/* Node header (CTE name / table source) */
.pipe-node-header {
  background: linear-gradient(90deg, #f8f9fa 0%, #f0f2f5 100%);
  padding: 10px 14px;
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid #e1e4e8;
}

.pipe-node-icon {
  width: 24px;
  height: 24px;
  background: linear-gradient(135deg, var(--asql-red) 0%, #a02828 100%);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: white;
  font-weight: bold;
  box-shadow: 0 2px 4px rgba(197, 48, 48, 0.3);
}

.pipe-node-title {
  color: #24292f;
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipe-node-type {
  color: #656d76;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Connection ports on nodes */
.pipe-port {
  width: 14px;
  height: 14px;
  background: #90a4ae;
  border: 2px solid white;
  border-radius: 50%;
  position: absolute;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  z-index: 2;
}

.pipe-port:hover {
  transform: scale(1.3);
  background: var(--asql-red);
  box-shadow: 0 2px 6px rgba(197, 48, 48, 0.4);
}

.pipe-port-in {
  left: -7px;
  top: 50%;
  transform: translateY(-50%);
}

.pipe-port-out {
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
}

.pipe-port-in:hover,
.pipe-port-out:hover {
  transform: translateY(-50%) scale(1.3);
}

/* Node body content */
.pipe-node-body {
  padding: 12px 14px;
  max-height: 300px;
  overflow-y: auto;
}

/* Transform step within node */
.pipe-step {
  background: #f8f9fa;
  border: 1px solid #e1e4e8;
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 8px;
  transition: background 0.15s, border-color 0.15s;
}

.pipe-step:last-child {
  margin-bottom: 0;
}

.pipe-step:hover {
  background: #f0f4f8;
  border-color: #d0d7de;
}

/* Step header with type badge */
.pipe-step-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.pipe-step-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Color coding for different transform types */
.pipe-step-type.where {
  background: rgba(244, 67, 54, 0.2);
  color: #ef9a9a;
  border: 1px solid rgba(244, 67, 54, 0.3);
}

.pipe-step-type.select {
  background: rgba(76, 175, 80, 0.2);
  color: #a5d6a7;
  border: 1px solid rgba(76, 175, 80, 0.3);
}

.pipe-step-type.join {
  background: rgba(156, 39, 176, 0.2);
  color: #ce93d8;
  border: 1px solid rgba(156, 39, 176, 0.3);
}

.pipe-step-type.group_by {
  background: rgba(255, 152, 0, 0.2);
  color: #ffcc80;
  border: 1px solid rgba(255, 152, 0, 0.3);
}

.pipe-step-type.order_by {
  background: rgba(33, 150, 243, 0.2);
  color: #90caf9;
  border: 1px solid rgba(33, 150, 243, 0.3);
}

.pipe-step-type.limit {
  background: rgba(121, 85, 72, 0.2);
  color: #bcaaa4;
  border: 1px solid rgba(121, 85, 72, 0.3);
}

.pipe-step-type.extend {
  background: rgba(0, 188, 212, 0.2);
  color: #80deea;
  border: 1px solid rgba(0, 188, 212, 0.3);
}

/* Step content/expression */
.pipe-step-content {
  color: #24292f;
  font-size: 12px;
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  word-break: break-word;
  line-height: 1.5;
}

.pipe-step-content .value-operator {
  color: var(--asql-red);
}

.pipe-step-content .value-column {
  color: var(--asql-variable);
}

.pipe-step-content .value-function {
  color: var(--asql-function);
}

.pipe-step-content .value-string {
  color: var(--asql-string);
}

.pipe-step-content .value-number {
  color: var(--asql-number);
}

/* Node footer with output columns */
.pipe-node-footer {
  background: #f8f9fa;
  border-top: 1px solid #e1e4e8;
  padding: 8px 12px;
  border-radius: 0 0 10px 10px;
}

.pipe-node-footer .output-columns {
  display: block;
  background: transparent;
  border: none;
  margin: 0;
  padding: 0;
}

.pipe-node-footer .output-columns table {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pipe-node-footer .output-columns th {
  background: white;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 10px;
  color: #24292f;
  font-weight: 500;
}

.pipe-node-footer .output-columns .col-type {
  color: #656d76;
  font-size: 9px;
}

/* Set operation connector (UNION, etc.) */
.pipe-set-operation {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
}

.pipe-set-op-badge {
  background: linear-gradient(135deg, var(--asql-red) 0%, #a02828 100%);
  color: white;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 2px 6px rgba(197, 48, 48, 0.3);
}

/* Source table indicator */
.pipe-source-badge {
  background: linear-gradient(135deg, #4caf50 0%, #388e3c 100%);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  margin-left: auto;
}

/* Reference to another CTE */
.pipe-ref-badge {
  background: linear-gradient(135deg, #7c4dff 0%, #651fff 100%);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s;
}

.pipe-ref-badge:hover {
  transform: scale(1.05);
}

/* Empty state */
.pipes-empty-state {
  color: #656d76;
  text-align: center;
  padding: 40px;
  font-size: 14px;
}

/* Override base styles for pipes mode - don't hide, re-render as nodes */
.visual-style-pipes .pipeline-block {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
}

/* Hide standard blocks only when pipes-nodes-container exists (pipes rendering active) */
.visual-style-pipes .pipes-nodes-container ~ .block,
.visual-style-pipes .pipes-nodes-container ~ .transforms-list,
.visual-style-pipes .pipes-nodes-container ~ .add-step-dropdown {
  display: none;
}

/* Hide from-block when in pipes mode - it's shown in the pipe node header */
.visual-style-pipes .input-pipeline > .from-block {
  display: none;
}

/* Scrollbar styling for pipes mode */
.visual-style-pipes .pipe-node-body::-webkit-scrollbar {
  width: 6px;
}

.visual-style-pipes .pipe-node-body::-webkit-scrollbar-track {
  background: #f0f2f5;
  border-radius: 3px;
}

.visual-style-pipes .pipe-node-body::-webkit-scrollbar-thumb {
  background: #c1c4c9;
  border-radius: 3px;
}

.visual-style-pipes .pipe-node-body::-webkit-scrollbar-thumb:hover {
  background: #a0a4a9;
}
