/**
 * UI/UX Improvements CSS for PaM GIS
 * Implements recommendations from UI_UX_IMPROVEMENT_REPORT.pdf
 * Version: 1.0
 */

/* ============================================================================
   1. ACCESSIBILITY IMPROVEMENTS
   ============================================================================ */

/* Skip navigation link */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: #000;
  color: #fff;
  padding: 8px 16px;
  z-index: 100;
  text-decoration: none;
  border-radius: 0 0 4px 0;
}

.skip-link:focus {
  top: 0;
}

/* Screen reader only content */
.visually-hidden,
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Focus indicators - WCAG 2.1 compliant */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
.btn:focus {
  outline: 3px solid #4A90E2;
  outline-offset: 2px;
}

*:focus-visible {
  outline: 3px solid #4A90E2;
  outline-offset: 2px;
}

/* Remove outline only when not using keyboard */
*:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================================================
   2. COLOR CONTRAST FIXES (WCAG AA Compliance)
   ============================================================================ */

/* Fix text-muted contrast */
.text-muted {
  color: #6c757d !important; /* Contrast ratio: 4.6:1 - PASS */
}

.text-secondary {
  color: #495057 !important; /* Contrast ratio: 7.1:1 - PASS AAA */
}

/* Ensure link contrast */
a {
  color: #363986;
}

a:hover {
  color: #252664;
}

/* ============================================================================
   3. MOBILE TOUCH TARGETS (44x44px minimum)
   ============================================================================ */

@media (max-width: 767.98px) {
  /* Buttons */
  .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  .btn-sm {
    min-height: 38px;
    min-width: 38px;
    padding: 8px 12px;
  }

  /* Form inputs */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    min-height: 44px;
    font-size: 16px; /* Prevent zoom on iOS */
  }

  /* Links */
  .nav-link,
  .dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 12px 16px;
  }

  /* Checkboxes and radio buttons */
  input[type="checkbox"],
  input[type="radio"] {
    width: 24px;
    height: 24px;
    margin: 10px;
  }

  /* Labels for checkboxes/radio */
  .form-check-label {
    padding-left: 8px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* Table action buttons */
  .table .btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* ============================================================================
   4. RESPONSIVE TABLES
   ============================================================================ */

.table-responsive-stack {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
  .table-responsive-stack table {
    border: 0;
  }

  .table-responsive-stack table thead {
    display: none;
  }

  .table-responsive-stack table tr {
    display: block;
    margin-bottom: 1.5rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  .table-responsive-stack table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border: none;
    border-bottom: 1px solid #dee2e6;
    min-height: 44px;
  }

  .table-responsive-stack table td:last-child {
    border-bottom: none;
  }

  .table-responsive-stack table td::before {
    content: attr(data-label);
    font-weight: 600;
    margin-right: 1rem;
    flex-shrink: 0;
    color: #495057;
  }

  .table-responsive-stack table td[data-label="Actions"] {
    justify-content: center;
  }

  .table-responsive-stack table td[data-label="Actions"]::before {
    display: none;
  }
}

/* ============================================================================
   5. BREADCRUMB NAVIGATION
   ============================================================================ */

.breadcrumb {
  background-color: transparent;
  padding: 1rem 0;
  margin-bottom: 1rem;
}

.breadcrumb-item + .breadcrumb-item::before {
  content: "›";
  color: #6c757d;
  font-size: 1.2em;
}

.breadcrumb-item a {
  color: #363986;
  text-decoration: none;
}

.breadcrumb-item a:hover {
  text-decoration: underline;
}

.breadcrumb-item.active {
  color: #6c757d;
}

/* ============================================================================
   6. LOADING STATES
   ============================================================================ */

/* Global loading overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

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

.loading-content {
  background-color: white;
  padding: 2rem;
  border-radius: 0.5rem;
  text-align: center;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  max-width: 90%;
}

.loading-message {
  margin: 0;
  color: #495057;
  font-weight: 500;
}

/* Inline loader */
.inline-loader {
  display: inline-flex;
  align-items: center;
  padding: 0.5rem;
}

/* Skeleton loader */
.skeleton-loader {
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-item {
  display: flex;
  padding: 1rem;
  border-bottom: 1px solid #f0f0f0;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: #e0e0e0;
  flex-shrink: 0;
}

.skeleton-content {
  flex: 1;
  margin-left: 1rem;
}

.skeleton-line {
  height: 12px;
  background-color: #e0e0e0;
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.skeleton-line.w-75 {
  width: 75%;
}

.skeleton-line.w-50 {
  width: 50%;
}

.skeleton-line.w-100 {
  width: 100%;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.6;
  }
}

/* ============================================================================
   7. FORM IMPROVEMENTS
   ============================================================================ */

/* Form validation states */
.form-control.is-invalid,
.form-select.is-invalid {
  border-color: #dc3545;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-valid,
.form-select.is-valid {
  border-color: #28a745;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.invalid-feedback {
  display: none;
  width: 100%;
  margin-top: 0.25rem;
  font-size: 0.875em;
  color: #dc3545;
}

.invalid-feedback[style*="display: block"] {
  display: block !important;
}

.form-control.is-invalid ~ .invalid-feedback,
.form-select.is-invalid ~ .invalid-feedback {
  display: block;
}

/* Required field indicator */
.required {
  color: #dc3545;
  margin-left: 2px;
}

/* Form help text */
.form-text {
  margin-top: 0.25rem;
  font-size: 0.875em;
  color: #6c757d;
}

/* ============================================================================
   8. NAVIGATION IMPROVEMENTS
   ============================================================================ */

/* Active navigation state */
.nav-link.active {
  color: #363986 !important;
  font-weight: 600;
  position: relative;
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background-color: #363986;
}

@media (max-width: 991.98px) {
  .nav-link.active::after {
    left: 0;
    width: 4px;
    height: 100%;
    bottom: auto;
    top: 0;
  }
}

/* Dropdown menu fixes */
.dropdown-menu {
  min-width: 200px;
}

@media (max-width: 991.98px) {
  .dropdown-menu {
    position: static !important;
    transform: none !important;
    width: 100%;
    border: none;
    box-shadow: none;
    background-color: rgba(0, 0, 0, 0.03);
  }

  .dropdown-item {
    padding: 1rem 1.5rem;
    white-space: normal;
  }

  .navbar-collapse {
    max-height: 80vh;
    overflow-y: auto;
  }
}

/* ============================================================================
   9. MOBILE FORM IMPROVEMENTS
   ============================================================================ */

@media (max-width: 575.98px) {
  /* Form groups */
  .form-group,
  .mb-3 {
    margin-bottom: 1.5rem !important;
  }

  /* Form labels */
  .form-label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 0.5rem;
  }

  /* Form controls */
  .form-control,
  .form-select {
    padding: 12px;
    font-size: 16px;
    border-radius: 8px;
  }

  /* Buttons full-width on mobile */
  .btn:not(.btn-sm):not(.btn-lg):not(.table .btn) {
    width: 100%;
    margin-bottom: 0.5rem;
  }

  /* Button groups */
  .btn-group {
    flex-direction: column;
    width: 100%;
  }

  .btn-group .btn {
    border-radius: 0.375rem !important;
    margin-bottom: 0.5rem;
  }

  /* Modal dialogs */
  .modal-dialog {
    margin: 0.5rem;
  }

  .modal-fullscreen-sm-down {
    width: 100vw;
    max-width: none;
    height: 100%;
    margin: 0;
  }
}

/* ============================================================================
   10. TOAST NOTIFICATIONS
   ============================================================================ */

.toast-container {
  z-index: 1090;
}

.toast {
  min-width: 250px;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.toast.show {
  display: block;
  opacity: 1;
}

.toast:not(.show) {
  display: none;
}

/* ============================================================================
   11. IMPROVED SPACING
   ============================================================================ */

/* Remove !important overrides */
@media (max-width: 575.98px) {
  .container {
    padding: 1rem;
  }

  .container.p-5 {
    padding: 1rem !important;
  }

  .nav.ps-3 {
    padding-left: 0 !important;
  }
}

/* ============================================================================
   12. PASSWORD STRENGTH INDICATOR
   ============================================================================ */

.password-strength-meter {
  height: 4px;
  background-color: #e0e0e0;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.5rem;
}

.strength-meter-fill {
  height: 100%;
  transition: width 0.3s, background-color 0.3s;
  width: 0%;
}

.strength-meter-fill[data-strength="1"] {
  width: 25%;
  background-color: #dc3545; /* Weak - Red */
}

.strength-meter-fill[data-strength="2"] {
  width: 50%;
  background-color: #ffc107; /* Fair - Yellow */
}

.strength-meter-fill[data-strength="3"] {
  width: 75%;
  background-color: #17a2b8; /* Good - Blue */
}

.strength-meter-fill[data-strength="4"] {
  width: 100%;
  background-color: #28a745; /* Strong - Green */
}

.password-requirements {
  list-style: none;
  padding: 0;
  margin-top: 0.5rem;
}

.password-requirements li {
  color: #6c757d;
  font-size: 0.875rem;
  padding: 0.25rem 0;
}

.password-requirements li.met {
  color: #28a745;
}

.password-requirements li .icon::before {
  content: "✗";
  color: #dc3545;
  margin-right: 0.5rem;
}

.password-requirements li.met .icon::before {
  content: "✓";
  color: #28a745;
}

/* ============================================================================
   13. SUCCESS ANIMATION
   ============================================================================ */

.success-checkmark {
  width: 80px;
  height: 80px;
  margin: 0 auto;
  animation: scaleIn 0.3s ease-in-out;
}

.check-icon {
  width: 80px;
  height: 80px;
  position: relative;
  border-radius: 50%;
  box-sizing: content-box;
  border: 4px solid #28a745;
}

.icon-line {
  height: 5px;
  background-color: #28a745;
  display: block;
  border-radius: 2px;
  position: absolute;
  z-index: 10;
}

.icon-line.line-tip {
  top: 46px;
  left: 14px;
  width: 25px;
  transform: rotate(45deg);
  animation: iconLineTip 0.75s;
}

.icon-line.line-long {
  top: 38px;
  right: 8px;
  width: 47px;
  transform: rotate(-45deg);
  animation: iconLineLong 0.75s;
}

@keyframes scaleIn {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes iconLineTip {
  0% { width: 0; left: 1px; top: 19px; }
  54% { width: 0; left: 1px; top: 19px; }
  70% { width: 50px; left: -8px; top: 37px; }
  84% { width: 17px; left: 21px; top: 48px; }
  100% { width: 25px; left: 14px; top: 45px; }
}

@keyframes iconLineLong {
  0% { width: 0; right: 46px; top: 54px; }
  65% { width: 0; right: 46px; top: 54px; }
  84% { width: 55px; right: 0px; top: 35px; }
  100% { width: 47px; right: 8px; top: 38px; }
}

/* ============================================================================
   14. UTILITY CLASSES
   ============================================================================ */

.page-break {
  page-break-before: always;
}

.no-wrap {
  white-space: nowrap;
}

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
