/**
 * ISC License
 *
 * Copyright (c) 2026 idnovate.com
 * idnovate is a Registered Trademark & Property of idnovate.com, innovación y desarrollo SCP
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * @author    idnovate
 * @copyright 2026 idnovate.com
 * @license   https://www.isc.org/licenses/ https://opensource.org/licenses/ISC ISC License
 */

/* The main colour is injected as an inline custom property by the template.
   The fallback keeps the button usable on browsers without custom properties. */
.cb {
    position: fixed;
    bottom: calc(20px + var(--cb-safe-bottom, 0px));
    z-index: 9998;
    font-family: inherit;
    line-height: 1.4;
}

.cb--right {
    right: 20px;
}

.cb--left {
    left: 20px;
}

.cb [hidden] {
    display: none !important;
}

/* ---------------------------------------------------------------- Floating button */
.cb__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 12px 18px;
    border: 0;
    border-radius: 40px;
    border-radius: var(--cb-radius, 40px);
    border: solid var(--cb-border-color, transparent);
    border-width: var(--cb-border-width, 0);
    background: #2b5cd8;
    background: var(--cb-color, #2b5cd8) !important;
    color: #fff;
    color: var(--cb-header-text, #fff) !important;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.cb__toggle:hover,
.cb__toggle:focus {
    color: #fff;
    color: var(--cb-header-text, #fff) !important;
    text-decoration: none;
}

/* The lift stays on :hover only. On :focus it would remain raised after a click,
   so the bounce would not play again until the button lost focus. */
.cb__toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}

.cb__toggle:focus-visible {
    outline: 3px solid rgba(255, 255, 255, 0.75);
    outline-offset: 2px;
}

.cb__toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.cb__toggle-open {
    display: inline-flex;
    align-items: center;
}

.cb__toggle-label {
    white-space: nowrap;
}

.cb__toggle-close {
    display: none;
}

.cb.cb--open .cb__toggle-open {
    display: none;
}

.cb.cb--open .cb__toggle-close {
    display: inline-block;
}

/* ---------------------------------------------------------------------- Panel */
.cb__panel {
    position: absolute;
    bottom: calc(100% + 12px);
    width: 350px;
    max-width: calc(100vw - 40px);
    /* The panel grows upward from the button, so cap it to the space above the button
       and lay it out as a column: the header stays pinned and the body shrinks, so the
       header is never pushed off the top on short viewports. */
    max-height: calc(100vh - 90px);
    display: flex;
    flex-direction: column;
    border-radius: 14px;
    background: #fff;
    background: var(--cb-panel-bg, #fff) !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    animation: cb-in 0.18s ease-out;
}

.cb--right .cb__panel {
    right: 0;
}

.cb--left .cb__panel {
    left: 0;
}

@keyframes cb-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .cb__panel {
        animation: none;
    }

    .cb__toggle {
        transition: none;
    }
}

.cb__header {
    /* Sticky (not just pinned by flex): the embedded tawk.to widget has a fixed
       minimum height and, on short viewports, makes the panel scrollable. When the
       chat starts, tawk focuses its input and the browser scrolls the panel, which
       would carry a statically placed header out of view. Sticky keeps it on top. */
    position: sticky;
    top: 0;
    z-index: 2;
    flex: 0 0 auto;
    padding: 18px 44px 16px 44px;
    background: #2b5cd8;
    background: var(--cb-color, #2b5cd8) !important;
    color: #fff;
    color: var(--cb-header-text, #fff) !important;
}

.cb__title {
    margin: 0;
    color: #fff;
    color: var(--cb-header-text, #fff) !important;
    font-size: 16px;
    font-weight: 700;
}

.cb__subtitle {
    margin: 4px 0 0;
    color: #fff;
    color: var(--cb-header-text, #fff) !important;
    font-size: 13px;
    opacity: 0.9;
}

.cb__close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: inline-flex;
    padding: 4px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    color: var(--cb-header-text, #fff) !important;
    cursor: pointer;
    opacity: 0.85;
}

.cb__close:hover,
.cb__close:focus {
    opacity: 1;
}

/* Return-to-list control. It lives in the sticky header (not in the scrollable chat)
   so it stays reachable while the tawk.to chat scrolls. Shown only during the chat. */
.cb__header-back {
    position: absolute;
    top: 12px;
    left: 12px;
    display: inline-flex;
    padding: 4px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    color: var(--cb-header-text, #fff) !important;
    cursor: pointer;
    opacity: 0.85;
}

.cb__header-back:hover,
.cb__header-back:focus {
    opacity: 1;
}

.cb__offline {
    margin: 0;
    padding: 12px 18px;
    background: #fff8e5;
    border-bottom: 1px solid #f2e3b8;
    color: #6b5320;
    font-size: 13px;
}

/* ----------------------------------------------------------------- Channel list */
.cb__list {
    margin: 0;
    padding: 8px;
    list-style: none;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.cb__item {
    margin: 0;
    padding: 0;
    list-style: none;
}

.cb__link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #232323;
    color: var(--cb-text-color, #232323) !important;
    font-size: 14px;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.cb__link:hover,
.cb__link:focus {
    background: #f2f4f8;
    color: #232323;
    color: var(--cb-text-color, #232323) !important;
    text-decoration: none;
}

/* The badge colour is chosen per channel in the back office and injected inline. */
.cb__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #6b7280;
    background: var(--cb-icon-color, #6b7280);
    color: #fff;
}

.cb__text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.cb__label {
    font-weight: 600;
}

.cb__value {
    color: var(--cb-text-color, #232323);
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --------------------------------------------------------------- Embedded chat */
.cb__chat {
    display: flex;
    flex-direction: column;
    height: 420px;
    flex: 1 1 auto;
    min-height: 0;
}

.cb__chat-frame {
    flex: 1 1 auto;
    min-height: 0;
}

.cb__chat-frame iframe {
    width: 100% !important;
    height: 100% !important;
    border: 0;
}

.cb__chat-loading {
    margin: 0;
    padding: 12px 16px;
    color: #6b7280;
    font-size: 13px;
    text-align: center;
}

/* ------------------------------------------------------------ Device filtering */
@media (max-width: 767px) {
    .cb--desktop-only {
        display: none !important;
    }

    .cb {
        bottom: calc(14px + var(--cb-safe-bottom, 0px));
    }

    .cb--right {
        right: 14px;
    }

    .cb--left {
        left: 14px;
    }

    /* On phones the anchored panel is too small for the tawk.to widget, which gets cut
       off. Take the whole screen instead, so the chat has room and nothing is clipped. */
    .cb__panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }

    /* The full-screen panel has its own close and back controls, so the floating
       button is redundant (and would sit on top of the panel) while it is open. */
    .cb.cb--open .cb__toggle {
        display: none;
    }

    /* Make the tawk.to iframe fill the whole chat area edge to edge. Positioning the
       frame turns it into the iframe's containing block, so tawk's absolutely-placed
       iframe stretches to the frame's width and height instead of leaving a gap. */
    .cb__chat-frame {
        position: relative;
    }

    .cb__chat-frame iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
    }
}

@media (min-width: 768px) {
    .cb--mobile-only {
        display: none !important;
    }
}
