/* mcp-gateway client panel — self-contained, no external assets/CDN.
   Light/dark via prefers-color-scheme. Small, responsive, pt-BR UI. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f0f3fa;
  --border: #e2e8f0;
  --text: #1a2233;
  --muted: #667085;
  --primary: #3557ff;
  --primary-ink: #ffffff;
  --primary-soft: #eaefff;
  --success: #1f9d55;
  --danger: #d23b3b;
  --danger-soft: #fdecec;
  --warn: #b7791f;
  --track: #e6eaf2;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.06);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1220;
    --surface: #171c2c;
    --surface-2: #1e2436;
    --border: #2a3145;
    --text: #e8ecf6;
    --muted: #94a0b8;
    --primary: #6d8bff;
    --primary-ink: #0b1020;
    --primary-soft: #23304f;
    --success: #47c07f;
    --danger: #f27171;
    --danger-soft: #3a2226;
    --warn: #e0b25a;
    --track: #2a3145;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 30px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 18px 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1.05rem;
  margin-bottom: 22px;
}
.brand svg { width: 26px; height: 26px; color: var(--primary); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

.card h2 { margin: 0 0 4px; font-size: 1.05rem; }
.card .sub { color: var(--muted); font-size: 0.88rem; margin: 0 0 16px; }

h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.02em; }
.lead { color: var(--muted); margin: 0 0 20px; }

label { display: block; font-size: 0.85rem; font-weight: 600; margin: 12px 0 6px; }

input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  background: var(--primary);
  color: var(--primary-ink);
  transition: filter 0.15s, background 0.15s;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.small { padding: 7px 12px; font-size: 0.85rem; }

.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row .btn { flex: 0 0 auto; }
.spacer { flex: 1 1 auto; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } }

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.stat .k { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .v { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }

.meter { margin-top: 14px; }
.meter .track { height: 10px; background: var(--track); border-radius: 999px; overflow: hidden; }
.meter .fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width 0.3s ease; }
.meter .fill.warn { background: var(--warn); }
.meter .fill.full { background: var(--danger); }
.meter .cap { display: flex; justify-content: space-between; font-size: 0.82rem; color: var(--muted); margin-top: 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.pill.ok { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.token-box {
  display: flex;
  gap: 8px;
  align-items: stretch;
  margin-top: 12px;
}
.token-box code {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  overflow-x: auto;
  white-space: nowrap;
}

.notice { font-size: 0.82rem; color: var(--warn); margin-top: 8px; }

.msg { font-size: 0.88rem; margin-top: 12px; padding: 10px 12px; border-radius: 10px; display: none; }
.msg.show { display: block; }
.msg.err { background: var(--danger-soft); color: var(--danger); }
.msg.ok { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }

.hidden { display: none !important; }

.foot { text-align: center; color: var(--muted); font-size: 0.8rem; margin-top: 28px; }
.foot a { text-decoration: none; }

/* Manual page */
.steps { counter-reset: step; padding: 0; margin: 0; list-style: none; }
.steps > li { position: relative; padding: 4px 0 18px 42px; }
.steps > li::before {
  counter-increment: step;
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  background: var(--primary); color: var(--primary-ink);
  border-radius: 50%; font-size: 0.85rem; font-weight: 700;
}
.steps h3 { margin: 2px 0 6px; font-size: 0.98rem; }
.steps p { margin: 0 0 8px; color: var(--muted); font-size: 0.9rem; }

pre.code {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 14px;
  overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  margin: 8px 0;
}
pre.code code { white-space: pre; }

.copybtn {
  position: absolute; top: 8px; right: 8px;
}

/* ============================================================
   Admin console
   ============================================================ */

.wrap-wide { max-width: 1180px; margin: 0 auto; padding: 24px 18px 64px; }

.admin-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.admin-head .spacer { flex: 1 1 auto; }
.admin-head h1 { margin: 0; }

/* Guard / restricted screen */
.guard-box { max-width: 460px; margin: 10vh auto 0; text-align: center; }
.guard-box .big { font-size: 2.2rem; margin-bottom: 6px; }

/* Two-column layout: main + activity aside */
.admin-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
@media (max-width: 960px) { .admin-layout { grid-template-columns: 1fr; } }

.admin-aside { position: sticky; top: 18px; }
@media (max-width: 960px) { .admin-aside { position: static; } }

/* Section header with an action on the right */
.sec-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sec-head h2 { margin: 0; }
.sec-head .spacer { flex: 1 1 auto; }

/* Users table */
.table-scroll { overflow-x: auto; margin: 0 -4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.tbl th, table.tbl td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
table.tbl th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; }
table.tbl tbody tr { cursor: pointer; transition: background 0.12s; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl .u-label { font-weight: 700; }
table.tbl .u-email { color: var(--muted); font-size: 0.82rem; }

/* Chips (packages) */
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.chip.analise { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); border-color: transparent; }
.chip.escrita { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }
.chip.reservado { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* Role badge */
.badge { display: inline-flex; align-items: center; font-size: 0.72rem; font-weight: 700; padding: 2px 9px; border-radius: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge.admin { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.badge.client { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.mini-num { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px; font-size: 0.78rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.mini-num.hot { background: var(--danger-soft); color: var(--danger); }

/* Checkbox / radio groups */
.check-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.check {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); font-size: 0.86rem; font-weight: 600; cursor: pointer; user-select: none;
}
.check input { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
.check.on { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 40px; height: 23px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: var(--track); border-radius: 999px; transition: background 0.18s; cursor: pointer; }
.switch .slider::before { content: ""; position: absolute; height: 17px; width: 17px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.18s; box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::before { transform: translateX(17px); }
.switch input:disabled + .slider { opacity: 0.5; cursor: default; }

/* Drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 24, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 40; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 520px; max-width: 94vw;
  background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0,0,0,0.22);
  transform: translateX(100%); transition: transform 0.24s ease; z-index: 41;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 1.15rem; }
.drawer-head .u-email { color: var(--muted); font-size: 0.85rem; }
.drawer-close { margin-left: auto; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 1.1rem; line-height: 1; flex: 0 0 auto; }
.drawer-close:hover { filter: brightness(1.06); }
.drawer-body { overflow-y: auto; padding: 18px 20px 40px; flex: 1 1 auto; }

.dsec { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 14px; background: var(--surface); }
.dsec h3 { margin: 0 0 4px; font-size: 0.95rem; }
.dsec .sub { color: var(--muted); font-size: 0.82rem; margin: 0 0 12px; }

/* Tools grid */
.tool-search { width: 100%; margin-bottom: 10px; }
.tool-list { display: flex; flex-direction: column; gap: 2px; max-height: 340px; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.tool-item { display: flex; align-items: center; gap: 12px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.tool-item:last-child { border-bottom: none; }
.tool-item .ti-main { min-width: 0; flex: 1 1 auto; }
.tool-item .ti-title { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-item .ti-alias { color: var(--primary); font-size: 0.78rem; font-family: ui-monospace, Menlo, Consolas, monospace; }
.tool-item .ti-real { color: var(--muted); font-size: 0.72rem; font-family: ui-monospace, Menlo, Consolas, monospace; opacity: 0.75; }
.tool-item.denied .ti-title { color: var(--muted); }

/* Tools grid: per-connection grouping, total + source seals */
.tool-total { font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; }
.tool-total strong { color: var(--text); font-size: 0.95rem; }
.tool-group { margin-bottom: 8px; }
.tool-group .tg-head { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; background: var(--surface); padding: 8px 4px 6px; z-index: 1; border-bottom: 1px solid var(--border); }
.tool-group .tg-count { color: var(--muted); font-size: 0.74rem; margin-left: auto; white-space: nowrap; }
.seal { display: inline-block; font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 6px; border-radius: 999px; vertical-align: middle; margin-left: 2px; }
.seal.pkg { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
.seal.granted { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.seal.denied { background: var(--danger-soft); color: var(--danger); }
.seal.off { background: var(--surface-2); color: var(--muted); }

/* Credentials modal (one-time) */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 24, 0.55); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 60; }
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); width: 640px; max-width: 100%; max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal h2 { margin: 0 0 4px; }

/* Tabs (installer) */
.tabs { display: inline-flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin: 6px 0 8px; }
.tabs button { appearance: none; border: none; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 0.83rem; padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* Activity feed */
.feed { display: flex; flex-direction: column; gap: 6px; max-height: 72vh; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.feed-item { display: flex; gap: 10px; padding: 9px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.82rem; align-items: flex-start; }
.feed-item .fi-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto; background: var(--muted); }
.feed-item.ok .fi-dot { background: var(--success); }
.feed-item.err .fi-dot { background: var(--danger); }
.feed-item .fi-main { min-width: 0; flex: 1 1 auto; }
.feed-item .fi-top { display: flex; gap: 8px; align-items: baseline; }
.feed-item .fi-ev { font-weight: 700; }
.feed-item .fi-time { color: var(--muted); font-size: 0.72rem; margin-left: auto; white-space: nowrap; }
.feed-item .fi-sub { color: var(--muted); font-size: 0.76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed-empty { color: var(--muted); font-size: 0.85rem; text-align: center; padding: 24px 0; }

.live-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 0.76rem; font-weight: 600; color: var(--success); }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: pulse 1.6s infinite; }
.live-dot.paused { color: var(--muted); }
.live-dot.paused::before { background: var(--muted); animation: none; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Toast */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { padding: 10px 16px; border-radius: 10px; font-size: 0.86rem; font-weight: 600; box-shadow: var(--shadow); border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.toast.ok { background: color-mix(in srgb, var(--success) 16%, var(--surface)); border-color: transparent; }
.toast.err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

.dim { color: var(--muted); }
.nowrap { white-space: nowrap; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
details.collapse > summary { cursor: pointer; font-weight: 600; list-style: none; }
details.collapse > summary::-webkit-details-marker { display: none; }
details.collapse > summary::before { content: "▸ "; color: var(--muted); }
details.collapse[open] > summary::before { content: "▾ "; }
