:root {
  --bg: #0f172a; --panel: #ffffff; --ink: #0f172a; --muted: #64748b;
  --line: #e2e8f0; --accent: #0ea5e9; --accent-ink: #0369a1;
  --ok: #15803d; --warn: #b45309; --err: #b91c1c; --chip: #f1f5f9;
  --radius: 12px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: #f8fafc; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--bg); color: #fff; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; }
.tag { font-size: 12px; font-weight: 400; background: #1e293b; border: 1px solid #334155; padding: 2px 8px; border-radius: 999px; color: #bae6fd; }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a { color: #e2e8f0; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 14px; min-height: 44px; display: inline-flex; align-items: center; }
.nav a[aria-current="page"] { background: #1e293b; color: #fff; }
.container { max-width: 960px; margin: 0 auto; padding: 20px 16px 64px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; overflow-wrap: anywhere; }
.card a, .sug a, .kcard a { overflow-wrap: anywhere; word-break: break-word; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card h2 { margin: 0 0 8px; font-size: 20px; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 10px 0 4px; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
/* P0 390px: inputs/selects com altura mínima de toque; radio/checkbox com tamanho e área de toque próprios */
input, select { min-height: 44px; }
input[type="radio"], input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--accent-ink); }
label:has(> input[type="radio"]), label:has(> input[type="checkbox"]) { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
textarea { min-height: 110px; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid var(--accent-ink); background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 15px; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.ghost { background: transparent; color: #e2e8f0; border-color: #475569; }
.btn.secondary { background: #fff; color: var(--accent-ink); }
.btn.danger { background: #fff; color: var(--err); border-color: var(--err); }
.hidden { display: none !important; }
.alert { border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 14px; }
.alert.error { background: #fef2f2; color: var(--err); border: 1px solid #fecaca; }
.alert.ok { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }
.alert.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.skeleton { background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 50%, #eef2f7 75%); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 8px; min-height: 18px; margin: 6px 0; }
@keyframes sh { to { background-position: -200% 0; } }
.empty { border: 1px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--muted); background: #fff; }
.score { display: inline-block; min-width: 44px; text-align: center; font-weight: 800; border-radius: 8px; padding: 4px 8px; background: var(--chip); }
.score.hi { background: #dcfce7; color: #166534; }
.score.mid { background: #fef9c3; color: #854d0e; }
.score.lo { background: #fee2e2; color: #991b1b; }
.reasons { margin: 8px 0 0; padding-left: 18px; font-size: 14px; color: #334155; }
.chip { display: inline-block; background: var(--chip); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 12px; margin: 2px 4px 2px 0; }
.ev { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); background: #f8fafc; }
.ev.exact_family { background: #dcfce7; border-color: #86efac; }
.ev.overlap_r6 { background: #fef9c3; border-color: #fde047; }
.ev.none { background: #fee2e2; border-color: #fca5a5; }
.sug { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 8px 0; background: #fff; overflow-wrap: anywhere; }
.sug .lbl { font-weight: 700; }
/* Dossiê (fatia 2): identificação em definição; 390px empilha */
.dl { display: grid; grid-template-columns: 190px 1fr; gap: 6px 12px; font-size: 14px; margin: 0; }
.dl dt { color: var(--muted); font-weight: 600; }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.footer { position: fixed; bottom: 0; left: 0; right: 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 8px; padding: 8px 16px; background: #fff; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
/* P1 UX sessão expirada: banner global (slot #session-banner entre topbar e
 * conteúdo). Escondido por padrão ([hidden]); visível = claro + CTA. */
.session-banner-slot[hidden] { display: none; }
.session-banner-slot { position: sticky; top: 0; z-index: 20; padding: 10px 16px 0; }
.session-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; background: #fffbeb; color: #92400e; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 12px 14px; font-size: 14px; }
.session-banner-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.session-banner-actions .btn.ghost { color: var(--accent-ink); border-color: #93c5fd; }
.footer span:first-child { overflow-wrap: anywhere; min-width: 0; }
.api-status.ok { color: var(--ok); }
.api-status.bad { color: var(--err); }
/* Kanban (fatia 3): 4 colunas comerciais (VS4); factual é badge, não coluna */
.kanban-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; align-items: start; }
.kcol { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.kcol h3 { margin: 0 0 8px; font-size: 15px; }
.kcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 8px 0; background: #fff; overflow-wrap: anywhere; }
.kcard p { margin: 6px 0; font-size: 14px; }
.kcard select { width: auto; padding: 6px 8px; font-size: 14px; min-height: 44px; }
.kcard summary { cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; }
/* P0 390px: labels com style="display:inline" (decisões/prefs) perdiam o
   inline-flex + min-height 44px do seletor :has() — inline vence stylesheet.
   Restaura área de toque sem mudar layout em linha. */
.row > label[style] { display: inline-flex !important; align-items: center; gap: 8px; min-height: 44px; flex-wrap: wrap; }
/* P0 390px: filhos flexíveis encolhem em vez de estourar a linha */
.row > input, .row > select, .row > textarea { min-width: 0; }
.kcard details { margin-top: 8px; }
.factual { font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line); background: #f8fafc; }
.f-aberta { background: #dcfce7; border-color: #86efac; }
.f-encerrada { background: #f1f5f9; border-color: #cbd5e1; }
.f-cancelada { background: #fee2e2; border-color: #fca5a5; }
/* Billing (fatia 5): barras simples de uso/limites */
.meter { height: 10px; border: 1px solid var(--line); border-radius: 999px; background: #f1f5f9; overflow: hidden; margin: 6px 0; }
.meter > i { display: block; height: 100%; background: var(--accent); }
/* Mobile 390px: 1 coluna */
@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .kanban-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
  .dl dd { margin-bottom: 8px; }
  .container { padding: 12px 10px 72px; }
  .nav a { padding: 6px 8px; font-size: 13px; }
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  /* P0 390px: nav em linha própria full-width; logout fica no topo à direita */
  #btn-logout { margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; margin-left: 0; }
}
