:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #cfd7e3;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eaf1ff;
  --side-bg: #0d1424;
  --side-bg-2: #141d31;
  --side-text: #a8b3c7;
  --side-text-active: #ffffff;
  --ok: #15803d;      --ok-bg: #e7f6ec;
  --warn: #a16207;    --warn-bg: #fdf4dc;
  --err: #b91c1c;     --err-bg: #fdecec;
  --info: #1d4ed8;    --info-bg: #e8effd;
  --muted: #475569;   --muted-bg: #eef1f5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .18);
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111a2c; --surface-2: #0f1727; --border: #1f2a40; --border-strong: #2c3a55;
    --text: #e6ebf3; --text-2: #b4bfd0; --text-3: #8592a8; --primary: #3b82f6; --primary-hover: #60a5fa;
    --primary-soft: #16264a; --side-bg: #070c17; --side-bg-2: #0e1628;
    --ok: #4ade80; --ok-bg: #0f2a1b; --warn: #facc15; --warn-bg: #2b240b; --err: #f87171; --err-bg: #2f1414;
    --info: #93c5fd; --info-bg: #13244a; --muted: #b4bfd0; --muted-bg: #1a2438;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--sans); font-size: 14px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }

/* splash */
.splash { height: 100vh; display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 700; letter-spacing: .08em; color: var(--text-2); }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary) url("favicon.svg") center/cover; flex: none; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a8a33, transparent 60%), radial-gradient(900px 500px at 110% 110%, #0ea5e922, transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px 28px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand .logo-mark { width: 40px; height: 40px; border-radius: 10px; }
.login-brand strong { font-size: 20px; letter-spacing: .06em; }
.login-sub { color: var(--text-3); margin: 0 0 24px; }
.login-card .campo { margin-bottom: 14px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; margin-top: 6px; }
.login-rodape { margin-top: 18px; font-size: 12px; color: var(--text-3); text-align: center; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 224px; flex: none; background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 18px; color: #fff; font-weight: 700; letter-spacing: .08em; }
.side-nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.side-sec { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: #5f6b82; padding: 14px 12px 6px; }
.side-nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: var(--side-text); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
.side-nav a:hover { background: var(--side-bg-2); color: #fff; }
.side-nav a.ativo { background: var(--primary); color: var(--side-text-active); }
.side-nav svg { width: 18px; height: 18px; flex: none; }
.side-user { border-top: 1px solid #1c2740; padding: 14px 16px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #1e3a8a; color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.side-user .quem { min-width: 0; flex: 1; }
.side-user .quem b { display: block; color: #fff; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .quem span { font-size: 12px; color: #7d8aa3; }
.side-user button { background: none; border: 0; color: var(--side-text); cursor: pointer; padding: 6px; border-radius: 6px; }
.side-user button:hover { background: var(--side-bg-2); color: #fff; }
.side-user svg { width: 18px; height: 18px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.conteudo { padding: 26px 26px 48px; max-width: 1680px; width: 100%; }

/* headings */
.cabecalho { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.cabecalho h1 { margin: 0; font-size: 26px; letter-spacing: .01em; font-weight: 800; }
.cabecalho .sub { color: var(--text-3); margin-top: 4px; }
.titulo-principal { font-size: 30px !important; letter-spacing: .02em !important; }
h2 { font-size: 16px; margin: 0 0 12px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .rot { color: var(--text-3); font-size: 12.5px; font-weight: 600; }
.kpi .val { font-size: 28px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .val.pq { font-size: 15px; font-weight: 700; }
.kpi.ok .val { color: var(--ok); } .kpi.err .val { color: var(--err); } .kpi.warn .val { color: var(--warn); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* toolbar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.busca { position: relative; flex: 1 1 320px; min-width: 220px; }
.busca svg { position: absolute; left: 11px; top: 50%; width: 17px; height: 17px; margin-top: -8.5px; color: var(--text-3); }
.busca input[type=search] { padding-left: 36px; }
.toolbar select { width: auto; min-width: 150px; }
.toolbar .esp { flex: 1; }

/* form */
.campo label { display: block; font-weight: 600; font-size: 12.5px; color: var(--text-2); margin-bottom: 5px; }
.campo .ajuda { font-size: 12px; color: var(--text-3); margin-top: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); outline: none; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px #2563eb22; }
textarea { min-height: 80px; resize: vertical; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--primary); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.erro-form { background: var(--err-bg); color: var(--err); padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; font-weight: 500; }
.aviso { background: var(--warn-bg); color: var(--warn); padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.info { background: var(--info-bg); color: var(--info); padding: 10px 12px; border-radius: 8px; font-size: 13px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--err); }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-copiar { padding: 6px 10px; font-size: 12.5px; background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.btn-copiar:hover { background: var(--primary); color: #fff; }
.icon-btn { display: inline-grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 6px; background: transparent; color: var(--text-3); cursor: pointer; vertical-align: middle; flex: none; }
.icon-btn:hover { background: var(--muted-bg); color: var(--primary); }
.icon-btn svg { width: 15px; height: 15px; }
.acoes { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }

/* table */
.tabela-wrap { overflow-x: auto; }
.scroll-topo { overflow-x: scroll; overflow-y: hidden; height: 16px; margin-bottom: 4px; }
.scroll-topo > div { height: 1px; }
.scroll-topo::-webkit-scrollbar, .tabela-wrap::-webkit-scrollbar { height: 12px; }
.scroll-topo::-webkit-scrollbar-thumb, .tabela-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
.scroll-topo::-webkit-scrollbar-thumb:hover, .tabela-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.scroll-topo::-webkit-scrollbar-track, .tabela-wrap::-webkit-scrollbar-track { background: transparent; }
table.tab { width: 100%; border-collapse: separate; border-spacing: 0; }
.tab th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 700; padding: 10px 9px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.tab th.ord { cursor: pointer; user-select: none; }
.tab th.ord:hover { color: var(--text); }
.tab th .seta { display: inline-block; width: 10px; margin-left: 3px; color: var(--primary); }
.tab td { padding: 9px 9px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tab tbody tr:hover td { background: var(--surface-2); }
.tab tbody tr:last-child td { border-bottom: 0; }
.cel { display: inline-flex; align-items: center; gap: 4px; }
.mun b { font-weight: 700; }
.mun span { white-space: nowrap; }
table.cards td { font-size: 13.5px; }
.uf { font-size: 11px; font-weight: 700; color: var(--text-3); margin-left: 6px; }
.senha { display: inline-flex; align-items: center; gap: 4px; }
.senha .val { font-family: var(--mono); font-size: 12.5px; letter-spacing: .04em; }
.vazio { padding: 48px 16px; text-align: center; color: var(--text-3); }
.vazio b { display: block; color: var(--text-2); font-size: 15px; margin-bottom: 4px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; color: var(--text-3); }
.pager .btns { display: flex; gap: 6px; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-err { background: var(--err-bg); color: var(--err); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-muted { background: var(--muted-bg); color: var(--muted); }
.tag { display: inline-block; padding: 2px 7px; border-radius: 5px; background: var(--muted-bg); color: var(--text-2); font-size: 11.5px; font-weight: 600; }

/* lists */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.lista li:last-child { border-bottom: 0; }
.lista .l1 { font-weight: 600; } .lista .l2 { font-size: 12.5px; color: var(--text-3); }

/* modal */
.modal-fundo { position: fixed; inset: 0; background: rgba(8, 13, 25, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.lg { max-width: 820px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.div-item { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; flex-wrap: wrap; }

/* toasts */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 36px); }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; display: flex; align-items: center; gap: 9px; animation: entra .18s ease-out; max-width: 420px; }
.toast.ok { background: #14532d; } .toast.erro { background: #7f1d1d; }
.toast svg { width: 18px; height: 18px; flex: none; }
@keyframes entra { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* tooltip */
[data-tip] { position: relative; }
[data-tip]:hover::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); right: 0; background: #0f172a; color: #fff; font-size: 12px; font-weight: 500; padding: 5px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; z-index: 20; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: gira .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes gira { to { transform: rotate(360deg); } }
.btn.girando svg { animation: gira .8s linear infinite; }
.btn:disabled { opacity: .6; cursor: default; }
.secao + .secao { margin-top: 22px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--text-3); } .kv dd { margin: 0; word-break: break-all; }
pre.erro { white-space: pre-wrap; word-break: break-word; background: var(--err-bg); color: var(--err); padding: 8px 10px; border-radius: 8px; font-size: 12px; margin: 6px 0 0; }

/* coluna de ações fixa à direita (desktop) */
@media (min-width: 901px) {
  table.cards td.td-acoes, table.cards th:last-child { position: sticky; right: 0; background: var(--surface); box-shadow: -8px 0 8px -8px rgba(15,23,42,.18); }
  table.cards th:last-child { background: var(--surface-2); z-index: 2; }
  table.cards tbody tr:hover td.td-acoes { background: var(--surface-2); }
}
/* responsive */
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu-aberto .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .shell.menu-aberto .veu { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 30; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--side-bg); color: #fff; font-weight: 700; letter-spacing: .08em; position: sticky; top: 0; z-index: 20; }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; cursor: pointer; }
  .topbar svg { width: 22px; height: 22px; }
  .conteudo { padding: 18px 16px 40px; }
  .titulo-principal { font-size: 23px !important; }
  .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .toolbar select { flex: 1 1 140px; }

  /* tabela principal vira cartões */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border-bottom: 1px solid var(--border); padding: 10px 14px; }
  table.cards td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  table.cards td::before { content: attr(data-label); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); font-weight: 700; text-align: left; }
  table.cards td.td-mun { font-size: 15px; }
  table.cards td.td-acoes { padding-top: 10px; }
  table.cards td.td-acoes::before { content: none; }
  table.cards td.td-acoes .acoes { width: 100%; }
  table.cards td.td-acoes .btn-copiar { flex: 1; justify-content: center; padding: 10px; font-size: 14px; }
  [data-tip]:hover::after { display: none; }
}
