/* Modern form styling - Mobile First */
.form-grid { 
  display: grid; 
  grid-template-columns: 1fr; 
  gap: 20px; 
  max-width: 600px; 
  margin: 0 auto; 
  padding: 24px; 
  background: #ffffff; 
  border-radius: 16px; 
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08); 
  border: 1px solid #f1f5f9; 
  position: relative;
}

.form-grid label { 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  font-size: 15px; 
  font-weight: 600; 
  color: #1e293b; 
  position: relative;
  overflow: hidden;
}

.form-grid input, 
.form-grid select,
.form-grid textarea { 
  padding: 16px 16px; 
  border: 2px solid #e2e8f0; 
  border-radius: 12px; 
  font-size: 16px; 
  background: #ffffff;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
  min-height: 52px;
  position: relative;
  z-index: 1;
}

.form-grid textarea {
  resize: vertical;
  min-height: 80px;
}

/* Do NOT apply text input styles to checkboxes */
.form-grid input[type="checkbox"] {
  -webkit-appearance: checkbox;
  appearance: checkbox;
  width: 18px;
  height: 18px;
  padding: 0;
  margin: 0;
  border: none;
  min-height: auto;
  background: initial;
  box-shadow: none;
  transform: none;
}

.form-grid input[type="checkbox"]:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.form-grid input:focus, 
.form-grid select:focus,
.form-grid textarea:focus { 
  outline: none;
  border-color: #3b82f6; 
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  transform: translateY(-1px);
}

.form-grid input:invalid {
  border-color: #ef4444;
}

.form-grid input:focus:valid {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.form-grid input:focus:invalid {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.form-grid select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 40px;
}

.form-grid select:valid {
  border-color: #10b981;
}

.form-grid .span-2 { 
  grid-column: span 1; 
}

/* Form sections with modern styling */
.form-section {
  background: #f8fafc;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
}

.form-section-title {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-section-title::before {
  content: '';
  width: 4px;
  height: 20px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: 2px;
}

/* Input groups for better organization */
.input-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Checkbox row utility to avoid overlap/clipping */
.form-grid label.checkbox-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
  overflow: visible;
  padding: 8px 0;
}
.form-grid label.checkbox-row span {
  font-weight: 600;
}
.form-grid label.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

/* Number input styling */
input[type="number"] {
  text-align: right;
}

/* Button styling updates */
.form-grid .btn {
  min-height: 52px;
  font-size: 16px;
  font-weight: 600;
  border-radius: 12px;
  transition: all 0.2s ease;
  cursor: pointer;
}

.form-grid .btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.form-grid .btn:active {
  transform: translateY(0);
}

.form-grid .btn.primary {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border: none;
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

.form-grid .btn.primary:hover {
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.4);
}

/* Form actions styling */
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.form-actions .btn {
  flex: 1;
  justify-content: center;
  display: flex;
  align-items: center;
}

/* Success states */
.form-grid input:valid:not(:placeholder-shown) {
  border-color: #10b981;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%2310b981'%3e%3cpath d='M12.416 3.376a.75.75 0 0 1 .208 1.04l-5 7.5a.75.75 0 0 1-1.154.114l-3-3a.75.75 0 0 1 1.06-1.06l2.353 2.353 4.493-6.74a.75.75 0 0 1 1.04-.207Z'/%3e%3c/svg%3e");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 40px;
}

/* Improved number input for currency */
input[name="amount"] {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23059669'%3e%3cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16'/3e%3cpath d='M8 13.5a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11m-2-8.5v1h-.5V5h.5m0 2.5h.5V6h-.5v1.5zm1.5 0V5h.5v1h.5v1.5h-.5V9H8V7.5z'/%3e%3c/svg%3e") !important;
  background-position: left 12px center !important;
  background-repeat: no-repeat !important;
  background-size: 20px !important;
  padding-left: 40px !important;
}

/* Field error styling */
.field-error {
  color: #ef4444;
  font-size: 13px;
  font-weight: 500;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.field-error::before {
  content: '⚠️';
  font-size: 12px;
}

/* Loading overlay for entire form */
.form-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  z-index: 10;
  backdrop-filter: blur(2px);
}

.form-loading-overlay .loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.form-loading-overlay .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top: 3px solid #3b82f6;
}

.form-loading-overlay .loading-text {
  color: #374151;
  font-weight: 600;
  font-size: 14px;
}

/* Mobile specific optimizations for iPhone */
@media (max-width: 480px) {
  .form-grid {
    padding: 16px;
    margin: 8px;
    border-radius: 12px;
  }
  
  .form-section {
    padding: 16px;
  }
  
  .input-group {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .form-grid input, .form-grid select {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 18px 16px;
    min-height: 56px;
  }
  
  .form-actions .btn {
    min-height: 56px;
    font-size: 16px;
  }
  
  /* Mobile loading states */
  .form-grid .btn.loading::before {
    font-size: 15px;
  }
  
  .form-grid .btn.loading::after {
    width: 18px;
    height: 18px;
  }
  
  /* Mobile loading overlay */
  .form-loading-overlay .loading-content {
    padding: 20px;
    margin: 0 16px;
  }
  
  .form-loading-overlay .loading-text {
    font-size: 15px;
  }
}

/* Medium mobile devices */
@media (min-width: 481px) and (max-width: 767px) {
  .form-grid {
    padding: 20px;
    margin: 12px;
  }
  
  .input-group {
    grid-template-columns: 1fr 1fr;
  }
}

/* Tablet responsive - 2 columns */
@media (min-width: 768px) {
  .form-grid { 
    grid-template-columns: 1fr 1fr; 
    gap: 20px 24px; 
    padding: 32px; 
  }
  
  .form-grid .span-2 { 
    grid-column: span 2; 
  }
  
  .input-group {
    grid-column: span 2;
  }
  
  .form-actions {
    grid-column: span 2;
    justify-content: flex-end;
    max-width: 300px;
    margin-left: auto;
  }
}

/* iPhone safe area support */
@supports (padding: max(0px)) {
  .form-grid {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }
}

/* Better touch targets */
.form-grid button,
.form-grid input,
.form-grid select {
  touch-action: manipulation;
}

/* Modern progress indicators */
.form-progress {
  height: 3px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 20px;
}

.form-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #1d4ed8);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Dark mode support (for future) */
@media (prefers-color-scheme: dark) {
  .form-grid {
    background: #1f2937;
    border-color: #374151;
  }
  
  .form-section {
    background: #111827;
    border-color: #374151;
  }
  
  .form-grid label {
    color: #f3f4f6;
  }
  
  .form-grid input,
  .form-grid select {
    background: #111827;
    border-color: #4b5563;
    color: #f3f4f6;
  }
  
  .form-section-title {
    color: #f3f4f6;
  }
}

/* Print styles */
@media print {
  .form-grid {
    box-shadow: none;
    border: 1px solid #000;
  }
  
  .form-actions {
    display: none;
  }
}