/* Relational Data Generator - Visual Builder */
.rd-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Header */
.rd-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.rd-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rd-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.rd-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

/* Stats badges */
.rd-stats {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.rd-stat {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  white-space: nowrap;
}

.rd-stat-accent {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* Tabs */
.rd-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
  overflow-x: auto;
}

.rd-tab {
  padding: 8px 18px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: var(--font-sans);
}

.rd-tab:hover {
  color: var(--text-secondary);
  background: var(--surface-3);
}

.rd-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Main content area */
.rd-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* Toolbar row */
.rd-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.rd-toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.rd-toolbar label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rd-toolbar select {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-sans);
  cursor: pointer;
  outline: none;
}

.rd-toolbar select:focus {
  border-color: var(--accent);
}

/* Visual Builder Canvas */
.rd-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: auto;
  background: var(--bg);
  min-height: 0;
}

.rd-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
  width: 2400px;
  height: 1400px;
}

.rd-canvas-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(circle, var(--border-light) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  opacity: 0.5;
}

/* SVG relationship lines */
.rd-svg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.rd-rel-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 6,4;
  pointer-events: stroke;
  cursor: pointer;
}

.rd-rel-line:hover {
  stroke-width: 3;
  stroke: var(--red);
}

.rd-rel-label {
  font-size: 10px;
  fill: var(--text-muted);
  font-family: var(--font-mono);
  pointer-events: none;
}

.rd-drag-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 4,4;
  opacity: 0.6;
  pointer-events: none;
}

/* Table Node Cards */
.rd-table-node {
  position: absolute;
  min-width: 220px;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 2;
  user-select: none;
  transition: box-shadow 0.15s;
}

.rd-table-node:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.rd-table-node.rd-dragging {
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  opacity: 0.92;
}

.rd-table-node.rd-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

.rd-node-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: grab;
  gap: 8px;
}

.rd-node-header:active {
  cursor: grabbing;
}

.rd-node-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  min-width: 0;
}

.rd-node-title-input {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  width: 100%;
  max-width: 140px;
  outline: none;
  font-family: var(--font-sans);
}

.rd-node-title-input:focus {
  border-color: var(--accent);
}

.rd-node-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 8px;
  background: var(--accent-light);
  color: var(--accent);
  white-space: nowrap;
}

.rd-node-delete {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.15s;
  flex-shrink: 0;
  font-family: var(--font-sans);
  padding: 0;
  line-height: 1;
}

.rd-node-delete:hover {
  background: var(--red);
  color: #fff;
}

/* Row count */
.rd-node-rowcount {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.rd-node-rowcount label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.rd-node-rowcount input {
  width: 70px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
  text-align: right;
}

.rd-node-rowcount input:focus {
  border-color: var(--accent);
}

/* Field list */
.rd-field-list {
  padding: 4px 0;
  max-height: 260px;
  overflow-y: auto;
}

.rd-field-item {
  display: flex;
  align-items: center;
  padding: 4px 8px 4px 4px;
  gap: 4px;
  font-size: 12px;
  transition: background 0.1s;
}

.rd-field-item:hover {
  background: var(--surface-2);
}

/* Connection handle */
.rd-field-handle {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: crosshair;
  flex-shrink: 0;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rd-field-handle:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: scale(1.2);
}

.rd-field-handle.rd-fk-handle {
  border-color: var(--accent);
  background: var(--accent);
}

.rd-field-handle.rd-fk-handle::after {
  content: '';
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #fff;
}

.rd-field-name {
  flex: 1;
  min-width: 0;
}

.rd-field-name input {
  width: 100%;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
}

.rd-field-name input:focus {
  border-color: var(--accent);
  background: var(--bg);
}

.rd-field-type {
  flex-shrink: 0;
}

.rd-field-type select {
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  outline: none;
}

.rd-field-type select:focus {
  border-color: var(--accent);
  background: var(--bg);
}

.rd-field-fk-info {
  font-size: 10px;
  color: var(--accent);
  white-space: nowrap;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rd-field-remove {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s;
  flex-shrink: 0;
  padding: 0;
  font-family: var(--font-sans);
  line-height: 1;
  opacity: 0;
}

.rd-field-item:hover .rd-field-remove {
  opacity: 1;
}

.rd-field-remove:hover {
  background: var(--red);
  color: #fff;
}

/* Add field button */
.rd-add-field {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  border-top: 1px solid var(--border);
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.rd-add-field:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* Output panel */
.rd-output-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.rd-output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.rd-output-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rd-output-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rd-format-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-3);
  border-radius: 6px;
  padding: 2px;
}

.rd-format-tab {
  padding: 4px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.rd-format-tab:hover {
  color: var(--text);
}

.rd-format-tab.active {
  background: var(--accent);
  color: #080b14;
}

.rd-table-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 2px;
}

.rd-table-tab {
  padding: 3px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  white-space: nowrap;
  font-family: var(--font-mono);
}

.rd-table-tab:hover {
  border-color: var(--accent);
}

.rd-table-tab.active {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

.rd-output-scroll {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  min-height: 0;
}

.rd-output-code {
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  margin: 0;
  min-height: 100%;
}

.rd-output-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 10px;
  padding: 40px;
  text-align: center;
}

.rd-output-empty svg {
  opacity: 0.3;
  margin-bottom: 4px;
}

.rd-output-empty p {
  font-size: 14px;
}

.rd-output-empty span {
  font-size: 12px;
  opacity: 0.6;
}

/* Progress bar */
.rd-progress-wrap {
  display: none;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.rd-progress-wrap.active {
  display: block;
}

.rd-progress-bar {
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}

.rd-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.2s;
  width: 0%;
}

.rd-progress-text {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

/* Preset button group */
.rd-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.rd-preset-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.rd-preset-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

/* Mobile list-based editor */
.rd-mobile-editor {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 12px;
  gap: 12px;
}

.rd-mobile-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.rd-mobile-table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.rd-mobile-table-header input {
  flex: 1;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  font-family: var(--font-sans);
  outline: none;
}

.rd-mobile-table-header input:focus {
  border-color: var(--accent);
}

.rd-mobile-row-count {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.rd-mobile-row-count label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.rd-mobile-row-count input {
  width: 80px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
}

.rd-mobile-field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-light);
}

.rd-mobile-field:last-of-type {
  border-bottom: none;
}

.rd-mobile-field input {
  flex: 1;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
  min-width: 0;
}

.rd-mobile-field select {
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 11px;
  font-family: var(--font-mono);
  outline: none;
}

.rd-mobile-field button {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  font-size: 12px;
  flex-shrink: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
}

.rd-mobile-field button:hover {
  background: var(--red);
  color: #fff;
}

.rd-mobile-add-field {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
}

.rd-mobile-add-field:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.rd-mobile-fk-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border-light);
}

.rd-mobile-fk-row label {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}

.rd-mobile-fk-row select {
  flex: 1;
  padding: 3px 6px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 11px;
  font-family: var(--font-mono);
  outline: none;
}

/* Status bar */
.rd-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  gap: 8px;
  flex-wrap: wrap;
}

/* Responsive: Mobile */
@media (max-width: 768px) {
  .rd-header {
    padding: 8px 12px;
  }

  .rd-title {
    font-size: 13px;
  }

  .rd-stats {
    display: none;
  }

  .rd-canvas-wrap {
    display: none !important;
  }

  .rd-mobile-editor {
    display: flex !important;
  }

  .rd-toolbar {
    padding: 6px 10px;
  }

  .rd-output-header {
    padding: 6px 10px;
  }

  .rd-presets {
    flex-wrap: wrap;
  }

  .rd-header-right {
    gap: 4px;
  }

  .rd-format-tabs {
    overflow-x: auto;
  }
}

/* Scrollbar styling for the canvas */
.rd-canvas-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.rd-canvas-wrap::-webkit-scrollbar-track {
  background: var(--surface-2);
}

.rd-canvas-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.rd-canvas-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.rd-field-list::-webkit-scrollbar {
  width: 4px;
}

.rd-field-list::-webkit-scrollbar-track {
  background: transparent;
}

.rd-field-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Enum values inline display */
.rd-field-enum-hint {
  font-size: 9px;
  color: var(--orange);
  max-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
