/* =============================================================================
   Sonhos ADMIN — CSS base do shell (portado do sonhos-pwa)
   Tailwind (CDN) cobre utilitários; aqui: vars de tema + layout fixo
   (sidebar recolhível desktop + barra inferior mobile + header) + chat.
   ============================================================================ */

:root {
    --bg:           #eef1f6;
    --bg-card:      #ffffff;
    --bg-elev:      #f3f5fa;
    --border:       #e3e7f0;
    --text:         #1f2430;
    --text-muted:   #6b7280;
    --primary:      #6d5df0;
    --primary-hover:#5b4bd9;
    --header-h: 56px;
    --nav-h: 64px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

.marca { font-family: 'Bebas Neue', sans-serif; letter-spacing: 1px; color: var(--primary); line-height: 1; }

/* ----- Layout app (header fixo + scroll + barra inferior) ----- */
body.app { padding-top: var(--header-h); padding-bottom: var(--nav-h); min-height: 100vh; }

/* ----- Sidebar desktop (>=768px) ----- */
.app-sidebar { display: none; }

@media (min-width: 768px) {
    body.app { padding-top: 0; padding-bottom: 0; padding-left: 260px; transition: padding-left .2s ease; }
    body.app.sidebar-recolhida { padding-left: 80px; }
    .app-header { display: none; }

    .app-sidebar {
        display: flex; flex-direction: column;
        position: fixed; top: 0; left: 0; bottom: 0;
        width: 260px;
        background: var(--bg-card);
        border-right: 1px solid var(--border);
        z-index: 50; overflow: hidden;
        transition: width .2s ease;
    }
    body.sidebar-recolhida .app-sidebar { width: 80px; }

    .app-sidebar .sidebar-logo {
        height: var(--header-h);
        display: flex; align-items: center; justify-content: flex-start;
        gap: 10px; padding: 0 14px;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0; overflow: hidden;
    }
    .app-sidebar .sidebar-toggle {
        background: transparent; border: 0; color: var(--text);
        width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
        display: inline-flex; align-items: center; justify-content: center;
        flex-shrink: 0; font-size: 18px; transition: background .15s, color .15s;
    }
    .app-sidebar .sidebar-toggle:hover { background: var(--bg-elev); color: var(--primary); }
    .app-sidebar .sidebar-logo .marca { font-size: 26px; white-space: nowrap; transition: opacity .2s ease, width .2s ease; }
    body.sidebar-recolhida .app-sidebar .sidebar-logo { justify-content: center; padding: 0; gap: 0; }
    body.sidebar-recolhida .app-sidebar .sidebar-logo .marca { width: 0; opacity: 0; }

    .app-sidebar nav { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
    .app-sidebar nav a, .app-sidebar .sidebar-sair {
        display: flex; align-items: center; gap: 12px;
        padding: 12px; border-radius: 8px;
        color: var(--text-muted); text-decoration: none;
        font-size: 16px; font-weight: 600; white-space: nowrap;
        transition: background .15s, color .15s;
    }
    .app-sidebar nav a i, .app-sidebar .sidebar-sair i { font-size: 22px; width: 22px; text-align: center; flex-shrink: 0; }
    .app-sidebar nav a:hover { background: var(--bg-elev); color: var(--text); }
    .app-sidebar nav a.ativo { background: var(--primary); color: #fff; }
    .app-sidebar .sidebar-sair { margin: 10px; border-top: 1px solid var(--border); border-radius: 8px; }
    .app-sidebar .sidebar-sair:hover { background: #fdecec; color: #dc2626; }
    body.sidebar-recolhida .app-sidebar nav a,
    body.sidebar-recolhida .app-sidebar .sidebar-sair { justify-content: center; padding: 12px 0; }
    body.sidebar-recolhida .app-sidebar nav a .label,
    body.sidebar-recolhida .app-sidebar .sidebar-sair .label { display: none; }
}

/* ----- Header fixo (mobile) ----- */
.app-header {
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--header-h);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 12px; gap: 8px;
    z-index: 40;
}
.app-header .marca { font-size: 24px; flex: 1; }

.app-main { padding: 16px; max-width: 900px; margin: 0 auto; }

/* ----- Barra inferior (mobile) ----- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: var(--nav-h);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex; justify-content: space-around; align-items: stretch;
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-muted); text-decoration: none; font-size: 11px; gap: 2px;
    -webkit-tap-highlight-color: transparent;
}
.bottom-nav a i { font-size: 21px; line-height: 1; }
.bottom-nav a.ativo { color: var(--primary); }

/* ===== Chat (estética WhatsApp) ===== */
.chat-fixed {
    position: fixed; top: var(--header-h); left: 0; right: 0; bottom: var(--nav-h);
    display: flex; overflow: hidden; background: #efe7dd;
}
@media (min-width: 768px) {
    .chat-fixed { top: 0; bottom: 0; left: 260px; transition: left .2s ease; }
    body.sidebar-recolhida .chat-fixed { left: 80px; }
    /* Desktop: mostra os dois painéis lado a lado (lista + conversa). */
    #chat-lista { max-width: 360px; border-right: 1px solid var(--border); }
    #chat-conversa.oculto { display: flex !important; }
    #chat-conversa.oculto .conversa-header,
    #chat-conversa.oculto .conversa-msgs,
    #chat-conversa.oculto .conversa-input { visibility: hidden; }
    .voltar-btn { display: none !important; }
}
.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-pane.oculto { display: none; }

/* Lista de conversas */
.lista-topo { background: var(--bg-card); padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text); }
.lista-topo > span { font-weight: 700; font-size: 18px; display: block; margin-bottom: 8px; }
.lista-busca { display: flex; align-items: center; gap: 8px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 20px; padding: 7px 12px; }
.lista-busca i { color: var(--text-muted); font-size: 13px; }
.lista-busca input { flex: 1; border: 0; background: transparent; outline: none; font-size: 14px; color: var(--text); }
.lista-itens { flex: 1; overflow-y: auto; background: var(--bg-card); }
.lista-loading { padding: 20px; text-align: center; color: var(--text-muted); }
.lista-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); }
.lista-item:hover, .lista-item.ativo { background: var(--bg-elev); }
.lista-item .avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--bg-elev); }
.lista-item .li-corpo { flex: 1; min-width: 0; }
.lista-item .li-nome { font-weight: 600; color: var(--text); display: flex; justify-content: space-between; gap: 8px; }
.lista-item .li-nome > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista-item .li-guia { font-size: 12px; color: var(--primary); font-weight: 600; }
.lista-item .li-hora { font-size: 11px; color: var(--text-muted); font-weight: 400; flex-shrink: 0; }
.lista-item .li-previa { font-size: 13px; color: var(--text-muted); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.lista-item .li-previa > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-badge { background: #25d366; color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; flex-shrink: 0; }

/* Conversa */
.conversa-header { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg-card); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.voltar-btn { background: transparent; border: 0; color: var(--text); font-size: 18px; cursor: pointer; padding: 4px 8px; }
.conversa-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--bg-elev); }
.conversa-nome { font-weight: 600; color: var(--text); }
.conversa-status { font-size: 12px; color: var(--text-muted); }
.conversa-msgs { flex: 1; overflow-y: auto; padding: 14px 10px; display: flex; flex-direction: column; gap: 4px; }
.sep-dia { align-self: center; background: rgba(255,255,255,.9); color: #5b6b73; font-size: 12px; padding: 4px 10px; border-radius: 8px; margin: 8px 0; }

/* Linha da mensagem = bolha + botão apagar (só admin) */
.msg-linha { display: flex; align-items: center; gap: 6px; max-width: 85%; }
.msg-linha.cliente { align-self: flex-end; flex-direction: row-reverse; }
.msg-linha.especialista { align-self: flex-start; }

.bolha { max-width: 100%; padding: 6px 9px 18px; border-radius: 8px; position: relative; font-size: 14.5px; line-height: 1.35; color: #111b21; box-shadow: 0 1px .5px rgba(0,0,0,.13); overflow-wrap: anywhere; }
.bolha .hora { position: absolute; right: 8px; bottom: 4px; font-size: 10px; color: #667781; }
.msg-linha.cliente .bolha { background: #d9fdd3; }
.msg-linha.especialista .bolha { background: #fff; }
.bolha.apagada { opacity: .55; }
.bolha.apagada .bolha-texto { text-decoration: line-through; }
.bolha .apagada-tag { display: inline-block; font-size: 10px; color: #b91c1c; font-weight: 700; margin-right: 6px; text-transform: uppercase; letter-spacing: .3px; }
.bolha-audio { display: flex; align-items: center; gap: 8px; }
.audio-icone { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 12px; }
.audio-dur { font-size: 11px; color: #667781; }
.audio-legenda { font-size: 12.5px; color: #3b4a54; margin-top: 6px; border-top: 1px solid rgba(0,0,0,.06); padding-top: 4px; }

/* Botão apagar mensagem */
.apagar-btn { background: transparent; border: 0; color: #94a3b8; cursor: pointer; padding: 4px; font-size: 13px; opacity: .35; transition: opacity .15s, color .15s; flex-shrink: 0; }
.msg-linha:hover .apagar-btn { opacity: 1; }
.apagar-btn:hover { color: #dc2626; }
@media (hover: none) { .apagar-btn { opacity: .6; } }

/* Input (escrever como o guia) */
.conversa-input { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg-card); border-top: 1px solid var(--border); flex-shrink: 0; }
.conversa-input input { flex: 1; border: 1px solid var(--border); background: #fff; border-radius: 20px; padding: 10px 14px; font-size: 15px; outline: none; color: #111b21; }
.enviar-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: #fff; border: 0; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 16px; }
.enviar-btn:disabled { opacity: .5; cursor: default; }

.conversa-vazia { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 14px; padding: 20px; text-align: center; }

/* Scrollbar discreta (desktop) */
.conversa-msgs, .lista-itens { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,.22) transparent; }
.conversa-msgs::-webkit-scrollbar, .lista-itens::-webkit-scrollbar { width: 8px; }
.conversa-msgs::-webkit-scrollbar-track, .lista-itens::-webkit-scrollbar-track { background: transparent; }
.conversa-msgs::-webkit-scrollbar-thumb, .lista-itens::-webkit-scrollbar-thumb { background: rgba(0,0,0,.18); border-radius: 4px; }

/* ===== Modal de confirmação (apagar) ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 120; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: 100%; max-width: 360px; text-align: center; }
.modal-card h3 { margin: 0 0 8px; font-size: 17px; color: var(--text); }
.modal-card p { margin: 0 0 18px; font-size: 14px; color: var(--text-muted); }
.modal-acoes { display: flex; gap: 10px; }
.modal-acoes button { flex: 1; padding: 11px; border-radius: 10px; border: 0; font-weight: 700; font-size: 14px; cursor: pointer; }
.modal-cancelar { background: var(--bg-elev); color: var(--text); }
.modal-confirmar { background: #dc2626; color: #fff; }
