/* =========================================================
   Red Dev Hub — chat widget
   ========================================================= */

.rdh-chat {
    position: fixed;
    right: clamp(16px, 3vw, 32px);
    bottom: clamp(16px, 3vw, 32px);
    z-index: 130;
    font-family: var(--font-body);
}

/* ---------- launcher ---------- */

.chat-launcher {
    position: relative;
    display: grid;
    place-items: center;
    width: 60px;
    height: 60px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 50%;
    background: linear-gradient(145deg, var(--red-bright), var(--red-deep));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 16px 40px rgba(179, 0, 27, 0.4), 0 6px 16px rgba(0, 0, 0, 0.35);
    transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease);
}

.chat-launcher:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 22px 48px rgba(179, 0, 27, 0.5), 0 8px 20px rgba(0, 0, 0, 0.4);
}

.chat-launcher:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 4px;
}

.chat-launcher svg {
    width: 26px;
    height: 26px;
}

.chat-launcher .chat-icon-close,
.chat-launcher .chat-icon-open {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    transition: opacity 0.25s ease, transform 0.35s var(--ease);
}

.chat-launcher .chat-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
}

.chat-launcher .chat-icon-open svg {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.28));
}

.rdh-chat.is-open .chat-launcher .chat-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.6);
}

.rdh-chat.is-open .chat-launcher .chat-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

.chat-ping {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: #3ddc84;
    border: 2px solid var(--bg);
}

.chat-ping::after {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: inherit;
    border: 2px solid rgba(61, 220, 132, 0.55);
    animation: chatPing 2.4s ease-out infinite;
}

.rdh-chat.is-open .chat-ping::after {
    animation: none;
}

@keyframes chatPing {
    0% { transform: scale(0.6); opacity: 1; }
    70% { transform: scale(1.7); opacity: 0; }
    100% { transform: scale(1.7); opacity: 0; }
}

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

.chat-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: min(560px, calc(100vh - 140px));
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 22px;
    background: linear-gradient(180deg, #16161a 0%, #0f0f12 100%);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(18px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.3s ease, transform 0.4s var(--ease), visibility 0.3s;
}

.rdh-chat.is-open .chat-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* ---------- header ---------- */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 14px;
    background: linear-gradient(120deg, rgba(179, 0, 27, 0.28), rgba(13, 13, 15, 0.1));
    border-bottom: 1px solid var(--line);
}

.chat-identity {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-avatar {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 13px;
    background: linear-gradient(145deg, var(--red-bright), var(--red-deep));
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    box-shadow: 0 8px 20px rgba(179, 0, 27, 0.35);
}

.chat-identity strong {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--muted);
    white-space: nowrap;
}

.chat-status i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #3ddc84;
    box-shadow: 0 0 8px rgba(61, 220, 132, 0.9);
}

.chat-close {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    color: var(--muted-2);
    cursor: pointer;
    transition: background 0.25s ease, color 0.25s ease, transform 0.25s ease;
}

.chat-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
    transform: rotate(90deg);
}

.chat-close:focus-visible {
    outline: 2px solid var(--red-bright);
    outline-offset: 2px;
}

.chat-close svg {
    width: 16px;
    height: 16px;
}

/* ---------- messages ---------- */

.chat-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

.chat-body::-webkit-scrollbar {
    width: 6px;
}

.chat-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
    border-radius: 999px;
}

.chat-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: chatMsgIn 0.35s var(--ease) both;
}

.chat-msg.is-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: linear-gradient(145deg, var(--red-bright), var(--red-deep));
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
}

.chat-bubble {
    padding: 10px 13px;
    border-radius: 16px 16px 16px 5px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.07);
    color: var(--muted-2);
    font-size: 0.875rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.chat-msg.is-bot .chat-bubble a {
    color: #ff6b7d;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-msg.is-bot .chat-bubble a:hover {
    color: #fff;
}

.chat-msg.is-user .chat-bubble {
    background: linear-gradient(145deg, var(--red-bright), var(--red-deep));
    border-color: transparent;
    color: #fff;
    border-radius: 16px 16px 5px 16px;
    box-shadow: 0 8px 22px rgba(179, 0, 27, 0.28);
}

.chat-bubble strong {
    color: var(--text);
}

@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* typing indicator */

.chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 13px 15px;
}

.chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: chatTyping 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.16s; }
.chat-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes chatTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- quick replies ---------- */

.chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 0 16px 12px;
}

.chat-quick.is-hidden {
    display: none;
}

.chat-quick button {
    padding: 7px 12px;
    border: 1px solid rgba(211, 27, 50, 0.4);
    border-radius: 999px;
    background: rgba(179, 0, 27, 0.1);
    color: var(--muted-2);
    font-family: inherit;
    font-size: 0.76rem;
    cursor: pointer;
    transition: background 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

.chat-quick button:hover {
    background: rgba(211, 27, 50, 0.22);
    border-color: var(--red-bright);
    color: #fff;
}

.chat-quick button:focus-visible {
    outline: 2px solid var(--red-bright);
    outline-offset: 2px;
}

/* ---------- input ---------- */

.chat-form {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 12px 12px 14px 16px;
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.02);
}

.chat-form input {
    flex: 1 1 auto;
    min-width: 0;
    height: 44px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    font-family: inherit;
    font-size: 0.87rem;
    outline: none;
    transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
}

.chat-form input::placeholder {
    color: rgba(255, 255, 255, 0.38);
}

.chat-form input:focus {
    border-color: rgba(211, 27, 50, 0.65);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 3px rgba(179, 0, 27, 0.18);
}

.chat-send {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--red-bright), var(--red-deep));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(179, 0, 27, 0.32);
    transition: transform 0.25s var(--ease), filter 0.25s ease;
}

.chat-send:hover {
    transform: scale(1.06);
    filter: brightness(1.12);
}

.chat-send:active {
    transform: scale(0.96);
}

.chat-send:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.chat-send svg {
    width: 18px;
    height: 18px;
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ---------- mobile ---------- */

@media (max-width: 520px) {
    .chat-panel {
        position: fixed;
        right: 12px;
        left: 12px;
        bottom: 92px;
        width: auto;
        max-width: none;
        height: min(74vh, 560px);
    }

    .chat-launcher {
        width: 54px;
        height: 54px;
    }

    .chat-launcher svg {
        width: 23px;
        height: 23px;
    }

    .chat-msg {
        max-width: 92%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-panel,
    .chat-launcher,
    .chat-msg,
    .chat-ping::after,
    .chat-typing span {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
