/*
 * Notices: the small messages of the site in one look. A variant says how important it is: help (the "i" that explains a field), info,
 * success, warning, error. It sets three variables, the accent colour, the tint of the background and the icon, and everything that is
 * a notice (the popup of a hint, the confirmation dialog, later the flash messages) reads them. The dark theme has its own colours
 * (css/dark.css); the scripts are in js/notice.js, the hint is Component/hint.latte.
 */

.notice-help    { --notice-color: #3b6ea5; --notice-tint: #eef4fb; --notice-icon: "\f431"; }
.notice-info    { --notice-color: #0b7285; --notice-tint: #e6f5f8; --notice-icon: "\f430"; }
.notice-success { --notice-color: #2f9e44; --notice-tint: #eaf7ed; --notice-icon: "\f26a"; }
.notice-warning { --notice-color: #b4690e; --notice-tint: #fff4dc; --notice-icon: "\f33a"; }
.notice-error   { --notice-color: #c92a2a; --notice-tint: #fdeaea; --notice-icon: "\f626"; }

.notice-icon::before {
    content: var(--notice-icon);
    font-family: bootstrap-icons !important;
    font-style: normal;
    font-weight: 400;
    line-height: 1;
    vertical-align: -.125em;
}

/* the hint: a small icon next to a field; the popup opens on a click (or a tap) */
.hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    min-height: 1.75rem;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--notice-color);
    font-size: 1rem;
    cursor: pointer;
}

.hint:hover,
.hint[aria-expanded="true"] {
    background: var(--notice-tint);
}

.hint:focus-visible {
    outline: 2px solid var(--notice-color);
    outline-offset: 1px;
}

.notice-popover {
    --notice-text: #333;
    --arrow-x: 50%;
    position: absolute;
    z-index: 1080;
    box-sizing: border-box;
    width: max-content;
    max-width: min(20rem, calc(100vw - 16px));
    padding: .65rem .85rem .65rem 2.4rem;
    border: 1px solid color-mix(in srgb, var(--notice-color) 40%, transparent);
    border-left: 4px solid var(--notice-color);
    border-radius: 10px;
    background: var(--notice-tint);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
    color: var(--notice-text);
    font-size: .9rem;
    line-height: 1.4;
}

.notice-popover::before {
    position: absolute;
    top: .65rem;
    left: .75rem;
    color: var(--notice-color);
    font-size: 1.1rem;
}

.notice-popover::after {
    content: "";
    position: absolute;
    left: var(--arrow-x);
    width: 10px;
    height: 10px;
    margin-left: -5px;
    background: var(--notice-tint);
    transform: rotate(45deg);
}

.notice-popover[data-placement="bottom"]::after {
    top: -6px;
    border-top: 1px solid color-mix(in srgb, var(--notice-color) 40%, transparent);
    border-left: 1px solid color-mix(in srgb, var(--notice-color) 40%, transparent);
}

.notice-popover[data-placement="top"]::after {
    bottom: -6px;
    border-right: 1px solid color-mix(in srgb, var(--notice-color) 40%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--notice-color) 40%, transparent);
}

/* the confirmation dialog: the icon and the colour of the variant, the question, two buttons */
.notice-dialog {
    --notice-text: #333;
    width: min(26rem, calc(100vw - 24px));
    padding: 0;
    border: 0;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
    color: var(--notice-text);
}

.notice-dialog::backdrop {
    background: rgba(15, 20, 27, .55);
}

.notice-dialog-form {
    margin: 0;
}

.notice-dialog-body {
    display: flex;
    gap: .9rem;
    padding: 1.25rem 1.25rem 1rem;
    border-top: 5px solid var(--notice-color);
    border-radius: 14px 14px 0 0;
}

.notice-dialog-icon {
    flex: 0 0 2.75rem;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    background: var(--notice-tint);
    color: var(--notice-color);
    font-size: 1.4rem;
    line-height: 2.75rem;
    text-align: center;
}

.notice-dialog-title {
    margin: 0 0 .25rem;
    font-size: 1.1rem;
    font-weight: 700;
}

.notice-dialog-message {
    margin: 0;
    overflow-wrap: anywhere;
}

.notice-dialog-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .5rem;
    padding: 0 1.25rem 1.25rem;
}

.notice-dialog .btn-notice {
    border-color: var(--notice-color);
    background: var(--notice-color);
    color: #fff;
}

.notice-dialog .btn-notice:hover,
.notice-dialog .btn-notice:focus {
    filter: brightness(.92);
    color: #fff;
}

/*
 * The flash messages: notices that float at the top of the page (Component/flash_toasts.latte); without the script they are plain notices in the flow of the page. An info or a success goes away by itself: a ring runs around its cross for the length of the countdown
 * (set in the style of the ring, FlashVariant::SECONDS), the end of the animation is the end of the notice, so pausing it (the pointer over it, the focus in it)
 * pauses both. A warning or an error has no ring and stays until it is closed.
 */
.toasts {
    margin: .5rem 0;
}

.toasts.is-floating {
    position: fixed;
    z-index: 1090;
    top: calc(.75rem + env(safe-area-inset-top, 0px));
    right: .75rem;
    left: .75rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    margin: 0;
    pointer-events: none;
}

body.is-local .toasts.is-floating {
    top: calc(2rem + env(safe-area-inset-top, 0px));
}

.toast-flash {
    --notice-text: #333;
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    box-sizing: border-box;
    width: 100%;
    max-width: 26rem;
    margin-bottom: .5rem;
    padding: .65rem .5rem .65rem .85rem;
    border: 1px solid color-mix(in srgb, var(--notice-color) 40%, transparent);
    border-left: 5px solid var(--notice-color);
    border-radius: 12px;
    background: var(--notice-tint);
    color: var(--notice-text);
    line-height: 1.4;
}

.is-floating .toast-flash {
    margin-bottom: 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
    animation: toast-in .25s ease-out;
    pointer-events: auto;
}

.is-floating .toast-flash.is-leaving {
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity .25s, transform .25s;
}

.toast-icon {
    flex: 0 0 auto;
    padding-top: .1rem;
    color: var(--notice-color);
    font-size: 1.25rem;
}

.toast-text {
    flex: 1;
    min-width: 0;
    padding-top: .15rem;
    overflow-wrap: anywhere;
}

.toast-text a {
    text-decoration: underline;
}

.toast-close {
    position: relative;
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    margin: -.15rem 0 -.15rem 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--notice-color);
    font-size: .85rem;
    cursor: pointer;
}

.toast-close:hover {
    background: color-mix(in srgb, var(--notice-color) 16%, transparent);
}

.toast-close:focus-visible {
    outline: 2px solid var(--notice-color);
    outline-offset: 1px;
}

/* the countdown: a ring that unwinds from the top (pathLength is 100 in the markup, so the numbers are percents) */
.toast-ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    pointer-events: none;
}

.toast-ring-circle {
    fill: none;
    stroke: var(--notice-color);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-dasharray: 100;
    stroke-dashoffset: 0;
}

.toast-flash:not(.toast-timed) .toast-ring {
    display: none;
}

.is-floating .toast-timed .toast-ring-circle {
    animation: toast-ring linear forwards;
}

.is-floating .toast-flash:hover .toast-ring-circle,
.is-floating .toast-flash:focus-within .toast-ring-circle {
    animation-play-state: paused;
}

@keyframes toast-ring {
    to { stroke-dashoffset: 100; }
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .is-floating .toast-flash { animation: none; }
    .is-floating .toast-flash.is-leaving { transform: none; }
}
