/* ==========================================================================
   1. ESTILOS GERAIS (VISUAL DA TELA)
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600&display=swap');

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0; padding: 0; background-color: #f4f7f6; color: #333; line-height: 1.6;
}

main {
    padding: 20px; max-width: 950px; margin: 20px auto; background-color: white;
    border-radius: 8px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05); min-height: 600px;
}

/* Cabeçalho */
header {
    background-color: #2DA8A8; color: white; padding: 15px 20px;
    display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
header h1 { margin: 0; font-size: 1.5rem; font-weight: bold; }
nav a { color: rgba(255, 255, 255, 0.9); margin-left: 20px; text-decoration: none; font-weight: 500; transition: color 0.3s; }
nav a:hover, nav a.active { color: #fff; text-decoration: underline; }

/* ==========================================================================
   2. FORMULÁRIOS E INPUTS
   ========================================================================== */
fieldset { border: 1px solid #ddd; padding: 20px; margin-bottom: 25px; border-radius: 6px; background-color: #fff; }
legend { font-weight: bold; padding: 0 10px; color: #2DA8A8; font-size: 1.1em; }
label { display: block; margin-top: 10px; font-weight: 600; color: #444; }

input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="datetime-local"], textarea, select {
    width: 100%; padding: 10px; margin-top: 5px; box-sizing: border-box;
    border: 1px solid #ccc; border-radius: 4px; font-family: inherit; font-size: 1rem; background-color: #fff;
}
textarea { resize: vertical; }

.grid-2-col { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 10px; }

/* Busca */
.search-box { display: flex; gap: 10px; margin-bottom: 10px; }
.search-box input { flex: 1; }
.search-box button { background-color: #2DA8A8; color: white; border: none; padding: 0 25px; border-radius: 4px; cursor: pointer; font-weight: bold; }
.hint-text { color: #666; font-size: 0.9em; font-style: italic; margin-top: 5px; }

/* Botões de Ação */
#barraAcoes { margin-top: 30px; padding: 20px; background-color: #f8f9fa; border-top: 2px solid #007bff; display: flex; gap: 15px; justify-content: flex-end; }
.btn-action { padding: 12px 25px; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; font-weight: bold; color: white; }
.btn-save { background-color: #28a745; flex-grow: 1; }
.btn-print { background-color: #17a2b8; }
#btnCancelar { background: #fff; border: 1px solid #dc3545; color: #dc3545; padding: 8px 15px; border-radius: 4px; cursor: pointer; font-weight: bold; }

/* ==========================================================================
   3. ESTILOS ESPECÍFICOS
   ========================================================================== */
.header-paciente { border: 1px solid #b3d9ff; background-color: #e3f2fd; padding: 15px; border-radius: 6px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; }
.header-content h3 { margin: 0 0 5px 0; color: #0056b3; }
.dados-paciente p { margin: 2px 0; color: #333; font-size: 0.95em; }

.image-container { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-start; margin-top: 15px; padding: 10px; background: #f9f9f9; border: 1px solid #eee; border-radius: 4px; }
.image-item { width: 18%; min-width: 120px; text-align: center; margin-bottom: 10px; position: relative; padding: 5px; background: #fff; border: 1px solid #ddd; border-radius: 4px; }
.image-item img { width: 100%; height: auto; display: block; }
.image-item input[type="checkbox"] { position: absolute; top: 5px; left: 5px; transform: scale(1.3); cursor: pointer; }

.upload-grid { display: flex; gap: 15px; justify-content: space-between; margin-bottom: 15px; }
.upload-box { width: 23%; height: 150px; border: 2px dashed #ccc; border-radius: 6px; position: relative; display: flex; align-items: center; justify-content: center; background-color: #f9f9f9; cursor: pointer; overflow: hidden; }
.img-preview { position: absolute; width: 100%; height: 100%; object-fit: cover; display: none; z-index: 1; }

.pdf-row { display: flex; align-items: center; margin-bottom: 10px; border-bottom: 1px dashed #eee; padding-bottom: 5px; }
.pdf-label { flex: 2; font-weight: bold; color: #555; }
.pdf-options { flex: 3; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pdf-input { flex: 3; }

.section-title { background-color: #9ccc65; color: white; padding: 6px 15px; border-radius: 20px 20px 20px 0; display: inline-block; margin-bottom: 15px; font-weight: bold; }
.sub-section { background-color: #fafafa; border: 1px solid #eee; padding: 15px; border-radius: 6px; margin-top: 20px; }

.print-only, .display-print { display: none; }

/* Agenda */
.fc .fc-toolbar { background-color: #2c3e50; padding: 10px; color: #fff; border-radius: 8px 8px 0 0; }

/* ==========================================================================
   4. RESPONSIVIDADE (MOBILE)
   ========================================================================== */
@media (max-width: 768px) {
    main { margin: 10px auto; padding: 15px; max-width: 95%; }
    header { flex-direction: column; text-align: center; gap: 15px; }
    nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }
    nav a { display: inline-block; width: auto; margin: 0; padding: 8px 12px; text-align: center; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 5px; background-color: rgba(255, 255, 255, 0.1); font-size: 0.85rem; box-sizing: border-box; }
    .grid-2-col { grid-template-columns: 1fr; gap: 10px; }
    .header-paciente { flex-direction: column; gap: 10px; text-align: center; }
    .header-content { width: 100%; }
    .upload-grid { flex-wrap: wrap; gap: 10px; }
    .upload-box { width: 48%; height: 120px; }
    .image-item { width: 45%; }
    #barraAcoes { flex-direction: column; gap: 10px; }
    .btn-action { width: 100%; padding: 15px; }
    .pdf-row { flex-direction: column; align-items: flex-start; gap: 5px; }
    .pdf-label { width: 100%; margin-bottom: 5px; }
    .pdf-options { width: 100%; justify-content: space-between; }
}

/* ==========================================================================
   5. MODO IMPRESSÃO (WYSIWYG - O QUE VOCÊ VÊ É O QUE SAI)
   ========================================================================== */
@media print {
    /* 1. LIMPEZA: Esconde cabeçalhos, botões, menus e barras de ação */
    header, 
    nav, 
    #barraAcoes, 
    .no-print, 
    .btn-action, 
    button, 
    .hint-text,
    .search-box,    /* Esconde caixa de busca na impressão */
    #secaoBusca,    /* Esconde a busca de pacientes se estiver visível */
    .sidebar-decor { /* Remove a barra lateral decorativa antiga se existir */
        display: none !important;
    }

    /* 2. CORES E FUNDO: Força o navegador a imprimir as cores exatas da tela */
    body {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        background-color: #fff !important;
        margin: 0;
        padding: 0;
    }

    main {
        margin: 0 !important;
        padding: 20px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-shadow: none !important; /* Remove sombra da caixa principal */
        border: none !important;
    }

    /* 3. INPUTS E TEXTAREAS: O PULO DO GATO */
    /* Ao contrário do código anterior, aqui nós FORÇAMOS os inputs a aparecerem */
    input, textarea, select {
        display: block !important;
        border: 1px solid #ccc !important; /* Mantém a borda para parecer formulário */
        background-color: #fff !important; /* Fundo branco para economizar tinta, ou use transparent */
        color: #000 !important;
        box-shadow: none !important;
        font-family: inherit;
        font-size: 10pt; /* Tamanho confortável para leitura */
    }

    /* Ajuste específico para Textareas não terem barra de rolagem no papel */
    textarea {
        overflow: visible !important;
        height: auto !important; /* Tenta ajustar altura */
        white-space: pre-wrap;
    }

    /* Selects aparecem limpos */
    select {
        appearance: none; /* Remove a seta padrão do navegador para ficar mais limpo */
        -webkit-appearance: none;
        padding-right: 10px;
    }

    /* 4. IMAGENS E PADRÕES */
    /* Garante que a imagem selecionada apareça */
    #areaImagemPrint {
        display: block !important;
        margin-top: 10px;
        page-break-inside: avoid; /* Evita que a imagem seja cortada na virada da folha */
    }
    
    img {
        max-width: 100% !important;
        display: block !important;
    }

    /* Esconde a grade de seleção de imagens na impressão, deixando só a escolhida (opcional) */
    /* Se quiser que apareçam todas as carinhas para marcar x no papel, remova a linha abaixo */
    .image-container { 
        display: none !important; 
    }
    
    /* Mas garante que a imagem de resultado ("Padrão Visual Identificado") apareça */
    #areaImagemPrint .image-container {
        display: block !important;
    }

    /* 5. LAYOUT DE PÁGINA */
    @page {
        size: A4;
        margin: 1.5cm; /* Margem segura para impressoras padrão */
    }

    /* Evita quebras de seção ruins */
    fieldset {
        page-break-inside: avoid;
        margin-bottom: 15px;
    }

    /* Seção de Assinatura (se houver no futuro) */
    .assinatura-box {
        margin-top: 50px;
        border-top: 1px solid #000;
        width: 40%;
        text-align: center;
        page-break-inside: avoid;
    }

    /* --- ORÇAMENTO E ASSINATURA (NÃO QUEBRAR) --- */
    .orcamento-container {
        margin-top: 40px;
        border-top: 1px solid #000;
        padding-top: 10px;
        /* Impede que o bloco se parta ao meio */
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        display: flex; /* Força layout flex */
        width: 100%;
    }
    
    .orcamento-box {
        display: flex;
        justify-content: space-between;
        width: 100%;
        align-items: flex-end;
    }
    
    .orcamento-label { font-weight: bold; font-size: 9pt; text-transform: uppercase; margin-bottom: 2px; }
    .orcamento-value { display: block; font-size: 11pt; margin-bottom: 2px; }
    .orcamento-line { width: 100%; border-bottom: 1px solid #000; }

    #footerPrint { display: flex !important; justify-content: space-between; align-items: flex-end; position: fixed; bottom: 30px; left: 80px; right: 40px; font-size: 8pt; color: #666; border-top: 1px solid #ccc; padding-top: 10px; }
    .footer-left p { margin: 1px 0; }
    .footer-right { text-align: center; min-width: 200px; }
    .signature-line { border-bottom: 1px solid #000; width: 100%; margin-bottom: 5px; }
    .sig-name { font-weight: bold; color: #000; font-size: 10pt; margin: 0; }
    
    .print-only { display: block !important; }
    .upload-grid { display: flex; gap: 10px; margin-bottom: 20px; justify-content: flex-start; }
    .upload-box { width: 120px; height: 120px; border: none; background: transparent; }
    .img-preview { display: block !important; width: 100%; height: 100%; object-fit: cover; border-radius: 2px; }
}