/**
 * Form Builder Styles
 * 
 * Main stylesheet for the Form Builder component.
 * Uses CSS custom properties for theming compatibility with naive-ui.
 */

/* CSS Custom Properties (defaults for light theme) */
:root {
  --fb-bg-color: #f5f5f5;
  --fb-card-bg: #ffffff;
  --fb-border-color: #e0e0e6;
  --fb-text-color: #333639;
  --fb-text-muted: #999;
  --fb-primary-color: #18a058;
  --fb-primary-hover: #36ad6a;
  --fb-warning-color: #f0a020;
  --fb-error-color: #d03050;
  --fb-highlight-color: rgba(24, 160, 88, 0.1);
  --fb-selected-border: #18a058;
  --fb-hover-bg: rgba(24, 160, 88, 0.08);
  --fb-drag-placeholder-bg: #f0f9f4;
  --fb-radius-sm: 3px;
  --fb-radius: 6px;
  --fb-radius-lg: 8px;
  --fb-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --fb-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --fb-transition: all 0.2s ease;
}

/* Base Form Builder Container */
.form-builder-container {
  display: flex;
  min-height: 100%;
  background: var(--fb-bg-color);
  font-size: 14px;
  line-height: 1.5;
}

.form-builder-container.resizing {
  user-select: none;
  cursor: col-resize;
}

/* Form Main Area */
.form-container {
  flex: 1;
  overflow: hidden;
}

.form-main {
  background: var(--fb-card-bg);
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius);
  margin: 8px;
  overflow: hidden;
}

/* Sidebar */
.form-controls {
  position: relative;
}

.form-sidebar {
  border-left: 1px solid var(--fb-border-color);
  background: var(--fb-card-bg);
  overflow-y: auto;
  max-height: calc(100vh - 120px);
}

/* Resize Handle */
.resize-handle {
  width: 4px;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  cursor: col-resize;
  z-index: 10;
  transition: background-color 0.15s;
}

.resize-handle:hover,
.resize-handle.active {
  background-color: var(--fb-primary-color);
}

/* Tab Styles */
.tab-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  background: var(--fb-bg-color);
  border-bottom: 1px solid var(--fb-border-color);
  overflow-x: auto;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--fb-radius);
  cursor: pointer;
  transition: var(--fb-transition);
  white-space: nowrap;
  user-select: none;
}

.tab:hover {
  background: var(--fb-hover-bg);
}

.tab.active {
  background: var(--fb-card-bg);
  box-shadow: var(--fb-shadow-sm);
}

.tab.selected {
  border: 2px solid var(--fb-selected-border);
}

.tab-label {
  font-weight: 500;
  color: var(--fb-text-color);
}

/* Section Styles */
.form-section {
  padding: 12px;
  border-bottom: 1px solid var(--fb-border-color);
}

.form-section:last-child {
  border-bottom: none;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--fb-radius-sm);
  transition: var(--fb-transition);
}

.section-header:hover {
  background: var(--fb-hover-bg);
}

.section-header.has-label {
  background: var(--fb-bg-color);
  margin-bottom: 8px;
}

.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--fb-text-color);
}

.section-description {
  padding: 0 12px;
  font-size: 13px;
  color: var(--fb-text-muted);
  margin-bottom: 8px;
}

.section-columns {
  margin-top: 8px;
}

.section-columns-container {
  display: flex;
  gap: 12px;
}

/* Column Styles */
.column {
  flex: 1;
  padding: 8px;
  border: 1px dashed var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  min-height: 80px;
  transition: var(--fb-transition);
}

.column:hover {
  border-color: var(--fb-primary-color);
  border-style: dashed;
}

.column.selected {
  border: 2px solid var(--fb-selected-border);
  background: var(--fb-highlight-color);
}

.column-header {
  padding: 4px 8px;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--fb-text-muted);
  font-size: 12px;
}

.column-container {
  min-height: 60px;
}

/* Field Styles */
.field {
  padding: 8px;
  margin-bottom: 8px;
  border: 1px solid transparent;
  border-radius: var(--fb-radius-sm);
  cursor: pointer;
  transition: var(--fb-transition);
}

.field:last-child {
  margin-bottom: 0;
}

.field:hover {
  background: var(--fb-hover-bg);
  border-color: var(--fb-border-color);
}

.field.selected {
  border: 2px solid var(--fb-selected-border);
  background: var(--fb-highlight-color);
}

.field.hovered {
  background: var(--fb-hover-bg);
}

.field-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.field-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.field:hover .field-actions,
.field.selected .field-actions {
  opacity: 1;
}

.field-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--fb-radius-sm);
  background: transparent;
  color: var(--fb-text-muted);
  cursor: pointer;
  transition: var(--fb-transition);
}

.field-action-btn:hover {
  background: var(--fb-bg-color);
  color: var(--fb-text-color);
}

.field-action-btn.danger:hover {
  background: rgba(208, 48, 80, 0.1);
  color: var(--fb-error-color);
}

/* Label Styles */
.label {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}

.label-text {
  font-weight: 500;
  color: var(--fb-text-color);
  font-size: 13px;
}

.reqd-indicator {
  color: var(--fb-error-color);
  font-weight: bold;
}

/* Control Styles */
.control {
  width: 100%;
}

.control.editable input,
.control.editable textarea,
.control.editable select,
.control.editable .input-field {
  background: var(--fb-card-bg);
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--fb-text-color);
  cursor: pointer;
  transition: var(--fb-transition);
}

.control.editable input:focus,
.control.editable textarea:focus,
.control.editable select:focus {
  outline: none;
  border-color: var(--fb-primary-color);
  box-shadow: 0 0 0 2px var(--fb-highlight-color);
}

.control .description {
  margin-top: 4px;
  font-size: 12px;
  color: var(--fb-text-muted);
}

/* Input Fields */
input.form-control {
  width: 100%;
  height: 32px;
  background: var(--fb-card-bg);
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  padding: 0 10px;
  font-size: 13px;
  color: var(--fb-text-color);
}

textarea.form-control {
  width: 100%;
  min-height: 80px;
  resize: vertical;
}

/* Select Input */
.select-input {
  position: relative;
  display: flex;
  align-items: center;
}

.select-input input {
  padding-right: 30px;
}

.select-input .icon {
  position: absolute;
  right: 8px;
  color: var(--fb-text-muted);
  pointer-events: none;
}

/* Checkbox/Radio Styles */
.checkbox-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.checkbox-control input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--fb-primary-color);
}

/* Button Control */
.btn-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--fb-radius-sm);
  font-weight: 500;
  cursor: pointer;
  transition: var(--fb-transition);
}

.btn-control.btn-primary {
  background: var(--fb-primary-color);
  color: white;
  border: none;
}

.btn-control.btn-default {
  background: var(--fb-card-bg);
  color: var(--fb-text-color);
  border: 1px solid var(--fb-border-color);
}

/* Table Control */
.table-preview {
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  overflow: hidden;
}

.table-preview .table-header {
  display: flex;
  background: var(--fb-bg-color);
  border-bottom: 1px solid var(--fb-border-color);
  padding: 8px 12px;
  font-weight: 500;
  font-size: 12px;
}

.table-preview .table-row {
  display: flex;
  padding: 8px 12px;
  border-bottom: 1px solid var(--fb-border-color);
}

.table-preview .table-row:last-child {
  border-bottom: none;
}

/* Rating Control */
.rating-stars {
  display: flex;
  gap: 4px;
}

.rating-star {
  color: var(--fb-border-color);
  font-size: 18px;
}

.rating-star.filled {
  color: var(--fb-warning-color);
}

/* Signature Control */
.signature-field {
  width: 200px;
  height: 60px;
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  background: var(--fb-card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fb-text-muted);
  font-size: 12px;
}

/* Image Control */
.missing-image {
  width: 100px;
  height: 100px;
  border: 2px dashed var(--fb-border-color);
  border-radius: var(--fb-radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--fb-text-muted);
  gap: 4px;
}

/* Code Control */
.code-preview {
  background: #1e1e1e;
  border-radius: var(--fb-radius-sm);
  padding: 12px;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
  color: #d4d4d4;
  min-height: 100px;
}

/* Link Control */
.link-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.link-input-group {
  display: flex;
  gap: 8px;
}

.link-input-group input {
  flex: 1;
}

.link-input-group .search-btn {
  padding: 6px 12px;
  background: var(--fb-bg-color);
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  color: var(--fb-text-muted);
  cursor: pointer;
}

/* Add Field Button */
.add-new-field-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 12px;
  border: 2px dashed var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  background: transparent;
  color: var(--fb-text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: var(--fb-transition);
}

.add-new-field-btn:hover {
  border-color: var(--fb-primary-color);
  color: var(--fb-primary-color);
  background: var(--fb-highlight-color);
}

/* Dropdown Menu */
.dropdown-menu {
  position: fixed;
  min-width: 160px;
  background: var(--fb-card-bg);
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius);
  box-shadow: var(--fb-shadow);
  padding: 4px;
  z-index: 1000;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--fb-radius-sm);
  color: var(--fb-text-color);
  font-size: 13px;
  cursor: pointer;
  transition: var(--fb-transition);
}

.dropdown-item:hover {
  background: var(--fb-hover-bg);
}

.dropdown-item.danger {
  color: var(--fb-error-color);
}

.dropdown-item.danger:hover {
  background: rgba(208, 48, 80, 0.1);
}

.dropdown-divider {
  height: 1px;
  background: var(--fb-border-color);
  margin: 4px 0;
}

/* Autocomplete/Combobox */
.combo-box-options {
  position: fixed;
  min-width: 200px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--fb-card-bg);
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius);
  box-shadow: var(--fb-shadow);
  z-index: 1001;
}

.combo-box-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: var(--fb-transition);
}

.combo-box-option:hover,
.combo-box-option.active {
  background: var(--fb-hover-bg);
}

.combo-box-option.selected {
  background: var(--fb-highlight-color);
  color: var(--fb-primary-color);
}

/* Editable Input */
.editable-input {
  display: flex;
  align-items: center;
}

.editable-input .edit-icon {
  opacity: 0;
  margin-left: 4px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.editable-input:hover .edit-icon {
  opacity: 1;
}

.editable-input input {
  border: none;
  border-bottom: 2px solid var(--fb-primary-color);
  background: transparent;
  padding: 2px 4px;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  outline: none;
}

/* Sidebar Styles */
.sidebar-container {
  width: 280px;
  padding: 16px;
}

.sidebar-header {
  margin-bottom: 16px;
}

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-section-title {
  font-weight: 600;
  font-size: 12px;
  color: var(--fb-text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

/* Property Group */
.property-group {
  margin-bottom: 12px;
}

.property-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--fb-text-muted);
  margin-bottom: 4px;
}

.property-input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius-sm);
  font-size: 13px;
  transition: var(--fb-transition);
}

.property-input:focus {
  outline: none;
  border-color: var(--fb-primary-color);
  box-shadow: 0 0 0 2px var(--fb-highlight-color);
}

/* Search Box */
.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--fb-border-color);
  border-radius: var(--fb-radius);
  font-size: 13px;
  transition: var(--fb-transition);
}

.search-box input:focus {
  outline: none;
  border-color: var(--fb-primary-color);
  box-shadow: 0 0 0 2px var(--fb-highlight-color);
}

.search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fb-text-muted);
}

/* Drag & Drop Styles */
.sortable-ghost {
  opacity: 0.4;
}

.sortable-drag {
  opacity: 1;
  box-shadow: var(--fb-shadow);
}

.sortable-chosen {
  background: var(--fb-drag-placeholder-bg);
}

.drop-placeholder {
  position: relative;
  height: 60px;
  border: 2px dashed var(--fb-primary-color);
  border-radius: var(--fb-radius-sm);
  background: var(--fb-highlight-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-placeholder::after {
  content: "Drop here";
  color: var(--fb-primary-color);
  font-weight: 500;
}

/* User Generated Field Indicator */
[data-is-user-generated="1"] {
  background-color: rgba(240, 160, 32, 0.15);
}

/* Preview Mode */
.preview .tab,
.preview .column,
.preview .field {
  background: var(--fb-card-bg);
}

.preview .column,
.preview .field {
  border: none;
  padding: 0;
}

.preview .add-new-field-btn,
.preview .field-actions,
.preview .resize-handle {
  display: none;
}

.preview .field-controls {
  margin-bottom: 4px;
}

/* Read Only Mode Indicator */
.read-only-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--fb-warning-color);
  color: white;
  border-radius: var(--fb-radius-sm);
  font-size: 12px;
  font-weight: 500;
}

/* Scrollbar Styles */
.form-builder-container ::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.form-builder-container ::-webkit-scrollbar-track {
  background: transparent;
}

.form-builder-container ::-webkit-scrollbar-thumb {
  background: var(--fb-border-color);
  border-radius: 3px;
}

.form-builder-container ::-webkit-scrollbar-thumb:hover {
  background: var(--fb-text-muted);
}

/* Utility Classes */
.mt-2 {
  margin-top: 8px;
}

.mt-4 {
  margin-top: 16px;
}

.mb-2 {
  margin-bottom: 8px;
}

.mb-4 {
  margin-bottom: 16px;
}

.gap-2 {
  gap: 8px;
}

.text-muted {
  color: var(--fb-text-muted);
}

.text-sm {
  font-size: 12px;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
