* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: #1f2430;
  background: #f3f4f6;
}

.btn {
  padding: 6px 12px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.btn:hover { background: #f9fafb; }
.btn:active { background: #f3f4f6; }
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: #fff;
}
.btn-primary {
  background: #4f46e5;
  border-color: #4f46e5;
  color: #fff;
}
.btn-primary:hover { background: #4338ca; }
.btn-primary:active { background: #3730a3; }
.cloud-bar { display: flex; align-items: center; gap: 6px; }
.cloud-status {
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.license-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  background: #1f2430;
}
body.gate-active .license-gate { display: flex; }
body.gate-active .topbar,
body.gate-active .app-body { display: none; }

.license-gate-box {
  width: 340px;
  max-width: calc(100vw - 48px);
  padding: 32px;
  border-radius: 12px;
  background: #fff;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
}
.license-gate-box h1 { margin: 0 0 8px; font-size: 20px; }
.license-gate-box p { margin: 0 0 20px; color: #6b7280; font-size: 14px; }
.license-gate-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}
.license-gate-box .btn-primary { width: 100%; padding: 10px 12px; }
.license-error {
  color: #b91c1c;
  font-size: 13px;
  margin: 12px 0 0;
}
.license-buy-link {
  display: block;
  margin-top: 16px;
  font-size: 13px;
  color: #4f46e5;
}
.btn-icon {
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  height: 48px;
}
.project-name-input {
  font-size: 15px;
  font-weight: 600;
  border: 1px solid transparent;
  padding: 4px 6px;
  border-radius: 6px;
  width: 160px;
}
.project-name-input:hover, .project-name-input:focus {
  border-color: #d1d5db;
  outline: none;
}
.screens-bar {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
}
.topbar-right {
  display: flex;
  gap: 8px;
}

/* Screens tabs */
.screen-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 6px;
  background: #f3f4f6;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.screen-tab.active {
  background: #eef2ff;
  border-color: #4f46e5;
  color: #4338ca;
}
.screen-tab .del-x {
  color: #9ca3af;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
}
.screen-tab .del-x:hover { color: #dc2626; }
.screen-tab { transition: background-color 0.12s ease, border-color 0.12s ease; }

/* App body layout */
.app-body {
  display: grid;
  grid-template-columns: 220px 1fr 300px;
  height: calc(100vh - 48px);
}

/* Palette */
.palette {
  border-right: 1px solid #e5e7eb;
  background: #fff;
  padding: 12px;
  overflow-y: auto;
}
.palette h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: #9ca3af;
  margin: 16px 0 8px;
}
.palette h3:first-child { margin-top: 0; }
.palette-item {
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f9fafb;
  cursor: grab;
  font-size: 13px;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}
.palette-item:hover { background: #eef2ff; border-color: #c7d2fe; }
.palette-item:active { cursor: grabbing; }
.template-item {
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
.template-item:hover { background: #f9fafb; }

/* Canvas */
.canvas-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  overflow: auto;
  background: #f3f4f6;
}
.canvas {
  position: relative;
  width: 375px;
  min-height: 700px;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  overflow: hidden;
}
.canvas.drag-over {
  outline: 2px dashed #4f46e5;
  outline-offset: -2px;
}

.canvas-empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  color: #9ca3af;
  font-size: 13px;
  pointer-events: none;
}

.screen-element {
  position: absolute;
  border: none;
  border-radius: 6px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: box-shadow 0.1s ease;
}
.screen-element:hover {
  box-shadow: 0 0 0 1px rgba(0, 122, 255, 0.4);
}
.screen-element.selected {
  outline: 2px solid #007AFF;
  outline-offset: 1px;
}
.screen-element.dragging,
.screen-element.resizing {
  cursor: grabbing;
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
  z-index: 10;
  opacity: 0.92;
}

/* Content wrapper clips overflow so the resize handle (positioned just
   outside the element's own box) never gets clipped along with it. */
.element-content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 400;
  white-space: pre-wrap;
  display: flex;
  align-items: center;
}

/* Type-specific looks, iOS-flavored */
.el-type-text .element-content {
  padding: 0;
  font-size: 15px;
  color: #1C1C1E;
}

.el-type-input { border-radius: 10px; }
.el-type-input .element-content { font-size: 15px; }

.el-type-button {
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}
.el-type-button .element-content {
  justify-content: center;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.1px;
}

.el-type-link .element-content {
  padding: 0;
  font-size: 15px;
  font-weight: 500;
}

.el-type-card {
  border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.el-type-card .element-content {
  align-items: flex-start;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
}

.el-type-navbar {
  border-radius: 0;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.08);
}
.el-type-navbar .element-content {
  justify-content: center;
  font-size: 17px;
  font-weight: 600;
}

.el-type-image { border-radius: 10px; }
.el-type-image .element-content {
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.image-caption {
  font-size: 11px;
  color: #8E8E93;
}

.el-type-list { border-radius: 12px; }
.el-type-list .element-content {
  flex-direction: column;
  align-items: stretch;
  padding: 0;
  overflow: auto;
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  font-size: 15px;
  border-bottom: 1px solid rgba(60, 60, 67, 0.1);
  flex: none;
}
.list-row:last-child { border-bottom: none; }
.list-chevron {
  color: #C7C7CC;
  font-size: 15px;
  margin-left: 8px;
}

.el-type-tabbar {
  box-shadow: inset 0 1px 0 rgba(0,0,0,0.08);
}
.el-type-tabbar .element-content {
  padding: 0;
  align-items: stretch;
}
.tab-segment {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  color: inherit;
}
.tab-segment.active { color: #007AFF; font-weight: 600; }

.el-type-checkbox { position: relative; }
.el-type-checkbox .element-content {
  padding-right: 60px;
  font-size: 15px;
}
.el-type-checkbox::before {
  content: '';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 24px;
  border-radius: 12px;
  background: #34C759;
}
.el-type-checkbox::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}

.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: transparent;
  cursor: nwse-resize;
  display: none;
}
.resize-handle::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  background: #007AFF;
  border: 2px solid #fff;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
}
.screen-element.selected .resize-handle {
  display: block;
}

/* Properties panel */
.properties {
  border-left: 1px solid #e5e7eb;
  background: #fff;
  padding: 14px;
  overflow-y: auto;
}
.properties h3 {
  font-size: 13px;
  margin: 0 0 12px;
}
.field {
  margin-bottom: 12px;
}
.field label {
  display: block;
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 4px;
}
.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.field input[type="text"]:focus,
.field input[type="number"]:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.field input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
}
.field textarea { resize: vertical; min-height: 50px; }
.field-row {
  display: flex;
  gap: 8px;
}
.field-row .field { flex: 1; }
.empty-hint {
  color: #9ca3af;
  font-size: 13px;
}
.delete-el-btn {
  width: 100%;
  padding: 8px;
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #dc2626;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  margin-top: 8px;
}
.delete-el-btn:hover { background: #fee2e2; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #fff;
  border-radius: 10px;
  width: 560px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid #e5e7eb;
}
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-body {
  padding: 18px;
  overflow-y: auto;
}
.modal-body.hidden { display: none; }
.stack-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 18px;
  font-size: 13px;
}
#export-output {
  width: 100%;
  height: 340px;
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 12px;
  padding: 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
}
.export-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
