:root {
  --bg: #f7f7f8;
  --card-bg: #ffffff;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --muted: #71717a;
  --muted-soft: #a1a1aa;
  --primary: #27272a;
  --primary-dark: #18181b;
  --primary-soft: #f4f4f5;
  --accent: #0f766e;
  --accent-dark: #0b5c56;
  --accent-soft: #f0fdfa;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --ok: #15803d;
  --ok-soft: #eafaf0;
  --warn: #b45309;
  --warn-soft: #fef6e7;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.05);
  --shadow-md: 0 2px 4px -1px rgba(24, 24, 27, 0.04), 0 4px 10px -2px rgba(24, 24, 27, 0.07);
  --shadow-lg: 0 12px 28px -8px rgba(24, 24, 27, 0.2);
  --radius: 8px;
}
* { box-sizing: border-box; }
.hidden { display: none !important; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  color: var(--text);
  padding: 0.9rem 1.75rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.brand { display: flex; align-items: baseline; gap: 0.6rem; }
.brand-nome {
  font-size: 1.2rem; font-weight: 500; letter-spacing: -0.01em; color: var(--text);
}
.brand-tagline {
  font-size: 0.68rem; font-weight: 400; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--muted-soft);
}
.usuario-logado { display: flex; align-items: center; gap: 0.7rem; font-size: 0.85rem; color: var(--muted); }
.usuario-logado .btn-link { font-size: 0.82rem; }

.login-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.login-box {
  background: white; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 2.2rem 2.4rem; width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 0.9rem;
}
.login-box label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.8rem; font-weight: 500; color: var(--muted); }
.login-erro { color: var(--danger); font-size: 0.82rem; background: var(--danger-soft); padding: 0.5rem 0.7rem; border-radius: 6px; }

.tabs { display: flex; gap: 0.25rem; }
.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.55rem 1.05rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.87rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: var(--primary-soft); color: var(--text); }
.tab-btn.active { background: var(--primary-soft); color: var(--text); font-weight: 600; }

main { padding: 1.75rem; max-width: 1200px; margin: 0 auto; }
main.main-largo, main:has(#tab-processos.active) { max-width: none; }
.tab-content { display: none; }
.tab-content.active { display: block; }
h1 { font-size: 1.35rem; margin-bottom: 0.3rem; font-weight: 600; letter-spacing: -0.01em; }
.hint { color: var(--muted); margin-top: 0; margin-bottom: 1rem; font-size: 0.88rem; line-height: 1.5; }

/* ---------- Home ---------- */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.home-card {
  text-align: left; background: var(--card-bg); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 1.5rem 1.4rem; cursor: pointer;
  display: flex; flex-direction: column; gap: 0.5rem; font-family: inherit;
  box-shadow: var(--shadow-sm); transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.home-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.home-card-title { font-size: 1.05rem; font-weight: 600; color: var(--text); }
.home-card-desc { font-size: 0.85rem; color: var(--muted); line-height: 1.5; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  box-shadow: var(--shadow-sm);
}
.form-row { display: flex; flex-wrap: wrap; gap: 1.1rem; align-items: end; }
.form-row label {
  display: flex; flex-direction: column; gap: 0.4rem;
  font-size: 0.8rem; font-weight: 500; color: var(--muted); flex: 1 1 200px;
}
input, select, textarea {
  font-family: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 0.92rem;
  color: var(--text);
  background: white;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}
textarea { resize: vertical; }

.btn-primary, .btn-secondary, .btn-link, .btn-danger {
  padding: 0.6rem 1.15rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.87rem;
  letter-spacing: 0.005em;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn-primary { background: var(--primary); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: white; border: 1px solid var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--primary-soft); border-color: var(--muted-soft); }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary:disabled:hover { background: white; border-color: var(--border-strong); }
.btn-link { background: none; color: var(--accent); text-decoration: underline; padding: 0.3rem 0; font-weight: 500; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #8f1e18; }

.status-line { margin-top: 1rem; font-weight: 600; font-size: 0.88rem; }
.log-box {
  margin-top: 0.5rem; background: var(--primary-dark); color: #d4d4d8;
  padding: 0.85rem 1rem; border-radius: 6px; max-height: 320px; overflow-y: auto;
  font-size: 0.78rem; font-family: 'SF Mono', Monaco, Consolas, monospace; white-space: pre-wrap;
  line-height: 1.6;
}

.filters { display: flex; gap: 0.75rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.filters input[type="text"] { flex: 1 1 280px; }

.barra-lote {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  background: var(--primary-soft); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 0.7rem 1rem; margin-bottom: 1.1rem;
}
.barra-lote #lote-contagem { font-weight: 600; font-size: 0.85rem; margin-right: 0.4rem; }

.table-wrap { overflow-x: auto; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; table-layout: fixed; }
th, td { text-align: left; padding: 0.65rem 0.7rem; border-bottom: 1px solid var(--border); overflow-wrap: break-word; }
th {
  background: var(--primary-soft); color: var(--muted); font-weight: 600;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border-strong);
}
th.ordenavel { cursor: pointer; user-select: none; }
th.ordenavel:hover { background: #ececee; color: var(--text); }
th.ordenavel .seta { display: inline-block; margin-left: 0.3rem; opacity: 0.35; font-size: 0.9em; }
th.ordenavel.ativo .seta { opacity: 1; color: var(--accent); }
/* checkbox | Nº | Revisado | Nº Processo | Tribunal | Autor | Réu | Valor condenação | Valor atualizado | Chance de Reversão | Status */
th:nth-child(1), td:nth-child(1) { width: 4%; text-align: center; }
th:nth-child(2), td:nth-child(2) { width: 5%; font-variant-numeric: tabular-nums; color: var(--muted); }
th:nth-child(3), td:nth-child(3) { width: 6%; text-align: center; }
th:nth-child(4), td:nth-child(4) { width: 11%; font-variant-numeric: tabular-nums; }
th:nth-child(5), td:nth-child(5) { width: 6%; }
th:nth-child(6), td:nth-child(6) { width: 15%; }
th:nth-child(7), td:nth-child(7) { width: 15%; }
th:nth-child(8), td:nth-child(8) { width: 13%; font-variant-numeric: tabular-nums; }
th:nth-child(9), td:nth-child(9) { width: 10%; font-variant-numeric: tabular-nums; }
th:nth-child(10), td:nth-child(10) { width: 6%; text-align: center; }
th:nth-child(11), td:nth-child(11) { width: 9%; text-align: center; }
td:nth-child(8), td:nth-child(9) { white-space: nowrap; font-weight: 500; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:hover { background: #fafafa; }
tbody tr:nth-child(even) { background: #fcfcfd; }
tbody tr:nth-child(even):hover { background: #fafafa; }

.badge {
  display: inline-block; padding: 0.2rem 0.6rem; border-radius: 4px;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  text-align: center;
}
.badge.dados_coletados { background: #ececee; color: #45454a; }
.badge.em_tratativas { background: var(--warn-soft); color: var(--warn); }
.badge.proposta_aceita { background: var(--ok-soft); color: var(--ok); }
.badge.acordo_formalizado { background: var(--accent-soft); color: var(--accent-dark); }
.badge.proposta_nao_aceita { background: var(--danger-soft); color: var(--danger); }
.badge.arquivado { background: #e8e9ec; color: #565b66; }

.linha-arquivada { opacity: 0.55; }
.linha-arquivada:hover { opacity: 0.85; }

.dot-revisado {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 0 2px var(--danger-soft);
}
.dot-revisado.sim { background: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft); }

.dot-reversao {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  background: #d4d4d8; /* nao analisado */
}
.dot-reversao.provavel { background: var(--danger); box-shadow: 0 0 0 2px var(--danger-soft); }
.dot-reversao.possivel { background: var(--warn); box-shadow: 0 0 0 2px var(--warn-soft); }
.dot-reversao.remota { background: var(--ok); box-shadow: 0 0 0 2px var(--ok-soft); }

.select-reversao {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.45rem 0.9rem; border-radius: 6px; font-weight: 700; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.03em; border: 1px solid transparent;
}
.select-reversao.provavel { background: var(--danger-soft); color: var(--danger); border-color: #f2c9c5; }
.select-reversao.possivel { background: var(--warn-soft); color: var(--warn); border-color: #f0dca4; }
.select-reversao.remota { background: var(--ok-soft); color: var(--ok); border-color: #bfe3cf; }
.select-reversao.nao_analisado { background: #f0f1f4; color: var(--muted); border-color: var(--border); }

.toggle-revisado {
  display: inline-flex; align-items: center; gap: 0.55rem;
  padding: 0.45rem 0.95rem; border-radius: 6px; border: none; cursor: pointer;
  font-weight: 700; font-size: 0.8rem; color: white; text-transform: uppercase; letter-spacing: 0.03em;
  background: var(--danger);
}
.toggle-revisado.revisado { background: var(--ok); }
.toggle-revisado .bolinha {
  width: 8px; height: 8px; border-radius: 50%; background: white; opacity: 0.9;
}

.modal-header-row {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding-right: 2rem;
}
.modal-header-row h2 { margin: 0; font-size: 1.1rem; font-weight: 600; letter-spacing: -0.005em; }

.modal {
  position: fixed; inset: 0; background: rgba(24, 24, 27, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 2.5rem 1rem; overflow-y: auto; z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
  background: white; border-radius: 12px; padding: 1.6rem 2.1rem 2.1rem;
  max-width: 900px; width: 100%; position: relative;
  box-shadow: var(--shadow-lg);
}
.modal-close {
  position: absolute; top: 0.85rem; right: 1.1rem; border: none; background: none;
  font-size: 1.5rem; cursor: pointer; color: var(--muted-soft); line-height: 1;
  width: 32px; height: 32px; border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--primary-soft); color: var(--text); }

.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.85rem 1.3rem; margin-top: 1rem; }
.field-grid.wide { grid-template-columns: 1fr; }
.field-grid label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.field-grid label.span2 { grid-column: span 2; }

.section-title {
  margin-top: 1.6rem; margin-bottom: 0.5rem; font-size: 0.78rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text);
  border-bottom: 2px solid var(--accent); display: inline-block; padding-bottom: 4px;
}

.actions-row { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.1rem; }

.historico-list { list-style: none; padding: 0; margin: 0.5rem 0 0; max-height: 220px; overflow-y: auto; }
.historico-list li { padding: 0.5rem 0; border-bottom: 1px dashed var(--border); font-size: 0.82rem; }
.historico-list time { color: var(--muted-soft); display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.02em; margin-bottom: 1px; }

.anexos-list { list-style: none; padding: 0; margin: 0.5rem 0 0; max-height: 180px; overflow-y: auto; }
.anexos-list li { padding: 0.5rem 0; border-bottom: 1px dashed var(--border); font-size: 0.85rem; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.anexos-list a { color: var(--accent); font-weight: 600; text-decoration: none; }
.anexos-list a:hover { text-decoration: underline; }
.anexo-meta { color: var(--muted-soft); font-size: 0.75rem; }
.btn-excluir-anexo { color: var(--danger); margin-left: auto; }

.resumo-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.resumo-item { background: var(--primary-soft); border-radius: var(--radius); padding: 1rem 1.1rem; border: 1px solid var(--border); overflow: hidden; }
.resumo-item .n {
  font-size: 1.35rem; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em; word-break: break-word; overflow-wrap: break-word; line-height: 1.2;
}
.resumo-item .l { font-size: 0.76rem; color: var(--muted); font-weight: 500; margin-top: 3px; }

.proposta-box { background: var(--accent-soft); border: 1px solid #bfe3e0; border-radius: var(--radius); padding: 0.85rem 1.1rem; margin-top: 0.85rem; font-size: 0.9rem; }

/* ---------- Ficha de impressao ---------- */
#ficha-impressao { display: none; }

#ficha-impressao .cabecalho { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 3px solid var(--text); padding-bottom: 10px; margin-bottom: 18px; }
#ficha-impressao .cabecalho h1 { font-size: 20px; margin: 0; color: var(--text); letter-spacing: 0.01em; font-weight: 600; }
#ficha-impressao .cabecalho .sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; letter-spacing: 0.02em; }
#ficha-impressao .cabecalho .numero { text-align: right; font-size: 12px; color: var(--muted); }
#ficha-impressao .cabecalho .numero strong { font-size: 19px; display: block; color: var(--text); }
#ficha-impressao h2.secao { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text); border-bottom: 1px solid var(--accent); display: block; margin: 18px 0 8px; padding-bottom: 3px; font-weight: 700; }
#ficha-impressao .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 28px; font-size: 12.5px; }
#ficha-impressao .linha { display: flex; justify-content: space-between; border-bottom: 1px dotted #ccc; padding: 3px 0; gap: 12px; }
#ficha-impressao .rotulo { color: var(--muted); white-space: nowrap; }
#ficha-impressao .valor { text-align: right; font-weight: 600; }
#ficha-impressao .texto-corrido { font-size: 11.5px; line-height: 1.55; text-align: justify; white-space: pre-wrap; }
#ficha-impressao .proposta-destaque { background: var(--accent-soft); border: 1px solid #bfe3e0; border-radius: 6px; padding: 10px 14px; margin-top: 4px; font-size: 13px; }
#ficha-impressao .rodape { margin-top: 30px; font-size: 9.5px; color: #999; text-align: center; border-top: 1px solid #ddd; padding-top: 8px; letter-spacing: 0.02em; }

@media print {
  #tela-login { display: none !important; }
  #app-shell { display: block !important; }
  #app-shell > *:not(#ficha-impressao) { display: none !important; }
  #ficha-impressao { display: block !important; font-family: Georgia, 'Times New Roman', serif; color: #1c2430; padding: 0; }
  @page { size: A4; margin: 16mm; }
}
