/* ==========================================================================
   ui-enhance.css — shared look & animation polish for all Bootstrap pages.

   Safety rules (so page behaviour is never affected):
   - Loaded right after Bootstrap, before each page's own styles.
   - Entrance animations use :where() (zero specificity), so any page rule wins.
   - Containers (sections, cards, rows, tables, dropdowns) animate OPACITY ONLY.
     A transform on a container would break position:fixed children (modals,
     popups) and Popper-positioned dropdowns.
   - Keyframes only define a start state and use fill-mode "backwards", so
     nothing is held after the animation ends (hover effects keep working).
   - No JavaScript.
   ========================================================================== */

:root {
  --ue-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ue-shadow-hover: 0 10px 24px rgba(15, 42, 92, 0.12);
}

html {
  scroll-behavior: smooth;
}

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

/* ========== Page entrance ========== */
:where(body > *:not(script):not(style):not(.modal):not(.modal-backdrop):not(.offcanvas):not(.offcanvas-backdrop):not(.toast-container)) {
  animation: ue-fadeIn 0.6s ease backwards;
}

:where(.navbar, header) {
  animation: ue-fadeIn 0.6s ease backwards;
}

/* grid columns appear one after another */
:where(.row > [class*="col"]) {
  animation: ue-fadeIn 0.6s ease backwards;
}

:where(.row > [class*="col"]:nth-child(2)) { animation-delay: 0.06s; }
:where(.row > [class*="col"]:nth-child(3)) { animation-delay: 0.12s; }
:where(.row > [class*="col"]:nth-child(4)) { animation-delay: 0.18s; }
:where(.row > [class*="col"]:nth-child(5)) { animation-delay: 0.24s; }
:where(.row > [class*="col"]:nth-child(6)) { animation-delay: 0.3s; }
:where(.row > [class*="col"]:nth-child(n+7)) { animation-delay: 0.36s; }

/* ========== Cards ========== */
:where(.card) {
  animation: ue-fadeIn 0.6s ease backwards;
  transition: box-shadow 0.35s var(--ue-ease), border-color 0.35s ease;
}

/* tiles in a grid get a soft shadow on hover (no movement) */
:where(.row > [class*="col"] > .card:hover) {
  box-shadow: var(--ue-shadow-hover);
}

/* ========== Buttons ========== */
:where(.btn:not(.btn-close):not(.btn-link):not(.dropdown-toggle)) {
  transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease,
    box-shadow 0.25s ease, transform 0.2s var(--ue-ease);
}

:where(.btn:not(.btn-close):not(.btn-link):not(.dropdown-toggle):not(:disabled):not(.disabled):hover) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

:where(.btn:not(.btn-close):not(.btn-link):not(:disabled):not(.disabled):active) {
  transform: scale(0.97);
}

/* buttons glued inside input groups / button groups stay put */
:where(.input-group .btn:hover, .btn-group .btn:hover, .btn-group-vertical .btn:hover) {
  transform: none;
}

:where(.btn-close) {
  transition: transform 0.3s var(--ue-ease), opacity 0.2s ease;
}

:where(.btn-close:hover) {
  transform: rotate(90deg);
}

/* ========== Form controls ========== */
:where(.form-control, .form-select) {
  transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}

:where(.form-check-input) {
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* ========== Tables ========== */
:where(.table tbody tr) {
  animation: ue-fadeIn 0.45s ease backwards;
}

:where(.table tbody tr:nth-child(2)) { animation-delay: 0.03s; }
:where(.table tbody tr:nth-child(3)) { animation-delay: 0.06s; }
:where(.table tbody tr:nth-child(4)) { animation-delay: 0.09s; }
:where(.table tbody tr:nth-child(5)) { animation-delay: 0.12s; }
:where(.table tbody tr:nth-child(6)) { animation-delay: 0.15s; }
:where(.table tbody tr:nth-child(7)) { animation-delay: 0.18s; }
:where(.table tbody tr:nth-child(8)) { animation-delay: 0.21s; }
:where(.table tbody tr:nth-child(9)) { animation-delay: 0.24s; }
:where(.table tbody tr:nth-child(n+10)) { animation-delay: 0.27s; }

:where(.table tbody td) {
  transition: background-color 0.2s ease;
}

/* ========== Modals ========== */
.modal.fade .modal-dialog {
  transform: translateY(24px) scale(0.96);
  transition: transform 0.4s var(--ue-ease);
}

.modal.show .modal-dialog {
  transform: none;
}

.modal-backdrop.show {
  backdrop-filter: blur(2px);
}

:where(.modal-content) {
  border-radius: 14px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.25);
}

/* ========== Dropdowns (Popper sets transform: opacity only here) ========== */
:where(.dropdown-menu.show) {
  animation: ue-fadeIn 0.2s ease backwards;
}

:where(.dropdown-item) {
  transition: background-color 0.2s ease, color 0.2s ease, padding 0.2s var(--ue-ease);
}

:where(.dropdown-item:hover) {
  padding-inline-start: 1.25rem;
}

/* ========== Alerts & toasts ========== */
:where(.alert) {
  animation: ue-slideDown 0.45s var(--ue-ease) backwards;
}

:where(.toast.show, .toast.showing) {
  animation: ue-slideUp 0.4s var(--ue-ease) backwards;
}

/* ========== Tabs, pills, list groups ========== */
:where(.nav-link) {
  transition: color 0.2s ease, background-color 0.25s ease, border-color 0.25s ease;
}

:where(.tab-pane.active) {
  animation: ue-fadeIn 0.4s ease backwards;
}

:where(.list-group-item) {
  animation: ue-fadeIn 0.45s ease backwards;
  transition: background-color 0.2s ease, color 0.2s ease;
}

:where(.list-group-item-action:hover) {
  background-color: rgba(15, 42, 92, 0.05);
}

/* ========== Badges & progress ========== */
:where(.badge) {
  animation: ue-pop 0.35s var(--ue-ease) backwards;
}

:where(.progress-bar) {
  animation: ue-grow 0.9s var(--ue-ease) 0.2s backwards;
}

/* ========== Pagination ========== */
:where(.page-link) {
  transition: color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

/* ========== Keyframes ========== */
@keyframes ue-fadeIn {
  from { opacity: 0; }
}

@keyframes ue-slideDown {
  from { opacity: 0; transform: translateY(-10px); }
}

@keyframes ue-slideUp {
  from { opacity: 0; transform: translateY(12px); }
}

@keyframes ue-pop {
  from { opacity: 0; transform: scale(0.7); }
}

@keyframes ue-grow {
  from { width: 0; }
}

/* ========== Print: no animations, everything fully visible ========== */
@media print {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

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

  :where(*, *::before, *::after) {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    transition-duration: 0.01ms !important;
  }
}
