/**
 * Global UX enhancements — WellCare Pharmacy
 * Applies across all modules (layout, forms, tables, mobile)
 */

/* ----------------------------------------
   Base polish
   ---------------------------------------- */
html {
  scroll-behavior: smooth;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*:focus-visible {
  outline: 2px solid rgba(11, 107, 184, 0.55);
  outline-offset: 2px;
}

.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
a:focus-visible {
  outline: 2px solid rgba(11, 107, 184, 0.55);
  outline-offset: 2px;
}

/* ----------------------------------------
   Skip link (keyboard a11y)
   ---------------------------------------- */
.ux-skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 10000;
  padding: 0.75rem 1.25rem;
  background: #0b6bb8;
  color: #fff;
  font-weight: 600;
  border-radius: 0 0 0.5rem 0;
  text-decoration: none;
}

.ux-skip-link:focus {
  left: 0;
  color: #fff;
}

/* ----------------------------------------
   Menu search
   ---------------------------------------- */
.ux-menu-search {
  padding: 0.5rem 1rem 0.75rem;
  position: sticky;
  top: 0;
  z-index: 5;
  background: inherit;
}

.ux-menu-search-input {
  width: 100%;
  border: 1px solid #e7e7e8;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  font-size: 0.8125rem;
  color: #566a7f;
  background: #f5f5f9 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23a1acb8' viewBox='0 0 24 24'%3E%3Cpath d='M10 2a8 8 0 0 1 6.32 12.9l4.39 4.39-1.42 1.42-4.39-4.39A8 8 0 1 1 10 2zm0 2a6 6 0 1 0 0 12A6 6 0 0 0 10 4z'/%3E%3C/svg%3E") 0.7rem 50% no-repeat;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ux-menu-search-input:focus {
  outline: none;
  border-color: #0b6bb8;
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(11, 107, 184, 0.15);
}

.ux-menu-search-input::placeholder {
  color: #a1acb8;
}

.menu-item.ux-menu-hidden {
  display: none !important;
}

.ux-menu-empty {
  display: none;
  padding: 1rem 1.25rem;
  color: #a1acb8;
  font-size: 0.8125rem;
  text-align: center;
}

.ux-menu-empty.is-visible {
  display: block;
}

/* ----------------------------------------
   Navbar
   ---------------------------------------- */
.layout-navbar .navbar-nav-right {
  gap: 0.5rem;
}

.ux-navbar-greeting {
  display: none;
  flex-direction: column;
  line-height: 1.2;
  margin-right: 0.75rem;
  text-align: right;
}

.ux-navbar-greeting .ux-hello {
  font-size: 0.75rem;
  color: #a1acb8;
  margin: 0;
}

.ux-navbar-greeting .ux-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: #566a7f;
  margin: 0;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 992px) {
  .ux-navbar-greeting {
    display: flex;
  }
}

.ux-app-badges {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@media (max-width: 767.98px) {
  .ux-app-badges {
    display: none;
  }
}

.dropdown-user .dropdown-menu {
  min-width: 240px;
  border: 0;
  box-shadow: 0 8px 28px rgba(67, 89, 113, 0.16);
  border-radius: 0.75rem;
  padding: 0.5rem;
}

.dropdown-user .dropdown-item {
  border-radius: 0.5rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
}

.dropdown-user .dropdown-item:hover {
  background: rgba(11, 107, 184, 0.08);
  color: #0b6bb8;
}

.dropdown-user .dropdown-item.text-danger:hover {
  background: rgba(255, 62, 29, 0.08);
  color: #ff3e1d;
}

/* ----------------------------------------
   Cards / tables / filters — consistency
   ---------------------------------------- */
.card {
  border: 0;
  box-shadow: 0 2px 6px 0 rgba(67, 89, 113, 0.12);
  border-radius: 0.625rem;
}

.table-responsive {
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.table-responsive.ux-scroll-hint::after {
  content: "";
  pointer-events: none;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 28px;
  background: linear-gradient(to left, rgba(255, 255, 255, 0.95), transparent);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.table-responsive.ux-scroll-hint.has-overflow::after {
  opacity: 1;
}

.table-responsive.ux-scroll-hint.is-scrolled-end::after {
  opacity: 0;
}

/* DataTables polish */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
  border: 1px solid #e7e7e8;
  border-radius: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.875rem;
  color: #566a7f;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.dataTables_wrapper .dataTables_filter input:focus,
.dataTables_wrapper .dataTables_length select:focus {
  border-color: #0b6bb8;
  box-shadow: 0 0 0 3px rgba(11, 107, 184, 0.12);
  outline: none;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  border-radius: 0.4rem !important;
  margin: 0 2px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
  background: #0b6bb8 !important;
  border-color: #0b6bb8 !important;
  color: #fff !important;
}

.dataTables_wrapper .dataTables_info {
  color: #a1acb8;
  font-size: 0.8125rem;
  padding-top: 0.85rem !important;
}

table.dataTable thead th {
  white-space: nowrap;
}

/* Select2 */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
  border-color: #e7e7e8 !important;
  border-radius: 0.5rem !important;
  min-height: 38px;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple {
  border-color: #0b6bb8 !important;
  box-shadow: 0 0 0 3px rgba(11, 107, 184, 0.12);
}

.select2-dropdown {
  border-color: #e7e7e8 !important;
  border-radius: 0.5rem !important;
  box-shadow: 0 8px 24px rgba(67, 89, 113, 0.12);
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
  background-color: #0b6bb8 !important;
}

/* ----------------------------------------
   Forms
   ---------------------------------------- */
.form-control,
.form-select {
  border-radius: 0.5rem;
  border-color: #e7e7e8;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-select:focus {
  border-color: #0b6bb8;
  box-shadow: 0 0 0 3px rgba(11, 107, 184, 0.12);
}

.form-label {
  font-weight: 500;
  color: #566a7f;
  font-size: 0.8125rem;
  margin-bottom: 0.35rem;
}

.btn {
  border-radius: 0.5rem;
  font-weight: 500;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.btn-primary {
  box-shadow: 0 2px 6px rgba(11, 107, 184, 0.28);
}

.btn-primary:hover {
  box-shadow: 0 4px 12px rgba(11, 107, 184, 0.35);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn.ux-loading {
  position: relative;
  pointer-events: none;
  color: transparent !important;
}

.btn.ux-loading::after {
  content: "";
  position: absolute;
  width: 1rem;
  height: 1rem;
  top: 50%;
  left: 50%;
  margin: -0.5rem 0 0 -0.5rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ux-spin 0.6s linear infinite;
}

.btn-secondary.ux-loading::after,
.btn-outline-primary.ux-loading::after,
.btn-light.ux-loading::after {
  border-color: rgba(11, 107, 184, 0.25);
  border-top-color: #0b6bb8;
}

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

/* ----------------------------------------
   Page load progress bar
   ---------------------------------------- */
#ux-page-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  z-index: 10001;
  background: linear-gradient(90deg, #0b6bb8, #0ea5c6);
  transition: width 0.25s ease, opacity 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

#ux-page-progress.is-active {
  opacity: 1;
}

/* ----------------------------------------
   Confirm modal
   ---------------------------------------- */
.ux-confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(35, 52, 70, 0.45);
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ux-confirm-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

.ux-confirm-dialog {
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 16px 48px rgba(35, 52, 70, 0.2);
  max-width: 420px;
  width: 100%;
  padding: 1.5rem;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.2s ease;
}

.ux-confirm-backdrop.is-open .ux-confirm-dialog {
  transform: translateY(0) scale(1);
}

.ux-confirm-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: #fee2e2;
  color: #ff3e1d;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.ux-confirm-icon.info {
  background: #e0f2fe;
  color: #0284c7;
}

.ux-confirm-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: #233446;
  margin: 0 0 0.35rem;
}

.ux-confirm-message {
  color: #697a8d;
  font-size: 0.9rem;
  margin: 0 0 1.25rem;
  line-height: 1.5;
}

.ux-confirm-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* ----------------------------------------
   Alerts
   ---------------------------------------- */
.alert {
  border: 0;
  border-radius: 0.625rem;
  box-shadow: 0 2px 6px rgba(67, 89, 113, 0.08);
}

/* ----------------------------------------
   Sticky action bars on create/edit forms
   ---------------------------------------- */
.form-actions-sticky,
.create-form-actions,
.ux-sticky-actions {
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-top: 1px solid #e7e7e8;
  padding: 0.875rem 1.25rem;
  margin: 1rem -0.25rem 0;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  box-shadow: 0 -4px 16px rgba(67, 89, 113, 0.06);
  border-radius: 0 0 0.625rem 0.625rem;
}

/* ----------------------------------------
   Empty / loading helpers
   ---------------------------------------- */
.ux-empty-state {
  text-align: center;
  padding: 2.5rem 1.5rem;
  color: #a1acb8;
}

.ux-empty-state i {
  font-size: 2.5rem;
  color: #d9dee3;
  display: block;
  margin-bottom: 0.75rem;
}

.ux-empty-state h6 {
  color: #566a7f;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.ux-empty-state p {
  margin: 0;
  font-size: 0.875rem;
}

/* ----------------------------------------
   Mobile improvements
   ---------------------------------------- */
@media (max-width: 767.98px) {
  .container-p-y {
    padding-top: 1rem !important;
    padding-bottom: 1.25rem !important;
  }

  .module-header,
  .user-management-header,
  .leave-request-header,
  .create-form-header,
  .form-header,
  .branch-management-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 1rem;
    padding: 1rem 1.15rem !important;
  }

  .header-actions,
  .module-header .header-actions {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .header-actions > a,
  .header-actions > button,
  .module-header .header-actions > a,
  .module-header .header-actions > button {
    flex: 1 1 auto;
    justify-content: center;
    min-height: 42px;
  }

  .filter-card-body,
  .filter-grid {
    gap: 0.75rem;
  }

  .btn,
  .btn-primary-action,
  .btn-secondary-action,
  .btn-filter-apply,
  .btn-filter-reset {
    min-height: 40px;
  }

  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    float: none !important;
    text-align: left !important;
    width: 100%;
    margin-bottom: 0.5rem;
  }

  .dataTables_wrapper .dataTables_filter input {
    width: 100% !important;
    margin-left: 0 !important;
  }

  .layout-menu-toggle .nav-link {
    padding: 0.5rem !important;
  }
}

/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
  .menu-link,
  .dropdown-item,
  .btn-sm {
    min-height: 40px;
  }

  .paginate_button {
    min-width: 36px;
    min-height: 36px;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
