:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #64748b;
  --brand: #1d4ed8;
  --brand-2: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--surface-2);
  font-size: 14px;
}
a { color: var(--brand); }
button { font-family: inherit; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.login-card h1 { margin: 0 0 4px; font-size: 24px; }
.login-card p.sub { margin: 0 0 24px; color: var(--text-2); }

/* ---------- Layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: var(--bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar .brand {
  padding: 20px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar .brand small { display: block; font-size: 11px; font-weight: 400; color: #94a3b8; margin-top: 2px; }
.nav { padding: 12px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: #cbd5e1; text-decoration: none; margin-bottom: 2px;
  cursor: pointer; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: var(--brand-2); color: #fff; }
.sidebar .user {
  padding: 16px 20px; border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
}
.sidebar .user .nome { color: #fff; font-weight: 600; }
.sidebar .user .papel { color: #94a3b8; text-transform: capitalize; }
.sidebar .user button {
  margin-top: 10px; width: 100%; background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15); color: #cbd5e1;
  padding: 7px; border-radius: 7px; cursor: pointer;
}
.sidebar .user button:hover { background: rgba(255, 255, 255, 0.08); }

.main { flex: 1; padding: 28px 32px; overflow-x: auto; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head h2 { margin: 0; font-size: 22px; }
.page-head .desc { color: var(--text-2); margin-top: 2px; }

/* ---------- Cards / KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.kpi .n { font-size: 28px; font-weight: 700; }
.kpi .l { color: var(--text-2); font-size: 13px; margin-top: 2px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card .card-h { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.card .card-b { padding: 18px; }

/* ---------- Tabela ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-2); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
tbody tr { cursor: pointer; }
.num-proc { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-weight: 600; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.st-novo, .st-em_controle { background: #e0e7ff; color: #3730a3; }
.st-distribuido { background: #cffafe; color: #155e75; }
.st-em_pericia { background: #fef3c7; color: #92400e; }
.st-despachado { background: #ede9fe; color: #5b21b6; }
.st-devolvido { background: #fee2e2; color: #991b1b; }
.st-conferido { background: #dcfce7; color: #166534; }
.st-enviado_sei { background: #d1fae5; color: #065f46; }
.st-concluido { background: #e2e8f0; color: #334155; }

.pr-baixa { background: #f1f5f9; color: #475569; }
.pr-normal { background: #e0f2fe; color: #075985; }
.pr-alta { background: #fef3c7; color: #92400e; }
.pr-urgente { background: #fee2e2; color: #991b1b; }

/* ---------- Farol / stripe de severidade (triagem) ---------- */
.stripe { display:inline-block; width:6px; height:26px; border-radius:3px; vertical-align:middle; background:#94a3b8; }
.stripe.v { background:#16a34a; } .stripe.a { background:#d97706; } .stripe.r { background:#dc2626; }

/* ---------- Tags de canal (as 3 portas) ---------- */
.canal { font-size:11px; font-weight:700; padding:3px 9px; border-radius:999px; white-space:nowrap; }
.canal.sei { background:#dbeafe; color:#1e40af; }
.canal.fis { background:#fef3c7; color:#92400e; }
.canal.wa  { background:#dcfce7; color:#166534; }
.canal.gh  { background:#f1f5f9; color:#64748b; }

/* ---------- Contador da Caixa de entrada no menu ---------- */
.badge-caixa { display:none; }
.badge-caixa.on { display:inline-flex; align-items:center; justify-content:center; min-width:18px; height:18px;
  padding:0 5px; margin-left:auto; border-radius:999px; background:var(--danger); color:#fff; font-size:11px; font-weight:700; }
.nav a { display:flex; align-items:center; }

/* ---------- Botões / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--brand-2); color: #fff; border: none;
  padding: 9px 16px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--brand); }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ok { background: var(--ok); }
.btn.warn { background: var(--warn); }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: var(--brand-2); }
textarea { resize: vertical; min-height: 140px; }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 160px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { width: auto; }
.spacer { flex: 1; }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
.empty { text-align: center; color: var(--text-2); padding: 40px; }
.muted { color: var(--text-2); }

/* ---------- Detalhe do processo ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.info-list { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; }
.info-list dt { color: var(--text-2); }
.info-list dd { margin: 0; font-weight: 500; }
.aviso-seguranca { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fdecea; color: #8a2318; border: 1px solid #f3b7ae; border-radius: 10px;
  padding: 12px 16px; margin-bottom: 18px; font-size: 14px; }
.aviso-seguranca code { background: rgba(138,35,24,.12); padding: 1px 6px; border-radius: 5px; }
.aviso-seguranca button { margin-left: auto; background: #b3261e; color: #fff; border: 0;
  padding: 7px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.aviso-seguranca button:hover { background: #94190f; }
.user button.secondary { background: transparent; color: var(--text-2); border: 1px solid var(--border);
  margin-bottom: 6px; }
.user button.secondary:hover { color: var(--text); border-color: var(--text-2); }
.resumo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 18px; }
.resumo-item { display: flex; flex-direction: column; gap: 2px; }
.resumo-item .muted { font-size: 12px; }
.resumo-item b { font-size: 14px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-2); }
.timeline .acao { font-weight: 600; }
.timeline .meta { color: var(--text-2); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 460px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); max-height: 92vh; display: flex; flex-direction: column; }
.modal h3 { margin: 0; padding: 18px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal .modal-b { padding: 20px; overflow-y: auto; }
.modal .modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--bg); color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 100; transition: transform 0.25s; max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; }
  .nav { display: flex; overflow-x: auto; padding: 8px; }
  .nav a { margin: 0 2px; white-space: nowrap; }
  .sidebar .user { border: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .main { padding: 18px; }
}
