/* ==========================================================================
   IPTV n8n Studio - Custom Visual Workflow Builder Stylesheet
   Tailored for IPTV, Xtream-Masters, Kommo CRM & Supabase
   ========================================================================== */

:root {
  --n8n-bg-dark: #0f1422;
  --n8n-canvas-bg: #141a29;
  --n8n-panel-bg: #1e2538;
  --n8n-card-bg: #1e2538;
  --n8n-card-hover: #262e45;
  --n8n-card-selected: #2d3856;
  
  --n8n-border: rgba(255, 255, 255, 0.1);
  --n8n-border-active: #6366f1;
  --n8n-border-selected: #00d4b2;
  
  --n8n-text: #f1f5f9;
  --n8n-text-muted: #94a3b8;
  --n8n-text-dim: #64748b;
  
  --n8n-primary: #ff6d5a; /* n8n vibrant accent / IPTV Coral */
  --n8n-primary-hover: #ff523b;
  --n8n-cyan: #00d4b2;
  --n8n-indigo: #6366f1;
  --n8n-purple: #a855f7;
  --n8n-amber: #f59e0b;
  --n8n-emerald: #10b981;
  --n8n-rose: #f43f5e;
  
  --n8n-wire: #94a3b8;
  --n8n-wire-active: #00d4b2;
  --n8n-wire-selected: #ff6d5a;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body.n8n-studio-body {
  background-color: var(--n8n-bg-dark);
  color: var(--n8n-text);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

/* Studio Layout Header */
.n8n-header {
  height: 56px;
  background: var(--n8n-panel-bg);
  border-bottom: 1px solid var(--n8n-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px;
  position: relative;
  z-index: 100;
}

.n8n-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.n8n-logo-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--n8n-primary), #ff8f70);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  box-shadow: 0 0 15px rgba(255, 109, 90, 0.3);
}

.n8n-title-group h2 {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

.n8n-title-group span {
  font-size: 11px;
  color: var(--n8n-text-muted);
}

.n8n-workflow-select {
  background: var(--n8n-canvas-bg);
  border: 1px solid var(--n8n-border);
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.n8n-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.n8n-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--n8n-border);
  color: var(--n8n-text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.n8n-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.n8n-btn-primary {
  background: var(--n8n-primary);
  border-color: var(--n8n-primary);
  color: #fff;
}

.n8n-btn-primary:hover {
  background: var(--n8n-primary-hover);
  box-shadow: 0 0 15px rgba(255, 109, 90, 0.4);
}

.n8n-btn-execute {
  background: var(--n8n-cyan);
  border-color: var(--n8n-cyan);
  color: #0b1120;
  font-weight: 700;
}

.n8n-btn-execute:hover {
  box-shadow: 0 0 15px rgba(0, 212, 178, 0.4);
}

/* Studio Canvas Area */
.n8n-canvas-wrapper {
  position: relative;
  width: 100vw;
  height: calc(100vh - 56px);
  background-color: var(--n8n-canvas-bg);
  background-image: radial-gradient(rgba(255, 255, 255, 0.08) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
  overflow: hidden;
  cursor: grab;
}

.n8n-canvas-wrapper.grabbing {
  cursor: grabbing;
}

.n8n-canvas-transform-layer {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  width: 10000px;
  height: 10000px;
  pointer-events: none;
}

.n8n-svg-wire-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  z-index: 1;
}

.n8n-nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  z-index: 2;
}

/* Wires / Connections */
.n8n-wire-bg {
  stroke: transparent;
  stroke-width: 18px;
  fill: none;
  cursor: pointer;
}

.n8n-wire-line {
  stroke: var(--n8n-wire);
  stroke-width: 3px;
  fill: none;
  transition: stroke 0.2s;
}

.n8n-wire-line.active {
  stroke: var(--n8n-cyan);
  stroke-dasharray: 6;
  animation: n8nDash 25s linear infinite;
}

.n8n-wire-bg:hover + .n8n-wire-line {
  stroke: var(--n8n-primary);
  stroke-width: 4px;
}

@keyframes n8nDash {
  to { stroke-dashoffset: -1000; }
}

/* Authentic n8n Node Card */
.n8n-node {
  position: absolute;
  width: 220px;
  background: var(--n8n-card-bg);
  border: 1px solid var(--n8n-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s, border-color 0.2s;
  pointer-events: auto;
}

.n8n-node:hover {
  border-color: rgba(255, 255, 255, 0.25);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
}

.n8n-node.selected {
  border-color: var(--n8n-border-selected);
  box-shadow: 0 0 0 2px rgba(0, 212, 178, 0.3), 0 12px 30px rgba(0, 0, 0, 0.6);
}

.n8n-node.running {
  border-color: var(--n8n-cyan);
  animation: n8nPulse 1.2s infinite;
}

@keyframes n8nPulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 212, 178, 0.6); }
  70% { box-shadow: 0 0 0 12px rgba(0, 212, 178, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 212, 178, 0); }
}

.n8n-node-header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top-left-radius: var(--radius-md);
  border-top-right-radius: var(--radius-md);
  border-top: 3px solid var(--n8n-primary);
}

.n8n-node-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.n8n-node-info {
  flex: 1;
  overflow: hidden;
}

.n8n-node-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.n8n-node-type {
  font-size: 11px;
  color: var(--n8n-text-dim);
  white-space: nowrap;
}

.n8n-node-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--n8n-emerald);
  box-shadow: 0 0 6px var(--n8n-emerald);
}

.n8n-node-footer {
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.15);
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
  font-size: 10.5px;
  color: var(--n8n-text-muted);
  display: flex;
  justify-content: space-between;
}

/* Ports / Handles */
.n8n-port {
  width: 12px;
  height: 12px;
  background: var(--n8n-canvas-bg);
  border: 2.5px solid var(--n8n-wire);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  cursor: crosshair;
  transition: all 0.15s;
}

.n8n-port:hover {
  background: var(--n8n-cyan);
  border-color: #fff;
  transform: translateY(-50%) scale(1.3);
}

.n8n-port-in { left: -6px; }
.n8n-port-out { right: -6px; }

/* Floating Controls (Zoom / Add Node) */
.n8n-canvas-controls {
  position: fixed;
  bottom: 24px;
  left: 24px;
  background: var(--n8n-panel-bg);
  border: 1px solid var(--n8n-border);
  border-radius: var(--radius-md);
  padding: 4px;
  display: flex;
  gap: 4px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.n8n-zoom-btn {
  background: transparent;
  border: none;
  color: var(--n8n-text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.n8n-zoom-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.n8n-fab-add-node {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--n8n-primary);
  color: #fff;
  border: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(255, 109, 90, 0.4);
  transition: transform 0.2s, background 0.2s;
  z-index: 100;
}

.n8n-fab-add-node:hover {
  transform: scale(1.08);
  background: var(--n8n-primary-hover);
}

/* ==========================================================================
   Add Node Palette Modal (Specific to IPTV, Xtream, Kommo, Supabase)
   ========================================================================== */
.n8n-palette-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: 90%;
  max-width: 580px;
  background: #182033;
  border: 1px solid var(--n8n-border-active);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8);
  z-index: 1000;
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s, opacity 0.2s;
  opacity: 0;
}

.n8n-palette-modal.active {
  display: flex;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.n8n-palette-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--n8n-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.n8n-palette-list {
  padding: 16px 20px;
  max-height: 440px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.n8n-palette-item {
  background: var(--n8n-panel-bg);
  border: 1px solid var(--n8n-border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.n8n-palette-item:hover {
  background: #232c44;
  border-color: var(--n8n-cyan);
  transform: translateY(-2px);
}

.n8n-palette-item-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.n8n-palette-item-text h4 {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
}

.n8n-palette-item-text p {
  font-size: 11px;
  color: var(--n8n-text-muted);
  margin-top: 2px;
}

/* ==========================================================================
   Full n8n 3-Pane Node Configuration & Test Modal
   ========================================================================== */
.n8n-node-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: blur(10px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.n8n-node-modal.active {
  display: flex;
  opacity: 1;
}

.n8n-node-modal-box {
  width: 95%;
  max-width: 1280px;
  height: 88vh;
  background: #141b2c;
  border: 1px solid var(--n8n-border-active);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.n8n-node-modal-header {
  height: 60px;
  padding: 0 24px;
  border-bottom: 1px solid var(--n8n-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--n8n-panel-bg);
}

.n8n-node-modal-panes {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr 380px;
  overflow: hidden;
}

.n8n-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--n8n-border);
  background: #121828;
}

.n8n-pane:last-child {
  border-right: none;
}

.n8n-pane-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--n8n-border);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.n8n-pane-header h4 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--n8n-text-muted);
}

.n8n-pane-body {
  flex: 1;
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.n8n-code-viewer {
  background: #0b0f1a;
  border: 1px solid var(--n8n-border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: 'Fira Code', monospace;
  font-size: 12px;
  color: #a5b4fc;
  white-space: pre-wrap;
  word-break: break-all;
  height: 100%;
  overflow-y: auto;
}

.n8n-input-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.n8n-input-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--n8n-text-muted);
}

.n8n-input-field input, .n8n-input-field select, .n8n-input-field textarea {
  background: #0d1322;
  border: 1px solid var(--n8n-border);
  color: #fff;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.n8n-input-field input:focus, .n8n-input-field select:focus, .n8n-input-field textarea:focus {
  border-color: var(--n8n-cyan);
}

@media (max-width: 1024px) {
  .n8n-node-modal-panes { grid-template-columns: 1fr; }
  .n8n-palette-list { grid-template-columns: 1fr; }
}
