/*
 * In-app help assistant widget.
 *
 * Anchored bottom-RIGHT, the corner people reach for.
 *
 * That corner is also where _NotificationCenter.cshtml puts its toast container
 * ("bottom-0 end-0"), so the two are kept apart deliberately rather than left to overlap:
 *
 *   - While the launcher alone is showing, toasts are raised just above it.
 *   - While the panel is open, toasts move to the bottom-LEFT, which is free.
 *
 * Both rules live at the end of this file. If you move the widget again, move those with it.
 *
 * Built on the Bootstrap 5.3 CSS variables already loaded by both layouts, so it inherits the
 * application's colours rather than restating them.
 */

.help-chat {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 10900; /* under the 11000 toast container, so an urgent toast still wins */
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
}

/* ------------------------------------------------------------------ launcher */

.help-chat__launcher {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border: none;
    border-radius: 2rem;
    background-color: var(--bs-primary, #0d6efd);
    color: #fff;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.25);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.help-chat__launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.4rem 1rem rgba(0, 0, 0, 0.3);
}

.help-chat__launcher:focus-visible {
    outline: 3px solid var(--bs-warning, #ffc107);
    outline-offset: 2px;
}

.help-chat__launcher i {
    font-size: 1.15rem;
}

/* The launcher stays visible while the panel is open on desktop — it doubles as the minimize
   affordance for anyone who reaches for it rather than the header control. */
.help-chat[data-state="open"] .help-chat__launcher {
    opacity: 0.85;
}

/* ------------------------------------------------------------------ panel */

.help-chat__panel {
    display: flex;
    flex-direction: column;
    width: 380px;
    height: 520px;
    max-height: calc(100dvh - 6rem);
    background-color: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.75rem;
    box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.help-chat--max .help-chat__panel {
    width: min(720px, calc(100vw - 2rem));
    height: calc(100dvh - 4rem);
}

.help-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.625rem 0.5rem 0.625rem 0.875rem;
    background-color: var(--bs-primary, #0d6efd);
    color: #fff;
}

.help-chat__title {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.help-chat__controls {
    display: inline-flex;
    gap: 0.125rem;
    flex-shrink: 0;
}

.help-chat__control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border: none;
    border-radius: 0.25rem;
    background: transparent;
    color: #fff;
    font-size: 0.85rem;
}

.help-chat__control:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.help-chat__control:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -2px;
}

/* ------------------------------------------------------------------ transcript */

.help-chat__log {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

.help-chat__log:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: -2px;
}

.help-chat__message {
    border-radius: 0.5rem;
    padding: 0.625rem 0.75rem;
    max-width: 100%;
}

.help-chat__message--user {
    align-self: flex-end;
    background-color: var(--bs-primary, #0d6efd);
    color: #fff;
    max-width: 85%;
}

.help-chat__message--answer {
    align-self: stretch;
    background-color: var(--bs-tertiary-bg, #f8f9fa);
    border: 1px solid var(--bs-border-color, #dee2e6);
}

.help-chat__message--status {
    align-self: flex-start;
    font-style: italic;
    color: var(--bs-secondary-color, #6c757d);
    padding: 0.25rem 0.5rem;
}

.help-chat__paragraph {
    margin: 0 0 0.5rem;
}

.help-chat__paragraph:last-child {
    margin-bottom: 0;
}

.help-chat__answer-heading {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    font-weight: 700;
}

.help-chat__answer-heading:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
}

.help-chat__heading {
    margin: 0.75rem 0 0.35rem;
    font-size: 0.9rem;
    font-weight: 700;
}

.help-chat__list {
    margin: 0 0 0.5rem;
    padding-left: 1.25rem;
}

.help-chat__item {
    margin-bottom: 0.2rem;
}

.help-chat__link {
    color: var(--bs-link-color, #0d6efd);
    text-decoration: underline;
}

/* ------------------------------------------------------------------ live-data tables */

/* Four columns do not fit a 380px panel. The table scrolls inside its own container so the panel
   - and the page behind it - never scroll sideways. */
.help-chat__table-wrap {
    overflow-x: auto;
    margin: 0 0 0.5rem;
}

.help-chat__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}

.help-chat__table th,
.help-chat__table td {
    padding: 0.3rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.help-chat__table th {
    font-weight: 600;
    color: var(--bs-secondary-color, #6c757d);
    border-bottom-width: 2px;
}

.help-chat__table tr:last-child td {
    border-bottom: none;
}

.help-chat__truncated {
    margin: 0 0 0.5rem;
    font-size: 0.75rem;
    font-style: italic;
    color: var(--bs-secondary-color, #6c757d);
}

/* ------------------------------------------------------------------ chips */

.help-chat__chips-heading {
    margin: 0.75rem 0 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--bs-secondary-color, #6c757d);
}

.help-chat__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.help-chat__chip {
    border: 1px solid var(--bs-primary, #0d6efd);
    border-radius: 1rem;
    background: transparent;
    color: var(--bs-primary, #0d6efd);
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    text-align: left;
}

.help-chat__chip:hover {
    background-color: var(--bs-primary, #0d6efd);
    color: #fff;
}

.help-chat__chip:focus-visible {
    outline: 2px solid var(--bs-warning, #ffc107);
    outline-offset: 1px;
}

/* ------------------------------------------------------------------ feedback */

.help-chat__feedback {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.625rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.help-chat__feedback-label {
    font-size: 0.78rem;
    color: var(--bs-secondary-color, #6c757d);
}

.help-chat__feedback-button {
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 1rem;
    background: transparent;
    color: var(--bs-secondary-color, #6c757d);
    font-size: 0.75rem;
    padding: 0.15rem 0.6rem;
}

.help-chat__feedback-button:hover {
    border-color: var(--bs-primary, #0d6efd);
    color: var(--bs-primary, #0d6efd);
}

.help-chat__feedback-button:focus-visible {
    outline: 2px solid var(--bs-warning, #ffc107);
    outline-offset: 1px;
}

/* ------------------------------------------------------------------ contact fallback */

.help-chat__contact {
    margin-top: 0.75rem;
    padding-top: 0.625rem;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
}

.help-chat__contact-intro {
    margin: 0 0 0.35rem;
    font-size: 0.8rem;
    color: var(--bs-secondary-color, #6c757d);
}

.help-chat__contact-name {
    margin: 0 0 0.2rem;
    font-weight: 600;
}

.help-chat__contact-line {
    margin: 0 0 0.15rem;
}

/* ------------------------------------------------------------------ composer */

.help-chat__form {
    display: flex;
    gap: 0.375rem;
    padding: 0.625rem;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    background-color: var(--bs-body-bg, #fff);
}

.help-chat__input {
    flex: 1 1 auto;
    font-size: 0.9rem;
}

.help-chat__send {
    flex-shrink: 0;
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 575.98px) {
    .help-chat {
        right: 0.75rem;
        bottom: 0.75rem;
    }

    .help-chat[data-state="open"] {
        inset: 0;
        right: 0;
        bottom: 0;
    }

    .help-chat[data-state="open"] .help-chat__panel,
    .help-chat--max[data-state="open"] .help-chat__panel {
        width: 100vw;
        height: 100dvh;   /* dvh, so the iOS URL bar cannot clip the input off the bottom */
        max-height: none;
        border: none;
        border-radius: 0;
    }

    /* Full screen already is maximized, so the control would be a no-op that still takes a tab
       stop. Minimize and close remain. */
    .help-chat[data-state="open"] .help-chat__control--maximize {
        display: none;
    }

    .help-chat[data-state="open"] .help-chat__launcher {
        display: none;
    }

    /* 16px stops iOS zooming the whole page when the field takes focus. */
    .help-chat__input {
        font-size: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .help-chat__launcher {
        transition: none;
    }

    .help-chat__launcher:hover {
        transform: none;
    }
}

/* ------------------------------------------------------------------ keeping clear of the toasts
 *
 * _NotificationCenter.cshtml renders #toast-container as "position-fixed bottom-0 end-0", the same
 * corner this widget now occupies. Rather than let a toast land on the launcher, it is nudged up
 * to clear it, and moved out of the way entirely while the panel is open.
 *
 * An ID selector outranks Bootstrap's .bottom-0 / .end-0 utility classes on specificity, so none
 * of this needs !important. It is scoped to this file so the relationship stays discoverable from
 * the widget rather than hidden in site.css.
 */

#toast-container {
    /* Clears the launcher pill plus its shadow. */
    bottom: 4.75rem;
}

/* Panel open: the bottom-right corner is taken, and the bottom-left is free. Toasts stay fully
   visible instead of stacking on top of an answer somebody is reading. */
body.help-chat-open #toast-container {
    bottom: 1rem;
    right: auto;
    left: 1rem;
}

@media (max-width: 575.98px) {
    /* The panel is full screen here, so there is nowhere to move a toast to. It keeps the higher
       z-index and floats over the panel, which is correct: on a phone an urgent notification
       should interrupt. */
    body.help-chat-open #toast-container {
        left: auto;
        right: 0;
        bottom: 0;
    }
}
