/* ============================================================
   Chat Widget flutuante — visual profissional (prefixo cw-)
   Isolado da página /chat. Identidade roxa do sistema.
   ============================================================ */
:root {
    --cw-brand-1: #00444c;
    --cw-brand-2: #005e68;
    --cw-brand-grad: linear-gradient(135deg, #00444c, #002f34, #005e68);
    --cw-ink: #1f2430;
    --cw-muted: #8b93a3;
    --cw-line: #edeff3;
    --cw-surface: #ffffff;
    --cw-surface-2: #f7f8fb;
    --cw-online: #22c55e;
    --cw-danger: #ef4444;
    --cw-shadow: 0 18px 48px rgba(31, 36, 48, 0.20), 0 4px 12px rgba(31, 36, 48, 0.10);
}

/* ---------- Launcher ---------- */
.cw-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--cw-brand-grad);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(0, 68, 76, 0.45);
    cursor: pointer;
    z-index: 10500;
    transition: transform 0.18s cubic-bezier(.34,1.56,.64,1), box-shadow 0.18s ease;
}

.cw-launcher:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 14px 30px rgba(0, 68, 76, 0.55);
}

.cw-launcher:active {
    transform: scale(0.96);
}

.cw-launcher .glyphicon {
    font-size: 26px;
}

.cw-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--cw-danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 0 0 3px #fff;
    display: none;
}

.cw-badge.cw-show {
    display: block;
    animation: cw-pulse 1.8s ease-in-out infinite;
}

@keyframes cw-pulse {
    0%, 100% { box-shadow: 0 0 0 3px #fff, 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50%      { box-shadow: 0 0 0 3px #fff, 0 0 0 7px rgba(239, 68, 68, 0); }
}

/* ---------- Painel ---------- */
.cw-panel {
    position: fixed;
    right: 24px;
    bottom: 96px;
    width: 700px;
    height: 540px;
    max-height: calc(100vh - 120px);
    background: var(--cw-surface);
    border-radius: 16px;
    box-shadow: var(--cw-shadow);
    z-index: 10500;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: "Segoe UI", system-ui, Arial, sans-serif;
    color: var(--cw-ink);
}

.cw-panel.cw-open {
    display: flex;
    transform-origin: bottom right;
    animation: cw-pop 0.2s cubic-bezier(.34,1.4,.64,1);
}

@keyframes cw-pop {
    from { opacity: 0; transform: translateY(14px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Cabeçalho do painel ---------- */
.cw-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--cw-brand-grad);
    color: #fff;
}

.cw-header-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.cw-header-title .glyphicon {
    margin-right: 8px;
    opacity: 0.95;
}

.cw-online {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.18);
    padding: 3px 10px;
    border-radius: 20px;
}

.cw-online::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #b9f6ca;
    box-shadow: 0 0 0 2px rgba(185, 246, 202, 0.35);
}

.cw-close {
    margin-left: auto;
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease;
}

.cw-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

/* ---------- Corpo ---------- */
.cw-body {
    flex: 1 1 auto;
    display: flex;
    min-height: 0;
}

/* ---------- Coluna de usuários ---------- */
.cw-users {
    flex: 0 0 264px;
    /* Largura estática: nomes longos NÃO podem esticar a coluna e espremer o chat.
       min/max + overflow travam a largura; o nome é cortado com reticências. */
    width: 264px;
    min-width: 264px;
    max-width: 264px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--cw-line);
    background: var(--cw-surface);
    min-height: 0;
    overflow: hidden;
}

.cw-search {
    flex: 0 0 auto;
    padding: 12px;
    border-bottom: 1px solid var(--cw-line);
    position: relative;
}

.cw-search::before {
    content: "\e003"; /* glyphicon search */
    font-family: "Glyphicons Halflings";
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: var(--cw-muted);
    pointer-events: none;
}

.cw-search input {
    width: 100%;
    border: 1px solid var(--cw-line);
    background: var(--cw-surface-2);
    border-radius: 22px;
    padding: 8px 14px 8px 34px;
    font-size: 13px;
    color: var(--cw-ink);
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.cw-search input:focus {
    border-color: var(--cw-brand-2);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 94, 104, 0.12);
}

.cw-users-list {
    flex: 1 1 auto;
    list-style: none;
    margin: 0;
    padding: 6px 0;
    overflow-y: auto;
}

.cw-users-list::-webkit-scrollbar,
.cw-messages::-webkit-scrollbar { width: 8px; }
.cw-users-list::-webkit-scrollbar-thumb,
.cw-messages::-webkit-scrollbar-thumb { background: rgba(31,36,48,0.14); border-radius: 4px; }

.cw-group {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    color: var(--cw-muted);
    padding: 10px 16px 4px;
}

.cw-user {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    margin: 1px 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.12s ease;
}

.cw-user:hover {
    background: var(--cw-surface-2);
}

.cw-user.cw-selected {
    background: linear-gradient(135deg, rgba(0,68,76,0.12), rgba(0,94,104,0.16));
}

/* Avatar + status */
.cw-avatar-wrap {
    position: relative;
    flex: 0 0 40px;
    margin-right: 10px;
}

.cw-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    background: var(--cw-brand-grad);
    object-fit: cover; /* quando o avatar é <img> (foto real), recorta bonito */
}

.cw-status-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #cfd4dd;
}

.cw-status-dot.cw-dot-on { background: var(--cw-online); }
.cw-status-dot.cw-dot-off { background: #cfd4dd; }

.cw-user-info {
    flex: 1 1 auto;
    min-width: 0;
}

.cw-user-name {
    /* Nome pode quebrar em até 2 linhas (sem cortar com "..."); fonte um pouco menor */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--cw-ink);
    overflow: hidden;
    white-space: normal;
    line-height: 1.25;
    word-break: break-word;
}

.cw-user-sub {
    display: block;
    font-size: 11px;
    color: var(--cw-muted);
}

.cw-unread {
    flex: 0 0 auto;
    margin-left: 8px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--cw-brand-grad);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

/* ---------- Coluna da conversa ---------- */
.cw-chat {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--cw-surface-2);
}

.cw-chat-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid var(--cw-line);
}

.cw-back {
    display: none;
    background: transparent;
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--cw-brand-1);
    padding: 0 4px;
}

.cw-chat-avatar {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    text-transform: uppercase;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    background: var(--cw-brand-grad);
}

.cw-chat-headinfo {
    flex: 1 1 auto;
    min-width: 0;
}

.cw-chat-title {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--cw-ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cw-chat-status {
    display: block;
    font-size: 11px;
    color: var(--cw-muted);
}

.cw-chat-status.cw-on { color: var(--cw-online); }

.cw-dias {
    flex: 0 0 auto;
    border: 1px solid var(--cw-line);
    border-radius: 8px;
    font-size: 11px;
    padding: 4px 6px;
    color: var(--cw-muted);
    background: #fff;
    outline: none;
    cursor: pointer;
}

/* ---------- Mensagens ---------- */
.cw-messages {
    flex: 1 1 auto;
    padding: 16px;
    overflow-y: auto;
    min-height: 0;
}

.cw-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--cw-muted);
    font-size: 13px;
    text-align: center;
    gap: 10px;
}

.cw-empty .glyphicon {
    font-size: 34px;
    opacity: 0.35;
}

/* Separador de data */
.cw-daysep {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0 14px;
}

.cw-daysep span {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--cw-muted);
    background: rgba(31, 36, 48, 0.06);
    padding: 3px 12px;
    border-radius: 12px;
}

/* Bolhas */
.cw-msg {
    display: flex;
    margin-bottom: 8px;
}

.cw-msg.cw-mine { justify-content: flex-end; }

.cw-bubble {
    max-width: 76%;
    padding: 9px 13px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.cw-msg.cw-theirs .cw-bubble {
    background: #fff;
    color: var(--cw-ink);
    border: 1px solid var(--cw-line);
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(31, 36, 48, 0.05);
}

.cw-msg.cw-mine .cw-bubble {
    background: var(--cw-brand-grad);
    color: #fff;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 6px rgba(0, 68, 76, 0.30);
}

.cw-bubble a {
    color: inherit;
    text-decoration: underline;
    font-weight: 600;
}

.cw-time {
    display: block;
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
}

/* Botão de excluir a própria mensagem — aparece ao passar o mouse; backend limita a 2 dias */
.cw-bubble {
    position: relative;
}

.cw-del {
    position: absolute;
    left: -24px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--cw-danger);
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(31, 36, 48, 0.25);
}

.cw-msg.cw-mine:hover .cw-del {
    display: inline-flex;
}

.cw-del:hover {
    filter: brightness(1.08);
}

/* ---------- Rodapé ---------- */
.cw-footer {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid var(--cw-line);
}

.cw-footer textarea {
    flex: 1 1 auto;
    resize: none;
    height: 42px;
    max-height: 110px;
    border: 1px solid var(--cw-line);
    background: var(--cw-surface-2);
    border-radius: 22px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--cw-ink);
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.cw-footer textarea:focus {
    border-color: var(--cw-brand-2);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 94, 104, 0.12);
}

.cw-actions {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cw-selected-file {
    max-width: 110px;
    font-size: 10.5px;
    color: var(--cw-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cw-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    transition: transform 0.12s ease, filter 0.12s ease, background 0.12s ease;
}

.cw-btn:hover { transform: translateY(-1px); }
.cw-btn:active { transform: scale(0.94); }

.cw-btn-send {
    background: var(--cw-brand-grad);
    box-shadow: 0 3px 8px rgba(0, 68, 76, 0.35);
}

.cw-btn-file {
    background: #eef0f5;
    color: var(--cw-brand-1);
}

.cw-btn-file:hover { background: #d6ecef; }

.cw-btn-remove {
    background: #fdecec;
    color: var(--cw-danger);
}

.cw-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ---------- Responsivo (mobile) ---------- */
@media (max-width: 767px) {
    .cw-panel {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    .cw-body.cw-show-chat .cw-users { display: none; }
    .cw-body:not(.cw-show-chat) .cw-chat { display: none; }

    .cw-users { flex-basis: 100%; }
    .cw-back { display: inline-block; }
}
