@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
    --rca-navy: #171da2;
    --rca-navy-soft: #2a32c4;
    --rca-cyan: #00aef0;
    --rca-cyan-soft: #ddeffd;
    --rca-text: #1b1f3b;
    --rca-muted: #6b7285;
    --rca-line: #e3e8f2;
    --rca-bg: #eef3f9;
    --rca-surface: #ffffff;
    --rca-ok: #61ce70;
    --rca-warn: #d97706;
    --rca-danger: #dc2626;
    --rca-font: 'Poppins', sans-serif;
    --rca-radius: 18px;
    --rca-header-h: 64px;
    --rca-footer-h: 78px;
}

.rca-chat-shell {
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    padding: 0;
    box-sizing: border-box;
}

.rca-chat-shell *,
.rca-chat-shell *::before,
.rca-chat-shell *::after {
    box-sizing: border-box;
}

.rca-chat-container {
    display: flex;
    flex-direction: column;
    height: min(72vh, 680px);
    min-height: 480px;
    max-height: min(72vh, 680px);
    background: var(--rca-surface);
    border: 1px solid var(--rca-line);
    border-radius: 20px;
    overflow: hidden;
    font-family: var(--rca-font);
    color: var(--rca-text);
    box-shadow: 0 10px 40px rgba(23, 29, 162, 0.08);
}

/* Header — light messenger bar with logo */
.rca-chat-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: var(--rca-header-h);
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid var(--rca-line);
}

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

.rca-brand-logo {
    height: 34px;
    width: auto;
    max-width: 118px;
    object-fit: contain;
    display: block;
    flex-shrink: 0;
}

.rca-brand-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rca-chat-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--rca-navy);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rca-online-dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--rca-muted);
}

.rca-online-dot::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--rca-ok);
    box-shadow: 0 0 0 3px rgba(97, 206, 112, 0.25);
}

.rca-online-dot.typing::before {
    background: var(--rca-cyan);
    animation: rcaPulse 1.2s infinite;
}

.rca-online-dot.error::before {
    background: var(--rca-danger);
    box-shadow: none;
}

.rca-clear-history-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--rca-line);
    background: var(--rca-bg);
    color: var(--rca-muted);
    border-radius: 50%;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.rca-clear-history-btn:hover {
    color: var(--rca-navy);
    border-color: var(--rca-cyan);
    background: var(--rca-cyan-soft);
    box-shadow: 0 0 0 3px rgba(0, 174, 240, 0.12);
}

.rca-clear-history-btn:active {
    transform: scale(0.96);
}

.rca-clear-history-icon {
    display: block;
    pointer-events: none;
}

.rca-preview-loading {
    padding: 24px;
    text-align: center;
    color: var(--rca-muted);
    font-size: 0.85rem;
}

@keyframes rcaPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Messages */
.rca-chat-messages {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 14px 8px;
    background: var(--rca-bg);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.rca-chat-messages::-webkit-scrollbar { width: 6px; }
.rca-chat-messages::-webkit-scrollbar-thumb {
    background: #c5cedd;
    border-radius: 6px;
}

.rca-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 12px;
    width: 100%;
    max-width: 100%;
    animation: rcaIn 0.25s ease both;
}

@keyframes rcaIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

.rca-bot-message { justify-content: flex-start; }
.rca-user-message {
    justify-content: flex-end;
}

.rca-user-message .rca-bubble,
.rca-user-message .rca-message-content {
    margin-left: auto;
}

.rca-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #0a0a0a;
    border: 1px solid var(--rca-line);
}

.rca-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.rca-user-message .rca-message-avatar {
    display: none; /* messenger: no avatar on user side */
}

.rca-bubble {
    max-width: min(78%, 520px);
    padding: 10px 14px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.rca-bot-message .rca-bubble {
    background: #fff;
    border: 1px solid var(--rca-line);
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(23, 29, 162, 0.04);
}

.rca-user-message .rca-bubble {
    background: linear-gradient(160deg, var(--rca-navy) 0%, #232ac0 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
}

/* legacy class used by JS */
.rca-message-content {
    max-width: min(78%, 520px);
    padding: 10px 14px;
    border-radius: 18px;
    background: #fff;
    border: 1px solid var(--rca-line);
    border-bottom-left-radius: 6px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.rca-user-message .rca-message-content {
    background: linear-gradient(160deg, var(--rca-navy) 0%, #232ac0 100%);
    color: #fff;
    border-color: transparent;
    border-bottom-right-radius: 6px;
}

.rca-message-text,
.rca-message-content p,
.rca-bubble p {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.45;
    white-space: pre-wrap;
}

.rca-message-time {
    display: none; /* cleaner messenger look */
}

/* Sources */
.rca-message-sources {
    margin-top: 10px;
}

.rca-sources-chip,
.rca-sources-header {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--rca-cyan-soft);
    color: var(--rca-navy);
    font-size: 0.75rem;
    font-weight: 500;
    border: 0;
}

.rca-sources-header {
    width: 100%;
    border-radius: 12px;
    cursor: pointer;
    justify-content: flex-start;
}

.rca-sources-icon {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    display: inline-grid;
    place-items: center;
    background: rgba(23, 29, 162, 0.1);
    font-size: 0.68rem;
    font-weight: 700;
}

.rca-sources-text { flex: 1; }
.rca-sources-toggle { opacity: 0.6; font-size: 0.65rem; }

.rca-sources-files {
    display: none;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.rca-sources-files.show { display: flex; }

.rca-file-card {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    gap: 10px;
    align-items: center;
    width: 100%;
    padding: 10px;
    border-radius: 14px;
    border: 1px solid var(--rca-line);
    background: #f8fbff;
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
    transition: border-color 0.15s ease, transform 0.15s ease;
}

.rca-file-card:hover {
    border-color: var(--rca-cyan);
    transform: translateY(-1px);
}

.rca-file-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--rca-navy);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
}

.rca-file-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--rca-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rca-file-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 2px;
}

.rca-file-meta span {
    font-size: 0.68rem;
    color: var(--rca-muted);
    background: #eef2f8;
    padding: 1px 6px;
    border-radius: 999px;
}

.rca-file-open {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--rca-cyan);
    white-space: nowrap;
}

/* Composer */
.rca-chat-input-container {
    flex: 0 0 auto;
    padding: 10px 12px 12px;
    background: #fff;
    border-top: 1px solid var(--rca-line);
}

.rca-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 14px;
    background: var(--rca-bg);
    border: 1px solid var(--rca-line);
    border-radius: 24px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.rca-input-wrapper:focus-within {
    border-color: var(--rca-cyan);
    box-shadow: 0 0 0 3px rgba(0, 174, 240, 0.15);
    background: #fff;
}

.rca-message-input {
    flex: 1;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    font: inherit;
    font-size: 0.92rem;
    line-height: 1.4;
    max-height: 120px;
    min-height: 24px;
    padding: 8px 0;
    color: var(--rca-text);
}

.rca-message-input::placeholder { color: #9aa3b5; }

.rca-send-button {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    border: 0 !important;
    border-radius: 50% !important;
    background: var(--rca-navy) !important;
    background-color: var(--rca-navy) !important;
    color: #fff !important;
    display: grid !important;
    place-items: center !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    transition: transform 0.15s ease, background 0.15s ease;
}

.rca-send-button:hover {
    background: var(--rca-navy-soft) !important;
    background-color: var(--rca-navy-soft) !important;
    transform: scale(1.04);
}

.rca-send-button:disabled {
    background: #c5cad8 !important;
    background-color: #c5cad8 !important;
    cursor: not-allowed !important;
    transform: none !important;
}

.rca-file-card {
    width: 100% !important;
    background: #f8fbff !important;
    color: var(--rca-text) !important;
    border-radius: 14px !important;
    display: grid !important;
    justify-content: initial !important;
    text-align: left !important;
}

.rca-btn-ghost {
    background: var(--rca-bg) !important;
    color: var(--rca-text) !important;
    width: auto !important;
}

.rca-btn-solid {
    background: var(--rca-navy) !important;
    color: #fff !important;
    width: auto !important;
}

.rca-input-footer {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 6px;
    padding: 0 6px;
    font-size: 0.7rem;
    color: var(--rca-muted);
}

.rca-char-limit-warning,
.rca-limit-warning { color: var(--rca-warn) !important; font-weight: 600; }
.rca-limit-exceeded { color: var(--rca-danger) !important; font-weight: 600; }

/* Typing */
.rca-typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid var(--rca-line);
    border-radius: 18px;
    border-bottom-left-radius: 6px;
}

.rca-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9aa3b5;
    animation: rcaTyping 1.2s infinite ease-in-out;
}
.rca-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.rca-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes rcaTyping {
    0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* Modal */
.rca-source-modal[hidden] { display: none !important; }
.rca-source-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: grid;
    place-items: center;
    padding: 12px;
}
.rca-source-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 18, 40, 0.5);
}
.rca-source-modal-dialog {
    position: relative;
    width: min(900px, 100%);
    max-height: min(90vh, 820px);
    overflow: auto;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
    font-family: var(--rca-font);
}
.rca-source-modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: var(--rca-bg);
    font-size: 1.35rem;
    cursor: pointer;
    color: var(--rca-text);
}
.rca-source-modal-header {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 18px 48px 14px 18px;
    border-bottom: 1px solid var(--rca-line);
}
.rca-source-modal-badge {
    min-width: 48px;
    height: 48px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--rca-navy);
    color: #fff;
    font-weight: 700;
    font-size: 0.75rem;
}
.rca-source-modal-header h4 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--rca-navy);
}
.rca-source-modal-meta {
    margin: 3px 0 0;
    font-size: 0.78rem;
    color: var(--rca-muted);
}
.rca-source-modal-body { padding: 14px 18px; }
.rca-source-snippets { display: grid; gap: 10px; }
.rca-snippet-card {
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--rca-cyan-soft);
    border-left: 3px solid var(--rca-cyan);
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--rca-text);
}
.rca-snippet-label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--rca-navy);
}
.rca-source-viewer {
    margin-top: 12px;
    border: 1px solid var(--rca-line);
    border-radius: 12px;
    overflow: hidden;
    min-height: 280px;
    background: #111;
}
.rca-source-viewer iframe {
    width: 100%;
    height: min(50vh, 480px);
    border: 0;
    background: #fff;
}
.rca-source-viewer pre {
    margin: 0;
    padding: 14px;
    color: #e8eef8;
    white-space: pre-wrap;
    font-size: 0.82rem;
    max-height: 45vh;
    overflow: auto;
}
.rca-source-empty {
    padding: 14px;
    border-radius: 12px;
    background: var(--rca-bg);
    color: var(--rca-muted);
    font-size: 0.88rem;
}
.rca-source-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 18px 16px;
    border-top: 1px solid var(--rca-line);
}
.rca-btn-ghost,
.rca-btn-solid {
    border: 0;
    border-radius: 999px;
    padding: 9px 14px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.rca-btn-ghost { background: var(--rca-bg); color: var(--rca-text); }
.rca-btn-solid { background: var(--rca-navy); color: #fff; }
.rca-btn-solid[hidden] { display: none !important; }
.rca-btn-danger {
    border: 0;
    border-radius: 999px;
    padding: 9px 14px;
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--rca-navy);
    color: #fff;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}
.rca-btn-danger:hover {
    background: #12189a;
    box-shadow: 0 0 0 3px rgba(0, 174, 240, 0.15);
}
.rca-btn-danger:disabled {
    opacity: 0.65;
    cursor: wait;
}

/* Confirm modal */
.rca-confirm-modal[hidden] { display: none !important; }
.rca-confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 100010;
    display: grid;
    place-items: center;
    padding: 16px;
}
.rca-confirm-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 18, 40, 0.48);
}
.rca-confirm-modal-dialog {
    position: relative;
    width: min(380px, 100%);
    padding: 24px 22px 18px;
    background: #fff;
    border-radius: 18px;
    border: 1px solid var(--rca-line);
    box-shadow: 0 20px 48px rgba(23, 29, 162, 0.18);
    font-family: var(--rca-font);
    text-align: center;
}
.rca-confirm-modal-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 14px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--rca-cyan-soft);
    color: var(--rca-navy);
    border: 1px solid rgba(0, 174, 240, 0.25);
}
.rca-confirm-modal-dialog h4 {
    margin: 0 0 8px;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--rca-navy);
}
.rca-confirm-modal-text {
    margin: 0 0 18px;
    font-size: 0.88rem;
    line-height: 1.45;
    color: var(--rca-muted);
}
.rca-confirm-modal-actions {
    display: flex !important;
    flex-direction: row !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 10px !important;
    flex-wrap: wrap !important;
    position: relative !important;
    width: 100% !important;
}

.rca-confirm-modal-actions > button,
.rca-confirm-modal .rca-btn-ghost,
.rca-confirm-modal .rca-btn-danger {
    position: static !important;
    float: none !important;
    inset: auto !important;
    left: auto !important;
    right: auto !important;
    top: auto !important;
    bottom: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    min-width: 110px !important;
    max-width: none !important;
    height: auto !important;
    margin: 0 !important;
    padding: 10px 16px !important;
    border-radius: 999px !important;
    border: 0 !important;
    font-family: var(--rca-font) !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    text-align: center !important;
    text-transform: none !important;
    letter-spacing: normal !important;
    box-shadow: none !important;
    transform: none !important;
    cursor: pointer !important;
}

.rca-confirm-modal .rca-btn-ghost {
    background: var(--rca-bg) !important;
    background-color: var(--rca-bg) !important;
    color: var(--rca-text) !important;
    border: 1px solid var(--rca-line) !important;
}

.rca-confirm-modal .rca-btn-danger {
    background: var(--rca-navy) !important;
    background-color: var(--rca-navy) !important;
    color: #fff !important;
}

.rca-confirm-modal .rca-btn-danger:hover {
    background: var(--rca-navy-soft) !important;
    background-color: var(--rca-navy-soft) !important;
}

.rca-confirm-modal .rca-btn-danger:disabled {
    opacity: 0.65 !important;
    cursor: wait !important;
}

/* ---------- Responsive / messenger feel ---------- */
@media (max-width: 900px) {
    .rca-chat-shell {
        max-width: 100%;
    }
    .rca-chat-container {
        height: min(75vh, 640px);
        border-radius: 16px;
    }
}

@media (max-width: 768px) {
    .rca-chat-shell {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: var(--rca-mobile-top, 72px);
        padding: 0;
        max-width: 100%;
        z-index: 999;
        height: auto;
    }

    .rca-chat-container {
        height: 100%;
        min-height: 0;
        max-height: none;
        border-radius: 0;
        border-left: 0;
        border-right: 0;
        box-shadow: none;
    }

    .rca-chat-header {
        padding: 10px 12px;
        min-height: 56px;
    }

    .rca-brand-logo {
        height: 28px;
        max-width: 96px;
    }

    .rca-chat-header h3 {
        font-size: 0.88rem;
    }

    .rca-chat-messages {
        padding: 12px 10px;
    }

    .rca-bubble,
    .rca-message-content {
        max-width: 86%;
        padding: 9px 12px;
    }

    .rca-message-text,
    .rca-message-content p,
    .rca-bubble p {
        font-size: 0.9rem;
    }

    .rca-file-card {
        grid-template-columns: 32px 1fr;
    }

    .rca-file-open {
        grid-column: 2;
        justify-self: start;
    }

    .rca-chat-input-container {
        padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    }

    .rca-send-button {
        width: 38px;
        height: 38px;
    }

    .rca-source-modal {
        padding: 0;
        align-items: end;
    }

    .rca-source-modal-dialog {
        width: 100%;
        max-height: 92dvh;
        border-radius: 16px 16px 0 0;
    }
}

@media (max-width: 420px) {
    .rca-brand-copy h3 {
        max-width: 140px;
    }

    .rca-bubble,
    .rca-message-content {
        max-width: 90%;
    }
}

/* Prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .rca-message,
    .rca-typing-dot,
    .rca-online-dot.typing::before {
        animation: none !important;
    }
}
