/*
 * UI details — radius, shadows, focus rings, icon alignment and motion
 * ("the seven checks", adopted 2026-11-10 — see CLAUDE.md "Brand theme &
 * the seven checks"). Sitewide, both themes. Loaded in base.html AFTER
 * theme-brand.css and toasts.css so its tokens win.
 *
 * Nothing here changes colour roles (that is the "one accent" layer in the
 * theme files). Every animation lives inside
 * @media (prefers-reduced-motion: no-preference).
 */

/* ── Tokens ──────────────────────────────────────────────────────────────
 * Radius: containers 10px, controls/menus 8px, anything nested 6px.
 * Bootstrap's own radius scale is re-pointed at the tokens so every
 * component that reads --bs-border-radius* follows (buttons, inputs,
 * dropdowns, list groups, alerts, pagination, .rounded). */
:root,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
    --cs-radius-lg: 10px;
    --cs-radius: 8px;
    --cs-radius-sm: 6px;

    --bs-border-radius: var(--cs-radius);
    --bs-border-radius-sm: var(--cs-radius-sm);
    --bs-border-radius-lg: var(--cs-radius-lg);

    /* Floating UI: two soft layers (contact + ambient), never one heavy blur */
    --cs-shadow-pop: 0 1px 2px rgba(20, 24, 35, 0.05), 0 4px 12px rgba(20, 24, 35, 0.07);
    --cs-shadow-overlay: 0 2px 4px rgba(20, 24, 35, 0.05), 0 12px 32px rgba(20, 24, 35, 0.12);

    /* Focus ring: the accent at ~35-40%, 2px, offset 2px */
    --cs-focus-ring: rgba(var(--bs-primary-rgb), 0.4);

    --cs-ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}
/* Dark mode separates by lightness + hairline; shadows are near-invisible */
[data-bs-theme="dark"] {
    --cs-shadow-pop: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.16);
    --cs-shadow-overlay: 0 2px 4px rgba(0, 0, 0, 0.2), 0 12px 32px rgba(0, 0, 0, 0.28);
    --cs-focus-ring: rgba(81, 195, 225, 0.45);
}
/* Chrome (sidebar + header) is dark in both themes: ring in cyan */
.navbar.bg-dark,
nav.sidebar-nav,
#mobileSidebar {
    --cs-focus-ring: rgba(81, 195, 225, 0.6);
}

/* ── Radius: containers ──────────────────────────────────────────────── */
.card {
    --bs-card-border-radius: var(--cs-radius-lg);
    --bs-card-inner-border-radius: calc(var(--cs-radius-lg) - 1px);
}
.modal {
    --bs-modal-border-radius: var(--cs-radius-lg);
    --bs-modal-inner-border-radius: calc(var(--cs-radius-lg) - 1px);
}
.offcanvas { --bs-offcanvas-border-radius: var(--cs-radius-lg); }
.popover {
    --bs-popover-border-radius: var(--cs-radius);
    --bs-popover-inner-border-radius: calc(var(--cs-radius) - 1px);
}
.toast { --bs-toast-border-radius: var(--cs-radius); }

/* ── Radius: nested = smaller than its container ─────────────────────── */
.dropdown-menu {
    --bs-dropdown-border-radius: var(--cs-radius);
    --bs-dropdown-inner-border-radius: calc(var(--cs-radius) - 1px);
    --bs-dropdown-padding-x: 0.25rem;
    --bs-dropdown-padding-y: 0.25rem;
    --bs-dropdown-item-border-radius: var(--cs-radius-sm);
    --bs-dropdown-item-padding-x: 0.75rem;
}
.badge { --bs-badge-border-radius: var(--cs-radius-sm); }
.tooltip { --bs-tooltip-border-radius: var(--cs-radius-sm); }
.nav-pills { --bs-nav-pills-border-radius: var(--cs-radius-sm); }
.card .list-group { --bs-list-group-border-radius: var(--cs-radius-sm); }
.card .alert { --bs-alert-border-radius: var(--cs-radius-sm); }
.card .card { --bs-card-border-radius: var(--cs-radius); --bs-card-inner-border-radius: calc(var(--cs-radius) - 1px); }

/* ── Shadows: floating UI only (cards keep the hairline from the theme) ─ */
.dropdown-menu { box-shadow: var(--cs-shadow-pop); }
.popover { --bs-popover-box-shadow: var(--cs-shadow-pop); box-shadow: var(--cs-shadow-pop); }
.toast { --bs-toast-box-shadow: var(--cs-shadow-pop); }
.modal-content { box-shadow: var(--cs-shadow-overlay); }
/* Bootstrap's heavy single-blur utilities soften to the layered tokens.
   Card-scoped theme rules (.card.shadow) are more specific and still win. */
.shadow-lg { box-shadow: var(--cs-shadow-overlay) !important; }
.shadow { box-shadow: var(--cs-shadow-pop) !important; }

/* ── Icons: one size per context, optically centred on the text ──────── */
.dropdown-item > .bi:first-child,
.sidebar-nav .nav-link .bi:first-child,
#mobileSidebar .nav-link .bi:first-child {
    display: inline-block;
    width: 1.25em;
    text-align: center;
}
.btn > .bi,
.card-header .bi,
.dropdown-item > .bi,
.nav-link > .bi {
    line-height: 1;
}
.card-header .bi { font-size: 1em; }

/* ── Focus: a visible accent ring for keyboard users, both themes ────── */
:is(.btn, .nav-link, .dropdown-item, .list-group-item-action, .page-link,
    .btn-close, a):focus-visible {
    outline: 2px solid var(--cs-focus-ring);
    outline-offset: 2px;
    box-shadow: none;
}
.dropdown-item:focus-visible,
.list-group-item-action:focus-visible {
    outline-offset: -2px;          /* inside the menu, not over its edge */
}
tr:is([role="button"], [data-row-href], .row-clickable, .clickable, [tabindex]):focus-visible {
    outline: 2px solid var(--cs-focus-ring);
    outline-offset: -2px;
}
/* Form controls and checkboxes keep the theme's accent focus (teal/cyan
   border + 0.25rem halo, set in theme-brand.css / dark-theme-fixes.css).
   Hover on nav items, dropdown items, list-group actions and clickable rows
   is already neutral (raised / tertiary bg) in the theme files. */

/* ── Motion ──────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {

    /* Dropdowns grow out of their toggle. Popper positions menus with an
       inline `transform`, so the animation uses the independent `scale` /
       `translate` properties, which compose with it instead of fighting it.
       Close is instant (Bootstrap sets display:none synchronously). */
    @keyframes cs-menu-in {
        from { opacity: 0; scale: 0.96; translate: 0 -4px; }
        to   { opacity: 1; scale: 1;    translate: 0 0; }
    }
    @keyframes cs-menu-up {
        from { opacity: 0; scale: 0.96; translate: 0 4px; }
        to   { opacity: 1; scale: 1;    translate: 0 0; }
    }
    .dropdown-menu.show {
        transform-origin: top left;
        animation: cs-menu-in 160ms var(--cs-ease-out);
    }
    .dropdown-menu.show:is(.dropdown-menu-end, [data-popper-placement$="end"]) {
        transform-origin: top right;
    }
    .dropup .dropdown-menu.show,
    .dropdown-menu.show[data-popper-placement^="top"] {
        transform-origin: bottom left;
        animation-name: cs-menu-up;
    }
    .dropup .dropdown-menu.show:is(.dropdown-menu-end, [data-popper-placement$="end"]),
    .dropdown-menu.show[data-popper-placement="top-end"] {
        transform-origin: bottom right;
    }

    /* Modals rise a few px instead of Bootstrap's 50px drop from above */
    .modal.fade .modal-dialog {
        transform: translateY(12px) scale(0.98);
        transition: transform 220ms var(--cs-ease-out);
    }
    .modal.show .modal-dialog { transform: none; }
    .modal.fade { transition: opacity 180ms ease-out; }

    /* Sidebar groups expand/collapse in ~180ms instead of Bootstrap's 350ms */
    .sidebar-nav .collapsing,
    #mobileSidebar .collapsing {
        transition: height 180ms ease-out;
    }

    /* Popovers and tooltips: quick fade, no snap */
    .tooltip.fade,
    .popover.fade { transition: opacity 120ms ease-out; }
}
