/*
 * Seven Pharma — identidade visual do Roxinho 4.
 * DM Sans auto-hospedada: sem CDN, CSP fechada. Roxo só para ação e posição;
 * âmbar = pendente, verde = concluído, vermelho só para erro.
 */
@font-face {
    font-family: "DM Sans";
    src: url("../fonts/dm-sans-variable.woff2") format("woff2");
    font-weight: 100 1000;
    font-display: swap;
}

:root {
    --roxo-950: #290140;
    --roxo-800: #420c5d;
    --roxo-700: #5d2a7e;
    --roxo-600: #713f8d;
    --roxo-500: #8c59a4;
    --roxo-100: #efe7f5;
    --roxo-50: #f6f1f9;

    --grafite-900: #2c3032;
    --grafite-600: #5c6164;
    --grafite-400: #8b8f92;
    --grafite-200: #d9dbdd;
    --grafite-100: #ebecee;
    --grafite-50: #f4f5f6;

    --offwhite: #f7f5f8;

    --ambar-texto: #b45309;
    --ambar-fundo: #fef3c7;
    --verde-texto: #15803d;
    --verde-fundo: #dcfce7;
    --vermelho-texto: #b91c1c;
    --vermelho-fundo: #fef2f2;

    --raio: 8px;
    --raio-grande: 16px;
    --sombra-cartao: 0 12px 34px rgba(74, 37, 105, 0.09);
    --foco: 0 0 0 3px rgba(93, 42, 126, 0.3);
    --fonte: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--offwhite);
    color: var(--grafite-900);
    font-family: var(--fonte);
    font-size: 14px;
    line-height: 1.5;
}
body.com-modal { overflow: hidden; }
h1, h2, p { margin: 0; }
a { color: var(--roxo-700); }
a:focus-visible, button:focus-visible { outline: 2px solid var(--roxo-700); outline-offset: 2px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.tabular { font-variant-numeric: tabular-nums; }
.texto-auxiliar { color: var(--grafite-400); }
.link { color: var(--roxo-700); font-weight: 600; text-decoration: none; }
.link:hover { color: var(--roxo-600); text-decoration: underline; }

/* Botões */
.botao {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 36px; padding: 8px 14px;
    border: 1px solid transparent; border-radius: var(--raio);
    font: inherit; font-size: 13px; font-weight: 600; line-height: 1.2;
    text-decoration: none; white-space: nowrap; cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}
.botao--primario { background: var(--roxo-700); color: #fff; }
.botao--primario:hover { background: var(--roxo-600); }
.botao--secundario { background: #fff; color: var(--roxo-700); border-color: var(--roxo-100); }
.botao--secundario:hover { background: var(--roxo-50); border-color: var(--roxo-500); }
.botao--fantasma { background: transparent; color: var(--grafite-600); }
.botao--fantasma:hover { background: var(--grafite-50); color: var(--grafite-900); }
.botao--bloco { width: 100%; }
.botao:disabled, .botao--desabilitado { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* Formulários */
.form { display: grid; gap: 16px; }
.campo { display: grid; gap: 6px; }
.campo__rotulo {
    font-size: 12px; font-weight: 600; letter-spacing: .04em;
    text-transform: uppercase; color: var(--grafite-600);
}
.campo__entrada {
    width: 100%; min-height: 40px; padding: 9px 12px;
    border: 1px solid var(--roxo-100); border-radius: var(--raio);
    background: #fff; color: var(--grafite-900);
    font: inherit; font-size: 14px;
}
.campo__entrada::placeholder { color: var(--grafite-400); }
.campo__entrada:focus { outline: none; border-color: var(--roxo-700); box-shadow: var(--foco); }
.campo__entrada[aria-invalid="true"] { border-color: var(--vermelho-texto); }
.campo__entrada[readonly] { background: var(--grafite-50); color: var(--grafite-600); }
.campo__erro { font-size: 12px; color: var(--vermelho-texto); }
.campo__erro:empty { display: none; }

/* Alertas */
.alerta { padding: 10px 12px; border-radius: var(--raio); font-size: 13px; }
.alerta--erro { background: var(--vermelho-fundo); color: var(--vermelho-texto); }
.alerta--sucesso { background: var(--verde-fundo); color: var(--verde-texto); }
.alerta--info { background: var(--roxo-50); color: var(--roxo-700); }

/* Login e páginas de erro */
.pagina-login {
    min-height: 100vh;
    display: grid; place-items: center;
    padding: 24px 16px;
    background: radial-gradient(ellipse at top, var(--roxo-50), var(--offwhite) 60%);
}
.login { width: 100%; max-width: 384px; }
.login__cartao {
    position: relative; overflow: hidden;
    padding: 40px 32px 32px;
    background: #fff;
    border: 1px solid var(--grafite-100); border-radius: var(--raio-grande);
    box-shadow: var(--sombra-cartao);
}
.login__cartao::before {
    content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, var(--roxo-950), var(--roxo-800), var(--roxo-500));
}
.login__logo { display: block; height: 32px; width: auto; margin: 0 auto; }
.login__titulo { margin-top: 24px; text-align: center; font-size: 18px; font-weight: 700; }
.login__subtitulo { margin: 12px 0 28px; text-align: center; color: var(--grafite-600); font-size: 13px; }
.login .alerta { margin-bottom: 16px; }
.login .form .alerta { margin-bottom: 0; }
.login__rodape { margin-top: 16px; text-align: center; font-size: 12px; color: var(--grafite-400); }

/* Barra superior */
.topo {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    height: 56px; padding: 0 24px;
    background: #fff; border-bottom: 1px solid var(--grafite-100);
}
.topo__logo { height: 24px; width: auto; }
.topo__acoes { display: flex; align-items: center; gap: 12px; }
.topo__rotulo { font-size: 13px; color: var(--grafite-600); }
.topo form { margin: 0; }

/* Página */
.pagina { max-width: 1440px; margin: 0 auto; padding: 28px 24px 48px; }
.pagina__cabecalho {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 20px;
}
.pagina__titulo { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.pagina > .alerta { margin-bottom: 16px; }

/* Busca */
.busca { display: flex; align-items: center; gap: 8px; flex: 1 1 320px; max-width: 480px; }
.busca__entrada { flex: 1; }
.busca__limpar { font-size: 13px; color: var(--grafite-600); white-space: nowrap; }

/* Abas */
.abas {
    display: flex; gap: 4px; margin-bottom: 16px;
    border-bottom: 0; box-shadow: inset 0 -1px 0 var(--grafite-200);
    overflow-x: auto; overflow-y: hidden;
}
.aba {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    border-bottom: 2px solid transparent;
    color: var(--grafite-600); font-weight: 600; text-decoration: none; white-space: nowrap;
}
.aba:hover { color: var(--grafite-900); }
.aba--ativa { color: var(--roxo-700); border-bottom-color: var(--roxo-700); }
.aba__contador {
    min-width: 22px; padding: 1px 7px; border-radius: 999px;
    background: var(--grafite-100); color: var(--grafite-600);
    font-size: 12px; text-align: center; font-variant-numeric: tabular-nums;
}
.aba--ativa .aba__contador { background: var(--roxo-100); color: var(--roxo-700); }

/* Tabela */
.tabela-caixa {
    background: #fff; border: 1px solid var(--grafite-100); border-radius: var(--raio-grande);
    box-shadow: var(--sombra-cartao); overflow-x: auto;
}
.tabela { width: 100%; border-collapse: collapse; }
.tabela th {
    padding: 12px 14px; text-align: left; white-space: nowrap;
    font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
    color: var(--grafite-600); background: var(--grafite-50);
    border-bottom: 1px solid var(--grafite-100);
}
.tabela td { padding: 12px 14px; border-bottom: 1px solid var(--grafite-100); vertical-align: middle; }
.tabela tbody tr:last-child td { border-bottom: 0; }
.tabela tbody tr:hover { background: var(--grafite-50); }
.tabela td.tabular { white-space: nowrap; }
.tabela__destaque { font-weight: 600; }
.tabela__endereco {
    max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--grafite-600);
}
.tabela__acao { text-align: right; white-space: nowrap; }
.tabela .link { white-space: nowrap; }

/* Selos de status */
.selo {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.selo::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.selo--pendente { background: var(--ambar-fundo); color: var(--ambar-texto); }
.selo--producao { background: var(--roxo-100); color: var(--roxo-700); }
.selo--concluido { background: var(--verde-fundo); color: var(--verde-texto); }
.status { display: grid; gap: 4px; justify-items: start; }
.status__producao { display: grid; font-size: 12px; color: var(--grafite-600); white-space: nowrap; }
.tabela__acao form { margin: 0; }

/* Estado vazio e paginação */
.vazio {
    padding: 48px 16px; text-align: center;
    background: #fff; border: 1px dashed var(--grafite-200); border-radius: var(--raio-grande);
    color: var(--grafite-600);
}
.vazio .link { display: inline-block; margin-top: 8px; }
.paginacao { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 16px; }
.paginacao__info { color: var(--grafite-600); font-size: 13px; }

/* Celular e tablet: tabela vira cartões */
@media (max-width: 900px) {
    .topo { padding: 0 16px; }
    .topo__rotulo { display: none; }
    .pagina { padding: 20px 16px 40px; }
    .busca { max-width: none; flex-basis: 100%; }

    .tabela-caixa { background: transparent; border: 0; box-shadow: none; overflow: visible; }
    .tabela thead {
        position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
    }
    .tabela, .tabela tbody, .tabela tr, .tabela td { display: block; width: 100%; }
    .tabela tr {
        margin-bottom: 12px; padding: 14px 16px;
        background: #fff; border: 1px solid var(--grafite-100); border-radius: var(--raio-grande);
        box-shadow: var(--sombra-cartao);
    }
    .tabela tbody tr:hover { background: #fff; }
    .tabela td { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 6px 0; border: 0; }
    .tabela td::before {
        content: attr(data-rotulo); padding-top: 2px;
        font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
        color: var(--grafite-400);
    }
    .tabela__endereco { max-width: none; white-space: normal; }
    .tabela td.tabela__acao { display: block; padding-top: 12px; text-align: left; }
    .tabela td.tabela__acao::before { content: none; }
    .tabela__acao .botao { width: 100%; }
    .paginacao { justify-content: space-between; }
    .tabela td > .selo, .tabela td > .link, .tabela td > .status { justify-self: start; }
}

/* Celular e telas estreitas: as quatro abas só cabem com o nome curto (Aguardando, Produção) */
@media (max-width: 640px) {
    .abas { gap: 0; }
    .aba {
        flex: 1 1 0; min-width: 0; flex-direction: column; align-items: center; gap: 4px;
        padding: 8px 4px; text-align: center;
    }
    .aba__contador { min-width: 20px; padding: 1px 6px; }
    .aba__extra {
        position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
        overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
    }
    .aba__nucleo { text-transform: capitalize; }
}
@media (max-width: 360px) {
    .aba { flex: 1 1 auto; padding: 8px 2px; font-size: 13px; }
}

/* Modal de envio */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal__fundo { position: absolute; inset: 0; background: rgba(41, 1, 64, 0.45); }
.modal__caixa {
    position: relative; width: 100%; max-width: 460px; max-height: calc(100vh - 32px); overflow-y: auto;
    padding: 24px; background: #fff; border-radius: var(--raio-grande);
    box-shadow: 0 24px 60px rgba(41, 1, 64, 0.25);
}
.modal__cabecalho { position: relative; margin-bottom: 20px; padding-right: 36px; }
.modal__titulo { font-size: 18px; font-weight: 700; }
.modal__subtitulo { margin-top: 2px; color: var(--grafite-600); }
.modal__fechar {
    position: absolute; top: -6px; right: -6px; width: 32px; height: 32px;
    border: 0; border-radius: var(--raio); background: transparent;
    color: var(--grafite-600); font-size: 22px; line-height: 1; cursor: pointer;
}
.modal__fechar:hover { background: var(--grafite-50); color: var(--grafite-900); }
.modal__confirmacao {
    padding: 12px; border-radius: var(--raio);
    background: var(--ambar-fundo); color: var(--ambar-texto); font-size: 13px; font-weight: 500;
}
.modal__rodape { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 8px; }
#leitura-envio .modal__rodape { margin-top: 24px; }
.leitura { display: grid; gap: 14px; margin: 0; }
.leitura__linha { display: grid; gap: 2px; }
.leitura dt {
    font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--grafite-600);
}
.leitura dd { margin: 0; overflow-wrap: anywhere; }

/* Cadastro de prescrição */
.topo__marca { display: inline-flex; }
.topo__cadastrar { min-height: 32px; padding: 6px 12px; }
.pagina--estreita { max-width: 720px; }
.voltar { display: inline-block; margin-bottom: 8px; font-size: 13px; color: var(--grafite-600); text-decoration: none; }
.voltar:hover { color: var(--roxo-700); }
.cartao-form {
    margin-top: 16px; padding: 24px; gap: 28px;
    background: #fff; border: 1px solid var(--grafite-100); border-radius: var(--raio-grande);
    box-shadow: var(--sombra-cartao);
}
.grupo { display: grid; gap: 16px; margin: 0; padding: 0; border: 0; min-width: 0; }
.grupo legend { padding: 0; margin-bottom: 12px; font-size: 15px; font-weight: 700; color: var(--grafite-900); }
.linha-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
textarea.campo__entrada { resize: vertical; min-height: 76px; line-height: 1.5; }
.campo__arquivo { padding: 7px 10px; }
.campo__ajuda { font-size: 12px; color: var(--grafite-400); }
.form__acoes { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

@media (max-width: 600px) {
    .linha-2 { grid-template-columns: 1fr; }
    .cartao-form { padding: 18px; }
}
@media (max-width: 480px) {
    .topo__cadastrar-extra { display: none; }
}

/* Coluna Venda da listagem */
.venda { display: grid; gap: 2px; }
.venda__id { font-weight: 600; white-space: nowrap; }
.venda__data { font-size: 12px; color: var(--grafite-600); }
.venda__tratamento {
    max-width: 170px; margin-top: 2px; font-size: 12px; line-height: 1.35; color: var(--grafite-900);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
@media (max-width: 900px) {
    .venda__tratamento { max-width: none; -webkit-line-clamp: unset; display: block; }
}

/* Coluna Paciente: nome, CPF e telefone */
.paciente { display: grid; gap: 2px; }
.paciente__nome { font-weight: 600; }
.paciente__dado { font-size: 12px; color: var(--grafite-600); white-space: nowrap; }
