/* ═══════════════════════════════════════════════════════════════
   FormSync Designer — Canvas-based visual form builder
   ═══════════════════════════════════════════════════════════════ */

.fsd-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #f1f5f9;
  display: flex;
  flex-direction: column;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Inline mode: respect topbar & sidebar (MotorSync pages) */
.fsd-overlay.fsd-inline {
  top: var(--topbar-h, 50px);
  left: var(--sidebar-w, 230px);
  right: 0;
  bottom: 0;
  z-index: 900;
}
@media (max-width: 768px) {
  .fsd-overlay.fsd-inline { left: 0; }
}

/* ── Toolbar ── */
.fsd-toolbar {
  height: 52px;
  background: white;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.fsd-toolbar-left,
.fsd-toolbar-center,
.fsd-toolbar-right { display: flex; align-items: center; gap: 10px; }

.fsd-btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  background: white;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #374151;
  transition: all .15s;
}
.fsd-btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.fsd-btn-primary {
  background: var(--verdi-light, #02735E);
  color: white;
  border-color: var(--verdi-light, #02735E);
}
.fsd-btn-primary:hover { opacity: .9; }
.fsd-btn-ghost {
  background: none;
  border-color: transparent;
}
.fsd-btn-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #64748b;
  padding: 4px 8px;
  border-radius: 4px;
}
.fsd-btn-close:hover { color: #0f172a; background: #f1f5f9; }

/* ── Three-column layout ── */
.fsd-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── Right palette ── */
.fsd-palette {
  width: 240px;
  background: white;
  border-left: 1px solid #e2e8f0;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 12px;
}
.fsd-palette-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #0f172a;
  padding: 4px 4px 8px;
  border-bottom: 1px solid #f1f5f9;
  margin-bottom: 8px;
}
.fsd-palette-section { margin-bottom: 14px; }
.fsd-palette-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 4px;
  padding: 0 4px;
}
.fsd-palette-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  margin-bottom: 3px;
  cursor: grab;
  font-size: 12px;
  color: #374151;
  background: white;
  transition: all .15s;
  user-select: none;
}
.fsd-palette-item:hover { border-color: #e2e8f0; background: #f8fafc; }
.fsd-palette-item:active { cursor: grabbing; }
.fsd-palette-item .fsd-pi-icon {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}
.fsd-palette-item .fsd-pi-label { font-weight: 500; font-size: 11px; }
.fsd-palette-item.fsd-dragging-source { opacity: .4; }

/* ── Canvas area ── */
.fsd-canvas-area {
  flex: 1;
  overflow: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #e8ecf1;
  background-image: radial-gradient(circle, #d4d8de 0.5px, transparent 0.5px);
  background-size: 20px 20px;
}

/* ── Paper ── */
.fsd-paper {
  width: 816px;
  height: 1056px;
  background: white;
  border-radius: 3px;
  box-shadow: 0 4px 24px rgba(0,0,0,.12), 0 1px 3px rgba(0,0,0,.06);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Paper header */
.fsd-paper-header {
  padding: 28px 40px 14px;
  border-bottom: 3px solid var(--verdi-light, #02735E);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
}
.fsd-header-left { display: flex; align-items: center; gap: 14px; }
.fsd-header-logo {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  border: 2px dashed #d1d5db;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 9px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  overflow: hidden;
  flex-shrink: 0;
  line-height: 1.2;
}
.fsd-header-logo:hover { border-color: var(--verdi-light, #02735E); color: var(--verdi-light, #02735E); }
.fsd-header-logo img { width: 100%; height: 100%; object-fit: contain; }

.fsd-header-info { display: flex; flex-direction: column; gap: 2px; }
.fsd-header-title-input {
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  border: none;
  background: transparent;
  padding: 2px 6px;
  margin: -2px -6px;
  font-family: inherit;
  width: 340px;
  outline: none;
  border-radius: 4px;
}
.fsd-header-title-input:focus { background: rgba(2,115,94,.04); }
.fsd-header-title-input::placeholder { color: #cbd5e1; }

.fsd-header-meta {
  font-size: 10px;
  color: #94a3b8;
  display: flex;
  gap: 8px;
  padding-left: 6px;
}
.fsd-header-right { text-align: right; flex-shrink: 0; }
.fsd-header-serial {
  font-size: 11px;
  font-weight: 600;
  color: var(--verdi-light, #02735E);
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}
.fsd-header-version { font-size: 10px; color: #94a3b8; margin-top: 2px; }

/* Paper body — grid canvas */
.fsd-paper-body {
  flex: 1;
  padding: 20px 40px;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 10px;
  align-items: start;
  align-content: start;
  transition: background .15s;
  overflow: hidden;
}
.fsd-paper-body.fsd-dragover { background: rgba(2,115,94,.03); }

/* Paper footer */
.fsd-paper-footer {
  padding: 12px 40px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10px;
  color: #94a3b8;
  flex-shrink: 0;
  margin-top: auto;
}

/* ── Component on canvas ── */
.fsd-component {
  border: 1.5px solid transparent;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s, background .12s;
  position: relative;
  background: white;
  min-height: 32px;
  display: flex;
  flex-direction: column;
  align-self: start;
}
.fsd-component:hover { border-color: #e2e8f0; background: #fafbfc; }
.fsd-component.fsd-selected {
  border-color: var(--verdi-light, #02735E);
  background: rgba(2,115,94,.02);
  box-shadow: 0 0 0 2px rgba(2,115,94,.12);
  overflow: visible;
  z-index: 10;
}
.fsd-component.fsd-comp-dragging { opacity: .35; }
.fsd-comp-label {
  font-size: 11px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.fsd-comp-required { color: #ef4444; font-weight: 700; }
.fsd-comp-drag-handle {
  position: absolute;
  top: 4px;
  left: 4px;
  cursor: grab;
  color: #cbd5e1;
  font-size: 12px;
  opacity: 0;
  transition: opacity .12s;
  user-select: none;
}
.fsd-component:hover .fsd-comp-drag-handle,
.fsd-component.fsd-selected .fsd-comp-drag-handle { opacity: 1; }
.fsd-comp-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: flex;
  gap: 3px;
  opacity: 0;
  transition: opacity .12s;
}
.fsd-component:hover .fsd-comp-actions,
.fsd-component.fsd-selected .fsd-comp-actions { opacity: 1; }
.fsd-comp-action-btn {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}
.fsd-comp-action-del { background: #fef2f2; color: #ef4444; }
.fsd-comp-action-del:hover { background: #fee2e2; }

/* ── Inline toolbar (shown on selected component) ── */
.fsd-inline-toolbar {
  position: absolute;
  top: -36px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  background: #1e293b;
  border-radius: 8px;
  padding: 4px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
  z-index: 20;
  white-space: nowrap;
}
/* When the component sits at the top of the canvas, the -36px toolbar would be
   clipped by / overlap the form header. Flip it below the component instead. */
.fsd-component.fsd-toolbar-below .fsd-inline-toolbar {
  top: auto;
  bottom: -36px;
}
.fsd-inline-tb-group { display: flex; gap: 1px; }
.fsd-inline-tb-sep {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,.15);
  margin: 0 3px;
}
.fsd-inline-tb-btn {
  padding: 3px 8px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.7);
  font-size: 10px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border-radius: 4px;
  transition: all .12s;
  line-height: 1.4;
}
.fsd-inline-tb-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.fsd-inline-tb-btn.active { background: var(--verdi-light, #02735E); color: #fff; }
.fsd-inline-tb-btn.icon { padding: 3px 6px; font-size: 11px; }
.fsd-inline-tb-btn.danger:hover { background: rgba(239,68,68,.25); color: #fca5a5; }

/* Inline label editing input */
.fsd-inline-label-input {
  width: 100%;
  padding: 2px 6px;
  border: 1.5px solid var(--verdi-light, #02735E);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  color: #374151;
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(2,115,94,.12);
}

/* Component preview wrapper */
.fsd-comp-preview { cursor: text; }

/* Width grid spans */
.fsd-w-full  { grid-column: span 12; }
.fsd-w-half  { grid-column: span 6; }
.fsd-w-third { grid-column: span 4; }
.fsd-w-two-third { grid-column: span 8; }

/* Height presets */
.fsd-h-md { height: 80px; overflow: hidden; }
.fsd-h-lg { height: 140px; overflow: hidden; }
.fsd-h-xl { height: 220px; overflow: hidden; }
.fsd-h-md .fsd-comp-preview,
.fsd-h-lg .fsd-comp-preview,
.fsd-h-xl .fsd-comp-preview { flex: 1; min-height: 0; overflow: hidden; }

/* ── Resize handle (bottom-right corner) ── */
.fsd-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity .15s;
  z-index: 15;
}
.fsd-resize-handle::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid #94a3b8;
  border-bottom: 2px solid #94a3b8;
}
.fsd-component:hover .fsd-resize-handle,
.fsd-component.fsd-selected .fsd-resize-handle { opacity: 1; }
.fsd-component.fsd-resizing { outline: 2px dashed var(--verdi-light, #02735E); }

/* Drop indicator */
.fsd-drop-indicator {
  grid-column: 1 / -1;
  height: 3px;
  background: var(--verdi-light, #02735E);
  border-radius: 2px;
  pointer-events: none;
}

/* Empty canvas */
.fsd-paper-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 100px 40px 60px;
  color: #94a3b8;
}
.fsd-paper-empty-icon { font-size: 48px; opacity: .4; margin-bottom: 12px; }
.fsd-paper-empty-title { font-size: 15px; font-weight: 600; color: #64748b; margin-bottom: 6px; }
.fsd-paper-empty-sub { font-size: 12px; line-height: 1.5; }

/* ── Right properties panel ── */
.fsd-properties {
  width: 280px;
  background: white;
  border-top: 1px solid #e2e8f0;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 16px;
}
.fsd-props-title {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.fsd-props-group { margin-bottom: 10px; }
.fsd-props-divider {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #64748b;
  padding: 8px 0 4px;
  margin-top: 4px;
  border-top: 1px solid #f1f5f9;
}
.fsd-props-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #94a3b8;
  margin-bottom: 4px;
}
.fsd-props-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: #374151;
  background: white;
}
.fsd-props-input:focus {
  outline: none;
  border-color: var(--verdi-light, #02735E);
  box-shadow: 0 0 0 2px rgba(2,115,94,.1);
}
.fsd-props-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #374151;
  cursor: pointer;
  padding: 3px 0;
}
.fsd-props-checkbox input { accent-color: var(--verdi-light, #02735E); }

/* ── Collapsible property sections ── */
.fsd-section { border-top: 1px solid #f1f5f9; }
.fsd-section-hdr {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 2px;
  cursor: pointer;
  user-select: none;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #94a3b8;
  transition: color .15s;
}
.fsd-section-hdr:hover { color: #475569; }
.fsd-sec-chev { font-size: 8px; transition: transform .15s; width: 10px; text-align: center; }
.fsd-section.fsd-sec-open .fsd-sec-chev { transform: rotate(90deg); }
.fsd-section-body { display: none; padding-bottom: 6px; }
.fsd-section.fsd-sec-open .fsd-section-body { display: block; }

/* Width selector */
.fsd-width-selector { display: flex; gap: 4px; }
.fsd-width-btn {
  flex: 1;
  padding: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: white;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  color: #64748b;
  transition: all .15s;
  font-family: inherit;
}
.fsd-width-btn.fsd-active {
  border-color: var(--verdi-light, #02735E);
  background: rgba(2,115,94,.08);
  color: var(--verdi-light, #02735E);
}

/* No selection */
.fsd-props-empty {
  text-align: center;
  padding: 48px 16px;
  color: #94a3b8;
  font-size: 12px;
}
.fsd-props-empty-icon { font-size: 28px; opacity: .4; margin-bottom: 8px; }

/* ── Responsive ── */
@media (max-width: 1200px) {
  .fsd-palette { width: 200px; }
  .fsd-properties { width: 240px; }
}
@media (max-width: 1024px) {
  .fsd-paper { transform: scale(0.75); transform-origin: top center; }
  .fsd-palette { width: 180px; padding: 8px; }
  .fsd-properties { width: 220px; }
}

/* ── Icon Picker ── */
.fsd-icon-picker-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fsdFadeIn .15s;
}
@keyframes fsdFadeIn { from { opacity: 0; } to { opacity: 1; } }
.fsd-icon-picker {
  width: 480px;
  max-height: 70vh;
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.fsd-icon-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}
.fsd-icon-picker-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 12px;
}
.fsd-icon-cat-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: #94a3b8;
  padding: 8px 0 4px;
  border-top: 1px solid #f1f5f9;
  margin-top: 4px;
}
.fsd-icon-cat:first-child .fsd-icon-cat-label { border-top: none; margin-top: 0; }
.fsd-icon-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}
.fsd-icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  background: white;
  color: #475569;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .12s;
}
.fsd-icon-btn:hover { border-color: #02735E; color: #02735E; background: rgba(2,115,94,.04); }
.fsd-icon-btn.fsd-icon-sel {
  border-color: #02735E;
  background: rgba(2,115,94,.1);
  color: #02735E;
  box-shadow: 0 0 0 2px rgba(2,115,94,.15);
}
.fsd-icon-picker-footer {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid #f1f5f9;
  background: #f8fafc;
}
/* Icon trigger button in properties */
.fsd-icon-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 12px;
  color: #374151;
  font-family: inherit;
  width: 100%;
  transition: border-color .15s;
}
.fsd-icon-trigger:hover { border-color: #02735E; }
.fsd-icon-trigger i { font-size: 16px; color: #02735E; }
