* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #edf2f7;
  color: #17202a;
  font-family: Arial, Helvetica, sans-serif;
}

.session-user,
.top-actions {
  position: fixed;
  z-index: 30;
}

.session-user {
  top: 18px;
  left: 18px;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  max-width: calc(100vw - 220px);
  padding: 0 14px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: rgb(255 255 255 / 94%);
  color: #0f172a;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgb(15 23 42 / 10%);
  backdrop-filter: blur(8px);
}

.top-actions {
  top: 18px;
  right: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100vw - 36px);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.save-status {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: rgb(255 255 255 / 94%);
  color: #334155;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgb(15 23 42 / 10%);
  backdrop-filter: blur(8px);
}

.save-status.is-saving {
  color: #1d4ed8;
}

.save-status.is-saved {
  color: #047857;
}

.save-status.is-error {
  color: #b91c1c;
}

body.readonly-view {
  height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at top left, rgb(37 99 235 / 10%), transparent 28%),
    linear-gradient(180deg, #eef4ff 0%, #f7f9fc 100%);
}

body.public-page {
  min-height: 100svh;
  display: block;
  padding: 0;
  overflow-x: hidden;
  background: #f8fafc;
}

.public-state {
  margin: 0 auto;
  padding: 0 14px;
  width: max-content;
  max-width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: rgb(255 255 255 / 94%);
  color: #334155;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 24px rgb(15 23 42 / 10%);
}

.public-shell {
  width: 100%;
  min-height: 100svh;
  margin: 0 auto;
  overflow: visible;
  overflow-x: hidden;
}

.public-empty {
  display: grid;
  gap: 10px;
  justify-items: center;
  width: min(100%, 420px);
  margin: 24px auto;
  padding: 28px;
  border: 1px solid rgb(203 213 225 / 85%);
  border-radius: 24px;
  background: rgb(255 255 255 / 92%);
  box-shadow: 0 22px 50px rgb(15 23 42 / 10%);
  color: #334155;
  text-align: center;
}

.public-empty strong {
  color: #0f172a;
  font-size: 22px;
}

.public-empty span {
  font-size: 14px;
  line-height: 1.5;
}

.public-phone {
  width: min(100%, 390px);
  min-height: 100svh;
  margin: 0 auto;
  height: auto;
  overflow: visible;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.public-canvas {
  min-height: 100svh;
  height: auto;
  border-radius: 0;
  overflow: visible;
}

.public-phone .canvas {
  min-height: 100svh;
}

body.public-page .canvas.is-readonly {
  touch-action: pan-y;
}

.public-footer-shell {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.public-footer {
  width: min(100%, 390px);
  margin: 0 auto;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgb(255 255 255 / 94%);
  border-top: 1px solid rgb(203 213 225 / 92%);
  box-shadow: 0 -6px 20px rgb(15 23 42 / 8%);
  backdrop-filter: blur(10px);
}

.public-footer-copy {
  min-width: 0;
  color: #475569;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.public-footer-link {
  color: #0f766e;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

.public-footer-link:focus-visible {
  outline: 2px solid rgb(37 99 235 / 65%);
  outline-offset: 3px;
  border-radius: 6px;
}

.public-footer-link:active {
  opacity: 0.82;
}

@media (max-width: 520px) {
  body.public-page {
    min-height: 100svh;
  }

  .public-shell {
    width: 100%;
  }

  .public-footer {
    width: 100%;
  }
}

@media (min-width: 521px) {
  body.public-page {
    padding: 24px 16px 40px;
    background:
      radial-gradient(circle at top left, rgb(37 99 235 / 10%), transparent 28%),
      linear-gradient(180deg, #eef4ff 0%, #f7f9fc 100%);
  }

  .public-phone {
    border-radius: 28px;
    box-shadow:
      0 20px 50px rgb(15 23 42 / 10%),
      0 1px 0 rgb(255 255 255 / 70%) inset;
  }

  .public-canvas {
    border-radius: 28px;
  }

  .public-footer {
    border-radius: 0 0 28px 28px;
  }
}

.view-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: rgb(255 255 255 / 94%);
  color: #1d4ed8;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 10px 24px rgb(15 23 42 / 10%);
  backdrop-filter: blur(8px);
}

.view-link-button {
  cursor: pointer;
}

.view-link-button:disabled {
  border-color: #d1d5db;
  background: rgb(255 255 255 / 82%);
  color: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.phone {
  --canvas-photo: none;
  width: min(100vw, 390px);
  min-height: 100vh;
  background-image:
    var(--canvas-photo),
    linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  background-position: center, center;
  background-repeat: no-repeat;
  background-size: cover, auto;
  background-color: #f8fafc;
}

.phone.readonly-shell {
  width: 390px;
  height: min(844px, calc(100vh - 40px));
  min-height: 0;
  border: 12px solid #0f172a;
  border-radius: 36px;
  box-shadow: 0 28px 60px rgb(15 23 42 / 18%);
  overflow: auto;
  overscroll-behavior: contain;
}

.canvas {
  position: relative;
  width: 100%;
  min-height: 100vh;
  padding: 24px;
  overflow: hidden;
  touch-action: none;
  background-image:
    radial-gradient(circle at top left, rgb(37 99 235 / 6%), transparent 34%),
    linear-gradient(180deg, rgb(248 250 252 / 22%) 0%, rgb(241 245 249 / 38%) 100%);
  background-position: top left, center;
  background-repeat: no-repeat;
  background-size: auto, auto;
  transition: background 180ms ease;
}

.phone.readonly-shell .canvas {
  min-height: 100%;
}

.canvas.is-moving-mode {
  background-image:
    radial-gradient(circle at top left, rgb(37 99 235 / 10%), transparent 34%),
    repeating-linear-gradient(0deg, rgb(37 99 235 / 5%) 0 1px, transparent 1px 28px),
    repeating-linear-gradient(90deg, rgb(37 99 235 / 5%) 0 1px, transparent 1px 28px),
    linear-gradient(180deg, rgb(248 251 255 / 24%) 0%, rgb(237 244 255 / 38%) 100%);
  background-position: top left, center, center, center;
  background-repeat: no-repeat, repeat, repeat, no-repeat;
  background-size: auto, auto, auto, auto;
}

.canvas.is-resize-mode {
  background-image:
    radial-gradient(circle at top left, rgb(14 165 233 / 8%), transparent 34%),
    linear-gradient(180deg, rgb(248 252 255 / 26%) 0%, rgb(238 248 255 / 40%) 100%);
  background-position: top left, center;
  background-repeat: no-repeat;
  background-size: auto, auto;
}

.canvas-item {
  position: absolute;
  left: 0;
  top: 0;
  cursor: pointer;
  overflow: hidden;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.canvas.is-readonly .canvas-item {
  cursor: default;
}

.canvas.is-readonly .whatsapp-field[data-href] {
  cursor: pointer;
  touch-action: manipulation;
}

.canvas.is-readonly .whatsapp-field[data-href]:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 18%),
    0 14px 30px rgb(22 163 74 / 26%);
}

.canvas.is-readonly .whatsapp-field[data-href]:active {
  filter: brightness(0.98);
  box-shadow: 0 8px 20px rgb(22 163 74 / 28%);
}

.canvas-item.is-moving,
.canvas-item.is-resizing-active {
  transition: none;
}

.text-field {
  width: calc(100% - 56px);
  min-height: 48px;
  padding: 13px 14px 13px 48px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: inherit;
  font: inherit;
  text-align: left;
  box-shadow: 0 1px 2px rgb(15 23 42 / 8%);
}

.text-field::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translateY(-50%);
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 5px, currentColor 0 1.2px, transparent 1.35px),
    radial-gradient(circle at 50% 10px, currentColor 0 1.2px, transparent 1.35px),
    radial-gradient(circle at 50% 15px, currentColor 0 1.2px, transparent 1.35px);
  color: #94a3b8;
  opacity: 0.7;
  transition: color 160ms ease, opacity 160ms ease;
}

.text-field-plain {
  padding: 10px 12px;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: #0f172a;
  font-size: 22px;
  font-weight: 600;
}

.text-field-plain::before {
  display: none;
}

.text-field-plain::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px dashed rgb(37 99 235 / 42%);
  border-radius: 10px;
  pointer-events: none;
  transition:
    border-color 160ms ease,
    opacity 160ms ease,
    box-shadow 160ms ease;
}

.text-field.is-selected {
  border-color: #2563eb;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 12%),
    0 10px 24px rgb(37 99 235 / 10%);
}

.text-field.is-selected::before {
  color: #2563eb;
  opacity: 0.95;
}

.text-field-plain.is-selected {
  border-color: transparent;
  background: transparent;
  box-shadow: 0 0 0 4px rgb(37 99 235 / 10%);
}

.text-field-plain.is-selected::after {
  border-color: rgb(37 99 235 / 78%);
}

.text-field.is-moving {
  border-style: dashed;
  border-width: 2px;
  border-color: #2563eb;
  background:
    linear-gradient(180deg, #ffffff 0%, #eef5ff 100%);
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 16%),
    0 12px 28px rgb(37 99 235 / 14%);
  cursor: grab;
  user-select: none;
  animation: movePulse 1.2s ease-in-out infinite;
}

.text-field.is-moving::before {
  color: #2563eb;
  opacity: 1;
}

.text-field-plain.is-moving {
  border-color: transparent;
  background: transparent;
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 12%),
    0 10px 24px rgb(37 99 235 / 12%);
}

.text-field-plain.is-moving::after {
  border-color: #2563eb;
}

.text-field.is-moving:active {
  cursor: grabbing;
}

.text-field.is-resize-mode {
  border-color: #0f766e;
  box-shadow:
    0 0 0 4px rgb(20 184 166 / 12%),
    0 10px 24px rgb(15 118 110 / 10%);
}

.text-field.is-resizing-active {
  border-width: 2px;
  border-style: solid;
  border-color: #0f766e;
  box-shadow:
    0 0 0 5px rgb(20 184 166 / 14%),
    0 12px 28px rgb(15 118 110 / 16%);
}

.text-field-plain.is-resize-mode {
  border-color: transparent;
  background: transparent;
  box-shadow: 0 0 0 4px rgb(20 184 166 / 10%);
}

.text-field-plain.is-resize-mode::after {
  border-color: rgb(15 118 110 / 78%);
}

.text-field-plain.is-resizing-active {
  border-color: transparent;
  background: transparent;
  box-shadow:
    0 0 0 5px rgb(20 184 166 / 14%),
    0 12px 28px rgb(15 118 110 / 14%);
}

.text-field-plain.is-resizing-active::after {
  border-color: #0f766e;
}

.image-field {
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 22px rgb(15 23 42 / 10%);
}

.whatsapp-field {
  border: 1px solid #16a34a;
  border-radius: 16px;
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  color: #fff;
  box-shadow: 0 10px 24px rgb(22 163 74 / 22%);
}

.whatsapp-field-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 0 14px;
}

.whatsapp-field-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgb(255 255 255 / 16%);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.whatsapp-field-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.whatsapp-field-copy strong,
.whatsapp-field-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.whatsapp-field-copy strong {
  font-size: 15px;
  line-height: 1.1;
}

.whatsapp-field-copy span {
  font-size: 12px;
  color: rgb(240 253 244 / 88%);
  line-height: 1.2;
}

.image-field img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

#uploadButton:not(.is-active):hover {
  background: #cbd5e1;
  color: #334155;
}

.image-field.is-selected {
  border-color: #2563eb;
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 12%),
    0 12px 28px rgb(37 99 235 / 12%);
}

.whatsapp-field.is-selected {
  border-color: #2563eb;
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 12%),
    0 14px 30px rgb(37 99 235 / 12%);
}

.image-field.is-moving {
  border-style: dashed;
  border-width: 2px;
  border-color: #2563eb;
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 16%),
    0 12px 28px rgb(37 99 235 / 14%);
}

.whatsapp-field.is-moving {
  border-style: dashed;
  border-width: 2px;
  border-color: #2563eb;
  box-shadow:
    0 0 0 4px rgb(37 99 235 / 16%),
    0 14px 30px rgb(37 99 235 / 16%);
}

.image-field.is-moving:active {
  cursor: grabbing;
}

.image-field.is-resize-mode {
  border-color: #0f766e;
  box-shadow:
    0 0 0 4px rgb(20 184 166 / 12%),
    0 12px 28px rgb(15 118 110 / 12%);
}

.whatsapp-field.is-resize-mode {
  border-color: #0f766e;
  box-shadow:
    0 0 0 4px rgb(20 184 166 / 12%),
    0 14px 30px rgb(15 118 110 / 14%);
}

.image-field.is-resizing-active {
  border-width: 2px;
  border-style: solid;
  border-color: #0f766e;
  box-shadow:
    0 0 0 5px rgb(20 184 166 / 14%),
    0 12px 28px rgb(15 118 110 / 16%);
}

.whatsapp-field.is-resizing-active {
  border-width: 2px;
  border-style: solid;
  border-color: #0f766e;
  box-shadow:
    0 0 0 5px rgb(20 184 166 / 14%),
    0 14px 30px rgb(15 118 110 / 16%);
}

.text-field[contenteditable="true"] {
  outline: none;
  cursor: text;
}

.field-actions {
  position: absolute;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(344px, calc(100% - 16px));
  padding: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgb(15 23 42 / 16%);
}

.format-toolbar {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 24px;
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 28px rgb(15 23 42 / 16%);
}

.format-size,
.format-color {
  display: flex;
  align-items: center;
  gap: 8px;
}

.format-size {
  min-width: 88px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.format-size span {
  font-size: 15px;
  font-weight: 700;
  color: #334155;
}

.format-size input {
  width: 52px;
  height: 36px;
  border: 0;
  background: transparent;
  color: #0f172a;
  font: inherit;
  text-align: center;
}

.format-size input:focus {
  outline: none;
}

.format-toggle {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #e2e8f0;
  color: #64748b;
  font: inherit;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.format-toggle.is-active {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  border-color: #1d4ed8;
  color: #fff;
  box-shadow: 0 0 0 4px rgb(37 99 235 / 15%);
  transform: translateY(-1px);
}

.format-underline {
  text-decoration: underline;
}

.format-color {
  margin-left: auto;
  width: 40px;
  height: 40px;
  justify-content: center;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
}

.format-color input {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  background: transparent;
}

.format-color input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.format-color input::-webkit-color-swatch {
  border: 0;
  border-radius: 999px;
}

.format-color input::-moz-color-swatch {
  border: 0;
  border-radius: 999px;
}

.resize-handles {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 9;
  pointer-events: none;
}

.resize-handle {
  position: absolute;
  padding: 0;
  margin: 0;
  min-width: 0;
  min-height: 0;
  border: 1px solid #0f766e;
  background: rgb(240 253 250 / 96%);
  box-shadow: 0 6px 16px rgb(15 118 110 / 18%);
  appearance: none;
  -webkit-appearance: none;
  pointer-events: auto;
}

.resize-handle-right {
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  border-radius: 999px;
  cursor: ew-resize;
  transform: translateX(50%);
}

.resize-handle-bottom {
  left: 0;
  bottom: 0;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  cursor: ns-resize;
  transform: translateY(50%);
}

.resize-handle-corner {
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 4px;
  background:
    linear-gradient(135deg, transparent 0 35%, #14b8a6 35% 45%, transparent 45% 60%, #14b8a6 60% 70%, transparent 70% 100%),
    rgb(240 253 250 / 98%);
  cursor: nwse-resize;
  transform: translate(35%, 35%);
}

.field-actions button {
  min-width: 64px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #e2e8f0;
  color: #64748b;
  font: inherit;
  font-size: 13px;
  transition:
    background 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.field-actions button:disabled {
  background: #e5e7eb;
  color: #94a3b8;
  border-color: #d1d5db;
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.field-actions button:not(:disabled):not(.is-active):hover {
  background: #cbd5e1;
  color: #334155;
}

#deleteButton:not(:disabled) {
  color: #b91c1c;
  border-color: rgb(248 113 113 / 45%);
}

#editButton.is-active,
#moveButton.is-active,
#resizeButton.is-active {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  border-color: #1d4ed8;
  box-shadow: 0 0 0 4px rgb(37 99 235 / 15%);
  transform: translateY(-1px);
}

#editButton:not(.is-active):hover,
#moveButton:not(.is-active):hover,
#resizeButton:not(.is-active):hover {
  background: #cbd5e1;
  color: #334155;
}

#editButton:disabled:hover,
#moveButton:disabled:hover,
#resizeButton:disabled:hover {
  background: #e5e7eb;
  color: #94a3b8;
}

@keyframes movePulse {
  0%,
  100% {
    box-shadow:
      0 0 0 4px rgb(37 99 235 / 16%),
      0 12px 28px rgb(37 99 235 / 14%);
  }

  50% {
    box-shadow:
      0 0 0 6px rgb(37 99 235 / 10%),
      0 14px 30px rgb(37 99 235 / 18%);
  }
}
