/* =========================================================
   UI POLISH (all portals)
   Loaded on every page by includes/portal_theme.php.
   Purely additive: no layout changes. Most rules use :where()
   (zero specificity) so each page's own styles still win.
========================================================= */


/* ---------- Text rendering ---------- */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

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

:where(h1, h2, h3, h4, h5, h6) {
    text-wrap: balance;
}

:where(p, li, small) {
    text-wrap: pretty;
}

/* Numbers line up in tables and stat cards */
:where(table, .table, .summary-value, .stat-value, .stat-number, .stat-card, .badge) {
    font-variant-numeric: tabular-nums;
}

::selection {
    background: rgba(var(--accent-rgb, 37, 99, 235), .18);
}


/* ---------- Smooth scrolling ---------- */

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* Anchored sections don't hide under sticky top bars */
:where([id]) {
    scroll-margin-top: 88px;
}


/* ---------- Smooth page-to-page navigation ---------- */
/* Supported browsers cross-fade between pages instead of flashing white. */

@view-transition {
    navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: .22s;
    animation-timing-function: cubic-bezier(.2, .8, .2, 1);
}


/* ---------- Consistent, soft interaction timing ---------- */
/* Applies only where a page hasn't defined its own transition. */

:where(a, button, .btn, .nav-link, .dropdown-item, .page-link, .list-group-item,
       .form-control, .form-select, .form-check-input, .input-group-text, .card) {
    transition-property: color, background-color, border-color, box-shadow, opacity, transform;
    transition-duration: .18s;
    transition-timing-function: cubic-bezier(.2, .8, .2, 1);
}

:where(a, button, .btn, [role="button"], label[for], summary) {
    -webkit-tap-highlight-color: transparent;
}

/* Gentle press feedback on buttons */
.btn:not(:disabled):not(.disabled):active {
    transform: translateY(1px);
}

/* Keyboard focus ring in the theme color (mouse clicks stay clean) */
:where(a, button, [tabindex], summary):focus-visible {
    outline: 2px solid rgba(var(--accent-rgb, 37, 99, 235), .55);
    outline-offset: 2px;
    border-radius: 6px;
}

:where(a, button, [tabindex]):focus:not(:focus-visible) {
    outline: none;
}

/* Disabled controls look clearly inactive */
:where(.btn:disabled, .btn.disabled, button:disabled) {
    cursor: not-allowed;
}


/* ---------- Tables ---------- */

:where(.table) > tbody > tr {
    transition: background-color .15s ease;
}

:where(.table-responsive) {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}


/* ---------- Bootstrap overlays feel smoother ---------- */

.dropdown-menu.show {
    animation: uiPolishPop .16s cubic-bezier(.2, .8, .2, 1) both;
    transform-origin: top center;
}

.modal.fade .modal-dialog {
    transition: transform .24s cubic-bezier(.2, .8, .2, 1), opacity .24s ease;
}

.modal-backdrop.show {
    opacity: .45;
}

:where(.modal-content) {
    border: 0;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .22);
}

.alert {
    animation: uiPolishFade .28s ease-out both;
}

.tooltip,
.popover {
    animation: uiPolishFade .14s ease-out both;
}


/* ---------- Scrollbars ---------- */

html {
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, .45) transparent;
}


/* ---------- Keyframes ---------- */

@keyframes uiPolishPop {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes uiPolishFade {
    from {
        opacity: 0;
        transform: translateY(-3px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ---------- Respect "reduce motion" ---------- */

@media (prefers-reduced-motion: reduce) {
    @view-transition {
        navigation: none;
    }

    *,
    *::before,
    *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}


/* ---------- Print stays clean ---------- */

@media print {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}
