/* Universal Box Sizing */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Base Styles */
body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #e9ecef;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.form-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  max-width: 900px;
  width: 90%;
  display: flex;
  flex-direction: column;
  position: relative;
  /* To position the back button absolutely within the container */
}

/* Form Header */
.form-header {
  background: #6c757d;
  color: white;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  /* To position the back button */
}

.form-header h1 {
  margin: 0;
  /* Remove default margin */
  font-size: 1.5rem;
  text-align: center;
  flex-grow: 1;
  /* Allows the heading to take up available space */
}

/* Back Arrow Button */
.back-button {
  position: absolute;
  left: 20px;
  background-color: transparent;
  color: white;
  border: none;
  padding: 12px;
  cursor: pointer;
  border-radius: 50%;
  transition: background-color 0.2s ease, color 0.2s ease;
  min-width: 44px;
  /* Ensures minimum touch target size */
  min-height: 44px;
  /* Ensures minimum touch target size */
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  /* Ensure it stays on top */
  pointer-events: auto;
  /* Ensure it can receive pointer events */
}

.back-button:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.back-button svg {
  width: 24px;
  /* Slightly larger arrow for better visibility */
  height: 24px;
}

/* Screen Reader Only Text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Form Description */
.form-description {
  padding: 20px;
  font-size: 1rem;
  color: #555;
  line-height: 1.6;
  background-color: #f8f9fa;
  border-bottom: 1px solid #ddd;
}

.form-description h2 {
  font-size: 1.3rem;
  /* Adjust as needed */
  margin-top: 0;
}

/* Form Body */
.form-body {
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

h3 {
  color: #444;
  font-size: 1.2rem;
  margin-bottom: 10px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 5px;
  grid-column: span 2;
}

.form-group {
  display: flex;
  flex-direction: column;
  width: 100%;
  /* Ensure form-group spans full width */
  position: relative;
  /* For positioning error messages */
}

.form-group label {
  font-size: 14px;
  color: #555;
  margin-bottom: 5px;
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
  /* Ensure inputs span full width */
  box-sizing: border-box;
}

.form-group textarea {
  resize: vertical;
  height: 120px;
}

/* Error Message Styling */
.error-message {
  color: #dc3545;
  font-size: 12px;
  margin-top: 5px;
  display: none;
  /* Hidden by default */
  word-wrap: break-word;
}

/* Show error message */
.error-visible {
  display: block;
}

/* Drag and Drop Area */
.drag-drop {
  border: 2px dashed #ccc;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  border-radius: 6px;
  background: #fafafa;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  grid-column: span 2;
  position: relative;
}

.drag-drop:hover,
.drag-drop.dragover {
  border-color: #17a2b8;
  background-color: #e2f3f5;
}

/* Form Footer */
.form-footer {
  padding: 20px;
  background: #f8f9fa;
  border-top: 1px solid #ddd;
  grid-column: span 2;
  /* Spans the full form width */
  display: flex;
  justify-content: center;
  /* Center the Submit button */
  align-items: center;
  position: relative;
  /* To position the Submit button */
}

/* Submit Button */
.btn {
  background-color: #17a2b8;
  color: white;
  border: none;
  padding: 12px 20px;
  font-size: 16px;
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 0.2s ease;
  min-width: 100px;
  text-align: center;
}

.btn:hover {
  background-color: #138496;
}

/* File Preview */
#filePreview {
  margin-top: 10px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #f1f1f1;
  padding: 8px 12px;
  border-radius: 4px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.file-item span {
  font-size: 14px;
  color: #333;
  word-break: break-all;
  flex: 1 1 auto;
  margin-right: 10px;
}

.remove-btn {
  background-color: #dc3545;
  color: white;
  border: none;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.2s ease;
  flex: 0 0 auto;
}

.remove-btn:hover {
  background-color: #c82333;
}

/* Success Popup */
#successPopup {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #28a745;
  color: white;
  padding: 20px;
  border-radius: 8px;
  font-size: 18px;
  z-index: 1001;
  /* Higher than back-button's z-index */
  text-align: center;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  max-width: 90vw;
  width: 300px;
}

/* Overlay to prevent interaction when popup is visible */
#overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
}

/* Responsive Adjustments */
@media (max-width: 900px) {
  .form-body {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

@media (max-width: 768px) {
  .form-container {
    width: 95vw;
  }

  .form-description {
    font-size: 0.95rem;
  }

  h3 {
    font-size: 1.1rem;
  }

  .form-group label {
    font-size: 13px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 13px;
    padding: 8px;
  }

  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }

  .back-button {
    padding: 8px 12px;
    font-size: 14px;
  }

  .file-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .file-item span {
    margin-right: 0;
    margin-bottom: 5px;
  }

  .error-message {
    font-size: 11px;
  }
}

@media (max-width: 592px) {
  .back-button {
    left: 10px;
    /* Reduce left spacing */
    padding: 8px;
    min-width: 36px;
    min-height: 36px;
  }

  .form-header h1 {
    font-size: 1.2rem;
    /* Reduce font size */
    padding-left: 50px;
    /* Add padding to prevent overlap */
  }

  /* Ensure error messages don't push content */
  .form-group {
    margin-bottom: 15px;
  }

  .error-message {
    font-size: 11px;
    /* Slightly smaller font size on small screens */
  }

  /* Adjust grid spans for h3 and drag-drop */
  h3,
  .drag-drop,
  .form-footer {
    grid-column: span 1;
  }
}

@media (max-width: 480px) {
  .form-container {
    width: 100vw;
    border-radius: 0;
    /* Remove border radius for full-width */
    overflow-x: hidden;
    /* Prevent horizontal scroll */
  }

  .form-header {
    padding: 15px;
    font-size: 1.2rem;
  }

  .form-description {
    padding: 15px;
    font-size: 0.85rem;
  }

  h3 {
    font-size: 1rem;
  }

  .form-body {
    padding: 15px;
    gap: 15px;
    grid-template-columns: 1fr;
    /* Single column layout */
  }

  .form-group label {
    font-size: 12px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 12px;
    padding: 8px;
  }

  .drag-drop {
    padding: 15px;
    font-size: 0.9rem;
  }

  .form-footer {
    padding: 15px;
    flex-direction: row;
    /* Keep buttons side by side */
    justify-content: center;
    /* Center the Submit button */
    align-items: center;
  }

  .btn {
    padding: 8px 12px;
    font-size: 13px;
    min-width: 100px;
  }

  /* Ensure buttons do not interfere on small screens */
  .file-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .file-item span {
    font-size: 13px;
    margin-right: 0;
    margin-bottom: 5px;
  }

  .remove-btn {
    font-size: 11px;
    padding: 3px 6px;
  }

  /* Adjust Success Popup */
  #successPopup {
    width: 90vw;
    max-width: none;
    padding: 15px;
    font-size: 16px;
  }

  /* Adjust Overlay for Mobile */
  #overlay {
    z-index: 999;
    /* Below the success popup */
  }

  /* Adjust error messages to fit within single column layout */
  .form-group {
    margin-bottom: 10px;
  }

  .error-message {
    font-size: 11px;
    margin-top: 3px;
  }

  /* Ensure h3, drag-drop, and form-footer span only one column */
  h3,
  .drag-drop,
  .form-footer {
    grid-column: span 1;
  }
}

/* Error Message Display */
.error-visible {
  display: block;
}