/* ================================================= */
/* ===                 LAYOUT.CSS                === */
/* ================================================= */

.main-container { display: flex; position: relative; }
.container-fluid { padding: 20px; }
@media (max-width: 360px) { .container-fluid { padding-left: 10px; padding-right: 10px; } }

/* --- Sidebar --- */
.sidebar {
    width: 250px; background-color: var(--secondary-color); color: var(--text-light-color);
    height: 100vh; position: fixed; top: 0; left: 0; z-index: 1100;
    transform: translateX(-100%); transition: transform 0.3s ease-in-out, background-color 0.3s;
}
.sidebar.visible { transform: translateX(0); }

.sidebar-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 15px; border-bottom: 1px solid #4a627a;
}
.sidebar-header h3 { margin: 0; font-size: 1.5em; }

.close-sidebar-btn { background: none; border: none; color: var(--text-light-color); font-size: 2em; cursor: pointer; }
.sidebar-menu { list-style: none; margin-top: 20px; }
.sidebar-footer { margin-top: 0 !important; padding-top: 8px; border-top: 1px solid rgba(255,255,255,0.08); }

.sidebar-btn {
    display: flex; align-items: center; gap: 15px; background: none; border: none;
    color: var(--text-light-color); padding: 12px 15px; width: 100%; text-align: left;
    font-size: 0.95em; cursor: pointer; border-radius: 5px; transition: background-color 0.2s;
}
.sidebar-btn:hover, .sidebar-btn.active { background-color: #4a627a; }
.sidebar-btn i { width: 20px; }

/* --- Sidebar agrupada --- */
.sidebar-nav { padding: 8px 6px; list-style: none; }
.sidebar-group { margin-bottom: 2px; }
.sidebar-group-header {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; background: none; border: none;
    color: rgba(255,255,255,0.5);
    font-size: 0.7em; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.08em; padding: 14px 14px 6px; cursor: pointer;
    transition: color 0.2s;
}
.sidebar-group-header:hover { color: rgba(255,255,255,0.85); }
.sidebar-group-header i { font-size: 0.85em; transition: transform 0.2s; opacity: 0.7; }
.sidebar-group.collapsed .sidebar-group-header i { transform: rotate(-90deg); }
.sidebar-group-items {
    list-style: none; padding: 0; margin: 0;
    max-height: 800px; overflow: hidden;
    transition: max-height 0.25s ease;
}
.sidebar-group.collapsed .sidebar-group-items { max-height: 0; }

/* Badge de mensagens não lidas no botão Chat WhatsApp da sidebar */
.wa-sidebar-badge {
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 10px;
    padding: 0 6px;
    margin-left: auto;
    animation: waSidebarPulse 2.5s ease-in-out infinite;
}
@keyframes waSidebarPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* --- Content Wrapper --- */
.content { width: 100%; transition: margin-left 0.3s ease-in-out; }
@media (min-width: 992px) {
    .sidebar { transform: translateX(0); }
    .content { margin-left: 250px; }
    .mobile-menu-btn, .close-sidebar-btn { display: none; }
    .main-header { justify-content: center; }
}

/* --- Main Header --- */
.main-header {
    display: flex; align-items: center; background-color: var(--header-bg-color);
    padding: 10px 20px; box-shadow: 0 2px 4px var(--box-shadow-color);
    transition: background-color 0.3s;
}
.main-header h1 { font-size: 1.5em; color: var(--primary-color); }
@media (max-width: 768px) { .main-header h1 { font-size: 1.2em; } }

.mobile-menu-btn {
    background: none; border: none; font-size: 1.5em; color: var(--text-color);
    cursor: pointer; margin-right: 15px;
}

/* --- Theme Toggle Button --- */
.theme-toggle-btn {
    background: none; border: none; color: var(--text-light-color);
    width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
    font-size: 1.2em; display: flex; justify-content: center; align-items: center;
    transition: color 0.3s, background-color 0.3s, transform 0.3s; margin-right: 10px;
}
.theme-toggle-btn:hover { background-color: rgba(255, 255, 255, 0.2); transform: scale(1.1); }

/* --- Navegação entre Clientes (Header Modal) --- */
.nav-btn {
    background: none; border: 1px solid var(--input-border-color); color: var(--text-color);
    width: 40px; height: 40px; border-radius: 50%; font-size: 1em; cursor: pointer;
    transition: background-color 0.3s, color 0.3s;
}
.nav-btn:hover:not(:disabled) {
    background-color: var(--primary-color); color: var(--text-light-color); border-color: var(--primary-color);
}
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.modal-header-nav {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 25px; margin-top: 10px; text-align: center;
}
.modal-header-nav h2 { margin: 0; flex-grow: 1; }

@media (max-width: 768px) {
    .modal-header-nav { display: grid; justify-items: center; gap: 1px; }
    .modal-header-nav h2 { grid-row: 1; grid-column: 1 / 3; flex-grow: 0; }
    #prev-client-btn { grid-row: 2; grid-column: 1; }
    #next-client-btn { grid-row: 2; grid-column: 2; }
}

/* --- Bottom-tabs mobile --- */
.mobile-bottom-tabs {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1090;
    display: none; /* só aparece em mobile */
    justify-content: space-around; align-items: stretch;
    background: var(--header-bg-color, #fff);
    border-top: 1px solid var(--input-border-color);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
}
.mbt-btn {
    flex: 1; background: none; border: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 6px 4px;
    color: var(--text-color); opacity: 0.62;
    font-size: 0.7em; cursor: pointer;
    transition: opacity 0.15s, color 0.15s;
    min-height: 52px;
}
.mbt-btn i { font-size: 1.25em; }
.mbt-btn:hover { opacity: 0.85; }
.mbt-btn.active { opacity: 1; color: var(--primary-color); }
.mbt-badge {
    position: absolute; top: 4px; right: calc(50% - 22px);
    background: #e74c3c; color: #fff;
    font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px; line-height: 18px;
    border-radius: 9px; padding: 0 5px; text-align: center;
}
@media (max-width: 991px) {
    .mobile-bottom-tabs { display: flex; }
    /* Reserva espaço pra não cobrir conteúdo de fluxo normal */
    .content { padding-bottom: 70px; }
    /* Chat WhatsApp tem altura fixa baseada em viewport — usa apenas o desconto interno,
       sem o padding-bottom (que somaria ao desconto e geraria gap visual). */
    #whatsapp-chat-content { padding-bottom: 0 !important; }
    #whatsapp-chat-content > .container-fluid { height: calc(100vh - 50px - 60px) !important; }
    .wa-chat-container { height: 100% !important; }
    /* Scroll-to-top: sobe pra não ficar atrás da barra */
    #scrollToTopBtn { bottom: 80px !important; }
}

/* Quando uma conversa do chat é aberta no mobile (≤768px), .wa-chat-container.chat-open
   vira position:fixed bottom:0 e cobre a viewport inteira (whatsapp-chat.css:2189) —
   ignorando o cálculo de altura acima. Essa regra recua o bottom em 60px pra liberar
   espaço da bottom-tabs e o input não fica atrás dela. */
@media (max-width: 768px) {
    .wa-chat-container.chat-open {
        bottom: 60px !important;
        height: calc(100vh - 60px) !important;
        height: calc(100dvh - 60px) !important;
    }
    .wa-chat-container.chat-open .wa-quick-toolbar {
        bottom: 60px !important;
    }
}

/* --- Scroll To Top --- */
#scrollToTopBtn {
  display: none; position: fixed; bottom: 20px; right: 30px; z-index: 1080;
  border: none; outline: none; background-color: var(--primary-color); color: white;
  cursor: pointer; border-radius: 50%; font-size: 1.2rem; width: 50px; height: 50px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.2); display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity 0.4s, visibility 0.4s, background-color 0.3s;
}
#scrollToTopBtn.show { opacity: 1; visibility: visible; }
#scrollToTopBtn:hover { background-color: #2980b9; }