/*
 * Workflow forms
 * A field technician should be able to scan, complete, and submit a record
 * without navigating a long unstructured stack of controls. These rules are
 * scoped to the three operational forms and keep their existing IDs/events.
 */

#screen-form .form-container,
#screen-project-form .form-container,
#screen-task-form .form-container {
  width: min(100%, 1180px);
  margin-inline: auto;
  padding: 20px 24px 124px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-padding-bottom: 112px;
}

#screen-form .page-context,
#screen-project-form .page-context,
#screen-task-form .page-context {
  margin-bottom: 20px;
}

#screen-form .workflow-form,
#screen-project-form .workflow-form,
#screen-task-form .workflow-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

#screen-form .form-card,
#screen-project-form .form-card,
#screen-task-form .form-card {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: start;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 16px 38px rgba(47, 76, 101, .08);
}

#screen-form .form-card__heading,
#screen-project-form .form-card__heading,
#screen-task-form .form-card__heading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  min-height: 34px;
  margin: 0;
  padding-bottom: 14px;
  color: var(--navy);
  border-bottom: 1px solid var(--line);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.015em;
}

#screen-form .form-card .form-row-2,
#screen-form .form-card .form-row-3,
#screen-form .form-card .form-row-4,
#screen-project-form .form-card .form-row-2,
#screen-task-form .form-card .form-row-2 {
  grid-column: 1 / -1;
  width: 100%;
  gap: 16px;
}

#screen-form .form-card .form-row-2,
#screen-project-form .form-card .form-row-2,
#screen-task-form .form-card .form-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#screen-form .form-card .form-row-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#screen-form .form-card .form-row-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

#screen-form .form-card .form-group,
#screen-project-form .form-card .form-group,
#screen-task-form .form-card .form-group {
  min-width: 0;
  gap: 8px;
}

#screen-form .form-card .form-group label,
#screen-project-form .form-card .form-group label,
#screen-task-form .form-card .form-group label {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .045em;
  text-transform: uppercase;
}

#screen-form .form-card input:not([type='checkbox']):not([type='radio']):not([type='range']),
#screen-form .form-card select,
#screen-form .form-card textarea,
#screen-project-form .form-card input:not([type='checkbox']):not([type='radio']):not([type='range']),
#screen-project-form .form-card select,
#screen-project-form .form-card textarea,
#screen-task-form .form-card input:not([type='checkbox']):not([type='radio']):not([type='range']),
#screen-task-form .form-card select,
#screen-task-form .form-card textarea {
  width: 100%;
  min-height: 52px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid #dbe6ee;
  border-radius: 14px;
  box-shadow: none;
}

#screen-form .form-card textarea,
#screen-project-form .form-card textarea,
#screen-task-form .form-card textarea { min-height: 128px; resize: vertical; }

#screen-form .form-card input:focus,
#screen-form .form-card select:focus,
#screen-form .form-card textarea:focus,
#screen-project-form .form-card input:focus,
#screen-project-form .form-card select:focus,
#screen-project-form .form-card textarea:focus,
#screen-task-form .form-card input:focus,
#screen-task-form .form-card select:focus,
#screen-task-form .form-card textarea:focus {
  background: #fff;
  border-color: var(--coral);
  box-shadow: 0 0 0 4px rgba(255, 107, 87, .13);
}

/* Equipment is grouped by operating context, rather than visual rows. */
#milestone-form .form-card > .form-section,
#milestone-form .form-card > #cmms-form-fields,
#milestone-form .form-card > .form-section-divider { grid-column: 1 / -1; }
#milestone-form .form-card > #cmms-form-fields { display: grid; gap: 18px; }
#milestone-form .form-section {
  padding: 14px 16px;
  background: var(--surface-blue);
  border-radius: 16px;
}
#milestone-form .toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
#milestone-form .toggle-label { color: var(--navy); font-size: 13px; font-weight: 800; }

/* Project fields form a compact identity/plan layout on wide screens. */
#project-form .form-card > .form-group { grid-column: span 6; }
#project-form .form-card > .form-group:has(#pf-name) { grid-column: span 8; }
#project-form .form-card > .form-group:has(#pf-short-name),
#project-form .form-card > .form-group:has(#pf-status),
#project-form .form-card > .form-group:has(#pf-budget) { grid-column: span 4; }
#project-form .form-card > .form-group:has(#pf-completion),
#project-form .form-card > .form-group:has(#pf-summary) { grid-column: 1 / -1; }
#project-form #pf-completion { min-height: auto; padding: 0; accent-color: var(--coral) !important; }

/* Work-order context and handoff data stay deliberately full width. */
#task-form .form-card > .detail-section,
#task-form .form-card > #tf-context-selects,
#task-form .form-card > .form-section-divider,
#task-form .form-card > #tf-recurring-fields,
#task-form .form-card > .form-group { grid-column: 1 / -1; }
#task-form .task-form-context { overflow: hidden; border-radius: 16px; box-shadow: none; }
#task-form .task-assignees-list {
  min-height: 58px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px dashed #c9d8e4;
  border-radius: 14px;
}

#screen-form .form-card .form-section-divider,
#screen-project-form .form-card .form-section-divider,
#screen-task-form .form-card .form-section-divider {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  min-height: 42px;
  margin: 0;
  padding: 0 12px;
  color: var(--navy);
  background: var(--surface-blue);
  border: 0;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

#screen-form .workflow-form > .error-msg,
#screen-form .workflow-form > .success-msg,
#screen-project-form .workflow-form > .error-msg,
#screen-project-form .workflow-form > .success-msg,
#screen-task-form .workflow-form > .error-msg,
#screen-task-form .workflow-form > .success-msg { margin: 0; }

#screen-form .workflow-form > .form-actions,
#screen-project-form .workflow-form > .form-actions,
#screen-task-form .workflow-form > .form-actions {
  position: sticky;
  inset-block-end: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 0 -4px;
  padding: 14px 4px calc(14px + env(safe-area-inset-bottom, 0px));
  background: rgba(234, 241, 248, .94);
  border-top: 1px solid rgba(228, 235, 241, .92);
  box-shadow: 0 -10px 24px rgba(47, 76, 101, .08);
  backdrop-filter: blur(14px);
}

#screen-form .workflow-form > .form-actions .btn,
#screen-project-form .workflow-form > .form-actions .btn,
#screen-task-form .workflow-form > .form-actions .btn { min-width: 144px; }

@media (max-width: 1024px) {
  #screen-form .form-card .form-row-3,
  #screen-form .form-card .form-row-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  #screen-form .form-container,
  #screen-project-form .form-container,
  #screen-task-form .form-container { padding: 12px 12px calc(96px + env(safe-area-inset-bottom, 0px)); }

  #screen-form .page-context,
  #screen-project-form .page-context,
  #screen-task-form .page-context { margin-bottom: 14px; }

  #screen-form .workflow-form,
  #screen-project-form .workflow-form,
  #screen-task-form .workflow-form { gap: 14px; }

  #screen-form .form-card,
  #screen-project-form .form-card,
  #screen-task-form .form-card { grid-template-columns: 1fr; gap: 14px; padding: 16px; border-radius: 20px; }

  #screen-form .form-card > *,
  #screen-project-form .form-card > *,
  #screen-task-form .form-card > * { grid-column: 1 / -1 !important; }

  #screen-form .form-card .form-row-2,
  #screen-form .form-card .form-row-3,
  #screen-form .form-card .form-row-4,
  #screen-project-form .form-card .form-row-2,
  #screen-task-form .form-card .form-row-2 { grid-template-columns: 1fr; gap: 14px; }

  #screen-form .form-card input:not([type='checkbox']):not([type='radio']):not([type='range']),
  #screen-form .form-card select,
  #screen-form .form-card textarea,
  #screen-project-form .form-card input:not([type='checkbox']):not([type='radio']):not([type='range']),
  #screen-project-form .form-card select,
  #screen-project-form .form-card textarea,
  #screen-task-form .form-card input:not([type='checkbox']):not([type='radio']):not([type='range']),
  #screen-task-form .form-card select,
  #screen-task-form .form-card textarea { font-size: 16px; }

  #screen-form .workflow-form > .form-actions,
  #screen-project-form .workflow-form > .form-actions,
  #screen-task-form .workflow-form > .form-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-inline: -12px; padding-inline: 12px; }

  #screen-form .workflow-form > .form-actions .btn,
  #screen-project-form .workflow-form > .form-actions .btn,
  #screen-task-form .workflow-form > .form-actions .btn { width: 100%; min-width: 0; }
}

@media (max-width: 390px) {
  #screen-form .form-card,
  #screen-project-form .form-card,
  #screen-task-form .form-card { padding: 14px; }
  #screen-form .workflow-form > .form-actions,
  #screen-project-form .workflow-form > .form-actions,
  #screen-task-form .workflow-form > .form-actions { grid-template-columns: 1fr; }
  #milestone-form .toggle-row { align-items: flex-start; }
}
