:root {
  --blue: #0a66c2;
  --blue-dark: #004182;
  --blue-soft: #e8f3ff;
  --bg: #f4f2ee;
  --card: #ffffff;
  --border: #e0dfdc;
  --text: rgba(0, 0, 0, .9);
  --muted: rgba(0, 0, 0, .6);
  --green: #057642;
  --green-soft: #e3f3ea;
  --red: #cc1016;
  --red-soft: #fdeceb;
  --amber: #915907;
  --amber-soft: #fbf0da;
  --hover: #f3f2ef;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0; }
p { margin: 0; }

/* Topbar */
.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1128px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 600; font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; display: block; }
.brand-name { font-weight: 500; letter-spacing: -.2px; }
.brand-name b { font-weight: 700; color: var(--blue); }
.nav { display: flex; margin-left: auto; height: 100%; }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 84px; padding: 0 8px; color: var(--muted); font-size: 12px; border-bottom: 2px solid transparent; }
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); border-bottom-color: var(--text); }
.nav svg { width: 22px; height: 22px; fill: currentColor; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #b0b0b0; }
.live.on i { background: var(--green); box-shadow: 0 0 0 0 rgba(5, 118, 66, .5); animation: pulse 2s infinite; }
.live.off i { background: var(--red); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(5, 118, 66, 0); } 100% { box-shadow: 0 0 0 0 rgba(5, 118, 66, 0); } }

/* Layout */
.container { max-width: 1128px; margin: 0 auto; padding: 24px 16px 64px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 2px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-body { padding: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-form { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.stat { padding: 14px 16px; }
.stat small { color: var(--muted); font-size: 12px; display: block; }
.stat b { font-size: 26px; font-weight: 600; line-height: 1.2; }
.stat.ok b { color: var(--green); }
.stat.fail b { color: var(--red); }
.stat.blue b { color: var(--blue); }
.muted { color: var(--muted); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.back { font-weight: 600; font-size: 13px; }

/* Formulários */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; font: inherit; color: var(--text); background: #fff;
  border: 1px solid rgba(0, 0, 0, .6); border-radius: 4px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; min-height: 60px; }
.row { display: flex; gap: 8px; }
.row > .method { flex: 0 0 96px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
details.adv { margin-bottom: 12px; }
details.adv summary { cursor: pointer; color: var(--blue); font-weight: 600; font-size: 13px; margin-bottom: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  font: inherit; font-weight: 600; padding: 6px 16px; border-radius: 999px;
  border: 1px solid var(--blue); background: var(--blue); color: #fff; white-space: nowrap;
}
.btn:hover { background: var(--blue-dark); border-color: var(--blue-dark); text-decoration: none; }
.btn.ghost { background: transparent; color: var(--blue); }
.btn.ghost:hover { background: var(--blue-soft); box-shadow: inset 0 0 0 1px var(--blue); }
.btn.gray { background: transparent; color: var(--muted); border-color: rgba(0, 0, 0, .6); }
.btn.gray:hover { background: var(--hover); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .6); }
.btn.danger { background: transparent; color: var(--red); border-color: transparent; padding: 6px 10px; }
.btn.danger:hover { background: var(--red-soft); }
.btn.sm { padding: 3px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Listas */
.list-item { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; font-size: 15px; }
.avatar { width: 44px; height: 44px; border-radius: 4px; background: var(--blue-soft); color: var(--blue); font-weight: 700; display: grid; place-items: center; flex: none; font-size: 16px; }
.url { font-family: var(--mono); font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-box { display: flex; align-items: center; gap: 8px; background: var(--hover); border: 1px solid var(--border); border-radius: 4px; padding: 6px 6px 6px 10px; font-family: var(--mono); font-size: 12px; margin-top: 6px; }
.link-box span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* APIs de uma rota, agrupadas por fornecedor */
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.api-group-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #fafaf9; border-bottom: 1px solid var(--border); font-weight: 600; }
.api-group-head .count { margin-left: auto; font-size: 12px; font-weight: 400; color: var(--muted); }
.api-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.api-row:last-child { border-bottom: 0; }
.api-row:hover { background: #fcfcfb; }
.api-row .name { grid-column: 1 / -1; font-weight: 600; }
.api-row .meta { margin-left: 8px; font-size: 12px; font-weight: 400; color: var(--muted); }
.api-row .meta code, .api-link .ph { background: var(--amber-soft); color: var(--amber); border-radius: 3px; padding: 0 4px; font-family: var(--mono); font-size: 12px; }
.api-link { font-family: var(--mono); font-size: 12px; background: var(--hover); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.api-link .dim { color: var(--muted); }
.api-link .path { color: var(--blue); }
.api-link .badge { margin-right: 4px; }
@media (max-width: 640px) { .api-row { grid-template-columns: minmax(0, 1fr); } }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); vertical-align: middle; }
.badge.ok { background: var(--green-soft); color: var(--green); }
.badge.fail { background: var(--red-soft); color: var(--red); }
.badge.method { background: var(--blue-soft); color: var(--blue); font-family: var(--mono); }
.badge.warn { background: var(--amber-soft); color: var(--amber); }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child > td { border-bottom: 0; }
tr.log-row { cursor: pointer; }
tr.log-row:hover { background: var(--hover); }
tr.log-row.new { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--blue-soft); } to { background: transparent; } }
tr.log-detail td { background: #fafaf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }
.err { color: var(--red); }
pre {
  margin: 0; padding: 12px; background: #1b1f23; color: #e6edf3; border-radius: 6px;
  font: 12px/1.5 var(--mono); overflow: auto; max-height: 340px; white-space: pre-wrap; word-break: break-word;
}
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 12px; margin-bottom: 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-all; }

/* Gráfico */
.chart { width: 100%; height: 200px; display: block; }
.chart text { font-size: 10px; fill: rgba(0, 0, 0, .6); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }
.bar-line { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.bar-line .track { flex: 1; height: 8px; background: var(--hover); border-radius: 4px; overflow: hidden; display: flex; }
.bar-line .track i { display: block; height: 100%; }

/* Modal e toast */
dialog { border: 0; border-radius: 8px; padding: 0; width: min(680px, calc(100vw - 32px)); box-shadow: 0 8px 32px rgba(0, 0, 0, .3); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.modal-head { padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-content { padding: 16px 20px; max-height: 70vh; overflow: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); border-radius: 50%; width: 32px; height: 32px; }
.x:hover { background: var(--hover); }
.result-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 24px; left: 24px; background: #1b1f23; color: #fff; padding: 12px 16px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); z-index: 100; max-width: 360px; }
.toast.error { background: var(--red); }

@media (max-width: 900px) {
  .grid-2, .grid-form { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .nav a { min-width: 0; padding: 0 10px; }
  .nav a span, .brand-name, .live span { display: none; }
}

/* Tela de acesso (fora do Telegram ou ID não liberado) */
.gate { max-width: 420px; margin: 40px auto; padding: 28px 24px; text-align: center; display: grid; gap: 10px; justify-items: center; }
.gate .link-box { width: 100%; text-align: left; }
[hidden] { display: none !important; }

/* Celular / Mini App do Telegram */
@media (max-width: 640px) {
  .container { padding: 14px 10px 48px; gap: 12px; }
  .topbar-inner { padding-left: 10px; padding-right: 10px; gap: 6px; }
  .nav { flex: 1; justify-content: space-around; }
  .nav a { padding: 0 6px; }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .list-item { flex-wrap: wrap; }
  .list-item .actions { width: 100%; flex-direction: row !important; }
  .card-head { flex-wrap: wrap; gap: 8px; }
  .api-row .actions .btn { flex: 1; }
  .api-link { white-space: normal; word-break: break-all; }
  .toast { left: 10px; right: 10px; bottom: 14px; max-width: none; }
  dialog { width: calc(100vw - 20px); max-width: none; }
  input, select, textarea { font-size: 16px; } /* evita o zoom automático do iOS */
}

/* Busca nos logs */
.search { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; }
.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 11px 0; font: inherit; box-shadow: none; }
.search #lf-count { font-size: 12px; white-space: nowrap; }
