/* ==========================================================================
   Pesquisa em todo o Haver, 2026-10-13: Components/Shared/CommandPalette.razor e wwwroot/js/palette.js. Uma janela branca por cima de
   tudo (z-index 170: acima das janelas, 100, e da consulta de fichas, 150; abaixo dos tutoriais, 180, e do quadro de espera, 200),
   com o fundo escuro .palette-backdrop — que só existe com a janela aberta (o painel lateral e o modo foco contam com ele). Nos ecrãs
   largos abre presa ao campo da barra de topo, à direita (2026-10-14, html.palette-anchored); sem ele, 720px no topo do ecrã, ao
   centro. Resultados por grupos, um mosaico de ícone por tipo, o que bateu certo realçado e a linha escolhida com «↵ abrir»; no
   rodapé, as teclas. Nos telemóveis ocupa o ecrã.
   ========================================================================== */
.palette-backdrop {
    position: fixed;
    inset: 0;
    z-index: 170;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 12vh 16px 16px;
    background: rgba(15, 23, 42, .5);
    animation: palette-fade .12s ease-out;
}

/* A página por baixo não rola enquanto a janela está aberta. */
html:has(.palette-backdrop) { overflow: hidden; }

/* Presa ao campo «Procurar» da barra de topo (ecrãs largos; palette.js mede o campo e põe html.palette-anchored): a janela abre por
   cima dele, encostada à direita como ele, com 640px, e o fundo escurece menos (é a lista do campo, não um aviso). */
@media (min-width: 861px) {
    html.palette-anchored .palette-backdrop { justify-content: flex-end; padding: var(--palette-top, 9px) var(--palette-right, 16px) 16px 16px; background: rgba(15, 23, 42, .22); }
    html.palette-anchored .palette { width: 640px; max-height: calc(100vh - var(--palette-top, 9px) - 16px); max-height: calc(100dvh - var(--palette-top, 9px) - 16px); border-radius: 12px; }
}

.palette {
    display: flex;
    flex-direction: column;
    width: 720px;
    max-width: 100%;
    max-height: calc(88vh - 16px);
    max-height: calc(88dvh - 16px);
    overflow: hidden;
    background: var(--surface);
    color: var(--ink);
    border-radius: 14px;
    box-shadow: 0 24px 64px rgba(15, 23, 42, .35), 0 2px 8px rgba(15, 23, 42, .12);
    animation: palette-in .14s ease-out;
}

/* ---- Caixa de pesquisa */
.palette__search { display: flex; align-items: center; gap: .65rem; padding: .85rem .85rem .85rem 1.1rem; border-bottom: 1px solid var(--line); }
.palette__search-icon { width: 20px; height: 20px; flex: none; color: var(--muted); }
/* «.palette .palette__input» ganha às caixas de texto da aplicação (app.css: input[type="text"] com borda, preenchimento e contorno ao
   escrever): aqui a caixa é a própria janela. */
.palette .palette__input,
.palette .palette__input:focus { flex: 1; width: auto; min-width: 0; min-height: 0; padding: .2rem 0; border: 0; border-radius: 0; outline: 0; box-shadow: none; background: transparent; color: var(--ink); font: inherit; font-size: 1.08rem; }
.palette__input::placeholder { color: var(--muted); opacity: 1; }
.palette__busy { flex: none; }
.palette__close { display: inline-grid; place-items: center; flex: none; width: 30px; height: 30px; padding: 0; border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); cursor: pointer; }
.palette__close:hover { background: var(--surface-2); color: var(--ink); }
.palette__close-icon { width: 16px; height: 16px; }

/* ---- Pílulas: Tudo · Fichas · Documentos · Lançamentos · Contas · Páginas, com a contagem */
.palette__pills { display: flex; gap: .35rem; padding: .55rem 1.1rem; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.palette__pills::-webkit-scrollbar { display: none; }
.palette__pill { display: inline-flex; align-items: center; gap: .35rem; flex: none; padding: .2rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-2); font: inherit; font-size: .84rem; font-weight: 600; white-space: nowrap; cursor: pointer; }
.palette__pill:hover { border-color: var(--line-2); background: var(--surface-2); }
.palette__pill.is-on { border-color: var(--navy); background: var(--navy); color: #fff; }
.palette__pill.is-empty:not(.is-on) { color: var(--muted); }
.palette__count { padding: 0 .4rem; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-size: .74rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.palette__pill.is-on .palette__count { background: rgba(255, 255, 255, .18); color: #fff; }

/* ---- Resultados */
.palette__results { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: .3rem .5rem .6rem; }
.palette__group + .palette__group { margin-top: .25rem; }
.palette__group-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem .6rem .3rem; color: var(--muted); font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.palette__more { padding: 0; border: 0; background: none; color: var(--brand); font: inherit; font-size: .78rem; font-weight: 600; letter-spacing: 0; text-transform: none; cursor: pointer; }
.palette__more:hover { text-decoration: underline; }

.palette__item { display: flex; align-items: center; gap: .7rem; min-width: 0; padding: .5rem .6rem; border-radius: 10px; color: var(--ink); text-decoration: none; cursor: pointer; }
.palette__item:hover { text-decoration: none; }
.palette__item.is-active { background: var(--brand-tint); box-shadow: inset 0 0 0 1px rgba(var(--brand-rgb), .28); }

/* Mosaico do ícone, com a cor do tipo: atalhos, fichas, documentos, lançamentos, contas e páginas. */
.palette__tile { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2); color: var(--ink-2); }
.palette__icon { width: 18px; height: 18px; }
.palette__tile--action { background: var(--brand-soft); color: var(--brand-ink); }
.palette__tile--record { background: var(--info-soft); color: var(--info); }
.palette__tile--document { background: var(--warn-tint); color: #b45309; }
.palette__tile--entry { background: var(--ok-soft); color: #15803d; }
.palette__tile--account { background: var(--tab-bg); color: var(--tab-icon); }
.palette__tile--page { background: var(--surface-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); }

.palette__main { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.palette__title { display: flex; align-items: baseline; gap: .45rem; min-width: 0; font-size: .95rem; font-weight: 600; }
.palette__code { flex: none; color: var(--ink-2); font-family: var(--font-mono); font-size: .82rem; font-weight: 500; }
.palette__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__detail { overflow: hidden; color: var(--muted); font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
/* À direita: a etiqueta do estado e o valor (nos telemóveis, um por cima do outro, para o nome ter mais lugar). */
.palette__side { display: flex; flex: none; align-items: center; gap: .6rem; }
.palette__badge { flex: none; padding: .05rem .5rem; border-radius: 999px; background: var(--warn-tint); color: #92400e; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.palette__amount { flex: none; font-size: .9rem; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.palette__enter { flex: none; visibility: hidden; color: var(--brand-ink); font-size: .75rem; font-weight: 600; white-space: nowrap; }
.palette__item.is-active .palette__enter { visibility: visible; }

/* O que bateu certo com a pesquisa. */
.palette mark { padding: 0 1px; border-radius: 3px; background: #fde68a; color: inherit; }

.palette__note { margin: 0; padding: 1rem .75rem; color: var(--muted); font-size: .9rem; }
.palette__note--error { color: var(--danger); }

/* ---- Rodapé com as teclas e a empresa em que se procura */
.palette__foot { display: flex; align-items: center; gap: .5rem; padding: .55rem 1.1rem; border-top: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font-size: .78rem; }
.palette__foot kbd { display: inline-block; min-width: 1.4em; padding: 0 .35rem; border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); color: var(--ink-2); font-family: var(--font-sans); font-size: .72rem; line-height: 1.45; text-align: center; }
.palette__company { max-width: 45%; margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@keyframes palette-fade { from { opacity: 0; } }
@keyframes palette-in { from { opacity: 0; transform: translateY(-6px) scale(.99); } }

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

/* Telemóveis: a janela ocupa o ecrã; sem teclado físico, o rodapé das teclas e o «↵ abrir» não fazem falta. */
@media (max-width: 640px) {
    .palette-backdrop { padding: 0; }
    .palette { width: 100%; height: 100%; max-height: none; border-radius: 0; box-shadow: none; padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
    .palette__search { padding: .7rem .75rem .7rem 1rem; }
    /* 16px: o Safari do iPhone não aumenta a página ao entrar na caixa. */
    .palette .palette__input, .palette .palette__input:focus { font-size: 16px; }
    .palette__pills { padding: .5rem 1rem; }
    .palette__results { padding: .25rem .35rem .75rem; }
    .palette__side { flex-direction: column-reverse; align-items: flex-end; gap: .15rem; }
    .palette__enter, .palette__foot { display: none; }
}

@media print {
    .palette-backdrop { display: none !important; }
}
