* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--cor-fundo);
    color: var(--cor-texto);
}
.app-wrapper { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.app-header {
    height: 60px;
    background: var(--cor-primaria);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
}
.app-header-title { display: flex; flex-direction: column; margin-right: auto; }
.app-header-subtitle { font-size: 12px; opacity: .85; }
.app-header-actions { display: flex; align-items: center; gap: 12px; }
.btn-icon {
    background: transparent; border: none; color: #fff;
    font-size: 20px; cursor: pointer;
}
.btn-link { color: #fff; text-decoration: underline; }

/* Body: sidebar + conteúdo */
.app-body { display: flex; flex: 1; }
.app-sidebar {
    width: 220px;
    background: var(--cor-sidebar-fundo);
    color: var(--cor-sidebar-texto);
    transition: width .2s ease;
    overflow: hidden;
}
.app-sidebar.recolhida { width: 60px; }
.sidebar-menu { display: flex; flex-direction: column; height: 100%; padding: 12px 0; }
.sidebar-menu a {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    color: var(--cor-sidebar-texto);
    text-decoration: none;
    white-space: nowrap;
}
.sidebar-menu a:hover, .sidebar-menu a.ativo {
    background: rgba(255,255,255,0.1);
    border-left: 3px solid #fff;
}
.app-sidebar.recolhida .texto { display: none; }

/* "Sair" fica fixo embaixo do menu, separado dos demais itens */
.sidebar-menu a.sidebar-sair {
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.15);
}
.sidebar-menu a.sidebar-sair:hover {
    background: rgba(168,39,30,0.35);
    border-left: 3px solid #fca5a5;
}

.app-conteudo { flex: 1; padding: 24px; }

/* Footer */
.app-footer {
    padding: 12px 16px;
    font-size: 13px;
    color: #6b7280;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}
.app-footer-usuario {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Componentes gerais */
.card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 20px;
}
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card { text-align: center; }
.stat-card .valor { font-size: 28px; font-weight: bold; color: var(--cor-primaria); }
.stat-card .label { color: #6b7280; font-size: 14px; }
.stat-card-link {
    display: block;
    text-decoration: none;
    color: inherit;
    transition: box-shadow .15s ease, transform .15s ease;
}
.stat-card-link:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    transform: translateY(-2px);
}

table { width: 100%; border-collapse: collapse; background: #fff; }
table th, table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
    font-size: 14px;
}
table th { background: #f9fafb; }

.btn {
    display: inline-block;
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: var(--cor-primaria);
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
}
.btn:hover { background: var(--cor-primaria-escura); }

.form-grupo { margin-bottom: 14px; }
.form-grupo label { display: block; margin-bottom: 4px; font-size: 14px; font-weight: 600; }
.form-grupo input, .form-grupo select, .form-grupo textarea {
    width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px;
}

/* Grade responsiva para telas de cadastro/edição: distribui os campos
   lado a lado em vez de empilhar tudo numa coluna só. Campos que precisam
   da largura toda (textarea de descrição, avisos, etc.) usam
   .campo-largura-total. grid-auto-flow:dense evita buracos quando um
   campo de largura total "quebra" a grade no meio de uma linha. */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    column-gap: 24px;
    grid-auto-flow: dense;
}
.campo-largura-total { grid-column: 1 / -1; }

/* Barra de filtros (lista de Patrimônios): campos lado a lado numa linha só,
   com largura proporcional ao que cada um costuma precisar -- os que são
   caixa de busca por nome (Categoria/Localização/Tipo) ficam maiores, os
   que são lista curta e fixa (Status/Estado) ficam menores, e o grupo de
   botões some pro fim da linha. Tudo alinhado pela base (embaixo do label). */
.barra-filtros {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px;
    margin-bottom: 8px;
}
.barra-filtros .form-grupo { margin-bottom: 0; }
.campo-filtro-lg { flex: 2 1 190px; }
.campo-filtro-sm { flex: 1 1 150px; }
.campo-filtro-botoes { display: flex; gap: 10px; align-items: center; flex: 0 0 auto; }
.campo-filtro-botoes label { visibility: hidden; }

/* Ícone de ajuda (?) ao lado dos campos: passa o mouse (desktop) ou toca
   (celular) pra ver pra que serve o campo. */
.ajuda-campo {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: #e5e7eb; color: #4b5563; font-size: 11px; font-weight: 700;
    cursor: help; margin-left: 6px; position: relative; vertical-align: middle;
    user-select: none;
}
.ajuda-campo::after {
    content: attr(data-texto);
    position: absolute; left: 0; top: 22px; z-index: 30;
    background: #111827; color: #fff; font-weight: 400; text-transform: none;
    font-size: 12px; line-height: 1.4; padding: 8px 10px; border-radius: 6px;
    width: max-content; max-width: min(240px, 78vw);
    box-shadow: 0 4px 10px rgba(0,0,0,.18);
    display: none; white-space: normal;
}
.ajuda-campo:hover::after, .ajuda-campo.ajuda-aberta::after { display: block; }

/* Módulo de Recadastro */
.lista-resultados { margin-top: 8px; max-height: 320px; overflow-y: auto; border: 1px solid #e5e7eb; border-radius: 6px; }
.lista-resultados:empty { border: none; }
.lista-resultados-vazio { padding: 12px; color: #6b7280; font-size: 14px; }
.item-resultado {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-bottom: 1px solid #e5e7eb;
    cursor: pointer;
}
.item-resultado:last-child { border-bottom: none; }
.item-resultado:hover { background: #f9fafb; }
.item-resultado img, .item-resultado .foto-placeholder {
    width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
    background: #f3f4f6; display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.item-resultado-desc { font-size: 12px; color: #6b7280; }

.card-tipo-selecionado {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: 12px;
}
.card-tipo-selecionado img { width: 56px; height: 56px; border-radius: 6px; object-fit: cover; }
.card-tipo-selecionado .btn-link { margin-left: auto; color: var(--cor-primaria); background: none; border: none; cursor: pointer; text-decoration: underline; font-size: 13px; }

.contador-leitura {
    font-size: 16px; font-weight: 600; margin-bottom: 16px;
    padding: 10px 14px; background: #f9fafb; border-radius: 6px;
}
.contador-leitura #contadorTotal { font-size: 22px; color: var(--cor-primaria); }

/* Módulo de Conferência: 4 contadores lado a lado (esperados/conferidos/
   fora do lugar/não cadastrados), cada um com sua cor de destaque. */
.contadores-conferencia {
    display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px;
}
.contador-conferencia {
    flex: 1 1 110px; text-align: center; padding: 10px 8px;
    background: #f9fafb; border-radius: 6px;
}
.contador-conferencia span { display: block; font-size: 22px; font-weight: 700; color: var(--cor-primaria); }
.contador-conferencia small { color: #6b7280; font-size: 12px; }
.contador-conferencia.contador-ok span { color: #15803d; }
.contador-conferencia.contador-divergente span { color: #b45309; }
.contador-conferencia.contador-desconhecido span { color: #a8271e; }

#leitorCamera { max-width: 320px; border-radius: 8px; overflow: hidden; }

.mensagem-leitura { min-height: 20px; font-size: 14px; font-weight: 600; margin: 10px 0; }
.mensagem-sucesso { color: #15803d; }
.mensagem-aviso { color: #b45309; }
.mensagem-erro { color: #a8271e; }

.feed-leituras { max-height: 220px; overflow-y: auto; font-size: 13px; color: #374151; }
.feed-item { padding: 4px 0; border-bottom: 1px solid #f3f4f6; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.feed-item-duplicado { color: #b45309; }
.feed-item-ok { color: #15803d; }
.feed-item-divergente { color: #b45309; }
.feed-item-desconhecido { color: #a8271e; }
.btn-excluir-leitura {
    background: none; border: none; color: #a8271e; cursor: pointer;
    font-size: 13px; padding: 0 4px; line-height: 1; flex-shrink: 0;
}
.btn-excluir-leitura:hover { text-decoration: underline; }

/* Categorias / Usuários */
.btn-texto {
    background: none; border: none; padding: 0; cursor: pointer;
    font-size: 13px; text-decoration: underline; font-family: inherit;
}
.link-primario { color: var(--cor-primaria); }
.link-perigo { color: #a8271e; }
.link-desativado { color: #b8bec9; pointer-events: none; }

/* Paginação (lista de Patrimônios) */
.paginacao {
    display: flex; align-items: center; flex-wrap: wrap; gap: 4px;
    margin-top: 14px; padding-top: 14px; border-top: 1px solid #e5e7eb;
}
.paginacao a.btn-texto, .paginacao span.paginacao-atual {
    text-decoration: none; padding: 4px 10px; border-radius: 6px; font-size: 13px;
}
.paginacao a.btn-texto:hover { background: #f3f4f6; }
.paginacao span.paginacao-atual {
    background: var(--cor-primaria); color: #fff; font-weight: 600;
}
.paginacao-reticencias { padding: 0 2px; color: #9ca3af; }
.paginacao-info { margin-left: auto; color: #6b7280; font-size: 13px; }
.badge {
    display: inline-block; padding: 2px 10px; border-radius: 10px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-ativo { background: #dcfce7; color: #15803d; }
.badge-inativo { background: #fee2e2; color: #a8271e; }
.badge-admin { background: #ede9fe; color: #6d28d9; }
.badge-operador { background: #dbeafe; color: #1d4ed8; }
.badge-consulta { background: #f3f4f6; color: #4b5563; }
.badge-em_manutencao { background: #fef3c7; color: #b45309; }
.badge-emprestado { background: #dbeafe; color: #1d4ed8; }
.badge-baixado { background: #fee2e2; color: #a8271e; }

/* Central de Ajuda */
.grid-ajuda {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
    align-items: start;
}
.card-ajuda { display: flex; flex-direction: column; gap: 8px; margin-bottom: 0; }
.card-ajuda-cabecalho { display: flex; align-items: center; gap: 10px; }
.card-ajuda-icone { font-size: 24px; line-height: 1; }
.card-ajuda-titulo { font-size: 17px; font-weight: 700; margin: 0; }
.card-ajuda p { margin: 0; font-size: 14px; color: #374151; line-height: 1.5; }
.card-ajuda ol { margin: 4px 0 0; padding-left: 20px; font-size: 14px; color: #374151; line-height: 1.6; }
.card-ajuda-acesso { font-size: 12px; color: #6b7280; margin-top: auto; padding-top: 4px; }
.card-ajuda-largura-total { grid-column: 1 / -1; }

.login-wrapper {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: var(--cor-fundo);
}
.login-card { width: 340px; }

/* ===================================================================
   Responsivo (celular) -- o layout acima foi pensado pra tela de PC.
   Nas telas estreitas: o menu lateral vira uma gaveta que abre por
   cima do conteúdo (em vez de dividir o espaço), tabelas rolam por
   dentro de si mesmas em vez de estourar a página, e botões/campos
   ficam maiores para o toque.
   =================================================================== */
@media (max-width: 768px) {
    .app-header { padding: 0 12px; gap: 10px; }
    .app-header-subtitle { display: none; }

    .app-sidebar,
    .app-sidebar.recolhida {
        position: fixed;
        top: 60px; left: 0; bottom: 0;
        width: 240px; max-width: 80vw;
        transform: translateX(-100%);
        transition: transform .25s ease;
        z-index: 50;
        box-shadow: 2px 0 10px rgba(0,0,0,.25);
        overflow-y: auto;
    }
    /* No celular o menu nunca fica "só ícone" -- ou está fechado (fora da
       tela) ou aberto por completo, então o texto sempre aparece. */
    .app-sidebar.recolhida .texto { display: inline; }
    .app-body.menu-aberto .app-sidebar { transform: translateX(0); }

    .sidebar-backdrop {
        display: none;
        position: fixed; top: 60px; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,.4);
        z-index: 40;
    }
    .app-body.menu-aberto .sidebar-backdrop { display: block; }

    .app-conteudo { padding: 14px; }
    .card { padding: 14px; }
    h1 { font-size: 20px; }

    /* Tabela vira uma caixa com rolagem própria, sem estourar a largura
       da página (o resto da tela continua fixo/legível). */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 13px;
    }

    .form-grid { column-gap: 12px; }

    /* No celular a barra de filtros empilha em vez de espremer: cada campo
       ocupa a largura toda, e os botões vão junto, também de largura toda. */
    .campo-filtro-lg, .campo-filtro-sm { flex-basis: 100%; }
    .campo-filtro-botoes { flex-basis: 100%; }
    .campo-filtro-botoes .btn { flex: 1; text-align: center; }

    /* Alvos de toque maiores e campo de texto com 16px (evita o zoom
       automático que o iOS faz ao focar um campo com fonte menor). */
    .btn { padding: 10px 16px; font-size: 15px; }
    .form-grupo input, .form-grupo select, .form-grupo textarea { font-size: 16px; }

    #leitorCamera { max-width: 100%; }
    .card-tipo-selecionado { flex-wrap: wrap; }
    .grid-ajuda { grid-template-columns: 1fr; }
    .login-card { width: 100%; max-width: 340px; }
    .app-footer { justify-content: center; text-align: center; }
    .app-footer-usuario { margin: 0 auto; }
}
