body {
    font-family: Arial, sans-serif;
    margin: 20px;
    background-color: #f9f9f9;
    color: #333;
}

.page-header {
    text-align: center;
    margin-bottom: 20px;
}

.page-header h1 {
    margin: 0;
}

.clinica-logo {
    display: block;
    max-width: min(320px, 90vw);
    max-height: 120px;
    width: auto;
    height: auto;
    margin: 0 auto 10px;
    object-fit: contain;
}

.clinica-nome {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 600;
    color: #555;
}

.page-header.has-branding h1 {
    font-size: 22px;
    margin-top: 4px;
}

h1 {
    color: #007BFF;
    font-size: 24px;
    text-align: center;
    margin-bottom: 20px;
}

form {
    max-width: 400px;
    margin: 0 auto;
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

input {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

button {
    width: 100%;
    padding: 12px;
    background-color: #007BFF;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
}

button:hover {
    background-color: #0056b3;
}

button:disabled {
    background-color: #aaa;
    cursor: not-allowed;
}

#results {
    max-width: 800px;
    margin: 20px auto;
    padding: 20px;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#results h2 {
    margin: 0;
    color: #007BFF;
}

.patient-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.patient-header .btn-secondary {
    width: auto;
    padding: 8px 16px;
    font-size: 14px;
    background-color: #6c757d;
}

.patient-header .btn-secondary:hover {
    background-color: #5a6268;
}

.password-panel {
    margin-bottom: 20px;
    padding: 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #f8f9fa;
}

.password-panel h3 {
    margin: 0 0 12px;
    font-size: 16px;
    color: #333;
}

.password-panel input {
    max-width: 320px;
}

.password-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.password-panel-actions button {
    width: auto;
    min-width: 140px;
    padding: 10px 16px;
    font-size: 14px;
}

.password-msg {
    margin: 12px 0 0;
    font-size: 14px;
}

.success-msg {
    color: #155724;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

th, td {
    padding: 10px;
    text-align: left;
    border: 1px solid #ddd;
    vertical-align: middle;
}

#resultsTable {
    table-layout: auto;
}

#resultsTable th:last-child,
#resultsTable td.action-buttons {
    width: 1%;
    white-space: nowrap;
    padding-right: 10px;
}

th {
    background-color: #f4f4f4;
    font-weight: bold;
}

td {
    background-color: #fafafa;
}

.action-buttons {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
}

td.action-buttons > .icon-btn {
    width: 42px;
    min-width: 42px;
    max-width: 42px;
    margin: 0;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    flex: 0 0 auto;
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.icon-btn:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    filter: grayscale(35%);
    box-shadow: none;
    transform: none;
}

.icon-btn:disabled:hover {
    transform: none;
}

.images-btn:disabled {
    background-color: #28a745;
}

.images-btn:disabled:hover {
    background-color: #28a745;
}

.laudo-btn:disabled {
    background-color: #17a2b8;
}

.laudo-btn:disabled:hover {
    background-color: #17a2b8;
}

.download-btn:disabled {
    background-color: #6c757d;
}

.download-btn:disabled:hover {
    background-color: #6c757d;
}

.icon-btn--loading svg {
    animation: icon-spin 0.8s linear infinite;
}

@keyframes icon-spin {
    to {
        transform: rotate(360deg);
    }
}

.images-btn {
    background-color: #28a745;
}

.images-btn:hover {
    background-color: #218838;
}

.laudo-btn {
    background-color: #17a2b8;
}

.laudo-btn:hover {
    background-color: #138496;
}

.download-btn {
    background-color: #6c757d;
}

.download-btn:hover {
    background-color: #5a6268;
}

.download-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background-color: rgba(0, 0, 0, 0.45);
}

.download-modal[hidden] {
    display: none;
}

.download-modal-box {
    width: 100%;
    max-width: 360px;
    padding: 24px;
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.download-modal-box h3 {
    margin: 0 0 8px;
}

.download-modal-box p {
    margin: 0 0 20px;
    color: #555;
}

.download-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.download-modal-actions button {
    width: 100%;
}

.loading {
    text-align: center;
    color: #666;
    padding: 40px;
}

#autoLoading {
    display: none;
}

html.autologin-ativo #loginForm {
    display: none !important;
}

html.autologin-ativo #autoLoading {
    display: block !important;
}

.error-msg {
    color: #c00;
    text-align: center;
    margin-top: 20px;
}

.status-msg {
    max-width: 400px;
    margin: 0 auto 16px;
    padding: 12px 16px;
    border-radius: 6px;
    text-align: center;
    font-size: 15px;
}

.status-msg.erro {
    color: #842029;
    background: #f8d7da;
    border: 1px solid #f5c2c7;
}

.status-msg.aguarde {
    color: #084298;
    background: #cfe2ff;
    border: 1px solid #b6d4fe;
}

.back-link {
    display: block;
    text-align: center;
    margin-top: 20px;
    color: #007BFF;
}

.table-wrap {
    width: 100%;
}

@media (max-width: 640px) {
    body {
        margin: 12px;
    }

    h1 {
        font-size: 20px;
    }

    form,
    #results {
        padding: 16px;
    }

    input,
    select,
    textarea {
        font-size: 16px;
    }

    button {
        min-height: 44px;
    }

    .patient-header {
        flex-direction: column;
        align-items: stretch;
    }

    .patient-header h2 {
        font-size: 18px;
        text-align: center;
    }

    .patient-header .btn-secondary {
        width: 100%;
        min-height: 44px;
    }

    .password-panel input {
        max-width: none;
    }

    .password-panel-actions {
        flex-direction: column;
    }

    .password-panel-actions button {
        width: 100%;
    }

    #resultsTable thead {
        display: none;
    }

    #resultsTable tbody tr {
        display: block;
        margin-bottom: 14px;
        border: 1px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        background-color: #fafafa;
    }

    #resultsTable tbody td {
        display: block;
        border: none;
        border-bottom: 1px solid #eee;
        padding: 12px;
    }

    #resultsTable tbody td:last-child {
        border-bottom: none;
    }

    #resultsTable tbody td::before {
        content: attr(data-label);
        display: block;
        font-size: 12px;
        font-weight: bold;
        color: #666;
        margin-bottom: 4px;
        text-transform: uppercase;
        letter-spacing: 0.02em;
    }

    #resultsTable tbody td[colspan] {
        text-align: center;
    }

    #resultsTable tbody td[colspan]::before {
        display: none;
    }

    #resultsTable tbody td.action-buttons {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 8px;
    }

    #resultsTable tbody td.action-buttons::before {
        flex: 0 0 100%;
        text-align: left;
    }

    td.action-buttons > .icon-btn {
        width: 44px;
        min-width: 44px;
        max-width: 44px;
        flex: 0 0 auto;
    }
}
