/* ==========================================================================
   Nodos Custom Fullscreen Stylesheet (public/css/nodos.css)
   ========================================================================== */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --edge: #94a3b8;
  --edge-hover: #64748b;
  --node-bg: #ffffff;
  --node-border: #cbd5e1;
  --node-shadow: 0 1px 2px rgba(15,23,42,0.08), 0 4px 12px rgba(15,23,42,0.06);
  --radius: 12px;
  --header-h: 28px;
  --pad: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, Helvetica, Arial;
}

body.nodos-page {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

/* Fullscreen app layout below navbar */
.app,
.nodos-fullscreen-app {
  height: calc(100vh - var(--nav-height, 70px));
  width: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 3;
  flex-wrap: wrap;
}

.toolbar .title {
  font-weight: 700;
  margin-right: 0.5rem;
  color: #111827;
}

.toolbar .spacer {
  flex: 1;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding-right: 0.35rem;
  margin-right: 0.35rem;
  border-right: 1px dashed #e5e7eb;
}

.toolbar-group:last-child {
  border-right: none;
  padding-right: 0;
  margin-right: 0;
}

/* Botones compactos (icon-only) */
.btn {
  appearance: none;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #111827;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  box-shadow: 0 1px 1px rgba(0,0,0,.03);
  transition: 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0,0,0,.06);
}

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

.btn.primary[data-active="true"] {
  background: var(--accent-2);
}

.btn[data-active="true"] {
  outline: 2px solid var(--accent-2);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn.icon {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.btn.small {
  height: 32px;
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
}

input[type="file"] {
  display: none;
}

/* Workspace */
#workspace {
  position: relative;
  overflow: hidden;
  height: 100%;
  width: 100%;
  background: #ffffff;
}

#canvasWrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background: #ffffff;
  z-index: 0;
}

#canvasWrap.panning {
  cursor: grabbing;
}

#content {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
  background: #ffffff;
}

/* Layers */
#edgesSvg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  overflow: visible;
  z-index: 0;
}

#nodesLayer {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Node */
.node {
  position: absolute;
  min-width: 100px;
  background: var(--node-bg);
  border: 1px solid var(--node-border);
  border-radius: var(--radius);
  box-shadow: var(--node-shadow);
  pointer-events: auto;
  user-select: none;
  width: auto;
  overflow: visible;
}

.node.selected {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.node[data-editing="true"] {
  outline: 2px dashed var(--accent);
  outline-offset: 0;
}

.node[data-resizing="true"] {
  outline: 2px dashed var(--accent-2);
}

/* Header */
.node-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.35rem;
  border-bottom: 1px solid #e5e7eb;
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
  background: #f8fafc;
  cursor: grab;
}

.node-header .sp {
  flex: 1 1 auto;
}

.node-header.dragging {
  cursor: grabbing;
}

.drag-icon {
  font-size: 1rem;
  color: var(--muted);
  user-select: none;
}

.node-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.node-btn {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}

.node-btn:hover {
  background: #f8fafc;
  transform: translateY(-1px);
}

.node-btn.danger:hover {
  background: #fff1f2;
  border-color: #fecaca;
}

.node-btn.active {
  background: #eef2ff;
  border-color: #c7d2fe;
}

.node-btn svg,
.node-btn i {
  pointer-events: none;
}

/* Content */
.node-content {
  padding: var(--pad);
  font-size: 0.95rem;
  line-height: 1.25rem;
  white-space: pre-wrap;
  outline: none;
  min-height: 42px;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  background: transparent;
}

.node:not([data-editing="true"]) .node-content {
  cursor: grab;
  user-select: none;
}

.node[data-editing="true"] .node-content {
  cursor: text;
}

.node .node-content:empty:before {
  content: "Escribe aquí…";
  color: #9aa2b1;
}

/* Image node */
.node[data-type="image"] .node-content {
  cursor: default;
  min-height: auto;
}

.node[data-type="image"] .node-content:empty:before {
  content: "";
}

.node-image {
  display: block;
  max-width: 560px;
  max-height: 420px;
  width: auto;
  height: auto;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
  object-fit: contain;
}

/* Color dot */
.color-btn {
  position: relative;
}

.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  background: #fff;
}

/* Popover color */
.color-popover {
  position: fixed;
  z-index: 10000;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  box-shadow: 0 6px 30px rgba(15,23,42,.15);
  padding: 0.6rem;
  width: 240px;
}

.color-popover h4 {
  margin: 0.1rem 0 0.5rem;
  font-size: 0.9rem;
  color: #334155;
}

.color-popover .row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.color-popover input[type="color"] {
  width: 40px;
  height: 28px;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 128px;
  overflow: auto;
  border-top: 1px dashed #e5e7eb;
  padding-top: 0.5rem;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,.18);
  cursor: pointer;
  position: relative;
}

.swatch[data-active="true"]::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  color: #0f172a;
  text-shadow: 0 1px 2px rgba(255,255,255,.6);
}

/* Edges */
.edge {
  fill: none;
  stroke: var(--edge);
  color: var(--edge);
  cursor: pointer;
  transition: stroke 0.15s ease, stroke-width 0.15s ease, color 0.15s ease;
  pointer-events: stroke;
}

.edge:hover {
  stroke: var(--edge-hover);
  color: var(--edge-hover);
}

.edge.selected {
  stroke: var(--accent);
  color: var(--accent);
}

.edge-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  pointer-events: stroke;
}

.edge-preview {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.25;
  stroke-dasharray: 6 6;
  opacity: 0.9;
  pointer-events: none;
}

/* Legend */
.legend {
  position: absolute;
  left: 20px;
  top: 20px;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  box-shadow: 0 6px 30px rgba(15,23,42,.08);
  min-width: 220px;
  user-select: none;
  z-index: 2;
}

.legend-header {
  height: 30px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafc;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
  cursor: grab;
  font-weight: 600;
  color: #334155;
  font-size: 0.85rem;
}

.legend-header.dragging {
  cursor: grabbing;
}

.legend-body {
  padding: 0.5rem 0.5rem 0.6rem;
  max-height: 240px;
  overflow: auto;
}

.legend-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 0.5rem;
  align-items: center;
  padding: 0.25rem 0;
}

.legend-color {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,.18);
}

.legend-label {
  outline: none;
  border: 1px dashed transparent;
  padding: 0.15rem 0.25rem;
  border-radius: 6px;
  min-height: 1.2em;
  cursor: text;
  user-select: text;
}

.legend-label:focus {
  border-color: #cbd5e1;
  background: #f8fafc;
}

/* Help popover */
.help-popover {
  position: fixed;
  width: 320px;
  max-width: calc(100% - 32px);
  background: rgba(255,255,255,0.98);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 0.6rem;
  box-shadow: 0 8px 40px rgba(15,23,42,.08);
  z-index: 10000;
  color: #334155;
  font-size: 0.9rem;
}

/* Toast */
.toast {
  position: fixed;
  right: 20px;
  top: 20px;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  color: #065f46;
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  box-shadow: 0 6px 40px rgba(15,23,42,.06);
  z-index: 10020;
  font-weight: 600;
}

/* Selection Box */
.selection-box {
  position: absolute;
  border: 1.5px dashed var(--accent);
  background: rgba(79,70,229,.08);
  pointer-events: none;
  z-index: 2;
}

/* Resize handle */
.node-resize {
  position: absolute;
  top: calc(var(--header-h) + 8px);
  bottom: 8px;
  right: -3px;
  width: 6px;
  border-radius: 6px;
  background: transparent;
  cursor: ew-resize;
  pointer-events: auto;
  box-shadow: none;
}

.node:hover .node-resize {
  background: rgba(79,70,229,.1);
}

.node[data-editing="true"] .node-resize {
  display: none;
}
