/* static/css/forms/unified_form.css */

/* ----- Modal Overrides (reuse Upload Modal styles) ----- */
#formUploadModal .custom-modal-radius {
  border-radius: 16px; /* match upload modal */
}

#formUploadModal .custom-input-field {
  border-radius: 10px; /* match upload modal */
  font-size: 0.95rem;
  background-color: #f8f9fa; /* light gray background */
  border-color: #e2e8f0;
  transition:
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;
}
#formUploadModal .custom-input-field:focus {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

#formUploadModal .custom-btn-radius {
  border-radius: 10px; /* match upload modal */
}

#formUploadModal .tracking-wider {
  letter-spacing: 0.05em;
}

/* ----- Dynamic Wrappers (hidden by default) ----- */
.sub-category-wrapper,
.doc-type-wrapper {
  transition: opacity 0.2s ease;
}
.sub-category-wrapper select,
.doc-type-wrapper select {
  background-color: #fff;
}

/* ----- Responsive adjustments for modal ----- */
@media (max-width: 576px) {
  #formUploadModal .modal-dialog {
    margin: 0.5rem;
  }
  #formUploadModal .modal-body {
    padding: 1rem !important;
  }
}

/* ----- Edit page styling (consistent with modal) ----- */
.form-edit-page .form-control,
.form-edit-page .form-select {
  border-radius: 8px;
  border-color: #e2e8f0;
  padding: 0.6rem 1rem;
}
.form-edit-page .form-control:focus,
.form-edit-page .form-select:focus {
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* ----- Export buttons spacing ----- */
.export-btn-group .btn {
  margin-right: 0.5rem;
  margin-bottom: 0.5rem;
}

.sub-category-wrapper.visible,
.doc-type-wrapper.visible {
  display: block !important;
}

/* Card hover effect */
.hover-shadow {
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}
.hover-shadow:hover {
  transform: translateY(-4px);
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.08) !important;
}

/* ==================================================================
   Structured Content Builder (contents/subcontents + tables)
   Used in the "Create New Form" modal and the form edit page.
   ================================================================== */
.structured-builder {
  border: 1px dashed #ced4da;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  background: #fff;
}

.structured-builder .sb-toolbar-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6c757d;
  margin-right: 0.25rem;
}

.structured-builder .sb-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  white-space: nowrap;
}
.sb-badge-content {
  background: #e7f1ff;
  color: #0d6efd;
}
.sb-badge-section {
  background: #e7f1ff;
  color: #0d6efd;
}
.sb-badge-subsection {
  background: #eef2ff;
  color: #5b6bd6;
}
.sb-badge-table {
  background: #e6f7ee;
  color: #198754;
}

.structured-builder .sb-icon-btn {
  border: 1px solid #e2e8f0;
  background: #fff;
  color: #6c757d;
  line-height: 1;
  padding: 0.25rem 0.4rem;
  border-radius: 6px;
}
.structured-builder .sb-icon-btn:hover {
  background: #f1f3f5;
  color: #212529;
}
.structured-builder .sb-remove-btn {
  color: #dc3545;
  border-color: #f1c0c5;
}
.structured-builder .sb-remove-btn:hover {
  background: #fdecea;
  color: #dc3545;
}

.structured-builder .sb-title-input {
  font-weight: 600;
}

.structured-builder .sb-bullet {
  color: #0d6efd;
  font-weight: 700;
  width: 0.9rem;
  text-align: center;
  flex-shrink: 0;
}

.structured-builder .sb-add-sub,
.structured-builder .sb-add-row {
  font-size: 0.8rem;
  text-decoration: none;
}
.structured-builder .sb-add-sub:hover,
.structured-builder .sb-add-row:hover {
  text-decoration: underline;
}

/* ---- Table builder ---- */
.structured-builder .sb-table-scroll {
  overflow-x: auto;
  padding-bottom: 0.25rem;
}
.structured-builder .sb-col-header,
.structured-builder .sb-table-rows {
  min-width: max-content;
}
.structured-builder .sb-col-wrap {
  position: relative;
  flex: 0 0 150px;
  min-width: 150px;
}
.structured-builder .sb-col-wrap input {
  padding-right: 26px;
}
.structured-builder .sb-col-remove {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: #adb5bd;
  padding: 0 2px;
  line-height: 1;
  z-index: 2;
}
.structured-builder .sb-col-remove:hover {
  color: #dc3545;
}
.structured-builder .sb-add-col {
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 0.75rem;
}
.structured-builder .sb-add-col:disabled {
  opacity: 0.5;
  pointer-events: none;
}
.structured-builder .sb-table-rows .form-control {
  flex: 0 0 150px;
  min-width: 150px;
}
.structured-builder .sb-block .card-body {
  background: #fbfcfe;
}
.structured-builder .sb-col-limit {
  font-size: 0.72rem;
  color: #6c757d;
  font-style: italic;
}
.structured-builder .sb-table-rows.has-many-rows {
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}

/* ---- Sub sections (nested under a main section) ---- */
.structured-builder .sb-field-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6c757d;
  margin-bottom: 0.25rem;
}
.structured-builder .sb-subsection {
  border-left: 3px solid #dee2e6;
  background: #fff;
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
}
.structured-builder .sb-subsection .sb-title-input {
  font-weight: 600;
}
.structured-builder .sb-check {
  color: #198754;
  font-size: 1rem;
  width: 0.95rem;
  text-align: center;
  flex-shrink: 0;
}

/* Compact styling inside the modal */
#formUploadModal .structured-builder {
  padding: 0.75rem 0.85rem;
}
#formUploadModal .structured-builder .form-control {
  font-size: 0.875rem;
}

/* Pill selects & inputs – make them more modern */
.form-select-sm.rounded-pill,
.form-control-sm.rounded-pill {
  padding-left: 1rem;
  padding-right: 1rem;
  background-color: #f8f9fa;
  border-color: #e9ecef;
}
.form-select-sm.rounded-pill:focus,
.form-control-sm.rounded-pill:focus {
  background-color: #fff;
  border-color: #0d6efd;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

/* Stretched link inside card – make sure it doesn’t overlap interactive elements */
.card .stretched-link::after {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1;
  content: "";
}
.card .card-body .badge,
.card .card-body .btn {
  position: relative;
  z-index: 2;
}

/* Manage Forms mode (bulk selection) */
body.manage-mode .form-card {
  cursor: pointer;
}
body.manage-mode .stretched-link {
  pointer-events: none;
}
.form-card .manage-check {
  position: relative;
  z-index: 3;
}
#manage-toggle.active {
  background-color: #0d6efd;
  border-color: #0d6efd;
  color: #fff;
}

/* Sticky toolbar inside the structured builder.
   Sticks to the top of the viewport while the builder is in view,
   then releases when the builder scrolls out of view. */
.sb-toolbar {
  position: sticky;
  top: 0.5rem; /* small offset from the top of the viewport */
  z-index: 5; /* above the blocks below it */
  background: #ffffff; /* opaque so blocks don't show through */
  padding: 0.5rem 0.5rem; /* breathing room when stuck */
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); /* subtle lift when floating */
}

@media (max-width: 575.98px) {
  .sb-toolbar {
    padding: 0.35rem 0.5rem;
  }
  .sb-toolbar .btn {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
  }
}

/* Block header: badge + title + action buttons */
.sb-block-header .sb-title-input {
  flex: 1 1 220px; /* take remaining space, prefer at least 220px */
  min-width: 0; /* allow shrinking below natural width */
}

.sb-block-header .sb-actions {
  margin-left: auto; /* push to the right on desktop */
  flex-shrink: 0; /* don't let the buttons get squeezed */
}

/* Mobile: stack the header into three rows */
@media (max-width: 767.98px) {
  .sb-block-header {
    flex-direction: column;
    align-items: stretch;
  }

  /* Keep the badge its natural width (don't stretch to full width) */
  .sb-block-header .sb-badge {
    align-self: flex-start;
  }

  /* Title takes full width */
  .sb-block-header .sb-title-input {
    width: 100%;
    flex: 0 0 auto;
  }

  /* Buttons: full-width row, aligned to the right */
  .sb-block-header .sb-actions {
    margin-left: 0;
    align-self: stretch;
    justify-content: flex-end;
  }
}
