:root {
  --bg: #f8f9fa; --surface: #ffffff; --ink: #0f172a; --muted: #64748b;
  --faint: #94a3b8; --line: #f1f5f9; --line-soft: #f8fafc;
  --blue: #2563eb; --blue-dark: #1d4ed8; --blue-soft: #dbeafe;
  --green: #16a34a; --green-soft: #f0fdf4;
  --amber: #d97706; --amber-soft: #fffbeb;
  --red: #dc2626; --red-soft: #fef2f2;
  --radius: 8px; --sb-w: 268px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); overflow-x: hidden;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
.ic { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ic-lg { width: 20px; height: 20px; }
.ic-fill { fill: currentColor; stroke: none; }
.menu-wrap { position: relative; flex: none; }
.menu { display: none; position: absolute; right: 0; top: 36px; min-width: 210px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(15,23,42,.12); padding: 5px; z-index: 30; }
.menu.open { display: block; }
.menu-up { top: auto; bottom: 38px; }
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: none; text-align: left; font-size: 13px; font-weight: 500; color: #1e293b; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: #f1f5f9; }
.menu button .ic { width: 15px; height: 15px; color: var(--faint); }
.menu button.danger { color: var(--red); }
.menu button.danger .ic { color: var(--red); }
.menu-sep { height: 1px; background: var(--line-soft); margin: 5px 4px; }
.pill-row { display: flex; gap: 6px; }

/* ---------- modal overlay (usado por modal() em panel.js) ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box { background: #fff; border-radius: 14px; padding: 24px; box-shadow: 0 12px 40px rgba(15,23,42,.18); width: 100%; }
.modal-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 8px; color: var(--ink); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.btn-ghost { background: none; border: 1px solid var(--line); color: var(--muted); }
.btn-ghost:hover { background: #f8fafc; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; overflow-x: hidden; }
/* Sidebar fixo — não rola com a página */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sb-w); height: 100vh; z-index: 40;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  transition: width .22s cubic-bezier(.4,0,.2,1); overflow: hidden;
}
/* Main empurrado pela largura do sidebar */
.main {
  flex: 1; min-width: 0;
  margin-left: var(--sb-w);
  transition: margin-left .22s cubic-bezier(.4,0,.2,1);
}
.shell:has(.sidebar.collapsed) .main { margin-left: 64px; }

/* Sidebar header */
.sidebar-header {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 16px; flex: none;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--blue-soft);
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex: none;
}
.brand-mark img { width: 22px; height: 22px; object-fit: contain; }
.brand-text {
  display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.2;
  overflow: hidden;
}
.brand-name { font-weight: 600; font-size: 14px; letter-spacing: -.01em; white-space: nowrap; color: var(--ink); }
.brand-sub { font-size: 11px; color: var(--faint); margin-top: 2px; white-space: nowrap; }

/* Toggle fixo — sai do fluxo e não é cortado pelo overflow:hidden do sidebar */
.sb-toggle {
  position: fixed;
  left: calc(var(--sb-w) - 11px);
  top: 24px;
  width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: 0 1px 4px rgba(15,23,42,.1);
  cursor: pointer; z-index: 50;
  color: var(--faint); padding: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: auto;
  transition: opacity .15s, left .22s cubic-bezier(.4,0,.2,1), color .15s, box-shadow .15s;
}
.sidebar:hover .sb-toggle,
.sb-toggle:hover { opacity: 1; }
.sb-toggle:hover { color: var(--ink); box-shadow: 0 2px 8px rgba(15,23,42,.16); }
.sb-toggle .ic { width: 11px; height: 11px; transition: transform .22s cubic-bezier(.4,0,.2,1); }

/* Nav */
.nav { flex: 1; padding: 12px 8px; overflow-y: auto; overflow-x: hidden; }
.nav-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--faint); padding: 8px 10px 6px; white-space: nowrap;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px; margin-bottom: 2px;
  color: var(--ink); font-weight: 500; font-size: 14px;
  cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
  white-space: nowrap; overflow: hidden;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.nav-item.active .ic { color: var(--blue); opacity: 1; }
.nav-item .ic { opacity: .8; }
.side-foot { border-top: 1px solid var(--line); padding: 12px 8px; flex: none; }

/* ---------- sidebar collapsed ---------- */
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .sidebar-header { justify-content: center; }
.sidebar.collapsed .brand-text { display: none; }
.sidebar.collapsed .sb-toggle { left: calc(64px - 11px); }
.sidebar.collapsed .sb-toggle .ic { transform: rotate(180deg); }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .txt { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 8px; width: 40px; margin: 2px auto; }
.sidebar.collapsed .user-chip { justify-content: center; padding: 7px 0; }
.sidebar.collapsed .user-chip .icon-btn { display: none; }
.sidebar.collapsed .user-meta { display: none; }
/* ---------- mode toggle (AntD Segmented) ---------- */
.mode-toggle { display: inline-flex; background: rgba(0,0,0,.06); border-radius: 6px; padding: 2px; user-select: none; }
.mode-opt { padding: 2px 9px; border-radius: 4px; font-size: 11.5px; font-weight: 500; color: rgba(0,0,0,.45); cursor: pointer; transition: all .18s; white-space: nowrap; line-height: 18px; }
.mode-opt:hover { color: rgba(0,0,0,.65); }
.mode-opt.active { background: #fff; color: rgba(0,0,0,.88); box-shadow: 0 1px 3px rgba(0,0,0,.12); cursor: default; pointer-events: none; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 10px; }
.user-meta.clickable { cursor: pointer; }
.user-meta.clickable:hover .user-name { color: var(--blue-dark); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--blue-soft); color: var(--blue-dark); font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; flex: none; }
.user-meta { min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: 11.5px; color: var(--muted); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 8px; border: 1px solid transparent; background: none; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: #f1f5f9; color: var(--ink); }
.icon-btn.bordered { border-color: var(--line); background: var(--surface); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

.main { min-width: 0; padding: 28px 32px 60px; max-width: 1180px; overflow-x: hidden; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.page-sub { color: var(--muted); font-size: 13px; margin: 2px 0 0; }
.head-actions { display: flex; gap: 8px; align-items: center; }

.btn { display: inline-flex; align-items: center; gap: 8px; border-radius: 8px; font-size: 13px; font-weight: 600; padding: 9px 14px; cursor: pointer; border: 1px solid transparent; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-secondary { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger-ghost { background: none; border: 0; color: var(--red); }
.btn-block { width: 100%; justify-content: center; padding: 11px; }

.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; height: 36px; min-width: 220px; }
.search input { border: 0; outline: 0; background: none; font-size: 13px; width: 100%; color: var(--ink); }
.search .ic { color: var(--faint); }

.stats-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.stat-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.stat-chip .v { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-sep { color: #d1d5db; font-size: 12px; }

.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .grid { grid-template-columns: 1fr 1fr; } }
.inst { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; transition: border-color .15s, box-shadow .15s; }
.inst:hover { border-color: #d4d9e3; box-shadow: 0 2px 10px rgba(15,23,42,.05); }
.inst-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.inst-name { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.inst-slug { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--faint); margin-top: 1px; }
/* Card envolta da logo da instância */
.inst-logo {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  background: var(--blue-soft); border: 1px solid #bfdbfe;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  box-shadow: 0 1px 3px rgba(37,99,235,.08);
}
.inst-logo img { width: 30px; height: 30px; object-fit: contain; }
.inst-logo-letter { font-weight: 700; font-size: 17px; color: var(--blue); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.pill-green { background: var(--green-soft); color: #389e0d; border: 1px solid #b7eb8f; }
.pill-amber { background: var(--amber-soft); color: #d48806; border: 1px solid #ffe58f; }
.pill-gray  { background: #f1f5f9; color: var(--muted); }
.pill-blue  { background: var(--blue-soft); color: var(--blue-dark); }
.pill-dev   { background: #fff7e6; color: #d46b08; border: 1px solid #ffd591; border-radius: 4px; transition: opacity .15s; }
.pill-dev:hover  { opacity: .75; }
.pill-prod  { background: #f6ffed; color: #389e0d; border: 1px solid #b7eb8f; border-radius: 4px; transition: opacity .15s; }
.pill-prod:hover { opacity: .75; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-green { background: #22c55e; } .dot-amber { background: #f59e0b; } .dot-gray { background: #cbd5e1; }
.pulse { animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.spin { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; display: inline-block; vertical-align: -2px; margin-right: 6px; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.owner-line { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.owner-line .ic { width: 13px; height: 13px; color: var(--faint); }
.inst-actions { display: flex; align-items: center; gap: 4px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.url-block { background: #f8fafc; border: 1px solid var(--line-soft); border-radius: 9px; padding: 9px 11px; display: flex; flex-direction: column; gap: 7px; }
.url-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.url-row .tag { font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); width: 52px; flex: none; }
.url-row code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; color: #334155; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.mini-btn { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: #fff; border-radius: 7px; font-size: 11px; font-weight: 600; color: #334155; padding: 4px 9px; cursor: pointer; white-space: nowrap; }
.mini-btn:hover { background: #f1f5f9; }
.mini-btn .ic { width: 12px; height: 12px; }
.inst-actions .spacer { flex: 1; }
.btn-open { color: var(--blue-dark); font-weight: 600; }
.btn-open:hover { background: var(--blue-soft); }

.empty { border: 1.5px dashed #d4d9e3; border-radius: var(--radius); background: var(--surface); text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .ic-lg { color: #c3cad6; margin-bottom: 10px; }
.empty h3 { color: var(--ink); margin: 0 0 4px; font-size: 15px; }
.empty p { margin: 0 0 16px; font-size: 13px; }
.loading { text-align: center; padding: 56px 0; color: var(--muted); font-size: 13px; }

.section-head { display: flex; align-items: baseline; gap: 8px; margin: 34px 0 12px; }
.section-head h2 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.section-head span { font-size: 12px; color: var(--faint); }
.table-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; font-size: 13px; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); }
tr:last-child td { border-bottom: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--blue-dark); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(440px, 92vw); box-shadow: 0 12px 40px rgba(15,23,42,.16); }
dialog::backdrop { background: rgba(15,23,42,.45); }
dialog .body { padding: 24px; }
dialog h2 { margin: 0 0 4px; font-size: 17px; letter-spacing: -0.01em; }
dialog .desc { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-weight: 400; color: var(--faint); }
.field input, .field textarea { width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 9px 12px; font-size: 14px; color: var(--ink); background: #fff; font-family: inherit; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
.field input::placeholder, .field textarea::placeholder { color: #b3bac7; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.row { display: flex; gap: 8px; align-items: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.small { font-size: 13px; } .tiny { font-size: 11px; }
.muted { color: var(--muted); }
.err { display: none; font-size: 13px; color: var(--red); background: var(--red-soft); border-radius: 8px; padding: 9px 12px; margin-top: 12px; }
.err.show { display: block; }
.danger-text { color: var(--red); }

/* popover="manual" coloca no top-layer do browser — acima de qualquer dialog */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; font-size: 13px; font-weight: 500; padding: 10px 18px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 92vw; border: none; margin: 0; }

/* ---------- auth ---------- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(180deg, rgba(37,99,235,.1) 0%, #eef2ff 100%);
}
.auth-box { width: min(400px, 100%); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; }
.auth-logo-mark {
  width: 56px; height: 56px; border-radius: 16px; background: #fff;
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.auth-logo-mark img { width: 40px; height: 40px; object-fit: contain; }
.auth-title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.auth-card {
  background: var(--surface); border: 1px solid #eef1f6; border-radius: 14px;
  padding: 0 26px 26px; box-shadow: 0 2px 12px rgba(15,23,42,.06);
}
.auth-tabs { display: flex; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.auth-tab {
  flex: 1; border: 0; background: none; padding: 14px 0; font-size: 14px; font-weight: 500;
  color: var(--muted); cursor: pointer; position: relative; transition: color .15s;
}
.auth-tab:hover { color: var(--ink); }
.auth-tab.active { color: var(--blue); font-weight: 600; }
.auth-tab.active::after {
  content: ''; position: absolute; bottom: -1px; left: 0; right: 0;
  height: 2px; background: var(--blue); border-radius: 2px 2px 0 0;
}
.auth-pane { }
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 38px; }
.pass-eye {
  position: absolute; right: 0; top: 0; bottom: 0; width: 38px;
  border: 0; background: none; color: var(--faint); cursor: pointer; display: flex; align-items: center; justify-content: center; border-radius: 0 8px 8px 0;
}
.pass-eye:hover { color: var(--muted); }
.pass-eye .ic { width: 15px; height: 15px; }
.auth-note { text-align: center; font-size: 12px; color: var(--faint); margin-top: 16px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; overflow-x: hidden; }
  .sidebar { position: static; width: 100% !important; height: auto; flex-direction: row; align-items: center; overflow: visible; }
  .sidebar-header { padding: 10px 12px; flex: 0; gap: 8px; }
  .brand-sub { display: none; }
  .nav { flex: 0; padding: 0 4px; display: flex; flex-direction: row; overflow: visible; }
  .nav-label { display: none; }
  .nav-item { width: auto; padding: 8px; margin: 0; }
  .nav-item span.txt { display: none; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0 8px; }
  .user-meta { display: none; }
  .user-chip .icon-btn { display: flex !important; }
  .sb-toggle { display: none !important; }
  .main { margin-left: 0 !important; padding: 20px 16px 50px; }
  .search { min-width: 0; flex: 1; }
}
