/* =============================================================================
   SGC — Diálogo do sistema (confirmação e aviso)
   -----------------------------------------------------------------------------
   Substitui as caixas nativas do navegador — aquelas com "192.168.1.90:5051
   diz" no topo, botão verde do sistema operacional e nenhuma relação com o
   resto da tela.

   Mesma linguagem do .dialog que já existe em sgc.css (o "Enviar para
   autorização?"), só que montado pelo JS e disponível em qualquer tela.
   Os tokens têm fallback em hex porque as telas antigas não carregam sga.css.

   Carregado em todas as bases: o dialogo.js troca o window.alert por este, de
   modo que as 218 chamadas espalhadas pelo sistema passam a usá-lo sem que
   nenhuma delas precise ser reescrita.
============================================================================= */
.dlg-fundo {
    position: fixed;
    inset: 0;
    z-index: 10000;              /* acima dos modais, que ficam em 1000-1010 */
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(20, 28, 38, .45);
    animation: dlg-surge .12s ease-out;
}
.dlg-fundo[hidden] { display: none; }

.dlg {
    width: min(420px, 100%);
    padding: 18px;
    background: var(--surface, #fff);
    border: 1px solid var(--border, #e2e5ea);
    border-radius: var(--r-10, 10px);
    box-shadow: 0 16px 48px rgba(20, 28, 38, .22);
    font-family: var(--font, 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif);
    animation: dlg-entra .14s ease-out;
}

.dlg-titulo {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--ink, #1c2126);
}

.dlg-texto {
    margin: 8px 0 0;
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--ink-2, #4a535e);
    white-space: pre-line;       /* preserva as quebras dos alert() antigos */
    overflow-wrap: anywhere;
}
.dlg-texto:empty { display: none; }

/* Destaque do que será afetado — nome do arquivo, do paciente, do registro. */
.dlg-alvo {
    margin-top: 12px;
    padding: 10px 12px;
    font-size: 12.5px;
    color: var(--ink, #1c2126);
    background: var(--surface-2, #f7f8fa);
    border: 1px solid var(--divider, #eef0f3);
    border-radius: var(--r-8, 8px);
    overflow-wrap: anywhere;
}

/* perguntar(): campo de resposta, no lugar do prompt do navegador. */
.dlg-campo {
    display: block;
    width: calc(100% - 40px);
    margin: 14px 20px 0;
    box-sizing: border-box;
    padding: 9px 11px;
    font: inherit;
    font-size: 13.5px;
    color: var(--ink, #1c2126);
    border: 1px solid var(--border-field, #d7dbe1);
    border-radius: var(--r-8, 8px);
    resize: vertical;
    min-height: 70px;
}
.dlg-campo:focus {
    outline: none;
    border-color: var(--primary-light, #418ad1);
    box-shadow: 0 0 0 3px rgba(42, 117, 186, .14);
}

.dlg-acoes {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 18px;
}

/* Botões próprios: as telas chamam a primária ora de .btn-primary, ora de
   .btn--primary, e este diálogo aparece nas duas gerações. */
.dlg-btn {
    padding: 8px 14px;
    font: inherit;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.2;
    color: var(--ink, #1c2126);
    background: var(--surface, #fff);
    border: 1px solid var(--border-field, #d7dbe1);
    border-radius: var(--r-8, 8px);
    cursor: pointer;
}
.dlg-btn:hover { background: var(--surface-2, #f7f8fa); }
.dlg-btn:focus-visible {
    outline: 2px solid var(--primary, #3d5fa8);
    outline-offset: 2px;
}

.dlg-btn--ok {
    border-color: transparent;
    background: var(--primary, #3d5fa8);
    color: #fff;
    font-weight: 600;
}
.dlg-btn--ok:hover { background: var(--primary-hover, #32508f); }

/* Vermelho só para o que destrói. É o que separa "Remover este anexo?" de
   "Enviar para autorização?" antes de o usuário ler a frase. */
.dlg-btn--perigo {
    border-color: transparent;
    background: var(--alert-ink, #b3261e);
    color: #fff;
    font-weight: 600;
}
/* Precisa repetir o background: .dlg-btn:hover tem especificidade maior que
   .dlg-btn--perigo e, sem esta linha, o vermelho virava cinza sob o cursor. */
.dlg-btn--perigo:hover {
    background: var(--alert-ink, #b3261e);
    filter: brightness(.88);
}

@media (max-width: 480px) {
    .dlg-acoes { flex-direction: column-reverse; }
    .dlg-acoes .dlg-btn { width: 100%; }
}

@keyframes dlg-surge { from { opacity: 0 } to { opacity: 1 } }
@keyframes dlg-entra { from { opacity: 0; transform: translateY(-6px) } to { opacity: 1; transform: none } }

@media (prefers-reduced-motion: reduce) {
    .dlg-fundo, .dlg { animation: none; }
}

/* =============================================================================
   Confirmação: ícone ao lado da pergunta, rodapé com os botões
============================================================================= */
.dlg { padding: 0; overflow: hidden; }
.dlg-cab { display: flex; gap: 14px; padding: 20px 20px 0; }
.dlg-textos { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.dlg-textos .dlg-titulo { margin: 0; }
.dlg-textos .dlg-texto { margin: 0; font-size: 13px; }
.dlg-icone {
    width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font: 700 17px/1 var(--font, 'IBM Plex Sans', system-ui, sans-serif);
}
.dlg-icone--perigo { background: var(--alert-bg, #ffe3db); color: var(--alert-ink, #af2c1f); }
.dlg-icone--info { background: var(--info-bg, #e0f1ff); color: var(--info-ink, #004f8b); }
.dlg-alvo { margin: 14px 20px 0; }
.dlg-acoes {
    margin-top: 18px; padding: 12px 20px;
    background: var(--surface-2, #f7f8fa); border-top: 1px solid var(--divider, #eef0f3);
}

/* =============================================================================
   Avisos no canto (notificações)
   Empilhados no canto superior direito, sem fundo escuro: a tela continua
   usável. O de erro não tem barra de tempo porque não some sozinho.
============================================================================= */
.ntf-pilha {
    position: fixed; top: 16px; right: 16px; z-index: 10001;
    width: min(380px, calc(100vw - 32px));
    display: flex; flex-direction: column; gap: 10px;
    pointer-events: none;
}
.ntf {
    position: relative; overflow: hidden; pointer-events: auto;
    display: flex; align-items: flex-start; gap: 12px;
    padding: 12px 10px 14px 14px;
    background: var(--surface, #fff); border: 1px solid var(--border, #e2e5ea);
    border-radius: 10px; box-shadow: 0 10px 28px rgba(20, 28, 38, .16);
    font-family: var(--font, 'IBM Plex Sans', system-ui, sans-serif);
    animation: ntf-entra .18s ease-out;
}
.ntf.is-saindo { opacity: 0; transform: translateX(12px); transition: opacity .18s, transform .18s; }
@keyframes ntf-entra { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.ntf-icone {
    width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 15px; font-weight: 700; line-height: 1;
}
.ntf-corpo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ntf-titulo { font-size: 13.5px; font-weight: 600; color: var(--ink, #1c2126); overflow-wrap: anywhere; }
.ntf-texto { font-size: 12.5px; line-height: 1.45; color: var(--ink-2, #4a535e); white-space: pre-line; overflow-wrap: anywhere; }
.ntf-acao {
    align-self: flex-start; margin-top: 4px; padding: 0; border: 0; background: none;
    font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer; color: currentColor;
}
.ntf-fechar {
    width: 26px; height: 26px; flex-shrink: 0; border: 0; border-radius: 6px; background: transparent;
    font-size: 18px; line-height: 1; color: var(--label, #8e969f); cursor: pointer;
}
.ntf-fechar:hover { background: var(--surface-2, #f7f8fa); color: var(--ink, #1c2126); }
.ntf-fechar:focus-visible, .ntf-acao:focus-visible { outline: none; box-shadow: var(--focus, 0 0 0 3px rgba(42, 117, 186, .2)); }
.ntf-barra {
    position: absolute; left: 0; bottom: 0; height: 3px; width: 100%;
    background: currentColor; opacity: .35; transform-origin: left;
    animation: ntf-tempo linear forwards;
}
@keyframes ntf-tempo { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.ntf--ok { color: var(--success-hover, #00723b); }
.ntf--ok .ntf-icone { background: oklch(0.95 0.04 155); }
.ntf--info { color: var(--info-ink, #004f8b); }
.ntf--info .ntf-icone { background: var(--info-bg, #e0f1ff); }
.ntf--atencao { color: var(--warn-ink, #7b4800); }
.ntf--atencao .ntf-icone { background: var(--warn-bg, #fbedd1); }
.ntf--erro { color: var(--alert-ink, #af2c1f); border-color: #f5c9bd; }
.ntf--erro .ntf-icone { background: var(--alert-bg, #ffe3db); }

@media (prefers-reduced-motion: reduce) {
    .ntf, .ntf.is-saindo { animation: none; transition: none; }
    .ntf-barra { animation: none; display: none; }
}
