/* ==========================================================================
   GLOBAL VARIABLES & RESET
   ========================================================================== */
:root {
    --bg-main: #f8fafc;
    --surface-white: #FFFFFF;
    --primary-pink: #FF1493;
    --text-dark: #1e293b;
    --text-gray: #64748b;
    --border-light: #e2e8f0;
    --agent-red: #dc2626;
    --agent-red-dark: #991b1b;
    --agent-red-light: #fecaca;
    --agent-red-bg: #fff1f2;
}


* {
    box-sizing: border-box;
}

body { 
    margin: 0; 
    padding: 0; 
    background-color: var(--bg-main); 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    display: flex; 
    height: 100vh; 
    color: var(--text-dark); 
    overflow: hidden;
}

.dashboard-container { 
    display: flex; 
    width: 100%; 
    height: 100%;
}

/* ==========================================================================
   ENTERPRISE SIDEBAR
   ========================================================================== */
.sidebar { 
    width: 250px;
    min-width: 250px;
    max-width: 250px;
    flex: 0 0 250px; /* Prevents the sidebar from ever shrinking or expanding */
    background: var(--surface-white); 
    padding: 20px 0; 
    border-right: 1px solid var(--border-light); 
    display: flex; 
    flex-direction: column; 
}
.sidebar-brand { 
    padding: 0 20px 30px 20px; 
    font-size: 20px; 
    font-weight: bold; 
    color: var(--text-dark); 
}
.sidebar-brand span { 
    color: var(--primary-pink); 
}
.sidebar-heading {
    margin-bottom: 10px; 
    padding-left: 20px; 
    font-size: 11px; 
    color: #94a3b8; 
    font-weight: bold; 
    text-transform: uppercase;
}
.nav-item { 
    padding: 12px 20px; 
    color: var(--text-gray); 
    text-decoration: none; 
    font-size: 15px; 
    font-weight: 500; 
    display: block; 
    border-left: 3px solid transparent; 
}
.nav-item:hover { 
    background-color: var(--bg-main); 
    color: var(--text-dark); 
}
.nav-item.active { 
    background-color: #fff0f6; 
    color: var(--primary-pink); 
    border-left: 3px solid var(--primary-pink); 
}

/* ==========================================================================
   MAIN CONTENT WRAPPER & HEADERS
   ========================================================================== */
.main-content { 
    flex: 1; 
    min-width: 0; /* Prevents wide grids/tables from pushing against the sidebar */
    padding: 30px 40px; 
    overflow-y: auto; 
}
.page-header { 
    margin-bottom: 25px; 
}
.page-title { 
    font-size: 24px; 
    font-weight: bold; 
    margin: 0 0 5px 0; 
}
.page-subtitle { 
    color: var(--text-gray); 
    font-size: 14px; 
    margin: 0; 
}

/* ==========================================================================
   LEADS PAGE: DATA GRID & TOOLBAR
   ========================================================================== */
.toolbar { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.search-box { flex: 1; padding: 10px 15px; border: 1px solid var(--border-light); border-radius: 6px; min-width: 250px; font-size: 14px; outline: none; }
.search-box:focus { border-color: var(--primary-pink); }
.filter-select { padding: 10px 15px; border: 1px solid var(--border-light); border-radius: 6px; background: white; font-size: 14px; color: var(--text-dark); cursor: pointer; }
.btn-outline { padding: 10px 15px; border: 1px solid var(--border-light); border-radius: 6px; background: white; font-size: 14px; font-weight: 500; cursor: pointer; color: var(--text-dark); display: flex; align-items: center; gap: 6px; }
.btn-outline:hover { background: var(--bg-main); }

.table-wrapper { background: var(--surface-white); border: 1px solid var(--border-light); border-radius: 8px; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,0.02); }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { background-color: var(--bg-main); padding: 12px 20px; font-size: 12px; font-weight: 600; color: var(--text-gray); text-transform: uppercase; border-bottom: 1px solid var(--border-light); }
td { padding: 16px 20px; border-bottom: 1px solid var(--border-light); font-size: 14px; vertical-align: top; }
tr:hover { background-color: var(--bg-main); }

.cell-title { font-weight: 600; color: var(--text-dark); margin-bottom: 4px; }
.cell-subtext { font-size: 12px; color: var(--text-gray); }
.tag-dark { background-color: var(--text-dark); color: white; padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 500; display: inline-block; }
.tag-status { background-color: #e0f2fe; color: #0284c7; padding: 4px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; display: inline-block; }

/* ==========================================================================
   PIPELINE PAGE: KANBAN BOARD
   ========================================================================== */
.kanban-board { 
    display: flex; 
    gap: 20px; 
    height: calc(100vh - 155px); 
    overflow-x: auto; 
    padding-bottom: 20px; 
}
.column { background-color: var(--surface-white); min-width: 320px; border-radius: 12px; padding: 20px; border: 1px solid var(--border-light); box-shadow: 0 4px 12px rgba(0,0,0,0.02); display: flex; flex-direction: column; }
.column-header { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; padding-bottom: 15px; margin-bottom: 15px; border-bottom: 2px solid var(--primary-pink); }
.badge { background-color: #ffe4f0; color: var(--primary-pink); padding: 2px 8px; border-radius: 12px; font-size: 12px; font-weight: bold; }
.cards-container { display: flex; flex-direction: column; gap: 15px; overflow-y: auto; }
.card { background-color: var(--surface-white); border: 1px solid var(--border-light); border-radius: 10px; padding: 15px; border-left: 4px solid var(--primary-pink); box-shadow: 0 2px 6px rgba(0,0,0,0.04); }
.card-name { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.card-phone { font-size: 12px; color: var(--text-gray); margin-bottom: 12px; }
.card-msg { font-size: 13px; line-height: 1.5; color: var(--text-dark); }

/* ==========================================================================
   LIVE CHATS PAGE
   ========================================================================== */
.chat-container { 
    display: flex; 
    gap: 20px; 
    height: calc(100vh - 155px); 
    width: 100%; 
}
/* Also lock the Live Chats columns so switching contacts never shifts the layout: */
.chat-sidebar { 
    width: 320px; 
    flex: 0 0 320px; 
    background-color: var(--surface-white); 
    border: 1px solid var(--border-light); 
    border-radius: 12px; 
    display: flex; 
    flex-direction: column; 
    overflow-y: auto; 
}
.chat-main { 
    flex: 1; 
    min-width: 0; 
    background-color: var(--surface-white); 
    border: 1px solid var(--border-light); 
    border-radius: 12px; 
    display: flex; 
    flex-direction: column; 
}
.chat-profile { 
    width: 280px; 
    flex: 0 0 280px; 
    background-color: var(--surface-white); 
    border: 1px solid var(--border-light); 
    border-radius: 12px; 
    padding: 20px; 
    display: flex; 
    flex-direction: column;
}
.chat-header { padding: 20px; border-bottom: 1px solid var(--border-light); font-weight: bold; color: var(--text-dark); }
.chat-list-item { padding: 15px 20px; border-bottom: 1px solid var(--border-light); cursor: pointer; }
.chat-list-item:hover { background-color: var(--bg-main); }
.chat-list-item.active { border-left: 4px solid var(--primary-pink); background-color: var(--bg-main); }
.chat-history { flex: 1; padding: 20px; overflow-y: auto; background-color: #FAFBFF; display: flex; flex-direction: column;}
.chat-input-area { padding: 20px; border-top: 1px solid var(--border-light); display: flex; gap: 10px; }
.chat-input-area input { flex: 1; padding: 10px 15px; border-radius: 8px; border: 1px solid var(--border-light); outline: none; }
.chat-input-area input:focus { border-color: var(--primary-pink); }
.btn-pink { background-color: var(--primary-pink); color: white; border: none; padding: 10px 20px; border-radius: 8px; font-weight: bold; cursor: pointer; }

/* Chat Bubbles */
.msg-bubble { padding: 10px 15px; border-radius: 12px; max-width: 75%; margin-bottom: 15px; font-size: 14px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.msg-received { background-color: #E0E5F2; color: var(--text-dark); align-self: flex-start; border-bottom-left-radius: 2px; }
.msg-sent { background-color: var(--primary-pink); color: white; align-self: flex-end; border-bottom-right-radius: 2px; }

/* --- PROGRESS BAR UI --- */
.progress-wrapper {
    width: 100%;
    background-color: #f1f5f9;
    border-radius: 8px;
    height: 10px;
    margin-top: 10px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

.progress-fill {
    height: 100%;
    border-radius: 8px;
    transition: width 0.5s ease-in-out, background-color 0.5s ease-in-out;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    margin-top: 5px;
}

/* Custom UI Pop-up Card (Toast) */
#toastBox {
    position: fixed;
    bottom: -100px;
    right: 30px;
    background: white;
    color: #1e293b;
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    border-left: 4px solid #10b981;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 14px;
    transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9999;
}
#toastBox.show {
    bottom: 30px;
}

/* ==========================================================================
   NEEDS-AGENT NOTIFICATIONS (Leads page alert bar, panel & cards)
   ========================================================================== */
.agent-alert-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 20px;
    margin-bottom: 20px;
    background: linear-gradient(90deg, #fee2e2 0%, #fff1f2 100%);
    border: 1px solid var(--agent-red-light);
    border-left: 5px solid var(--agent-red);
    border-radius: 10px;
    color: var(--agent-red-dark);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.10);
    user-select: none;
    position: sticky;
    top: 0;
    z-index: 60;
}
.agent-alert-bar:hover { filter: brightness(0.98); }

.agent-alert-pulse-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    border-radius: 50%;
    background: var(--agent-red);
    animation: agentPulse 1.4s infinite;
}
@keyframes agentPulse {
    0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.55); }
    70%  { box-shadow: 0 0 0 12px rgba(220, 38, 38, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.agent-alert-bell { font-size: 18px; animation: agentBellSwing 2s infinite; }
@keyframes agentBellSwing {
    0%, 60%, 100% { transform: rotate(0deg); }
    70%           { transform: rotate(-14deg); }
    80%           { transform: rotate(12deg); }
    90%           { transform: rotate(-8deg); }
}

.agent-alert-text { flex: 1; }

.agent-alert-count {
    background: var(--agent-red);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    min-width: 24px;
    height: 24px;
    padding: 0 8px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.agent-alert-cta {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.75;
    white-space: nowrap;
}

.agent-alert-bar.shake { animation: agentBarShake 0.65s ease-in-out 2; }
@keyframes agentBarShake {
    0%, 100% { transform: translateX(0); }
    20%      { transform: translateX(-7px); }
    40%      { transform: translateX(7px); }
    60%      { transform: translateX(-4px); }
    80%      { transform: translateX(4px); }
}

/* --- Slide-out panel --- */
.agent-panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 900;
}
.agent-panel-backdrop.open { opacity: 1; pointer-events: auto; }

.agent-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    max-width: 92vw;
    background: var(--surface-white);
    border-left: 1px solid var(--border-light);
    box-shadow: -12px 0 36px rgba(15, 23, 42, 0.16);
    transform: translateX(105%);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    display: flex;
    flex-direction: column;
    z-index: 901;
}
.agent-panel.open { transform: translateX(0); }

.agent-panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 20px;
    border-bottom: 1px solid var(--border-light);
    background: var(--agent-red-bg);
}
.agent-panel-title { font-weight: 700; font-size: 15px; color: var(--agent-red-dark); }
.agent-panel-subtitle { font-size: 12px; color: var(--text-gray); margin-top: 4px; }
.agent-panel-close {
    background: transparent;
    border: none;
    font-size: 16px;
    color: var(--text-gray);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}
.agent-panel-close:hover { color: var(--text-dark); }

.agent-panel-actions {
    display: flex;
    gap: 10px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-wrap: wrap;
}
.agent-panel-btn {
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border-light);
    background: white;
    color: var(--text-dark);
}
.agent-panel-btn:hover { background: var(--bg-main); }
.agent-panel-btn.danger { border-color: var(--agent-red-light); color: var(--agent-red-dark); }

.agent-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px 30px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.agent-panel-empty {
    text-align: center;
    color: #94a3b8;
    font-size: 14px;
    padding: 50px 10px;
    line-height: 1.8;
}

/* --- Alert cards --- */
.agent-alert-card {
    border: 1px solid var(--agent-red-light);
    border-left: 4px solid var(--agent-red);
    border-radius: 10px;
    padding: 14px;
    background: var(--agent-red-bg);
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.06);
}
.agent-alert-card.handled {
    border-color: var(--border-light);
    border-left-color: #cbd5e1;
    background: var(--bg-main);
    box-shadow: none;
}
.agent-alert-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}
.agent-alert-name { font-weight: 700; font-size: 14px; color: var(--text-dark); }
.agent-alert-tag {
    background: var(--agent-red-light);
    color: var(--agent-red-dark);
    font-size: 10px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 10px;
    white-space: nowrap;
    letter-spacing: 0.3px;
}
.agent-alert-tag.handled-tag { background: #e2e8f0; color: #475569; }
.agent-alert-phone { font-size: 12px; color: var(--text-gray); margin-bottom: 8px; }
.agent-alert-preview {
    font-size: 13px;
    color: var(--text-dark);
    line-height: 1.5;
    margin-bottom: 10px;
    word-break: break-word;
}
.agent-alert-meta { font-size: 11px; color: #94a3b8; margin-bottom: 10px; }
.agent-alert-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.agent-card-btn {
    padding: 7px 12px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border-light);
    background: white;
    color: var(--text-dark);
}
.agent-card-btn.primary {
    background: var(--agent-red);
    border-color: var(--agent-red);
    color: white;
}
.agent-card-btn.primary:hover { background: var(--agent-red-dark); }
.agent-card-btn.ghost:hover { background: var(--bg-main); }

/* ==========================================================================
   SIDEBAR BELL BADGE (visible on every dashboard page)
   ========================================================================== */
.nav-with-alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.nav-alert-bell {
    display: none;               /* only shown once there are pending requests */
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    cursor: pointer;
    user-select: none;
}
.nav-alert-bell.has-alerts { display: flex; }

.nav-bell-icon { font-size: 15px; line-height: 1; }

/* Shown when the alert API cannot be reached (bot not restarted / offline) */
.nav-alert-bell.has-error { display: flex; }
.nav-alert-bell.has-error .nav-bell-icon { filter: grayscale(1); opacity: 0.55; }

.nav-alert-bell.ring .nav-bell-icon {
    animation: agentBellSwing 0.6s ease-in-out 2;
    display: inline-block;
}

.alert-badge {
    display: none;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--agent-red);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5);
    animation: alertBadgePulse 1.8s infinite;
}

@keyframes alertBadgePulse {
    0%   { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
    70%  { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
    100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

/* ==========================================================================
   LIVE CHATS: needs-agent card + manual pipeline stage control
   ========================================================================== */
.needs-agent-card {
    background: var(--agent-red-bg);
    border: 1px solid var(--agent-red-light);
    border-left: 4px solid var(--agent-red);
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 20px;
    animation: needsAgentGlow 2.2s infinite;
}
@keyframes needsAgentGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.16); }
    50%      { box-shadow: 0 0 0 7px rgba(220, 38, 38, 0); }
}

.needs-agent-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--agent-red-dark);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}
.needs-agent-text {
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-dark);
    margin-bottom: 12px;
    word-break: break-word;
}
.needs-agent-actions { display: flex; flex-direction: column; gap: 8px; }
.needs-agent-btn {
    width: 100%;
    font-size: 12px;
    font-weight: 600;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    justify-content: center;
}

.stage-help {
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-gray);
    margin: 0 0 10px 0;
}
.stage-control { display: flex; gap: 8px; }
.stage-select { flex: 1; min-width: 0; font-size: 12px; padding: 8px 10px; }
.stage-apply { font-size: 12px; padding: 8px 14px; }
.stage-buttons { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.stage-quick {
    flex: 1;
    min-width: 70px;
    padding: 7px 8px;
    border: 1px solid var(--border-light);
    border-radius: 7px;
    background: white;
    color: var(--text-dark);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
}
.stage-quick:hover { background: var(--bg-main); border-color: var(--primary-pink); color: var(--primary-pink); }

/* ==========================================================================
   LEADS PAGE: pending human-agent request list
   ========================================================================== */
.pending-agent-section {
    margin-bottom: 22px;
    border: 1px solid var(--agent-red-light);
    border-radius: 10px;
    background: var(--agent-red-bg);
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.08);
    overflow: hidden;
}
.pending-agent-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
    padding: 14px 20px;
    border-bottom: 1px solid var(--agent-red-light);
    font-size: 13px;
    font-weight: 700;
    color: var(--agent-red-dark);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.pending-agent-hint {
    font-size: 11px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-gray);
}
.pending-scroll {
    max-height: 260px;
    overflow-y: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--surface-white);
}
.pending-scroll table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-main);
}
.pending-scroll td { padding: 12px 20px; vertical-align: middle; }
.pending-preview { color: var(--text-dark); font-size: 13px; max-width: 420px; word-break: break-word; }

/* ==========================================================================
   LIVE CHATS: LOST contact lock (read-only contact)
   ========================================================================== */
.contact-lock {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-left: 4px solid #94a3b8;
    border-radius: 10px;
    padding: 14px;
    margin-bottom: 20px;
}
.contact-lock-title {
    font-size: 13px;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 8px;
}
.contact-lock-text { font-size: 12px; line-height: 1.55; color: var(--text-gray); }

/* Dim and block the settings block while the contact is locked */
#contactSettings.settings-locked {
    opacity: 0.55;
    filter: grayscale(0.6);
    pointer-events: none;
    user-select: none;
}
#contactSettings.settings-locked select,
#contactSettings.settings-locked button {
    cursor: not-allowed;
}

/* The composer is disabled for LOST contacts */
.chat-input-area input:disabled,
.chat-input-area button:disabled {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
    border-color: #cbd5e1;
}