/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Primary palette — refined indigo-blue with warm accents */
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: #EEF2FF;
  --primary-glow: rgba(79, 70, 229, 0.15);
  --primary-gradient: linear-gradient(135deg, #4F46E5 0%, #6366F1 100%);
  --secondary: #8B5CF6;
  --secondary-light: #F5F3FF;

  /* Semantic */
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --danger-light: #FEF2F2;
  --success: #10B981;
  --success-light: #ECFDF5;
  --warning: #F59E0B;
  --warning-light: #FFFBEB;

  /* Surfaces & depth */
  --bg: #F8FAFC;
  --bg-warm: #F1F5F9;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --border: #E2E8F0;
  --border-hover: #A5B4FC;
  --border-focus: #818CF8;

  /* Text hierarchy */
  --text: #0F172A;
  --text-body: #334155;
  --text-muted: #64748B;
  --text-faint: #94A3B8;

  /* Sizing & layout */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.05), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.08), 0 8px 10px -6px rgba(0,0,0,.04);
  --shadow-xl: 0 20px 40px -10px rgba(0,0,0,.12);
  --shadow-glow: 0 0 0 3px var(--primary-glow), 0 4px 12px rgba(79,70,229,.12);
  --sidebar-width: 380px;
  --toolbar-height: 60px;

  /* Motion — snappy spring-like curves */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-fast: 150ms var(--ease-out);
  --transition-normal: 250ms var(--ease-out);
  --transition-slow: 350ms var(--ease-out);
  --transition-spring: 400ms var(--ease-spring);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Smooth scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Keyframe animations */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes scaleOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.95); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(20px); }
}

@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes successPulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes subtleBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

/* ===== App Layout ===== */
.app-body {
  display: flex;
  min-height: calc(100vh - var(--toolbar-height));
  position: relative;
}

/* ===== Toolbar ===== */
.toolbar {
  background: var(--surface);
  height: var(--toolbar-height);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.03), 0 1px 0 rgba(0,0,0,.03);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.92);
}

.toolbar-left { display: flex; align-items: center; gap: 10px; }
.toolbar-left h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.3px;
}

.toolbar-center { display: flex; align-items: center; gap: 4px; }

.toolbar-btn-group { display: flex; gap: 4px; }

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 8px;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-status {
  font-size: 12px;
  color: var(--text-faint);
  transition: all var(--transition-normal);
  padding: 4px 10px;
  border-radius: 9999px;
  background: var(--bg);
}

.save-status.saving {
  color: var(--warning);
  background: var(--warning-light);
}

.save-status.saved {
  color: var(--success);
  background: var(--success-light);
  animation: successPulse 0.6s ease-out;
}

.template-indicator {
  font-size: 12px;
  padding: 4px 12px;
  background: var(--primary-light);
  border: 1px solid rgba(79, 70, 229, 0.15);
  border-radius: 9999px;
  color: var(--primary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.template-indicator:hover {
  background: rgba(79, 70, 229, 0.12);
}

/* ===== Buttons ===== */
.btn {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  font-family: inherit;
  position: relative;
  letter-spacing: 0.01em;
}

.btn:active {
  transform: scale(0.97);
  transition-duration: 80ms;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-primary:hover {
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35), inset 0 1px 0 rgba(255,255,255,0.15);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background: var(--bg-warm);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--border);
  border-color: transparent;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-body);
}
.btn-outline:hover {
  background: var(--primary-light);
  border-color: var(--border-hover);
  color: var(--primary);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger) 0%, #DC2626 100%);
  color: #fff;
  box-shadow: 0 1px 3px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
  transform: translateY(-1px);
}

.btn-sm { padding: 5px 12px; font-size: 12px; border-radius: var(--radius-sm); }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
  transform: scale(1.1);
}

.btn-icon:active {
  transform: scale(0.95);
}

/* ===== Form Canvas ===== */
.form-canvas {
  flex: 1;
  max-width: 880px;
  margin: 28px auto;
  padding: 0 20px;
  min-height: 400px;
  transition: margin-right var(--transition-slow);
}

body.sidebar-open .form-canvas {
  margin-right: calc(var(--sidebar-width) + 20px);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 72px 24px;
  color: var(--text-muted);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  animation: fadeInUp 0.5s var(--ease-out);
  transition: border-color var(--transition-normal), background var(--transition-normal);
}

.empty-state:hover {
  border-color: var(--border-hover);
  background: var(--primary-light);
}

.empty-state-icon {
  font-size: 56px;
  margin-bottom: 20px;
  opacity: 0.7;
  animation: subtleBounce 2s ease-in-out infinite;
}

.empty-state h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.3px;
}

.empty-state p {
  font-size: 14px;
  max-width: 400px;
  margin: 0 auto;
  color: var(--text-muted);
  line-height: 1.6;
}

.quick-start-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.quick-start-links .text-muted {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Field Group ===== */
.field-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition-normal), border-color var(--transition-normal), transform var(--transition-normal);
  animation: fadeInUp 0.4s var(--ease-out) both;
}

.field-group:hover {
  box-shadow: var(--shadow-md);
}

.field-group.sortable-ghost {
  opacity: 0.95;
  box-shadow: var(--shadow-xl);
  transform: rotate(1.5deg) scale(1.02);
  border-color: var(--border-hover);
}

.field-group.sortable-chosen {
  box-shadow: var(--shadow-glow);
}

.field-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-warm) 100%);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transition: background var(--transition-fast);
}

.field-group-header:hover {
  background: linear-gradient(180deg, var(--primary-light) 0%, var(--bg-warm) 100%);
}

.drag-handle {
  color: var(--text-faint);
  font-size: 18px;
  cursor: grab;
  user-select: none;
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.field-group-header:hover .drag-handle,
.field-card-header:hover .drag-handle {
  opacity: 0.7;
}

.drag-handle:hover { opacity: 1 !important; color: var(--primary); transform: scale(1.15); }
.drag-handle:active { cursor: grabbing; transform: scale(1.05); }

.field-group-name {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  letter-spacing: -0.2px;
}

.field-group-name input {
  border: none;
  background: transparent;
  font: inherit;
  color: inherit;
  width: 100%;
  outline: none;
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  margin: -2px -6px;
  transition: all var(--transition-fast);
}

.field-group-name input:hover {
  background: rgba(255,255,255,0.6);
}

.field-group-name input:focus {
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--primary-glow), inset 0 0 0 1px var(--primary);
}

.field-group-actions { display: flex; gap: 4px; align-items: center; }

.field-group-body {
  padding: 14px 18px;
  min-height: 40px;
  max-height: 2000px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 300ms var(--ease-out), opacity 200ms var(--ease-out), padding 300ms var(--ease-out);
}

.field-group-body.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  min-height: 0;
  overflow: hidden;
}

.field-group-body .empty-fields {
  text-align: center;
  padding: 24px;
  color: var(--text-faint);
  font-size: 13px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  transition: all var(--transition-normal);
}

.field-group-body .empty-fields:hover {
  border-color: var(--border-hover);
  color: var(--primary);
  background: var(--primary-light);
}

/* ===== Field Card ===== */
.field-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: all var(--transition-normal);
  animation: fadeInUp 0.35s var(--ease-out) both;
}

.field-card:hover {
  border-color: var(--border-hover);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.08), 0 1px 3px rgba(0,0,0,.04);
  transform: translateY(-1px);
}

.field-card.selected {
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}

.field-card.sortable-ghost {
  box-shadow: var(--shadow-xl);
  opacity: 0.95;
  transform: rotate(2deg) scale(1.03);
  border-color: var(--primary);
}

.field-card.sortable-chosen {
  box-shadow: var(--shadow-glow);
  z-index: 10;
}

.field-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
}

.field-type-badge {
  font-size: 10px;
  padding: 3px 9px;
  border-radius: 9999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  white-space: nowrap;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

/* Color-coded field type badges — richer tones with subtle borders */
.badge-free-text-short { background: #EEF2FF; color: #4F46E5; border-color: rgba(79,70,229,0.12); }
.badge-free-text-long  { background: #EEF2FF; color: #4F46E5; border-color: rgba(79,70,229,0.12); }
.badge-multiple-option  { background: #F5F3FF; color: #7C3AED; border-color: rgba(124,58,237,0.12); }
.badge-date             { background: #FFF7ED; color: #EA580C; border-color: rgba(234,88,12,0.12); }
.badge-calculated       { background: #ECFDF5; color: #059669; border-color: rgba(5,150,105,0.12); }
.badge-auto-number      { background: #F0FDFA; color: #0D9488; border-color: rgba(13,148,136,0.12); }
.badge-attachment       { background: #FFF1F2; color: #E11D48; border-color: rgba(225,29,72,0.12); }
.badge-information      { background: #F8FAFC; color: #475569; border-color: rgba(71,85,105,0.1); }

.field-card-label {
  flex: 1;
  font-weight: 500;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.1px;
}

.field-card-meta {
  display: flex;
  gap: 6px;
  align-items: center;
}

.meta-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 9999px;
  background: var(--danger-light);
  color: var(--danger);
  font-weight: 600;
  letter-spacing: 0.2px;
  border: 1px solid rgba(239, 68, 68, 0.15);
}

.meta-tag.optional {
  background: var(--bg-warm);
  color: var(--text-muted);
  border-color: var(--border);
}

.field-card-details {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 13px;
  max-height: 500px;
  opacity: 1;
  overflow: hidden;
  transition: max-height 250ms var(--ease-out), opacity 200ms var(--ease-out), padding 250ms var(--ease-out);
}

.field-card-details.collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top-color: transparent;
  overflow: hidden;
}

.field-detail-row {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.field-detail-row .label {
  font-weight: 600;
  color: var(--text-faint);
  min-width: 120px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ===== Field Settings Sidebar ===== */
.field-sidebar {
  position: fixed;
  top: var(--toolbar-height);
  right: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0,0,0,.06);
  transform: translateX(100%);
  transition: transform var(--transition-slow);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.field-sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg) 100%);
}

.sidebar-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
  padding: 0 6px;
  gap: 2px;
}

.sidebar-tab {
  flex: 1;
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-normal);
  font-family: inherit;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  position: relative;
}

.sidebar-tab:hover {
  color: var(--text);
  background: var(--surface);
}

.sidebar-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--surface);
  font-weight: 600;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
}

.sidebar-tab-panel {
  display: none;
}

.sidebar-tab-panel.active {
  display: block;
  animation: fadeIn 0.25s var(--ease-out);
}

/* Backend name auto-generated display */
.backend-name-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--bg-warm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  margin-top: 4px;
  transition: all var(--transition-fast);
}

.backend-name-display:hover {
  border-color: var(--border-hover);
}

.backend-name-display .edit-link {
  font-size: 12px;
  color: var(--primary);
  cursor: pointer;
  font-family: inherit;
  margin-left: auto;
}

.backend-name-display .edit-link:hover {
  text-decoration: underline;
}

.backend-name-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s var(--ease-out);
}

.modal-overlay.hidden { display: none; }

.modal-overlay.closing {
  animation: fadeOut 0.2s var(--ease-out) forwards;
  pointer-events: none;
}

.modal-overlay.closing .modal {
  animation: scaleOut 0.2s var(--ease-out) forwards;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0,0,0,.05);
  animation: scaleIn 0.3s var(--ease-spring);
}

.modal-wide { width: 750px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
  background: var(--bg);
  transform: scale(1.1);
}

.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--bg);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ===== Form Elements ===== */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.form-group .hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-top: 4px;
  line-height: 1.5;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal), background var(--transition-fast);
  color: var(--text-body);
  background: var(--surface);
}

input[type="text"]:hover,
input[type="number"]:hover,
textarea:hover,
select:hover {
  border-color: var(--border-hover);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
  background: var(--surface);
}

textarea { resize: vertical; min-height: 80px; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.checkbox-row:hover {
  background: var(--bg);
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  border-radius: 4px;
  cursor: pointer;
}

.checkbox-row label {
  font-size: 14px;
  margin-bottom: 0;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

/* Options list for Multiple Option */
.options-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 4px;
  background: var(--bg);
}

.option-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  animation: fadeInUp 0.2s var(--ease-out) both;
}

.option-item input {
  flex: 1;
  background: var(--surface);
}

.option-item .btn-icon { color: var(--danger); }

/* ===== Preview ===== */
.preview-group {
  margin-bottom: 28px;
  animation: fadeInUp 0.4s var(--ease-out) both;
}

.preview-group h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary);
  color: var(--text);
  letter-spacing: -0.2px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.preview-field {
  margin-bottom: 18px;
  animation: fadeInUp 0.3s var(--ease-out) both;
}

.preview-field label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}

.preview-field label .required { color: var(--danger); }

.preview-field .description {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.preview-field input,
.preview-field textarea,
.preview-field select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: all var(--transition-normal);
}

.preview-field input:focus,
.preview-field textarea:focus,
.preview-field select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
  outline: none;
}

.preview-field .info-text {
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 14px;
  color: var(--primary-hover);
  line-height: 1.6;
}

.preview-field .calculated-display {
  background: var(--bg-warm);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.preview-field .auto-number-display {
  background: var(--bg-warm);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  border: 1px solid var(--border);
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ===== Template Status (compact) ===== */
.template-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 28px;
  background: linear-gradient(90deg, var(--primary-light), rgba(238, 242, 255, 0.5));
  border-bottom: 1px solid rgba(79, 70, 229, 0.1);
  font-size: 13px;
  flex-wrap: wrap;
  animation: fadeIn 0.3s var(--ease-out);
}

.template-filename { font-weight: 600; color: var(--primary); }

/* ===== Template Mapping ===== */
.mapping-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: var(--radius);
  overflow: hidden;
}

.mapping-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}

.mapping-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  transition: background var(--transition-fast);
}

.mapping-row.matched { background: var(--success-light); }
.mapping-row.unmatched { background: var(--warning-light); }

.mapping-row:hover td {
  background: var(--bg);
}

.mapping-status {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 8px;
}

.mapping-status.matched { background: var(--success); box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15); }
.mapping-status.unmatched { background: var(--warning); box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.15); }

.mapping-progress {
  padding: 12px 0;
  font-size: 14px;
  font-weight: 600;
}

.mapping-progress-bar {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}

.mapping-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #34D399);
  border-radius: 3px;
  transition: width 0.6s var(--ease-out);
}

/* ===== Validation States ===== */
.preview-field input.invalid,
.preview-field textarea.invalid,
.preview-field select.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
  animation: shake 0.4s var(--ease-out);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.preview-field .validation-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  animation: fadeInUp 0.2s var(--ease-out);
}

/* ===== Quick Start Buttons ===== */
.quick-start-links .btn-outline {
  transition: all var(--transition-normal);
}

.quick-start-links .btn-outline:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ===== Selection & Focus Rings ===== */
::selection {
  background: rgba(79, 70, 229, 0.15);
  color: var(--text);
}

/* ===== Toast / Snackbar ===== */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  max-width: 480px;
  min-width: 280px;
  animation: toastIn 0.2s var(--ease-out);
  border-left: 3px solid transparent;
}

.toast.exiting {
  animation: toastOut 0.15s ease-in forwards;
}

.toast-info    { border-left-color: var(--primary); }
.toast-success { border-left-color: var(--success); }
.toast-error   { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }

.toast-message { flex: 1; }

.toast-action {
  background: none;
  border: none;
  color: #A5B4FC;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  font-family: inherit;
  padding: 0;
  white-space: nowrap;
}

.toast-action:hover {
  color: #C7D2FE;
}

.toast-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 16px;
  cursor: pointer;
  padding: 0 0 0 4px;
  line-height: 1;
}

.toast-close:hover {
  color: #fff;
}

/* ===== Tooltips ===== */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--text);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms var(--ease-out) 300ms, transform 150ms var(--ease-out) 300ms;
  z-index: 200;
  line-height: 1.4;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-delay: -1ms !important;
    transition-duration: 1ms !important;
  }
  html { scroll-behavior: auto !important; }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .toolbar {
    height: auto;
    padding: 12px 16px;
    flex-direction: column;
    gap: 8px;
  }
  .toolbar-center { flex-wrap: wrap; justify-content: center; }
  .toolbar-divider { display: none; }
  .field-sidebar {
    width: 100%;
    top: auto;
    bottom: 0;
    height: 60vh;
    border-left: none;
    border-top: 1px solid var(--border);
    transform: translateY(100%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .field-sidebar.open { transform: translateY(0); }
  body.sidebar-open .form-canvas { margin-right: 0; }
}
