/* VeraChat in the bottom right corner of every page (_VeraChatWidget.cshtml, verachat-widget.js).
   A modern chat panel in the site's colours (_variables.scss, veraresurs.scss): the brand oranges,
   with dark text and icons on orange, since white on the brand oranges is 2.3:1. Unlike the chat
   inside the systems this is a small floating panel that a visitor opens and closes. */

.vcw {
    /* $orange-primary, $orange-medium, $orange-dark, $orange-text and $orange-text-hover. */
    --vcw-orange: #fcac45;
    --vcw-orange-medium: #F79239;
    --vcw-orange-dark: #e09030;
    --vcw-orange-text: #b35900;
    --vcw-orange-text-hover: #8a4400;
    /* The orange tints on Vera Resurs. */
    --vcw-user: #fff1e4;
    --vcw-user-line: #f5c79c;
    --vcw-panel: #f5f5f5;
    --vcw-text: #333;
    --vcw-muted: #5a5a5a;
    --vcw-line: #ddd;
    --vcw-error: #b23b3b;
    --vcw-error-bg: #fbeceb;
    --vcw-green: #3d7a45;
    /* Raised by the script while the cookie banner is showing, so the button never covers it. */
    --vcw-bottom: 20px;
    position: fixed;
    right: 20px;
    bottom: var(--vcw-bottom);
    z-index: 1040;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 14px;
    font-family: "Open Sans", "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--vcw-text);
    text-align: left;
    transition: bottom .2s ease;
}

/* ---- The round button ---- */

.vcw-launcher {
    position: relative;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: var(--vcw-orange-medium);
    color: #222;
    font-size: 26px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
    cursor: pointer;
    transition: transform .15s ease, background-color .15s ease;
}

    .vcw-launcher:hover {
        background: var(--vcw-orange-dark);
        color: #000;
        transform: scale(1.08);
    }

    .vcw-launcher:focus-visible {
        outline: 3px solid var(--vcw-orange-text);
        outline-offset: 5px;
    }

    /* A ring in the lighter brand orange; it goes when the panel is open. */
    .vcw-launcher::after {
        content: "";
        position: absolute;
        inset: -5px;
        border: 2px solid var(--vcw-orange);
        border-radius: 50%;
        transition: opacity .2s;
    }

/* FriSam2's VeraChat robot (inline SVG in _VeraChatWidget.cshtml). 640 x 512, like the Font Awesome glyph. */
.vcw-bot {
    display: block;
    width: 1.25em;
    height: 1em;
    fill: currentColor;
}

/* Two icons on top of each other: the robot, and the paper plane the button turns into as it becomes the
   send button. The script animates the change (see morph in verachat-widget.js); at rest the robot shows. */
.vcw-launcher .vcw-bot,
.vcw-launcher .vcw-launcher-send {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.vcw-launcher .vcw-launcher-send {
    opacity: 0;
    font-size: 22px;
}

.vcw.is-morphing .vcw-launcher::after {
    opacity: 0;
}

/* While the panel is open the button has become its send button. */
.vcw.is-open:not(.is-morphing) .vcw-launcher {
    visibility: hidden;
}

.vcw.is-morphing .vcw-send {
    opacity: 0;
}

/* ---- The panel ---- */

/* Fixed on its own, so it can be moved and resized. By default its bottom right corner is where the
   button is, so it opens out of the button. A moved or resized panel gets left, top, width and height
   inline from the script. */
.vcw-panel {
    position: fixed;
    right: 20px;
    bottom: var(--vcw-bottom);
    width: 380px;
    /* Clear of the site's fixed menu (about 100px) above and the cookie banner while it shows, below. */
    height: min(580px, calc(100vh - var(--vcw-bottom) - 120px));
    min-width: 300px;
    min-height: 320px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .22), 0 2px 6px rgba(0, 0, 0, .1);
}

/* Larger on larger screens, where a short panel leaves the answers cramped. */
@media (min-width: 1200px) and (min-height: 760px) {
    .vcw-panel {
        width: 440px;
        height: min(680px, calc(100vh - var(--vcw-bottom) - 120px));
    }
}

@media (min-width: 1600px) and (min-height: 900px) {
    .vcw-panel {
        width: 500px;
        height: min(800px, calc(100vh - var(--vcw-bottom) - 120px));
    }
}

    .vcw-panel[hidden] {
        display: none;
    }

    .vcw-panel.is-dragging,
    .vcw-panel.is-resizing {
        user-select: none;
    }

.vcw-head {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 10px 14px 16px;
    background: linear-gradient(135deg, var(--vcw-orange) 0%, var(--vcw-orange-medium) 100%);
    color: #222;
    /* The header moves the panel. */
    cursor: move;
    touch-action: none;
}

    .vcw-head button {
        cursor: pointer;
    }

/* The grip at the top of the header says the panel can be dragged, as on a sheet. */
.vcw-grip {
    position: absolute;
    top: 5px;
    left: 50%;
    width: 36px;
    height: 4px;
    margin-left: -18px;
    border-radius: 2px;
    background: rgba(34, 34, 34, .35);
}

/* Invisible strips along every edge and in every corner that resize the panel; the cursor shows it. */
.vcw-resize {
    position: absolute;
    z-index: 3;
    touch-action: none;
}

.vcw-resize-n,
.vcw-resize-s {
    left: 14px;
    right: 14px;
    height: 6px;
    cursor: ns-resize;
}

.vcw-resize-n { top: 0; }
.vcw-resize-s { bottom: 0; }

.vcw-resize-e,
.vcw-resize-w {
    top: 14px;
    bottom: 14px;
    width: 6px;
    cursor: ew-resize;
}

.vcw-resize-e { right: 0; }
.vcw-resize-w { left: 0; }

.vcw-resize-ne,
.vcw-resize-nw,
.vcw-resize-se,
.vcw-resize-sw {
    width: 14px;
    height: 14px;
}

.vcw-resize-ne { top: 0; right: 0; cursor: nesw-resize; }
.vcw-resize-nw { top: 0; left: 0; cursor: nwse-resize; }
.vcw-resize-se { bottom: 0; right: 0; cursor: nwse-resize; }
.vcw-resize-sw { bottom: 0; left: 0; cursor: nesw-resize; }

/* Shown the first time the panel opens on a larger screen. */
.vcw-tip {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 8px 8px 14px;
    border-bottom: 1px solid var(--vcw-user-line);
    background: var(--vcw-user);
    font-size: 12.5px;
    line-height: 1.4;
}

    .vcw-tip[hidden] {
        display: none;
    }

    .vcw .vcw-tip p {
        flex: 1 1 auto;
        margin: 2px 0 0;
        font-size: 12.5px;
        line-height: 1.4;
        color: var(--vcw-text);
    }

.vcw-tip-close {
    flex: none;
    width: 26px;
    height: 26px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--vcw-text);
    cursor: pointer;
}

    .vcw-tip-close:hover {
        background: rgba(0, 0, 0, .06);
    }

    .vcw-tip-close:focus-visible {
        outline: 2px solid var(--vcw-orange-text);
        outline-offset: 1px;
    }

.vcw-avatar {
    flex: none;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, .45);
    color: #222;
    font-size: 17px;
}

.vcw-head-text {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: 4px;
}

/* Reset against the site's heading styles in _style.scss. */
.vcw .vcw-title {
    margin: 0;
    padding: 0;
    font-family: 'Lato', sans-serif;
    font-size: 17px;
    font-weight: 900;
    letter-spacing: normal;
    text-transform: none;
    line-height: 1.2;
    color: #222;
}

.vcw-icon-btn {
    flex: none;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #222;
    font-size: 15px;
    cursor: pointer;
}

    .vcw-icon-btn:hover {
        background: rgba(255, 255, 255, .35);
    }

    .vcw-icon-btn:focus-visible {
        outline: 2px solid #222;
        outline-offset: 1px;
    }

/* ---- Messages ---- */

.vcw-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px 8px;
    background: var(--vcw-panel);
}

.vcw-msg {
    max-width: 88%;
    margin-bottom: 10px;
    padding: 9px 13px;
    border-radius: 14px;
    overflow-wrap: anywhere;
}

    .vcw-msg.user {
        margin-left: auto;
        background: var(--vcw-user);
        border: 1px solid var(--vcw-user-line);
        border-bottom-right-radius: 4px;
        white-space: pre-wrap;
    }

    .vcw-msg.assistant {
        background: #fff;
        border: 1px solid var(--vcw-line);
        border-bottom-left-radius: 4px;
    }

    .vcw-msg.error {
        max-width: 100%;
        background: var(--vcw-error-bg);
        color: var(--vcw-error);
        font-size: 13px;
    }

    .vcw-msg.removed {
        opacity: .5;
        margin-bottom: 2px;
    }

.vcw-removed-note {
    margin: 0 0 10px;
    font-size: 11px;
    color: var(--vcw-muted);
    text-align: right;
}

/* Markdown from VeraChat, rendered by the script. The site's p, ul and table styles are reset here. */
.vcw-msg.assistant p,
.vcw-msg.assistant ul,
.vcw-msg.assistant ol {
    margin: 0 0 8px;
    font-size: 14px;
    line-height: 1.5;
    color: inherit;
}

.vcw-msg.assistant > :last-child {
    margin-bottom: 0;
}

.vcw-msg.assistant ul,
.vcw-msg.assistant ol {
    padding-left: 20px;
}

.vcw-msg.assistant li {
    margin-bottom: 2px;
}

.vcw .vcw-msg.assistant h1,
.vcw .vcw-msg.assistant h2,
.vcw .vcw-msg.assistant h3 {
    margin: 4px 0 6px;
    padding: 0;
    font-family: 'Lato', sans-serif;
    font-size: 15px;
    font-weight: 900;
    letter-spacing: normal;
    text-transform: none;
    color: inherit;
}

.vcw-msg.assistant a {
    color: var(--vcw-orange-text);
    text-decoration: underline;
    text-underline-offset: 2px;
}

    .vcw-msg.assistant a:hover,
    .vcw-msg.assistant a:focus {
        color: var(--vcw-orange-text-hover);
    }

.vcw-msg.assistant code {
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--vcw-panel);
    font-size: 12.5px;
}

.vcw-msg.assistant pre {
    margin: 0 0 8px;
    padding: 8px;
    border-radius: 6px;
    background: var(--vcw-panel);
    font-size: 12.5px;
    white-space: pre-wrap;
}

.vcw-msg.assistant hr {
    margin: 8px 0;
    border: 0;
    border-top: 1px solid var(--vcw-line);
}

.vcw-table-wrap {
    margin: 0 0 8px;
    overflow-x: auto;
}

.vcw-table {
    border-collapse: collapse;
    font-size: 12.5px;
}

    .vcw-table th,
    .vcw-table td {
        padding: 4px 8px;
        border: 1px solid var(--vcw-line);
        vertical-align: top;
    }

    .vcw-table th {
        background: var(--vcw-panel);
    }

/* ---- Thumbs ---- */

.vcw-feedback {
    display: flex;
    align-items: center;
    gap: 2px;
    margin: -4px 0 12px 6px;
}

.vcw-thumb {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--vcw-muted);
    font-size: 14px;
    cursor: pointer;
}

    .vcw-thumb:hover:not(:disabled) {
        background: var(--vcw-user);
        color: var(--vcw-orange-text);
    }

    .vcw-thumb:disabled {
        cursor: default;
    }

    .vcw-thumb.active {
        color: var(--vcw-orange-text);
    }

.vcw-feedback-label {
    margin-left: 6px;
    font-size: 12px;
    color: var(--vcw-green);
}

/* ---- Thinking: the dots from Veratech's maintenance page (App_Offline.htm), two rows of three in the
   brand oranges, pulsing in a wave ---- */

.vcw-typing {
    display: inline-grid;
    grid-template-columns: repeat(3, 8px);
    gap: 5px;
    margin: 4px 0 12px 6px;
}

    .vcw-typing span:not(.visually-hidden) {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        animation: vcw-pulse 1.8s ease-in-out infinite;
    }

        .vcw-typing span:nth-child(3n+1) { background: #ffd6a1; }
        .vcw-typing span:nth-child(3n+2) { background: var(--vcw-orange); }
        .vcw-typing span:nth-child(3n+3) { background: #f18c34; }
        .vcw-typing span:nth-child(2),
        .vcw-typing span:nth-child(4) { animation-delay: .15s; }
        .vcw-typing span:nth-child(3),
        .vcw-typing span:nth-child(5) { animation-delay: .3s; }
        .vcw-typing span:nth-child(6) { animation-delay: .45s; }

@keyframes vcw-pulse {
    0%, 100% {
        transform: scale(.7);
        opacity: .5;
    }

    50% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ---- Input ---- */

.vcw-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    border-top: 1px solid var(--vcw-line);
    background: #fff;
}

    .vcw-form textarea {
        flex: 1 1 auto;
        min-height: 40px;
        max-height: 120px;
        padding: 9px 12px;
        border: 1px solid var(--vcw-line);
        border-radius: 10px;
        font: inherit;
        color: inherit;
        resize: none;
        overflow-y: auto;
    }

        .vcw-form textarea:focus {
            outline: none;
            /* The dark orange: the brand oranges are under 3:1 against white, too faint for a focus mark. */
            border-color: var(--vcw-orange-text);
            box-shadow: 0 0 0 2px rgba(179, 89, 0, .35);
        }

.vcw-send {
    flex: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: var(--vcw-orange-medium);
    color: #222;
    font-size: 15px;
    cursor: pointer;
}

    .vcw-send:hover:not(:disabled) {
        background: var(--vcw-orange-dark);
        color: #000;
    }

    .vcw-send:disabled {
        opacity: .5;
        cursor: default;
    }

    .vcw-send:focus-visible {
        outline: 3px solid var(--vcw-orange-text);
        outline-offset: 2px;
    }

/* ---- Phones: the panel takes the screen, the button stays where it is ---- */

@media (max-width: 575px) {
    .vcw {
        right: 14px;
        bottom: max(var(--vcw-bottom), 14px);
    }

    /* !important over the inline size and position of a panel moved or resized on a larger screen. */
    .vcw-panel {
        inset: 0 !important;
        width: auto !important;
        height: auto !important;
        min-width: 0;
        border-radius: 0;
    }

    /* No moving or resizing a panel that fills the screen. */
    .vcw-head {
        cursor: default;
    }

    .vcw-resize,
    .vcw-grip,
    .vcw-tip {
        display: none;
    }

    .vcw.is-open .vcw-launcher {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .vcw,
    .vcw-launcher,
    .vcw-launcher .vcw-bot,
    .vcw-launcher .vcw-launcher-send,
    .vcw-typing span {
        animation: none;
        transition: none;
    }

    .vcw-launcher:hover {
        transform: none;
    }
}
