* {
    box-sizing: border-box;
}

:root {
    --primary: #1e3a8a;
    --primary-hover: #172554;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --glass: rgba(255, 255, 255, 0.8);
}

body {
    font-family: 'Outfit', 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.5;
}

.navbar {
    background: var(--card);
    padding: 0.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: none;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.1rem;
}

.nav-logo {
    height: 24px;
    width: auto;
    object-fit: contain;
}

.navbar strong {
    font-size: 2rem;
    color: var(--primary);
}

.nav-links a {
    text-decoration: none;
    color: var(--text-muted);
    margin-left: 1rem;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-links a:hover {
    color: var(--primary);
}

.container {
    max-width: 1000px;
    margin: 0.5rem auto;
    padding: 0 1.5rem;
}

.card {
    background: var(--card);
    padding: 1.25rem;
    border-radius: 1rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.5rem;
    border-radius: 0.6rem;
    border: none;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    font-size: 0.95rem;
    line-height: 1.2;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

table .btn {
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    border-radius: 6px;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.form-group {
    margin-bottom: 0.85rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}

input, select, textarea {
    width: calc(100% - 10px);
    margin: 5px;
    padding: 0.5rem 0.85rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.6rem;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

textarea {
    resize: vertical;
}

.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.alert-error {
    background: #fee2e2;
    color: #991b1b;
}

.alert-success {
    background: #d1fae5;
    color: #065f46;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.75rem;
    font-size: 0.9rem;
}

th {
    text-align: left;
    padding: 0.6rem 0.8rem;
    border-bottom: 2px solid #f1f5f9;
    color: var(--text-muted);
}

td {
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid #f1f5f9;
}

.compact-table th, 
.compact-table td {
    padding: 0.35rem 0.6rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 1rem;
}

@media (max-width: 768px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    /* ── Navbar ── */
    .navbar {
        padding: 0.35rem 1rem;
        gap: 0.5rem;
    }
    .logo img {
        height: 48px !important;
    }
    .logo > a > span {
        display: none;
    }

    /* ── Container ── */
    .container {
        padding: 0 0.4rem;
    }

    /* ─────────────────────────────────────────
       Classes reutilizáveis para telas de paciente
       ───────────────────────────────────────── */

    /* Card principal das telas de paciente */
    .patient-card {
        margin: 0.25rem !important;
        border-radius: 8px !important;
    }

    /* Cabeçalho (nome do paciente + botão Voltar) */
    .patient-header {
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
    }
    .patient-header h2 {
        font-size: 1rem !important;
    }

    /* Barra de abas (Ficha Geral / Endereço / Convênio ...) */
    .patient-tabs {
        flex-wrap: wrap !important;
        gap: 0.25rem !important;
        overflow-x: auto;
    }
    .patient-tabs a {
        padding: 0.5rem 0.4rem !important;
        font-size: 0.85rem !important;
        white-space: nowrap;
    }

    /* Área de conteúdo do card */
    .patient-body {
        padding: 1rem !important;
    }

    /* Grids de dois e mais colunas → coluna única */
    .patient-grid-2,
    .patient-grid-auto {
        grid-template-columns: 1fr !important;
    }

    /* Linha do botão salvar → empilhada */
    .patient-save-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    /* Tabelas → scroll horizontal */
    .table-scroll {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .table-scroll table {
        min-width: 520px;
    }

    /* Linha de exame (flex space-between) */
    .exam-item {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
    }
    .exam-item > div:last-child {
        margin-left: 0 !important;
    }
}


/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    flex-direction: column;
    gap: 1.5rem;
    transition: all 0.3s ease;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: white;
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}