/* ==========================================================================
   Celular e tablet (24/10/2026)

   A plataforma é um site que funciona em qualquer navegador; este arquivo cuida de
   quem usa com o dedo. Carrega depois do solaris-ui.css, nos DOIS desenhos (novo e
   clássico), e só age em tela de até 1023px -- o computador não muda.

   1. Tablet em pé (768-1023px): o menu lateral de 264px ficava fixo e sobrava
      ~490px para o conteúdo. Agora é uma gaveta (botão ☰) por cima da página.
      Celular (<768px) continua como era: o menu abre empilhado, no topo.
   2. Alvos de toque de ao menos ~38px (o dedo não acerta botões de 22-28px).
   3. Texto de 10px sobe um pouco (era ilegível no celular).
   ========================================================================== */

@media (max-width: 1023px) {
    #mobileMenuBtn { display: inline-flex; }
    #mainSidebar { display: none; }
    #sidebarHeaderRow button { display: none; }
    /* O cabeçalho já tem a busca a partir de 768px; só o celular a guarda dentro do menu. */
    #mobileSearch { display: none; }
}
@media (max-width: 767px) {
    #mobileSearch { display: block; }
}

/* Tablet em pé: gaveta por cima do conteúdo, com a página escurecida atrás. */
@media (min-width: 768px) and (max-width: 1023px) {
    html body #mainSidebar.mobile-open {
        display: flex;
        position: fixed;
        top: 4rem;
        left: 0;
        bottom: 0;
        height: auto;
        width: min(20rem, 82vw);
        z-index: 45;
        overflow-y: auto;
        background: var(--s-gunmetal, #26323d);
        box-shadow: 10px 0 28px rgba(0, 0, 0, 0.35);
    }
    /* A página escurecida atrás da gaveta é uma camada de verdade: recebe o toque (e o fecha) em vez de
       deixá-lo cair numa imagem ou botão embaixo -- o visor de imagem captura o clique antes de tudo. */
    body.drawer-open::after {
        content: '';
        position: fixed;
        top: 4rem; left: 0; right: 0; bottom: 0;
        background: rgba(8, 15, 26, 0.5);
        z-index: 44;
    }
}

/* ---------- toque: alvos maiores e texto legível ---------- */
@media (max-width: 1023px) {
    /* Botões e campos de formulário */
    main button:not([data-remove-tag]):not([data-rotate]):not([data-ic-view]):not(.ic-del):not(.dash-btn):not([data-tag-chip] *) { min-height: 38px; }
    main input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="range"]):not([type="file"]):not([data-add-tag]),
    main select { min-height: 38px; }
    /* Links que são botões (fundo colorido com padding) */
    main a[class*="px-3"][class*="rounded"],
    main a[class*="px-4"][class*="rounded"] { min-height: 38px; display: inline-flex; align-items: center; }
    /* Ícones de ação em linha de tabela (editar, apagar, enviar e-mail...) */
    main .p-1\.5:is(button, a) { min-width: 38px; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; }

    /* Botões estreitos ("Save", "x") também precisam de largura para o dedo */
    main button:not([data-remove-tag]):not([data-rotate]):not([data-ic-view]):not(.ic-del):not(.dash-btn):not([data-tag-chip] *) { min-width: 36px; }

    /* Cabeçalho: sair, sino, tema */
    body > header button, body > header a[href="/profile.php"] { min-height: 38px; min-width: 38px; }

    /* Os da grade de mídia e do painel (estilo próprio; o estilo deles vem depois deste arquivo na página, por isso o html body) */
    html body .ic-del { width: 36px; height: 36px; font-size: 13px; }
    html body .ic-seg button { padding: 10px 14px; }
    html body .ic-view { padding: 8px 14px; }
    html body .ic-rotate button { width: 32px; height: 32px; }
    html body .dash-btn { width: 36px; height: 36px; }
    /* Cabeçalhos de tabela: 10,9px -> 11px */
    main th { font-size: 11px; }

    /* 10px não se lê no celular */
    [class*="text-[10px]"] { font-size: 11.5px; }
}

/* ---------- Celular: tabela de lista vira cartões (assets/js/stack-tables.js põe .rtable e os rótulos) ---------- */
@media (max-width: 767px) {
    table.rtable, table.rtable tbody, table.rtable tr, table.rtable td { display: block; width: 100%; }
    table.rtable { min-width: 0 !important; }
    table.rtable thead { display: none; }
    table.rtable tr {
        border: 1px solid rgba(148, 163, 184, 0.4);
        border-radius: 12px;
        margin: 0 0 12px;
        padding: 6px 14px;
        background: transparent;
    }
    table.rtable td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 7px 0 !important;
        border: 0 !important;
        text-align: right;
        width: auto;
        white-space: normal !important;
        word-break: break-word;
    }
    table.rtable td::before {
        content: attr(data-label);
        flex: 0 0 34%;
        text-align: left;
        font-size: 11px;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: #64748b;
    }
    /* Sem cabeçalho (a coluna das ações) ou célula que ocupa a linha toda: sem rótulo, alinhada à esquerda */
    table.rtable td[data-label=""]::before,
    table.rtable td:not([data-label])::before { display: none; }
    table.rtable td[data-label=""],
    table.rtable td:not([data-label]) { justify-content: flex-start; flex-wrap: wrap; }
    table.rtable td[data-label=""] { border-top: 1px solid rgba(148, 163, 184, 0.3) !important; margin-top: 4px; padding-top: 10px !important; }
    table.rtable td[colspan] { display: block; text-align: left; }
}

/* ---------- Celular: o que não cabe quebra de linha em vez de passar da borda ---------- */
@media (max-width: 767px) {
    /* Fileiras de botões e de filtros: se somam mais que a tela, a que sobra desce. */
    main .flex:not(.flex-col):not(.flex-wrap):not(.flex-nowrap):not(.inline-flex) { flex-wrap: wrap; }
    main img, main video, main canvas, main iframe, main svg, main select, main input, main textarea { max-width: 100%; }
    main pre, main code { overflow-wrap: anywhere; }
    /* Uma linha de resumo/insight com texto corrido nunca fica mais larga que o cartão */
    main .wr-insight { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
    /* Cabeçalho em tela bem estreita (320px): aproxima os botões da direita */
    @media (max-width: 359px) {
        body > header > div { gap: 0.25rem; padding-left: 0.5rem; padding-right: 0.5rem; }
        body > header .space-x-4 > * + * { margin-left: 0.15rem !important; }
        body > header button, body > header a[href="/profile.php"] { min-width: 32px; min-height: 36px; }
        body > header a[href="/profile.php"] img, body > header a[href="/profile.php"] .w-8 { width: 30px; height: 30px; }
        body > header form[action="/logout.php"] button { padding-left: 0.4rem; padding-right: 0.4rem; }
    }
}

/* Linha de "nada encontrado" (uma célula só, com colspan): sem moldura de cartão dentro da moldura da lista */
@media (max-width: 767px) {
    table.rtable tr:has(> td[colspan]:only-child) { border: 0; padding: 0; margin: 0; }
}

/* Duas colunas fixas (gráficos do relatório de custo): empilham em tela estreita */
@media (max-width: 900px) {
    main .grid.stack-sm { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- List / Thumbnails (assets/js/stack-tables.js): a escolha acima de cada lista, e a lista em cartões ---------- */
.rtable-viewbar { display: flex; justify-content: flex-end; padding: .5rem .75rem; }
.rtable-switch { display: inline-flex; border: 1px solid #cfdde7; border-radius: .5rem; overflow: hidden; background: #fff; }
.rtable-switch button { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .6rem; font-size: .72rem; font-weight: 600; color: #64748b; }
.rtable-switch button + button { border-left: 1px solid #cfdde7; }
.rtable-switch button:hover { color: #1d7fae; background: #f1f7fb; }
.rtable-switch button.on { background: #1d7fae; color: #fff; }
.dark .rtable-switch { background: #0f172a; border-color: #334155; }
.dark .rtable-switch button + button { border-left-color: #334155; }

table.rtable-cards { display: block; min-width: 0 !important; width: 100%; }
table.rtable-cards thead { display: none; }
table.rtable-cards tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: .9rem; padding: .25rem .9rem .9rem; border: 0; }
table.rtable-cards tbody > tr { display: flex; flex-direction: column; border: 1px solid #dbe6ee; border-radius: .8rem; background: #fff; padding: .7rem .9rem; box-shadow: 0 1px 2px rgba(15, 23, 42, .04); min-width: 0; }
table.rtable-cards tbody > tr:hover { border-color: #9cc6dd; box-shadow: 0 4px 12px rgba(15, 23, 42, .08); }
table.rtable-cards tbody > tr.hidden { display: none; }
table.rtable-cards td { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .3rem 0 !important; border: 0 !important; text-align: right; width: auto; min-width: 0; white-space: normal !important; overflow-wrap: anywhere; }
table.rtable-cards td::before { content: attr(data-label); flex: 0 0 38%; text-align: left; font-size: .64rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #64748b; }
/* A primeira coluna é o título do cartão */
table.rtable-cards td:first-child { display: block; text-align: left; font-size: .95rem; padding-bottom: .5rem !important; margin-bottom: .2rem; border-bottom: 1px solid #e3edf3 !important; }
table.rtable-cards td:first-child::before { display: none; }
/* As ações (coluna sem título) vão para o pé do cartão */
table.rtable-cards td[data-label=""]:not(:first-child) { justify-content: flex-start; flex-wrap: wrap; margin-top: auto; padding-top: .6rem !important; border-top: 1px solid #e3edf3 !important; }
table.rtable-cards td[data-label=""]::before, table.rtable-cards td:not([data-label])::before { display: none; }
table.rtable-cards td[data-label=""] > div, table.rtable-cards td[data-label=""] > .flex { justify-content: flex-start; }
/* Linha de "nada encontrado": ocupa a largura toda, sem moldura */
table.rtable-cards tbody > tr:has(> td[colspan]:only-child) { grid-column: 1 / -1; border: 0; box-shadow: none; background: transparent; }
table.rtable-cards td[colspan] { display: block; text-align: center; }
.dark table.rtable-cards tbody > tr { background: #0f172a; border-color: #334155; }
