/* Mini MRP — estilo mobile-first (uso principal é celular no chão de fábrica). */

:root {
  --azul: #1D4ED8;
  --azul-escuro: #1E3A8A;
  --texto: #10192B;
  --texto-suave: #55617A;
  --borda: #E4E9F2;
  --fundo: #F7F9FC;
  --branco: #FFFFFF;
  --sombra: 0 1px 3px rgba(16, 25, 43, .07);
  --raio: 12px;
  --altura-nav: 62px;
}

* { box-sizing: border-box; }

/* Garante que o atributo "hidden" sempre vença, mesmo em elementos cuja classe
   define "display" explicitamente (ex: .tela-login, .carregando usam display:grid,
   que sem isso sobrepõe o [hidden] nativo e o elemento nunca some de verdade). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--fundo);
  color: var(--texto);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { letter-spacing: -.02em; margin: 0; }

/* ---------------------------------------------------------------- Login */

.tela-login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(150deg, var(--azul) 0%, var(--azul-escuro) 100%);
}

.cartao-login {
  width: 100%;
  max-width: 380px;
  background: var(--branco);
  border-radius: 16px;
  padding: 1.75rem 1.5rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  display: grid;
  gap: 1rem;
}

.login-marca { display: flex; align-items: center; gap: .9rem; margin-bottom: .25rem; }
.login-marca img { border-radius: 12px; }
.login-marca h1 { font-size: 1.4rem; font-weight: 800; }
.login-marca p { margin: .1rem 0 0; color: var(--texto-suave); font-size: .85rem; }

label { display: grid; gap: .35rem; font-size: .85rem; font-weight: 600; color: var(--texto-suave); }
/* Label de checkbox único: texto ao lado da caixinha, não empilhado (display:grid da
   regra acima não vira linha só com flex-direction — precisa de display:flex mesmo). */
label.linha-checkbox { display: flex; flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }

input, select, textarea {
  font: inherit;
  font-weight: 500;
  color: var(--texto);
  padding: .7rem .8rem;
  border: 1px solid var(--borda);
  border-radius: 10px;
  background: var(--branco);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul); outline-offset: -1px; }
textarea { min-height: 76px; resize: vertical; }

.erro { color: #DC2626; font-size: .85rem; margin: 0; font-weight: 600; }

/* ---------------------------------------------------------------- Shell */

.cabecalho {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: max(.75rem, env(safe-area-inset-top)) 1rem .75rem;
  background: linear-gradient(120deg, var(--azul) 0%, var(--azul-escuro) 100%);
  color: var(--branco);
  box-shadow: 0 2px 10px rgba(29, 78, 216, .2);
}
.cabecalho-titulo { font-weight: 800; font-size: 1.05rem; }
.cabecalho-acoes { display: flex; align-items: center; gap: .4rem; }

.botao-icone {
  background: rgba(255, 255, 255, .16);
  border: 0; color: var(--branco);
  width: 36px; height: 36px; border-radius: 10px;
  font-size: 1.05rem; cursor: pointer;
}
.botao-icone:active { background: rgba(255, 255, 255, .3); }

.chip {
  background: #DC2626; color: #fff;
  padding: .2rem .6rem; border-radius: 999px;
  font-size: .78rem; font-weight: 700; white-space: nowrap;
}

.conteudo {
  padding: 1rem;
  padding-bottom: calc(var(--altura-nav) + env(safe-area-inset-bottom) + 1rem);
  max-width: 1100px; margin: 0 auto;
}

.navegacao {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--branco);
  border-top: 1px solid var(--borda);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  position: relative;
  background: none; border: 0; cursor: pointer;
  display: grid; gap: 2px; justify-items: center;
  padding: .55rem .2rem;
  font-size: .7rem; font-weight: 600; color: var(--texto-suave);
  height: var(--altura-nav);
}
.nav-item span { font-size: 1.25rem; line-height: 1.1; }
.nav-item.ativo { color: var(--azul); background: rgba(29, 78, 216, .08); }
.nav-item.ativo::before {
  content: '';
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 32px; height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--azul);
}

/* ---------------------------------------------------------------- Blocos */

.cartao {
  background: var(--branco);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  padding: 1rem;
  box-shadow: var(--sombra);
}

.secao { margin-bottom: 1.25rem; }
.secao > h2 { font-size: 1.05rem; margin-bottom: .6rem; }
.subtexto { color: var(--texto-suave); font-size: .85rem; margin: .2rem 0 .8rem; line-height: 1.45; }

.metricas { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; }
.metrica { background: var(--branco); border: 1px solid var(--borda); border-radius: var(--raio); padding: .85rem; box-shadow: var(--sombra); }
.metrica .rotulo { font-size: .78rem; color: var(--texto-suave); font-weight: 600; }
.metrica .valor { font-size: 1.6rem; font-weight: 800; margin-top: .15rem; }
.metrica.alerta { border-color: #FCA5A5; background: #FEF2F2; }
.metrica.alerta .valor { color: #B91C1C; }
.metrica.aviso { border-color: #FDE68A; background: #FFFBEB; }
.metrica.aviso .valor { color: #92400E; }
.metrica.ok { border-color: #BBF7D0; background: #F0FDF4; }
.metrica.ok .valor { color: #166534; }

.badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; color: #fff;
}

.botao {
  font: inherit; font-weight: 600; cursor: pointer;
  padding: .65rem 1rem; border-radius: 10px;
  border: 1px solid var(--borda); background: var(--branco); color: var(--texto);
}
.botao.primario { background: var(--azul); color: #fff; border-color: var(--azul); }
.botao.perigo { background: #FEF2F2; color: #B91C1C; border-color: #FECACA; }
.botao.verde { background: #F0FDF4; color: #166534; border-color: #BBF7D0; }
.botao.verde:active { background: #DCFCE7; }
.botao.indigo { background: #EFF6FF; color: #1E40AF; border-color: #BFDBFE; }
.botao.indigo:active { background: #DBEAFE; }
.botao.largo { width: 100%; }
.botao:disabled { opacity: .55; cursor: not-allowed; }
.botao-linha { display: flex; gap: .5rem; flex-wrap: wrap; }

.grupo-exportar { margin-bottom: .9rem; }
.grupo-exportar:last-child { margin-bottom: 0; }
.rotulo-grupo { font-size: .78rem; font-weight: 700; color: var(--texto-suave); margin-bottom: .4rem; text-transform: uppercase; letter-spacing: .03em; }

/* Segmented control de sub-abas dentro de uma tela (ex: Faltas -> Lista/Indicadores/Histórico). */
.sub-nav {
  display: flex; gap: .3rem;
  background: var(--branco); border: 1px solid var(--borda); border-radius: 12px;
  padding: .3rem; box-shadow: var(--sombra);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.sub-nav-item {
  flex: 1 0 auto; white-space: nowrap;
  background: none; border: 0; border-radius: 9px;
  padding: .55rem .7rem; font-size: .82rem; font-weight: 700; color: var(--texto-suave);
  cursor: pointer;
}
.sub-nav-item.ativo { background: var(--azul); color: #fff; }

.form-grid { display: grid; gap: .8rem; }
@media (min-width: 640px) { .form-grid.duas { grid-template-columns: 1fr 1fr; } }

/* ---------------------------------------------------------------- Galeria */

.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .7rem; }
.peca {
  background: var(--branco); border: 2px solid var(--borda); border-radius: var(--raio);
  padding: .55rem; cursor: pointer; text-align: left; font: inherit; color: inherit;
  display: grid; gap: .4rem; box-shadow: var(--sombra);
}
.peca.selecionada { border-color: var(--azul); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15); }
.peca.pendente { border-color: #DC2626; }
.peca img, .moldura-img {
  width: 100%; aspect-ratio: 1; object-fit: contain;
  background: #FBFCFE; border-radius: 8px; border: 1px solid var(--borda);
}
.moldura-img { display: grid; place-items: center; color: var(--texto-suave); font-size: 1.5rem; }
.peca .nome { font-size: .76rem; font-weight: 600; line-height: 1.25; }
.peca .topo { display: flex; justify-content: space-between; align-items: center; gap: .25rem; min-height: 20px; }
.peca .numero { font-size: .72rem; font-weight: 800; color: var(--texto-suave); }

/* ---------------------------------------------------------------- Listas */

.lista { display: grid; gap: .7rem; }
.item-lista { display: grid; grid-template-columns: 72px 1fr; gap: .8rem; align-items: start; }
.item-lista img, .item-lista .moldura-img { width: 72px; height: 72px; aspect-ratio: auto; }
.item-lista .titulo { font-weight: 700; font-size: .92rem; line-height: 1.3; }
.item-lista .meta { color: var(--texto-suave); font-size: .8rem; margin-top: .25rem; line-height: 1.45; }

.codigo-destaque { font-size: 1.15rem; font-weight: 800; color: var(--texto); line-height: 1.25; }
.dimensoes-destaque { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.dim-chip {
  display: inline-block; background: var(--fundo); border: 1px solid var(--borda);
  border-radius: 8px; padding: .28rem .6rem;
  font-size: .82rem; font-weight: 700; color: var(--azul-escuro);
}

.tabela-rolagem { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--borda); border-radius: var(--raio); background: var(--branco); }
table { border-collapse: collapse; width: 100%; font-size: .84rem; }
th, td { padding: .55rem .7rem; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--borda); }
th { background: #F3F5F9; font-weight: 700; color: var(--texto-suave); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: 0; }
td.numero, th.numero { text-align: right; font-variant-numeric: tabular-nums; }

details.comentarios { margin-top: .5rem; }
details.comentarios summary { cursor: pointer; font-size: .82rem; font-weight: 600; color: var(--azul); }
.comentario { background: #F7F9FC; border-radius: 8px; padding: .5rem .6rem; margin-top: .45rem; font-size: .84rem; }
.comentario .autor { font-weight: 700; font-size: .76rem; color: var(--texto-suave); }

/* ---------------------------------------------------------------- Modal */

.modal-fundo {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(16, 25, 43, .55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: surgir-fundo .15s ease-out;
}
@media (min-width: 640px) { .modal-fundo { align-items: center; padding: 1rem; } }
@keyframes surgir-fundo { from { opacity: 0; } to { opacity: 1; } }

.modal-painel {
  background: var(--branco);
  width: 100%; max-width: 560px;
  max-height: min(88dvh, 780px);
  border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: subir-painel .2s ease-out;
}
@media (min-width: 640px) { .modal-painel { border-radius: 16px; } }
@keyframes subir-painel { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-cabecalho {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: 1rem 1rem .8rem;
  border-bottom: 1px solid var(--borda);
  flex-shrink: 0;
}
.modal-cabecalho h2 { font-size: 1.02rem; color: var(--texto); }
.modal-cabecalho .botao-icone { background: var(--fundo); color: var(--texto); flex-shrink: 0; }

.modal-corpo { padding: 1rem; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.aviso { border-radius: var(--raio); padding: .8rem .9rem; font-size: .86rem; line-height: 1.45; }
.aviso.alerta { background: #FFFBEB; border: 1px solid #FDE68A; color: #92400E; }
.aviso.info { background: #EFF6FF; border: 1px solid #BFDBFE; color: #1E40AF; }
.aviso.sucesso { background: #F0FDF4; border: 1px solid #BBF7D0; color: #166534; }

.filtros { display: grid; gap: .6rem; margin-bottom: .9rem; }
@media (min-width: 640px) { .filtros.tres { grid-template-columns: 1fr 1fr 1fr; } }
.busca-linha { display: flex; gap: .4rem; }
.busca-linha input { flex: 1; }

/* ---------------------------------------------------------------- Feedback */

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--altura-nav) + 1rem); z-index: 60; display: grid; gap: .5rem; width: min(92vw, 420px); }
.toast {
  background: var(--texto); color: #fff; padding: .7rem .9rem; border-radius: 10px;
  font-size: .88rem; font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  animation: surgir .18s ease-out;
}
.toast.erro { background: #B91C1C; }
.toast.sucesso { background: #15803D; }
@keyframes surgir { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.carregando {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(255, 255, 255, .82);
  display: grid; place-content: center; justify-items: center; gap: .8rem;
  font-weight: 600; color: var(--texto-suave); text-align: center; padding: 1rem;
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--borda); border-top-color: var(--azul);
  animation: girar .8s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }

.vazio { text-align: center; color: var(--texto-suave); padding: 1.5rem 1rem; font-size: .9rem; }

.botao-topo {
  position: fixed;
  right: 1rem;
  bottom: calc(var(--altura-nav) + env(safe-area-inset-bottom) + 1rem);
  z-index: 25;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--azul);
  color: #fff;
  font-size: 1.15rem;
  box-shadow: 0 4px 14px rgba(29, 78, 216, .35);
  cursor: pointer;
  display: grid; place-items: center;
  animation: surgir .18s ease-out;
}
.botao-topo:active { background: var(--azul-escuro); }
