/* CSS Variables */
:root {
    --rg-primary: #1e3a5f;
    --rg-primary-dark: #152a45;
    --rg-light: #f5f7fa;
    --rg-border: #e1e5eb;
    --rg-text: #333;
    --rg-text-light: #666;
}

/* Widget Container */
.rg-chat-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    z-index: 999999;
}

.rg-chat-widget * {
    box-sizing: border-box;
}

/* Floating Positions - Bottom */
.rg-chat-bottom-right {
    position: fixed;
    bottom: 20px;
    right: 20px;
}

.rg-chat-bottom-left {
    position: fixed;
    bottom: 20px;
    left: 20px;
}

/* Floating Positions - Top */
.rg-chat-top-right {
    position: fixed;
    top: 20px;
    right: 20px;
}

.rg-chat-top-left {
    position: fixed;
    top: 20px;
    left: 20px;
}

/* Embedded */
.rg-chat-embedded {
    position: relative;
    width: 100%;
    max-width: 450px;
    margin: 0 auto;
}

.rg-chat-embedded .rg-chat-window {
    position: relative;
    display: flex !important;
    height: 500px;
}

/* Toggle Button */
.rg-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--rg-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s, background 0.2s;
    position: absolute;
}

/* Button positions - Bottom */
.rg-chat-bottom-right .rg-chat-toggle {
    bottom: 0;
    right: 0;
}

.rg-chat-bottom-left .rg-chat-toggle {
    bottom: 0;
    left: 0;
}

/* Button positions - Top */
.rg-chat-top-right .rg-chat-toggle {
    top: 0;
    right: 0;
}

.rg-chat-top-left .rg-chat-toggle {
    top: 0;
    left: 0;
}

.rg-chat-toggle:hover {
    background: var(--rg-primary-dark);
    transform: scale(1.05);
}

/* Chat Window */
.rg-chat-window {
    width: 380px;
    height: 520px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: absolute;
}

/* Window positions - Bottom */
.rg-chat-bottom-right .rg-chat-window {
    bottom: 75px;
    right: 0;
}

.rg-chat-bottom-left .rg-chat-window {
    bottom: 75px;
    left: 0;
}

/* Window positions - Top */
.rg-chat-top-right .rg-chat-window {
    top: 75px;
    right: 0;
}

.rg-chat-top-left .rg-chat-window {
    top: 75px;
    left: 0;
}

@media (max-width: 420px) {
    .rg-chat-bottom-right,
    .rg-chat-bottom-left,
    .rg-chat-top-right,
    .rg-chat-top-left {
        bottom: auto;
        top: auto;
        right: auto;
        left: auto;
    }
    
    .rg-chat-window {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        position: fixed;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
    }
    
    .rg-chat-toggle {
        position: fixed !important;
    }
    
    .rg-chat-bottom-right .rg-chat-toggle,
    .rg-chat-bottom-left .rg-chat-toggle {
        bottom: 20px !important;
        top: auto !important;
    }
    
    .rg-chat-top-right .rg-chat-toggle,
    .rg-chat-top-left .rg-chat-toggle {
        top: 20px !important;
        bottom: auto !important;
    }
    
    .rg-chat-bottom-right .rg-chat-toggle,
    .rg-chat-top-right .rg-chat-toggle {
        right: 20px !important;
        left: auto !important;
    }
    
    .rg-chat-bottom-left .rg-chat-toggle,
    .rg-chat-top-left .rg-chat-toggle {
        left: 20px !important;
        right: auto !important;
    }
}

/* Header */
.rg-chat-header {
    background: var(--rg-primary);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.rg-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.rg-chat-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rg-chat-title {
    font-weight: 600;
    font-size: 15px;
}

.rg-chat-status {
    font-size: 12px;
    opacity: 0.9;
}

.rg-chat-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.rg-chat-close:hover {
    opacity: 1;
}

/* Messages Container */
.rg-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--rg-light);
}

/* Message Bubbles */
.rg-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
}

.rg-message a {
    color: inherit;
    text-decoration: underline;
}

.rg-message-user {
    background: var(--rg-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.rg-message-assistant {
    background: white;
    color: var(--rg-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Typing Indicator */
.rg-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.rg-typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.rg-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.rg-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Input Area */
.rg-chat-input-container {
    padding: 12px;
    background: white;
    border-top: 1px solid var(--rg-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.rg-chat-input {
    flex: 1;
    border: 1px solid var(--rg-border);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
}

.rg-chat-input:focus {
    outline: none;
    border-color: var(--rg-primary);
}

.rg-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--rg-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
    transition: background 0.2s;
}

.rg-chat-send:hover {
    background: var(--rg-primary-dark);
}

.rg-chat-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Footer */
.rg-chat-footer {
    padding: 10px 16px;
    background: #f8f9fa;
    border-top: 1px solid var(--rg-border);
    text-align: center;
    font-size: 12px;
    color: var(--rg-text-light);
    flex-shrink: 0;
}

.rg-chat-footer a {
    color: var(--rg-primary);
    text-decoration: none;
    font-weight: 500;
}

.rg-chat-footer a:hover {
    text-decoration: underline;
}