/* Necesitas — UI tokens & layout inspirado en n8n */

:root,
[data-theme="dark"] {
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --surface: #131419;
  --on-surface: #f4f4f5;
  --muted: #9b9ba7;
  --card: #1c1c21;
  --border: #33333a;
  --primary: #ff6d5a;
  --on-primary: #fff;
  --accent: #ff6d5a;
  --warn: #f59e0b;
  --ok: #10b981;
  --diagram-bg: #1a1a1e;
  --grid-dot: #2e2e35;
  --grid-bg: #1a1a1e;
  --ndv-bg: #222228;
  --node-bg: #2d2d33;
  --node-border: #3f3f46;
  --node-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  --edge: #6b6b76;
  --port: #9b9ba7;
  --port-hover: #ff6d5a;
  --icon-step: #6366f1;
  --icon-subflow: #f59e0b;
  --icon-info: #10b981;
  --icon-terminal: #64748b;
}

[data-theme="light"] {
  --surface: #f4f4f5;
  --on-surface: #18181b;
  --muted: #71717a;
  --card: #fff;
  --border: #e4e4e7;
  --primary: #ea4c3c;
  --accent: #ea4c3c;
  --diagram-bg: #ebebef;
  --grid-dot: #d4d4d8;
  --grid-bg: #ebebef;
  --ndv-bg: #fff;
  --node-bg: #fff;
  --node-border: #e4e4e7;
  --node-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  --edge: #a1a1aa;
  --port: #71717a;
}

body { font-family: var(--font); -webkit-font-smoothing: antialiased; }

.brand small { font-weight: 400; color: var(--muted); font-size: 0.8em; }

.brand-mark {
  background: linear-gradient(135deg, #ff6d5a, #ff8f7a);
  border-radius: 6px;
}

.topbar {
  height: 48px;
  padding: 0 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.btn {
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  border-color: var(--border);
}

#editor-toolbar .btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 0.35rem 0.55rem;
}

#editor-toolbar .btn:hover {
  background: var(--surface);
  color: var(--on-surface);
}

.brand-btn {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.topbar-link {
  border: none !important;
  background: transparent !important;
  color: var(--muted) !important;
  font-size: 0.75rem !important;
}

.topbar-link:hover { color: var(--on-surface) !important; text-decoration: none; }

.btn-primary, .btn-accent {
  background: var(--primary);
  color: var(--on-primary);
  border-color: transparent;
  font-weight: 600;
}

.btn-primary:hover, .btn-accent:hover {
  filter: brightness(1.06);
  background: var(--primary);
}

.btn-ghost {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
}

.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

/* —— Editor layout —— */

.editor-view { display: flex; flex-direction: column; height: calc(100vh - 48px); overflow: hidden; }

.editor-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  flex: 1;
  min-height: 0;
}

@media (max-width: 960px) {
  .editor-layout { grid-template-columns: 1fr; }
  .ndv { max-height: 45vh; border-top: 1px solid var(--border); }
}

.canvas-zone {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.workflow-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: 44px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

.workflow-name {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--on-surface);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  min-width: 0;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.workflow-name:hover,
.workflow-name:focus {
  background: var(--surface);
  outline: none;
}

.workflow-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.version-bar { display: flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; }
.ver-vs { color: var(--muted); font-size: 0.7rem; }
.ver-select {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--on-surface);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
}

.canvas-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}

.n8n-canvas {
  background-color: var(--grid-bg);
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: 16px 16px;
  height: 100%;
}

.flow-canvas-host {
  height: 100%;
  overflow: hidden;
  padding: 0;
  cursor: grab;
  position: relative;
  touch-action: none;
}

.flow-canvas-host.is-panning { cursor: grabbing; }

.fc-transform {
  transform-origin: 0 0;
  will-change: transform;
}

.fc-stage {
  position: relative;
  margin: 0 auto;
}

.fc-svg {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.fc-nodes {
  position: relative;
  z-index: 1;
}

.fc-inserts {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

/* Floating toolbar (n8n add-node style) */

.canvas-float-toolbar {
  position: absolute;
  left: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  z-index: 10;
}

.cft-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--on-surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--node-shadow);
  transition: border-color 0.15s, transform 0.1s;
}

.cft-btn:hover {
  border-color: var(--primary);
  transform: scale(1.05);
}

.cft-btn .material-symbols-outlined { font-size: 1.25rem; }

/* —— Nodes (n8n card style) —— */

.fc-node {
  position: absolute;
  display: flex;
  align-items: stretch;
  background: var(--node-bg);
  border: 1px solid var(--node-border);
  border-radius: 8px;
  box-shadow: var(--node-shadow);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: border-color 0.12s, box-shadow 0.12s;
  overflow: hidden;
}

.fc-node:hover {
  border-color: color-mix(in srgb, var(--primary) 50%, var(--node-border));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
}

.fc-node-terminal {
  border-radius: 26px;
  min-height: 52px !important;
}

.fc-node-terminal .fc-node-iconbox {
  width: 40px;
  border-right: none;
  border-radius: 26px 0 0 26px;
}

.fc-node-terminal .fc-node-body {
  padding-right: 1rem;
}

.fc-node-subflow {
  border-color: color-mix(in srgb, var(--icon-subflow) 45%, var(--node-border));
}

.fc-node-info {
  border-color: color-mix(in srgb, var(--icon-info) 40%, var(--node-border));
}

.fc-node.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent), var(--node-shadow);
}

.fc-node.is-dragging { cursor: grabbing; z-index: 20; opacity: 0.95; }
.fc-node.is-dim { opacity: 0.4; }

.fc-node-iconbox {
  width: 44px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--node-border);
}

.fc-node-iconbox .material-symbols-outlined { font-size: 1.35rem; color: #fff; }

.fc-icon-step { background: var(--icon-step); }
.fc-icon-subflow { background: var(--icon-subflow); }
.fc-icon-info { background: var(--icon-info); }
.fc-icon-terminal { background: var(--icon-terminal); }

.fc-node-body {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
}

.fc-node-title {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fc-node-sub {
  font-size: 0.6875rem;
  color: var(--muted);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fc-subflow-hint {
  font-size: 0.625rem;
  color: var(--icon-subflow);
  margin-top: 0.15rem;
}

.fc-info-excerpt { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.fc-open {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border: none;
  background: color-mix(in srgb, var(--icon-subflow) 20%, transparent);
  color: var(--icon-subflow);
  border-radius: 4px;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
}

.fc-node:hover .fc-open,
.fc-node.is-selected .fc-open { opacity: 1; }

.fc-open .material-symbols-outlined { font-size: 0.9rem; }

.fc-port {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--port);
  border: 2px solid var(--node-bg);
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  transition: background 0.12s;
}

.fc-node:hover .fc-port { background: var(--port-hover); }

.fc-port-in { left: -4px; }
.fc-port-out { right: -4px; }

.fc-edge {
  fill: none;
  stroke: var(--edge);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke 0.12s;
}

.fc-stage:hover .fc-edge {
  stroke: color-mix(in srgb, var(--edge) 80%, var(--on-surface));
}

.fc-insert {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--primary);
  cursor: pointer;
  pointer-events: auto;
  display: grid;
  place-items: center;
  padding: 0;
  opacity: 0;
  z-index: 5;
  transition: opacity 0.15s, transform 0.12s, background 0.12s, color 0.12s;
  box-shadow: var(--node-shadow);
}

.fc-stage:hover .fc-insert,
.fc-insert:focus-visible { opacity: 1; }

.fc-insert:hover {
  transform: translate(-50%, -50%) scale(1.08);
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.fc-insert .material-symbols-outlined { font-size: 0.85rem; }

/* —— NDV panel (node details view) —— */

.ndv {
  background: var(--ndv-bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.ndv-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.5rem;
  color: var(--muted);
}

.ndv-empty-icon { font-size: 2.5rem; opacity: 0.35; margin-bottom: 0.75rem; }
.ndv-empty h3 { font-size: 0.9375rem; color: var(--on-surface); margin-bottom: 0.35rem; }
.ndv-empty p { font-size: 0.8125rem; line-height: 1.5; max-width: 16rem; }

.panel-step-view,
.panel-info-view {
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.panel-toolbar {
  padding: 0.85rem 1rem;
  margin: 0;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.panel-toolbar h2 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-top: 0.2rem;
}

.spec-summary {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
  background: none;
  border: none;
  padding: 0;
}

.ndv-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  padding: 0 0.5rem;
}

.ndv-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.65rem 0.5rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.12s, border-color 0.12s;
}

.ndv-tab:hover { color: var(--on-surface); }

.ndv-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.ndv-panel {
  padding: 1rem;
  flex: 1;
}

.ndv-hint {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.45;
}

.ndv-fold {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
}

.ndv-fold summary {
  cursor: pointer;
  color: var(--muted);
  padding: 0.4rem 0;
  font-weight: 500;
}

#spec-block { flex: 1; display: flex; flex-direction: column; }

.field label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  border-radius: 6px;
  font-size: 0.8125rem;
  border-color: var(--border);
  background: var(--surface);
}

.spec-section-head h4 {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.req-row {
  display: grid;
  grid-template-columns: 1fr minmax(6.5rem, 8rem) auto;
  grid-template-rows: auto auto;
  gap: 0.35rem 0.4rem;
  padding: 0.55rem;
  margin-bottom: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  align-items: center;
}

.req-row .map-name { grid-column: 1 / -1; }
.req-row .map-kind { grid-column: 1; }
.req-row .map-req {
  grid-column: 2;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.7rem;
  color: var(--muted);
}
.req-row .map-req input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
}
.req-row .map-note { grid-column: 1 / 3; }
.req-row .map-del {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: start;
}

.map-req-txt { font-size: 0.7rem; }

.req-row input,
.req-row select {
  font-size: 0.75rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  color: var(--on-surface);
  min-width: 0;
  width: 100%;
}

.panel-actions {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

.editor-mermaid {
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0;
  flex-shrink: 0;
  background: var(--card);
}

.editor-mermaid summary {
  cursor: pointer;
  padding: 0.3rem 1rem;
  user-select: none;
  font-size: 0.7rem;
}

.editor-mermaid:not([open]) summary { opacity: 0.6; }

.editor-mermaid textarea {
  width: 100%;
  min-height: 4rem;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 0.5rem 1rem;
  resize: vertical;
}

/* —— Dashboard polish —— */

.dashboard-view {
  max-width: 1080px;
  padding: 2.5rem clamp(1rem, 4vw, 2rem);
}

.landing-hero {
  background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 8%, var(--card)), var(--card));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem;
  margin-bottom: 2.5rem;
}

.landing-hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.landing-accent { color: var(--primary); }

.landing-mock-node {
  display: flex;
  align-items: stretch;
  background: var(--node-bg);
  border: 1px solid var(--node-border);
  border-radius: 8px;
  box-shadow: var(--node-shadow);
  overflow: hidden;
  min-width: 168px;
}

.mock-iconbox {
  width: 40px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--node-border);
}

.mock-iconbox .material-symbols-outlined { font-size: 1.2rem; color: #fff; }

.mock-icon-step { background: var(--icon-step); }

.mock-body {
  padding: 0.5rem 0.65rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.1rem;
}

.mock-body strong { font-size: 0.78rem; font-weight: 600; }
.mock-body small { font-size: 0.65rem; color: var(--muted); }

.landing-visual {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 1rem;
  background: var(--diagram-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  background-image: radial-gradient(circle, var(--grid-dot) 1px, transparent 1px);
  background-size: 16px 16px;
}

.landing-mock-arrow { color: var(--muted); font-size: 1.1rem; opacity: 0.6; }

.workflow-bar .btn-accent {
  font-size: 0.75rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(255, 109, 90, 0.25);
}

.breadcrumb[hidden] { display: none; }

.crumb {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.crumb:hover { color: var(--on-surface); background: var(--surface); }

.crumb-sep { color: var(--muted); opacity: 0.5; margin: 0 0.1rem; }

.tpl-card {
  border-radius: 10px;
  transition: border-color 0.15s, transform 0.12s;
}

.tpl-card:hover {
  border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
  transform: translateY(-2px);
}

.tpl-icon { color: var(--primary); }

.dash-card {
  border-radius: 10px;
  transition: border-color 0.15s;
}

.dash-card:hover { border-color: color-mix(in srgb, var(--primary) 30%, var(--border)); }

.theme-fab {
  border-radius: 8px;
  width: 2.5rem;
  height: 2.5rem;
  box-shadow: var(--node-shadow);
}

.checklist-dialog { border-radius: 12px; }

.chk-head h2 { font-weight: 600; }

.struct-table { border-radius: 6px; overflow: hidden; }

.panel-type-badge {
  border-radius: 4px;
  font-size: 0.625rem;
}

.btn-danger {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent);
  color: var(--warn);
  font-size: 0.75rem;
}

.subflow-banner {
  margin: 0 1rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
}

.breadcrumb { font-size: 0.8125rem; flex-shrink: 0; }
.crumb.active { color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); }

/* —— v1.0 zoom bar —— */

.fc-zoom-bar {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--node-shadow);
  z-index: 12;
}

.zbtn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--on-surface);
  border-radius: 6px;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.zbtn:hover { background: var(--surface); }
.zbtn .material-symbols-outlined { font-size: 1.1rem; }

.zbtn-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 2.5rem;
  text-align: center;
}

.fc-zoom-hint {
  font-size: 0.625rem;
  color: var(--muted);
  padding: 0 0.35rem 0 0.15rem;
  border-left: 1px solid var(--border);
  margin-left: 0.15rem;
  user-select: none;
}

.canvas-viewport.is-space-pan,
.flow-canvas-host.is-panning { cursor: grab; }
.flow-canvas-host.is-panning { cursor: grabbing; }

.canvas-viewport { overflow: hidden; }
.canvas-float-toolbar { z-index: 11; }

.storage-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.65rem !important;
  font-size: 0.78rem;
  color: var(--muted);
}

.storage-notice .material-symbols-outlined { font-size: 1rem; color: var(--primary); }

.ver-tag {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
}

@media (max-width: 960px) {
  .editor-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(52vh, 1fr) auto;
  }

  .ndv {
    max-height: none;
    min-height: 36vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .workflow-bar { flex-wrap: wrap; height: auto; padding: 0.5rem 0.75rem; }
  .workflow-name { width: 100%; flex: none; }
}

@media (max-width: 600px) {
  .tpl-grid { grid-template-columns: 1fr; }
  .req-row { grid-template-columns: 1fr auto; }
  .req-row .map-note { grid-column: 1 / -1; }
}
