:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --line: #e2e7ee;
  --line-2: #eef1f5;
  --text: #1b2733;
  --muted: #677789;
  --brand: #0f766e;
  --brand-2: #0b5d57;
  --brand-soft: #e3f3f1;
  --side: #0e1f2c;
  --side-2: #16303f;
  --ok: #157a3c;
  --ok-soft: #dcf5e4;
  --warn: #a65a05;
  --warn-soft: #fdf1d6;
  --err: #b42323;
  --err-soft: #fde3e3;
  --info: #1f4fc2;
  --info-soft: #e0e9fd;
  --gray-soft: #edf0f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .25);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); }
.mono { font-family: "Cascadia Mono", Consolas, "Courier New", monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--side); color: #cfdbe5;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px 18px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 18px;
}
.brand-name { color: #fff; font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: #8aa0b3; }
.nav { display: flex; flex-direction: column; padding: 8px 10px; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #c3d1dc; text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--side-2); color: #fff; }
.nav a.active { background: #1d4050; color: #fff; }
.nav a.active .ico { color: #2dd4bf; }
.sidebar-foot { margin-top: auto; padding: 16px; }
.mock-flag {
  font-size: 11px; letter-spacing: .04em; color: #fcd34d; border: 1px dashed #735f1d;
  border-radius: 6px; padding: 6px 8px; text-align: center;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 28px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { margin: 0; font-size: 20px; }
.page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.env { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 99px; }
.env.prod { background: var(--ok-soft); color: var(--ok); }
.env.homolog { background: var(--warn-soft); color: var(--warn); }
.view { padding: 24px 28px 48px; max-width: 1480px; width: 100%; }

/* ---------- Icons ---------- */
.ico { display: inline-flex; width: 16px; height: 16px; flex-shrink: 0; }
.ico svg { width: 100%; height: 100%; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; background: var(--gray-soft); white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #e2e7ed; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: var(--panel); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--err-soft); color: var(--err); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px; background: transparent; color: var(--muted); }
.btn-icon:hover { background: var(--gray-soft); color: var(--text); }
.link { background: none; border: 0; padding: 0; color: var(--brand); font-weight: 600; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* ---------- Cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.card-h h2, .card-h h3 { margin: 0; font-size: 15px; }
.card-b { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.kpi { padding: 16px 18px; }
.kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-size: 28px; font-weight: 700; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kpi.accent { border-left: 4px solid var(--warn); }
.two-col { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tbody tr:hover { background: #f8fafb; }
tbody tr.sel { background: #effaf8; }
tbody tr.clickable { cursor: pointer; }
td .sub { font-size: 12px; color: var(--muted); }
td .sub.mono { white-space: nowrap; }
.chk { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 99px; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.nodot::before { display: none; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-err { background: var(--err-soft); color: var(--err); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-gray { background: var(--gray-soft); color: var(--muted); }
.tag { font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 5px; letter-spacing: .02em; }
.tag-emit { background: #e6f0ff; color: #2451b3; }
.tag-rec { background: #f3e8ff; color: #7433b8; }

/* ---------- Progress ---------- */
.bar { height: 7px; background: var(--gray-soft); border-radius: 99px; overflow: hidden; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .15s; }
.bar.warn > span { background: #f59e0b; }
.frac { display: flex; align-items: center; gap: 10px; }
.frac .bar { flex: 1; }
.frac-txt { font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 52px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field > label { font-size: 12.5px; font-weight: 600; color: #3b4a59; }
.input, select.input {
  border: 1px solid #cfd7e0; border-radius: 8px; padding: 8px 10px; background: #fff; min-width: 0; width: 100%;
}
.input:focus { outline: 2px solid #99e0d6; border-color: var(--brand); }
.hint { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.err-txt { font-size: 12px; color: var(--err); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.checks label { display: inline-flex; gap: 7px; align-items: center; font-size: 13.5px; cursor: pointer; }
.fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.fieldset-t { font-weight: 700; font-size: 13px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }

/* ---------- Filters ---------- */
.filters { padding: 14px 18px; display: grid; grid-template-columns: 1.4fr 1.6fr 1fr 1fr 1fr 1.3fr; gap: 12px; align-items: end; }
.seg { display: inline-flex; background: var(--gray-soft); border-radius: 8px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.period-row { display: flex; gap: 8px; align-items: center; padding: 0 18px 14px; flex-wrap: wrap; }
.period-row .input { width: 150px; }
.summary-strip { display: flex; gap: 0; border-top: 1px solid var(--line-2); }
.summary-strip > div { flex: 1; padding: 12px 18px; border-right: 1px solid var(--line-2); }
.summary-strip > div:last-child { border-right: 0; }
.summary-strip .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary-strip .l { font-size: 12px; color: var(--muted); }

.actionbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 18px; flex-wrap: wrap;
}
.selbar { background: #e9f7f5; border: 1px solid #b7e4dd; border-radius: 8px; padding: 8px 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; color: var(--muted); font-size: 13px; }

/* ---------- Modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 25, 35, .45); z-index: 20; }
.modal {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 30; background: #fff;
  border-radius: 14px; box-shadow: var(--shadow-lg); width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
}
.modal.wide { width: min(880px, calc(100vw - 32px)); }
.modal-h { padding: 18px 22px 12px; display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.modal-h h2 { margin: 0; font-size: 18px; }
.modal-b { padding: 6px 22px 18px; overflow-y: auto; }
.modal-f { padding: 14px 22px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 10px; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: #fff; z-index: 30;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.drawer .modal-b { flex: 1; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }
.section-t { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 0 10px; }
pre.xml {
  background: #0f1d28; color: #cfe3f1; padding: 14px; border-radius: 8px; font-size: 12px; overflow: auto; max-height: 340px;
  white-space: pre;
}

.plist { display: flex; flex-direction: column; gap: 10px; }
.pitem { display: grid; grid-template-columns: 1fr 200px 120px; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 8px; }
.pitem .res { font-size: 12.5px; }
.big-progress { margin: 6px 0 16px; }
.big-progress .bar { height: 10px; }
.tree { font-family: Consolas, monospace; font-size: 12.5px; background: #f7f9fb; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; line-height: 1.7; white-space: pre; overflow-x: auto; }
.callout { border-radius: 10px; padding: 12px 14px; font-size: 13px; display: flex; gap: 10px; align-items: flex-start; }
.callout.info { background: var(--info-soft); color: #1b3f91; }
.callout.warn { background: var(--warn-soft); color: #7a4304; }
.callout.ok { background: var(--ok-soft); color: #11602f; }
.callout .ico { margin-top: 2px; }

/* ---------- Lists ---------- */
.alist { list-style: none; margin: 0; padding: 0; }
.alist li { padding: 11px 18px; border-bottom: 1px solid var(--line-2); display: flex; gap: 10px; align-items: flex-start; font-size: 13px; }
.alist li:last-child { border-bottom: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: #10212e; color: #fff; padding: 11px 16px; border-radius: 9px; box-shadow: var(--shadow-lg); font-size: 13.5px; max-width: 380px; animation: tin .2s ease-out; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Flow (Como funciona) ---------- */
.flow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; align-items: stretch; }
.flow-step { position: relative; border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fff; }
.flow-step .n { width: 24px; height: 24px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; font-size: 12px; display: grid; place-items: center; margin-bottom: 8px; }
.flow-step h4 { margin: 0 0 6px; font-size: 13.5px; }
.flow-step p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.flow-step code { font-size: 11.5px; background: var(--gray-soft); padding: 1px 4px; border-radius: 4px; color: var(--text); }
.prose { line-height: 1.6; font-size: 13.5px; }
.prose code { background: var(--gray-soft); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.prose ul { padding-left: 20px; margin: 6px 0; }
.prose li { margin-bottom: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
  .flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .sidebar-foot { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { position: static; flex-wrap: wrap; padding: 14px 16px; }
  .view { padding: 16px; }
  .filters, .form-grid { grid-template-columns: 1fr; }
  .pitem { grid-template-columns: 1fr; }
  .flow { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
}

/* ---------- Sistema real: login, menu do usuário, estados ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, #0e1f2c 0%, #133040 55%, #0f766e 140%); }
.login-card { width: min(400px, 100%); background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); padding: 30px 28px; }
.login-card .brand { padding: 0 0 18px; }
.login-card .brand-name { color: var(--text); font-size: 17px; }
.login-card .brand-sub { color: var(--muted); }
.login-card h2 { margin: 0 0 4px; font-size: 19px; }
.login-card form { display: grid; gap: 14px; margin-top: 18px; }
.login-card .btn { justify-content: center; padding: 10px 14px; }
.user-menu { position: relative; }
.user-btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 4px 12px 4px 4px; cursor: pointer; font-weight: 600; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-2); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.user-drop { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 220px; padding: 6px; z-index: 15; }
.user-drop .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line-2); margin-bottom: 4px; }
.user-drop button { display: flex; width: 100%; gap: 8px; align-items: center; background: none; border: 0; padding: 9px 10px; border-radius: 7px; cursor: pointer; text-align: left; }
.user-drop button:hover { background: var(--bg); }
.sync-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--info-soft); color: var(--info); font-weight: 600; font-size: 12.5px; padding: 6px 12px; border-radius: 99px; cursor: pointer; border: 0; }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira .7s linear infinite; display: inline-block; flex-shrink: 0; }
@keyframes gira { to { transform: rotate(360deg); } }
.carregando { padding: 48px; display: flex; gap: 10px; justify-content: center; align-items: center; color: var(--muted); }
.vazio { padding: 48px 24px; text-align: center; }
.vazio h3 { margin: 10px 0 6px; }
.vazio p { color: var(--muted); margin: 0 auto 16px; max-width: 460px; line-height: 1.5; }
.vazio .ico { width: 34px; height: 34px; color: var(--brand); }
.senha-box { font-family: Consolas, monospace; font-size: 18px; letter-spacing: .04em; background: var(--bg); border: 1px dashed #b7c3cf; border-radius: 8px; padding: 12px 14px; text-align: center; user-select: all; }
.stat-list { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: 13.5px; }
.stat-list .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.readonly-note { font-size: 12.5px; color: var(--muted); background: var(--bg); padding: 8px 12px; border-radius: 8px; }
.form-erro { background: var(--err-soft); color: var(--err); border-radius: 8px; padding: 9px 12px; font-size: 13px; }
.btn-danger:hover { background: #fbd0d0; }
