:root {
    --chat-bg: var(--backgroundColor, #f9f9f9);
    --chat-border: var(--content-border-color);
    --chat-accent: var(--header-background-color);
    --chat-user-bg: var(--main-color);
    --chat-bot-bg: var(--secondaryColor, #f8f9fa);
    --chat-form-bg: var(--panel-background);
    --chat-overlay-bg: var(--header-background-color);
    --chat-user-text-color: var(--light);
    --chat-bot-text-color: var(--field-color);
    --min-message-width: 50px;

    --chat-text-primary: var(--textColor, #333);
    --chat-text-muted: var(--textDisabled, #777);
    --chat-surface-hover: var(--hoverColor, #f5f7fb);
    --chat-surface-active: var(--tertiaryColor, #e8f0fe);
    --chat-surface-raised: var(--secondaryColor, #f8f9fa);
    --chat-border-subtle: var(--borderColor, #f0f0f0);
}

.custom-theme #chat_container {
    background: var(--chat-form-bg);
}

#chat_container {
    /*width: unset !important;
    margin-left: 5px !important;
    margin-right: 5px !important;*/
    display: flex;
    flex-direction: column;
    height: calc(100vh - 140px);
}

#chat_status {
    position: absolute;
    top: 16px;
    right: 11px;
    display: flex;
    align-items: center;
    font-size: 0.8em;
    font-weight: 600;
}

#statusDot {
    width: 10px;
    height: 10px;
    background-color: #ccc;
    border-radius: 50%;
    display: inline-block;
    margin-left: 8px;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.status-online {
    background-color: #28a745 !important;
}

.status-offline {
    background-color: #dc3545 !important;
}

#messages {
    /*position: absolute;
    top: 40px;
    bottom: 50px;*/
    flex: 1;
    left: 0;
    right: 0;
    overflow-y: auto;
    padding: 10px;
    /* padding-top: 10px; */
    /* padding-bottom: 58px; */
    margin-bottom: 58px;
    margin-top: 46px;
}

#chatForm {
    position: absolute;
    bottom: 0;
    /*padding: 10px;*/
    left: 0;
    right: 0;
    padding: 10px;
    border-top: 1px solid var(--chat-border);
    background: var(--chat-form-bg);
    white-space: nowrap;
}

#message {
    display: inline-block;
    width: calc(100% - 130px);
    padding: 8px 12px !important;
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    font-size: 0.95em;
    line-height: 1.4;
    color: var(--chat-bot-text-color);
    background: var(--chat-form-bg);
    outline: none;
    box-sizing: border-box;
    vertical-align: middle;
    resize: none;
    overflow-y: hidden;
    max-height: calc(1.4em * 5 + 18px);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#message:focus {
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

#sendBtn {
    width: 80px;
}

.btnAction {
    display: inline-block;
    position: relative;
    padding: 8px 0;
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    vertical-align: middle;
    transition: background 0.2s;
    text-align: center;
}

.msg .message-footer {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-top: 2px;
}
.msg .add-reaction-btn {
    opacity:0;
    display: flex;
    height:0px;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px 0px 0px 2px;
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.1s ease;
    overflow: hidden;
}
.msg:hover .add-reaction-btn {
    opacity:1;
    height: 1.2rem;
}
.msg .add-reaction-btn .fa-smile {
    filter: grayscale(100%);
    transition: filter 0.2s ease;
    color: var(--chat-text-muted);
}
.msg .add-reaction-btn:hover .fa-smile {
    filter: grayscale(0%);
    color: #ffc107;
}
.msg .add-reaction-btn .plus-icon {
    font-size: 0.7rem;
    color: var(--chat-text-muted);
    font-weight: bold;
    transition: color 0.2s ease;
}
.msg .add-reaction-btn:hover .plus-icon {
    color: #28a745;
}

.msg .message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.msg.local .reaction-item {
    --background: color-mix(in srgb, var(--chat-bot-bg) 20%, transparent);
    color: var(--chat-bot-bg);
}

.msg.remote .reaction-item {
    --background: color-mix(in srgb, var(--chat-user-bg) 15%, transparent);
    color: var(--chat-user-bg);
}

.msg .reaction-item .remove {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
    font-size: 0.75rem;
    z-index: 10;
}

.msg .reaction-item.removable:hover .remove {
    display:block;
}

.msg .reaction-item {
    position: relative;
    display: inline-flex;
    align-items: center;
    background: var(--chat-bg);
    /*border: 1px solid var(--chat-border);*/
    border-radius: 12px;
    padding: 2px 6px 0px 6px;
    font-size: 0.85rem;
    transition: transform 0.2s ease;
    user-select: none;
    z-index: 2;
    background: var(--background);
    border: 1px var(--background);
}

.msg .reaction-item:hover {
    transform: scale(1.15);
}

.msg .reaction-item .count {
    margin-left: 4px;
    font-weight: bold;
}

.msg {
    position: relative;
    clear: both;
    max-width: 80%;
    min-width: var(--min-message-width);
    margin: 6px 0;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.95em;
    line-height: 1.4;
    word-wrap: break-word;
}

.msg .author {
    font-weight: 600;
    margin-right: 5px;
}

.msg .time {
    font-size: 0.78em;
}

.msg.local {
    float: right;
    background: var(--chat-user-bg);
    border-bottom-right-radius: 2px;
    color: var(--chat-user-text-color);
}

.msg.local .text {
    white-space: pre-wrap;
}

.msg.remote {
    float: left;
    background: var(--chat-bot-bg);
    border-bottom-left-radius: 2px;
    color: var(--chat-bot-text-color);
    border: 1px solid var(--chat-border);
}

.msg .media {
    display: none;
    background-color: transparent;
}

.msg .media * {
    margin:auto;
    border-radius: 5px;
}

.msg .media .sticker {
    width: 100px;
}

.msg .media .image,
.msg .media .video {
    width: 400px;
}

.msg .media .audio {
    border-radius: 8px;
}

.msg .media .media-card {
    display: flex;
    align-items: center;
    padding: 10px;
    border-radius: 8px;
    transition: background 0.2s;
    color: var(--chat-bot-text-color);
}

.msg .media .media-card i {
    cursor: pointer;
}

.msg .media .media-card  { background: var(--chat-surface-raised); }
.msg .media .media-card:hover { background: var(--chat-surface-hover); }

.msg .media .card-info {
    flex: 1;
    overflow: hidden;
    margin: 0 10px;
}

.msg .media .card-title {
    font-weight: 600;
    font-size: 0.9em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.msg .media .card-subtitle {
    font-size: 0.8em;
    color: var(--chat-text-muted);
}

.msg .media .document-item i.fa-file-alt { color: var(--chat-text-muted); }
.msg .media .document-item i.fa-download { color: var(--chat-accent); }

.msg:has(.media > .sticker) {
    min-width: 125px;
}

.media-viewer {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.media-viewer.visible {
    display: flex;
}

.viewer-content {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    border-radius: 4px;
}

.close-viewer {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10001;
}

.close-viewer:hover {
    color: #bbb;
}

.media-unavailable-container {
    display: flex;
    align-items: center; 
    padding: 16px;
    background: var(--chat-surface-raised);
    border: 1px dashed var(--chat-border-subtle);
    border-radius: 12px;
    color: var(--chat-text-muted);
    margin: 10px 0;
    max-width: 100%;
}

.unavailable-text {
    display: flex;
    flex-direction: column;
    line-height: 1.4;
    font-size: 0.85rem;
}

.unavailable-text strong {
    color: var(--chat-text-primary);
    margin-bottom: 2px;
}

.msg .media .image,
.msg .media .sticker,
.msg .media .video {
    cursor: zoom-in;
    transition: opacity 0.2s;
}

.msg .media .image:hover,
.msg .media .sticker:hover,
.msg .media .video:hover {
    opacity: 0.9;
}

.msg .placeholder {
    display: none;
    align-items: center;
    justify-content: center;
    background-color: var(--chat-surface-raised);
    border-radius: 8px;
}

.msg .placeholder .loading-spinner {
    width: 40px;
    height: 40px;
    animation: rotate 2s linear infinite;
}

.msg .placeholder .loading-spinner .path {
    stroke: #4A90E2;
    stroke-linecap: round;
    animation: dash 1.5s ease-in-out infinite;
}

@keyframes rotate {
    100% { transform: rotate(360deg); }
}

@keyframes dash {
    0% {
        stroke-dasharray: 1, 150;
        stroke-dashoffset: 0;
    }
    50% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -35;
    }
    100% {
        stroke-dasharray: 90, 150;
        stroke-dashoffset: -124;
    }
}

.msg .text table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 14px;
}

.msg .text th,
.msg .text td {
    border: 1px solid var(--chat-border-subtle);
    padding: 6px 10px;
    text-align: left;
}

.msg .text th {
    background: var(--chat-surface-raised);
    font-weight: bold;
}

.msg .text tr:nth-child(even) {
    background: var(--chat-surface-raised);
}

#chat_header {
    position:absolute;
    top:0px;
    z-index:1;
    left:0px;
    right:0px;
    height:46px;
    background: var(--chat-form-bg);
    color: var();
    border-bottom: 1px solid var(--chat-border);
}

.chatActionsLeft {
    display: flex;
    align-items: center;
    gap: 0px;
}

.chatActionsLeft button {
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    margin: 5px 0px 5px 5px;
}

#chatForm #emojiBtn {
    display: inline-block;
    width: 40px;
}

.emoji-picker {
    position: absolute;
    bottom: 65px;
    right: 9px;
    background: var(--chat-form-bg);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 0px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.emoji-search {
    grid-column: span 7;
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid var(--chat-border);
    background: var(--chat-bot-bg);
    color: var(--chat-bot-text-color);
    width: 100%;
    box-sizing: border-box;
    position: sticky;
    top: 0px;
    box-shadow: white 0px -15px 0px;
    z-index: 11;
}

.emoji-category-title {
    font-size: 0.8em;
    font-weight: bold;
    color: var(--chat-text-muted);
    margin: 15px 0 0 5px;
    text-transform: uppercase;
    grid-column: span 7;
}

.emoji-grid {
    display: contents;
}

.emoji-item {
    cursor: pointer;
    font-size: 1.4em;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    border-radius: 4px;
    transition: background 0.2s;
    user-select: none;
}

.emoji-item:hover {
    background: rgba(0,0,0,0.05);
}

.modal-custom {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-dialog-custom {
    width: 400px;
    max-width: 650px;
    margin: 20px;
}

.modal-content-custom {
    background: var(--chat-surface-raised);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}

.modal-header-custom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--chat-border-subtle);
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
}

.modal-body-custom {
    max-height: 60vh;
    overflow-y: auto;
    padding: 15px;
}

.atendimento-item {
    background: #f6fffa;
    border: 1px solid #d2f5e3;
    border-left: 4px solid #28a745;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 10px;
    transition: all 0.2s ease;
    cursor: pointer;
}

.atendimento-item:hover {
    background: #ecfff5;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.atendimento-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.atendimento-id {
    font-weight: 600;
    font-size: 14px;
    color: var(--chat-text-primary);
}

.atendimento-data {
    font-size: 11px;
    color: var(--chat-text-muted);
    margin-top: 4px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    background: #28a745;
    border-radius: 50%;
}


/* === 3 PONTOS / APAGAR MENSAGEM === */
.msg {
    position: relative;
}

.msg-options {
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 16px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
    user-select: none;
}

.msg:hover .msg-options {
    opacity: 0.6;
}

.msg::after {
    content: '';
    display: table;
    clear: both;
}

#statusDot.status-online {
    background-color: #28a745;
    box-shadow: 0 0 6px rgba(40, 167, 69, 0.5);
}

#statusDot.status-offline {
    background-color: #dc3545;
    box-shadow: 0 0 6px rgba(220, 53, 69, 0.5);
}

.btn-atendimento-encerrar {
    background-color: var(--red, #dc3545) !important;
    color: white !important;
}

.btn-atendimento-encerrar:hover {
    background-color: var(--red, #c82333) !important;
    filter: brightness(0.9);
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    #chat_container {
        border-radius: 0;
        border: none;
    }

    .msg {
        max-width: 90%;
    }

    .msg .media .image,
    .msg .media .video {
        width: 100%;
    }
}
