/* FormPing Dashboard — Form Builder */
:root {
  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #64748b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ---- Header ---- */
.fp-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.fp-header-back {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.fp-header-back:hover { color: var(--brand); }
.fp-header-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}
.fp-header-actions {
  display: flex;
  gap: 8px;
}

/* ---- Buttons ---- */
.fp-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  font-family: inherit;
}
.fp-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.fp-btn-primary { background: var(--brand); color: #fff; }
.fp-btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.fp-btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.fp-btn-secondary:hover:not(:disabled) { background: var(--bg); }
.fp-btn-danger { background: var(--danger); color: #fff; }
.fp-btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.fp-btn-sm { padding: 4px 10px; font-size: 12px; }

/* ---- Layout ---- */
.fp-layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  height: calc(100vh - 53px);
  overflow: hidden;
}

.fp-panel {
  overflow-y: auto;
  padding: 16px;
  border-right: 1px solid var(--border);
}
.fp-panel:last-child { border-right: none; }
.fp-panel-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ---- Left: Field Palette ---- */
.fp-palette-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 24px;
}
.fp-palette-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.fp-palette-btn:hover {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
}
.fp-palette-icon {
  font-size: 20px;
  line-height: 1;
}

/* ---- Center: Preview ---- */
.fp-preview-area {
  background: var(--bg);
  display: flex;
  justify-content: center;
  padding: 32px 16px;
  overflow-y: auto;
}
.fp-preview-form {
  width: 100%;
  max-width: 480px;
  padding: 24px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-family: inherit;
}
.fp-preview-field {
  margin-bottom: 16px;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .15s;
}
.fp-preview-field:hover { border-color: rgba(79, 70, 229, 0.2); }
.fp-preview-field.fp-selected { border-color: var(--brand); background: rgba(79, 70, 229, 0.04); }
.fp-preview-field.sortable-ghost { opacity: 0.4; }
.fp-preview-field.sortable-chosen { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }

.fp-preview-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}
.fp-preview-input,
.fp-preview-textarea,
.fp-preview-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 14px;
  background: #f7fafc;
  color: var(--text);
  font-family: inherit;
  pointer-events: none;
}
.fp-preview-textarea { min-height: 80px; resize: none; }
.fp-preview-select { appearance: none; }
.fp-preview-radio-group,
.fp-preview-checkbox-group { display: flex; flex-direction: column; gap: 6px; }
.fp-preview-radio-label,
.fp-preview-checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  pointer-events: none;
}
.fp-preview-radio-label input,
.fp-preview-checkbox-label input {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}
.fp-preview-submit {
  width: 100%;
  padding: 10px;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: default;
  margin-top: 8px;
}
.fp-preview-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 14px;
}
.fp-preview-compact .fp-preview-field { margin-bottom: 8px; }

/* ---- Right: Properties Panel ---- */
.fp-props { padding: 16px; }
.fp-props-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 32px 0;
}
.fp-props-group {
  margin-bottom: 16px;
}
.fp-props-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.fp-props-input,
.fp-props-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.fp-props-input:focus,
.fp-props-select:focus { outline: none; border-color: var(--brand); }
.fp-props-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}
.fp-props-toggle label {
  font-size: 14px;
  cursor: pointer;
}

/* Toggle switch */
.fp-switch {
  position: relative;
  width: 40px;
  height: 22px;
}
.fp-switch input { opacity: 0; width: 0; height: 0; }
.fp-switch-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e0;
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}
.fp-switch-slider::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.fp-switch input:checked + .fp-switch-slider { background: var(--brand); }
.fp-switch input:checked + .fp-switch-slider::before { transform: translateX(18px); }

/* Options list */
.fp-options-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.fp-option-row {
  display: flex;
  gap: 4px;
  align-items: center;
}
.fp-option-row input {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.fp-option-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
  line-height: 1;
}

/* ---- Design Panel ---- */
.fp-design-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.fp-design-section:last-child { border-bottom: none; }
.fp-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.fp-color-row label {
  flex: 1;
  font-size: 13px;
}
.fp-color-input {
  width: 36px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: none;
}

/* ---- Separator ---- */
.fp-separator {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* ---- Modal ---- */
.fp-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.fp-modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.fp-modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}
.fp-modal-close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}
.fp-code-block {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px;
  border-radius: 8px;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-bottom: 12px;
  position: relative;
}
.fp-code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.1);
  color: #cdd6f4;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.fp-code-copy:hover { background: rgba(255,255,255,0.2); }
.fp-code-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ---- Toast ---- */
.fp-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .3s, transform .3s;
}
.fp-toast-show { opacity: 1; transform: translateY(0); }
.fp-toast-success { background: #166534; color: #fff; }
.fp-toast-error { background: #991b1b; color: #fff; }

/* ---- Token Select ---- */
.fp-token-select {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 0;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #f0fdf4 100%);
}
.fp-token-header {
  width: 100%;
  padding: 32px 24px 0;
  text-align: center;
}
.fp-token-header h2 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 4px;
}
.fp-token-header p {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 24px;
}
.fp-token-header-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
}
.fp-token-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  width: 100%;
  max-width: 640px;
  padding: 0 24px 48px;
}
.fp-token-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.fp-token-item:hover {
  border-color: var(--brand);
  box-shadow: 0 4px 16px rgba(79,70,229,.1);
  transform: translateY(-2px);
}
.fp-token-item-label {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}
.fp-token-item-id {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 4px;
}
.fp-token-item-arrow {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  flex-shrink: 0;
  transition: background .2s, color .2s;
}
.fp-token-item:hover .fp-token-item-arrow {
  background: var(--brand);
  color: #fff;
}

/* ---- Stepper ---- */
.fp-stepper-row {
  display: flex;
  align-items: center;
  gap: 0;
}
.fp-stepper-btn {
  width: 32px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  transition: background .15s;
}
.fp-stepper-btn:first-child { border-radius: 6px 0 0 6px; }
.fp-stepper-btn:last-child { border-radius: 0 6px 6px 0; }
.fp-stepper-btn:hover { background: var(--bg); }
.fp-stepper-input {
  flex: 1;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-left: none;
  border-right: none;
  font-size: 14px;
  font-family: inherit;
  text-align: center;
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}
.fp-stepper-input:focus { outline: none; border-color: var(--brand); }

/* ---- Preview Grid ---- */
.fp-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}
.fp-preview-grid .fp-preview-field[data-width="full"] {
  grid-column: 1 / -1;
}
.fp-preview-grid .fp-preview-field[data-width="half"] {
  grid-column: span 1;
}

/* ---- Auth Screen ---- */
.fp-auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #eef2ff 0%, #f8fafc 50%, #f0fdf4 100%);
}
.fp-auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.fp-auth-card h2 {
  margin-bottom: 4px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--brand), #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.fp-auth-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
  transition: border-color .2s, box-shadow .2s;
}
.fp-auth-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
  background: var(--surface);
}
.fp-auth-btn {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 4px;
  letter-spacing: 0.02em;
  transition: background .2s, transform .1s, box-shadow .2s;
}
.fp-auth-btn:hover:not(:disabled) {
  box-shadow: 0 2px 12px rgba(79, 70, 229, 0.25);
}
.fp-auth-btn:active:not(:disabled) {
  transform: scale(0.985);
}
.fp-auth-error {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 14px;
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ---- Segmented Buttons ---- */
.fp-segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.fp-segmented-btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
  font-weight: 500;
}
.fp-segmented-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}
.fp-segmented-btn:hover {
  background: #f1f5f9;
}
.fp-segmented-active {
  background: var(--brand) !important;
  color: #fff !important;
  font-weight: 600;
}

/* ---- Preset Themes Grid ---- */
.fp-presets-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.fp-preset-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: all .15s;
  font-family: inherit;
}
.fp-preset-btn:hover {
  border-color: var(--brand);
  box-shadow: 0 0 0 1px var(--brand);
}
.fp-preset-swatch {
  width: 40px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fp-preset-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.fp-preset-name {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---- Preview: Title & Description ---- */
.fp-preview-title {
  font-size: 1.3em;
  font-weight: 700;
  margin: 0 0 4px 0;
  line-height: 1.3;
}
.fp-preview-description {
  font-size: 0.95em;
  opacity: 0.75;
  margin: 0 0 16px 0;
  line-height: 1.5;
}

/* ---- Preview: Label Left ---- */
.fp-preview-field.fp-label-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.fp-preview-field.fp-label-left .fp-preview-label {
  min-width: 80px;
  margin-bottom: 0;
}

/* ---- Preview: Floating Labels ---- */
.fp-floating-wrapper {
  position: relative;
}
.fp-floating-label {
  display: none !important;
}
.fp-float-text {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  opacity: 0.5;
  pointer-events: none;
  transition: all .2s;
}

/* ---- Preview: Input Style Variants ---- */
.fp-preview-input.fp-input-filled,
.fp-preview-textarea.fp-input-filled,
.fp-preview-select.fp-input-filled {
  border: none;
}
.fp-preview-input.fp-input-underlined,
.fp-preview-textarea.fp-input-underlined,
.fp-preview-select.fp-input-underlined {
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  background: transparent;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .fp-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .fp-panel { border-right: none; border-bottom: 1px solid var(--border); }
}
