:root {
  --bg:        #0c0c1a;
  --surface:   #13132a;
  --surface2:  #1c1c38;
  --border:    #2c2c50;
  --accent:    #7c6fb0;
  --accent-l:  #9d92cc;
  --accent-bg: rgba(124,111,176,0.15);
  --danger:    #c94040;
  --ok:        #4caa74;
  --text:      #dddaf0;
  --muted:     #6e6e9a;
  --node-w:    160px;
  --node-h:    220px;
  --radius:    14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Toolbar ─────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  margin-right: 4px;
}
.app-title svg {
  width: 20px; height: 20px;
  stroke: var(--accent-l);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

#toolbar button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
#toolbar button svg {
  width: 15px; height: 15px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}
#toolbar button:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent-l);
}
#toolbar button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 16px rgba(124,111,176,0.45);
}

#status-bar {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.2s;
}
#status-bar.ok    { color: var(--ok); }
#status-bar.error { color: var(--danger); }

/* ── Workspace ───────────────────────────────────────── */
#workspace {
  flex: 1;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(124,111,176,0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(80,60,140,0.05) 0%, transparent 60%),
    var(--bg);
}

/* ── Canvas (трансформируемый холст) ─────────────────── */
#canvas {
  position: absolute;
  top: 0; left: 0;
  width: 8000px; height: 6000px;
  transform-origin: 0 0;
  will-change: transform;
}

/* Точечная сетка — внутри canvas, чтобы масштабироваться вместе с ним */
#canvas::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.08) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}

#svg-layer {
  position: absolute;
  top: 0; left: 0;
  width: 8000px; height: 6000px;
  overflow: visible;
  pointer-events: none; /* клики идут через SVG к canvas/workspace */
}

/* Исключение: группы-связи внутри SVG должны ловить клики */
.conn-group { pointer-events: all; }

/* ── Zoom controls ────────────────────────────────────── */
#zoom-controls {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

#zoom-controls button {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
#zoom-controls button:hover { background: var(--surface2); }
#zoom-controls button svg {
  width: 14px; height: 14px;
  stroke: currentColor; fill: none;
  stroke-width: 2.5; stroke-linecap: round;
}

#btn-zoom-reset {
  width: auto !important;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted) !important;
  letter-spacing: 0.3px;
}
#btn-zoom-reset:hover { color: var(--text) !important; }

.zoom-divider {
  width: 1px; height: 20px;
  background: var(--border);
  margin: 0 2px;
}

/* ── Empty hint ──────────────────────────────────────── */
#empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
  opacity: 0.35;
}
#empty-hint svg {
  width: 56px; height: 56px;
  stroke: var(--muted); fill: none;
  stroke-width: 1.2; stroke-linecap: round;
}
#empty-hint p {
  font-size: 14px;
  color: var(--muted);
}

/* ── Node cards ──────────────────────────────────────── */
.node {
  position: absolute;
  width: var(--node-w);
  height: var(--node-h);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background-color: var(--surface2);
  background-size: cover;
  background-position: center;
  cursor: grab;
  z-index: 10;
  user-select: none;
  overflow: hidden;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.node::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: calc(var(--radius) - 2px);
  background: linear-gradient(160deg, rgba(255,255,255,0.03) 0%, transparent 60%);
  pointer-events: none;
}
.node:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 28px rgba(0,0,0,0.5), 0 0 0 1px rgba(124,111,176,0.3);
  z-index: 20;
}
.node.connect-mode { cursor: crosshair; }
.node.connect-mode:hover {
  border-color: #8acd8a;
  box-shadow: 0 6px 28px rgba(0,0,0,0.5), 0 0 16px rgba(100,200,100,0.3);
}
.node.node-source {
  border-color: #e0943a !important;
  box-shadow: 0 6px 28px rgba(0,0,0,0.5), 0 0 20px rgba(224,148,58,0.45) !important;
  cursor: crosshair;
}

.node-inner {
  position: relative;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.node-foot {
  padding: 28px 10px 10px;
  background: linear-gradient(to top, rgba(0,0,0,0.88) 0%, rgba(0,0,0,0) 100%);
}
.node-name {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,1);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.btn-edit-node {
  position: absolute;
  top: 7px; right: 7px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.node:hover .btn-edit-node { opacity: 1; }
.btn-edit-node:hover { background: rgba(124,111,176,0.7) !important; }

.doc-badge {
  position: absolute;
  top: 8px; left: 8px;
  font-size: 13px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.9));
}

/* ── SVG connections ─────────────────────────────────── */
.conn-hit {
  stroke: transparent;
  stroke-width: 16;
  fill: none;
  cursor: pointer;
}
.conn-line {
  stroke: #5a508a;
  stroke-width: 2;
  fill: none;
  pointer-events: none;
  transition: stroke 0.15s;
}
.conn-label-bg {
  fill: var(--surface2);
  stroke: #5a508a;
  stroke-width: 1;
  cursor: pointer;
  transition: stroke 0.15s;
  rx: 5; ry: 5;
}
.conn-label-text {
  fill: #b0a8d8;
  font-size: 11px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  cursor: pointer;
  pointer-events: none;
}
.conn-group:hover .conn-line      { stroke: var(--accent-l); }
.conn-group:hover .conn-label-bg  { stroke: var(--accent-l); fill: var(--accent-bg); }
.conn-group:hover .conn-label-text { fill: var(--text); }

/* ── Modals ──────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fadeIn 0.15s ease;
}
.modal-overlay.hidden { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  width: 390px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.6);
  animation: slideUp 0.18s ease;
}
.modal-box.sm { width: 320px; }

/* Scrollbar in modal */
.modal-box::-webkit-scrollbar { width: 6px; }
.modal-box::-webkit-scrollbar-track { background: transparent; }
.modal-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }

.modal-close {
  width: 28px; height: 28px;
  border: none; background: var(--surface2);
  border-radius: 50%; color: var(--muted);
  font-size: 18px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }

/* Photo section */
.photo-section {
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
}
.photo-wrap {
  width: 110px; height: 140px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--surface2);
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
#photo-preview {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: none;
}
#photo-placeholder {
  display: flex; flex-direction: column;
  align-items: center; gap: 6px;
  opacity: 0.4;
}
#photo-placeholder svg {
  width: 36px; height: 36px;
  stroke: var(--muted); fill: none;
  stroke-width: 1.5; stroke-linecap: round;
}
#photo-placeholder span { font-size: 11px; color: var(--muted); }

.photo-actions { display: flex; flex-direction: column; align-items: center; gap: 6px; }

/* Upload labels */
.upload-label {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer; font-size: 13px; color: var(--text);
  transition: all 0.15s;
}
.upload-label:hover { border-color: var(--accent); background: var(--accent-bg); color: var(--accent-l); }
.upload-label svg {
  width: 14px; height: 14px; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.upload-label.sm { font-size: 12px; padding: 5px 11px; }
.upload-label.sm svg { width: 12px; height: 12px; }

/* Form */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: 11px; color: var(--muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px;
}
.form-group input {
  padding: 9px 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text); font-size: 14px;
  transition: border-color 0.15s;
  width: 100%;
}
.form-group input:focus { outline: none; border-color: var(--accent); }
.form-group input::placeholder { color: var(--muted); }

.form-group textarea {
  padding: 9px 13px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text); font-size: 13px; line-height: 1.55;
  resize: vertical;
  min-height: 90px;
  width: 100%;
  font-family: inherit;
  transition: border-color 0.15s;
}
.form-group textarea:focus { outline: none; border-color: var(--accent); }
.form-group textarea::placeholder { color: var(--muted); }

/* Описание на карточке узла */
.node-desc {
  font-size: 10px;
  color: rgba(255,255,255,0.7);
  line-height: 1.45;
  margin-top: 3px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

/* Docs section */
.docs-section { display: flex; flex-direction: column; gap: 8px; }
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; color: var(--muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px;
}
#docs-list { display: flex; flex-direction: column; gap: 4px; }
.doc-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px; font-size: 12px;
}
.doc-item svg {
  width: 13px; height: 13px; stroke: var(--muted); fill: none;
  stroke-width: 2; stroke-linecap: round; flex-shrink: 0;
}
.doc-item a {
  flex: 1; color: #88aaee; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-item a:hover { color: #aaccff; text-decoration: underline; }
.doc-item .doc-remove {
  border: none; background: none; color: var(--muted);
  font-size: 16px; cursor: pointer; line-height: 1; flex-shrink: 0;
  padding: 0 2px;
}
.doc-item .doc-remove:hover { color: var(--danger); }

/* Modal footer */
.modal-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 4px; border-top: 1px solid var(--border);
  gap: 8px;
}
.modal-footer-right { display: flex; gap: 8px; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-danger, .btn-link {
  padding: 8px 18px; border: none; border-radius: 8px;
  font-size: 13px; cursor: pointer; transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-l); }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }

.btn-danger {
  background: none; color: var(--danger); padding: 8px 12px;
  border: 1px solid transparent;
}
.btn-danger:hover { border-color: var(--danger); background: rgba(201,64,64,0.1); }

.btn-link { background: none; color: var(--muted); padding: 4px 8px; font-size: 12px; }
.btn-link:hover { color: var(--danger); }
.btn-link.danger { color: var(--danger); opacity: 0.7; }
.btn-link.danger:hover { opacity: 1; }

/* ── Toolbar: spacer + user bar ──────────────────────── */
.toolbar-spacer { flex: 1; }

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.user-name {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-logout svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: rgba(201,64,64,0.08);
}

/* ── Login page ──────────────────────────────────────── */
.auth-body {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 30% 40%, rgba(124,111,176,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 70%, rgba(80,60,140,0.08) 0%, transparent 60%),
    var(--bg);
}

.auth-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  box-shadow: 0 24px 80px rgba(0,0,0,0.55);
  animation: slideUp 0.22s ease;
}

.auth-logo {
  width: 56px; height: 56px;
  background: var(--accent-bg);
  border: 1px solid rgba(124,111,176,0.35);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
}
.auth-logo svg {
  width: 28px; height: 28px;
  stroke: var(--accent-l); fill: none;
  stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}

.auth-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.auth-subtitle {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 24px;
  line-height: 1.5;
}

.auth-error {
  width: 100%;
  padding: 10px 14px;
  background: rgba(201,64,64,0.12);
  border: 1px solid rgba(201,64,64,0.4);
  border-radius: 8px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  margin-bottom: 16px;
}

.auth-buttons {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.auth-btn {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.16s;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}
.auth-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}

.auth-btn.google:hover  { border-color: #4285F4; background: rgba(66,133,244,0.08); }
.auth-btn.yandex:hover  { border-color: #fc3f1d; background: rgba(252,63,29,0.08); }
.auth-btn.guest:hover   { border-color: var(--accent); background: var(--accent-bg); }

.provider-icon {
  width: 20px; height: 20px;
  flex-shrink: 0;
}

.yandex-icon {
  display: flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  border-radius: 4px;
  background: #fc3f1d;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-style: normal;
}

.provider-icon:not(.yandex-icon) {
  stroke: none; fill: none;
}

.auth-btn.guest .provider-icon {
  stroke: var(--muted); fill: none;
  stroke-width: 1.5; stroke-linecap: round;
}
.auth-btn.guest:hover .provider-icon {
  stroke: var(--accent-l);
}

.auth-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 12px;
  margin: 2px 0;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-guest-note {
  margin-top: 18px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  line-height: 1.6;
  opacity: 0.75;
}
