/* ------------------------------------------------------------------
   TeyaRx chat widget
   Tokens mirror the site's palette (index.html :root): teal primary,
   navy ink, soft cream surfaces, Inter type, pill CTAs, 12-20px radii.
   ------------------------------------------------------------------ */
:root {
    --rx-teal: #0a8f75;
    --rx-teal-dark: #077a63;
    --rx-teal-light: #e6f7f4;
    --rx-navy: #1a2b4a;
    --rx-gray-100: #f7f8fa;
    --rx-gray-200: #e8ecf1;
    --rx-gray-500: #7a8599;
    --rx-gray-700: #4a5568;
    --rx-bg: #fafbfc;
    --rx-white: #ffffff;
    --rx-mint: #8fe8c5;
    --rx-shadow: 0 16px 48px rgba(26, 43, 74, 0.16);
    --rx-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    --rx-serif: "Playfair Display", Georgia, "Times New Roman", serif;
}

/* One fixed anchor for both the launcher and the panel */
#teyaChat {
    position: fixed;
    right: 22px;
    bottom: 20px;
    z-index: 2147483647;
    font-family: var(--rx-sans);
}

#teyaChat *,
#teyaChat *::before,
#teyaChat *::after { box-sizing: border-box; }

/* -------------------- Launcher -------------------- */
.chat-toggle-btn {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--rx-teal) 0%, var(--rx-teal-dark) 100%);
    color: var(--rx-white);
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 26px rgba(10, 143, 117, 0.38);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
}

.chat-toggle-btn svg { width: 28px; height: 28px; display: block; }

.chat-toggle-btn::after {
    /* Soft idle pulse so the launcher reads as "live" */
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(10, 143, 117, 0.35);
    animation: rx-pulse 2.6s ease-out infinite;
    pointer-events: none;
}

@keyframes rx-pulse {
    0% { box-shadow: 0 0 0 0 rgba(10, 143, 117, 0.35); }
    70% { box-shadow: 0 0 0 14px rgba(10, 143, 117, 0); }
    100% { box-shadow: 0 0 0 0 rgba(10, 143, 117, 0); }
}

.chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 14px 32px rgba(10, 143, 117, 0.46);
}

.chat-toggle-btn:active { transform: scale(0.94); }

/* -------------------- Panel -------------------- */
#chatContainer {
    position: absolute;
    right: 0;
    bottom: 0;
    width: clamp(320px, 26vw, 384px);
    height: clamp(480px, 64vh, 600px);
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 48px);
    background: var(--rx-white);
    border-radius: 20px;
    border: 1px solid var(--rx-gray-200);
    box-shadow: var(--rx-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom right;
    pointer-events: none;
    visibility: hidden;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.28s ease, visibility 0.28s;
}

#chatContainer.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    visibility: visible;
}

#chatToggle.teya-hidden { display: none !important; }
.teya-hidden { display: none !important; }

/* -------------------- Header (brand) -------------------- */
.chat-header {
    background: linear-gradient(135deg, var(--rx-teal) 0%, var(--rx-teal-dark) 100%);
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.header-logo-img {
    height: 30px;
    width: auto;
    object-fit: contain;
    display: block;
    align-self: flex-start;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.88);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-dot {
    /* Halo drawn as a border (not an outset box-shadow) so the status line's
       overflow clipping can't cut it. */
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--rx-mint);
    background-clip: content-box;
    border: 3px solid rgba(143, 232, 197, 0.28);
    flex-shrink: 0;
}

.chat-close-btn {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: var(--rx-white);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.25s ease;
}

.chat-close-btn svg { width: 14px; height: 14px; display: block; }

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.26);
    transform: rotate(90deg);
}

/* -------------------- Views -------------------- */
.view-section {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.view-section.active-flex { display: flex; }

.center-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(18px, 3vh, 30px) 26px;
    text-align: center;
    background:
        radial-gradient(120% 70% at 100% 0%, rgba(230, 247, 244, 0.9) 0%, rgba(230, 247, 244, 0) 55%),
        var(--rx-bg);
    overflow-y: auto;
}

/* Greeting brand card: the TeyaRx logo on a soft white tile */
.brand-icon {
    width: 150px;
    padding: 18px 20px;
    border-radius: 20px;
    background: var(--rx-white);
    border: 1px solid var(--rx-gray-200);
    box-shadow: 0 8px 24px rgba(26, 43, 74, 0.10);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    animation: rx-float 3.2s ease-in-out infinite;
}

.brand-icon img {
    width: 100%;
    height: auto;
    display: block;
}

@keyframes rx-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-7px); }
}

.center-content h2 {
    margin: 0 0 8px;
    color: var(--rx-navy);
    font-family: var(--rx-serif);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.center-content p {
    color: var(--rx-gray-700);
    font-size: 14px;
    line-height: 1.65;
    margin: 0 0 24px;
    max-width: 262px;
}

/* -------------------- Forms -------------------- */
.form-group {
    width: 100%;
    margin-bottom: 13px;
    text-align: left;
}

.form-group label {
    font-size: 12px;
    font-weight: 700;
    color: var(--rx-navy);
    letter-spacing: .02em;
    margin-bottom: 6px;
    display: block;
}

.styled-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--rx-gray-200);
    border-radius: 12px;
    font-family: var(--rx-sans);
    font-size: 14px;
    color: var(--rx-navy);
    outline: none;
    background: var(--rx-white);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.styled-input::placeholder { color: var(--rx-gray-500); }

.styled-input:focus {
    border-color: var(--rx-teal);
    box-shadow: 0 0 0 3px rgba(10, 143, 117, 0.15);
}

/* Pill buttons, same language as the site's CTAs */
.chat-btn {
    width: 100%;
    padding: 13px 18px;
    border-radius: 100px;
    border: none;
    font-family: var(--rx-sans);
    font-weight: 600;
    font-size: 14px;
    letter-spacing: .01em;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.12s ease, box-shadow 0.2s ease;
}

.chat-btn:active { transform: scale(0.98); }

.chat-btn.primary {
    background: var(--rx-teal);
    color: var(--rx-white);
    box-shadow: 0 2px 12px rgba(10, 143, 117, 0.25);
    margin-bottom: 10px;
}

.chat-btn.primary:hover {
    background: var(--rx-teal-dark);
    transform: translateY(-1px);
}

.chat-btn.secondary {
    background: transparent;
    border: 2px solid var(--rx-gray-200);
    color: var(--rx-navy);
}

.chat-btn.secondary:hover {
    border-color: var(--rx-teal);
    color: var(--rx-teal);
}

/* -------------------- Messages -------------------- */
#chatMessages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 16px;
    background: var(--rx-bg);
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: rgba(10, 143, 117, 0.28) transparent;
}

#chatMessages::-webkit-scrollbar { width: 6px; }
#chatMessages::-webkit-scrollbar-thumb { background: rgba(10, 143, 117, 0.28); border-radius: 3px; }
#chatMessages::-webkit-scrollbar-track { background: transparent; }

.system-message {
    font-size: 11.5px;
    font-weight: 500;
    color: var(--rx-teal-dark);
    text-align: center;
    margin: 8px auto;
    background: var(--rx-teal-light);
    border: 1px solid rgba(10, 143, 117, 0.15);
    padding: 5px 14px;
    border-radius: 100px;
    max-width: 90%;
}

.chat-message {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
    margin-bottom: 10px;
}

.chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--rx-white);
    flex-shrink: 0;
}

/* Agent avatar: rounded teal tile with "Rx", echoing the site's logo icon */
.chat-avatar.brand-avatar {
    border-radius: 9px;
    background: linear-gradient(135deg, var(--rx-teal) 0%, var(--rx-teal-dark) 100%);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.assistant-message { justify-content: flex-start; }
.assistant-message .chat-avatar { order: 0; }

.user-message { justify-content: flex-end; }

.user-message .chat-avatar {
    order: 2;
    background: linear-gradient(135deg, var(--rx-navy) 0%, #2d4a7a 100%);
}

.message-group {
    display: flex;
    flex-direction: column;
    max-width: 76%;
    order: 1;
}

.assistant-message .message-group { align-items: flex-start; }
.user-message .message-group { align-items: flex-end; }

.message-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--rx-gray-500);
    margin: 0 4px 3px;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.assistant-message .message-bubble {
    background: var(--rx-white);
    color: var(--rx-navy);
    border: 1px solid var(--rx-gray-200);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(26, 43, 74, 0.06);
}

.user-message .message-bubble {
    background: var(--rx-teal);
    color: var(--rx-white);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(10, 143, 117, 0.25);
}

.msg-time {
    font-size: 10px;
    font-weight: 500;
    color: var(--rx-gray-500);
    margin: 3px 4px 0;
}

.edited-label {
    font-size: 10px;
    font-style: italic;
    opacity: 0.7;
    margin-left: 4px;
    color: inherit;
}

/* Typing indicator */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 13px 14px;
}

.dot {
    width: 6px;
    height: 6px;
    background: var(--rx-gray-500);
    border-radius: 50%;
    animation: rx-bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes rx-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* -------------------- Input area -------------------- */
.chat-input-area {
    padding: 12px 14px;
    background: var(--rx-white);
    border-top: 1px solid var(--rx-gray-200);
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}

#chatInput {
    flex: 1;
    margin: 0;
    border-radius: 100px;
    padding: 11px 18px;
    background: var(--rx-gray-100);
    border: 1px solid transparent;
}

#chatInput:focus {
    background: var(--rx-white);
    border-color: var(--rx-teal);
    box-shadow: 0 0 0 3px rgba(10, 143, 117, 0.12);
}

#sendChatBtn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--rx-teal);
    color: var(--rx-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 12px rgba(10, 143, 117, 0.25);
}

#sendChatBtn svg { width: 18px; height: 18px; display: block; }

#sendChatBtn:hover:not(:disabled) {
    transform: scale(1.06);
    background: var(--rx-teal-dark);
}

#sendChatBtn:disabled {
    background: var(--rx-gray-200);
    color: var(--rx-gray-500);
    box-shadow: none;
    cursor: not-allowed;
}

/* -------------------- Responsive & motion -------------------- */
@media (max-width: 480px) {
    #teyaChat { right: 12px; bottom: 14px; }

    #chatContainer {
        width: calc(100vw - 24px);
        height: min(76vh, 560px);
        border-radius: 16px;
    }

    .chat-toggle-btn { width: 56px; height: 56px; }
    .chat-toggle-btn svg { width: 25px; height: 25px; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-toggle-btn::after { animation: none; }
    .brand-icon { animation: none; }
    #chatContainer { transition: opacity 0.2s ease, visibility 0.2s; transform: none; }
}
