/* Live chat widget */
.live-chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1200;
    font-family: "Inter", sans-serif;
}

body.customer-app .live-chat-widget {
    bottom: 96px;
}

.live-chat-widget .live-chat-launcher {
    position: relative;
    background: #f3b300;
    color: #000;
    border: none;
    border-radius: 999px;
    padding: 12px 18px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    font-weight: 600;
    cursor: pointer;
}

.live-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 999px;
    padding: 0 5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.live-chat-badge.hidden {
    display: none;
}

.live-chat-widget .live-chat-panel {
    width: 320px;
    max-height: 420px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.2);
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.live-chat-panel.hidden {
    display: none;
}

.live-chat-header {
    padding: 16px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.live-chat-header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.live-chat-end,
.live-chat-close {
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 600;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.live-chat-escalate {
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 600;
    background: #fde68a;
    color: #92400e;
    box-shadow: 0 4px 10px rgba(146, 64, 14, 0.15);
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.live-chat-escalate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.live-chat-escalate:hover:not(:disabled) {
    background: #fcd34d;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 9999;
}

.modal-overlay.is-open {
    display: flex;
}

.modal-card {
    width: min(520px, 95vw);
    background: #ffffff;
    border-radius: 18px;
    padding: 20px 22px 22px;
    box-shadow: 0 30px 60px rgba(15, 23, 42, 0.35);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.modal-close {
    border: none;
    background: transparent;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    color: #111827;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 16px;
    flex-wrap: wrap;
}

.modal-actions .btn-primary {
    background: #f59e0b;
    border: none;
    color: #111827;
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
}

.modal-actions .btn-secondary {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #111827;
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
}

body.modal-open {
    overflow: hidden;
}

.live-chat-end {
    background: #fee2e2;
    color: #b91c1c;
    box-shadow: 0 4px 10px rgba(185, 28, 28, 0.15);
}

.live-chat-end:hover {
    background: #fecaca;
}

.live-chat-close {
    background: #f3f4f6;
    color: #111827;
    box-shadow: 0 3px 8px rgba(17, 24, 39, 0.12);
}

.live-chat-close:hover {
    background: #e5e7eb;
}

.live-chat-header-actions button:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4);
}

.live-chat-status {
    padding: 8px 16px;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.9rem;
    border-bottom: 1px solid #f5d399;
}

.live-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.live-chat-message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.4;
}

.live-chat-message.staff {
    background: #fff;
    border: 1px solid #e4e4e4;
    align-self: flex-start;
}

.live-chat-message.customer {
    background: #f3b300;
    color: #000;
    align-self: flex-end;
}

.chat-action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: #25d366;
    color: #0b1f12;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid rgba(11, 31, 18, 0.15);
}

.chat-action-button:hover {
    background: #1ebe5d;
}

.live-chat-ended {
    background: #fef2f2;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: 12px;
    margin: 8px 16px;
    border: 1px solid #fecaca;
    text-align: center;
    font-weight: 600;
}

.live-chat-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 0 16px 16px;
}

.live-chat-actions[hidden] {
    display: none;
}

.live-chat-actions button {
    border: none;
    border-radius: 999px;
    padding: 8px 20px;
    font-weight: 600;
    cursor: pointer;
    background: #f3b300;
    color: #000;
}

.live-chat-actions button.secondary {
    background: #e5e7eb;
    color: #111827;
}
.live-chat-composer {
    padding: 12px 16px 16px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    gap: 8px;
}

.live-chat-composer textarea {
    flex: 1;
    border-radius: 10px;
    border: 1px solid #ddd;
    padding: 8px 10px;
    resize: none;
    min-height: 50px;
    font-family: inherit;
}

.live-chat-composer button {
    background: #f3b300;
    border: none;
    border-radius: 10px;
    padding: 0 18px;
    font-weight: 600;
    cursor: pointer;
}

.live-chat-typing {
    font-size: 0.85rem;
    padding: 0 16px 8px;
    color: #555;
}

.live-chat-feedback {
    font-size: 0.85rem;
    padding: 0 16px 8px;
    color: #2563eb;
    min-height: 1.2em;
    transition: opacity 0.2s ease;
    opacity: 0;
}

/* Staff console */
.live-chat-console {
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 20px;
    min-height: 70vh;
    position: relative;
}

.chat-sidebar {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #f2f2f2;
}

.chat-thread-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1;
}

.chat-thread-item {
    padding: 14px 16px;
    border-bottom: 1px solid #f7f7f7;
    cursor: pointer;
}

.chat-thread-item.active {
    background: #fef6dd;
}

.chat-thread-item .thread-meta {
    font-size: 0.82rem;
    color: #6b7280;
}

.chat-panel {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    min-height: 70vh;
    min-width: 0;
}

.chat-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f2f2f2;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.chat-split-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 999px;
    width: 30px;
    height: 30px;
    font-size: 1rem;
    cursor: pointer;
    color: #111827;
    position: absolute;
    top: 50%;
    left: var(--chat-sidebar-width, 280px);
    transform: translate(-50%, -50%);
    z-index: 5;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.chat-split-toggle::before {
    content: "‹";
    line-height: 1;
}

.chat-panel-actions > button {
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 10px;
    padding: 6px 14px;
    cursor: pointer;
    margin-left: 8px;
}

.chat-panel-actions > button.primary {
    background: #f3b300;
    border-color: #f3b300;
}

.chat-panel-actions > button.is-assigned-self {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #6b7280;
    cursor: not-allowed;
}

/* ── Chat Actions Dropdown ── */
.chat-actions-dropdown {
    position: relative;
    display: inline-block;
}

.chat-actions-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #d1d5db;
    background: #fff;
    border-radius: 10px;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.chat-actions-toggle:hover {
    background: #f3f4f6;
}

.chat-actions-toggle:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-actions-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    min-width: 200px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    z-index: 50;
    padding: 6px 0;
}

.chat-actions-dropdown.open .chat-actions-menu {
    display: block;
}

.chat-actions-assign-row {
    padding: 4px 10px;
}

.chat-actions-assign-row select {
    width: 100%;
    font-size: 0.85rem;
    border-radius: 6px;
    margin-bottom: 2px;
}

.chat-action-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 14px;
    border: none;
    background: none;
    font-size: 0.875rem;
    color: #374151;
    cursor: pointer;
    text-decoration: none;
    text-align: left;
}

.chat-action-item:hover {
    background: #f3f4f6;
}

.chat-action-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    flex-shrink: 0;
}

.chat-action-assign {
    color: #1e3a8a;
}

.chat-action-resolve {
    color: #047857;
}

.chat-action-whatsapp {
    color: #25d366;
}

.chat-action-call {
    color: #2563eb;
}

.chat-panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-panel-messages {
    flex: 1;
    padding: 18px 20px;
    overflow-y: auto;
    background: #f9fafb;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-panel-message {
    padding: 10px 14px;
    border-radius: 12px;
    max-width: 80%;
}

.chat-panel-message.staff {
    background: #fff;
    align-self: flex-start;
    border: 1px solid #e5e7eb;
}

.chat-panel-message.customer {
    background: #fef3c7;
    align-self: flex-end;
    border: 1px solid #fde68a;
}

.chat-panel-composer {
    padding: 14px 18px 20px;
    border-top: 1px solid #f2f2f2;
    display: flex;
    gap: 12px;
}

.chat-panel-composer textarea {
    flex: 1;
    border-radius: 12px;
    border: 1px solid #d1d5db;
    padding: 10px 12px;
    resize: none;
    min-height: 70px;
}

.chat-panel-composer button {
    border: none;
    border-radius: 12px;
    background: #f3b300;
    color: #000;
    padding: 0 24px;
    font-weight: 600;
    cursor: pointer;
}

.chat-panel-feedback {
    font-size: 0.85rem;
    color: #2563eb;
    padding: 0 18px 8px;
    min-height: 1.2em;
    transition: opacity 0.2s ease;
    opacity: 0;
}

.chat-context {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 16px;
}

.chat-context-section {
    margin-bottom: 16px;
}

.chat-empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 1.1rem;
}

@media (max-width: 1024px) {
    .live-chat-console {
        --chat-sidebar-width: 280px;
        grid-template-columns: minmax(0, var(--chat-sidebar-width)) minmax(0, 1fr);
        gap: 16px;
    }
    .chat-sidebar {
        max-height: none;
        min-height: 70vh;
        transition: opacity 0.2s ease;
    }
    .chat-panel {
        min-height: 70vh;
    }
    .chat-panel-header {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .live-chat-console.sidebar-collapsed {
        --chat-sidebar-width: 0px;
        gap: 0;
        grid-template-columns: 0 minmax(0, 1fr);
    }

    .live-chat-console.sidebar-collapsed .chat-sidebar {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        border-color: transparent;
        padding: 0;
        margin: 0;
        overflow: hidden;
    }

    .live-chat-console.sidebar-collapsed .chat-panel {
        width: 100%;
        max-width: 100%;
    }


    .live-chat-console.sidebar-collapsed .chat-split-toggle::before {
        content: "›";
    }
    .live-chat-console.sidebar-collapsed .chat-split-toggle {
        left: 0;
    }
}

/* ── Mobile: exclusive view – sidebar OR chat panel, never both ── */
@media (max-width: 768px) {
    .live-chat-console,
    .live-chat-console.sidebar-collapsed {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
    }

    /* Default state: sidebar visible, chat panel + toggle hidden */
    .live-chat-console:not(.sidebar-collapsed) .chat-panel {
        display: none;
    }
    .live-chat-console:not(.sidebar-collapsed) .chat-split-toggle {
        display: none !important;
    }

    /* Collapsed state: chat panel visible, sidebar hidden */
    .live-chat-console.sidebar-collapsed .chat-sidebar {
        display: none !important;
    }
    .live-chat-console.sidebar-collapsed .chat-panel {
        display: flex;
    }

    /* Back button visible in collapsed (chat) view */
    .live-chat-console.sidebar-collapsed .chat-split-toggle {
        display: inline-flex !important;
        position: absolute !important;
        top: 12px !important;
        left: 12px !important;
        transform: none !important;
        z-index: 10;
    }
    .live-chat-console.sidebar-collapsed .chat-split-toggle::before {
        content: "\2039";
    }

    /* Make room for the back button in the chat header */
    .live-chat-console.sidebar-collapsed .chat-panel-header {
        padding-left: 48px;
    }
}

@media (min-width: 1025px) {
    .chat-split-toggle {
        display: none;
    }
}

/* ── Phone: fullscreen chat overlay ── */
@media (max-width: 640px) {
    .live-chat-console.chat-mobile-fullscreen {
        position: static;
    }

    .live-chat-console.chat-mobile-fullscreen .chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        z-index: 9999;
        border-radius: 0;
        border: none;
        display: flex !important;
        flex-direction: column;
    }

    .live-chat-console.chat-mobile-fullscreen .chat-sidebar {
        display: none !important;
    }

    .live-chat-console.chat-mobile-fullscreen .chat-panel-body {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .live-chat-console.chat-mobile-fullscreen .chat-panel-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .live-chat-console.chat-mobile-fullscreen .chat-panel-composer {
        background: #fff;
        z-index: 2;
        border-top: 1px solid #e5e7eb;
        padding: 12px 14px 16px;
        flex-shrink: 0;
    }

    .live-chat-console.chat-mobile-fullscreen .chat-panel-composer textarea {
        min-height: 44px;
        font-size: 16px; /* prevent iOS zoom on focus */
    }

    /* Close button — fixed top-left */
    .live-chat-console.chat-mobile-fullscreen .chat-split-toggle {
        display: inline-flex !important;
        position: fixed !important;
        top: 12px !important;
        left: 12px !important;
        transform: none !important;
        z-index: 10000 !important;
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        width: 32px;
        height: 32px;
        border-radius: 50%;
        font-size: 1rem;
    }

    .live-chat-console.chat-mobile-fullscreen .chat-split-toggle::before {
        content: "\2715"; /* ✕ */
        font-size: 0.9rem;
        font-weight: 700;
        line-height: 1;
    }

    /* Make room for close button in header */
    .live-chat-console.chat-mobile-fullscreen .chat-panel-header {
        padding-left: 52px;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    /* Hide context section on fullscreen to save space */
    .live-chat-console.chat-mobile-fullscreen .chat-context-section {
        display: none;
    }

    /* Center the Actions dropdown so it doesn't clip off-screen */
    .live-chat-console.chat-mobile-fullscreen .chat-actions-menu {
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }

    /* Hide the resolved notice top padding */
    .live-chat-console.chat-mobile-fullscreen .chat-resolved-notice {
        border-radius: 0;
    }
}

.chat-resolved-notice {
    padding: 8px 16px;
    background: #ecfccb;
    color: #3f6212;
    border-bottom: 1px solid #d9f99d;
}
