:root {
  --azul-escuro: #0B3974;
  --azul: #095EDE;
  --azul-claro: #E3EEFD;
  --fundo: #F4F8FD;
  --branco: #fff;
  --texto: #14213D;
  --texto-suave: #5B6B85;
  --borda: #D7E2F2;
  --verde: #168B49; --verde-bg: #E3F5EA;
  --cinza: #5B6B85; --cinza-bg: #E6EAF1;
  --ambar: #8A5A00; --ambar-bg: #FFF1CF;
  --verm: #C62828; --verm-bg: #FCE4E4;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--fundo); color: var(--texto); font: 16px/1.35 Roboto, system-ui, -apple-system, "Segoe UI", sans-serif; }
body { overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { display: flex; flex-direction: column; height: 100dvh; max-width: 820px; margin: 0 auto; background: var(--fundo); position: relative; }

/* topo */
#topo { background: var(--azul-escuro); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 14px 14px; flex: none; }
.topo-linha { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
h1 { font-size: 21px; margin: 0; letter-spacing: .1px; }
#subtitulo { margin: 2px 0 0; color: #A9C6F5; font-size: 13px; }
.topo-acoes { display: flex; align-items: center; gap: 6px; }
.badge-amb { font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 99px; letter-spacing: .4px; }
.badge-amb.ensaio { background: var(--ambar-bg); color: var(--ambar); }
.badge-amb.audiencia { background: #D9F5E4; color: #0E6B38; }
.icone { background: none; border: 0; color: inherit; font-size: 24px; width: 44px; height: 44px; border-radius: 50%; }
.icone:active { background: rgba(255,255,255,.15); }
.busca { margin-top: 10px; background: #fff; color: var(--texto-suave); border-radius: 14px; display: flex; align-items: center; padding: 0 4px 0 12px; gap: 8px; height: 50px; }
.busca input { flex: 1; min-width: 0; border: 0; outline: 0; font-size: 18px; background: transparent; color: var(--texto); height: 100%; }
.busca input::-webkit-search-cancel-button { display: none; }
.busca .limpar { color: var(--texto-suave); font-size: 18px; }
.busca input:focus-visible { outline: 0; }
.busca:focus-within { outline: 3px solid #6FA4F5; }

/* conteúdo */
#view { flex: 1; overflow-y: auto; padding: 12px 12px 18px; -webkit-overflow-scrolling: touch; }
.card { background: var(--branco); border: 1px solid var(--borda); border-radius: 16px; padding: 12px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--azul-escuro); display: flex; gap: 8px; align-items: center; }
.muted { color: var(--texto-suave); }
.pequeno { font-size: 13px; }

/* filtros e contadores */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; padding: 0 16px; border-radius: 99px; border: 1px solid var(--borda); background: var(--branco); color: var(--texto); }
.chip[aria-pressed="true"] { background: var(--azul); border-color: var(--azul); color: #fff; font-weight: 600; }
.contadores { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--azul-claro); border-radius: 14px; margin: 4px 0 10px; text-align: center; }
.contadores div { padding: 8px 4px; font-size: 12px; color: var(--texto-suave); }
.contadores b { display: block; font-size: 22px; color: var(--azul-escuro); }
.contadores div + div { border-left: 1px solid var(--borda); }

/* linhas do catálogo: Ordem | CNS | Cidade | Cartório (+ estado) */
.cab { display: grid; grid-template-columns: 46px 64px minmax(0,1fr) minmax(0,1.3fr); gap: 6px; padding: 8px 10px; font-size: 12px; font-weight: 700; color: var(--azul-escuro); background: #E6EDF7; border-radius: 10px; margin-bottom: 6px; }
.linha { width: 100%; text-align: left; display: grid; grid-template-columns: 46px 64px minmax(0,1fr) minmax(0,1.3fr); gap: 6px; align-items: start; background: var(--branco); border: 1px solid var(--borda); border-radius: 12px; padding: 10px; margin-bottom: 6px; min-height: 56px; }
.linha:active { background: var(--azul-claro); }
.linha .ord { font-weight: 700; font-size: 17px; }
.linha .cns { font-variant-numeric: tabular-nums; font-size: 14px; padding-top: 2px; }
.linha .cid { font-size: 15px; overflow-wrap: anywhere; }
.linha .nome { font-size: 14px; overflow-wrap: anywhere; }
.linha .nome .sel { display: inline-block; margin-top: 4px; }
.sel { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.sel::before { content: "● "; }
.s-OFERTAVEL { background: var(--verde-bg); color: var(--verde); }
.s-ESCOLHIDA { background: var(--cinza-bg); color: var(--cinza); }
.s-ESCOLHIDA::before { content: "✓ "; }
.s-FORA_DA_ETAPA, .s-INDETERMINADA { background: var(--ambar-bg); color: var(--ambar); }
.s-BLOQUEADA { background: var(--verm-bg); color: var(--verm); }
.s-BLOQUEADA::before { content: "⛔ "; }
.s-SEM_ETAPA { background: #EEF2F8; color: var(--texto-suave); }
.linha.escolhida { opacity: .75; }
.linha.destaque { border: 2px solid var(--azul); }
.vazio { text-align: center; padding: 28px 12px; color: var(--texto-suave); }

/* dados da serventia (ordem, cidade, cartório) */
.grade { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin-bottom: 8px; }
.grade span:nth-child(odd) { color: var(--texto-suave); }
.grade span:nth-child(even) { font-weight: 600; }

/* cartão de resultado único */
.resultado { border: 2px solid var(--azul); background: var(--branco); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.resultado .grade { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin-bottom: 8px; }
.resultado .grade span:nth-child(odd) { color: var(--texto-suave); }
.resultado .grade span:nth-child(even) { font-weight: 600; }
.motivo { margin: 6px 0 10px; font-size: 14px; }
.motivo.alerta { background: var(--ambar-bg); color: #5B3A00; padding: 8px 10px; border-radius: 10px; }

/* botões */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 56px; border-radius: 14px; border: 0; font-size: 17px; font-weight: 600; padding: 0 16px; background: var(--azul); color: #fff; }
.btn:active { filter: brightness(.9); }
.btn.sec { background: var(--branco); color: var(--azul); border: 2px solid #A9C6F5; }
.btn.perigo { background: var(--verm-bg); color: var(--verm); }
.btn.cinza { background: var(--cinza-bg); color: var(--texto); }
.btn[disabled] { opacity: .45; }
.btn + .btn { margin-top: 10px; }
.btn-linha { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-linha .btn + .btn { margin-top: 0; }

/* etapas */
.seg { display: flex; border: 1px solid var(--borda); border-radius: 12px; overflow: hidden; background: #F0F5FC; }
.seg button { flex: 1; min-height: 48px; border: 0; background: transparent; }
.seg button[aria-pressed="true"] { background: var(--azul); color: #fff; font-weight: 700; }
.acao { width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; min-height: 56px; border-radius: 12px; border: 0; padding: 0 14px; margin-bottom: 8px; font-size: 16px; font-weight: 500; }
.acao::after { content: "›"; margin-left: auto; font-size: 24px; color: var(--texto-suave); }
.acao[disabled] { opacity: .45; }
.acao.verm { background: var(--verm-bg); color: var(--verm); }
.acao.verde { background: var(--verde-bg); color: #0E6B38; }
.acao.azul { background: var(--azul-claro); color: var(--azul-escuro); }
.stat { display: flex; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid var(--borda); }
.stat:last-child { border: 0; }
.stat b { font-size: 20px; }
.aviso { background: var(--ambar-bg); color: #5B3A00; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.info { background: var(--azul-claro); color: var(--azul-escuro); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.giro-aberto { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 0; font-size: 15px; }
.giro-aberto button { min-height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--borda); background: #fff; }

/* histórico */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; margin-bottom: 8px; }
.pino { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px; }
.pino.verde { background: #1FA55C; } .pino.azul { background: var(--azul); } .pino.verm { background: #D33; } .pino.cinza { background: #6B7A93; } .pino.ambar { background: #E09B00; }
.tl .corpo { background: #fff; border: 1px solid var(--borda); border-radius: 12px; padding: 8px 12px; }
.tl .hora { font-size: 12px; color: var(--texto-suave); }
.tl .sub { font-size: 13px; color: var(--texto-suave); }
.tl .desf { text-decoration: line-through; opacity: .6; }

/* resumo */
.destaque-card { background: #E8F6EE; border: 1px solid #BFE5CD; border-radius: 16px; padding: 14px; margin-bottom: 14px; }
.destaque-card h2 { color: #0E6B38; margin: 0 0 2px; font-size: 18px; }
.mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.mini div { background: #fff; border: 1px solid var(--borda); border-radius: 14px; padding: 10px; font-size: 12px; color: var(--texto-suave); }
.mini b { display: block; font-size: 22px; color: var(--azul-escuro); }

/* navegação inferior */
#abas { display: grid; grid-template-columns: repeat(4, 1fr); background: #fff; border-top: 1px solid var(--borda); padding-bottom: env(safe-area-inset-bottom); flex: none; }
#abas button { border: 0; background: none; min-height: 62px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--texto-suave); font-size: 13px; position: relative; }
#abas svg { width: 26px; height: 26px; }
#abas button[aria-current="page"] { color: var(--azul); font-weight: 700; }
#abas button[aria-current="page"]::after { content: ""; position: absolute; bottom: 4px; width: 46px; height: 4px; border-radius: 2px; background: var(--azul); }

/* sheet e toast */
#sheet-fundo { position: absolute; inset: 0; background: rgba(10,25,50,.5); display: flex; align-items: flex-end; z-index: 20; }
#sheet-fundo[hidden], #toast[hidden] { display: none; }
.sheet { background: #fff; width: 100%; border-radius: 22px 22px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 92%; overflow-y: auto; }
.sheet .alca { width: 44px; height: 5px; border-radius: 3px; background: #C5CFDD; margin: 0 auto 12px; }
.sheet h2 { margin: 0 0 10px; font-size: 21px; }
.sheet .grade { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin-bottom: 10px; }
.sheet .grade span:nth-child(odd) { color: var(--texto-suave); }
.sheet .grade span:nth-child(even) { font-weight: 600; }
.sheet label.opc { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; font-size: 15px; min-height: 48px; }
.sheet input[type="checkbox"] { width: 22px; height: 22px; flex: none; margin-top: 1px; }
.sheet textarea, .sheet input[type="text"] { width: 100%; font: inherit; font-size: 16px; padding: 10px; border: 1px solid var(--borda); border-radius: 10px; }
.sheet textarea { min-height: 110px; }
.sheet .menu-item { width: 100%; text-align: left; min-height: 52px; border: 0; background: none; border-bottom: 1px solid var(--borda); font-size: 16px; }
.sheet .menu-item small { display: block; color: var(--texto-suave); font-size: 13px; }
#toast { position: absolute; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); background: #14213D; color: #fff; border-radius: 12px; padding: 10px 12px 10px 16px; display: flex; align-items: center; gap: 10px; z-index: 30; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
#toast span { flex: 1; }
#toast button { background: none; border: 0; color: #8DB8FF; font-weight: 700; font-size: 16px; min-height: 44px; padding: 0 8px; text-transform: uppercase; }

button:focus-visible, input:focus-visible { outline: 3px solid #6FA4F5; outline-offset: 2px; }
@media (min-width: 700px) {
  .cab, .linha { grid-template-columns: 56px 90px minmax(0,1fr) minmax(0,1.6fr); }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: sobe .18s ease-out; }
  @keyframes sobe { from { transform: translateY(40px); opacity: .6; } }
}
