/**
 * form-base.css - Shared styles for all user-facing forms
 *
 * This stylesheet provides consistent styling modeled on the order form:
 * - Loading overlay with spinner
 * - Toolbar (sticky header)
 * - Buttons (primary, secondary, danger)
 * - Document container and page layout
 * - Form fields (inputs, selects, textareas)
 * - Progress indicator
 * - File upload components
 * - Radio/checkbox groups
 * - Tables
 * - Print styles
 *
 * Usage: Include this CSS first, then form-specific CSS for overrides
 */

/* ============================================
   CSS Reset
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ============================================
   Base Typography & Layout
   ============================================ */
body {
  font-family: Arial, sans-serif;
  background: #525659;
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 9998;
}

.loading-overlay.show {
  display: flex;
}

/* ============================================
   Notification Modal
   ============================================ */
.form-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  padding: 20px;
}

.form-modal-overlay.show {
  display: flex;
}

.form-modal {
  background: #1e1e1e;
  color: white;
  border-radius: 12px;
  padding: 36px 32px 28px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
  animation: modal-pop 0.2s ease-out;
}

@keyframes modal-pop {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.form-modal-icon {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 14px;
}

.form-modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
  color: white;
}

.form-modal-message {
  font-size: 14px;
  line-height: 1.55;
  color: #ccc;
  margin-bottom: 24px;
  white-space: pre-wrap;
}

/* Type variants */
.form-modal[data-type="success"] .form-modal-icon::before { content: "✅"; }
.form-modal[data-type="error"]   .form-modal-icon::before { content: "❌"; }
.form-modal[data-type="warning"] .form-modal-icon::before { content: "⚠️"; }
.form-modal[data-type="info"]    .form-modal-icon::before { content: "ℹ️"; }

.form-modal[data-type="success"] .form-modal-btn { background: #28a745; }
.form-modal[data-type="success"] .form-modal-btn:hover:not(:disabled) { background: #218838; }
.form-modal[data-type="error"]   .form-modal-btn { background: #dc3545; }
.form-modal[data-type="error"]   .form-modal-btn:hover:not(:disabled) { background: #c82333; }
.form-modal[data-type="warning"] .form-modal-btn { background: #e65100; }
.form-modal[data-type="warning"] .form-modal-btn:hover:not(:disabled) { background: #bf360c; }

.form-modal-footer {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.form-modal-btn {
  min-width: 130px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

/* Primary button colours driven by modal type */
.form-modal-btn.modal-btn-primary { background: #4285f4; color: white; }
.form-modal-btn.modal-btn-primary:hover { background: #357ae8; }
.form-modal[data-type="success"] .form-modal-btn.modal-btn-primary { background: #28a745; }
.form-modal[data-type="success"] .form-modal-btn.modal-btn-primary:hover { background: #218838; }
.form-modal[data-type="error"]   .form-modal-btn.modal-btn-primary { background: #dc3545; }
.form-modal[data-type="error"]   .form-modal-btn.modal-btn-primary:hover { background: #c82333; }
.form-modal[data-type="warning"] .form-modal-btn.modal-btn-primary { background: #e65100; }
.form-modal[data-type="warning"] .form-modal-btn.modal-btn-primary:hover { background: #bf360c; }

/* Secondary button — white outline, used inside the dark modal */
.form-modal-btn.modal-btn-secondary {
  background: transparent;
  color: #ccc;
  border: 1px solid #555;
}
.form-modal-btn.modal-btn-secondary:hover { background: rgba(255,255,255,0.08); color: white; border-color: #888; }


.loading-content {
  background: #1e1e1e;
  padding: 30px 40px;
  border-radius: 8px;
  text-align: center;
  color: white;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #333;
  border-top-color: #4285f4;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

.spinner-small {
  width: 16px;
  height: 16px;
  border: 2px solid #e0e0e0;
  border-top-color: #4285f4;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   Toolbar (Sticky Header) - Hidden on Desktop
   ============================================ */
.toolbar {
  display: none; /* Hidden on desktop */
}

.toolbar-actions {
  display: flex;
  gap: 10px;
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  padding: 10px 24px;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: #4285f4;
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #357ae8;
}

.btn-secondary {
  background: transparent;
  color: white;
  border: 1px solid white;
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
  background: #dc3545;
  color: white;
}

.btn-danger:hover:not(:disabled) {
  background: #c82333;
}

.btn-outline {
  background: transparent;
  color: #4285f4;
  border: 1px solid #4285f4;
}

.btn-outline:hover:not(:disabled) {
  background: #f0f7ff;
  border-color: #357ae8;
  color: #357ae8;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

/* ============================================
   Document Container & Page
   ============================================ */
.document-container {
  max-width: 850px;
  margin: 30px auto;
  background: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  position: relative;
}

/* ============================================
   Bottom Button Container
   ============================================ */
.bottom-button-container {
  padding: 30px 60px 50px;
  text-align: center;
  background: white;
}

.bottom-button-container .btn-submit {
  min-width: 200px;
  padding: 14px 32px;
  font-size: 16px;
  font-weight: 600;
}

.page {
  background: white;
  padding: 50px 60px;
  position: relative;
  min-height: 1100px;
  transition: background-color 0.2s, border 0.2s;
}

.page.drag-over {
  background: rgba(66, 133, 244, 0.05);
  border: 3px dashed #4285f4;
  padding: 47px 57px;
}

.page + .page {
  border-top: 2px solid #ddd;
}

/* ============================================
   Document Header
   ============================================ */
.doc-header {
  text-align: center;
  border-bottom: 3px solid #000;
  padding-bottom: 15px;
  margin-bottom: 25px;
}

.doc-header h1 {
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 6px;
}

.doc-header p {
  font-size: 11px;
  margin: 2px 0;
  color: #333;
}

.doc-header h2 {
  font-size: 16px;
  font-weight: bold;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px solid #999;
}

/* ============================================
   Form Fields
   ============================================ */
.form-field {
  position: relative;
  margin-bottom: 18px;
}

.form-field-label {
  font-size: 12px;
  font-weight: bold;
  color: #000;
  margin-bottom: 4px;
  display: block;
}

.fillable-input {
  width: 100%;
  border: none;
  border-bottom: 2px solid #4285f4;
  background: rgba(66, 133, 244, 0.08);
  padding: 8px 6px;
  font-size: 13px;
  font-family: Arial, sans-serif;
  transition: all 0.2s;
  color: #000;
}

.fillable-input:focus {
  outline: none;
  background: rgba(66, 133, 244, 0.15);
  border-bottom-color: #1a73e8;
}

.fillable-input::placeholder {
  color: #999;
  font-style: italic;
}

.fillable-input[readonly] {
  background: rgba(0, 0, 0, 0.04);
  border-bottom-color: #999;
  color: #666;
}

.fillable-select {
  width: 100%;
  border: none;
  border-bottom: 2px solid #4285f4;
  background: rgba(66, 133, 244, 0.08);
  padding: 8px 6px;
  font-size: 13px;
  font-family: Arial, sans-serif;
  cursor: pointer;
  color: #000;
}

.fillable-select:focus {
  outline: none;
  background: rgba(66, 133, 244, 0.15);
  border-bottom-color: #1a73e8;
}

.textarea-field {
  width: 100%;
  border: 2px solid #4285f4;
  background: rgba(66, 133, 244, 0.08);
  padding: 8px;
  font-size: 12px;
  font-family: Arial, sans-serif;
  resize: vertical;
  min-height: 60px;
}

.textarea-field:focus {
  outline: none;
  background: rgba(66, 133, 244, 0.15);
  border-color: #1a73e8;
}

/* Field Layout */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.field-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

/* ============================================
   Radio & Checkbox Groups
   ============================================ */
.radio-group {
  display: flex;
  gap: 30px;
  margin: 12px 0;
}

.radio-group-vertical {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0;
}

.radio-option,
.checkbox-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.radio-option input[type="radio"],
.checkbox-option input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: #4285f4;
}

.radio-option label,
.checkbox-option label {
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
}

/* ============================================
   Tables
   ============================================ */
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 11px;
}

.items-table th {
  background: #f5f5f5;
  padding: 10px 6px;
  text-align: left;
  font-weight: bold;
  border: 1px solid #999;
  font-size: 11px;
}

.items-table td {
  padding: 6px;
  border: 1px solid #ddd;
  position: relative;
}

.items-table .line-num {
  text-align: center;
  font-weight: bold;
  background: #fafafa;
  width: 35px;
}

.table-input {
  width: 100%;
  border: none;
  background: rgba(66, 133, 244, 0.06);
  padding: 6px 4px;
  font-size: 11px;
  font-family: Arial, sans-serif;
}

.table-input:focus {
  outline: none;
  background: rgba(66, 133, 244, 0.12);
}

.table-select {
  width: 100%;
  border: none;
  background: rgba(66, 133, 244, 0.06);
  padding: 6px 4px;
  font-size: 11px;
  font-family: Arial, sans-serif;
  cursor: pointer;
  color: #000;
}

.table-select:focus {
  outline: none;
  background: rgba(66, 133, 244, 0.12);
}

/* ============================================
   Progress Indicator (Desktop: Floating Modal, Mobile: Toolbar)
   ============================================ */
.toolbar-center {
  /* Desktop: Floating modal in bottom-right corner */
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  width: auto;
}

.toolbar-progress-widget {
  background: #2d2d2d;
  padding: 16px 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  text-align: center;
  min-width: 220px;
  border: 2px solid #4285f4;
}

.progress-bar {
  height: 8px;
  background: #555;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
  width: 100%;
}

.progress-fill {
  height: 100%;
  background: #4285f4;
  transition: width 0.3s;
  width: 0%;
}

/* ============================================
   File Upload
   ============================================ */
.file-upload-box {
  border: 2px dashed #4285f4;
  border-radius: 8px;
  padding: 20px;
  background: rgba(66, 133, 244, 0.02);
  transition: all 0.3s;
  text-align: center;
  cursor: pointer;
}

.file-upload-box:hover {
  background: rgba(66, 133, 244, 0.05);
  border-color: #357ae8;
}

.file-upload-box.has-file {
  border-style: solid;
  background: rgba(66, 133, 244, 0.08);
}

.file-upload-box.drag-over {
  background: rgba(66, 133, 244, 0.1);
  border-color: #1a73e8;
}

.upload-area {
  border: 2px dashed #4285f4;
  border-radius: 8px;
  padding: 20px;
  background: rgba(66, 133, 244, 0.02);
  transition: all 0.3s;
  text-align: center;
}

.upload-area:hover {
  background: rgba(66, 133, 244, 0.05);
  border-color: #357ae8;
}

.custom-file-upload-btn {
  width: 100%;
  padding: 12px 20px;
  background: #4285f4;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  font-family: Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.custom-file-upload-btn:hover {
  background: #357ae8;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(66, 133, 244, 0.3);
}

.upload-icon {
  font-size: 18px;
  line-height: 1;
}

.drag-drop-hint {
  margin-top: 12px;
  font-size: 12px;
  color: #666;
  font-style: italic;
}

.file-input-hidden {
  display: none;
}

/* File List */
.file-list {
  margin-top: 10px;
}

.file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 12px;
}

.file-item-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-item-name {
  font-weight: 500;
  color: #333;
}

.file-item-size {
  color: #666;
  font-size: 11px;
}

.file-item-remove {
  background: #dc3545;
  color: white;
  border: none;
  padding: 4px 12px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}

.file-item-remove:hover {
  background: #c82333;
}

/* Image Preview */
.image-preview-container {
  display: none;
  position: relative;
  margin-top: 10px;
  max-width: 100%;
  overflow: hidden;
}

.image-preview,
#imagePreview {
  display: block;
  max-width: 100% !important;
  width: auto !important;
  height: auto !important;
  max-height: 300px !important;
  object-fit: contain !important;
  border-radius: 8px;
  border: 2px solid #4285f4;
}

.remove-image-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(220, 53, 69, 0.9);
  color: white;
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-image-btn:hover {
  background: #dc3545;
}

/* ============================================
   Info Box
   ============================================ */
.info-box {
  background: #f9f9f9;
  border: 1px solid #ccc;
  padding: 12px;
  margin: 20px 0;
  font-size: 10px;
}

.info-box h3 {
  font-size: 11px;
  margin-bottom: 6px;
  font-weight: bold;
}

.info-box p {
  margin: 3px 0;
  line-height: 1.4;
}

/* ============================================
   Section Styling
   ============================================ */
.form-section {
  margin-bottom: 30px;
}

.section-title {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 2px solid #ddd;
  color: #333;
}

/* ============================================
   Error & Success States
   ============================================ */
.error-message {
  background: #fff3f3;
  border: 1px solid #dc3545;
  color: #dc3545;
  padding: 12px 15px;
  border-radius: 4px;
  margin: 10px 0;
  font-size: 13px;
}

.success-message {
  background: #f0fff0;
  border: 1px solid #28a745;
  color: #28a745;
  padding: 12px 15px;
  border-radius: 4px;
  margin: 10px 0;
  font-size: 13px;
}

.warning-message {
  background: #fff8e1;
  border: 1px solid #ff9800;
  color: #e65100;
  padding: 12px 15px;
  border-radius: 4px;
  margin: 10px 0;
  font-size: 13px;
}

/* Field Error States */
.field-error .fillable-input,
.field-error .fillable-select,
.field-error .textarea-field {
  background: rgba(220, 53, 69, 0.08) !important;
  border-bottom-color: #dc3545 !important;
}

.field-error .form-field-label {
  color: #dc3545;
}

/* Radio group error state */
.radio-group.field-error {
  background: rgba(220, 53, 69, 0.08);
  padding: 8px;
  border-radius: 4px;
  border: 2px solid #dc3545;
}

/* File upload error state */
.field-error .file-upload-box {
  border-color: #dc3545 !important;
  background: rgba(220, 53, 69, 0.08) !important;
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  body {
    background: white;
    padding: 0;
  }

  .toolbar,
  .toolbar-progress-widget,
  .loading-overlay,
  .bottom-button-container {
    display: none !important;
  }

  .document-container {
    box-shadow: none;
    margin: 0;
    max-width: none;
  }

  .page {
    min-height: auto;
    padding: 30px;
  }

  .btn,
  .file-upload-box,
  .file-item-remove,
  .remove-image-btn {
    display: none !important;
  }

  .fillable-input,
  .fillable-select,
  .textarea-field {
    border: none;
    border-bottom: 1px solid #000;
    background: transparent;
  }
}

/* ============================================
   Responsive Styles
   ============================================ */
@media screen and (max-width: 768px) {
  /* Show toolbar on mobile */
  .toolbar {
    display: flex;
    background: #2d2d2d;
    color: white;
    padding: 12px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    justify-content: center;
    align-items: center;
  }

  /* Adjust progress widget for toolbar on mobile */
  .toolbar-center {
    position: static;
    width: 100%;
    bottom: auto;
    right: auto;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .toolbar-progress-widget {
    width: auto;
    max-width: 250px;
    background: transparent;
    padding: 0;
    box-shadow: none;
    border: none;
    border-radius: 0;
  }

  .progress-bar {
    background: #555;
  }

  .toolbar-actions {
    width: 100%;
    display: flex;
    gap: 8px;
    justify-content: space-between;
  }

  .toolbar-actions .btn {
    flex: 1;
    padding: 12px 16px;
    font-size: 13px;
    white-space: nowrap;
  }

  .document-container {
    margin: 15px;
  }

  .page {
    padding: 30px 20px;
    min-height: auto;
  }

  .bottom-button-container {
    padding: 20px;
  }

  .bottom-button-container .btn-submit {
    width: 100%;
    padding: 16px 24px;
  }

  .field-row,
  .field-row-3 {
    grid-template-columns: 1fr;
  }

  .radio-group {
    flex-direction: column;
    gap: 10px;
  }

  .toolbar-progress-widget {
    bottom: 10px;
    right: 10px;
    left: 10px;
    text-align: center;
  }

  .status-indicator {
    display: none;
  }
}
