/* ===========================================================
   1. GLOBAL VARIABLES & RESET (App-like Palette)
   =========================================================== */
:root {
    /* Gradients */
    --wc-grad-main: linear-gradient(135deg, #FF0055 0%, #0088FF 100%);
    --wc-grad-hover: linear-gradient(135deg, #FF0055 20%, #0088FF 120%);
    
    /* Solid Colors */
    --wc-primary: #FF0055;
    --wc-secondary: #0088FF;
    --wc-success: #00cc66;
    --wc-warning: #ffa502;
    --wc-danger: #ff4757;
    
    /* Neutrals */
    --wc-dark: #2d3436;
    --wc-light: #f1f2f6;
    --wc-white: #ffffff;
    --wc-border: #e0e0e0;
    --wc-shadow: 0 5px 20px rgba(0,0,0,0.08);
}

/* Global Box Sizing for Plugin Elements */
.wc389-modal-overlay *, 
.wc389-admin-wrapper *,
#wc389-agent-dashboard *,
.wc389-user-search-wrapper * {
    box-sizing: border-box;
}

/* Custom Scrollbar (Pro Look) */
.wc389-body::-webkit-scrollbar,
.wc389-chat-content::-webkit-scrollbar,
.wc389-chat-list::-webkit-scrollbar,
.wc389-admin-modal-body::-webkit-scrollbar,
.wc389-scroll-table::-webkit-scrollbar,
.wc389-search-results::-webkit-scrollbar {
    width: 6px;
}
.wc389-body::-webkit-scrollbar-track,
.wc389-chat-content::-webkit-scrollbar-track,
.wc389-admin-modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
}
.wc389-body::-webkit-scrollbar-thumb,
.wc389-chat-content::-webkit-scrollbar-thumb,
.wc389-admin-modal-body::-webkit-scrollbar-thumb,
.wc389-search-results::-webkit-scrollbar-thumb {
    background: #ccc; 
    border-radius: 10px;
}
.wc389-body::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}


/* ===========================================================
   2. CUSTOM AGENT LOGIN PAGE
   (Replaces WP Login Style)
   =========================================================== */
.wc389-login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 600px;
    background: #f0f2f5;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

.wc389-login-card {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 380px;
    text-align: center;
    border-top: 5px solid var(--wc-primary);
    position: relative;
    overflow: hidden;
}

.wc389-login-icon {
    width: 70px;
    height: 70px;
    background: var(--wc-grad-main);
    color: white;
    font-size: 28px;
    border-radius: 50%;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.wc389-login-card h2 {
    margin: 0 0 25px 0;
    color: #333;
    font-size: 26px;
    font-weight: 700;
}

.wc389-login-card input {
    width: 100%;
    padding: 14px 15px;
    margin-bottom: 15px;
    border: 1px solid #e1e1e1;
    border-radius: 10px;
    outline: none;
    background: #fafafa;
    transition: 0.3s;
    font-size: 15px;
}

.wc389-login-card input:focus {
    border-color: var(--wc-secondary);
    background: white;
    box-shadow: 0 0 0 3px rgba(0,136,255,0.1);
}

#wc389-login-btn {
    width: 100%;
    padding: 14px;
    background: var(--wc-grad-main);
    color: white;
    border: none;
    border-radius: 30px;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    transition: 0.3s;
    box-shadow: 0 5px 15px rgba(255, 0, 85, 0.2);
}

#wc389-login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(255, 0, 85, 0.3);
}

#wc389-login-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Error Shake Animation */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25%, 75% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
}
.shake { animation: shake 0.4s; }


/* ===========================================================
   3. FRONTEND CHAT WIDGET & BOX
   (Fixed Height & Scrolling)
   =========================================================== */
#wc389-floating-icon {
    position: fixed;
    width: 60px;
    height: 60px;
    background: var(--wc-grad-main);
    color: white;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    cursor: pointer;
    z-index: 999999;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#wc389-floating-icon:hover { transform: scale(1.1); }
.wc389-pos-bottom-right { bottom: 30px; right: 30px; }
.wc389-pos-bottom-left { bottom: 30px; left: 30px; }

/* Main Chat Modal Wrapper */
.wc389-modal-overlay {
    position: fixed;
    bottom: 100px;
    right: 30px;
    z-index: 999998;
    width: 360px;
    max-width: 90vw; /* Responsive Safety */
}

/* Chat Box Container - Fixed Height */
.wc389-chat-box {
    width: 100%;
    height: 550px !important; /* STRICT FIXED HEIGHT */
    max-height: 80vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column; /* Flex layout */
    overflow: hidden;
    font-family: 'Segoe UI', sans-serif;
    border: 1px solid rgba(0,0,0,0.05);
    animation: wcSlideUp 0.3s ease-out;
}

@keyframes wcSlideUp { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }

/* Header */
.wc389-header {
    flex: 0 0 60px; /* Fixed height */
    background: var(--wc-grad-main);
    color: white;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
}
.wc389-close-chat { cursor: pointer; font-size: 20px; opacity: 0.8; transition: 0.3s; }
.wc389-close-chat:hover { opacity: 1; transform: rotate(90deg); }

/* Body - The Scrolling Part */
.wc389-body {
    flex: 1 1 auto; /* Grow to fill space */
    min-height: 0;  /* CRITICAL FIX for flex scrolling */
    padding: 15px;
    overflow-y: auto; /* Enable Scrollbar */
    overflow-x: hidden;
    background: #fff;
    background-image: radial-gradient(#f0f0f0 1px, transparent 1px);
    background-size: 20px 20px;
    scroll-behavior: smooth;
}

.wc389-messages-area {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding-bottom: 10px;
}

/* Footer Input Area */
.wc389-footer {
    flex: 0 0 auto;
    padding: 12px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    background: white;
}

#wc389-msg-input {
    flex: 1;
    border: none;
    background: #f4f6f9;
    padding: 12px 15px;
    border-radius: 25px;
    outline: none;
    margin: 0 8px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    height: 45px;
    line-height: 1.4;
    overflow: hidden;
}

.wc389-icon-btn { color: #999; cursor: pointer; font-size: 18px; padding: 5px; transition: color 0.3s; }
.wc389-icon-btn:hover { color: var(--wc-primary); }
#wc389-send-btn { border:none; background:none; color:var(--wc-secondary); font-size: 22px; cursor:pointer; margin-left:5px; }

/* Start Screen Center Content */
.wc389-start-screen { text-align: center; margin-top: 40%; }
.wc389-start-screen h3 { color: var(--wc-primary); margin-bottom: 5px; }
.wc389-start-screen select { width: 85%; padding: 12px; border-radius: 25px; border: 1px solid #ddd; outline: none; background: white; cursor: pointer; }


/* ===========================================================
   4. CHAT BUBBLES & TEXT BREAKING
   (Ensures text stays inside bubbles)
   =========================================================== */
.wc389-msg {
    max-width: 75%;
    padding: 10px 15px;
    margin-bottom: 8px;
    border-radius: 15px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    
    /* CRITICAL: Text Breaking Rules */
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: pre-wrap; /* Keeps lines breaks visible */
}

/* User/Self Message (Right Side, Blue) */
.wc389-msg-user, .wc389-msg-self {
    background: var(--wc-secondary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

/* Agent/Other Message (Left Side, Gray) */
.wc389-msg-agent, .wc389-msg-other {
    background: #f1f2f6;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    border: 1px solid #e5e5e5;
}


/* ===========================================================
   5. AGENT DASHBOARD (STRICT SCROLLING FIX)
   =========================================================== */
#wc389-agent-dashboard {
    display: flex;
    /* STRICT HEIGHT: 80% of viewport height */
    height: 80vh !important; 
    min-height: 600px;
    max-height: 900px;
    width: 100%;
    background: #fff;
    border: 1px solid #ddd;
    box-shadow: 0 0 20px rgba(0,0,0,0.05);
    font-family: 'Segoe UI', sans-serif;
    /* CRITICAL: Prevents the dashboard itself from growing */
    overflow: hidden; 
    border-radius: 8px;
    margin: 20px 0;
}

/* Left Sidebar */
.wc389-sidebar {
    width: 320px;
    background: #f8f9fa;
    border-right: 1px solid #e5e5e5;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.wc389-sidebar-header {
    flex: 0 0 65px;
    padding: 0 20px;
    background: #fff;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.agent-profile { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.avatar { width: 35px; height: 35px; background: var(--wc-secondary); color: white; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-weight: bold; }
.status-online { color: var(--wc-success); font-size: 11px; font-weight: bold; }

.wc389-chat-list {
    flex: 1 1 auto;
    min-height: 0; /* Fixes scrolling inside sidebar */
    overflow-y: auto;
}

.wc389-list-item {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: 0.2s;
    background: #fff;
}
.wc389-list-item:hover { background: #fafafa; }
.wc389-list-item.active { background: #e6f7ff; border-left: 4px solid var(--wc-secondary); }
.wc389-list-item.new-req { background: #fff0f5; border-left: 4px solid var(--wc-primary); }

/* Right Main Chat Area */
.wc389-main-chat {
    flex: 1; /* Take remaining width */
    display: flex;
    flex-direction: column;
    background: #fff;
    min-width: 0;
    height: 100%; /* Fill the container */
    overflow: hidden; /* Prevent spillover */
}

.wc389-chat-header-bar {
    flex: 0 0 65px;
    padding: 0 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
}

/* Chat Messages Content (THE SCROLLABLE AREA) */
.wc389-chat-content {
    flex: 1 1 0%; /* Flex-basis 0 helps force constraint */
    min-height: 0; /* CRITICAL: Forces scrollbar inside this div instead of expanding parent */
    padding: 20px;
    overflow-y: auto; /* Enable vertical scroll */
    background: #f0f2f5;
    background-image: radial-gradient(#ddd 1px, transparent 1px);
    background-size: 20px 20px;
    display: flex;
    flex-direction: column;
}

.wc389-chat-input-bar {
    flex: 0 0 auto; /* Don't grow */
    padding: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
}

#wc389-agent-msg {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
    font-family: inherit;
    resize: none;
    height: 50px;
    line-height: 1.4;
    overflow: hidden;
}

.wc389-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    margin: auto; 
}


/* ===========================================================
   6. ADMIN PANEL & UTILS
   =========================================================== */
.wc389-admin-wrapper { font-family: sans-serif; }
.wc389-admin-wrapper h1 { font-size: 28px; font-weight: 800; margin-bottom: 20px; }

.wc-card {
    background: white;
    padding: 25px;
    flex: 1;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border-radius: 8px;
    text-align: center;
    border: 1px solid #eee;
}
.wc-card h2 { margin: 0; font-size: 36px; color: #333; }
.wc-card p { margin: 5px 0 0; color: #888; font-size: 12px; text-transform: uppercase; font-weight: bold; }

/* Custom Alert Modal */
.wc389-alert-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); z-index: 1000000;
    display: flex; justify-content: center; align-items: center;
}
.wc389-alert-box {
    background: white; padding: 30px; border-radius: 15px;
    text-align: center; width: 300px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    border-top: 5px solid var(--wc-primary);
    animation: wcPop 0.3s;
}
@keyframes wcPop { from{transform:scale(0.8);opacity:0} to{transform:scale(1);opacity:1} }

/* Buttons */
.wc389-btn-primary {
    background: var(--wc-grad-main); color: white; border: none; padding: 10px 25px;
    border-radius: 25px; font-weight: 600; cursor: pointer; transition: 0.2s;
}
.wc389-btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.wc389-btn-secondary { background: white; color: #333; border: 1px solid #ddd; padding: 6px 12px; border-radius: 5px; cursor: pointer; }

.wc389-btn-sm { padding: 6px 15px; font-size: 12px; border: none; border-radius: 4px; cursor: pointer; color: white; font-weight: 600; }
.wc389-btn-sm.danger { background: var(--wc-danger); }
.wc389-btn-sm.warning { background: var(--wc-warning); color: #333; }

/* Smart Confirm Button */
.confirm-state {
    background: var(--wc-warning) !important;
    color: #333 !important;
    animation: shake 0.3s;
}

/* ===========================================================
   7. ADMIN MODAL STYLES (REQUIRED FOR HISTORY VIEW)
   =========================================================== */
#wc389-admin-view-modal {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(0,0,0,0.6); 
    z-index: 99999;
    display: flex; 
    justify-content: center; 
    align-items: center;
}

.wc389-admin-modal-content {
    background: white; 
    width: 600px; 
    max-width: 95%;
    height: 500px; 
    max-height: 90%;
    display: flex; 
    flex-direction: column;
    border-radius: 10px; 
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    animation: wcPop 0.2s ease-out;
}

.wc389-admin-modal-header {
    background: #f9f9f9; 
    padding: 15px 20px;
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    border-bottom: 1px solid #eee; 
    flex: 0 0 auto;
}

.wc389-admin-modal-header h3 { margin: 0; font-size: 18px; }

.wc389-admin-modal-body {
    flex: 1; 
    min-height: 0; 
    padding: 15px; 
    overflow-y: auto; 
    background: #fff;
}

.wc389-admin-close {
    font-size: 24px;
    cursor: pointer;
    color: #888;
    line-height: 1;
}
.wc389-admin-close:hover { color: #333; }


/* ===========================================================
   8. SEARCHABLE DROPDOWN STYLES (NEW)
   =========================================================== */
.wc389-user-search-wrapper {
    position: relative;
    width: 100%;
}

.wc389-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 9999;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    display: none; /* Hidden by default */
}

.wc389-search-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: 0.2s;
    font-size: 13px;
    color: #333;
}

.wc389-search-item:hover {
    background: #f0f7ff;
    color: #0088FF;
}

.wc389-search-item strong {
    display: block;
    margin-bottom: 2px;
}

.wc389-search-item small {
    color: #888;
}


/* ===========================================================
   9. MOBILE RESPONSIVE
   =========================================================== */
@media (max-width: 768px) {
    /* Center the Frontend Widget Modal */
    .wc389-modal-overlay {
        width: 92%; 
        left: 50%; right: auto; 
        transform: translateX(-50%);
        bottom: 90px; 
        height: auto; max-height: 80vh; 
        margin: 0;
    }
    
    /* Agent Dashboard Mobile Stack */
    #wc389-agent-dashboard {
        flex-direction: column;
        height: 85vh !important; /* Keep fixed height for internal scroll */
        max-height: none;
        overflow: visible; /* Allow modals to pop out if needed */
    }
    
    .wc389-sidebar {
        width: 100%;
        height: 250px; /* Fixed height for queue list on mobile */
        flex: 0 0 250px;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }
    
    .wc389-main-chat {
        flex: 1; /* Take remaining space */
        height: auto;
    }
}