/* Base Reset & Variables */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-error: #dc2626;
  --color-success: #16a34a;
  --color-text: #1f2937;
  --color-text-light: #6b7280;
  --color-border: #d1d5db;
  --color-border-focus: #2563eb;
  --color-bg: #f9fafb;
  --color-bg-white: #ffffff;
  --color-bg-section: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --radius: 6px;
  --max-width: 720px;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
}

/* Container */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}

.header-logo {
  max-width: 180px;
  height: auto;
  margin-bottom: 0.75rem;
  background: transparent;
  mix-blend-mode: multiply;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--color-text);
}

header p {
  margin: 0;
  font-size: 1rem;
  color: var(--color-text-light);
}

header .header-subtitle {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  font-style: italic;
}

/* Section Helper Text */
.section-helper {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--color-text-light);
}

/* Form Sections */
.form-section {
  background: var(--color-bg-section);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.form-section h2 {
  margin: 0 0 1.25rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.form-section h3 {
  margin: 1.5rem 0 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-light);
}

.form-section h3:first-of-type {
  margin-top: 0;
}

/* Form Groups */
.form-group {
  margin-bottom: 1rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text);
}

/* Required Field Indicator */
.required {
  color: var(--color-error);
}

/* Inputs & Textareas */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="number"],
textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input:disabled,
textarea:disabled {
  background-color: var(--color-bg);
  color: var(--color-text-light);
  cursor: not-allowed;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* Radio & Checkbox Groups */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.radio-group label {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 400;
  cursor: pointer;
}

.radio-group input[type="radio"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
}

/* Present Checkbox */
.present-checkbox {
  margin-top: 0.5rem;
  font-size: 0.875rem;
}

/* Form Row (side-by-side fields) */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Field Notes */
.field-note {
  margin: 1rem 0 0;
  font-size: 0.8125rem;
  color: var(--color-text-light);
  font-style: italic;
}

/* Error Messages */
.error-message {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8125rem;
  color: var(--color-error);
  min-height: 1.25rem;
}

input.error,
textarea.error {
  border-color: var(--color-error);
}

input.error:focus,
textarea.error:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

/* Reference & Work Entries */
.reference-entry,
.work-entry {
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.reference-entry:first-of-type,
.work-entry:first-of-type {
  padding-top: 0;
  border-top: none;
}

.work-entry {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
}

.work-entry:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* Hidden Work History */
#workHistoryContainer.hidden {
  display: none;
}

/* Consent Text */
.consent-text {
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.consent-text p {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--color-text);
}

/* Signature Canvas */
.signature-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#signatureCanvas {
  width: 100%;
  height: 150px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background-color: var(--color-bg-white);
  cursor: crosshair;
  touch-action: none;
}

#signatureCanvas.signed {
  border-color: var(--color-success);
}

#signatureCanvas.error {
  border-color: var(--color-error);
}

/* Buttons */
.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  font-family: inherit;
  line-height: 1;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn-primary {
  width: 100%;
  background-color: var(--color-primary);
  color: #ffffff;
  border: 1px solid var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

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

.btn-secondary {
  align-self: flex-start;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  background-color: var(--color-bg-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background-color: var(--color-bg);
  border-color: var(--color-text-light);
}

/* Form Actions */
.form-actions {
  margin-top: 1.5rem;
}

/* Success Message */
.success-message {
  background-color: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  margin-top: 1.5rem;
}

.success-message h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  color: var(--color-success);
}

.success-message p {
  margin: 0;
  color: var(--color-text);
}

.success-message[hidden] {
  display: none;
}

/* Form hidden state after submission */
#applicationForm.submitted .form-section,
#applicationForm.submitted .form-actions {
  display: none;
}

/* Loading State */
.btn-primary.loading {
  position: relative;
  color: transparent;
}

.btn-primary.loading::after {
  content: "";
  position: absolute;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #ffffff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Mobile Responsive */
@media (max-width: 600px) {
  .container {
    padding: 1rem 0.75rem 2rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .form-section {
    padding: 1.25rem 1rem;
  }

  .form-section h2 {
    font-size: 1rem;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .radio-group {
    flex-direction: column;
    gap: 0.625rem;
  }

  #signatureCanvas {
    height: 120px;
  }

  .btn-primary {
    padding: 0.875rem 1.5rem;
  }
}

/* Print Styles */
@media print {
  body {
    background: #fff;
  }

  .container {
    max-width: none;
    padding: 0;
  }

  .form-section {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }

  .btn-primary,
  .btn-secondary {
    display: none;
  }
}
