/* ==========================================================================
   1. VARIÁVEIS E CONFIGURAÇÕES GERAIS
   ========================================================================== */
:root {
    --cor-fundo: #e0f7e9;
    --cor-destaque: #ffffff;
    --cor-texto: #333;
    --cor-botao: #4caf50;
    --cor-botao-hover: #388e3c;
    --fonte: 'Segoe UI', sans-serif;

    --cor-titulo-padrao: #2e7d32;
    --cor-titulo-secundario: #0056b3;
    --cor-alerta: #d9534f;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--fonte);
    background-color: var(--cor-fundo);
    color: var(--cor-texto);
    min-height: 100vh;
}

/* ==========================================================================
   2. TELA DE LOGIN / INDEX
   ========================================================================== */
body.index {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px 16px;
}

.index .container {
    max-width: 400px;
    width: 100%;
    background-color: var(--cor-destaque);
    border-radius: 12px;
    padding: 32px 24px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.index .container h2 {
    font-size: 24px;
    margin-bottom: 20px;
}

.index .container a {
    display: inline-block;
    background-color: var(--cor-botao);
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    border-radius: 6px;
    font-size: 16px;
    transition: background-color 0.2s ease;
}

.index .container a:hover {
    background-color: var(--cor-botao-hover);
}

/* ==========================================================================
   3. ESTRUTURA E CONTAINERS PRINCIPAIS
   ========================================================================== */
.container {
    max-width: 900px;
    margin: 20px auto;
    padding: 40px 20px;
    background-color: var(--cor-destaque);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Títulos */
h1, h2, h3 {
    color: var(--cor-titulo-padrao);
    margin-bottom: 16px;
    text-align: center;
}

h2 span {
    color: #4CAF50;
}

h3 strong {
    color: var(--cor-alerta);
}

h4 {
    color: var(--cor-titulo-secundario);
    text-align: center;
    margin-bottom: 15px;
    margin-top: 30px;
}

p {
    text-align: center;
    color: #666;
    margin-top: 15px;
}

hr {
    margin: 40px 0;
    border: 0;
    border-top: 1px solid #eee;
}

/* Cartões Genéricos */
.card, .paciente, .turno {
    background: var(--cor-destaque);
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 18px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Imagens */
img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

/* ==========================================================================
   4. BOTÕES E CAMPOS DE FORMULÁRIO
   ========================================================================== */
button, .btn {
    background-color: var(--cor-botao);
    color: white;
    border: none;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    margin-top: 10px;
    width: 100%;
    transition: background-color 0.2s ease;
}

button:hover, .btn:hover {
    background-color: var(--cor-botao-hover);
}

.botao-link {
    display: inline-block;
    background-color: #2e7d32;
    color: white;
    padding: 10px 16px;
    border-radius: 6px;
    font-weight: bold;
    text-decoration: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.botao-link:hover {
    background-color: #388e3c;
}

input, select, textarea {
    width: 100%;
    padding: 10px;
    margin: 8px 0 14px 0;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 16px;
}

form {
    text-align: center;
    margin-bottom: 30px;
}

form label {
    font-weight: bold;
    margin-right: 10px;
}

form select {
    width: auto;
    display: inline-block;
}

/* ==========================================================================
   5. CABEÇALHO / TOPO E MENUS
   ========================================================================== */
.topo {
    background-color: #2e7d32;
    color: white;
    padding: 10px 0;
    position: sticky;
    top: 0;
    width: 100%;
    z-index: 1000;
}

.topo-container {
    max-width: 960px;
    margin: auto;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.logo {
    font-size: 18px;
    font-weight: bold;
    padding: 8px 0;
}

.usuario {
    font-size: 14px;
    margin-top: 4px;
    color: white;
}

.menu {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-top: 8px;
}

.menu a {
    color: white;
    background-color: rgba(255, 255, 255, 0.1);
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 14px;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.menu a:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

.menu a.sair {
    border: 1px solid #ffcdd2;
    color: #ffcdd2;
    margin-left: auto;
}

.menu a.sair:hover {
    background-color: rgba(255,255,255,0.1);
}

/* Dropdowns */
.dropdown {
    position: relative;
}

.dropbtn {
    background-color: transparent;
    border: none;
    color: white;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    font-weight: bold;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: white;
    color: #333;
    min-width: 160px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    z-index: 1001;
    border-radius: 6px;
    overflow: hidden;
}

.dropdown-content a {
    padding: 10px 12px;
    display: block;
    text-decoration: none;
    color: #2e7d32;
}

.dropdown-content a:hover {
    background-color: #e0f7e9;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown:hover .dropbtn {
    text-decoration: underline;
}

/* ==========================================================================
   6. CARDS DE CONSULTAS E EXAMES (PAINEL ADMIN)
   ========================================================================== */
.consultas-cards {
    display: grid;
    gap: 16px;
    margin-top: 20px;
}

.card-consulta {
    background: #f9f9f9;
    border-left: 4px solid #1e88e5;
    padding: 12px 14px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    font-size: 15px;
    line-height: 1.5;
}

/* ==========================================================================
   7. TABELAS DE RELATÓRIO (DESKTOP)
   ========================================================================== */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    margin-bottom: 20px;
    font-size: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

th, td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

th {
    background-color: #f4f4f4;
    font-weight: bold;
    color: var(--cor-texto);
}

tr:nth-child(even) {
    background-color: #f9f9f9;
}

tr:hover {
    background-color: #f1f1f1;
}

.total {
    font-weight: bold;
    background-color: var(--cor-destaque);
    text-align: right;
}

.total td:last-child {
    text-align: left;
}

/* ==========================================================================
   8. RESPONSIVIDADE MOBILE (max-width: 600px)
   ========================================================================== */
@media (max-width: 600px) {
    /* Ajustes Gerais de Layout no Mobile */
    .container {
        padding: 12px;
        margin: 10px;
    }

    .card {
        padding: 12px;
    }

    button {
        width: 100%;
        font-size: 15px;
        padding: 10px 12px;
    }

    input, select, textarea {
        font-size: 15px;
        padding: 10px;
        margin: 6px 0 12px 0;
    }

    form select {
        width: 90%;
        margin-top: 5px;
    }

    form label {
        display: block;
        margin-bottom: 5px;
    }

    /* Menu Superior Otimizado no Celular (Grade de 2 Colunas) */
    .topo-container {
        flex-direction: column;
        align-items: center;
        padding: 10px 12px;
    }

    .logo {
        font-size: 17px;
        text-align: center;
        margin-bottom: 2px;
    }

    .usuario {
        font-size: 12px;
        margin-bottom: 8px;
        opacity: 0.9;
        text-align: center;
    }

    .menu {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        width: 100%;
        gap: 6px;
        margin-top: 4px;
    }

    .menu a {
        width: auto;
        font-size: 13px;
        text-align: center;
        padding: 8px 6px;
        background-color: rgba(255, 255, 255, 0.12);
        border-radius: 6px;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    /* Botão Sair centralizado e estendido em largura total */
    .menu a.sair {
        grid-column: span 2;
        margin-left: 0;
        margin-top: 2px;
        background-color: rgba(239, 83, 80, 0.15);
        border: 1px solid #ef5350;
        color: #ffcdd2;
    }

    /* 
       TABELAS RESPONSIVAS (Isoladas por classe)
       Nota: Apenas tabelas marcadas com a classe "tabela-relatorio" sofrem a quebra.
       Isso previne interferências nas estruturas internas de menus e rodapés.
    */
    table.tabela-relatorio {
        border: none !important;
        box-shadow: none !important;
    }

    table.tabela-relatorio thead {
        display: none !important;
    }

    table.tabela-relatorio tr {
        margin-bottom: 12px !important;
        border: 1px solid #ddd !important;
        border-radius: 8px !important;
        padding: 10px !important;
        display: block !important;
        background-color: var(--cor-destaque) !important;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06) !important;
    }

    table.tabela-relatorio td {
        position: relative !important;
        padding-left: 50% !important;
        text-align: left !important;
        padding-top: 6px !important;
        padding-bottom: 6px !important;
        border: none !important;
        margin-bottom: 0 !important;
        word-wrap: break-word !important;
        display: block !important;
    }

    table.tabela-relatorio td::before {
        position: absolute !important;
        left: 8px !important;
        top: 6px !important;
        width: 45% !important;
        white-space: nowrap !important;
        font-weight: bold !important;
        color: #555 !important;
        content: attr(data-label) !important;
    }

    /* Totais da tabela estruturados para celular */
    table.tabela-relatorio .total {
        background-color: var(--cor-destaque) !important;
        border: 1px solid #ccc !important;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06) !important;
    }

    table.tabela-relatorio .total td {
        padding-left: 10px !important;
        text-align: right !important;
        border: none !important;
        display: block !important;
    }

    table.tabela-relatorio .total td::before {
        content: none !important;
        display: none !important;
    }

    table.tabela-relatorio .total td:first-child {
        text-align: left !important;
    }

    table.tabela-relatorio .total td:last-child {
        text-align: right !important;
    }
}