/*!
 * Copyright 2022 youngmonkeys.org
 *
 * Licensed under the ezyplatform, Version 1.0.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://youngmonkeys.org/licenses/ezyplatform-1.0.0.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

/* ==================== theme tokens ==================== */
.ezychat-root {
    --ezychat-primary-from: #ff7675;
    --ezychat-primary-to: #ff8ba3;
    --ezychat-on-primary: #ffffff;
    --ezychat-surface: #ffffff;
    --ezychat-border: #e2e4e8;
    --ezychat-text: #2c3038;
    --ezychat-muted: #8a8f98;
    --ezychat-danger: #e03131;
    --ezychat-bubble-me-bg: #2d7ff9;
    --ezychat-bubble-me-text: #ffffff;
    --ezychat-bubble-other-bg: #ededf0;
    --ezychat-bubble-other-text: #2c3038;
    --ezychat-radius: 6px;
    --ezychat-panel-width: 350px;
    --ezychat-messages-height: 400px;
    --ezychat-z-index: 2147483000;
    --ezychat-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI",
        Roboto, "Helvetica Neue", Arial, sans-serif;

    font-family: var(--ezychat-font-family);
    font-size: 14px;
    line-height: 1.5;
    color: var(--ezychat-text);
}

/* the widget is injected into arbitrary themes, so reset what it owns */
.ezychat-root,
.ezychat-root *,
.ezychat-root *::before,
.ezychat-root *::after {
    box-sizing: border-box;
}

.ezychat-hidden {
    display: none !important;
}

/*
 * ezyweb.processUpdateApiErrors toggles the bootstrap `d-none` class on
 * the `<field>ErrorLabel` elements, keep it working without bootstrap
 * and without leaking the rule to the host theme.
 */
.ezychat-root .d-none {
    display: none !important;
}

/* ==================== toggle button ==================== */
.ezychat-toggle {
    position: fixed;
    right: 20px;
    bottom: 30px;
    z-index: var(--ezychat-z-index);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--ezychat-on-primary);
    background-image: linear-gradient(
        to top,
        var(--ezychat-primary-from) 0%,
        var(--ezychat-primary-to) 100%
    );
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* the open/close icon spans need a definite box so the launcher image
   inside can resolve its percentage sizing and get clipped to the
   button's shape; the ping ring below stays outside this box so it can
   still overflow the button to draw the eye */
.ezychat-toggle > span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    overflow: hidden;
}

.ezychat-toggle:hover {
    color: var(--ezychat-on-primary);
    transform: scale(1.06);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

.ezychat-toggle:focus {
    outline: none;
}

.ezychat-toggle:focus-visible {
    outline: 2px solid var(--ezychat-primary-to);
    outline-offset: 3px;
}

.ezychat-toggle-icon {
    display: block;
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* ==================== toggle launcher image ==================== */
.ezychat-toggle-img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: contain;
    background-color: #ffffff;
}

/* the border only decorates the launcher image itself, not the close
   icon that takes its place once the chat panel is open */
.ezychat-root[data-ezychat-launcher-image="true"] .ezychat-toggle:not(.ezychat-toggle-open) {
    border: 3px solid var(--ezychat-primary-from);
}

/* a subtle recurring pulse + ping ring to draw the eye to the launcher,
   only while the chat panel is closed */
.ezychat-root[data-ezychat-launcher-effect="true"] .ezychat-toggle:not(.ezychat-toggle-open) {
    animation: ezychat-toggle-attention 2.6s ease-in-out infinite;
}

.ezychat-root[data-ezychat-launcher-effect="true"] .ezychat-toggle:not(.ezychat-toggle-open)::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    background-color: var(--ezychat-primary-to);
    animation: ezychat-toggle-ping 2.6s ease-out infinite;
}

@keyframes ezychat-toggle-attention {
    0%, 80%, 100% { transform: scale(1); }
    88% { transform: scale(1.08); }
}

@keyframes ezychat-toggle-ping {
    0% { transform: scale(1); opacity: 0.55; }
    80%, 100% { transform: scale(1.6); opacity: 0; }
}

.ezychat-panel-close {
    position: absolute;
    top: 3px;
    left: 3px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    color: var(--ezychat-on-primary);
    background-color: var(--ezychat-primary-from);
    border: none;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    cursor: pointer;
}

.ezychat-panel-close:hover {
    background-color: var(--ezychat-primary-to);
}

.ezychat-panel-close:focus {
    outline: none;
}

.ezychat-panel-close:focus-visible {
    outline: 2px solid var(--ezychat-primary-from);
    outline-offset: 2px;
}

.ezychat-panel-close .ezychat-toggle-icon {
    width: 14px;
    height: 14px;
}

/* ==================== panel ==================== */
.ezychat-panel {
    position: fixed;
    right: 25px;
    bottom: 96px;
    z-index: var(--ezychat-z-index);
    width: var(--ezychat-panel-width);
    max-width: calc(100vw - 32px);
    overflow: hidden;
    background-color: var(--ezychat-surface);
    border-radius: var(--ezychat-radius);
    box-shadow: rgba(0, 0, 0, 0.35) 0 5px 15px;
}

@media (max-width: 420px) {
    .ezychat-panel {
        right: 16px;
        left: 16px;
        width: auto;
        max-width: none;
    }
}

/* ==================== toggle button variants ==================== */
/* position: mirror the toggle and panel to the opposite side */
.ezychat-root[data-ezychat-position="left"] .ezychat-toggle {
    right: auto;
    left: 20px;
}

.ezychat-root[data-ezychat-position="left"] .ezychat-panel {
    right: auto;
    left: 25px;
}

/* shape: circle is the default set on .ezychat-toggle above */
.ezychat-root[data-ezychat-button-style="rounded-square"] .ezychat-toggle {
    border-radius: 16px;
}

.ezychat-root[data-ezychat-button-style="square"] .ezychat-toggle {
    border-radius: 4px;
}

/* size: medium matches the default 52px/22px set on .ezychat-toggle above */
.ezychat-root[data-ezychat-size="small"] .ezychat-toggle {
    width: 44px;
    height: 44px;
}

.ezychat-root[data-ezychat-size="small"] .ezychat-toggle-icon {
    width: 18px;
    height: 18px;
}

.ezychat-root[data-ezychat-size="large"] .ezychat-toggle {
    width: 60px;
    height: 60px;
}

.ezychat-root[data-ezychat-size="large"] .ezychat-toggle-icon {
    width: 26px;
    height: 26px;
}

.ezychat-header {
    padding: 13px 15px;
    color: var(--ezychat-on-primary);
    background-image: linear-gradient(
        to top,
        var(--ezychat-primary-from) 0%,
        var(--ezychat-primary-to) 100%
    );
}

.ezychat-header-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    color: inherit;
}

.ezychat-intro {
    padding: 12px 15px 0;
    text-align: center;
    color: var(--ezychat-muted);
}

/* ==================== form ==================== */
.ezychat-form {
    padding: 15px;
}

.ezychat-input {
    display: block;
    width: 100%;
    margin: 0 0 10px;
    padding: 8px 12px;
    font: inherit;
    color: var(--ezychat-text);
    background-color: var(--ezychat-surface);
    border: 1px solid var(--ezychat-border);
    border-radius: var(--ezychat-radius);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ezychat-input::placeholder {
    color: var(--ezychat-muted);
}

.ezychat-input:focus {
    border-color: var(--ezychat-primary-to);
    box-shadow: 0 0 0 3px rgba(255, 139, 163, 0.25);
}

/*
 * the toggle sits on top of the input, so the bottom margin moves to the
 * wrapper to keep the height of the wrapper equal to the one of the input
 */
.ezychat-password {
    position: relative;
    margin: 0 0 10px;
}

.ezychat-password .ezychat-input {
    margin: 0;
    padding-right: 38px;
}

.ezychat-password-toggle {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 10px;
    color: var(--ezychat-muted);
    background: none;
    border: none;
    cursor: pointer;
}

.ezychat-password-toggle:hover {
    color: var(--ezychat-text);
}

.ezychat-password-icon {
    display: block;
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.ezychat-error-label {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0 0 4px;
    font-size: 12px;
    color: var(--ezychat-danger);
}

.ezychat-error-icon {
    flex: none;
    display: block;
    width: 13px;
    height: 13px;
    fill: currentColor;
}

.ezychat-btn {
    display: inline-block;
    padding: 8px 30px;
    font: inherit;
    font-weight: 600;
    color: var(--ezychat-on-primary);
    background-image: linear-gradient(
        to top,
        var(--ezychat-primary-from) 0%,
        var(--ezychat-primary-to) 100%
    );
    border: none;
    border-radius: var(--ezychat-radius);
    cursor: pointer;
    transition: filter 0.15s ease;
}

.ezychat-btn:hover {
    color: var(--ezychat-on-primary);
    filter: brightness(1.05);
}

.ezychat-btn:focus {
    outline: none;
}

.ezychat-btn:focus-visible {
    outline: 2px solid var(--ezychat-primary-to);
    outline-offset: 2px;
}

/* ==================== messages ==================== */
.ezychat-messages {
    position: relative;
    height: var(--ezychat-messages-height);
    max-height: 60vh;
    padding: 15px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ezychat-loading {
    padding: 6px 0;
    font-size: 13px;
    text-align: center;
    color: var(--ezychat-muted);
}

.ezychat-message {
    display: flex;
    margin-bottom: 12px;
}

.ezychat-message-me {
    justify-content: flex-end;
}

.ezychat-message-other {
    justify-content: flex-start;
}

.ezychat-message-body {
    min-width: 0;
    max-width: 75%;
}

.ezychat-avatar {
    flex: none;
    width: 36px;
    height: 36px;
    margin-right: 8px;
    border-radius: 50%;
    object-fit: cover;
}

.ezychat-bubble {
    margin: 0 0 4px;
    padding: 8px 10px;
    font-size: 13px;
    border-radius: var(--ezychat-radius);
    overflow-wrap: break-word;
    word-break: break-word;
}

.ezychat-bubble p {
    margin: 0 0 6px;
}

.ezychat-bubble p:last-child {
    margin-bottom: 0;
}

.ezychat-bubble h1,
.ezychat-bubble h2,
.ezychat-bubble h3,
.ezychat-bubble h4,
.ezychat-bubble h5,
.ezychat-bubble h6 {
    margin: 8px 0 6px;
    font-weight: 600;
    line-height: 1.3;
}

.ezychat-bubble h1:first-child,
.ezychat-bubble h2:first-child,
.ezychat-bubble h3:first-child,
.ezychat-bubble h4:first-child,
.ezychat-bubble h5:first-child,
.ezychat-bubble h6:first-child {
    margin-top: 0;
}

.ezychat-bubble h1 {
    font-size: 17px;
}

.ezychat-bubble h2 {
    font-size: 16px;
}

.ezychat-bubble h3 {
    font-size: 15px;
}

.ezychat-bubble h4,
.ezychat-bubble h5,
.ezychat-bubble h6 {
    font-size: 14px;
}

.ezychat-bubble ul,
.ezychat-bubble ol {
    margin: 0 0 6px;
    padding-left: 20px;
}

.ezychat-bubble ul:last-child,
.ezychat-bubble ol:last-child {
    margin-bottom: 0;
}

.ezychat-bubble pre {
    margin: 6px 0;
    padding: 8px;
    background-color: rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    overflow-x: auto;
    white-space: pre-wrap;
}

.ezychat-bubble code {
    background-color: rgba(0, 0, 0, 0.08);
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 12px;
}

.ezychat-bubble pre code {
    background-color: transparent;
    padding: 0;
}

.ezychat-bubble a {
    color: inherit;
    text-decoration: underline;
}

.ezychat-bubble blockquote {
    margin: 6px 0;
    padding-left: 8px;
    border-left: 2px solid currentColor;
    opacity: 0.85;
}

.ezychat-bubble-me {
    color: var(--ezychat-bubble-me-text);
    background-color: var(--ezychat-bubble-me-bg);
}

.ezychat-bubble-other {
    color: var(--ezychat-bubble-other-text);
    background-color: var(--ezychat-bubble-other-bg);
}

.ezychat-bubble-media {
    color: var(--ezychat-bubble-other-text);
    background-color: var(--ezychat-bubble-other-bg);
}

.ezychat-bubble-typing {
    background-color: transparent;
}

.ezychat-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 16px;
}

.ezychat-typing-dots > span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: var(--ezychat-muted);
    animation: ezychat-typing-bounce 1.2s infinite ease-in-out both;
}

.ezychat-typing-dots > span:nth-child(2) {
    animation-delay: 0.15s;
}

.ezychat-typing-dots > span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes ezychat-typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.ezychat-message-link {
    color: inherit;
    text-decoration: underline;
}

.ezychat-message-media {
    display: block;
    max-width: 100%;
    max-height: 200px;
    border-radius: 8px;
}

.ezychat-message-audio {
    display: block;
    max-width: 100%;
    height: 36px;
}

.ezychat-message-file {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ezychat-message-file-icon {
    flex: none;
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.ezychat-time {
    margin: 0;
    font-size: 11px;
    color: var(--ezychat-muted);
}

.ezychat-message-me .ezychat-time {
    text-align: right;
}

.ezychat-typing-status {
    display: flex;
    align-items: center;
    height: 28px;
    padding: 0 15px;
}

/* ==================== footer ==================== */
.ezychat-footer {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 4px;
    border-top: 1px solid var(--ezychat-border);
}

.ezychat-footer .ezychat-input {
    flex: 1 1 auto;
    min-width: 0;
    margin-bottom: 0;
}

.ezychat-file-input {
    display: none;
}

.ezychat-action-buttons {
    flex: none;
    display: flex;
    align-items: center;
    gap: 0;
}

.ezychat-add-menu-wrap {
    position: relative;
    flex: none;
}

.ezychat-add-menu {
    position: absolute;
    left: 0;
    bottom: calc(100% + 8px);
    z-index: 1;
    min-width: 170px;
    padding: 5px;
    background-color: var(--ezychat-surface);
    border: 1px solid var(--ezychat-border);
    border-radius: var(--ezychat-radius);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
}

.ezychat-add-menu-item {
    display: block;
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    font-size: 13px;
    line-height: 1.35;
    text-align: left;
    color: var(--ezychat-text);
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.ezychat-add-menu-item:hover,
.ezychat-add-menu-item:focus {
    background-color: rgba(255, 118, 117, 0.12);
    outline: none;
}

.ezychat-add-btn,
.ezychat-attach-btn,
.ezychat-send-btn {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    color: var(--ezychat-primary-from);
    background: none;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.ezychat-add-btn:hover,
.ezychat-attach-btn:hover,
.ezychat-send-btn:hover {
    background-color: rgba(255, 118, 117, 0.12);
}

.ezychat-add-btn:focus,
.ezychat-attach-btn:focus,
.ezychat-send-btn:focus {
    outline: none;
}

.ezychat-add-btn:focus-visible,
.ezychat-attach-btn:focus-visible,
.ezychat-send-btn:focus-visible {
    outline: 2px solid var(--ezychat-primary-to);
    outline-offset: 2px;
}

.ezychat-add-icon,
.ezychat-attach-icon,
.ezychat-send-icon {
    display: block;
    width: 18px;
    height: 18px;
    fill: currentColor;
}
