/* static/custom.css */

/* Chatbot — item de conversa na lista split */
.conversa-item.active {
    background-color: #e8f0fe !important;
    border-left: 3px solid var(--bs-primary);
}

/* Chatbot — botões de filtro por status */
.filtro-btn {
    border-bottom: 2px solid transparent;
    color: #6c757d;
    border-radius: 0;
    transition: color .15s, border-color .15s;
}
.filtro-btn:hover {
    color: var(--bs-primary);
    background: none;
}
.filtro-btn.ativo {
    color: var(--bs-primary) !important;
    border-bottom: 2px solid var(--bs-primary) !important;
    font-weight: 600;
}

/* Chatbot — handle de redimensionamento do painel esquerdo */
#resize-handle {
    width: 5px;
    flex-shrink: 0;
    cursor: col-resize;
    background: transparent;
    border-left: 1px solid #dee2e6;
    margin: 8px 2px;
    border-radius: 2px;
    transition: background .15s;
}
#resize-handle:hover,
#resize-handle.dragging {
    background: var(--bs-primary);
    opacity: .4;
}

/* Configurações Gerais */
body { font-family: 'Inter', sans-serif; background-color: #f4f6f8; }

/* Cards de Estatísticas */
.stat-card { border: none; border-radius: 12px; min-height: 120px; transition: transform 0.2s, box-shadow 0.2s; overflow: hidden; }
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important; }

/* Gradientes */
.bg-gradient-blue { background: linear-gradient(135deg, #0d6efd 0%, #0a58ca 100%); color: white; }
.bg-gradient-green { background: linear-gradient(135deg, #198754 0%, #157347 100%); color: white; }
.bg-gradient-yellow { background: linear-gradient(135deg, #ffc107 0%, #ffca2c 100%); color: #212529; }

/* Conteúdo dos Cards */
.card-body-custom { display: flex; align-items: center; padding: 1.5rem; }
.card-icon { font-size: 3rem; margin-right: 1.5rem; opacity: 0.8; }
.card-label { font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.9; }
.card-value { font-size: 2.5rem; font-weight: 700; line-height: 1; }

/* Listas Flutuantes (Autocompletar) */
#resultados-busca { max-height: 250px; overflow-y: auto; cursor: pointer; box-shadow: 0 10px 25px rgba(0,0,0,0.15); border-radius: 0 0 8px 8px; }

/* Loading do HTMX */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }

/* ======== HTMX: Elimina piscadas e tremidos ======== */

/* Fade-in suave para todo conteúdo inserido por HTMX */
.htmx-added {
    animation: htmxFadeIn 180ms ease-in forwards;
}
@keyframes htmxFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Feedback visual em botões durante submit — evita duplo clique e confirma ação */
button.htmx-request,
.btn.htmx-request {
    opacity: 0.65;
    pointer-events: none;
    transition: opacity 80ms ease;
}

/* Garante que containers HTMX não colapsam enquanto carregam */
#pacientes-list,
#medicamentos-list,
#horarios-list,
#horarios-content,
#chatbot-conversas,
#chatbot-conversa-detail,
#relatorios-content,
#campanha-content {
    min-height: 80px;
}

/* Menu de Abas (Pills) */
.nav-pills .nav-link { color: #6c757d; transition: all 0.3s ease; border-radius: 8px; margin: 0 2px; }
.nav-pills .nav-link:hover { background-color: rgba(13, 110, 253, 0.1); color: #0d6efd; }
.nav-pills .nav-link.active { background-color: #0d6efd !important; color: white !important; box-shadow: 0 4px 6px rgba(13, 110, 253, 0.3); }

/* Estabilização de Layout para Tabelas HTMX */
.table-responsive { transition: all 0.3s ease; }

/* ======================================================================
   DARK MODE — CSS Custom Properties
   ====================================================================== */

:root {
    --fs-bg: #f4f6f8;
    --fs-bg-card: #ffffff;
    --fs-bg-input: #ffffff;
    --fs-text: #212529;
    --fs-text-muted: #6c757d;
    --fs-border: #dee2e6;
    --fs-shadow: rgba(0,0,0,0.08);
    --fs-table-stripe: rgba(0,0,0,0.02);
    --fs-hover: rgba(0,0,0,0.04);
}

[data-bs-theme="dark"] {
    --fs-bg: #1a1d21;
    --fs-bg-card: #212529;
    --fs-bg-input: #2b3035;
    --fs-text: #e9ecef;
    --fs-text-muted: #adb5bd;
    --fs-border: #495057;
    --fs-shadow: rgba(0,0,0,0.3);
    --fs-table-stripe: rgba(255,255,255,0.03);
    --fs-hover: rgba(255,255,255,0.06);
}

[data-bs-theme="dark"] body,
[data-bs-theme="dark"] .bg-light {
    background-color: var(--fs-bg) !important;
    color: var(--fs-text);
}

[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .dropdown-menu,
[data-bs-theme="dark"] .offcanvas {
    background-color: var(--fs-bg-card) !important;
    color: var(--fs-text);
    border-color: var(--fs-border) !important;
}

[data-bs-theme="dark"] .table {
    --bs-table-bg: var(--fs-bg-card);
    --bs-table-striped-bg: var(--fs-table-stripe);
    --bs-table-hover-bg: var(--fs-hover);
    color: var(--fs-text);
    border-color: var(--fs-border);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .input-group-text {
    background-color: var(--fs-bg-input) !important;
    color: var(--fs-text) !important;
    border-color: var(--fs-border) !important;
}

[data-bs-theme="dark"] .form-label {
    color: var(--fs-text-muted) !important;
}

[data-bs-theme="dark"] .text-muted {
    color: var(--fs-text-muted) !important;
}

[data-bs-theme="dark"] .text-dark {
    color: var(--fs-text) !important;
}

[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-bottom,
[data-bs-theme="dark"] .border-top {
    border-color: var(--fs-border) !important;
}

[data-bs-theme="dark"] .list-group-item {
    background-color: var(--fs-bg-card);
    color: var(--fs-text);
    border-color: var(--fs-border);
}

[data-bs-theme="dark"] .dropdown-item {
    color: var(--fs-text);
}
[data-bs-theme="dark"] .dropdown-item:hover {
    background-color: var(--fs-hover);
}

[data-bs-theme="dark"] .nav-tabs .nav-link.active {
    background-color: var(--fs-bg-card) !important;
    color: #6ea8fe !important;
    border-bottom-color: #6ea8fe !important;
}
[data-bs-theme="dark"] .nav-tabs .nav-link {
    color: var(--fs-text-muted);
}

[data-bs-theme="dark"] .alert-info {
    background-color: rgba(13, 202, 240, 0.15);
    color: #6edff6;
    border-color: rgba(13, 202, 240, 0.3);
}
[data-bs-theme="dark"] .alert-warning {
    background-color: rgba(255, 193, 7, 0.15);
    color: #ffda6a;
    border-color: rgba(255, 193, 7, 0.3);
}
[data-bs-theme="dark"] .alert-danger {
    background-color: rgba(220, 53, 69, 0.15);
    color: #ea868f;
    border-color: rgba(220, 53, 69, 0.3);
}
[data-bs-theme="dark"] .alert-success {
    background-color: rgba(25, 135, 84, 0.15);
    color: #75b798;
    border-color: rgba(25, 135, 84, 0.3);
}

/* Botão toggle dark mode */
.theme-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.25);
    color: rgba(255,255,255,0.75);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}
.theme-toggle:hover {
    border-color: rgba(255,255,255,0.5);
    color: #fff;
}

/* Stat cards mantêm gradiente no dark */
[data-bs-theme="dark"] .stat-card:not([class*="bg-gradient"]) {
    background-color: var(--fs-bg-card) !important;
}

/* ======================================================================
   BARRA DE PROGRESSO HTMX (topo da página)
   ====================================================================== */

#htmx-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #0d6efd, #6ea8fe);
    z-index: 9999;
    transition: width 0.3s ease;
    pointer-events: none;
}
#htmx-progress.active {
    width: 70%;
    transition: width 1.5s ease;
}
#htmx-progress.done {
    width: 100%;
    transition: width 0.2s ease;
    opacity: 0;
    transition: width 0.2s ease, opacity 0.4s ease 0.2s;
}

/* ======================================================================
   ANIMAÇÕES DE TRANSIÇÃO
   ====================================================================== */

/* Slide-up suave para toasts */
.toast {
    animation: toastSlideUp 0.3s ease-out;
}
@keyframes toastSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

/* Hover suave em linhas de tabela */
.table-hover tbody tr {
    transition: background-color 0.15s ease;
}

/* Botões com transição suave */
.btn {
    transition: all 0.15s ease;
}

/* Fade para conteúdo HTMX swappado */
.htmx-swapping {
    opacity: 0.5;
    transition: opacity 0.15s ease;
}

/* ======================================================================
   EMPTY STATES
   ====================================================================== */

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--fs-text-muted);
}
.empty-state-icon {
    font-size: 3.5rem;
    opacity: 0.3;
    margin-bottom: 1rem;
}
.empty-state-title {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--fs-text);
    opacity: 0.7;
}
.empty-state-text {
    font-size: 0.9rem;
    max-width: 400px;
    margin: 0 auto;
}

/* ======================================================================
   SKELETON LOADER (loading placeholder)
   ====================================================================== */

.skeleton {
    background: linear-gradient(90deg, #e9ecef 25%, #f8f9fa 50%, #e9ecef 75%);
    background-size: 200% 100%;
    animation: skeletonPulse 1.5s ease-in-out infinite;
    border-radius: 4px;
}
[data-bs-theme="dark"] .skeleton {
    background: linear-gradient(90deg, #2b3035 25%, #343a40 50%, #2b3035 75%);
    background-size: 200% 100%;
}
@keyframes skeletonPulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 80%;
}
.skeleton-title {
    height: 20px;
    margin-bottom: 12px;
    width: 50%;
}
.skeleton-card {
    height: 120px;
    border-radius: 12px;
}

/* ======================================================================
   ACESSIBILIDADE
   ====================================================================== */

/* Skip link (pular para conteúdo) */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: #0d6efd;
    color: #fff;
    padding: 8px 16px;
    z-index: 10000;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 8px 0;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 0;
    color: #fff;
}

/* Focus ring visível para navegação por teclado */
:focus-visible {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Respeita preferência do sistema por movimento reduzido */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    #htmx-progress { transition: none !important; }
}

/* ======================================================================
   ATALHOS DE TECLADO — MODAL DE AJUDA
   ====================================================================== */

.kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.78rem;
    font-family: 'SF Mono', Consolas, monospace;
    color: var(--fs-text);
    background-color: var(--fs-bg);
    border: 1px solid var(--fs-border);
    border-radius: 4px;
    box-shadow: 0 1px 0 var(--fs-border);
}

/* ======================================================================
   TOOLTIP DE PRIMEIRO ACESSO (tour)
   ====================================================================== */

.tour-highlight {
    position: relative;
    z-index: 1050;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.4), 0 0 20px rgba(13, 110, 253, 0.2);
    border-radius: 8px;
}
.tour-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
}
.tour-popover {
    position: absolute;
    z-index: 1055;
    background: var(--fs-bg-card);
    border: 1px solid var(--fs-border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    box-shadow: 0 10px 30px var(--fs-shadow);
    max-width: 320px;
}
.tour-popover-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}
.tour-popover-text {
    font-size: 0.85rem;
    color: var(--fs-text-muted);
    margin-bottom: 0.75rem;
}
.tour-step-indicator {
    font-size: 0.75rem;
    color: var(--fs-text-muted);
}

/* ======================================================================
   SIDEBAR LAYOUT
   ====================================================================== */

:root {
    --sidebar-width: 220px;
    --topbar-height: 52px;
    --sidebar-bg: #1a1d21;
    --sidebar-hover: rgba(255,255,255,0.07);
    --sidebar-active: #0d6efd;
    --sidebar-text: rgba(255,255,255,0.72);
    --sidebar-text-hover: #fff;
}

/* ---- Wrapper layout ---- */
/* NOTA: #sidebar width é controlado por base.html via .cb-sidebar */
#sidebar {
    /* Transições controladas por .cb-sidebar em base.html */
}

#main-area {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Brand ---- */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 14px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

/* ---- Nav scrollável ---- */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* ---- Seções collapsíveis ---- */
.sidebar-section { margin-bottom: 2px; }

.sidebar-section-header {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    background: none;
    border: none;
    color: rgba(255,255,255,0.35);
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.15s;
}
.sidebar-section-header:hover { color: rgba(255,255,255,0.55); }
.sidebar-section-header .bi-chevron-down {
    font-size: 0.65rem;
    transition: transform 0.2s;
}
.sidebar-section-header[aria-expanded="true"] .bi-chevron-down {
    transform: rotate(180deg);
}

/* ---- Itens ---- */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 14px 6px 18px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.84rem;
    border-radius: 6px;
    margin: 1px 6px;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-item i { font-size: 0.95rem; flex-shrink: 0; width: 16px; text-align: center; }
.sidebar-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-hover); }
.sidebar-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 600;
}

/* ---- Footer ---- */
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 10px 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}
.sidebar-footer-user {
    display: flex;
    align-items: center;
    gap: 6px;
    color: rgba(255,255,255,0.45);
    font-size: 0.76rem;
    padding: 0 4px;
    overflow: hidden;
}

/* ---- Topbar ---- */
#topbar {
    height: var(--topbar-height);
    background: var(--fs-bg-card, #fff);
    border-bottom: 1px solid var(--fs-border, #dee2e6);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}
.topbar-spacer { flex: 1; }
.topbar-controls { display: flex; align-items: center; gap: 8px; }
.topbar-hamburger {
    background: none;
    border: 1px solid var(--fs-border, #dee2e6);
    border-radius: 6px;
    padding: 5px 8px;
    color: var(--fs-text, #212529);
    cursor: pointer;
    display: flex;
    align-items: center;
}
.topbar-btn {
    background: none;
    border: 1px solid var(--fs-border, #dee2e6);
    border-radius: 6px;
    padding: 5px 9px;
    color: var(--fs-text-muted, #6c757d);
    cursor: pointer;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    transition: all 0.15s;
}
.topbar-btn:hover {
    background: var(--fs-hover, rgba(0,0,0,0.04));
    color: var(--fs-text, #212529);
}

/* ---- Dark mode overrides ---- */
[data-bs-theme="dark"] #sidebar { background: #111316; }
[data-bs-theme="dark"] #topbar {
    background: var(--fs-bg-card);
    border-color: var(--fs-border);
}

/* ---- Overlay mobile ---- */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 299;
}
#sidebar-overlay.show { display: block; }

/* ---- Mobile ---- */
@media (max-width: 767px) {
    #sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }
    #sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    }
    #main-area {
        margin-left: 0;
    }
}

/* Ajuste na barra de progresso com sidebar */
@media (min-width: 768px) {
    #htmx-progress {
        left: var(--sidebar-width);
    }
}