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

: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; } /* desktop: sem header; sidebar já tem a marca */

    .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 {
        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 svg { width: 22px; height: 22px; stroke-width: 1.8; flex-shrink: 0; }
    .app-sidebar nav a 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; }
    body.sidebar-recolhida .app-sidebar nav a { justify-content: center; padding: 12px 0; }
    body.sidebar-recolhida .app-sidebar nav a .label { display: none; }
}

/* ----- Header fixo ----- */
.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; }

.icon-btn {
    background: transparent; border: 0; color: var(--text);
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--bg-elev); }

.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 svg { width: 24px; height: 24px; stroke-width: 1.8; }
.bottom-nav a i { font-size: 22px; 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; }
}
.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-pane.oculto { display: none; }

/* Lista de guias */
.lista-topo { background: var(--bg-card); padding: 14px 16px; font-weight: 700; font-size: 18px; border-bottom: 1px solid var(--border); 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 { 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-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; }
.bolha { max-width: 78%; 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; }
.bolha.cliente { align-self: flex-end; background: #d9fdd3; }
.bolha.especialista { align-self: flex-start; background: #fff; }
.bolha-audio { display: flex; align-items: center; gap: 8px; }
.audio-play { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; border: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.audio-wave { flex: 1; min-width: 80px; height: 3px; background: #c9d2d6; border-radius: 2px; }
.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; }

/* Digitando */
.digitando { align-self: flex-start; background: #fff; border-radius: 8px; padding: 11px 13px; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.digitando span { display: inline-block; width: 7px; height: 7px; margin: 0 2px; background: #9aa6ad; border-radius: 50%; animation: dig 1.2s infinite; }
.digitando span:nth-child(2) { animation-delay: .2s; }
.digitando span:nth-child(3) { animation-delay: .4s; }
@keyframes dig { 0%,60%,100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* Input */
.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: 0; background: #fff; border: 1px solid var(--border); 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.oculto { display: none; }
.aviso-espera { align-self: center; background: #fff4d6; color: #7a5d00; font-size: 12.5px; padding: 6px 12px; border-radius: 8px; margin: 8px 0; max-width: 85%; text-align: center; box-shadow: 0 1px .5px rgba(0,0,0,.1); }

/* Scrollbar discreta (desktop) na lista e na conversa */
.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; }
.conversa-msgs::-webkit-scrollbar-thumb:hover, .lista-itens::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.3); }

/* Filtro de período — botão ativo (helper global _filtro_periodo) */
.btn-periodo.ativo { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Mic gravando (chat) */
.enviar-btn.gravando { background: #e53935 !important; color: #fff; animation: pulseRec 1s infinite; }
@keyframes pulseRec { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
