/**
 * Faraid Calculator Styles
 * Matches the design from the provided screenshots
 */

.faraid-calculator {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px 20px; /* buang padding atas supaya tajuk rapat ke atas */
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.faraid-calculator:focus {
  outline: none;
}

/* Progress Bar */
.faraid-progress-container {
  margin-top: 0; /* rapat dengan tajuk hijau */
  margin-bottom: 0; /* tiada jarak tambahan di bawah */
  margin-left: -20px; /* bentang penuh kiri/kanan */
  margin-right: -20px;
}

.faraid-progress-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  margin: 0; /* buang sebarang gap di atas/bawah */
  padding: 12px 0; /* pad kecil untuk ruang bernafas */
}

.faraid-progress-bar::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 4px;
  background: #e8edf3;
  z-index: 1;
}

.faraid-progress-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
  background: #fff;
  padding: 0 10px;
}

.faraid-step-number {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  margin-bottom: 8px;
  transition: all 0.3s ease;
}

.faraid-progress-step.active .faraid-step-number {
  background: #007527;
  color: white;
}

.faraid-progress-step.completed .faraid-step-number {
  background: #007527;
  color: white;
}

.faraid-progress-step.pending .faraid-step-number {
  background: #e0e0e0;
  color: #666;
}

.faraid-step-label {
  font-size: 22px;
  text-align: center;
  color: #4a4a4a;
  white-space: nowrap;
}

.faraid-progress-step.active .faraid-step-label {
  color: #007527;
  font-weight: 600;
}

.faraid-progress-step.completed .faraid-step-label {
  color: #007527;
  font-weight: 600;
}

/* Step Headers */
.faraid-step-header {
  margin-top: 0; /* rapat ke bahagian atas kontena */
  margin-bottom: 0; /* rapat dengan progress bar di bawah */
  margin-left: -20px; /* bentang penuh kiri/kanan */
  margin-right: -20px;
}

.faraid-step-header h2 {
  background: #007527;
  color: white;
  padding: 15px 20px;
  margin: 0; /* tiada jarak di bawah tajuk */
  border-radius: 8px 8px 0 0;
  font-size: 24px;
  font-weight: bold;
}

.faraid-step-header p {
  color: #666;
  line-height: 1.6;
  margin-bottom: 15px;
}

.faraid-step-header ul {
  margin: 10px 0;
  padding-left: 20px;
}

.faraid-step-header li {
  margin-bottom: 5px;
  color: #666;
}

/* Form Groups */
.faraid-form-group {
  margin-bottom: 20px;
}

.faraid-form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
}

.faraid-form-group input[type="text"],
.faraid-form-group input[type="email"],
.faraid-form-group input[type="tel"],
.faraid-form-group input[type="number"],
.faraid-form-group select {
  width: 100%;
  padding: 12px 15px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 16px;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
}

.faraid-form-group input:focus,
.faraid-form-group select:focus {
  outline: none;
  border-color: #007527;
}

.faraid-help-text {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  color: #666;
}

/* Radio Groups */
.faraid-radio-group {
  display: flex;
  gap: 20px;
  margin-top: 10px;
}

.faraid-radio-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-weight: normal;
  margin-bottom: 0;
}

.faraid-radio-label input[type="radio"] {
  display: none;
}

.faraid-radio-custom {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 2px solid #c9c9c9;
  border-radius: 50%;
  margin-right: 12px;
  position: relative;
  transition: all 0.2s ease-in-out;
  box-sizing: border-box;
  flex: 0 0 28px;
  line-height: 28px; /* ensure perfect circle */
}

.faraid-radio-label input[type="radio"]:checked + .faraid-radio-custom {
  border-color: #1a73e8;
  background: #1a73e8;
  box-shadow: 0 0 0 4px rgba(26, 115, 232, 0.2);
}

.faraid-radio-label input[type="radio"]:checked + .faraid-radio-custom::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
}

.faraid-radio-label {
  gap: 10px;
  font-size: 20px;
  align-items: center;
}

/* Info Box */
.faraid-info-box {
  background: #f8f9fa;
  border-left: 4px solid #007527;
  padding: 20px;
  margin: 20px 0;
  border-radius: 0 6px 6px 0;
}

.faraid-info-box h4 {
  margin: 0 0 10px 0;
  color: #007527;
  font-size: 16px;
}

.faraid-info-box p {
  margin: 0 0 15px 0;
  color: #666;
  line-height: 1.6;
}

.faraid-info-box ul {
  margin: 10px 0;
  padding-left: 20px;
}

.faraid-info-box li {
  margin-bottom: 5px;
  color: #666;
}

.faraid-info-box em {
  color: #888;
  font-size: 14px;
}

/* Buttons */
.faraid-btn {
  background: #007527;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-block;
}

.faraid-btn:hover {
  background: #005a1f;
  transform: translateY(-2px);
}

.faraid-btn:active {
  transform: translateY(0);
}

.faraid-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
}

.faraid-btn-back {
  background: #6c757d;
}

.faraid-btn-back:hover {
  background: #545b62;
}

.faraid-btn-reset {
  background: #dc3545;
}

.faraid-btn-reset:hover {
  background: #c82333;
}

/* Dev helper button */
.faraid-btn-random {
  background: #0d6efd;
}

.faraid-btn-random:hover {
  background: #0b5ed7;
}

/* Step Navigation */
.faraid-step-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.faraid-step-navigation .faraid-btn {
  min-width: 120px;
}

/* Results Table */
.faraid-results-table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.faraid-results-table th {
  background: #007527;
  color: white;
  padding: 15px;
  text-align: center;
  font-weight: 600;
}

.faraid-results-table td {
  padding: 15px;
  text-align: center;
  border-bottom: 1px solid #e0e0e0;
}

/* Fix: ensure rowspan (merged) cells are vertically centered and do not
   shift neighbouring cells. Apply explicit vertical-align and adjust
   padding for name column to maintain visual balance. */
.faraid-results-table td[rowspan],
.faraid-results-table th[rowspan] {
  vertical-align: middle;
}

/* Make name column left-aligned and allow it to control row height
   without pushing the merged cell content off-center. */
.faraid-results-table td:first-child,
.faraid-results-table th:first-child {
  text-align: left;
  padding-left: 22px;
}

/* Reduce padding on merged cell to match visual spacing from screenshot */
.faraid-results-table td[rowspan] {
  padding-top: 12px;
  padding-bottom: 12px;
}

/* Target merged bahagian cell with a specific class for precise tuning */
.faraid-results-table td.merged-bahagian {
  vertical-align: middle;
  line-height: 1.2; /* slightly tighter to visually center multi-row groups */
  font-weight: 500;
}
.faraid-results-table td.merged-bahagian.anak-perempuan {
  font-size: 18px; /* ensure 2/3 is prominent and appears centered */
}

.faraid-results-table tbody tr:hover {
  background: #f8f9fa;
}

.faraid-results-table tbody tr:last-child td {
  border-bottom: none;
}

/* Loading State */
.faraid-loading {
  text-align: center;
  padding: 40px;
  color: #666;
}

.faraid-loading p {
  font-size: 18px;
  margin: 0;
}

/* Error Messages */
.faraid-error {
  background: #f8d7da;
  color: #721c24;
  padding: 15px;
  border-radius: 6px;
  margin: 20px 0;
  border-left: 4px solid #dc3545;
}

.faraid-success {
  background: #d4edda;
  color: #155724;
  padding: 15px;
  border-radius: 6px;
  margin: 20px 0;
  border-left: 4px solid #28a745;
}

/* Form Validation */
.faraid-form-group.error input,
.faraid-form-group.error select {
  border-color: #dc3545;
}

.faraid-form-group .error-message {
  color: #dc3545;
  font-size: 14px;
  margin-top: 5px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .faraid-calculator {
    margin: 0; /* full width on mobile */
    padding: 0 8px 15px; /* no horizontal padding for full width */
  }

  .faraid-step-header {
    margin-left: -8px;
    margin-right: -8px;
  }

  .faraid-progress-container {
    margin-left: -8px;
    margin-right: -8px;
  }

  /* Bug fix: prevent steps from wrapping to a second line on any mobile size */
  .faraid-progress-bar {
    flex-wrap: nowrap;
    gap: 4px;
    padding: 10px 0;
  }

  .faraid-progress-step {
    flex: 1;
    min-width: 0;
    padding: 0 4px;
  }

  /* Scale down step circles at tablet/mobile so all 4 fit in one row */
  .faraid-step-number {
    width: 36px;
    height: 36px;
    font-size: 15px;
    margin-bottom: 5px;
  }

  .faraid-step-label {
    font-size: 11px;
  }

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

  /* Bug fix: radio label font was 20px globally — normalise on mobile */
  .faraid-radio-label {
    font-size: 14px;
  }

  .faraid-radio-custom {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
  }

  .faraid-step-navigation {
    flex-direction: column;
    gap: 15px;
  }

  .faraid-step-navigation .faraid-btn {
    width: 100%;
  }

  /* Results table: shrink-to-fit on mobile — no horizontal scroll needed */
  #faraid-results-container {
    overflow-x: visible;
  }

  .faraid-results-table {
    width: 100%;
    font-size: 12px;
    table-layout: fixed;
  }

  .faraid-results-table th {
    font-size: 10px;
    padding: 8px 4px;
    word-break: break-word;
    white-space: normal;
    line-height: 1.3;
  }

  .faraid-results-table td {
    font-size: 12px;
    padding: 8px 4px;
    word-break: break-word;
    white-space: normal;
  }

  /* Column width hints: heir name gets more space, share fraction gets less */
  .faraid-results-table th:nth-child(1),
  .faraid-results-table td:nth-child(1) {
    width: 30%;
  }

  .faraid-results-table th:nth-child(2),
  .faraid-results-table td:nth-child(2) {
    width: 18%;
  }

  .faraid-results-table th:nth-child(3),
  .faraid-results-table td:nth-child(3) {
    width: 26%;
  }

  .faraid-results-table th:nth-child(4),
  .faraid-results-table td:nth-child(4) {
    width: 26%;
  }
}

@media (max-width: 480px) {
  .faraid-step-header h2 {
    font-size: 20px;
    padding: 12px 8px;
  }

  /* Removed min-width: 60px here — would conflict with nowrap + min-width: 0 above */
  .faraid-step-number {
    width: 28px;
    height: 28px;
    font-size: 12px;
  }

  .faraid-step-label {
    font-size: 9px;
  }

  /* Further tighten table on very small phones */
  .faraid-results-table {
    font-size: 11px;
  }

  .faraid-results-table th {
    font-size: 9px;
    padding: 6px 3px;
  }

  .faraid-results-table td {
    font-size: 11px;
    padding: 6px 3px;
  }
}

/* Animation for step transitions */
.faraid-step {
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Focus states for accessibility */
.faraid-btn:focus,
.faraid-form-group input:focus,
.faraid-form-group select:focus {
  outline: 2px solid #007527;
  outline-offset: 2px;
}

/* Test Case Buttons */
.faraid-btn-test-case {
  background: #6f42c1 !important;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  margin-right: 10px;
}

.faraid-btn-test-case:hover {
  background: #5a32a3 !important;
}

/* Print styles */
@media print {
  .faraid-calculator {
    box-shadow: none;
    border: 1px solid #ccc;
  }

  .faraid-step-navigation,
  .faraid-btn {
    display: none;
  }
}
