:root {
  --grid: rgba(0, 0, 0, 0.08);
  --danger: #dc2626;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: #fff;
  color: #111;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ── Toolbar ─────────────────────────────────────────────── */

.toolbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  z-index: 100;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}

.toolbar--hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  pointer-events: none;
}

.toolbar__left, .toolbar__right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.3px;
  color: #000;
  white-space: nowrap;
}

.toolbar__hint {
  font-size: 11px;
  color: #aaa;
  white-space: nowrap;
}

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  appearance: none;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  padding: 5px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 500;
  font-size: 12px;
  font-family: inherit;
  line-height: 1.5;
  transition: background 0.1s, color 0.1s;
}

.btn:hover { background: #000; color: #fff; }

.btn--primary { background: #000; color: #fff; }
.btn--primary:hover { background: #333; }

.btn--danger { border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }

.btn--zoom {
  border-color: #ccc;
  color: #777;
  min-width: 46px;
  font-variant-numeric: tabular-nums;
}
.btn--zoom:hover { border-color: #000; color: #000; background: #fff; }

/* ── Canvas ──────────────────────────────────────────────── */

.canvas {
  position: fixed;
  inset: 48px 0 0 0;
  overflow: hidden;
  cursor: crosshair;
  background-color: #fff;
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  transition: inset 0.18s ease;
}

.canvas--fullscreen {
  inset: 0;
}

.canvas--panning { cursor: grabbing; }

.canvas--dropTarget::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.72);
  z-index: 8;
  pointer-events: none;
}

.canvasWorld {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.emptyState {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px 24px;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.emptyState--visible {
  opacity: 1;
  visibility: visible;
}

.emptyState__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.emptyState__icon {
  width: clamp(50px, 6vw, 72px);
  height: clamp(50px, 6vw, 72px);
  border-radius: 16px;
  flex-shrink: 0;
}

.emptyState__title {
  margin: 0;
  font-family: "Nunito", ui-sans-serif, system-ui, sans-serif;
  font-size: clamp(42px, 7vw, 88px);
  line-height: 0.94;
  letter-spacing: -0.05em;
  color: #111;
}

.emptyState__content {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.emptyState__body {
  margin: 0;
  max-width: 620px;
  font-size: clamp(14px, 1.5vw, 18px);
  line-height: 1.65;
  color: #6a6a6a;
}

.emptyState__importBtn {
  margin-top: 28px;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  pointer-events: auto;
}

.emptyState__cta {
  margin-top: 18px;
  font-size: 13px;
  font-weight: 700;
  color: #111;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.emptyState__inner {
  width: min(920px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn:disabled:hover {
  background: #fff;
  color: #000;
}

@media (max-width: 720px) {
  .emptyState {
    padding: 24px 20px;
  }

  .emptyState__brand {
    gap: 12px;
  }

  .emptyState__title {
    font-size: clamp(36px, 14vw, 58px);
  }

  .emptyState__icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .emptyState__body {
    max-width: 420px;
    font-size: 14px;
    line-height: 1.6;
  }

  .emptyState__importBtn {
    margin-top: 22px;
    width: 100%;
    max-width: 300px;
  }

  .emptyState__cta {
    margin-top: 10px;
    font-size: 12px;
  }
}

.importDropHint {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(480px, calc(100% - 32px));
  padding: 18px 20px;
  border: 2px dashed #000;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  text-align: center;
  z-index: 9;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.canvas--dropTarget .importDropHint {
  opacity: 1;
}

.importDropHint__title {
  font-size: 15px;
  font-weight: 700;
  color: #000;
}

.importDropHint__body {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.5;
  color: #555;
}

.connectionsSvg {
  position: absolute;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 0;
}

/* ── Notes ───────────────────────────────────────────────── */

.note {
  position: absolute;
  min-width: 180px;
  max-width: 480px;
  background: #fff;
  border: 1px solid #000;
  border-radius: 7px;
  overflow: visible;
  z-index: 2;
}

.note--aiCollapsed {
  width: fit-content;
  min-height: auto;
}

.note--source { box-shadow: 0 0 0 2px #000; }

/* Resize handle */
.note__resizeHandle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  border-radius: 0 0 6px 0;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 11;
}

.note__resizeHandle::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid #bbb;
  border-bottom: 1.5px solid #bbb;
}

.note:hover .note__resizeHandle { opacity: 1; }
.note__resizeHandle:hover::after { border-color: #000; }

/* Connection ports */
.note__port {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #000;
  cursor: crosshair;
  opacity: 0;
  transition: opacity 0.12s, background 0.1s;
  z-index: 10;
}

.note:hover .note__port  { opacity: 1; }
.note--source .note__port { opacity: 1; }
.note__port:hover { background: #000; opacity: 1; }

.note__port--top    { top: -5px;  left: 50%; transform: translateX(-50%); }
.note__port--right  { right: -5px; top: 50%; transform: translateY(-50%); }
.note__port--bottom { bottom: -5px; left: 50%; transform: translateX(-50%); }
.note__port--left   { left: -5px; top: 50%; transform: translateY(-50%); }

/* Note header */
.note__header {
  height: 32px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  border-radius: 6px 6px 0 0;
  cursor: grab;
  user-select: none;
}

.note__header:active { cursor: grabbing; }

.note__dragHandle {
  color: #ccc;
  font-size: 15px;
  line-height: 1;
  flex: 1;
  letter-spacing: 2px;
}

.note__headerActions { display: flex; gap: 4px; }

/* Icon buttons */
.note__iconBtn {
  appearance: none;
  border: 1px solid #ddd;
  background: #fff;
  color: #888;
  width: 22px;
  height: 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
  transition: border-color 0.1s, color 0.1s;
}

.note__iconBtn:hover { border-color: #000; color: #000; }
.note__iconBtn[data-action="delete"]:hover { border-color: var(--danger); color: var(--danger); }

/* Note body */
.note__body {
  padding: 10px;
  color: #111;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 72px;
  font-family: var(--note-font, inherit);
}

/* Note footer */
.note__footer {
  display: flex;
  justify-content: flex-end;
  padding: 4px 8px 6px;
  border-top: 1px solid #ebebeb;
}

.note__iconBtn--ai { font-size: 9px; font-weight: 800; color: #999; border-color: #ddd; width: 26px; }
.note__iconBtn--ai:hover { border-color: #000; color: #000; }
.note__iconBtn--loading { opacity: 0.45; cursor: default; }
.note__iconBtn--editLocked { opacity: 0.3; cursor: not-allowed; }
.note__iconBtn--aiToggle { font-size: 13px; line-height: 1; color: #aaa; border-color: #eee; }
.note__iconBtn--aiToggle:hover { color: #000; border-color: #000; }
.note__iconBtn--clear { font-size: 10px; color: #ccc; border-color: #eee; }
.note__iconBtn--clear:hover { color: var(--danger); border-color: var(--danger); }

/* AI response panel */
.note__aiPanel {
  border-top: 1px solid #ebebeb;
  border-radius: 0 0 7px 7px;
  overflow: hidden;
}

.note__aiHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  background: #fafafa;
  border-radius: 0 0 6px 6px;
}

.note__aiLabel {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #aaa;
  text-transform: uppercase;
  user-select: none;
}

.note__aiHeaderActions {
  display: flex;
  gap: 4px;
}

.note__aiBody {
  padding: 10px;
  color: #444;
  font-size: 12px;
  line-height: 1.55;
  white-space: normal;
  word-break: break-word;
  border-top: 1px solid #f0f0f0;
  border-radius: 0 0 6px 6px;
}

.note__aiBody p {
  margin: 0 0 0.65em;
}

.note__aiBody p:last-child {
  margin-bottom: 0;
}

.note__aiBody ul,
.note__aiBody ol {
  margin: 0.35em 0 0.65em;
  padding-left: 1.35em;
}

.note__aiBody li {
  margin: 0.22em 0;
}

.note__aiBody strong,
.note__aiBody b {
  font-weight: 700;
  color: #222;
}

.note__aiBody em,
.note__aiBody i {
  font-style: italic;
}

.note__aiBody code {
  font-family: ui-monospace, monospace;
  font-size: 0.92em;
  background: #f4f4f4;
  padding: 0.08em 0.35em;
  border-radius: 3px;
}

.note__aiBody pre {
  margin: 0.6em 0;
  padding: 8px 10px;
  background: #f6f6f6;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 11px;
  line-height: 1.45;
}

.note__aiBody pre code {
  background: transparent;
  padding: 0;
}

.note__aiBody h1,
.note__aiBody h2,
.note__aiBody h3,
.note__aiBody h4 {
  margin: 0.75em 0 0.4em;
  font-size: inherit;
  line-height: 1.35;
  font-weight: 700;
  color: #222;
}

.note__aiBody h1:first-child,
.note__aiBody h2:first-child,
.note__aiBody h3:first-child,
.note__aiBody h4:first-child {
  margin-top: 0;
}

.note__aiBody hr {
  border: none;
  border-top: 1px solid #e8e8e8;
  margin: 0.85em 0;
}

.note__aiBody blockquote {
  margin: 0.5em 0;
  padding-left: 10px;
  border-left: 3px solid #ddd;
  color: #555;
}

.note__aiBody table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.55em 0;
  font-size: 11px;
}

.note__aiBody th,
.note__aiBody td {
  border: 1px solid #e4e4e4;
  padding: 5px 7px;
  text-align: left;
}

/* Spinner */
@keyframes note-spin { to { transform: rotate(360deg); } }

.note__aiSpinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid #ddd;
  border-top-color: #000;
  border-radius: 50%;
  animation: note-spin 0.8s linear infinite;
}

/* Edit */
.note__editWrap { padding: 10px; }

.note__editTextarea {
  width: 100%;
  resize: vertical;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #000;
  padding: 8px;
  outline: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
}

.note__editTextarea:focus { border-color: #000; }

/* contenteditable rich-text editor (inline edit + popover) */
.note__editContent,
.popover__content {
  width: 100%;
  min-height: 80px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #000;
  padding: 8px;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  box-sizing: border-box;
  cursor: text;
}

.note__editContent:focus,
.popover__content:focus {
  border-color: #000;
}

/* placeholder via data-placeholder + :empty */
.note__editContent:empty::before,
.popover__content:empty::before {
  content: attr(data-placeholder);
  color: #bbb;
  pointer-events: none;
}

.note__editActions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

.note__editBtn { padding: 5px 10px; font-size: 12px; }

/* ── Popover ─────────────────────────────────────────────── */

.popover {
  position: fixed;
  width: 320px;
  border: 1px solid #000;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  padding: 14px;
  z-index: 200;
}

.popover__title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 10px;
  color: #000;
}

.popover__textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #000;
  padding: 8px;
  outline: none;
  font: inherit;
  font-size: 13px;
  line-height: 1.5;
}

.popover__textarea:focus { border-color: #000; }

/* popover content (contenteditable) */
.popover__content {
  resize: none;
}

.popover__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

/* ── Connection delete button ────────────────────────────── */

.connDelete {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #bbb;
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transform: translate(-50%, -50%);
  z-index: 3;
  color: #bbb;
  opacity: 0.4;
  transition: opacity 0.15s, background 0.1s, color 0.1s;
  line-height: 1;
}

.connDelete:hover {
  opacity: 1;
  background: #000;
  border-color: #000;
  color: #fff;
}

/* ── Formatting Toolbar ──────────────────────────────────── */

.formatToolbar {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 4px 5px;
  margin-bottom: 6px;
  background: #f7f7f7;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  flex-wrap: wrap;
  user-select: none;
}

.formatToolbar__btn {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #555;
  width: 24px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
  flex-shrink: 0;
}

.formatToolbar__btn:hover {
  background: #ebebeb;
  border-color: #d0d0d0;
  color: #000;
}

.formatToolbar__btn--active {
  background: #000;
  border-color: #000;
  color: #fff;
}

.formatToolbar__btn--italic { font-style: italic; }

.formatToolbar__divider {
  width: 1px;
  height: 16px;
  background: #ddd;
  margin: 0 2px;
  flex-shrink: 0;
}

.formatToolbar__select {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  color: #555;
  padding: 2px 18px 2px 6px;
  height: 22px;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 5px center;
  background-size: 7px;
  max-width: 110px;
  transition: border-color 0.1s, background-color 0.1s;
}

.formatToolbar__select:hover {
  border-color: #d0d0d0;
  background-color: #ebebeb;
}

.formatToolbar__select:focus {
  border-color: #000;
  background-color: #fff;
}
