/*
 * Built-in per-page help.
 *
 * The panel deliberately mirrors the keyboard-shortcuts overlay
 * (rad/static/css/keyboard_shortcuts.css) so the two help surfaces look like
 * the same feature. It is self-contained so pages that do not load the
 * shortcuts asset (for example candidate/CID pages) still get a styled panel.
 */

.penra-help-fab {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1500;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--bs-border-color, rgba(255, 255, 255, 0.2));
    background: var(--bs-primary, #0d6efd);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.4);
}

.penra-help-fab:hover,
.penra-help-fab:focus-visible {
    filter: brightness(1.1);
    color: #fff;
}

/* Keep the button clear of the on-screen keyboard / safe area on phones. */
@media (max-width: 575.98px) {
    .penra-help-fab {
        right: 0.75rem;
        bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }
}

/* Pages that also show a floating "Filters" handle in the bottom-right corner
   (see generic/partials/filter_bar.html) would otherwise overlap the help
   button. Lift the help button above the filter handle. */
html.penra-help-has-filter .penra-help-fab {
    bottom: 4.5rem;
}

@media (max-width: 575.98px) {
    html.penra-help-has-filter .penra-help-fab {
        bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
    }
}

.penra-help-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh 1rem 1rem;
    background: rgba(0, 0, 0, 0.55);
}

.penra-help-backdrop[hidden] {
    display: none;
}

.penra-help-panel {
    width: min(560px, 100%);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bs-body-bg, #1b1f24);
    color: var(--bs-body-color, #e6eef6);
    border: 1px solid var(--bs-border-color, rgba(255, 255, 255, 0.14));
    border-radius: 0.75rem;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.55);
}

.penra-help-panel .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.penra-help-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--bs-border-color, rgba(255, 255, 255, 0.12));
}

.penra-help-title {
    font-weight: 600;
}

.penra-help-summary {
    margin-top: 0.15rem;
    font-size: 0.85rem;
    color: var(--bs-secondary-color, rgba(255, 255, 255, 0.6));
}

.penra-help-body {
    overflow-y: auto;
    padding: 0.5rem 1rem;
}

.penra-help-steps {
    list-style: none;
    counter-reset: penra-help-step;
    margin: 0;
    padding: 0.5rem 0;
}

.penra-help-step {
    position: relative;
    padding: 0 0 0 2.4rem;
    margin-bottom: 1rem;
}

.penra-help-step::before {
    counter-increment: penra-help-step;
    content: counter(penra-help-step);
    position: absolute;
    left: 0;
    top: 0.1rem;
    width: 1.7rem;
    height: 1.7rem;
    border-radius: 50%;
    background: var(--bs-primary, #0d6efd);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.penra-help-step-title {
    font-weight: 600;
}

.penra-help-step-body {
    margin-top: 0.2rem;
    font-size: 0.9rem;
    color: var(--bs-secondary-color, rgba(255, 255, 255, 0.75));
}

.penra-help-step-links {
    margin-top: 0.35rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.penra-help-show {
    font-size: 0.75rem;
    padding: 0.05rem 0.5rem;
    border-radius: 0.3rem;
    border: 1px solid var(--bs-border-color, rgba(255, 255, 255, 0.2));
    background: transparent;
    color: var(--bs-secondary-color, rgba(255, 255, 255, 0.75));
    cursor: pointer;
}

.penra-help-show:hover {
    color: #fff;
    border-color: var(--bs-primary, #0d6efd);
}

.penra-help-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--bs-border-color, rgba(255, 255, 255, 0.12));
}

/* Applied briefly to the element a "Show me" step points at. */
.penra-help-highlight {
    outline: 3px solid var(--bs-warning, #ffc107) !important;
    outline-offset: 3px;
    border-radius: 0.25rem;
    animation: penra-help-pulse 1.2s ease-in-out 2;
}

@keyframes penra-help-pulse {
    0%,
    100% {
        outline-color: var(--bs-warning, #ffc107);
    }
    50% {
        outline-color: rgba(255, 193, 7, 0.2);
    }
}

/* Glossary terms inside help step text, with their definition popover. */
.penra-term {
    all: unset;
    cursor: help;
    color: inherit;
    border-bottom: 1px dotted var(--bs-info, #0dcaf0);
    font: inherit;
}

.penra-term:hover,
.penra-term:focus-visible {
    color: var(--bs-info, #0dcaf0);
    border-bottom-style: solid;
}

.penra-help-popover {
    position: fixed;
    z-index: 2100;
    width: min(320px, 90vw);
    padding: 0.6rem 0.75rem;
    background: var(--bs-body-bg, #1b1f24);
    color: var(--bs-body-color, #e6eef6);
    border: 1px solid var(--bs-border-color, rgba(255, 255, 255, 0.18));
    border-radius: 0.5rem;
    box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.5);
}

.penra-help-popover[hidden] {
    display: none;
}

.penra-help-popover-term {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.penra-help-popover-def {
    font-size: 0.85rem;
    color: var(--bs-secondary-color, rgba(255, 255, 255, 0.75));
}

.penra-help-popover-link {
    display: inline-block;
    margin-top: 0.4rem;
    font-size: 0.78rem;
}

