/* ============ Reset ============ */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f4;
  color: #1a1a1a;
  font-size: 14px;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

/* ============ Topbar ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 56px;
  background: #111;
  color: #fff;
  border-bottom: 1px solid #000;
  flex-shrink: 0;
}

.brand {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
}
.brand span {
  font-weight: 300;
  opacity: 0.7;
  margin-left: 4px;
}

.tabs {
  display: flex;
  gap: 4px;
}
.tab-btn {
  background: transparent;
  border: none;
  color: #aaa;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.15s;
}
.tab-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }
.tab-btn.active { color: #fff; background: rgba(255,255,255,0.15); }

.topbar-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ============ Buttons ============ */
.btn {
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.btn.primary {
  background: #fff;
  color: #111;
  border-color: #fff;
}
.btn.primary:hover { background: #f0f0f0; }
.btn.ghost {
  background: transparent;
  color: #fff;
  border-color: rgba(255,255,255,0.3);
}
.btn.ghost:hover { background: rgba(255,255,255,0.1); }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 24px;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  color: #666;
}
.icon-btn:hover { background: #f0f0f0; color: #111; }

/* ============ Layout ============ */
.layout {
  display: flex;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.editor {
  width: 42%;
  min-width: 380px;
  background: #fff;
  overflow-y: auto;
  border-right: 1px solid #e0e0e0;
  padding: 20px 24px 40px;
}

.preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f5f5f4;
  overflow: hidden;
}

/* ============ Editor (form) ============ */
.editor h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #888;
  margin: 24px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #eee;
}
.editor h3:first-child { margin-top: 4px; }

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #444;
  margin-bottom: 4px;
}
.field .hint {
  font-size: 11px;
  color: #888;
  font-weight: 400;
  margin-left: 6px;
}
.field input[type="text"],
.field input[type="url"],
.field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  background: #fff;
  transition: border-color 0.15s;
}
.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: #1a73e8;
}
.field textarea {
  resize: vertical;
  min-height: 60px;
}
.field input::placeholder,
.field textarea::placeholder {
  color: #b0b0b0;
}

.field-row {
  display: flex;
  gap: 10px;
}
.field-row .field { flex: 1; }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #f9f9f9;
  border: 1px solid #e6e6e6;
  border-radius: 4px;
  margin-bottom: 16px;
}
.checkbox-field input { margin: 0; }
.checkbox-field label {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: #111;
  cursor: pointer;
}

.group-block {
  background: #fafafa;
  border: 1px solid #e6e6e6;
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.group-block.disabled {
  opacity: 0.5;
  pointer-events: none;
}
.group-block-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: #555;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e6e6e6;
}

/* ============ Preview ============ */
.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}
.preview-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #888;
}
.preview-status {
  font-size: 11px;
  color: #4caf50;
  margin-left: 8px;
}
.preview-status.saving { color: #ff9800; }

.preview-frame-wrap {
  flex: 1;
  overflow: hidden;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.scaler {
  width: 600px;
  transform-origin: top left;
  flex-shrink: 0;
}
#previewFrame {
  width: 600px;
  height: 1400px;
  border: 1px solid #ddd;
  background: #fff;
  display: block;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* ============ Modal ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  background: #fff;
  border-radius: 8px;
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.modal-body {
  padding: 16px 20px;
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#generatedHtml {
  width: 100%;
  flex: 1;
  min-height: 360px;
  padding: 12px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 12px;
  border: 1px solid #d0d0d0;
  border-radius: 4px;
  resize: none;
}
.modal-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #888;
}
.modal-info #missingInfo { color: #c62828; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid #e0e0e0;
}
.modal-footer .btn.primary {
  background: #111;
  color: #fff;
}
.modal-footer .btn.primary:hover { background: #333; }
.modal-footer .btn.ghost {
  color: #1a73e8;
  border-color: #1a73e8;
}
.modal-footer .btn.ghost:hover { background: #f0f7ff; }
