/* =============================================
   RayoChat Widget — iMessage-Inspired Design
   Premium chat UI with full color customization
   ============================================= */

:root {
    --rc-primary: #6C3CE1;
    --rc-secondary: #5A2DC5;
    --rc-user-bubble: #6C3CE1;
    --rc-user-text: #FFFFFF;
    --rc-bot-bubble: #F0F0F0;
    --rc-bot-text: #1A1A1A;
    --rc-bg: #FFFFFF;
    --rc-bg-secondary: #F8F9FA;
    --rc-border: #E8E8E8;
    --rc-text-light: #8E8E93;
    --rc-radius: 22px;
    --rc-font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ─── FAB (Floating Action Button) ────────── */

.rc-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--rc-primary) 0%, var(--rc-secondary) 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.1);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    animation: rc-fab-entrance 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    overflow: hidden;
}

.rc-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.2), 0 3px 10px rgba(0, 0, 0, 0.12);
}

.rc-fab:active {
    transform: scale(0.95);
}

.rc-fab-icon {
    width: 28px;
    height: 28px;
    transition: opacity 0.2s, transform 0.3s;
}

.rc-fab-icon--close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.rc-open .rc-fab .rc-fab-icon--chat,
.rc-open .rc-fab .rc-fab-img {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.rc-open .rc-fab .rc-fab-icon--close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

.rc-fab-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    transition: opacity 0.2s, transform 0.3s;
}

@keyframes rc-fab-entrance {
    from {
        opacity: 0;
        transform: scale(0) translateY(20px);
    }

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

/* Notification pulse */
.rc-fab::after {
    content: '';
    position: absolute;
    top: -3px;
    right: -3px;
    width: 14px;
    height: 14px;
    background: #34C759;
    border-radius: 50%;
    border: 2.5px solid #fff;
    animation: rc-pulse 2s infinite;
}

.rc-open .rc-fab::after {
    display: none;
}

@keyframes rc-pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.15);
        opacity: 0.8;
    }
}

/* ─── Chat Window ─────────────────────────── */

.rc-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 140px);
    background: var(--rc-bg);
    border-radius: var(--rc-radius);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 99998;
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.3s ease;
}

.rc-open .rc-window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ─── Header ──────────────────────────────── */

/* ─── Header ──────────────────────────────── */

.rc-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--rc-border);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-radius: var(--rc-radius) var(--rc-radius) 0 0;
}

.rc-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rc-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.rc-avatar svg {
    width: 20px;
    height: 20px;
    color: var(--rc-primary);
}

.rc-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rc-title {
    display: block;
    font-weight: 600;
    font-size: 16px;
    font-family: var(--rc-font);
    color: #1A1A1A;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.rc-subtitle {
    display: none;
    /* Removed for cleaner look */
}

.rc-header-actions {
    display: flex;
    gap: 2px;
}

.rc-header-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    color: #8E8E93;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.rc-header-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #1A1A1A;
}

/* ─── Messages ────────────────────────────── */

.rc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--rc-bg);
    scroll-behavior: smooth;
}

.rc-messages::-webkit-scrollbar {
    width: 4px;
}

.rc-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 4px;
}

.rc-msg {
    display: flex;
    flex-direction: column;
    max-width: 78%;
    animation: rc-msg-in 0.3s ease both;
}

.rc-msg--new {
    animation: rc-msg-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes rc-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }

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

/* User messages — right, like iMessage */
.rc-msg--user {
    align-self: flex-end;
}

.rc-msg--user .rc-bubble {
    background: var(--rc-user-bubble);
    color: var(--rc-user-text);
    border-radius: 20px 20px 6px 20px;
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.45;
    font-family: var(--rc-font);
    word-wrap: break-word;
    position: relative;
}

.rc-msg--user .rc-bubble code {
    background: rgba(255, 255, 255, 0.2);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* Bot messages — left, like iMessage */
.rc-msg--bot {
    align-self: flex-start;
}

.rc-msg--bot .rc-bubble {
    background: var(--rc-bot-bubble);
    color: var(--rc-bot-text);
    border-radius: 20px 20px 20px 6px;
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.45;
    font-family: var(--rc-font);
    word-wrap: break-word;
    position: relative;
}

.rc-msg--bot .rc-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* Message grouping — consecutive same sender */
.rc-msg--user+.rc-msg--user {
    margin-top: -2px;
}

.rc-msg--user+.rc-msg--user .rc-bubble {
    border-radius: 20px 6px 6px 20px;
}

.rc-msg--bot+.rc-msg--bot {
    margin-top: -2px;
}

.rc-msg--bot+.rc-msg--bot .rc-bubble {
    border-radius: 6px 20px 20px 6px;
}

/* Message formatting */
.rc-bubble strong {
    font-weight: 600;
}

.rc-bubble em {
    font-style: italic;
}

.rc-bubble ul,
.rc-bubble ol {
    margin: 4px 0;
    padding-left: 18px;
}

.rc-bubble li {
    margin-bottom: 2px;
}

/* Timestamp */
.rc-msg-time {
    font-size: 11px;
    color: var(--rc-text-light);
    margin-top: 3px;
    padding: 0 4px;
    font-family: var(--rc-font);
}

.rc-msg--user .rc-msg-time {
    text-align: right;
}

/* ─── Typing Indicator ────────────────────── */

.rc-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    min-width: 52px;
}

.rc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--rc-text-light);
    animation: rc-bounce 1.4s infinite both;
}

.rc-dot:nth-child(2) {
    animation-delay: 0.16s;
}

.rc-dot:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes rc-bounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

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

/* ─── Input Area ──────────────────────────── */

.rc-input-area {
    padding: 10px 14px;
    background: var(--rc-bg);
    border-top: 1px solid var(--rc-border);
    flex-shrink: 0;
}

.rc-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--rc-bg-secondary);
    border: 1px solid var(--rc-border);
    border-radius: 22px;
    padding: 6px 6px 6px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.rc-input-wrapper:focus-within {
    border-color: var(--rc-primary);
    box-shadow: 0 0 0 3px rgba(108, 60, 225, 0.1);
}

.rc-input-wrapper textarea {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    outline: none;
    font-size: 15px;
    line-height: 1.4;
    max-height: 120px;
    padding: 6px 0;
    font-family: var(--rc-font);
    color: #1A1A1A;
}

.rc-input-wrapper textarea::placeholder {
    color: var(--rc-text-light);
}

.rc-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--rc-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s;
}

.rc-send-btn:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
}

.rc-send-btn:not(:disabled):hover {
    transform: scale(1.08);
}

.rc-send-btn:not(:disabled):active {
    transform: scale(0.92);
}

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

/* ─── Footer ──────────────────────────────── */

.rc-powered-by {
    text-align: center;
    font-size: 10px;
    color: var(--rc-text-light);
    margin-top: 6px;
    opacity: 0.6;
    font-family: var(--rc-font);
}

.rc-powered-by a {
    color: var(--rc-text-light);
    text-decoration: none;
    transition: color 0.2s;
}

.rc-powered-by a:hover {
    color: var(--rc-primary);
    text-decoration: underline;
}

.rc-powered-by--hidden {
    display: none;
}

/* ─── Responsive ──────────────────────────── */

@media (max-width: 480px) {
    .rc-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 90px);
        max-height: none;
        bottom: 78px;
        right: 8px;
        border-radius: 18px;
    }

    .rc-fab {
        bottom: 16px;
        right: 16px;
        width: 54px;
        height: 54px;
    }
}

/* ─── Reduced Motion ──────────────────────── */

@media (prefers-reduced-motion: reduce) {

    .rc-fab,
    .rc-window,
    .rc-msg,
    .rc-msg--new,
    .rc-dot {
        animation: none !important;
        transition: opacity 0.15s !important;
    }
}