:root {
  --ink: #15171c;
  --muted: #6c7280;
  --line: rgba(20, 24, 32, 0.12);
  --soft-line: rgba(20, 24, 32, 0.075);
  --surface: rgba(255, 255, 255, 0.88);
  --surface-solid: #ffffff;
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, 0.16);
  --danger: #b42318;
  --shadow: 0 16px 44px rgba(18, 23, 31, 0.12);
  --grid-size: 28px;
  --grid-x: 0px;
  --grid-y: 0px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #ffffff;
  letter-spacing: 0;
}

button,
input,
textarea {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  position: relative;
}

.viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: grab;
  background-color: #ffffff;
  background-image:
    linear-gradient(to right, var(--soft-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--soft-line) 1px, transparent 1px);
  background-position: var(--grid-x) var(--grid-y);
  background-size: var(--grid-size) var(--grid-size);
  touch-action: none;
}

.viewport.is-panning {
  cursor: grabbing;
}

.world {
  position: absolute;
  inset: 0 auto auto 0;
  width: 1px;
  height: 1px;
  transform-origin: 0 0;
}

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

.connection-line {
  fill: none;
  stroke: rgba(29, 35, 45, 0.66);
  stroke-width: 2;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
  cursor: pointer;
}

.connection-line.is-dotted {
  stroke-dasharray: 4 7;
}

.connection-line.is-selected {
  stroke: var(--accent);
  stroke-width: 2.7;
}

.topbar {
  position: fixed;
  z-index: 40;
  top: 14px;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.brand,
.toolbar,
.inspector,
.context-menu,
.status {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.brand {
  height: 38px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1;
  pointer-events: auto;
}

.toolbar {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  pointer-events: auto;
}

.toolbar + .toolbar {
  margin-left: 2px;
}

.zoom-tools {
  margin-left: auto;
}

.icon-button,
.zoom-readout {
  appearance: none;
  height: 32px;
  min-width: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease, transform 130ms ease;
}

.zoom-readout {
  width: 56px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.icon-button:hover,
.zoom-readout:hover {
  background: rgba(17, 24, 39, 0.07);
}

.icon-button.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.icon-button:active,
.zoom-readout:active {
  transform: translateY(1px);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node {
  position: absolute;
  outline: none;
  touch-action: none;
  user-select: none;
}

.frame {
  overflow: hidden;
  border: 1px solid rgba(19, 24, 32, 0.14);
  border-radius: 8px;
  background: #f7f7f4;
  box-shadow: 0 10px 28px rgba(16, 19, 26, 0.12);
  cursor: grab;
}

.frame.is-dragging,
.text-node.is-dragging {
  cursor: grabbing;
}

.frame.is-selected,
.text-node.is-selected {
  border-color: rgba(15, 118, 110, 0.72);
  box-shadow:
    0 0 0 3px var(--accent-soft),
    0 12px 34px rgba(16, 19, 26, 0.14);
}

.frame.is-connection-start,
.text-node.is-connection-start {
  border-color: rgba(15, 118, 110, 0.88);
  box-shadow:
    0 0 0 4px rgba(15, 118, 110, 0.2),
    0 12px 34px rgba(16, 19, 26, 0.14);
}

.frame-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.frame-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(24, 28, 36, 0.24);
}

.frame-empty svg {
  width: 42px;
  height: 42px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.caption {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  min-height: 28px;
  max-height: calc(100% - 16px);
  display: flex;
  align-items: center;
  padding: 6px 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 6px;
  color: #111827;
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(10px);
  font-size: 14px;
  line-height: 1.25;
  word-break: break-word;
  cursor: text;
}

.caption:empty {
  display: none;
}

.caption.is-editing {
  display: flex;
}

.caption.is-editing:empty::before {
  content: "Legenda";
  color: rgba(17, 24, 39, 0.38);
}

.caption[contenteditable="true"],
.text-content[contenteditable="true"] {
  user-select: text;
  cursor: text;
}

.resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 22px;
  height: 22px;
  border-radius: 6px 0 7px 0;
  background:
    linear-gradient(135deg, transparent 48%, rgba(17, 24, 39, 0.22) 49%, rgba(17, 24, 39, 0.22) 51%, transparent 52%),
    linear-gradient(135deg, transparent 61%, rgba(17, 24, 39, 0.22) 62%, rgba(17, 24, 39, 0.22) 64%, transparent 65%);
  opacity: 0;
  cursor: nwse-resize;
}

.frame.is-selected .resize-handle {
  opacity: 1;
}

.text-node {
  min-width: 80px;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: grab;
}

.text-content {
  min-width: 80px;
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 7px;
  color: #15171c;
  font-weight: 600;
  line-height: 1.15;
  white-space: pre;
  word-break: normal;
}

.inspector {
  position: fixed;
  z-index: 45;
  top: 64px;
  right: 14px;
  width: min(278px, calc(100vw - 28px));
  padding: 12px;
  border-radius: 8px;
}

.inspector[hidden] {
  display: none;
}

.inspector-title {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.field label,
.toggle-field {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.field input[type="text"],
.field input[type="number"],
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
  padding: 8px 9px;
  outline: none;
}

.field textarea {
  min-height: 76px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: rgba(15, 118, 110, 0.68);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  gap: 8px;
}

.color-row input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.inspector-actions {
  display: flex;
  gap: 6px;
  margin-top: 12px;
}

.tool-button {
  appearance: none;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
  padding: 0 10px;
  color: #20242c;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.tool-button:hover {
  border-color: rgba(15, 118, 110, 0.46);
  background: #ffffff;
}

.tool-button.danger {
  color: var(--danger);
}

.context-menu {
  position: fixed;
  z-index: 70;
  min-width: 188px;
  padding: 6px;
  border-radius: 8px;
}

.context-menu[hidden] {
  display: none;
}

.context-menu button {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  color: #1d222b;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}

.context-menu button:hover {
  background: rgba(17, 24, 39, 0.07);
}

.context-menu .danger {
  color: var(--danger);
}

.status {
  position: fixed;
  z-index: 42;
  right: 14px;
  bottom: 14px;
  max-width: min(360px, calc(100vw - 28px));
  min-height: 32px;
  display: flex;
  align-items: center;
  padding: 0 11px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  pointer-events: none;
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .brand {
    width: auto;
  }

  .zoom-tools {
    margin-left: 0;
  }

  .inspector {
    top: auto;
    right: 10px;
    bottom: 54px;
  }
}
