// ════════════════════════════════════════════════════════════════════
//  flssurveybuilder.component.scss
// ════════════════════════════════════════════════════════════════════

:host {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 97px);
  overflow: hidden;
}

.FormOverView.scrollbar {
  height: auto;
  min-height: 0;
  max-height: none;
  flex: 0 0 auto;
  overflow: visible;
}

.sb-root {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: var(--bg-page, #f8f9fa);
  overflow-y: auto;
  font-family: var(--font-family-primary), "Inter", sans-serif;
  padding-bottom: 32px;
}

.sb-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 24px 12px;
  flex-shrink: 0;
}

.sb-page-header-left { display: flex; flex-direction: column; gap: 4px; }
.sb-page-title { font-size: 20px; font-weight: 700; color: #1e293b; margin: 0; }
.sb-page-subtitle { font-size: 13px; color: #64748b; margin: 0; }

.sb-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 24px;
  margin: 12px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sb-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; width: 100%; }
.sb-field-full { width: 100%; }

/* Custom wrappers for the fields */
.sb-form-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sb-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sb-toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sb-toggle-text {
  font-size: 13px;
  color: #64748b;
}

.sb-sections-wrap { margin: 0 24px 0; display: flex; flex-direction: column; gap: 0; }

.sb-sections-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sb-sections-heading { font-size: 16px; font-weight: 700; color: #1e293b; margin: 0; }

.sb-loading,
.sb-sections-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px;
  color: #64748b;
  font-size: 13px;
}

.sb-empty-sections {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 24px;
  background: #ffffff;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  text-align: center;
  gap: 6px;

  .sb-empty-icon  { font-size: 42px; margin-bottom: 8px; opacity: 0.8; }
  .sb-empty-title { font-size: 16px; font-weight: 600; color: #1e293b; margin: 0; }
  .sb-empty-hint  { font-size: 13px; color: #64748b; margin: 0; max-width: 300px; }

  .sb-empty-actions { margin-top: 20px; display: flex; gap: 12px; }
}

@keyframes sb-spin { to { transform: rotate(360deg); } }

.sb-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--action-primary-default, #148074);
  border-radius: 50%;
  animation: sb-spin 0.7s linear infinite;
  flex-shrink: 0;
}

.sb-section-row {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  margin-bottom: 24px;
  overflow: hidden;
}

.sb-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  flex-wrap: nowrap;
}

.sb-drag-handle {
  color: #cbd5e1;
  cursor: grab;
  font-size: 18px;
  user-select: none;
  line-height: 1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;

  &:active { cursor: grabbing; }
  &:hover { color: #94a3b8; }
}

.sb-section-name {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-q-count { font-size: 13px; color: #64748b; white-space: nowrap; flex-shrink: 0; }

.sb-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 14px;
  transition: opacity 0.15s;
  flex-shrink: 0;
  opacity: 0.6;

  &:hover { opacity: 1; }
  &.sb-icon-edit { color: var(--action-primary-default, #148074); }
  &.sb-icon-delete { color: #ef4444; }
}

.sb-section-questions {
  padding: 0;
  display: flex;
  flex-direction: column;
}

.sb-no-questions { font-size: 13px; color: #64748b; padding: 16px 20px; margin: 0; }

.sb-q-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #ffffff;
  border-bottom: 1px solid #f1f5f9;

  &:last-child { border-bottom: none; }
  &:hover { background: #f8fafc; }
}

.sb-q-tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  white-space: nowrap;
  background: #f1f5f9;
  color: #475569;
  flex-shrink: 0;
  border: 1px solid #e2e8f0;
}

.sb-q-text {
  flex: 1;
  font-size: 13px;
  color: #334155;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;

  .sb-q-req { color: #ef4444; margin-left: 2px; }
}

.sb-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.sb-badge-type { background: #e0f2f1; color: #00796b; } /* Custom light teal for all types per screenshot */

.sb-btn-edit-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--action-primary-default, #148074);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.12s;
  font-family: inherit;

  &:hover { opacity: 0.8; }
}

.sb-add-q-row {
  padding: 12px 20px;
  border-top: 1px solid #e2e8f0;
  display: flex;
}

.sb-btn-add-q {
  border: none;
  background: transparent;
  color: var(--action-primary-default, #148074);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;

  &:hover { opacity: 0.8; }
}

.sb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
  gap: 8px;
}

.sb-btn-primary {
  background: var(--action-primary-default, #148074);
  color: #fff;
  border-color: var(--action-primary-default, #148074);

  &:hover { opacity: 0.9; }
}

.sb-btn-outline {
  background: #ffffff;
  color: var(--action-primary-default, #148074);
  border-color: var(--action-primary-default, #148074);

  &:hover { background: #f0fdfa; }
}

.sb-btn-neutral {
  background: #ffffff;
  color: #334155;
  border-color: #cbd5e1;

  &:hover { background: #f8fafc; }
}

.sb-bottom-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  margin-top: auto; /* Push to bottom if viewport is larger */
  background: transparent;
}

::ng-deep .sb-question-lightbox {
  .mat-mdc-dialog-container { padding: 0 !important; border-radius: 12px !important; overflow: hidden; }
  .mdc-dialog__surface { border-radius: 12px !important; overflow: hidden; }
}

// ── Section modal ─────────────────────────────────────────────────
.sb-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(15, 23, 42, 0.4);
  padding-top: 10dvh;
}

.sb-modal-content-wrapper { display: flex; justify-content: center; }

.sb-modal-content {
  background: #ffffff;
  border-radius: 12px;
  padding: 24px;
  width: min(520px, 95vw);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sb-modal-titlebar { display: flex; align-items: flex-start; justify-content: space-between; }
.sb-modal-title { font-size: 18px; font-weight: 600; color: #0f172a; margin: 0; }
.sb-modal-subtitle { font-size: 14px; color: #64748b; margin: 4px 0 0 0; }
.sb-modal-close { cursor: pointer; font-size: 20px; color: #94a3b8; transition: color 0.15s; line-height: 1; }
.sb-modal-close:hover { color: #475569; }

.sb-modal-body { display: flex; flex-direction: column; gap: 16px; }

.sb-modal-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sb-modal-label {
  font-size: 13px;
  color: #334155;
  font-weight: 500;
}

.sb-modal-input {
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: #ffffff;
  color: #0f172a;
  transition: border-color 0.15s;

  &:focus { outline: none; border-color: var(--action-primary-default, #148074); box-shadow: 0 0 0 1px var(--action-primary-default, #148074); }
}

.sb-modal-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.sb-modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 8px; }

// ── CDK drag styling ──────────────────────────────────────────────
.cdk-drag-preview {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  background: #ffffff;
}
.cdk-drag-placeholder { opacity: 0; }
.cdk-drop-list-dragging .sb-section-row:not(.cdk-drag-placeholder) { transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); }

// ── Responsive ───────────────────────────────────────────────────
@media (max-width: 640px) {
  .sb-grid-2 { grid-template-columns: 1fr; }
  .sb-section-header { flex-wrap: wrap; }
  .sb-card, .sb-sections-wrap { margin-left: 16px; margin-right: 16px; }
  .sb-bottom-actions { padding: 16px; flex-direction: column-reverse; gap: 12px; align-items: stretch; }
  .sb-modal-grid-2 { grid-template-columns: 1fr; }
}