/*
 * MRP Live Chat CSS - Version 1.12
 * Changes from 1.11:
 * - Mobile panel lowered further (bottom: 60px) for better balance
 * - Hide floating toggle icon when chat is open → allows panel to sit lower cleanly
 * - Increased bottom padding on mobile messages/input for keyboard clearance
 * - Kept perfect centering and taller message area
 */
#mrp-chat-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 10000;
    pointer-events: none;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#mrp-chat-container .mrp-chat-toggle,
#mrp-chat-container .mrp-chat-panel {
    pointer-events: auto;
}

/* Hide toggle when chat is open (cleaner bottom on mobile) */
#mrp-chat-container.mrp-chat-open .mrp-chat-toggle {
    display: none !important;
}

/* Toggle Button (visible only when closed) */
.mrp-chat-toggle {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #0cbdd6, #1ad60c);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 0 25px rgba(12, 189, 214, 0.7), 0 10px 30px rgba(0,0,0,0.6);
    transition: all 0.3s ease;
    border: 4px solid #000;
    animation: pulse 4s infinite alternate;
    position: relative;
}

.mrp-chat-toggle:hover,
.mrp-chat-toggle:active {
    transform: scale(1.15) translateY(-6px);
    box-shadow: 0 0 40px rgba(12, 189, 214, 0.9), 0 15px 40px rgba(0,0,0,0.8);
}

.mrp-chat-toggle svg {
    color: white;
    width: 40px;
    height: 40px;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
}

/* Toggle Unread Badge */
.mrp-chat-unread-count {
    position: absolute;
    top: -6px;
    right: -2px;
    background: #ff2e2e;
    color: white;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #000;
    box-shadow: 0 0 8px rgba(255,46,46,0.8);
    padding: 0 4px;
    animation: bounce 1.8s infinite;
}

.mrp-chat-unread-count:empty {
    display: none !important;
}

/* Animations */
@keyframes pulse {
    0% { box-shadow: 0 0 25px rgba(12,189,214,0.6), 0 10px 30px rgba(0,0,0,0.5); }
    100% { box-shadow: 0 0 40px rgba(12,189,214,0.9), 0 10px 30px rgba(0,0,0,0.6); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-9px); }
}

/* New Message Flash */
@keyframes flash-glow-private {
    0%, 100% { box-shadow: 0 0 25px rgba(12,189,214,0.6), 0 10px 30px rgba(0,0,0,0.5); }
    50% { box-shadow: 0 0 60px #ff2e2e, 0 15px 45px rgba(255,46,46,0.7); }
}

@keyframes flash-glow-public {
    0%, 100% { box-shadow: 0 0 25px rgba(12,189,214,0.6), 0 10px 30px rgba(0,0,0,0.5); }
    50% { box-shadow: 0 0 60px #0cbdd6, 0 15px 45px rgba(12,189,214,0.7); }
}

.mrp-chat-toggle.new-message-flash-private {
    animation: flash-glow-private 1.8s ease-out 2;
}

.mrp-chat-toggle.new-message-flash-public {
    animation: flash-glow-public 1.8s ease-out 2;
}

/* Panel */
.mrp-chat-panel {
    position: fixed;
    bottom: 110px;
    right: 30px;
    width: 480px;
    height: 620px;
    background: linear-gradient(to bottom, #0d0d0d, #111);
    border: 4px solid var(--chat-accent, #ff4444);
    border-radius: 24px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.95), 0 0 40px rgba(12, 189, 214, 0.4);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(40px) scale(0.94);
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
    backdrop-filter: blur(12px);
    z-index: 10000;
    overscroll-behavior: contain;
    touch-action: manipulation;
}

#mrp-chat-container.mrp-chat-open .mrp-chat-panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Mobile Panel - Centered, Lowered, Better Balance */
@media (max-width: 768px) {
    #mrp-chat-container {
        bottom: 20px;
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
    }

    .mrp-chat-toggle {
        width: 60px;
        height: 60px;
        border: 3px solid #000;
    }

    .mrp-chat-toggle svg {
        width: 34px;
        height: 34px;
    }

    .mrp-chat-panel {
        position: fixed !important;
        bottom: 10px !important;          /* Lowered as requested - adjust to 40px or 80px if needed */
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        width: calc(100vw - 32px) !important;
        max-width: 420px !important;
        height: 62vh !important;
        max-height: 88vh !important;
        border-radius: 16px 16px 0 0 !important;
        padding-bottom: 140px !important; /* More room for keyboard + input */
        overflow-y: auto !important;
    }

    .mrp-chat-header {
        padding: 16px 20px !important;
        min-height: 60px !important;
    }

    .mrp-chat-controls {
        gap: 16px !important;
    }

    .mrp-chat-controls select,
    .mrp-chat-controls button {
        font-size: 15px !important;
        padding: 8px 12px !important;
        min-height: 44px !important;
    }

    .mrp-chat-messages {
        padding: 80px 16px 180px !important; /* Extra bottom for input/keyboard */
    }

    #mrp-chat-form {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        padding: 12px 16px !important;
        background: #1a1a1a !important;
        border-top: 2px solid #333 !important;
        z-index: 10001 !important;
        box-shadow: 0 -4px 12px rgba(0,0,0,0.5);
        margin: 0 !important;
    }

    .mrp-chat-input-wrapper {
        gap: 12px !important;
    }

    .mrp-chat-form button[type="submit"] {
        min-width: 80px !important;
        font-size: 16px !important;
        padding: 12px 20px !important;
    }
}

/* Header */
.mrp-chat-header {
    background: var(--chat-gradient, linear-gradient(to right, #0cbdd6, #1ad60c));
    color: white;
    padding: 12px 16px;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid #000;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
    cursor: move;
    user-select: none;
    flex-wrap: wrap;
    gap: 8px;
}

.mrp-chat-header h3 {
    margin: 0;
    font-size: 18px;
    flex: 1;
}

.mrp-chat-close-btn {
    background: rgba(0,0,0,0.4);
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.mrp-chat-close-btn:hover {
    background: rgba(255,255,255,0.3);
    transform: rotate(90deg);
}

/* Tabs */
.mrp-chat-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-right: 10px;
}

.mrp-tab-btn,
#mrp-new-message-btn {
    background: rgba(0,0,0,0.55);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 15px;
    font-weight: bold;
    transition: all 0.25s ease;
}

.mrp-tab-btn.active,
#mrp-new-message-btn:hover {
    background: white;
    color: var(--chat-accent, #0cbdd6);
    box-shadow: 0 2px 12px rgba(12, 189, 214, 0.5);
}

/* Private Tab Badge */
.mrp-tab-btn[data-mode="private"] .tab-unread {
    margin-left: 10px;
    background: #ff0000;
    color: white;
    font-size: 13px;
    font-weight: 900;
    min-width: 22px;
    height: 22px;
    line-height: 22px;
    padding: 0 7px;
    border-radius: 50%;
    box-shadow: 0 0 8px #ff0000, 0 0 14px #ff3333;
    border: 3px solid #ffffff;
    text-shadow: 0 0 4px rgba(0,0,0,0.9);
    animation: private-tab-pulse 1.8s infinite alternate;
}

@keyframes private-tab-pulse {
    0% { transform: scale(1); box-shadow: 0 0 8px #ff0000, 0 0 14px #ff3333; }
    100% { transform: scale(1.10); box-shadow: 0 0 12px #ff0000, 0 0 20px #ff6666; }
}

.mrp-tab-btn[data-mode="private"] .tab-unread:empty {
    display: none;
}

.mrp-tab-btn[data-mode="private"].active {
    background: white;
    color: #ff0000;
    box-shadow: 0 4px 16px rgba(255, 0, 0, 0.45);
}

.mrp-back-btn {
    background: rgba(0,0,0,0.5);
    color: white;
    border: none;
    padding: 7px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
}

/* Content Wrapper */
.mrp-chat-content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
}

/* Conversation List */
#mrp-conversations-list {
    background: #111;
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: none;
}

.mrp-tab-btn[data-mode="private"].active ~ .mrp-chat-content-wrapper #mrp-conversations-list {
    display: block;
}

#mrp-chat-messages:has(.mrp-chat-message) ~ #mrp-conversations-list {
    display: none;
}

/* Conversation Item */
.mrp-conversation-item {
    display: flex;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 12px;
    background: #1e1e1e;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    border: 1px solid #333;
}

.mrp-conversation-item:hover {
    background: #2a2a2a;
    transform: translateX(4px);
}

.mrp-conversation-item img {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    margin-right: 12px;
    border: 3px solid #444;
    object-fit: cover;
    box-shadow: 0 0 10px rgba(0,0,0,0.6);
}

.mrp-conv-info {
    flex: 1;
    min-width: 0;
}

.mrp-conv-info strong {
    display: block;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
}

.mrp-conv-preview {
    display: block;
    font-size: 13px;
    color: #aaa;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Unread Styles */
.mrp-conversation-item.has-unread {
    background: rgba(255, 46, 46, 0.22);
    border: 2px solid #ff2e2e;
    border-left: 8px solid #ff2e2e;
    box-shadow: 0 0 20px rgba(255,46,46,0.6), inset 0 0 15px rgba(255,46,46,0.3);
    animation: unread-glow-pulse 2.2s infinite alternate ease-in-out;
}

.mrp-conversation-item.has-unread .mrp-conv-info strong {
    color: #ff3333;
    font-weight: 900;
    text-shadow: 0 0 12px #ff0000, 0 0 6px #ff4444;
    letter-spacing: 0.5px;
}

.mrp-conversation-item.has-unread .unread-badge {
    min-width: 24px;
    height: 24px;
    font-size: 12px;
    line-height: 24px;
    background: #ff0000;
    color: white;
    border: 2px solid white;
    box-shadow: 0 0 10px #ff0000;
    animation: badge-bounce 1.4s infinite ease-in-out;
}

@keyframes unread-glow-pulse {
    0% { box-shadow: 0 0 20px rgba(255,46,46,0.6), inset 0 0 15px rgba(255,46,46,0.3); transform: scale(1); }
    100% { box-shadow: 0 0 35px rgba(255,46,46,0.9), inset 0 0 25px rgba(255,46,46,0.5); transform: scale(1.015); }
}

@keyframes badge-bounce {
    0%, 100% { transform: scale(1) translateY(0); }
    50% { transform: scale(1.15) translateY(-2px); }
}

.mrp-conversation-item .unread-badge {
    position: absolute;
    right: 50px;
    top: 50%;
    transform: translateY(-50%);
    background: #ff2e2e;
    color: white;
    min-width: 24px;
    height: 24px;
    line-height: 24px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    padding: 0 6px;
    box-shadow: 0 2px 8px rgba(255,46,46,0.7);
    border: 2px solid #000;
}

/* Delete Button */
.mrp-delete-conv-btn {
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    background: rgba(220, 38, 38, 0.85);
    color: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 16px;
    line-height: 32px;
    cursor: pointer;
    opacity: 0.8;
    transition: all 0.2s ease;
    z-index: 10;
}

.mrp-delete-conv-btn:hover {
    opacity: 1;
    background: #dc2626;
    transform: translateY(-50%) scale(1.15);
    box-shadow: 0 4px 12px rgba(220,38,38,0.6);
}

/* Messages Area */
.mrp-chat-messages {
    flex: 1;
    padding: 16px 14px;
    overflow-y: auto;
    background: #0f0f0f;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.mrp-chat-welcome {
    color: #888;
    font-style: italic;
    text-align: center;
    margin: 40px 0;
    font-size: 16px;
}

/* No Convo Placeholder */
#mrp-no-convo-placeholder {
    display: none;
    background: rgba(0,0,0,0.4);
    border-radius: 12px;
    margin: 40px 20px;
    padding: 50px 25px;
    border: 1px dashed #555;
    text-align: center;
    color: #aaa;
}

#mrp-no-convo-placeholder strong {
    color: #ff4444;
    font-size: 24px;
    display: block;
    margin-bottom: 20px;
}

/* Message Bubbles */
.mrp-chat-message {
    display: flex;
    gap: 12px;
    animation: fadeInUp 0.4s ease;
}

.mrp-own-message {
    flex-direction: row-reverse;
}

.mrp-message-avatar img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 3px solid var(--chat-accent, #0cbdd6);
    object-fit: cover;
    box-shadow: 0 0 12px rgba(12, 189, 214, 0.4);
}

.mrp-message-content {
    flex: 1;
    max-width: 75%;
}

.mrp-message-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.mrp-message-header strong {
    color: var(--chat-accent, #0cbdd6);
    font-size: 15px;
}

.mrp-message-time {
    color: #666;
    font-size: 12px;
}

.mrp-message-text {
    background: #1e1e1e;
    padding: 12px 16px;
    border-radius: 20px;
    line-height: 1.4;
    word-wrap: break-word;
    border: 1px solid #333;
    font-size: 15px;
}

.mrp-own-message .mrp-message-text {
    background: var(--chat-gradient, linear-gradient(135deg, #0cbdd6, #1ad60c));
    color: white;
}

/* Message Actions */
.mrp-message-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.mrp-action-btn {
    background: rgba(0,0,0,0.6);
    border: 1px solid var(--chat-accent, #0cbdd6);
    color: var(--chat-accent, #0cbdd6);
    font-size: 12px;
    padding: 5px 9px;
    border-radius: 10px;
    cursor: pointer;
}

.mrp-action-btn:hover {
    background: var(--chat-accent, #0cbdd6);
    color: white;
}

/* Input Form */
.mrp-chat-form {
    padding: 16px;
    background: #1a1a1a;
    border-top: 3px solid var(--chat-accent, #0cbdd6);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mrp-chat-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mrp-chat-form input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid #444;
    border-radius: 30px;
    background: #222;
    color: white;
    font-size: 15px;
    outline: none;
}

.mrp-chat-form input:focus {
    border-color: var(--chat-accent, #0cbdd6);
    box-shadow: 0 0 15px rgba(12, 189, 214, 0.4);
}

.mrp-chat-form button[type="submit"] {
    padding: 14px 20px;
    background: var(--chat-gradient, linear-gradient(to right, #0cbdd6, #1ad60c));
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
}

/* Themes */
.mrp-chat-theme-neon { --chat-accent: #ff4444; --chat-gradient: linear-gradient(to right, #ff4444, #ff00aa); }
.mrp-chat-theme-cyber { --chat-accent: #00ffff; --chat-gradient: linear-gradient(to right, #00ffff, #0088ff); }
.mrp-chat-theme-purple { --chat-accent: #aa00ff; --chat-gradient: linear-gradient(to right, #aa00ff, #ff00ff); }
.mrp-chat-theme-green { --chat-accent: #00ff88; --chat-gradient: linear-gradient(to right, #00ff88, #00cc66); }
.mrp-chat-theme-orange { --chat-accent: #ff8800; --chat-gradient: linear-gradient(to right, #ff8800, #ff4400); }
.mrp-chat-theme-matrix { --chat-accent: #00ff41; --chat-gradient: linear-gradient(to right, #00ff41, #003300); }
.mrp-chat-theme-sunset { --chat-accent: #ff6b35; --chat-gradient: linear-gradient(to right, #f7931e, #ff4e50); }
.mrp-chat-theme-galaxy { --chat-accent: #9d4edd; --chat-gradient: linear-gradient(to right, #5e35b1, #9d4edd); }
.mrp-chat-theme-ocean { --chat-accent: #00d2ff; --chat-gradient: linear-gradient(to right, #00d2ff, #3a7bd5); }
.mrp-chat-theme-retro { --chat-accent: #ff0090; --chat-gradient: linear-gradient(to right, #ff0090, #ff8a00); }
.mrp-chat-theme-blood { --chat-accent: #ff0000; --chat-gradient: linear-gradient(to right, #ff0000, #880000); }
.mrp-chat-theme-gold { --chat-accent: #ffd700; --chat-gradient: linear-gradient(to right, #ffd700, #b8860b); }
.mrp-chat-theme-ice { --chat-accent: #00ffff; --chat-gradient: linear-gradient(to right, #88ffff, #00cccc); }

/* Theme Application */
.mrp-chat-panel[class*="mrp-chat-theme-"] {
    border-color: var(--chat-accent) !important;
}

.mrp-chat-header[class*="mrp-chat-theme-"] {
    background: var(--chat-gradient) !important;
}

.mrp-tab-btn.active[class*="mrp-chat-theme-"] {
    color: var(--chat-accent) !important;
}

.mrp-message-header strong[class*="mrp-chat-theme-"] {
    color: var(--chat-accent) !important;
}

.mrp-message-avatar img[class*="mrp-chat-theme-"] {
    border-color: var(--chat-accent) !important;
}

.mrp-chat-form button[type="submit"][class*="mrp-chat-theme-"] {
    background: var(--chat-gradient) !important;
}

.mrp-message-text[class*="mrp-chat-theme-"] {
    border-color: var(--chat-accent) !important;
}

/* Private User Dropdown */
.mrp-private-user-dropdown {
    appearance: none;
    background: #1a1a1a url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12"><polygon points="0,0 12,0 6,12" fill="%23aaa"/></svg>') no-repeat right 14px center;
    background-size: 12px;
    padding: 12px 40px 12px 16px;
    margin: 12px 12px 8px;
    width: calc(100% - 24px);
    border: 2px solid #444;
    border-radius: 10px;
    font-size: 15px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.mrp-private-user-dropdown:hover,
.mrp-private-user-dropdown:focus {
    border-color: var(--chat-accent, #0cbdd6);
    box-shadow: 0 0 12px rgba(12, 189, 214, 0.5);
}

/* Template-specific classes */
.mrp-conversations-list {
    height: calc(100% - 120px);
    overflow-y: auto;
    padding: 10px;
}

.mrp-user-select {
    padding: 10px;
}

.mrp-no-convo-placeholder {
    text-align: center;
    padding: 60px 20px;
    color: #888;
    font-size: 17px;
    line-height: 1.5;
    background: rgba(0,0,0,0.3);
    border-radius: 12px;
    margin: 20px;
    border: 1px dashed #555;
}

.mrp-no-convo-placeholder strong {
    color: #ff4444;
    font-size: 22px;
    display: block;
    margin-bottom: 15px;
}

.mrp-no-convo-hint {
    margin-top: 25px;
    font-size: 15px;
    color: #666;
}

.mrp-loading-message {
    display: none;
}

.mrp-settings-section {
    margin-top: 15px;
    padding: 0 15px;
}

.mrp-guest-login {
    font-size: 12px;
    margin-top: 10px;
    color: #888;
}