:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1b1f24; --muted: #6b7280; --line: #e4e7eb;
  --brand: #0f766e; --brand-ink: #fff; --brand-soft: #e6f4f2;
  --ok: #15803d; --ok-bg: #e8f6ec; --warn: #a16207; --warn-bg: #fdf5e1; --err: #b91c1c; --err-bg: #fdecec; --info: #1d4ed8; --info-bg: #e9effd;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215; --panel: #171b20; --ink: #e6e8eb; --muted: #9aa3ad; --line: #272d34;
    --brand: #2dd4bf; --brand-ink: #062b27; --brand-soft: #12302d;
    --ok: #4ade80; --ok-bg: #12291b; --warn: #facc15; --warn-bg: #2d2610; --err: #f87171; --err-bg: #2f1616; --info: #93b4ff; --info-bg: #17213b;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }
.muted { color: var(--muted); } .sm { font-size: .85rem; } .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.center { text-align: center; } .left { text-align: left; } .nowrap { white-space: nowrap; } .mt { margin-top: .8rem; }

/* topo */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; padding: .6rem 1.2rem; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--ink); display: inline-flex; align-items: center; gap: .5rem; }
.brand:hover { text-decoration: none; }
.logo { display: inline-flex; align-items: center; gap: .55rem; }
.logo img { width: 30px; height: 30px; border-radius: 8px; display: block; }
.wordmark { font-weight: 800; letter-spacing: -.02em; font-size: 1.12rem; color: var(--ink); }
.wordmark em { font-style: normal; color: var(--brand); font-weight: 700; }
.logo.lg img { width: 52px; height: 52px; border-radius: 14px; }
.logo.lg .wordmark { font-size: 1.7rem; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 1.2rem; }
.tag { font-size: .7rem; background: var(--brand-soft); color: var(--brand); padding: .1rem .45rem; border-radius: 99px; vertical-align: middle; font-weight: 600; }
#nav { display: flex; gap: .2rem; flex-wrap: wrap; flex: 1; align-items: center; }
#nav a, #nav .link { padding: .4rem .7rem; border-radius: 8px; color: var(--ink); font-size: .92rem; }
#nav a:hover { background: var(--bg); text-decoration: none; }
#nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.who { font-size: .88rem; color: var(--muted); }
.menu-btn { display: none; margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); font-size: 1.1rem; padding: .2rem .6rem; }
@media (max-width: 860px) {
  .menu-btn { display: block; }
  #nav { display: none; order: 3; flex-basis: 100%; flex-direction: column; align-items: stretch; }
  #nav.open { display: flex; }
  .who { order: 2; flex-basis: 100%; }
}

main { max-width: 1200px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
main.narrow { max-width: 440px; padding-top: 8vh; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.narrow-card { max-width: 620px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.cards .card { margin: 0; }
.cards.mini { grid-template-columns: repeat(4, 1fr); margin: 1rem 0; }
@media (max-width: 600px) { .cards.mini { grid-template-columns: repeat(2, 1fr); } }
.stat .label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .value.sm2 { font-size: 1.1rem; }
.cards.mini .stat { background: var(--bg); border-radius: 8px; padding: .6rem .7rem; }
.stat.hl { border-color: var(--brand); } .stat.hl .value { color: var(--brand); }
.stat.warn { border-color: var(--warn); } .stat.warn .value { color: var(--warn); }
.stat.err { border-color: var(--err); } .stat.err .value { color: var(--err); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 1rem; }
.grid2.top { align-items: start; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } }

.row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.gap > * { flex: 1; }

/* formulários */
.stack { display: flex; flex-direction: column; gap: .8rem; }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
form.inline { display: inline; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin: .6rem 0 1rem; }
.filters input { flex: 1 1 240px; width: auto; } .filters select { width: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .92rem; padding: .5rem .95rem; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: .25rem .6rem; font-size: .82rem; }
.btn.block { width: 100%; padding: .7rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
button.link { background: none; border: 0; font: inherit; cursor: pointer; }
.quick { display: flex; gap: .4rem; } .quick .btn { flex: 1; }
.total { font-size: 1.1rem; }
dialog.modal { border: 1px solid var(--line); border-radius: 14px; padding: 1.3rem; width: min(420px, calc(100vw - 32px)); background: var(--panel); color: var(--ink); box-shadow: 0 20px 50px rgba(0,0,0,.35); }
dialog.modal::backdrop { background: rgba(10, 14, 18, .6); }
dialog.modal[open] { display: flex; flex-direction: column; gap: .8rem; }
dialog.modal h3 { margin: 0; }
dialog.modal p { margin: 0; }
dialog.modal input { font-size: 1.1rem; letter-spacing: .03em; }
.err-msg { color: var(--err); font-size: .88rem; }

.flash { padding: .7rem .9rem; border-radius: 8px; margin-bottom: 1rem; font-size: .93rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); } .flash.err { background: var(--err-bg); color: var(--err); }
.flash.warn { background: var(--warn-bg); color: var(--warn); } .flash.info { background: var(--info-bg); color: var(--info); }

.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: .12rem .55rem; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.muted { background: var(--bg); color: var(--muted); }

/* tabelas */
.table-wrap { overflow-x: auto; margin: 0 -1.2rem; padding: 0 1.2rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; padding: .5rem .6rem; border-bottom: 1px solid var(--line); }
td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); font-weight: 600; } .neg { color: var(--err); font-weight: 600; }
td.details { font-size: .8rem; color: var(--muted); max-width: 380px; word-break: break-word; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: .8rem 0; }
dl.kv dt { color: var(--muted); font-size: .88rem; } dl.kv dd { margin: 0; word-break: break-word; }

.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin: -.3rem 0 1rem; overflow-x: auto; }
.tabs a { padding: .5rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); font-weight: 600; }

.auth { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.6rem; box-shadow: var(--shadow); }

.copybox { display: flex; gap: .5rem; margin: .8rem 0; } .copybox input { flex: 1; }
.qr { width: 240px; max-width: 100%; height: auto; margin: .6rem auto 1rem; display: block; background: #fff; padding: 8px; border-radius: 10px; }
.big { font-size: 1.15rem; }
.spinner { display: inline-block; width: .9em; height: .9em; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -.1em; }
@keyframes spin { to { transform: rotate(360deg); } }

.feed { list-style: none; margin: 0; padding: 0; font-size: .88rem; }
.feed li { padding: .35rem 0; border-bottom: 1px solid var(--line); } .feed li:last-child { border: 0; }

/* mini gráfico de barras */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding-top: .5rem; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.bar span { display: block; width: 100%; height: calc(var(--h) * 1% * .85); min-height: 2px; background: var(--brand); border-radius: 4px 4px 0 0; }
.bars.alt .bar span { background: var(--info); }
.bar em { font-style: normal; font-size: .68rem; color: var(--muted); }

.alert-cpf { background: var(--warn-bg); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); border-radius: 10px; padding: .7rem .85rem; font-size: .92rem; line-height: 1.45; margin: .2rem 0 .6rem; }
.alert-cpf.sm { font-size: .86rem; }

/* ---------- seletor de aplicativo ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field .lbl { font-size: .9rem; font-weight: 500; }
.picker { position: relative; }
.picker-btn { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: .5rem; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .7rem; min-height: 44px; cursor: pointer; text-align: left; }
.picker.open .picker-btn, .picker-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
.picker.invalid .picker-btn { border-color: var(--err); }
.picker-cur { display: flex; align-items: center; gap: .6rem; min-width: 0; font-weight: 600; }
.picker-cur span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); font-size: .8rem; }
.picker-pop { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 40px rgba(0,0,0,.35); overflow: hidden; }
.picker-search { display: flex; align-items: center; gap: .5rem; padding: .55rem .75rem; border-bottom: 1px solid var(--line); }
.picker-search span { opacity: .6; font-size: .9rem; }
.picker-search input { border: 0; padding: .35rem 0; background: transparent; }
.picker-search input:focus { outline: none; }
.picker-list { list-style: none; margin: 0; padding: .3rem; max-height: 320px; overflow-y: auto; }
.picker-list li { display: flex; align-items: center; gap: .65rem; padding: .45rem .55rem; border-radius: 8px; cursor: pointer; font-size: .93rem; }
.picker-list li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-list li.act { background: var(--brand-soft); }
.picker-list li.sel { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.picker-list li.sel .tag-key { background: rgba(255,255,255,.25); color: inherit; }
.picker-empty { padding: .8rem 1rem; margin: 0; }
.app-ico { width: 28px; height: 28px; border-radius: 7px; object-fit: cover; flex: none; background: #0b0d10; display: inline-block; }
.app-ico.ph { display: inline-flex; align-items: center; justify-content: center; font-size: .66rem; font-weight: 700; color: var(--brand); background: var(--brand-soft); }
.app-cell { display: inline-flex; align-items: center; gap: .5rem; }
.app-cell .app-ico { width: 22px; height: 22px; border-radius: 6px; }
dd .app-cell .app-ico { width: 24px; height: 24px; }
.tag-key { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .08rem .4rem; border-radius: 99px; background: var(--warn-bg); color: var(--warn); }
[data-key-hint].need { color: var(--warn); font-weight: 600; }
