/* WhatsApp Multi-Agent - Modern Optimized UI (Redesigned) */
:root {
    --wa-primary: #00a884; /* WhatsApp Web Green */
    --wa-primary-dark: #008f6f;
    --wa-header-bg: #008069;
    --wa-bg-light: #efeae2; /* WhatsApp Chat BG */
    --wa-bg-gray: #f0f2f5;
    --wa-white: #ffffff;
    --wa-text-main: #111b21;
    --wa-text-sub: #54656f;
    --wa-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --wa-radius: 12px;
    --wa-font: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --wa-z-index: 999999;
}

/* Widget Container */
.wa-ma-widget {
    font-family: var(--wa-font);
    z-index: var(--wa-z-index);
    position: fixed;
    bottom: 20px;
    right: 20px;
    line-height: 1.4;
}

/* Reset Box Sizing */
.wa-ma-widget * {
    box-sizing: border-box;
}

/* Floating Button */
.wa-ma-button {
    width: var(--wa-size, 50px);
    height: var(--wa-size, 50px);
    border-radius: 50%;
    background-color: var(--wa-color, var(--wa-primary));
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    cursor: pointer;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: fixed;
    z-index: var(--wa-z-index);
}

.wa-ma-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 14px rgba(0,0,0,0.3);
}

.wa-ma-button svg {
    width: 50%;
    height: 50%;
    fill: white;
}

/* Pulse Animation */
.wa-ma-button-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--wa-color, var(--wa-primary));
    opacity: 0;
    animation: waPulse 2s infinite;
    z-index: -1;
}

@keyframes waPulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Button Positioning */
.wa-ma-widget[data-position="bottom-right"] .wa-ma-button { bottom: var(--wa-offset-y, 20px); right: var(--wa-offset-x, 20px); }
.wa-ma-widget[data-position="bottom-left"] .wa-ma-button { bottom: var(--wa-offset-y, 20px); left: var(--wa-offset-x, 20px); }
.wa-ma-widget[data-position="top-right"] .wa-ma-button { top: var(--wa-offset-y, 20px); right: var(--wa-offset-x, 20px); bottom: auto; }
.wa-ma-widget[data-position="top-left"] .wa-ma-button { top: var(--wa-offset-y, 20px); left: var(--wa-offset-x, 20px); bottom: auto; }

/* Popup Container */
.wa-ma-popup {
    position: fixed;
    bottom: calc(var(--wa-size, 50px) + var(--wa-offset-y, 20px) + 15px);
    right: var(--wa-offset-x, 20px);
    width: 320px; /* Reduced width */
    max-width: calc(100vw - 40px);
    height: auto;
    max-height: 480px; /* Reduced height */
    background: var(--wa-bg-light);
    border-radius: var(--wa-radius);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: calc(var(--wa-z-index) - 1);
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png'); /* WhatsApp Doodle BG */
    background-blend-mode: overlay;
}

.wa-ma-popup.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    display: flex !important;
}

/* Position overrides for popup based on button position */
.wa-ma-widget[data-position="bottom-left"] .wa-ma-popup { right: auto !important; left: var(--wa-offset-x, 20px) !important; }
.wa-ma-widget[data-position="top-right"] .wa-ma-popup { top: calc(var(--wa-size, 50px) + var(--wa-offset-y, 20px) + 15px) !important; bottom: auto !important; }
.wa-ma-widget[data-position="top-left"] .wa-ma-popup { top: calc(var(--wa-size, 50px) + var(--wa-offset-y, 20px) + 15px) !important; bottom: auto !important; left: var(--wa-offset-x, 20px) !important; right: auto !important; }

/* Header */
.wa-ma-popup-header {
    background-color: var(--wa-header-bg);
    color: white;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    min-height: 60px;
}

.wa-ma-back-btn {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: -4px;
}

.wa-ma-back-btn svg {
    width: 20px;
    height: 20px;
}

.wa-ma-popup-header-content {
    flex: 1;
    min-width: 0; /* Text truncation fix */
}

.wa-ma-popup-header-content h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-ma-popup-header-content p {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-ma-agent-status-header {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    opacity: 0.9;
    margin-top: 2px;
}

.wa-status-dot {
    width: 8px;
    height: 8px;
    background-color: #25D366; /* Online green */
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.5);
}

.wa-ma-popup-close {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    padding: 6px;
    opacity: 0.8;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

/* Header Agent Info */
.wa-ma-header-agent-info {
    display: flex;
    align-items: center;
    flex: 1;
    overflow: hidden;
}

.wa-ma-header-avatar {
    width: 36px;
    height: 36px;
    margin-right: 10px;
    border-radius: 50%;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.3);
    flex-shrink: 0;
}

.wa-ma-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wa-ma-header-text {
    overflow: hidden;
}

.wa-ma-header-text h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-ma-header-text p {
    margin: 2px 0 0;
    font-size: 11px;
    opacity: 0.9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Inner Content Area */
.wa-ma-popup-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Agents List */
.wa-ma-agents-container {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.wa-ma-agents-container::-webkit-scrollbar {
    width: 4px;
}
.wa-ma-agents-container::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 4px;
}

.wa-ma-agent-item {
    display: flex;
    align-items: center;
    background: white;
    padding: 10px; /* Compact padding */
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
    border: 1px solid rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
}

.wa-ma-agent-item:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transform: translateY(-1px);
}

.wa-ma-agent-item.active {
    border-left: 4px solid var(--wa-primary);
    padding-left: 6px; /* Adjust for border */
}

/* Agent Avatar */
.wa-ma-agent-avatar {
    position: relative;
    width: 40px; /* Smaller avatar */
    height: 40px;
    margin-right: 10px;
    flex-shrink: 0;
}

.wa-ma-agent-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid rgba(0,0,0,0.1);
}

.wa-ma-agent-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
}

.wa-status-online { background-color: #25D366; }
.wa-status-offline { background-color: #ccc; }
.wa-status-away { background-color: #f1c40f; }

/* Agent Details */
.wa-ma-agent-details {
    flex: 1;
    min-width: 0; /* Text truncation fix */
}

.wa-ma-agent-name {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--wa-text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-ma-agent-position {
    margin: 0;
    font-size: 11px;
    color: var(--wa-text-sub);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-ma-agent-info-row {
    display: flex;
    align-items: center;
    margin-top: 2px;
    gap: 8px;
}

.wa-ma-status-badge {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 4px;
    background: #f0f2f5;
    color: var(--wa-text-sub);
    font-weight: 500;
}

.wa-ma-response-time {
    font-size: 10px;
    color: var(--wa-text-sub);
    display: flex;
    align-items: center;
    gap: 3px;
}

.wa-ma-response-time svg {
    width: 10px;
    height: 10px;
}

.wa-ma-agent-select {
    color: var(--wa-text-sub);
    opacity: 0.5;
    margin-left: 8px;
}

/* Chat Interface */
.wa-ma-chat-interface {
    display: none; /* Hidden by default */
    flex-direction: column;
    height: 100%;
    background-color: #efeae2;
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-blend-mode: overlay;
}

.wa-ma-chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wa-ma-message {
    display: flex;
    align-items: flex-end;
    margin-bottom: 10px;
    max-width: 85%;
}

.wa-ma-message-agent {
    align-self: flex-start;
}

.wa-ma-message-avatar {
    width: 28px;
    height: 28px;
    margin-right: 8px;
    flex-shrink: 0;
}

.wa-ma-message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
}

.wa-ma-message-bubble {
    background: white;
    padding: 8px 12px;
    border-radius: 0 12px 12px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
    font-size: 13px;
    color: var(--wa-text-main);
    line-height: 1.4;
}

.wa-ma-message-agent .wa-ma-message-bubble {
    border-radius: 0 12px 12px 12px;
}

.wa-ma-message-author {
    font-size: 10px;
    color: var(--wa-primary-dark);
    font-weight: 600;
    margin-bottom: 2px;
}

/* Typing Indicator */
.wa-ma-typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 4px 0;
}

.wa-ma-typing-indicator span {
    width: 5px;
    height: 5px;
    background: #999;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.wa-ma-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.wa-ma-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Quick Templates */
.wa-ma-quick-templates {
    padding: 8px 12px 0;
    display: flex;
    overflow-x: auto;
    gap: 6px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.wa-ma-quick-templates::-webkit-scrollbar {
    display: none;
}

.wa-template-btn {
    background: rgba(255,255,255,0.8);
    border: 1px solid #ddd;
    border-radius: 16px;
    padding: 5px 10px;
    font-size: 11px;
    color: var(--wa-text-main);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.wa-template-btn:hover {
    background: white;
    border-color: var(--wa-primary);
    color: var(--wa-primary-dark);
}

/* Input Area */
.wa-ma-chat-input {
    padding: 8px;
    background: #f0f2f5;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.wa-ma-input {
    flex: 1;
    background: white;
    border: none;
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none; /* Hide resize handle */
    font-family: inherit;
    max-height: 120px; /* Limit height */
    min-height: 40px;
    outline: none;
    overflow-y: auto; /* Scroll when content exceeds max-height */
    line-height: 1.4;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.wa-ma-input::-webkit-scrollbar {
    width: 4px;
}
.wa-ma-input::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 4px;
}

.wa-ma-input:focus {
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
}

.wa-ma-send-btn {
    background: var(--wa-primary);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s;
    flex-shrink: 0;
}

.wa-ma-send-btn:hover {
    background: var(--wa-primary-dark);
}

.wa-ma-send-btn:active {
    transform: scale(0.95);
}

.wa-ma-send-btn svg {
    width: 18px;
    height: 18px;
    margin-left: 2px; /* Visual balance */
    fill: currentColor;
    stroke: none;
}

/* Thank You & Return Screens */
.wa-ma-thank-you, .wa-ma-return-notice {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 30px 20px;
    background: white;
}

/* Return User UI */
.wa-ma-return-icon {
    width: 70px;
    height: 70px;
    color: var(--wa-primary);
    margin-bottom: 20px;
}

.wa-ma-return-icon svg {
    width: 100%;
    height: 100%;
    stroke-width: 1.5;
}

.wa-ma-return-title {
    margin: 0 0 10px;
    font-size: 20px;
    font-weight: 600;
    color: var(--wa-text-main);
}

.wa-ma-return-text {
    margin: 0 0 25px;
    font-size: 14px;
    color: var(--wa-text-sub);
    line-height: 1.5;
    max-width: 260px;
}

.wa-ma-return-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 260px;
}

.wa-ma-btn-yes, .wa-ma-btn-no {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.wa-ma-btn-yes {
    background: var(--wa-primary);
    color: white;
}

.wa-ma-btn-yes:hover {
    background: var(--wa-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.2);
}

.wa-ma-btn-no {
    background: #f0f2f5;
    color: var(--wa-text-main);
}

.wa-ma-btn-no:hover {
    background: #e4e6eb;
    transform: translateY(-1px);
}

.wa-ma-btn-yes svg, .wa-ma-btn-no svg {
    width: 18px;
    height: 18px;
}

/* Thank You UI */
.wa-ma-thank-you-icon {
    width: 60px;
    height: 60px;
    background: #d9fdd3;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--wa-primary);
    margin-bottom: 15px;
}

.wa-ma-thank-you h3 { margin: 0 0 8px; font-size: 16px; }
.wa-ma-thank-you p { margin: 0 0 15px; font-size: 13px; color: var(--wa-text-sub); }

.wa-ma-countdown {
    font-size: 11px;
    color: #888;
}

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .wa-ma-popup {
        width: calc(100vw - 40px) !important;
        right: 20px !important;
        left: 20px !important;
        bottom: 90px !important;
        max-height: 70vh;
    }
    
    .wa-ma-button {
        width: 50px !important; /* Force manageable size on mobile */
        height: 50px !important;
    }
}
