:root {
  --primary-color: #1e3a8a;
  --secondary-color: #64748b;
  --success-color: #059669;
  --text-color: #1e293b;
  --border-color: #e2e8f0;
  --bg-light: #f8fafc;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Noto Sans Thai', 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  background-attachment: fixed;
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app-container {
  width: 100%;
  max-width: 900px;
}

.form-wrapper {
  background: white;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  padding: 2rem 1.5rem;
}

.form-title {
  color: var(--primary-color);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

/* ================================
   PROGRESS BAR - MOBILE OPTIMIZED
   ================================ */

.progress-container {
  margin: 1.5rem 0;
}

.progress-bar-wrapper {
  height: 4px;
  background: var(--border-color);
  border-radius: 4px;
  position: relative;
  margin-bottom: 1rem;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), #3b82f6);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 33.33%;
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  min-width: 0;
}

.step-number {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--secondary-color);
  transition: all 0.3s ease;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
}

.progress-step.active .step-number {
  border-color: var(--primary-color);
  background: var(--primary-color);
  color: white;
}

.progress-step.completed .step-number {
  border-color: var(--success-color);
  background: var(--success-color);
  color: white;
}

.step-label {
  font-size: 0.75rem;
  color: var(--secondary-color);
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
}

.progress-step.active .step-label {
  color: var(--primary-color);
  font-weight: 600;
}

/* ================================
   FORM STYLES - MOBILE OPTIMIZED
   ================================ */

.step-container {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.step-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border-color);
}

.step-header h2 {
  color: var(--primary-color);
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.step-header p {
  font-size: 0.9rem;
  line-height: 1.4;
}

.anonymous-id-badge {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--bg-light);
  border-left: 4px solid var(--primary-color);
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--secondary-color);
  margin-bottom: 1rem;
  word-break: break-all;
}

.form-label {
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 0.5rem;
  display: block;
  font-size: 0.95rem;
  line-height: 1.4;
}

.form-label.required::after {
  content: ' *';
  color: #dc2626;
}

.form-control,
.form-select {
  border: 2px solid var(--border-color);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  transition: all 0.2s ease;
  width: 100%;
  font-family: inherit;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* iOS Safari specific */
.form-control,
.form-select,
textarea.form-control {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
  outline: none;
}

.form-control.is-invalid {
  border-color: #dc2626;
}

.invalid-feedback {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: #dc2626;
  line-height: 1.3;
}

textarea.form-control {
  resize: vertical;
  min-height: 120px;
  line-height: 1.5;
}

.form-text {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: var(--secondary-color);
  line-height: 1.3;
}

.word-counter {
  color: var(--secondary-color);
  font-size: 0.875rem;
  font-weight: 500;
}

.mb-4 {
  margin-bottom: 1.25rem;
}

/* ================================
   BUTTONS - MOBILE OPTIMIZED
   ================================ */

.button-group {
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  margin-top: 1.5rem;
}

.btn {
  padding: 1rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  transition: all 0.2s ease;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  min-height: 48px; /* Minimum touch target size */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-lg {
  padding: 1.125rem 2rem;
  font-size: 1.05rem;
  min-height: 52px;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: #1e40af;
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background: #047857;
}

.btn-success:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-outline-secondary {
  background: white;
  color: var(--secondary-color);
  border: 2px solid var(--border-color);
}

.btn-outline-secondary:hover:not(:disabled) {
  background: var(--bg-light);
  border-color: var(--secondary-color);
}

.btn-outline-secondary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ================================
   SUCCESS SCREEN
   ================================ */

.success-container {
  text-align: center;
  padding: 2rem 1rem;
  animation: fadeIn 0.5s ease;
}

.success-icon {
  width: 70px;
  height: 70px;
  background: var(--success-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  margin: 0 auto 1.5rem;
  animation: scaleIn 0.5s ease;
}

@keyframes scaleIn {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

.success-container h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.anonymous-id-box {
  background: var(--bg-light);
  border: 2px solid var(--primary-color);
  border-radius: 12px;
  padding: 1.5rem 1rem;
  margin: 1.5rem 0;
}

.anonymous-id-box h3 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0.5rem 0;
  letter-spacing: 1px;
  color: var(--primary-color);
  word-break: break-all;
}

/* ================================
   MODAL - MOBILE OPTIMIZED
   ================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
  backdrop-filter: blur(4px);
  overflow-y: auto;
}

.modal-overlay.show {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 550px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
  max-height: 90vh;
  overflow-y: auto;
  margin: auto;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  padding: 1.5rem 1.5rem 1rem;
  text-align: center;
  border-bottom: 2px solid var(--border-color);
}

.modal-header h2 {
  color: #dc2626;
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
}

.modal-body {
  padding: 1.5rem;
}

.duplicate-info p {
  margin-bottom: 1rem;
  color: var(--text-color);
  font-size: 1rem;
  text-align: center;
  line-height: 1.4;
}

.anonymous-id-display {
  margin: 1rem 0;
}

.anonymous-id-display label {
  display: block;
  font-size: 0.85rem;
  color: var(--secondary-color);
  margin-bottom: 0.5rem;
  font-weight: 600;
  text-align: center;
}

.id-box {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  border: 2px solid #dc2626;
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: #dc2626;
  letter-spacing: 1px;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.2);
  word-break: break-all;
}

.help-text {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  padding: 1rem;
  border-radius: 8px;
  margin-top: 1rem;
}

.help-text p {
  margin: 0 0 0.5rem 0;
  color: #92400e;
  font-weight: 600;
  font-size: 0.9rem;
}

.help-text ul {
  margin: 0.5rem 0 0 0;
  padding-left: 1.25rem;
}

.help-text li {
  color: #92400e;
  margin: 0.4rem 0;
  font-size: 0.85rem;
  line-height: 1.4;
}

.modal-footer {
  padding: 1rem 1.5rem 1.5rem;
  text-align: center;
}

.modal-footer .btn {
  min-width: 180px;
}

/* ================================
   ALERT
   ================================ */

.alert {
  border-radius: 8px;
  border: none;
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  line-height: 1.4;
}

.alert-info {
  background: #dbeafe;
  color: #1e40af;
}

.alert-warning {
  background: #fef3c7;
  color: #92400e;
}

/* ================================
   LOADING SPINNER
   ================================ */

.checking-container {
  text-align: center;
  padding: 3rem 1rem;
}

.spinner-border {
  display: inline-block;
  width: 3rem;
  height: 3rem;
  border: 0.25em solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spinner-border 0.75s linear infinite;
  color: var(--primary-color);
}

@keyframes spinner-border {
  to {
    transform: rotate(360deg);
  }
}

/* ================================
   UTILITY CLASSES
   ================================ */

.text-center { text-align: center; }
.text-muted { color: var(--secondary-color); }
.text-primary { color: var(--primary-color); }
.text-danger { color: #dc2626; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mb-5 { margin-bottom: 3rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.w-100 { width: 100%; }

.d-flex { display: flex; }
.gap-2 { gap: 0.5rem; }
.justify-content-center { justify-content: center; }

/* ================================
   CHECK STATUS PAGE SPECIFIC
   ================================ */

.status-badge {
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85rem;
  display: inline-block;
  margin: 0.5rem 0;
}

.status-pending {
  background: #e0e7ff;
  color: #3730a3;
  border: 2px solid #6366f1;
}

.status-approved {
  background: #d1fae5;
  color: #065f46;
  border: 2px solid #059669;
}

.status-rejected {
  background: #fee2e2;
  color: #991b1b;
  border: 2px solid #dc2626;
}

.status-documents {
  background: #fef3c7;
  color: #92400e;
  border: 2px solid #f59e0b;
}

.result-container {
  margin-top: 1.5rem;
  animation: fadeIn 0.5s ease;
}

.card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.card-body {
  padding: 1.5rem;
}

.card-header {
  background: var(--bg-light);
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
  gap: 1rem;
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  font-weight: 600;
  color: var(--secondary-color);
  font-size: 0.9rem;
  flex-shrink: 0;
}

.info-value {
  color: var(--text-color);
  text-align: right;
  font-size: 0.9rem;
  word-break: break-word;
}

/* ================================
   SWEETALERT2 CUSTOM
   ================================ */

.swal-custom-popup {
  border-radius: 16px !important;
  font-family: 'Noto Sans Thai', 'Sarabun', sans-serif !important;
  padding: 1rem !important;
}

.swal-custom-button {
  border-radius: 8px !important;
  padding: 0.75rem 2rem !important;
  font-weight: 600 !important;
  min-height: 48px !important;
}

.swal2-html-container {
  font-family: 'Noto Sans Thai', 'Sarabun', sans-serif !important;
  font-size: 0.95rem !important;
  line-height: 1.5 !important;
}

.swal2-title {
  font-size: 1.3rem !important;
  line-height: 1.3 !important;
  padding: 0.5rem 0 !important;
}

/* ================================
   TABLET STYLES (768px - 1024px)
   ================================ */

@media (min-width: 768px) {
  body {
    padding: 2rem 1rem;
  }

  .form-wrapper {
    padding: 3rem 2.5rem;
  }

  .form-title {
    font-size: 2rem;
  }

  .step-header h2 {
    font-size: 1.75rem;
  }

  .step-number {
    width: 48px;
    height: 48px;
    font-size: 1rem;
  }

  .step-label {
    font-size: 0.875rem;
  }

  .button-group {
    margin-top: 2rem;
  }

  .btn {
    padding: 0.875rem 2rem;
  }

  .btn-lg {
    padding: 1rem 2.5rem;
    font-size: 1.1rem;
  }

  .success-icon {
    width: 80px;
    height: 80px;
    font-size: 3rem;
  }

  .success-container {
    padding: 3rem 2rem;
  }

  .anonymous-id-box h3 {
    font-size: 2rem;
    letter-spacing: 2px;
  }

  .modal-header h2 {
    font-size: 1.5rem;
  }

  .id-box {
    font-size: 1.75rem;
    padding: 1.25rem;
    letter-spacing: 2px;
  }
}

/* ================================
   MOBILE SPECIFIC (< 576px)
   ================================ */

@media (max-width: 576px) {
  body {
    padding: 0.5rem;
  }

  .form-wrapper {
    padding: 1.5rem 1rem;
    border-radius: 12px;
  }

  .form-title {
    font-size: 1.25rem;
  }

  .progress-container {
    margin: 1rem 0;
  }

  .step-header {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
  }

  .step-header h2 {
    font-size: 1.1rem;
  }

  .step-header p {
    font-size: 0.85rem;
  }

  .button-group {
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.25rem;
  }

  .btn {
    width: 100%;
    padding: 1rem;
  }

  .btn-lg {
    width: 100%;
    padding: 1.125rem;
  }

  /* Hide step labels on very small screens */
  .step-label {
    font-size: 0.65rem;
  }

  .step-number {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }

  /* Modal adjustments */
  .modal-content {
    margin: 0.5rem;
    max-height: 95vh;
  }

  .modal-header {
    padding: 1rem;
  }

  .modal-body {
    padding: 1rem;
  }

  .modal-footer {
    padding: 1rem;
  }

  .modal-footer .btn {
    width: 100%;
    min-width: auto;
  }

  /* Success screen mobile */
  .success-container {
    padding: 1.5rem 0.5rem;
  }

  .success-container h2 {
    font-size: 1.25rem;
  }

  .anonymous-id-box {
    padding: 1rem 0.75rem;
  }

  .anonymous-id-box h3 {
    font-size: 1.25rem;
  }

  /* Alert mobile */
  .alert {
    font-size: 0.85rem;
    padding: 0.875rem;
  }

  /* Form elements */
  .form-control,
  .form-select {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 0.875rem 0.75rem;
  }

  .form-label {
    font-size: 0.9rem;
  }

  .form-text,
  .invalid-feedback {
    font-size: 0.8rem;
  }

  /* Card for check status */
  .card-body {
    padding: 1rem;
  }

  .info-row {
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.625rem 0;
  }

  .info-label,
  .info-value {
    text-align: left;
    font-size: 0.85rem;
  }

  .status-badge {
    font-size: 0.8rem;
    padding: 0.4rem 0.8rem;
  }
}

/* ================================
   VERY SMALL SCREENS (< 375px)
   ================================ */

@media (max-width: 375px) {
  .form-title {
    font-size: 1.1rem;
  }

  .step-header h2 {
    font-size: 1rem;
  }

  .step-label {
    display: none; /* Hide completely on very small screens */
  }

  .progress-steps {
    gap: 0.25rem;
  }

  .form-wrapper {
    padding: 1.25rem 0.875rem;
  }

  .anonymous-id-box h3 {
    font-size: 1.1rem;
  }
}

/* ================================
   LANDSCAPE MODE (Mobile)
   ================================ */

@media (max-height: 500px) and (orientation: landscape) {
  body {
    padding: 0.5rem;
  }

  .form-wrapper {
    padding: 1rem;
  }

  .step-header {
    margin-bottom: 0.75rem;
  }

  .mb-4 {
    margin-bottom: 0.75rem;
  }

  .progress-container {
    margin: 0.75rem 0;
  }

  .button-group {
    margin-top: 1rem;
  }

  .modal-content {
    max-height: 95vh;
  }
}

/* ================================
   TOUCH IMPROVEMENTS
   ================================ */

@media (hover: none) and (pointer: coarse) {
  /* This targets touch devices */
  
  .btn {
    min-height: 48px; /* Ensure minimum touch target */
  }

  .form-control,
  .form-select {
    min-height: 48px;
  }

  /* Remove hover effects on touch devices */
  .btn:hover {
    transform: none;
    box-shadow: none;
  }

  /* Add active/pressed state instead */
  .btn:active {
    opacity: 0.8;
  }
}

/* ================================
   DARK MODE SUPPORT (Optional)
   ================================ */

@media (prefers-color-scheme: dark) {
  /* Add dark mode styles if needed */
}

/* ================================
   PRINT STYLES
   ================================ */

@media print {
  body {
    background: white;
  }

  .form-wrapper {
    box-shadow: none;
  }

  .button-group {
    display: none;
  }
}

/* ================================
   ACCESSIBILITY IMPROVEMENTS
   ================================ */

/* Focus visible for keyboard navigation */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn {
    border: 2px solid currentColor;
  }

  .form-control,
  .form-select {
    border-width: 3px;
  }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}