:root {
  /* Tramita — Protocolo Digital */
  --brand: #062b5b;      /* azul-marinho da marca */
  --brand-2: #041f44;    /* barra lateral */
  --brand-soft: #e6ecf5;
  --gold: #15aba3;       /* verde-água da marca (acento) */
  --gold-ink: #062b5b;   /* texto sobre o verde-água */
  --gold-soft: #e1f5f3;
  --gold-soft-ink: #0b6b66;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --line: #dce2ea;
  --ink: #0f1c2e;
  --ink-2: #475569;
  --ink-3: #718096;
  --ok: #1a7f4b;      --ok-bg: #e5f4ec;
  --warn: #9a6400;    --warn-bg: #fdf1d8;
  --bad: #b42318;     --bad-bg: #fde8e6;
  --info: #1f5fa8;    --info-bg: #e6eefa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,36,42,.06), 0 2px 8px rgba(16,36,42,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #8fb4ea; --brand-2: #04162f; --brand-soft: #14243a;
    --gold: #2fc4bb; --gold-ink: #04162f; --gold-soft: #113a39; --gold-soft-ink: #6fdcd4;
    --bg: #0b1320; --surface: #121c2b; --surface-2: #172233; --line: #26344a;
    --ink: #e7eef0; --ink-2: #b3c1c5; --ink-3: #82939a;
    --ok: #5cc98e; --ok-bg: #173226; --warn: #e6b04a; --warn-bg: #362a12;
    --bad: #f07a6f; --bad-bg: #3a1c19; --info: #80b0ec; --info-bg: #182a40;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; background: linear-gradient(to right, var(--brand-2) 232px, transparent 232px); align-items: start; }
@media (prefers-color-scheme: dark) { .shell { background: linear-gradient(to right, #04162f 232px, transparent 232px); } }
.side { background: var(--brand-2); color: #dfe9eb; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
@media (prefers-color-scheme: dark) { .side { background: #04162f; } }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 10px; }
.brand img { width: 36px; height: 36px; border-radius: 8px; }
.brand b { display: block; font-size: 15px; color: #fff; letter-spacing: .02em; }
.brand small { color: #9fb3cf; font-size: 11px; letter-spacing: .08em; }
.nav a span { white-space: nowrap; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: #cfdfe2; text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.on { background: rgba(21,171,163,.18); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav .count { margin-left: auto; background: var(--gold); color: var(--gold-ink); border-radius: 999px; font-size: 12px; padding: 0 7px; font-weight: 700; }
.side .me { margin-top: auto; font-size: 13px; padding: 10px; border-top: 1px solid rgba(255,255,255,.1); color: #b8ccd0; }
.side .me b { color: #fff; display: block; }
.side .me button { margin-top: 8px; background: transparent; border: 1px solid rgba(255,255,255,.2); color: #dfe9eb; border-radius: 6px; padding: 4px 10px; cursor: pointer; }
.main { padding: 22px clamp(16px, 3vw, 36px) 90px; max-width: 1180px; width: 100%; }
.topbar { display: none; }
.tabbar { display: none; }

@media (max-width: 860px) {
  .shell { display: block; background: none; }
  #det > div:last-child { order: -1; }
  .box-acoes { position: static; }
  .side { display: none; }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--brand-2); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; position: sticky; top: 0; z-index: 20; }
  .topbar img { width: 28px; height: 28px; border-radius: 6px; }
  .topbar b { font-size: 15px; }
  .topbar small { display: block; font-size: 12px; color: #9fb3cf; }
  .topbar .sair { margin-left: auto; background: none; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 6px; padding: 4px 10px; font-size: 13px; }
  .tabbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: 11px; color: var(--ink-3); text-decoration: none; position: relative; }
  .tabbar a.on { color: var(--brand); font-weight: 600; }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar .count { position: absolute; top: 3px; left: 55%; background: var(--gold); color: var(--gold-ink); border-radius: 999px; font-size: 10px; padding: 0 5px; font-weight: 700; }
  .main { padding: 16px 16px 96px; }
}
.ico { width: 18px; height: 18px; flex: none; }

/* ---------- elementos ---------- */
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
.sub { color: var(--ink-2); margin: 0 0 18px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head .sub { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 14px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
@media (max-width: 860px) { .g2, .g3 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 500; text-decoration: none; min-height: 38px; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); }
.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.pri { color: #04162f; } }
.btn.pri:hover { filter: brightness(1.08); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

label.f { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }
label.f > span { display: block; margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 9px 11px; font-weight: 400; color: var(--ink); min-height: 40px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.req::after { content: " *"; color: var(--bad); }
.seg { display: inline-flex; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; overflow-y: hidden; background: var(--surface); scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; white-space: nowrap; border: 0; background: none; padding: 7px 14px; cursor: pointer; color: var(--ink-2); font-weight: 500; }
.seg button.on { background: var(--brand); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on { color: #04162f; } }
.seg .n { font-size: 12px; opacity: .8; margin-left: 4px; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.b-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.b-bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.b-info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.b-gold { background: var(--gold-soft); color: var(--gold-soft-ink); border-color: transparent; }
.b-new { background: var(--gold); color: var(--gold-ink); border-color: transparent; }

/* ---------- lista de processos ---------- */
.plist { display: flex; flex-direction: column; gap: 8px; }
.pitem { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.pitem:hover { border-color: var(--brand); }
.pitem.novo { border-left: 4px solid var(--gold); }
.pitem .cod { font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }
.pitem .ass { font-weight: 600; }
.pitem .meta { color: var(--ink-3); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; }
.pitem .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.empty { text-align: center; color: var(--ink-3); padding: 40px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- detalhe ---------- */
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 14px; margin: 0; }
.dl dt { color: var(--ink-3); font-size: 13px; }
.dl dd { margin: 0; }
@media (max-width: 560px) { .dl { grid-template-columns: 1fr; } .dl dt { margin-top: 6px; } }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 16px 28px; }
.timeline li::before { content: ""; position: absolute; left: 8px; top: 18px; bottom: -2px; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline .dot { position: absolute; left: 1px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand); }
.timeline .dot.gold { border-color: var(--gold); }
.timeline .dot.ok { border-color: var(--ok); }
.timeline .dot.muted { border-color: var(--ink-3); }
.timeline .t { font-weight: 600; }
.timeline .w { font-size: 12px; color: var(--ink-3); }
.timeline .txt { white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 6px; }
.box-acoes { position: sticky; top: 12px; }
.anexo { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.anexo:last-child { border-bottom: 0; }
.anexo a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- painel ---------- */
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; }
.kpi .lbl { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.kpi .val { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .hint { font-size: 12px; color: var(--ink-3); }
.kpi.alert .val { color: var(--bad); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--line); }
table.t td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.n { text-align: right; font-variant-numeric: tabular-nums; }
table.t th.n { text-align: right; }
.bar { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.bar .track { flex: 1; height: 10px; }
.bar .fill { height: 10px; background: var(--brand); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar .v { width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); font-size: 13px; }
.scroll-x { overflow-x: auto; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--brand-2), var(--brand) 70%); }
@media (prefers-color-scheme: dark) { .login { background: linear-gradient(160deg, #020c1c, #062b5b); } }
.login .card { width: 100%; max-width: 400px; padding: 26px; }
.login .logo { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.login .logo img { width: 48px; height: 48px; border-radius: 10px; }
.login .logo b { font-size: 18px; display: block; }
.err { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: 8px 10px; font-size: 14px; margin-bottom: 12px; }
.note { background: var(--gold-soft); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(8,20,24,.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h2 { font-size: 18px; }
.modal .actions { justify-content: flex-end; margin-top: 8px; }

#toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100vw - 32px); font-size: 14px; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); color: #fff; }

/* ---------- ofício (A4) ---------- */
.oficio-wrap { display: grid; grid-template-columns: minmax(0, 420px) 1fr; gap: 18px; align-items: start; }
@media (max-width: 1000px) { .oficio-wrap { grid-template-columns: 1fr; } }
.folha-scroll { overflow-x: auto; background: #d9dedd; border-radius: var(--radius); padding: 16px; }
.folha { width: 210mm; min-height: 297mm; background: #fff; color: #000; margin: 0 auto; padding: 18mm 20mm 20mm 25mm; font-family: "Times New Roman", Times, serif; font-size: 12pt; line-height: 1.5; box-shadow: 0 2px 10px rgba(0,0,0,.15); position: relative; display: flex; flex-direction: column; }
.folha .cab { text-align: center; border-bottom: 1.5px solid #000; padding-bottom: 8px; margin-bottom: 18px; }
.folha .cab img { height: 70px; margin-bottom: 4px; }
.folha .cab .o { font-weight: bold; font-size: 12pt; }
.folha .cab .s { font-weight: bold; font-size: 11pt; }
.folha .num { font-weight: bold; margin: 0; }
.folha .data { text-align: right; margin: 0 0 16px; }
.folha .dest { margin-bottom: 14px; }
.folha .dest p { margin: 0; }
.folha .ass { margin-bottom: 12px; }
.folha .corpo p { text-indent: 2.5cm; text-align: justify; margin: 0 0 10px; }
.folha .fecho { text-indent: 2.5cm; margin-top: 12px; }
.folha .assin { margin-top: 56px; text-align: center; }
.folha .assin .linha { width: 70%; margin: 0 auto 4px; border-top: 1px solid #000; }
.folha .assin b { display: block; }
.folha .rod { margin-top: auto; padding-top: 14px; border-top: 1px solid #000; text-align: center; font-size: 9pt; color: #222; }

/* capa de processo impressa */
.capa h3 { text-align: center; font-size: 15pt; margin: 6px 0 14px; }
.capa table { width: 100%; border-collapse: collapse; font-size: 11pt; }
.capa td, .capa th { border: 1px solid #000; padding: 4px 6px; text-align: left; vertical-align: top; }
.capa th { background: #eee; width: 30%; }

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .shell { display: block; }
  .side, .topbar, .tabbar, .no-print, #toast { display: none !important; }
  .main { padding: 0; max-width: none; }
  .folha-scroll { padding: 0; background: none; overflow: visible; }
  .folha { box-shadow: none; margin: 0; width: 210mm; min-height: 297mm; zoom: 1 !important; }
  .oficio-wrap { display: block; }
}

@media (max-width: 860px) {
  .plist .pitem { grid-template-columns: 1fr; }
  .plist .pitem .right { flex-direction: row; flex-wrap: wrap; align-items: center; order: -1; justify-content: flex-start; }
  .t .nome-setor { display: none; }
  .grid.kpis { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
  .kpi .val { font-size: 26px; }
}

/* ---------- marca Tramita ---------- */
:root { --font-marca: "Montserrat", var(--font); }
h1, h2, .brand b, .topbar b, .kpi .val { font-family: var(--font-marca); }
h1 { font-weight: 700; }
.brand { gap: 12px; }
.brand img { width: 40px; height: auto; border-radius: 0; }
.brand b { font-size: 19px; font-weight: 800; letter-spacing: .04em; }
.topbar img { width: 30px; height: auto; border-radius: 0; }
.topbar b { font-weight: 800; letter-spacing: .04em; }
.login { background: linear-gradient(150deg, #041f44 0%, #062b5b 55%, #0d6b73 100%); }
.login .marca-login { display: block; width: 100%; max-width: 280px; margin: 4px auto 22px; }
@media (prefers-color-scheme: dark) { .login .card { background: #fff; color: #0f1c2e; } .login .card input { background: #f7f9fb; color: #0f1c2e; border-color: #dce2ea; } .login .card .muted { color: #718096; } .login .card .btn.pri { color: #fff; background: #062b5b; border-color: #062b5b; } }
.nav a.on { box-shadow: inset 3px 0 0 var(--gold); }

/* ---------- assinatura eletrônica ---------- */
.selo { margin-top: 6px; font-size: 12.5px; line-height: 1.6; color: var(--ink-2); background: var(--surface-2); border: 1px dashed var(--line); border-radius: 8px; padding: 6px 10px; }
.selo .btn { margin-left: 6px; vertical-align: middle; }
.selo.ok { color: var(--ok); background: var(--ok-bg); border: 1px solid transparent; }
.selo a { color: inherit; }
.assinar-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 4px 0 12px; }
.folha .autentica { border: 1px solid #000; padding: 8px 10px; margin-top: 18px; font-size: 9pt; line-height: 1.35; break-inside: avoid; }
.folha .autentica .linha-aut { display: flex; gap: 12px; align-items: center; }
.folha .autentica .linha-aut + .linha-aut { border-top: 1px solid #000; margin-top: 6px; padding-top: 6px; }
.folha .autentica .selo-ass { flex: none; width: 84px; height: 84px; display: block; }
.folha .autentica p { margin: 0 0 4px; text-indent: 0; }
.folha .autentica .qr { flex: none; width: 84px; height: 84px; }
.folha .autentica .qr svg { width: 84px; height: 84px; display: block; }
.login .card .card { max-width: none; width: 100%; padding: 14px; }

/* ---------- usuários externos ---------- */
.sol { border-top: 1px solid var(--line); padding: 10px 0; }
.sol:first-of-type { border-top: 0; padding-top: 0; }
.portal { min-height: 100vh; }
.portal .main { max-width: 820px; }
.portal-top { display: flex !important; position: sticky; top: 0; z-index: 20; align-items: center; gap: 10px; background: var(--brand-2); color: #fff; padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; }
.portal-top img { width: 30px; height: auto; }
.portal-top b { font-family: var(--font-marca); font-weight: 800; letter-spacing: .04em; }
.portal-top small { display: block; font-size: 12px; color: #9fb3cf; }
.portal-me { margin-left: auto; display: flex; gap: 8px; align-items: center; font-size: 13px; text-align: right; }
.portal-me small { color: #9fb3cf; }
.portal-me .sair { background: none; border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 6px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
@media (max-width: 560px) { .portal-me span { display: none; } }
.sol-card + .sol-card { margin-top: 12px; }
.folha.termo ol { padding-left: 20px; text-align: justify; }
.folha.termo ol li { margin-bottom: 6px; }
.folha.termo p { text-align: justify; }
