/* ============================================
   MOBILE-OPTIMIZED FORM STYLES
   ============================================
   Specifically for report forms:
   - Job Setup
   - AOI Report
   - Final Inspection
   - Rework
   - Shipping
   ============================================ */

/* ============================================
   FORM SECTIONS - MOBILE LAYOUT
   ============================================ */

@media (max-width: 640px) {
  /* All form sections stack vertically */
  .form-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
  }
  
  .form-section h3 {
    margin: 0 0 1rem 0;
    font-size: 18px;
    color: var(--color-text);
    font-weight: 600;
  }
  
  /* Grid layouts become single column */
  .form-grid-two,
  .form-grid-three,
  .form-grid-four {
    display: flex !important;
    flex-direction: column;
    gap: 1rem;
  }
  
  .form-grid-two label,
  .form-grid-three label,
  .form-grid-four label {
    width: 100%;
  }
}

/* ============================================
   COLLAPSIBLE FORM SECTIONS
   ============================================ */

@media (max-width: 640px) {
  .form-section-collapsible {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 1rem;
  }
  
  .form-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--color-surface-alt);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
  }
  
  .form-section-header:active {
    background: var(--color-border);
  }
  
  .form-section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text);
    margin: 0;
  }
  
  .form-section-toggle {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
  }
  
  .form-section-toggle::before {
    content: '▼';
    font-size: 12px;
    color: var(--color-muted);
  }
  
  .form-section-collapsible.collapsed .form-section-toggle {
    transform: rotate(-90deg);
  }
  
  .form-section-body {
    padding: 1rem;
    display: block;
  }
  
  .form-section-collapsible.collapsed .form-section-body {
    display: none;
  }
}

/* ============================================
   DEFECT ENTRY TABLE - CARD VIEW
   ============================================ */

@media (max-width: 640px) {
  /* Hide traditional table view */
  .defect-table-wrapper table {
    display: none;
  }
  
  /* Card-based defect entries */
  .defect-card-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  .defect-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    position: relative;
  }
  
  .defect-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--color-divider);
  }
  
  .defect-card-number {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-primary);
  }
  
  .defect-card-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--color-danger);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }
  
  .defect-card-remove:active {
    transform: scale(0.9);
    background: #dc2626;
  }
  
  .defect-card-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  .defect-card-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .defect-card-field label {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  
  .defect-card-field input,
  .defect-card-field select {
    padding: 0.875rem 1rem;
    min-height: 44px;
    font-size: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-field-bg);
  }
  
  .defect-card-field input:focus,
  .defect-card-field select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(2, 129, 82, 0.1);
  }
  
  /* Add defect button */
  .add-defect-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    min-height: 48px;
    background: var(--color-surface);
    color: var(--color-accent);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
  }
  
  .add-defect-btn:active {
    background: var(--color-surface-alt);
    border-color: var(--color-accent);
  }
  
  .add-defect-btn::before {
    content: '+';
    font-size: 24px;
    font-weight: 400;
  }
}

/* ============================================
   AUTOCOMPLETE / SEARCHABLE DROPDOWNS
   ============================================ */

@media (max-width: 640px) {
  .searchable-select-wrapper {
    position: relative;
    width: 100%;
  }
  
  .searchable-select-input {
    width: 100%;
    padding: 0.875rem 3rem 0.875rem 1rem;
    min-height: 44px;
    font-size: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-field-bg);
  }
  
  .searchable-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 240px;
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: var(--shadow-soft);
    z-index: 1000;
    display: none;
  }
  
  .searchable-select-dropdown.active {
    display: block;
  }
  
  .searchable-select-option {
    padding: 0.875rem 1rem;
    min-height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--color-divider);
    -webkit-tap-highlight-color: transparent;
  }
  
  .searchable-select-option:last-child {
    border-bottom: none;
  }
  
  .searchable-select-option:active,
  .searchable-select-option.selected {
    background: var(--color-accent);
    color: white;
  }
  
  .searchable-select-option.highlighted {
    background: var(--color-surface-alt);
  }
}

/* ============================================
   INLINE VALIDATION & ERROR MESSAGES
   ============================================ */

@media (max-width: 640px) {
  .field-error {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    background: rgba(239, 68, 68, 0.08);
    border-left: 3px solid var(--color-danger);
    border-radius: var(--radius-xs);
    font-size: 14px;
    color: #991b1b;
  }
  
  .field-error::before {
    content: '⚠';
    font-size: 16px;
  }
  
  .field-success {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    background: rgba(34, 197, 94, 0.08);
    border-left: 3px solid var(--color-success);
    border-radius: var(--radius-xs);
    font-size: 14px;
    color: #166534;
  }
  
  .field-success::before {
    content: '✓';
    font-size: 16px;
  }
  
  .form-grid input.error,
  .form-grid select.error,
  .form-grid textarea.error {
    border-color: var(--color-danger);
    background: rgba(239, 68, 68, 0.03);
  }
  
  .form-grid input.success,
  .form-grid select.success,
  .form-grid textarea.success {
    border-color: var(--color-success);
    background: rgba(34, 197, 94, 0.03);
  }
}

/* ============================================
   STICKY SUBMIT BUTTON
   ============================================ */

@media (max-width: 640px) {
  .form-submit-wrapper {
    position: sticky;
    bottom: 0;
    background: var(--color-surface);
    padding: 1rem;
    border-top: 1px solid var(--color-border);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
    margin-left: -1rem;
    margin-right: -1rem;
    margin-bottom: -1rem;
    z-index: 50;
  }
  
  .form-submit-wrapper .btn {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
    font-weight: 600;
  }
  
  /* Account for safe areas */
  @supports (padding: max(0px)) {
    .form-submit-wrapper {
      padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
  }
}

/* ============================================
   PROGRESS INDICATORS
   ============================================ */

@media (max-width: 640px) {
  .form-progress {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-surface-alt);
    border-radius: var(--radius-sm);
  }
  
  .form-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--color-border);
    border-radius: 3px;
    overflow: hidden;
  }
  
  .form-progress-fill {
    height: 100%;
    background: var(--color-accent);
    border-radius: 3px;
    transition: width 0.3s ease;
  }
  
  .form-progress-text {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-muted);
    white-space: nowrap;
  }
}

/* ============================================
   FIELD GROUPS & SPACING
   ============================================ */

@media (max-width: 640px) {
  .field-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  
  .field-group-inline {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }
  
  .field-group-inline.three-col {
    grid-template-columns: 1fr 1fr 1fr;
  }
  
  /* For very small screens, stack even inline groups */
  @media (max-width: 380px) {
    .field-group-inline {
      grid-template-columns: 1fr;
    }
  }
}

/* ============================================
   TEXTAREA AUTO-RESIZE SUPPORT
   ============================================ */

@media (max-width: 640px) {
  .form-grid textarea.auto-resize {
    min-height: 100px;
    resize: vertical;
  }
}

/* ============================================
   FORM HINTS & HELP TEXT
   ============================================ */

@media (max-width: 640px) {
  .field-hint {
    font-size: 13px;
    color: var(--color-muted);
    margin-top: 0.375rem;
    line-height: 1.4;
  }
  
  .field-hint::before {
    content: 'ℹ️ ';
    margin-right: 0.25rem;
  }
}

/* ============================================
   RADIO BUTTONS & CHECKBOXES
   ============================================ */

@media (max-width: 640px) {
  .radio-group,
  .checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .radio-option,
  .checkbox-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }
  
  .radio-option:active,
  .checkbox-option:active {
    background: var(--color-surface-alt);
    border-color: var(--color-accent);
  }
  
  .radio-option input[type="radio"],
  .checkbox-option input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin: 0;
    cursor: pointer;
  }
  
  .radio-option label,
  .checkbox-option label {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    margin: 0;
  }
}

/* ============================================
   LOADING STATE FOR FORMS
   ============================================ */

@media (max-width: 640px) {
  .form-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
  }
  
  .form-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin-top: -16px;
    margin-left: -16px;
    border: 3px solid rgba(2, 129, 82, 0.2);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
  }
}

/* ============================================
   FORM NAVIGATION (Multi-step)
   ============================================ */

@media (max-width: 640px) {
  .form-nav {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
  }
  
  .form-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    padding: 0.75rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-height: 44px;
    transition: all 0.2s ease;
  }
  
  .form-nav-btn.active {
    background: var(--color-accent);
    color: white;
    border-color: var(--color-accent);
  }
  
  .form-nav-btn.completed {
    background: var(--color-success);
    color: white;
    border-color: var(--color-success);
  }
  
  .form-nav-number {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-border);
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
  }
  
  .form-nav-btn.active .form-nav-number,
  .form-nav-btn.completed .form-nav-number {
    background: rgba(255, 255, 255, 0.3);
    color: white;
  }
  
  .form-nav-label {
    font-size: 12px;
    font-weight: 500;
    text-align: center;
  }
}
