:root {
  --fundo: #0f172a; --painel: #1e293b; --painel2: #273449; --borda: #334155; --texto: #e2e8f0; --sub: #94a3b8;
  --primario: #38bdf8; --primario-txt: #0f172a; --perigo: #f87171; --ok: #4ade80; --aviso: #fbbf24;
  --raio: 16px; --barra-alt: 68px; --toque: 52px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--fundo); color: var(--texto);
  font: 17px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-text-size-adjust: 100%; touch-action: manipulation; }
.oculto { display: none !important; }
.marca { color: var(--primario); font-weight: 800; letter-spacing: .04em; }
button, input, select { font: inherit; }
button { touch-action: manipulation; user-select: none; }
.botao { display: block; width: 100%; min-height: var(--toque); padding: 12px 18px; margin-top: 12px; border-radius: var(--raio); border: 1px solid var(--borda);
  background: var(--painel2); color: var(--texto); font-weight: 700; font-size: 17px; cursor: pointer; }
.botao.primario { background: var(--primario); color: var(--primario-txt); border-color: var(--primario); }
.botao.perigo { border-color: var(--perigo); color: var(--perigo); }
.botao.compacto { width: auto; margin: 0; padding: 10px 16px; min-height: 44px; font-size: 15px; }
.botao:disabled { opacity: .5; }
.botao:active { transform: scale(.98); filter: brightness(1.1); }
input, select { width: 100%; min-height: var(--toque); padding: 12px 16px; border-radius: var(--raio); border: 1px solid var(--borda); background: #0b1220; color: var(--texto); font-size: 17px; }
input#codigo, input#modal-codigo { font-size: 32px; letter-spacing: .4em; text-align: center; }
label { display: block; margin: 16px 0 6px; color: var(--sub); font-size: 15px; }
label.check { display: flex; gap: 12px; align-items: center; color: var(--texto); font-size: 16px; min-height: var(--toque); }
label.check input { width: 26px; height: 26px; min-height: 0; }
.erro { color: var(--perigo); margin-top: 12px; }
.sub { color: var(--sub); font-size: 14px; margin: 4px 0 10px; }
.chip { display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--borda); font-size: 14px; font-weight: 600; }
.chip.ok { background: #14532d; color: var(--ok); } .chip.erro { background: #7f1d1d; color: #fecaca; }
.chip.a_decorrer { background: #78350f; color: #fde68a; } .chip.pendente, .chip.desconhecido, .chip.na { background: var(--borda); color: var(--sub); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 12px; }
.chips .chip { min-height: 40px; display: inline-flex; align-items: center; }

/* login */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.cartao { width: 100%; max-width: 440px; background: var(--painel); border: 1px solid var(--borda); border-radius: 22px; padding: 26px; }
.cartao h1 { margin: 0; font-size: 24px; }
.cartao .sub { margin: 4px 0 18px; }

/* app: topo, pesquisa, vista, barra */
body.app { padding-bottom: calc(var(--barra-alt) + env(safe-area-inset-bottom)); }
.topo { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--painel); border-bottom: 1px solid var(--borda); }
.topo .titulo { flex: 1; font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icone { width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--borda); background: var(--painel2); color: var(--texto); font-size: 22px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.pesquisa { display: flex; gap: 8px; padding: 10px 12px; background: var(--painel); border-bottom: 1px solid var(--borda); position: sticky; top: calc(68px + env(safe-area-inset-top)); z-index: 5; }
.pesquisa input { flex: 1; }
.faixa { background: #7c2d12; color: #fff; padding: 12px 16px; font-size: 15px; }
.vista { padding: 14px 12px 24px; max-width: 960px; margin: 0 auto; }
.painel h2 { margin: 0; font-size: 22px; }
.painel h3 { margin: 22px 0 10px; font-size: 15px; color: var(--sub); text-transform: uppercase; letter-spacing: .06em; }
.cabeca { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.vazio { color: var(--sub); padding: 14px 0; }

/* cartões tocáveis */
.cartoes { list-style: none; padding: 0; margin: 0; }
.cartoes li { margin-bottom: 10px; }
.cartoes .item { display: block; width: 100%; text-align: left; background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio); padding: 14px 16px; color: var(--texto); min-height: 64px; }
.cartoes .item:active { background: var(--painel2); }
.item .linha1 { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.item .id { font-weight: 800; font-size: 18px; }
.item .id small { color: var(--sub); font-weight: 500; font-size: 13px; margin-left: 6px; }
.item .texto { color: var(--texto); margin-top: 4px; font-size: 16px; }
.item .motivo { color: var(--sub); margin-top: 4px; font-size: 14px; }
.item .quando { color: var(--sub); font-size: 13px; margin-top: 6px; }
.item.urg1 { border-left: 5px solid var(--perigo); } .item.urg2 { border-left: 5px solid var(--aviso); } .item.urg3 { border-left: 5px solid var(--borda); }
.grupo { margin-bottom: 14px; }
.grupo summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; min-height: var(--toque); padding: 10px 16px; background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio); font-weight: 700; }
.grupo summary::-webkit-details-marker { display: none; }
.grupo[open] summary { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.grupo .cartoes { padding: 10px 8px 0; }

/* ficha do processo */
.ficha-cabeca { background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio); padding: 16px; }
.ficha-cabeca .iso { font-size: 26px; font-weight: 800; }
.ficha-cabeca .cliente { font-size: 17px; margin-top: 4px; }
.ficha-cabeca .detalhe { color: var(--sub); font-size: 14px; margin-top: 4px; }
.passos { list-style: none; padding: 0; margin: 0; }
.passos li { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; background: var(--painel); border: 1px solid var(--borda); border-radius: var(--raio); margin-bottom: 8px; }
.passos .estado { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; flex: 0 0 30px; }
.passos .estado.ok { background: #14532d; color: var(--ok); } .passos .estado.erro { background: #7f1d1d; color: #fecaca; }
.passos .estado.a_decorrer { background: #78350f; color: #fde68a; } .passos .estado.pendente, .passos .estado.desconhecido { background: var(--borda); color: var(--sub); }
.passos .nome { font-weight: 700; } .passos .det { color: var(--sub); font-size: 14px; word-break: break-word; }
.acoes-grelha { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.acoes-grelha .botao { margin: 0; }
.eventos { list-style: none; padding: 0; margin: 0; }
.eventos li { padding: 10px 12px; border-left: 3px solid var(--borda); margin-bottom: 8px; font-size: 14px; }
.eventos .ts { color: var(--sub); font-size: 12px; } .eventos .fonte { color: var(--primario); font-size: 12px; margin-left: 6px; }
.eventos .txt { word-break: break-word; }

/* conta */
.factos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin: 12px 0; }
.factos dt { color: var(--sub); font-size: 14px; } .factos dd { margin: 0; }
.lista { list-style: none; padding: 0; margin: 0; }
.lista li { padding: 12px 14px; border: 1px solid var(--borda); border-radius: 12px; margin-bottom: 8px; background: var(--painel); font-size: 15px; }
.lista.mono li { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-word; }
.acoes { margin-top: 12px; }

/* barra inferior */
.barra { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--barra-alt) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: var(--painel); border-top: 1px solid var(--borda); z-index: 6; }
.barra button { flex: 1; border: 0; background: transparent; color: var(--sub); font-size: 12px; font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--barra-alt); }
.barra button .ico { font-size: 24px; line-height: 1; }
.barra button.ativo { color: var(--primario); }
.barra button:active { background: var(--painel2); }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.modal-caixa { width: 100%; max-width: 520px; background: var(--painel); border: 1px solid var(--borda); border-radius: 22px 22px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); }
.modal-caixa h3 { margin: 0 0 8px; font-size: 18px; }
.toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--barra-alt) + 14px + env(safe-area-inset-bottom)); background: #0b1220; border: 1px solid var(--borda); color: var(--texto); padding: 14px 16px; border-radius: 14px; z-index: 20; font-size: 15px; text-align: center; }

/* PC: barra lateral, colunas mais largas */
@media (min-width: 900px) {
  body.app { padding-bottom: 0; padding-left: 210px; }
  .barra { top: 0; bottom: 0; right: auto; width: 210px; height: auto; flex-direction: column; border-top: 0; border-right: 1px solid var(--borda); padding-top: 70px; justify-content: flex-start; }
  .barra button { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 14px 20px; font-size: 16px; min-height: 56px; }
  .modal { align-items: center; } .modal-caixa { border-radius: 22px; }
  .acoes-grelha { grid-template-columns: repeat(4, 1fr); }
}

/* v0.3.0: ações sugeridas, badges, histórico recolhido */
.acoes-linha { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip.acao { background: #0b1220; border: 1px solid var(--borda); color: var(--primario); font-size: 13px; font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--perigo); color: #fff; font-size: 11px; line-height: 18px; text-align: center; margin-left: 2px; vertical-align: top; }
.badge:empty { display: none; }
.grupo.historico { margin-top: 22px; }
.grupo.historico summary { color: var(--sub); background: transparent; border-style: dashed; }

/* v0.4.0: botões de ação nos cartões, folha genérica, saída de tarefas */
.botoes-acao { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.botoes-acao .botao { margin: 0; flex: 1 1 45%; min-height: 48px; font-size: 15px; }
.botoes-acao .botao.resolvido { flex-basis: 100%; border-style: dashed; color: var(--ok); }
.cartoes .item.com-acoes { cursor: default; }
.cartoes .abrir { display: inline-block; margin-top: 8px; color: var(--primario); font-weight: 700; font-size: 15px; min-height: 40px; line-height: 40px; }
.saida { background: #0b1220; border: 1px solid var(--borda); border-radius: 12px; padding: 12px; font: 12px/1.4 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word; max-height: 45vh; overflow: auto; }
#folha .modal-caixa { max-height: 92vh; overflow: auto; }

/* conversa com o Jarvas-ADENE */
.chat { display: flex; gap: 8px; align-items: stretch; }
.chat textarea { flex: 1; min-height: 56px; padding: 12px 14px; border-radius: var(--raio); border: 1px solid var(--borda); background: #0b1220; color: var(--texto); font: inherit; resize: vertical; }
.botoes-acao .botao.conversar { flex-basis: 100%; background: #0b1220; color: var(--primario); }
