/* ============================================================
   KRASIVO AI — Node Canvas styles
   ============================================================ */

.canvas-view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); z-index: 50; }

/* ---------- Toolbar ---------- */
.ctoolbar {
  height: 58px; flex: none; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  border-bottom: 1px solid var(--border); background: var(--glass); backdrop-filter: blur(14px); z-index: 20;
}
.ctoolbar .tb-left, .ctoolbar .tb-right { display: flex; align-items: center; gap: 10px; }
.ctoolbar .tb-center { margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.proj-name { font-weight: 600; font-size: 15px; padding: 6px 10px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text); min-width: 120px; transition: border-color .2s; }
.proj-name:hover, .proj-name:focus { border-color: var(--border); outline: none; }
.tb-divider { width: 1px; height: 26px; background: var(--border); }
.status-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); }
.status-chip .sd { width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.status-chip.running .sd { background: var(--gold); animation: pulse 1s infinite; }
.cost-chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 600; font-family: var(--font-mono); background: var(--raised); border: 1px solid var(--border); }
.cost-chip svg { color: var(--gold); }
.balance-chip { color: var(--teal); border-color: var(--teal-soft); }
.balance-chip svg { color: var(--teal); }
@keyframes pulse { 0%,100%{ opacity:1;} 50%{ opacity:.35;} }

.canvas-body { flex: 1; display: flex; min-height: 0; position: relative; }

/* ---------- Node palette ---------- */
.palette { width: 264px; flex: none; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; transition: width .3s var(--ease); z-index: 10; }
.palette.collapsed { width: 52px; }
.palette-head { padding: 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.palette-search { flex: 1; display: flex; align-items: center; gap: 8px; padding: 8px 11px; border-radius: 9px; background: var(--raised); border: 1px solid var(--border); color: var(--muted); }
.palette-search input { background: none; border: none; outline: none; color: var(--text); font-size: 13.5px; width: 100%; }
.palette.collapsed .palette-search, .palette.collapsed .palette-scroll { display: none; }
.palette-scroll { flex: 1; overflow-y: auto; padding: 10px; }
.pal-cat { margin-bottom: 6px; }
.pal-cat-head { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 9px 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.pal-cat-head .chev { transition: transform .2s; }
.pal-cat.collapsed .chev { transform: rotate(-90deg); }
.pal-cat.collapsed .pal-items { display: none; }
.pal-items { display: flex; flex-direction: column; gap: 4px; padding-bottom: 6px; }
.pal-node { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; border: 1px solid transparent; cursor: grab; transition: all .15s; font-size: 13.5px; font-weight: 500; }
.pal-node:hover { background: var(--raised); border-color: var(--border); }
.pal-node:active { cursor: grabbing; }
.pal-node .pn-ic { width: 28px; height: 28px; border-radius: 8px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--gold-soft); color: var(--gold); }
.pal-node .pn-ic.teal { background: var(--teal-soft); color: var(--teal); }
.pal-node .pn-cost { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

/* ---------- Canvas surface ---------- */
.canvas-surface {
  flex: 1; position: relative; overflow: hidden; min-width: 0;
  background:
    radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 26px 26px,
    var(--bg);
  cursor: grab;
}
.canvas-surface:active { cursor: grabbing; }
.canvas-pan { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.wires-svg { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; z-index: 1; }
.wire-path { fill: none; stroke-width: 2.5; transition: stroke .2s, filter .2s; }
.wire-path.hl { filter: drop-shadow(0 0 6px currentColor); stroke-width: 3.5; }
.wire-flow { stroke-dasharray: 7 10; animation: wireflow 1s linear infinite; }
@keyframes wireflow { to { stroke-dashoffset: -34; } }

/* ---------- Node card ---------- */
.node {
  position: absolute; width: 300px; border-radius: var(--r-node); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-md); z-index: 2; user-select: none;
  transition: box-shadow .2s, border-color .2s, transform .12s; cursor: grab;
}
.node:active { cursor: grabbing; }
.node:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.node.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 30px -6px var(--gold-soft), var(--shadow-lg); }
.node.state-error { border-color: var(--error); }
.node.state-done { border-color: color-mix(in oklab, var(--success) 50%, var(--border)); }
.node-head { display: flex; align-items: center; gap: 9px; padding: 11px 12px; border-bottom: 1px solid var(--border-soft); cursor: grab; }
.node-head .nh-ic { width: 26px; height: 26px; border-radius: 7px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--gold-soft); color: var(--gold); }
.node-head .nh-ic.teal { background: var(--teal-soft); color: var(--teal); }
.node-title { font-size: 13.5px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-state-ic { flex: none; }
.node-body { padding: 11px 12px; }
/* full-bleed превью: картинка во всю ширину карточки, край в край (как у Weavy),
   без вложенной рамки и отступов — иначе миниатюра мелкая и нечитаемая.
   Отрицательные margin'ы гасят padding .node-body, картинка ложится встык к шапке и подвалу. */
.node-preview { overflow: hidden; position: relative; background: var(--raised); min-height: 90px;
  margin: -11px -12px 0; }
.node-preview img { width: 100%; height: auto; max-height: 620px; object-fit: cover; object-position: center; display: block; cursor: grab; -webkit-user-drag: none; }
.node-preview img:active { cursor: grabbing; }
.node-dl-btn {
  position: absolute; top: 6px; right: 6px;
  width: 28px; height: 28px; border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.55); backdrop-filter: blur(6px);
  color: #fff; display: flex; align-items: center; justify-content: center;
  cursor: pointer; opacity: 0; transition: opacity 0.2s, background 0.15s;
  z-index: 2;
}
.node-preview:hover .node-dl-btn { opacity: 1; }
.node-dl-btn:hover { background: var(--gold); color: #000; }
.node-history-nav {
  position: absolute; left: 50%; bottom: 7px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 3px 5px;
  border: 1px solid rgba(255,255,255,.16); border-radius: 9px;
  background: rgba(0,0,0,.68); backdrop-filter: blur(7px); color: #fff;
  font: 11px/1 var(--font-mono); z-index: 3; cursor: default;
}
.node-history-nav button {
  width: 24px; height: 24px; padding: 0; border: 0; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: #fff; cursor: pointer;
}
.node-history-nav button:hover:not(:disabled) { background: var(--gold); color: #000; }
.node-history-nav button:disabled { opacity: .3; cursor: default; }
.node-history-nav span { min-width: 29px; text-align: center; }
.image-viewer { position: fixed; inset: 0; z-index: 99999; background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center; overflow: hidden; animation: viewFade .18s; }
.image-viewer-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; cursor: grab; touch-action: none; }
.image-viewer-stage:active { cursor: grabbing; }
.image-viewer-img { max-width: 92vw; max-height: 92vh; object-fit: contain; border-radius: 8px; box-shadow: 0 12px 60px rgba(0,0,0,.6); user-select: none; will-change: transform; transform-origin: center center; }
.image-viewer-controls { position: fixed; top: 18px; right: 18px; z-index: 100000; display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 11px; background: rgba(20,20,20,.72); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(10px); }
.image-viewer-controls span { min-width: 48px; text-align: center; font-family: var(--font-mono); font-size: 12px; color: #fff; }
.image-viewer-controls .icon-btn { width: 32px; height: 32px; background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.16); }
.image-viewer-controls .icon-btn:hover { color: #000; background: var(--gold); border-color: var(--gold); }
.node-params { display: flex; flex-direction: column; gap: 7px; }
.node-param-row { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.node-param-row .v { color: var(--text); font-family: var(--font-mono); font-size: 11.5px; }
.node-prompt-mini {
  font-size: 12px; color: var(--muted); line-height: 1.45; background: var(--raised);
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-soft);
  max-height: 92px; overflow-y: auto; overflow-x: hidden; white-space: pre-wrap;
  overflow-wrap: anywhere; word-break: break-word;
}
.node-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-top: 1px solid var(--border-soft); }
.node-model-badge { font-family: var(--font-mono); font-size: 10.5px; padding: 2px 7px; border-radius: 6px; background: var(--gold-soft); color: var(--gold); border: 1px solid var(--gold-line); flex: 1 1 auto; min-width: 0; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
.node-run-btn { width: 26px; height: 24px; border-radius: 7px; border: 1px solid var(--gold-line); background: var(--gold-soft); color: var(--gold); display: inline-flex; align-items: center; justify-content: center; flex: none; cursor: pointer; transition: background .15s, color .15s, border-color .15s, transform .15s; }
.node-run-btn:hover:not(:disabled) { background: var(--gold); border-color: var(--gold); color: #000; transform: translateY(-1px); }
.node-run-btn:disabled { opacity: .55; cursor: default; }
.node-run-btn:disabled svg { animation: spin 1s linear infinite; }
.node-cost { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.node-charge { font-family: var(--font-mono); font-size: 11.5px; color: var(--gold); display: inline-flex; align-items: center; gap: 4px; font-weight: 650; }

/* progress bar for running */
.node-progress { height: 3px; background: var(--raised); border-radius: 2px; overflow: hidden; margin-top: 9px; }
.node-progress > i { display: block; height: 100%; width: 40%; background: var(--gold); border-radius: 2px; animation: indeterminate 1.2s var(--ease) infinite; }
@keyframes indeterminate { 0%{ margin-left: -40%;} 100%{ margin-left: 100%;} }

/* ports */
.port { position: absolute; width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--bg); top: 50%; transform: translateY(-50%); z-index: 3; transition: transform .15s, box-shadow .15s; cursor: crosshair; box-shadow: 0 0 0 2px rgba(0,0,0,.18); }
.port:hover { transform: translateY(-50%) scale(1.22); box-shadow: 0 0 0 5px rgba(255,184,64,.14); }
.port.in { left: -12px; }
.port.out { right: -12px; }
.port.img, .port.ref { background: #ff9f2f; }
.port.threed { background: var(--teal); }
.port.text, .port.prompt { background: #8b5cf6; }
.port.any { background: linear-gradient(135deg, #ff9f2f 0 45%, #8b5cf6 55% 100%); }

.node-error-msg { padding: 9px 12px; font-size: 12px; color: var(--error); border-top: 1px solid var(--border-soft); display: flex; gap: 6px; align-items: flex-start; }

/* ---------- Inspector ---------- */
.inspector { width: 320px; flex: none; border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; z-index: 10; }
.inspector-head { padding: 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.inspector-scroll { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 18px; }
.insp-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; color: var(--muted); padding: 40px; }
.insp-empty .ie-ic { width: 56px; height: 56px; border-radius: 14px; background: var(--raised); display: inline-flex; align-items: center; justify-content: center; color: var(--faint); }
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field textarea, .field select, .field input[type=text], .field input[type=email], .field input[type=password], .field input[type=number] {
  background: var(--raised); border: 1px solid var(--border); border-radius: 9px; color: var(--text);
  padding: 10px 12px; font-size: 13.5px; outline: none; transition: border-color .2s; resize: vertical;
}
.field textarea.auto-grow-textarea {
  min-height: 72px; max-height: 260px; resize: none; overflow-y: hidden; overflow-x: hidden;
  line-height: 1.42; white-space: pre-wrap;
}
.field textarea:focus, .field select:focus, .field input:focus { border-color: var(--gold-line); }
.field-range input[type=range] { width: 100%; accent-color: var(--gold); }
.range-val { font-family: var(--font-mono); font-size: 11.5px; color: var(--gold); }
.insp-preview { aspect-ratio: 16/11; border-radius: 12px; overflow: hidden; background: var(--raised); border: 1px solid var(--border); }
.insp-preview img { width: 100%; height: 100%; object-fit: contain; }
.insp-cost { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 11px; background: var(--gold-soft); border: 1px solid var(--gold-line); font-weight: 600; }
.insp-cost .c { color: var(--gold); font-family: var(--font-mono); }

/* ---------- zoom controls + minimap ---------- */
.zoom-ctl { position: absolute; bottom: 18px; left: 18px; display: flex; flex-direction: column; gap: 6px; z-index: 12; }
.zoom-ctl button { width: 36px; height: 36px; border-radius: 9px; background: var(--glass); border: 1px solid var(--border); color: var(--text); backdrop-filter: blur(8px); display:inline-flex; align-items:center; justify-content:center; transition: all .15s; }
.zoom-ctl button:hover { border-color: var(--gold-line); color: var(--gold); }
.zoom-pct { font-size: 11px; text-align: center; color: var(--muted); font-family: var(--font-mono); padding: 4px 0; }
.minimap { position: absolute; bottom: 18px; right: 18px; width: 180px; height: 120px; border-radius: 11px; background: var(--glass); border: 1px solid var(--border); backdrop-filter: blur(8px); overflow: hidden; z-index: 12; box-shadow: var(--shadow-md); }
.minimap svg { width: 100%; height: 100%; }
.mm-node { fill: var(--gold); opacity: .85; }
.mm-view { fill: none; stroke: var(--teal); stroke-width: 2; }

/* empty canvas onboarding */
.canvas-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center; z-index: 5; padding: 40px; }
.canvas-empty h2 { font-size: 28px; }
.canvas-empty p { color: var(--muted); max-width: 420px; }
.quick-templates { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.qt-chip { display: inline-flex; align-items: center; gap: 9px; padding: 11px 16px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; font-size: 14px; transition: all .2s; }
.qt-chip:hover { border-color: var(--gold-line); background: var(--gold-soft); color: var(--gold); transform: translateY(-2px); }

/* ---------- Templates modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(6px); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 30px; animation: viewFade .25s; }
.modal { width: 100%; max-width: 720px; max-height: 84vh; overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.modal-head { padding: 22px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 24px; overflow-y: auto; }
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tpl-card { padding: 20px; border-radius: 14px; border: 1px solid var(--border); background: var(--raised); cursor: pointer; transition: all .2s; display: flex; flex-direction: column; gap: 10px; }
.tpl-card:hover { border-color: var(--gold-line); transform: translateY(-3px); box-shadow: var(--shadow-md); }
.tpl-card .tc-ic { width: 40px; height: 40px; border-radius: 10px; background: var(--gold-soft); color: var(--gold); display: inline-flex; align-items: center; justify-content: center; }
.tpl-card h4 { font-family: var(--font-body); font-size: 15px; font-weight: 600; }
.tpl-card p { color: var(--muted); font-size: 13px; }
.tpl-flow { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }

/* low-credit banner */
.credit-banner { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-radius: 11px; background: var(--surface); border: 1px solid var(--error); box-shadow: var(--shadow-md); font-size: 14px; font-weight: 500; }
.credit-banner svg { color: var(--error); }

/* mobile canvas notice */
.canvas-mobile-note { display: none; }
@media (max-width: 860px) {
  .palette, .inspector, .minimap { display: none; }
  .canvas-mobile-note { display: flex; position: absolute; bottom: 0; left: 0; right: 0; z-index: 40; align-items: center; gap: 10px; padding: 14px 18px; background: var(--glass); border-top: 1px solid var(--border); backdrop-filter: blur(10px); font-size: 13.5px; color: var(--muted); }
}

/* ---------- Context menu ---------- */
.ctx-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  width: 220px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  backdrop-filter: blur(16px);
  animation: ctxFadeIn 0.12s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes ctxFadeIn {
  from { opacity: 0; transform: scale(0.95) translateY(-5px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.ctx-group {
  margin-bottom: 6px;
}
.ctx-group:last-child {
  margin-bottom: 0;
}
.ctx-group-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 8px 4px;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 4px;
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 8px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}
.ctx-item:hover {
  background: var(--raised);
}
.ctx-item svg.gold {
  color: var(--gold);
}
.ctx-item svg.teal {
  color: var(--teal);
}
.ctx-item-cost {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
}

/* ---------- Marquee selection rectangle ---------- */
.marquee-rect {
  fill: rgba(255, 187, 0, 0.08);
  stroke: var(--gold);
  stroke-width: 1.5;
  stroke-dasharray: 6 3;
  pointer-events: none;
  rx: 3;
  ry: 3;
}
