/* ===== VARIAVEIS ===== */
:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --success: #16a34a;
    --success-light: #f0fdf4;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --radius: 8px;
}

/* ===== TEMA ESCURO ===== */
body.tema-escuro {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #1e3a8a;
    --success: #22c55e;
    --success-light: #14532d;
    --success-bg: #14532d;
    --danger: #ef4444;
    --danger-light: #7f1d1d;
    --danger-bg: #450a0a;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --bg-page: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

/* Cores específicas para validação no tema claro */
:root {
    --success-bg: #f0fdf4;
    --danger-bg: #fef2f2;
}

/* ===== BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-page);
    padding: 20px;
}

.container {
    max-width: 100%;
    width: 95%;
    margin: auto;
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

/* ===== TITULOS ===== */
h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--primary);
    padding-bottom: 8px;
    margin-top: 24px;
    margin-bottom: 16px;
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

/* ===== ABAS ===== */
.abas {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.aba {
    padding: 8px 18px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.22s cubic-bezier(.4,0,.2,1);
    position: relative;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.aba:hover {
    color: var(--primary);
    background: var(--bg-card);
    box-shadow: 0 1px 4px rgba(37,99,235,0.10);
}

.aba.ativa {
    color: var(--primary);
    background: var(--bg-card);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(37,99,235,0.13), 0 1px 2px rgba(0,0,0,0.06);
    border-bottom: none;
}

/* ===== TELAS ===== */
.tela {
    display: none;
}

.tela.ativa {
    display: block;
}

/* ===== FIELDSET ===== */
fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    background: var(--bg-card);
}

legend {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--primary);
    padding: 0 8px;
}

/* ===== LINHAS E CAMPOS ===== */
.linha {
    display: flex;
    gap: 15px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.campo {
    display: flex;
    flex-direction: column;
}

.campo label {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: 4px;
    white-space: nowrap;
}

.campo.obrigatorio label::after {
    content: ' *';
    color: var(--danger);
}

/* ===== INPUTS E SELECTS ===== */
.campo input,
.campo select,
.campo textarea {
    height: 38px;
    padding: 8px 12px;
    font-size: 0.875rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: var(--text-primary);
}

.campo textarea {
    height: auto;
    min-height: 70px;
    resize: vertical;
    font-family: inherit;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.campo input[type="checkbox"],
.campo input[type="radio"] {
    height: auto;
    width: auto;
    padding: 0;
}

.campo input:focus,
.campo select:focus,
.campo textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.campo input:disabled {
    background: #e9ecef;
    color: var(--text-secondary);
    cursor: not-allowed;
}

.campo input::placeholder {
    color: #94a3b8;
    font-size: 0.8125rem;
}

/* ===== BOTOES ===== */
.botoes {
    margin-top: 24px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.tela#cadastro .botoes {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 10px 12px;
}

.tela#lembretes .botoes {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 10px 12px;
}

/* Filtros: Status + Motivo sempre lado a lado */
.tela#lembretes .linha-lembretes-filtro-status-motivo {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 15px;
    align-items: flex-end;
    flex: 0 0 auto;
}

.tela#lembretes .linha-lembretes-filtro-status-motivo .campo {
    min-width: 0;
}

.tela#agenda .botoes {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 10px 12px;
}

/* Agenda: Fieldset mais largo com espaçamento interno */
.tela#agenda fieldset {
    padding-left: 20px !important;
    padding-right: 20px !important;
}

.tela#aniversarios .linha-aniversarios-data {
    justify-content: flex-start;
}

.tela#cadastro .botoes .btn {
    font-size: 0.8rem;
    padding: 8px 14px;
    min-width: 120px;
    justify-content: center;
    text-align: center;
    line-height: 1.25;
    white-space: normal;
}

.btn {
    padding: 10px 24px;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: white;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-page);
}

.btn-editar {
    background: var(--primary-light);
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 6px 12px;
    font-size: 0.8125rem;
    border-radius: 4px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-editar:hover {
    background: var(--primary);
    color: white;
}

.btn-excluir {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 4px 12px;
    font-size: 0.75rem;
    border-radius: 4px;
}

.btn-excluir:hover {
    background: var(--danger);
    color: white;
}

.btn-rx-final {
    background: #f0f9ff;
    color: #0284c7;
    border: 1px solid #0284c7;
    padding: 4px 12px;
    font-size: 0.75rem;
    border-radius: 4px;
    cursor: pointer;
}

.btn-rx-final:hover {
    background: #0284c7;
    color: white;
}

.btn-rx-final:disabled {
    background: #f3f4f6;
    color: #9ca3af;
    border: 1px solid #d1d5db;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ===== BUSCA ===== */
.busca-container {
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.busca-container label {
    margin: 0;
    white-space: nowrap;
    font-weight: 600;
    color: var(--text-secondary);
}

.busca-container input {
    padding: 8px 12px;
    font-size: 0.875rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    height: 38px;
    box-sizing: border-box;
    max-width: 350px;
    flex: 1;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.busca-container input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.busca-container select {
    height: 38px;
    padding: 8px 12px;
    font-size: 0.875rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: var(--text-primary);
}

.busca-container select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ===== TABELA ===== */
.tabela-wrapper {
    width: 100%;
    overflow-x: auto;
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
}

.tabela-wrapper::after {
    content: none;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: none;
}

thead th {
    background: var(--primary);
    color: white;
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px;
    text-align: left;
}

/* Coluna de ações mais estreita agora que só tem 1 botão */
thead th:nth-child(4) {
    width: 100px;
    text-align: center;
}

/* Coluna de CPF com largura fixa para não cortar */
thead th:nth-child(3) {
    width: 170px;
}

tbody td:last-child {
    text-align: center;
}

/* Estilo para célula de CPF */
tbody td:nth-child(3) {
    font-family: monospace;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

tbody td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

tbody tr:hover {
    background: var(--primary-light);
}

tbody tr:last-child td {
    border-bottom: none;
}

.acoes {
    display: flex;
    gap: 6px;
}

/* ===== RESUMO CARDS ===== */
.resumo-cards {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.card {
    flex: 1;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-numero {
    display: block;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 8px;
}

.card-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Cards dentro do box de situação */
.card-situacao {
    min-width: 120px;
    flex: 1;
}

.card-situacao .card-numero {
    font-size: 2rem;
}

.card-situacao .card-label {
    font-size: 0.8125rem;
}

/* ===== GRAFICOS ===== */
.graficos-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    margin-top: 32px;
}

.grafico-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.grafico-box h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 20px 0;
    padding: 0;
    border: none;
}

.grafico-box canvas {
    max-height: 300px;
}

/* ===== TOOLBAR LISTA ===== */
.lista-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
}

.contador-resultados {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.por-pagina {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.por-pagina select {
    height: 32px;
    padding: 4px 8px;
    font-size: 0.8125rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    cursor: pointer;
}

.por-pagina select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ===== PAGINACAO ===== */
.paginacao {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.paginacao-numeros {
    display: flex;
    align-items: center;
    gap: 4px;
}

.paginacao-dots {
    padding: 0 4px;
    color: var(--text-secondary);
}

.btn-paginacao {
    padding: 6px 16px;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-paginacao:hover:not(:disabled) {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-paginacao:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-pagina {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-pagina:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-pagina-ativa {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-pagina-ativa:hover {
    background: var(--primary-hover);
    color: white;
}

/* ===== STATUS PACIENTE ===== */
.status-ativo {
    color: var(--success);
    font-weight: 600;
}

.status-inativo {
    color: var(--danger);
    font-weight: 600;
}

/* ===== ANIVERSARIOS ===== */
#listaAniversarios thead th:last-child {
    text-align: center;
    vertical-align: middle;
}

#listaAniversarios tbody td:last-child {
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    padding: 8px;
}

#listaAniversarios .btn-whatsapp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    white-space: nowrap;
}

.msg-vazia {
    margin: 16px 0;
    padding: 20px;
    background: var(--bg-input);
    border-radius: var(--radius);
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

/* ===== NOTIFICACOES (TOASTS) ===== */
#notificacoes {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notificacao {
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
    min-width: 280px;
    max-width: 420px;
}

.notificacao-sucesso {
    background: var(--success-light);
    color: var(--success);
    border-left: 4px solid var(--success);
}

.notificacao-erro {
    background: var(--danger-light);
    color: var(--danger);
    border-left: 4px solid var(--danger);
}

.notificacao-info {
    background: var(--primary-light);
    color: var(--primary);
    border-left: 4px solid var(--primary);
}

.notificacao-saindo {
    animation: slideOut 0.3s ease forwards;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }

    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ===== CONFIGURACOES ===== */
.config-info {
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.7;
}

.config-status {
    margin-top: 12px;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    display: none;
}

.config-status.status-ok {
    display: block;
    background: var(--success-light);
    color: var(--success);
    border: 1px solid var(--success);
}

.config-status.status-erro {
    display: block;
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.config-status.status-aviso {
    display: block;
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #f59e0b;
}

.config-conectado {
    margin-top: 16px;
    padding: 12px 20px;
    background: var(--success-light);
    color: var(--success);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.875rem;
    text-align: center;
}

.aviso-sem-conexao {
    background: #fffbeb;
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    text-align: center;
    color: #b45309;
    font-size: 0.875rem;
}

.aviso-sem-conexao a {
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
    font-weight: 600;
}

/* ===== FILE INPUT ===== */
input[type="file"] {
    padding: 8px;
    font-size: 0.875rem;
    border: 1px dashed var(--border);
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    max-width: 400px;
}

input[type="file"]:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

/* ===== RODAPE ===== */
.rodape {
    max-width: 100%;
    width: 100%;
    margin: 8px auto 0 auto;
    padding: 8px 24px;
    text-align: center;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border-top: 2px solid var(--border);
}

/* Desktop - Footer alinhado com container (menu lateral) */
@media (min-width: 769px) {
    .rodape {
        margin-left: 260px !important;
        width: calc(100% - 260px) !important;
        margin-right: auto !important;
    }
}

.rodape p {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-align: center;
    display: block;
    width: 100%;
}

.rodape strong {
    color: var(--primary);
    font-weight: 600;
}

/* ===== RESPONSIVO ===== */
@media (max-width: 768px) {
    /* FORÇA TUDO A CABER NA TELA - PREVINE OVERFLOW */
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    body {
        padding: 10px;
    }

    .container {
        padding: 12px;
        max-width: 100%;
        margin: 0;
        overflow-x: hidden;
    }
    
    /* Previne qualquer elemento de ultrapassar a largura da tela */
    .tela {
        max-width: 100%;
        overflow-x: hidden;
    }

    .linha {
        flex-direction: column;
        gap: 8px;
    }

    /* Força os campos da aba Lembretes a ocuparem toda a largura no mobile */
    .tela#lembretes .linha {
        align-items: flex-start !important;
    }

    /* Aniversários: com .linha em coluna, flex-end joga o campo pra direita — força esquerda no celular */
    .tela#aniversarios .linha-aniversarios-data {
        align-items: flex-start !important;
        justify-content: flex-start !important;
        width: 100%;
    }
    .tela#aniversarios .linha-aniversarios-data-campo {
        width: 100%;
        max-width: 100%;
        align-self: stretch;
    }
    .tela#aniversarios #filtroDataAniversario {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Largura útil e tipografia iguais à aba Contrato (rx-form / form-group); sem padding horizontal extra no fieldset */
    .tela#lembretes fieldset {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    .tela#lembretes .patient-name-wrapper {
        display: block;
        width: 100%;
        min-width: 0;
    }
    .tela#lembretes #lembretePacienteNome,
    .tela#lembretes #filtroLembreteNome {
        font-size: 0.875rem !important;
        padding: 8px 12px !important;
        height: 38px !important;
        min-height: 38px !important;
        width: 100%;
        box-sizing: border-box;
    }

    /* Motivo + Lembrar em: dois selects lado a lado no celular (como no desktop) */
    .tela#lembretes .linha-lembretes-motivo-prazo {
        flex-direction: row !important;
        flex-wrap: wrap;
        gap: 8px 10px;
        align-items: flex-end;
    }
    .tela#lembretes .linha-lembretes-motivo-prazo > .campo:not(#campoDataEspecifica) {
        flex: 1 1 calc(50% - 6px) !important;
        max-width: calc(50% - 4px);
        min-width: 0;
    }
    .tela#lembretes .linha-lembretes-motivo-prazo > #campoDataEspecifica {
        flex: 1 1 100% !important;
        max-width: 100%;
    }
    .tela#lembretes .linha-lembretes-motivo-prazo select {
        width: 100%;
        min-width: 0;
    }

    /* Adicionar Lembrete + Limpar lado a lado, legíveis no celular */
    .tela#lembretes .botoes-lembretes-form {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 8px;
        justify-content: stretch;
    }
    .tela#lembretes .botoes-lembretes-form .btn {
        flex: 1 1 50% !important;
        min-width: 0 !important;
        max-width: none !important;
        font-size: 0.78rem !important;
        padding: 10px 8px !important;
        white-space: normal !important;
        line-height: 1.25 !important;
        overflow: visible !important;
        text-overflow: clip !important;
    }

    /* Filtros: Status + Motivo na mesma linha no celular */
    .tela#lembretes .linha-lembretes-filtro-status-motivo {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 10px;
        width: 100%;
        align-items: flex-end;
    }
    .tela#lembretes .linha-lembretes-filtro-status-motivo .campo {
        flex: 1 1 calc(50% - 5px) !important;
        max-width: none;
        min-width: 0;
    }
    .tela#lembretes .linha-lembretes-filtro-status-motivo select {
        width: 100%;
    }

    .campo {
        flex: 1 1 100% !important;
    }
    
    /* Remove largura mínima de botões no mobile */
    .btn {
        min-width: 0 !important;
        max-width: 100%;
    }
    
    .tela#cadastro .botoes .btn {
        min-width: 0 !important;
        flex: 1 1 auto;
    }

    .abas {
        overflow-x: unset;
        flex-wrap: wrap;
        border-radius: 10px;
        padding: 4px;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }

    .aba {
        padding: 9px 6px;
        font-size: 0.78rem;
        border-radius: 7px;
        text-align: center;
        white-space: normal;
        line-height: 1.2;
    }

    /* Tabela responsiva com scroll horizontal */
    .tabela-wrapper {
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.75rem;
        min-width: 600px;
    }

    thead th {
        padding: 10px 8px;
        font-size: 0.75rem;
        white-space: nowrap;
    }

    tbody td {
        padding: 8px;
        white-space: nowrap;
    }

    /* Exibe lembretes como cards no mobile para evitar textos cortados */
    .tela#lembretes .tabela-wrapper {
        overflow-x: hidden;
    }

    .tela#lembretes .tabela-wrapper table {
        width: 100%;
        min-width: 0;
        border: 0;
    }

    /* Contratos também deve ser 100% e não forçar scroll global */
    .tela#contratos .tabela-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tela#contratos .tabela-wrapper table {
        width: 100%;
        min-width: 0;
    }

    .tela#contratos fieldset {
        overflow-x: hidden;
    }

    .tela#lembretes .tabela-wrapper thead {
        display: none;
    }

    .tela#lembretes .tabela-wrapper tr {
        display: block;
        margin-bottom: 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--bg-card);
        padding: 10px 12px;
    }

    .tela#lembretes .tabela-wrapper td {
        display: grid;
        grid-template-columns: 130px 1fr;
        gap: 10px;
        padding: 10px 0;
        border-bottom: 1px solid rgba(0,0,0,0.05);
        white-space: normal;
    }

    .tela#lembretes .tabela-wrapper td:last-child {
        border-bottom: none;
    }

    .tela#lembretes .tabela-wrapper td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        white-space: normal;
    }

    .tela#lembretes .tabela-wrapper td[data-label="Status"] {
        align-items: center;
    }

    .tela#lembretes .tabela-wrapper td[data-label="Ações"] {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 8px;
    }

    .acoes {
        flex-direction: row;
        gap: 4px;
        flex-wrap: nowrap;
    }

    .btn-editar,
    .btn-excluir,
    .btn-rx-final {
        padding: 6px 10px;
        font-size: 0.7rem;
        white-space: nowrap;
        height: 34px;
        display: inline-flex;
        align-items: center;
    }

    .resumo-cards {
        flex-direction: column;
    }

    .card {
        min-width: auto;
    }

    .busca-container {
        flex-direction: column;
        align-items: stretch;
    }

    .busca-container input {
        max-width: none;
    }

    .lista-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .paginacao {
        gap: 4px;
    }

    .btn-paginacao {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .btn-pagina {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }

    .botoes {
        flex-direction: column;
    }

    .botoes .btn {
        width: 100%;
        justify-content: center;
    }

    .header-auth {
        flex-direction: column;
        gap: 8px;
        padding: 10px 12px;
    }

    .header-esquerda {
        width: 100%;
        justify-content: center;
    }

    .header-direita {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }

    .header-usuario-nome {
        display: none;
    }

    .header-btn {
        padding: 6px 12px !important;
        font-size: 0.75rem !important;
        flex: 0 0 auto;
    }

    .login-card {
        margin: 10px;
        padding: 24px;
    }

    .rodape {
        margin: 10px;
        padding: 12px 16px;
        font-size: 0.75rem;
    }

    .graficos-container {
        grid-template-columns: 1fr;
    }

    .grafico-box {
        padding: 16px;
    }
}

/* ===== HEADER AUTH ===== */
.header-auth {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1000px;
    margin: 0 auto 16px auto;
    padding: 14px 28px;
    background: linear-gradient(135deg, var(--bg-card) 0%, var(--primary-light) 100%);
    border-radius: 14px;
    box-shadow: 0 4px 18px rgba(37,99,235,0.10), var(--shadow-sm);
    border: 1px solid var(--border);
    border-left: 5px solid var(--primary);
    position: relative;
    overflow: hidden;
}

.header-auth::before {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 180px; height: 100%;
    background: radial-gradient(ellipse at 100% 50%, rgba(37,99,235,0.07) 0%, transparent 70%);
    pointer-events: none;
}

.header-esquerda {
    display: flex;
    align-items: center;
    gap: 14px;
}

.header-direita {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-sistema-nome {
    font-weight: 800;
    font-size: 1.08rem;
    color: var(--primary);
    letter-spacing: 0.01em;
    text-shadow: 0 1px 4px rgba(37,99,235,0.08);
}

.header-usuario-nome {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 3px 12px;
}

.header-btn {
    padding: 6px 16px !important;
    font-size: 0.8125rem !important;
    min-height: 32px;
    border-radius: 8px !important;
    transition: all 0.2s !important;
}

.header-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.12) !important;
}

.header-admin-link {
    text-decoration: none;
}

/* ===== BOTAO TEMA ===== */
.btn-tema {
    padding: 4px 8px;
    font-size: 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(.4,0,.2,1);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.btn-tema:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    transform: rotate(20deg) scale(1.1);
    box-shadow: 0 3px 10px rgba(37,99,235,0.18);
}

/* ===== BOTAO WHATSAPP ===== */
.btn-whatsapp {
    padding: 6px 12px;
    font-size: 0.875rem;
    background: #25D366;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-whatsapp:hover {
    background: #128C7E;
    box-shadow: var(--shadow-md);
}

.btn-whatsapp-enviado {
    background: #e5e7eb !important;
    color: #374151 !important;
    border: 1px solid #d1d5db !important;
}

.btn-whatsapp-enviado:hover {
    background: #d1d5db !important;
}

/* ===== LOGIN PAGE ===== */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: var(--bg-card);
    padding: 40px 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border-top: 4px solid var(--primary);
}

.login-titulo {
    text-align: center;
    font-size: 1.5rem;
    border-bottom: none;
    padding-bottom: 4px;
    margin-top: 0;
    margin-bottom: 4px;
    color: var(--primary);
}

.login-subtitulo {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 24px;
}

.login-card .campo {
    margin-bottom: 16px;
}

.login-card .campo input {
    height: 42px;
    padding: 10px 14px;
    font-size: 0.9375rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-card .campo input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.login-erro {
    margin-top: 16px;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid var(--danger);
    text-align: center;
}

/* ===== RX FORM STYLES ===== */
.rx-form-container {
    max-width: 800px;
    margin: 20px auto;
    padding: 0;
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: var(--text-primary);
    font-size: 0.875rem;
    height: 38px;
}

.form-group textarea {
    height: auto;
    resize: vertical;
    min-height: 100px;
}

.tooth-inputs {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.tooth-input {
    flex: 1;
    min-width: 150px;
}

.form-group .btn {
    margin-top: 8px;
    padding: 8px 16px;
}

/* Autocomplete nome do paciente (Pedido RX) */
.patient-name-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.patient-name-wrapper input {
    width: 100%;
}

.autocomplete-list {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: 2px;
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 1000;
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-primary);
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover {
    background: var(--primary-light);
}

.autocomplete-item.autocomplete-vazio {
    cursor: default;
    color: var(--text-secondary);
}

.autocomplete-cpf {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: 6px;
}

/* Modal seleção de paciente para RX */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-width: 90vw;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal-pacientes-rx {
    min-width: 600px;
}

@media (max-width: 640px) {
    .modal-pacientes-rx {
        min-width: 0;
        width: 92vw !important;
        max-width: 92vw !important;
    }

}

/* Estilo específico para o modal de busca de pacientes para agenda */
#modalBuscaPacienteAgenda {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

#modalBuscaPacienteAgenda .modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-width: 92vw;
    max-height: 80vh;
    width: 500px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#modalBuscaPacienteAgenda .modal-body {
    flex: 1;
    overflow: auto;
    max-height: calc(80vh - 120px); /* Ajusta para caber header e footer */
}

/* Limitar a altura da lista de pacientes */
#listaPacientesAgenda {
    max-height: 300px;
    overflow-y: auto;
}

/* Estilo para a linha selecionada na tabela de pacientes */
.modal-paciente-row.selecionado {
    background-color: var(--primary-light) !important;
    outline: 2px solid var(--primary);
}

/* Estilo para botões pequenos */
.btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
    min-height: auto;
    margin: 0;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
}

.modal-fechar {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 6px;
}

.modal-fechar:hover {
    color: var(--text-primary);
}

/* Estilo para o botão de fechar genérico */
.fechar-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 6px;
}

.fechar-modal:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 16px;
    overflow: auto;
}

.modal-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
}

.modal-paciente-row {
    cursor: pointer;
}

.modal-paciente-row:hover {
    background: var(--primary-light);
}

.btn-small {
    padding: 4px 10px;
    font-size: 0.8125rem;
}

/* Botões de ação na tabela de pacientes */
.btn-tabela {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-tabela:hover {
    background: var(--bg-page);
}

/* Botão Pedido RX na tabela de pacientes */
.btn-pedido-rx {
    margin-left: 8px;
    background: var(--success-light);
    color: var(--success);
    border: 1px solid var(--success);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s;
}

.btn-pedido-rx:hover {
    background: var(--success);
    color: white;
}

.btn-atestado {
    margin-left: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.btn-atestado:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.print-template {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius);
}

.header-info {
    text-align: center;
    margin-bottom: 20px;
}

.patient-info,
.rx-details {
    margin-bottom: 20px;
}

.info-row {
    display: flex;
    margin-bottom: 8px;
    padding: 4px 0;
}

.info-label {
    font-weight: 600;
    min-width: 150px;
    color: var(--text-secondary);
}

/* Organização da coluna Ações na lista de pacientes (HORIZONTAL alinhado) */
#pacientes .tabela-wrapper table tbody td:last-child {
    display: flex;
    flex-direction: row !important;
    align-items: center !important;
    gap: 6px;
    justify-content: flex-start;
    flex-wrap: nowrap;
}

/* Botões e select na mesma altura */
#pacientes .btn-tabela,
#pacientes .btn-editar,
#pacientes .acoes-select {
    margin: 0 !important;
    vertical-align: middle !important;
}

/* Campo Situação mais largo para não quebrar texto */
#pacientes .tabela-wrapper table tbody td:nth-child(5),
#pacientes .tabela-wrapper table thead th:nth-child(5) {
    min-width: 140px;
    max-width: 140px;
}

/* Campo NOME com largura generosa pra mostrar nome completo */
#pacientes .tabela-wrapper table tbody td:nth-child(2),
#pacientes .tabela-wrapper table thead th:nth-child(2) {
    min-width: 280px;
    max-width: 350px;
}

/* Aumentar largura da coluna Ações (SEM espaço extra) */
#pacientes .tabela-wrapper table tbody td:last-child,
#pacientes .tabela-wrapper table thead th:last-child {
    min-width: 250px;
}

/* Tabela ocupa toda largura disponível no desktop */
@media (min-width: 1200px) {
    #pacientes .tabela-wrapper {
        display: block;
        width: 100%;
    }
    #pacientes .tabela-wrapper table {
        min-width: 100%;
        width: 100%;
    }
}

#pacientes .tabela-wrapper table thead th:last-child {
    text-align: left;
}

/* Dá mais espaço horizontal para as ações em telas largas */
@media (min-width: 900px) {
    #pacientes .tabela-wrapper table th:last-child,
    #pacientes .tabela-wrapper table td:last-child {
        min-width: 0;
    }
}

/* Unificar a cor/estilo dos botões de ação para o mesmo do Atestado */
#pacientes .btn-tabela,
#pacientes .btn-editar,
#pacientes .btn-pedido-rx,
#pacientes .btn-rx-final {
    background: var(--bg-card) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-weight: 500;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#pacientes .btn-tabela:hover,
#pacientes .btn-editar:hover,
#pacientes .btn-pedido-rx:hover,
#pacientes .btn-rx-final:hover {
    background: var(--primary) !important;
    color: #fff !important;
    border-color: var(--primary) !important;
}

/* Caixa de seleção de ações por paciente */
.acoes-select {
    width: 140px;
    padding: 6px 10px;
    height: 34px;
    font-size: 0.8125rem;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.acoes-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Evita scroll/piscada quando um modal está aberto (mobile-friendly) */
body.modal-aberto {
    overflow: hidden;
    touch-action: none;
}
/* ===== FICHA CLINICA IMPRESSAO ===== */
.print-template-ficha {
    display: none;
    font-family: Arial, Helvetica, sans-serif;
    color: #000;
    max-width: 800px;
    margin: 0 auto;
    background: white;
    padding: 6px 15px;
}

.ficha-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.ficha-logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.ficha-logo-icon {
    width: 60px;
    height: 60px;
    position: relative;
}

.ficha-logo-icon::before {
    content: "A";
    position: absolute;
    font-size: 80px;
    color: #9ca3af;
    font-weight: 300;
    line-height: 0.8;
}

.ficha-logo-text h1 {
    font-size: 20px;
    color: #9ca3af;
    font-weight: 300;
    margin: 0;
    border: none;
    padding: 0;
    line-height: 1.1;
    letter-spacing: 1px;
}

.ficha-logo-text p {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
}

.ficha-clinica-info {
    text-align: right;
    font-size: 11px;
    line-height: 1.6;
}

.ficha-top-info {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    border-bottom: 2px solid #000;
    padding: 2px 0;
    margin-bottom: 5px;
}

.ficha-top-info strong {
    font-weight: normal;
}

.ficha-sessao-titulo {
    background-color: #d1d5db;
    border: 2px solid #000;
    text-align: center;
    font-weight: bold;
    font-size: 13px;
    padding: 1px 0;
    margin-bottom: 4px;
    margin-top: 5px;
}

.ficha-identificacao,
.ficha-historia {
    font-size: 12px;
    line-height: 1.25;
    color: #000;
}

.ficha-linha {
    display: flex;
    align-items: flex-end;
    margin-bottom: 4px;
    min-height: 16px;
}

.ficha-label {
    white-space: nowrap;
    margin-right: 5px;
}

.ficha-valor {
    border-bottom: 1px solid #000;
    min-height: 16px;
    padding-left: 5px;
    padding-bottom: 1px;
    font-family: monospace;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ficha-valor-full {
    flex: 1;
    border-bottom: 1px solid #000;
    min-height: 18px;
}

.ficha-doencas-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.ficha-doenca-item {
    font-size: 13px;
}

.ficha-hr {
    border-top: 1px solid #000;
    margin: 0;
}

@media print {
    .no-print {
        display: none;
    }

    body * {
        visibility: hidden;
    }

    /* Outros templates de impressão */
    body:not(.imprimindo-ficha) .print-template,
    body:not(.imprimindo-ficha) .print-template * {
        visibility: visible;
    }

    body:not(.imprimindo-ficha) #pedido-rx .print-template,
    body:not(.imprimindo-ficha) #atestado .print-template,
    body:not(.imprimindo-ficha) #receituario .print-template,
    body:not(.imprimindo-ficha) #orcamento .print-template {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        box-shadow: none;
        margin: 0;
        padding: 20px;
        background-color: white !important;
        page-break-inside: avoid;
    }

    /* Garante que o atestado caiba em uma página */
    #printTemplateAtestado {
        page-break-after: avoid;
        page-break-before: avoid;
    }

    #printTemplateAtestado .atestado-corpo,
    #printTemplateAtestado .atestado-data {
        page-break-inside: avoid;
    }

    /* Garante que o receituário caiba em uma página */
    #printTemplateReceituario {
        page-break-after: avoid;
        page-break-before: avoid;
    }

    #printTemplateReceituario .receituario-corpo,
    #printTemplateReceituario .receituario-data {
        page-break-inside: avoid;
    }

    /* Segunda via do receituário controlado */
    #printTemplateReceituario2Via {
        page-break-after: avoid;
        page-break-before: always;
    }

    #printTemplateReceituario2Via .receituario-corpo,
    #printTemplateReceituario2Via .receituario-data {
        page-break-inside: avoid;
    }

    /* Ficha Clinica template print rules */
    body.imprimindo-ficha .print-template-ficha,
    body.imprimindo-ficha .print-template-ficha * {
        visibility: visible;
    }

    /* Receituário template print rules */
    body.imprimindo-receituario .print-template,
    body.imprimindo-receituario .print-template * {
        visibility: visible;
    }

    /* Evitar que elementos ocultos gerem páginas extras e layout enorme */
    body.imprimindo-receituario .container> :not(#receituario),
    body.imprimindo-receituario #receituario> :not(.print-template),
    body.imprimindo-receituario .header-auth,
    body.imprimindo-receituario .abas {
        display: none !important;
    }

    body.imprimindo-receituario .print-template {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        box-shadow: none;
        margin: 0;
        padding: 10px;
        background-color: white !important;
    }

    /* Evitar que elementos ocultos gerem páginas extras e layout enorme */
    body.imprimindo-ficha .container> :not(#cadastro),
    body.imprimindo-ficha #cadastro> :not(#printTemplateFicha),
    body.imprimindo-ficha .header-auth,
    body.imprimindo-ficha .abas {
        display: none !important;
    }

    body.imprimindo-ficha .print-template-ficha {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        box-shadow: none;
        margin: 0;
        padding: 10px;
        background-color: white !important;
    }

    /* Contrato - isolar impressão */
    body.imprimindo-contrato .print-template,
    body.imprimindo-contrato .print-template * {
        visibility: visible;
    }

    body.imprimindo-contrato .container > :not(#contrato),
    body.imprimindo-contrato #contrato > :not(.print-template),
    body.imprimindo-contrato .header-auth,
    body.imprimindo-contrato .abas {
        display: none !important;
    }

    body.imprimindo-contrato .print-template {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        box-shadow: none;
        margin: 0;
        padding: 20px;
        background-color: white !important;
    }

    #printTemplateContrato {
        page-break-after: avoid;
        page-break-before: avoid;
    }
}
/* ===== AGENDA - NAVEGAÇÃO POR DIA ===== */
.agenda-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.agenda-nav-esquerda {
    display: flex;
    align-items: center;
    gap: 6px;
}

.agenda-nav-esquerda input[type="date"] {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.875rem;
    height: 34px;
    cursor: pointer;
}

.agenda-nav-direita {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.agenda-titulo-dia {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.agenda-titulo-dia h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

/* Destaque para linhas de hoje na tabela */
.agenda-hoje {
    background-color: var(--primary-light, rgba(37, 99, 235, 0.07)) !important;
    font-weight: 500;
}

.agenda-hoje td:nth-child(2) {
    color: var(--primary);
    font-weight: 700;
}

/* Padronização de fonte na tabela de agendamentos da Agenda */
#tabelaAgendamentos thead th {
    font-size: 0.8125rem;
    text-align: left;
}

#tabelaAgendamentos tbody td {
    font-size: 0.875rem;
    font-family: inherit;
    letter-spacing: normal;
}

/* Garantir que largura/alinhamento de outras tabelas não afete a agenda */
#tabelaAgendamentos thead th:nth-child(3),
#tabelaAgendamentos thead th:nth-child(4) {
    width: auto;
    text-align: left;
}

/* Nome do paciente na agenda deve usar a mesma família de fonte */
#tabelaAgendamentos tbody td:nth-child(3) {
    font-family: inherit;
    letter-spacing: normal;
}

@media (max-width: 600px) {
    .agenda-nav {
        flex-direction: column;
        align-items: flex-start;
    }
    .agenda-nav-direita {
        width: 100%;
    }
    .agenda-nav-direita .btn {
        flex: 1;
        justify-content: center;
        text-align: center;
    }
}

/* Coluna de nome do paciente na tabela de agendamentos — não quebra em nomes longos */
#tabelaAgendamentos thead th:nth-child(3),
#tabelaAgendamentos tbody td:nth-child(3) {
    min-width: 220px;
    white-space: nowrap;
}

/* Busca de paciente na agenda — responsivo */
.agenda-busca-paciente-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    flex-wrap: nowrap;
}

@media (max-width: 600px) {
    .agenda-busca-paciente-wrapper {
        flex-wrap: wrap;
    }
    .agenda-busca-paciente-wrapper > div {
        flex: 1 1 100%;
        width: 100%;
    }
    .agenda-busca-paciente-wrapper > button {
        width: 100%;
    }
}

/* Autocomplete da agenda — largura total no celular */
#patientNameAutocompleteListAgenda {
    left: 0;
    right: 0;
    min-width: 100%;
    white-space: normal;
    word-break: break-word;
}

/* Modal de busca de paciente na agenda — responsivo */
.modal-agenda-responsivo {
    width: 480px;
    max-width: 92vw;
    height: 460px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

.modal-agenda-responsivo .modal-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.modal-agenda-responsivo table {
    font-size: 0.82rem;
}

@media (max-width: 640px) {
    .modal-agenda-responsivo {
        width: 92vw !important;
        max-width: 92vw !important;
        min-width: 0 !important;
        height: auto !important;
        max-height: 70vh !important;
    }
}

/* Input padrão reutilizável — mesmo estilo do .campo input */
.campo-input-padrao {
    flex: 1;
    height: 38px;
    padding: 8px 12px;
    font-size: 0.875rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
}

.campo-input-padrao:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.campo-input-padrao::placeholder {
    color: #94a3b8;
    font-size: 0.8125rem;
}

/* Correção de responsividade para abas de formulários no mobile */
@media (max-width: 768px) {
    /* Força todo conteúdo a caber na tela */
    * {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .rx-form-container {
        max-width: 100%;
        margin: 10px 0;
        padding: 0;
        overflow-x: hidden;
    }
    
    .rx-form-container .linha {
        flex-direction: column;
        gap: 8px;
    }
    
    .rx-form-container .campo {
        flex: 1 1 100% !important;
        max-width: 100%;
        min-width: 0;
    }
    
    .rx-form-container .form-group {
        margin-bottom: 12px;
        width: 100%;
    }
    
    .rx-form-container input,
    .rx-form-container select,
    .rx-form-container textarea {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }
    
    /* Força botões a caberem na tela */
    .rx-form-container .btn {
        min-width: 0;
        max-width: 100%;
        white-space: normal;
        padding: 10px 16px;
        font-size: 0.85rem;
    }
    
    /* Garante que botões ocupem linha inteira se necessário */
    .rx-form-container form > .btn {
        width: 100%;
        margin: 8px 0;
    }
    
    /* ===== CORREÇÕES ESPECÍFICAS PARA ADMIN CONTRATOS ===== */
    
    /* Labels longas - MUITO MENOR no mobile */
    .campo label {
        font-size: 0.65rem !important;
        line-height: 1.2;
        word-break: break-word;
        overflow-wrap: anywhere;
        white-space: normal;
        max-width: 100%;
        padding: 0;
        margin-bottom: 4px;
    }
    
    /* Inputs e textareas - compacto */
    .campo input,
    .campo textarea,
    .campo select {
        font-size: 0.75rem !important;
        padding: 6px !important;
        width: 100%;
        box-sizing: border-box;
        max-width: 100%;
    }
    
    /* Textarea (campo HTML do contrato) - fonte bem pequena */
    .campo textarea {
        font-size: 0.65rem !important;
        padding: 6px !important;
        overflow-x: auto;
        white-space: pre-wrap;
        word-break: break-all;
        max-width: 100%;
        line-height: 1.3;
    }
    
    /* Textos explicativos (variáveis do contrato) - BEM PEQUENO */
    .campo p,
    .campo p strong {
        font-size: 0.6rem !important;
        line-height: 1.3;
        word-break: break-word;
        overflow-wrap: anywhere;
        max-width: 100%;
        margin: 2px 0;
    }
    
    /* Checkbox com label longa - compacto */
    .campo label[style*="display: flex"],
    .campo label[style*="cursor: pointer"] {
        font-size: 0.7rem !important;
        gap: 4px !important;
        word-break: break-word;
        overflow-wrap: anywhere;
        line-height: 1.2;
    }
    
    /* Botões no admin - BEM MENORES */
    .botoes .btn {
        font-size: 0.7rem !important;
        padding: 6px 8px !important;
        min-width: 0 !important;
        white-space: nowrap;
        line-height: 1.2;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Botões lado a lado - 50% cada */
    /* Mobile: Botões em pares lado a lado (2 colunas) */
    .tela#cadastro .botoes {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        justify-content: stretch !important;
        width: 100% !important;
    }
    
    .tela#cadastro .botoes .btn {
        width: 100% !important;
        max-width: none !important;
        white-space: normal !important;
        word-wrap: break-word !important;
        font-size: 0.85rem !important;
        padding: 10px 8px !important;
        line-height: 1.2 !important;
    }
    
    /* Fieldset mais compacto */
    fieldset {
        padding: 10px !important;
        margin: 10px 0 !important;
    }
    
    fieldset legend {
        font-size: 0.85rem !important;
        padding: 0 6px !important;
    }

    /* Agenda (celular): Agendar + Limpar na mesma linha */
    .tela#agenda .botoes-agenda-form {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 8px;
        justify-content: stretch;
        align-items: stretch;
    }
    .tela#agenda .botoes-agenda-form .btn {
        flex: 1 1 50% !important;
        width: auto !important;
        max-width: none !important;
        min-width: 0 !important;
        font-size: 0.78rem !important;
        padding: 10px 8px !important;
        white-space: normal !important;
        line-height: 1.25 !important;
        overflow: visible !important;
        text-overflow: clip !important;
    }
    
    /* Agenda: Fieldset mais largo com espaçamento interno */
    .tela#agenda fieldset {
        padding-left: 20px !important;
        padding-right: 20px !important;
    }
}

/* ========================================
   MENU LATERAL - NOVO (Substitui Header e Abas)
   ======================================== */

/* Botão Hambúrguer (Mobile) */
.btn-hamburguer {
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1001;
    background: #2196F3;
    color: white;
    border: none;
    padding: 10px 14px;
    font-size: 20px;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.2s ease;
    display: none; /* Só aparece no mobile */
}

.btn-hamburguer:hover {
    background: #1976D2;
    transform: scale(1.05);
}

/* Menu Lateral */
.menu-lateral {
    position: fixed;
    top: 0;
    left: -300px; /* Escondido */
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: white;
    z-index: 1000;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 12px rgba(0,0,0,0.3);
    overflow-y: auto;
}

.menu-lateral.aberto {
    left: 0; /* Aberto */
}

/* Header do Menu */
.menu-header {
    padding: 20px;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.menu-header .header-sistema-nome {
    font-size: 1.1rem;
    font-weight: bold;
    color: #2196F3;
}

.btn-fechar-menu {
    background: transparent;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.btn-fechar-menu:hover {
    background: rgba(255,255,255,0.1);
}

/* Área do Usuário */
.menu-usuario {
    padding: 15px 20px;
    background: rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.menu-usuario .header-usuario-nome {
    font-size: 0.9rem;
    color: #94a3b8;
}

/* Itens do Menu */
.menu-itens {
    flex: 1;
    padding: 10px 0;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 14px 20px;
    background: transparent;
    border: none;
    color: #e2e8f0;
    text-align: left;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.menu-item:hover {
    background: rgba(255,255,255,0.05);
    border-left-color: #2196F3;
    padding-left: 25px;
}

.menu-item.ativo {
    background: rgba(33, 150, 243, 0.15);
    border-left-color: #2196F3;
    color: #2196F3;
    font-weight: 600;
}

.menu-item a {
    color: inherit;
    text-decoration: none;
    display: block;
    width: 100%;
}

/* Footer do Menu */
.menu-footer {
    padding: 15px 20px;
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255,255,255,0.1);
}

.menu-footer .menu-item {
    margin-bottom: 8px;
}

.menu-footer .menu-item:last-child {
    margin-bottom: 0;
}

.btn-sair {
    background: rgba(255, 255, 255, 0.03);
    border-left-color: rgba(255, 255, 255, 0.2) !important;
    color: #94a3b8 !important;
    margin-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-sair:hover {
    background: rgba(239, 68, 68, 0.1) !important;
    color: #fca5a5 !important;
    border-left-color: #ef4444 !important;
}

/* Overlay (fundo escuro) */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.menu-overlay.visivel {
    display: block;
    opacity: 1;
}

/* DESKTOP (PC) - Menu sempre visível */
@media (min-width: 769px) {
    .btn-hamburguer {
        display: none;
    }
    
    .menu-lateral {
        left: 0;
        width: 260px;
    }
    
    .menu-overlay {
        display: none !important;
    }
    
    .container {
        margin-left: 260px;
        width: calc(100% - 260px);
    }
}

/* MOBILE (Celular) - Menu escondido */
@media (max-width: 768px) {
    .btn-hamburguer {
        display: block;
    }
    
    .menu-lateral {
        width: 280px;
        left: -280px;
    }
    
    .menu-lateral.aberto {
        left: 0;
    }
    
    .container {
        margin-left: 0;
        width: 100%;
        padding-top: 80px; /* Espaço para a barra mobile */
    }

    /* Mobile Top Bar */
    .mobile-top-bar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 60px;
        background: #1e293b;
        color: white;
        z-index: 1000;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
        padding: 0 20px;
    }

    .mobile-top-bar #headerSistemaNomeMobile {
        font-size: 1.1rem;
        font-weight: 700;
        color: #2196F3;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .btn-hamburguer {
        display: block;
        top: 10px;
        left: 10px;
    }

    /* Agenda Navigation Mobile */
    .agenda-header {
        padding: 10px 5px;
    }

    .agenda-nav {
        flex-direction: column;
        align-items: center;
        gap: 8px;
        width: 100%;
    }

    .agenda-nav-group {
        justify-content: center;
        width: 100%;
    }

    .agenda-titulo {
        width: 100%;
        text-align: center;
        margin: 0;
        font-size: 1rem;
        min-width: auto;
    }
}

/* Esconder header e abas antigas */
.header-auth,
.abas {
    display: none !important;
}

/* ==========================================================================
   NOVA AGENDA PROFISSIONAL (GRID SEMANAL)
   ========================================================================== */

.agenda-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 100px);
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-top: 10px;
}

/* Header da Agenda (Navegação) */
.agenda-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-card);
    border-bottom: 2px solid var(--border);
}

.agenda-nav {
    display: flex;
    align-items: center;
    gap: 15px;
}

.agenda-nav-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.agenda-titulo {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 250px;
}

/* Grade da Agenda */
.agenda-grid-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
}

.agenda-grid {
    display: grid;
    grid-template-columns: 80px repeat(7, 1fr); /* 80px para as horas + 7 colunas */
    min-width: 1000px; /* Garante que não aperte demais no mobile */
}

/* Cabeçalho da Grade (Dias) */
.agenda-col-header {
    background: var(--bg-page);
    padding: 10px;
    text-align: center;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Fixar primeira coluna (Horas) no mobile/horizontal scroll */
.agenda-col-header:nth-child(1) {
    left: 0;
    z-index: 25;
}

.agenda-col-header.hoje {
    background: var(--primary-light);
    color: var(--primary);
}

/* Células de Hora */
.agenda-time-cell {
    padding: 5px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    height: 60px; /* 30 min = 60px de altura */
    background: var(--bg-page);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    position: sticky;
    left: 0;
    z-index: 15;
}

/* Células de Slot */
.agenda-slot {
    height: 60px;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    position: relative;
    cursor: pointer;
    transition: background 0.1s;
}

.agenda-slot:hover {
    background: rgba(37, 99, 235, 0.05);
}

/* Chips de Agendamento */
.agenda-chip {
    position: absolute;
    left: 2px;
    right: 2px;
    top: 2px;
    bottom: 2px;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 0.75rem;
    overflow: hidden;
    z-index: 5;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.1s;
}

.agenda-chip:hover {
    transform: scale(1.02);
    z-index: 20;
}

.agenda-chip-paciente {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agenda-chip-tipo {
    font-size: 0.65rem;
    opacity: 0.8;
}

.agenda-chip-status {
    position: absolute;
    bottom: 2px;
    right: 4px;
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
}

.agenda-chip-wa {
    color: #25d366;
    display: inline-flex;
    filter: drop-shadow(0 0 1px rgba(0,0,0,0.2));
}

/* Cores por Tipo */
.chip-tipo-consulta   { background: #e0f2fe; color: #0369a1; border-left: 4px solid #0369a1; }
.chip-tipo-limpeza    { background: #dcfce7; color: #15803d; border-left: 4px solid #15803d; }
.chip-tipo-procedimento { background: #fef9c3; color: #a16207; border-left: 4px solid #a16207; }
.chip-tipo-cirurgia   { background: #fee2e2; color: #b91c1c; border-left: 4px solid #b91c1c; }
.chip-tipo-outro      { background: #f3f4f6; color: #4b5563; border-left: 4px solid #4b5563; }

/* Status Indicators */
.agenda-chip-status {
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 0.8rem;
}

/* Modal de Agendamento */
.agenda-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.agenda-modal {
    background: var(--bg-card);
    width: 450px;
    max-width: 90%;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    overflow: hidden;
    animation: modalPop 0.3s cubic-bezier(.34,1.56,.64,1);
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.agenda-modal-header {
    padding: 15px 20px;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.agenda-modal-body {
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-acoes-footer {
    padding: 15px 20px;
    background: var(--bg-page);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border);
}

/* Autocomplete Custom */
.agenda-autocomplete {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border-radius: 0 0 6px 6px;
    display: none;
}

.agenda-autocomplete-item {
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}

.agenda-autocomplete-item:hover {
    background: var(--primary-light);
}

/* WhatsApp Link Styling */
.agenda-whatsapp-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #25d366;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.85rem;
    margin-top: 10px;
}

.agenda-whatsapp-link:hover {
    text-decoration: underline;
}

/* Dark Mode Overrides */
body.tema-escuro .agenda-grid-container { background: #1e293b; }
body.tema-escuro .agenda-col-header { background: #334155; }
body.tema-escuro .agenda-time-cell { background: #334155; }
body.tema-escuro .agenda-slot { border-color: #475569; }
body.tema-escuro .agenda-slot:hover { background: rgba(59, 130, 246, 0.1); }

/* Correção link Admin */
.menu-admin-link {
    text-decoration: none !important;
}
