/* ============================================================
   FLOW WHATSAPP
   Extraído de backend/web/css/flow-ui.css
   Escopo: layout do chat, sidebar, lista, input, modal e leitura
   ============================================================ */

/* ============================================================
   FLOW MESSAGES (WhatsApp Layout)
   ============================================================ */
#flow-messages-wrapper {
    display: flex;
    height: calc(100vh - 120px);
}

#flow-messages-sidebar {
    width: 340px;
    background: #fff;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 10px;
    border-bottom: 1px solid #ddd;
}

.sidebar-list {
    flex: 1;
    overflow-y: auto;
}

#stage-tabs {
    margin-top: 10px;
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.stage-tab {
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: #f3f3f3;
    cursor: pointer;
}

.stage-tab.active {
    background: #007bff;
    color: #fff;
    border-color: #007bff;
}

/* ============================================================
   Lista de conversas
   ============================================================ */
.flow-chat-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

.chat-item:hover {
    background: #f6f6f6;
}

.chat-item.active {
    background: #e6f0ff;
}

.chat-item-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e0e7ff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    margin-right: 10px;
}

.chat-item-body {
    flex: 1;
    min-width: 0;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.chat-item-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
}

.chat-item-time {
    font-size: 11px;
    color: #999;
    white-space: nowrap;
}

.chat-item-subtitle,
.chat-item-lastmsg {
    font-size: 12px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-lastmsg {
    color: #999;
}

.chat-item-unread {
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: #007bff;
    color: #fff;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 8px;
}

/* ============================================================
   Busca da sidebar
   ============================================================ */
.sidebar-search {
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
}

#flow-search-input {
    border-radius: 20px;
    padding-left: 15px;
}

.flow-search-wrapper {
    position: relative;
}

.flow-search-wrapper input {
    padding-right: 35px;
}

.search-clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    cursor: pointer;
    color: #999;
    display: none;
}

.search-clear-btn:hover {
    color: #333;
}

/* ============================================================
   Área principal do chat
   ============================================================ */
#flow-messages-chat {
    flex: 1;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
}

.chat-main-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    background-image: url('https://easyflows.com.br/app/imagens/whatsapp-bg-light.png');
    background-repeat: repeat;
}

/* Override específico dentro do WhatsApp layout */
#chat-area .message-history {
    background: transparent;
    border: none;
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    margin: 0;
}

.chat-header-bar {
    padding: 10px 20px;
    border-bottom: 1px solid #ddd;
    background: #ffffff;
}

.chat-footer {
    width: 100%;
}

/* ============================================================
   Mensagens (layout bubble WhatsApp)
   ============================================================ */
.message-item {
    margin-bottom: 8px;
    display: flex;
}

.message-out {
    justify-content: flex-end;
}

.message-in {
    justify-content: flex-start;
}

.message-bubble {
    position: relative;
    max-width: 70%;
    padding: 8px 10px;
    border-radius: 8px;
    background: #e1ffc7;
}

.message-in .message-bubble {
    background: #ffffff;
}

.message-reaction {
    position: absolute;
    bottom: -10px;
    right: 10px;
    background: #fff;
    border-radius: 12px;
    padding: 2px 6px;
    font-size: 16px;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.message-in .message-reaction {
    right: auto;
    left: 10px;
}

/* ============================================================
   Input do chat
   ============================================================ */
.message-input {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-select {
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 8px;
    font-size: 1em;
    background: #fff;
    color: #333;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.user-select:focus {
    border-color: #007bff;
    box-shadow: 0 0 3px rgba(0, 123, 255, 0.5);
    outline: none;
}

#flow-messages-chat .message-input {
    border-top: 1px solid #ddd;
    padding: 8px 12px;
    background: #f9f9f9;
}

/* FIX CRÍTICO: mantido escopado ao chat */
.message-input textarea {
    resize: none;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 8px;
    font-size: 1em;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.message-input textarea:focus {
    border-color: #007bff;
    box-shadow: 0 0 3px rgba(0, 123, 255, 0.5);
    outline: none;
}

.message-input button {
    background: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px;
    font-size: 1em;
    cursor: pointer;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.message-input button:hover {
    background: #0056b3;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message-input button:active {
    background: #004085;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   Input row
   ============================================================ */
.chat-input-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-items: stretch;
}

.chat-input-row select,
.chat-input-row textarea {
    font-size: 13px;
}

.chat-input-row select {
    max-width: 260px;
}

.message-textarea-wrapper {
    flex: 1;
    min-width: 0;
}

.chat-input-row textarea {
    width: 100%;
    flex: 1;
    resize: vertical;
    min-height: 40px;
    max-height: 120px;
    padding-right: 8px;
}

.chat-footer-action-button {
    width: 42px;
    min-width: 42px;
    height: 40px;
    padding: 0 !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px !important;
}

.chat-emoji-wrapper {
    position: relative;
    display: flex;
    align-items: stretch;
}

.chat-emoji-button {
    background-color: #f1f3f5 !important;
    color: #007bff !important;
}

.chat-emoji-button:hover {
    background-color: #007bff !important;
    color: #fff !important;
}

.chat-emoji-picker {
    position: absolute;
    right: 0;
    bottom: 46px;
    z-index: 9999;
}

.chat-send-button {
    min-width: 72px;
}

/* ============================================================
   Badge de novas mensagens
   ============================================================ */
.new-messages-badge {
    position: absolute;
    right: 20px;
    bottom: 80px;
    z-index: 20;
    box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

/* ============================================================
   Modal de abertura de demanda via chat
   ============================================================ */
.modal-dialog-fullscreen {
    width: 90vw;
    max-width: 90vw;
    height: 85vh;
    margin: 0 auto;
}

.modal-dialog-fullscreen .modal-content {
    height: 85vh;
    border-radius: 10px;
    overflow: hidden;
}

.modal-dialog-fullscreen .modal-body {
    height: 100%;
    overflow-y: auto;
}

/* Esconde prev/next quando estiverem desabilitados (Yii2 LinkPager real) */
.flow-pagination li.prev.disabled,
.flow-pagination li.next.disabled {
    display: none !important;
}

/* ============================================================
   Indicação de leitura
   ============================================================ */
.message-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #999;
}

.message-status {
    font-size: 12px;
}

.message-delivered {
    color: #999;
}

.message-read {
    color: #34b7f1;
}

/*
 * O endpoint de mensagens marca como lidas as mensagens carregadas pelo usuário logado.
 * Para mensagens WhatsApp enviadas pelo operador, esse estado representa leitura local
 * do histórico, não confirmação de leitura do destinatário no WhatsApp.
 * Mantemos o indicador de saída como entregue até existir um recibo real do destinatário.
 */
#flow-messages-wrapper .message-item.message-out.message-whatsapp .message-status.message-read {
    color: #999;
}

/* ============================================================
   Emojis
   ============================================================ */
.chat-message,
#message-content,
#conversation-message-content,
.message-history {
    font-family:
            system-ui,
            -apple-system,
            BlinkMacSystemFont,
            "Segoe UI",
            "Segoe UI Emoji",
            "Apple Color Emoji",
            "Noto Color Emoji",
            sans-serif;
}

.flow-messages-tabs .flow-messages-tab.active {
    font-weight: 600;
}

.people-chat-list .chat-item-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #e9ecef;
    font-weight: 600;
    flex-shrink: 0;
}

.person-flows-container {
    margin-left: 54px;
    margin-top: -4px;
    margin-bottom: 6px;
}

.person-flow-item {
    padding: 8px 10px;
    border-left: 2px solid #d9dee3;
    cursor: pointer;
    background: #f8f9fb;
    margin-bottom: 4px;
    border-radius: 6px;
}

.person-flow-item:hover {
    background: #eef2f7;
}

.person-flow-item.active {
    background: #dde7f3;
    border-left-color: #4a7db8;
}

.person-flow-main {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.person-flow-title {
    font-size: 12px;
    font-weight: 600;
    color: #1f2d3d;
}

.person-flow-time {
    font-size: 11px;
    color: #7a8694;
    white-space: nowrap;
}

.person-flow-preview {
    font-size: 12px;
    color: #6c757d;
    margin-top: 2px;
}

@media (max-width: 767.98px) {
    #flow-messages-wrapper {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        width: 100vw !important;
        max-width: 100vw !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
    }

    #flow-messages-sidebar,
    #flow-messages-chat {
        flex: 0 0 100vw !important;
        width: 100vw !important;
        min-width: 100vw !important;
        max-width: 100vw !important;
    }

    .chat-input-row {
        flex-wrap: wrap;
    }

    .chat-input-row select {
        max-width: none;
        flex: 1 1 calc(100% - 50px);
    }

    .message-textarea-wrapper {
        flex: 1 1 100%;
    }
}

#flow-messages-wrapper {
    scroll-snap-type: x mandatory;
}

#flow-messages-sidebar,
#flow-messages-chat {
    scroll-snap-align: start;
}

#add-chat-participant {
    background-color: #f1f3f5;
    border: none;
    color: #6c757d;
}

#add-chat-participant:hover {
    background-color: #25D366; /* verde WhatsApp */
    color: #fff;
}

.message-sender {
    font-weight: 600; /* ou bold */
}

.message-temporary {
    opacity: 0.75;
}

.message-temporary .message-bubble {
    filter: saturate(0.85);
}

.isa-thinking-dots span {
    animation: isaThinkingBlink 1.2s infinite;
}

.isa-thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.isa-thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes isaThinkingBlink {
    0%, 20% {
        opacity: 0.2;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.2;
    }
}