:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --ok: #16a34a;
  --warn: #ca8a04;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: #f8fafc;
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font: inherit;
  cursor: pointer;
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-weight: 600;
  transition: background .15s;
}
button:hover { background: var(--primary-hover); }
button.link {
  background: transparent;
  color: var(--primary);
  padding: 4px 8px;
  font-weight: 500;
}
button.danger { background: var(--danger); }
button.danger:hover { background: #b91c1c; }

input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  background: white;
}
input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

code {
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: .9em;
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
}

/* ---------- Login ---------- */
.auth-bg {
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.auth-card {
  background: var(--card);
  padding: 40px 32px;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
  width: min(380px, calc(100% - 32px));
}
.auth-card h1 {
  margin: 0 0 4px;
  font-size: 24px;
}
.auth-card .subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.auth-card button { margin-top: 8px; padding: 12px; }

/* ---------- App ---------- */
.topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  gap: 24px;
  flex-wrap: wrap;
}
.topbar h1 { margin: 0; font-size: 18px; }
.topbar h1 a { color: var(--text); }
.topbar .nav { display: flex; gap: 18px; flex: 1; }
.topbar .nav a {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.topbar .nav a:hover { color: var(--text); text-decoration: none; }
.topbar .nav a.active { color: var(--primary); border-bottom-color: var(--primary); }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.inline { display: inline; margin: 0; padding: 0; }

.container {
  max-width: 720px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.container-wide { max-width: 920px; }
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); }

.row { display: flex; gap: 8px; }
.row.between { justify-content: space-between; align-items: center; }
.row input { flex: 1; }

.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
}
.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.success { background: #dcfce7; color: var(--ok); border: 1px solid #bbf7d0; }
.success-msg {
  background: #dcfce7;
  color: var(--ok);
  border: 1px solid #bbf7d0;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  margin: 0;
}

.muted { color: var(--muted); font-size: 14px; }
.ok { color: var(--ok); font-weight: 500; }

.instances { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.instance-link {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.instance-link:hover { background: #f1f5f9; text-decoration: none; }
.instance-link strong { font-size: 14px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: #f1f5f9;
  color: var(--muted);
}
.badge-open, .badge-connected { background: #dcfce7; color: var(--ok); }
.badge-connecting { background: #fef3c7; color: var(--warn); }
.badge-close, .badge-error, .badge-unknown { background: #fee2e2; color: var(--danger); }

.qr {
  display: block;
  margin: 16px auto;
  width: min(280px, 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: white;
  padding: 8px;
}

.danger-zone { border-color: #fecaca; background: #fffafa; }

/* ---------- Form fields (usado em credentials, account, etc.) ---------- */
.field { margin-top: 16px; }
.field:first-of-type { margin-top: 0; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.field label code { font-size: 11px; }

/* Botao de submit que segue uma sequencia de .field ganha respiro */
.field + button[type="submit"],
.field ~ button[type="submit"] {
  margin-top: 20px;
}

.copy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.copy-row code {
  flex: 1;
  min-width: 200px;
  font-size: 13px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  transition: all .15s;
}
.btn-secondary:hover { background: #f1f5f9; border-color: #cbd5e1; }
.btn-secondary.ok { background: #dcfce7; color: var(--ok); border-color: #bbf7d0; }

.link-arrow {
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Code blocks (docs) ---------- */
pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.55;
}
pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
}
.card h3 {
  margin: 18px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .03em;
}

/* HTTP method tags inline em titulos de endpoint */
.method {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: .05em;
  vertical-align: middle;
  margin-right: 4px;
  color: white;
}
.method.get { background: #2563eb; }
.method.post { background: #16a34a; }
.method.delete { background: #dc2626; }
.method.put { background: #ca8a04; }

/* Tabela de parametros */
.params {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0 16px;
}
.params th, .params td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.params th {
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #f8fafc;
}
.params code { font-size: 12px; }

.card ul { padding-left: 20px; line-height: 1.65; }
.card ul li { margin: 4px 0; }

/* ---------- Docs header (com botao Baixar PDF) ---------- */
.docs-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin: 8px 0 4px;
  flex-wrap: wrap;
}
.docs-title { margin: 0 0 4px; font-size: 22px; }
.docs-header p { margin: 0; }
.docs-header .btn-secondary { white-space: nowrap; flex-shrink: 0; }

.print-only { display: none; }
.print-cover h1 { margin: 0 0 8px; }

/* ---------- Print stylesheet ---------- */
@media print {
  /* Esconder cromos da UI */
  .topbar,
  .no-print,
  .danger-zone,
  .copy-row button,
  button { display: none !important; }

  body { background: white; color: #000; font-size: 11pt; }

  .container, .container-wide {
    max-width: none;
    margin: 0;
    padding: 0;
    gap: 12px;
  }

  .print-only { display: block; }
  .print-cover {
    text-align: center;
    padding: 80px 0 40px;
    border-bottom: 2px solid #000;
    margin-bottom: 24px;
    page-break-after: always;
  }
  .print-cover h1 { font-size: 28pt; }
  .print-cover p { font-size: 12pt; }

  /* Cards viram blocos limpos sem fundo/borda */
  .card {
    background: white;
    border: none;
    padding: 0;
    margin-bottom: 16px;
    page-break-inside: avoid;
  }
  .card h2 {
    font-size: 16pt;
    border-bottom: 1px solid #999;
    padding-bottom: 4px;
    margin: 18px 0 10px;
  }
  .card h3 {
    font-size: 11pt;
    color: #000;
    margin: 12px 0 4px;
  }

  /* Code blocks: tema claro pra economizar tinta e ficar legivel impresso */
  pre {
    background: #f5f5f5 !important;
    color: #000 !important;
    border: 1px solid #ddd;
    page-break-inside: avoid;
    font-size: 9pt;
    padding: 10px;
  }
  pre code { color: #000 !important; }
  code {
    background: #f0f0f0 !important;
    color: #000 !important;
    border: 1px solid #e0e0e0;
  }

  /* Card de credenciais: mostra os valores ao inves de campos com botoes */
  .credentials .copy-row code {
    background: #f5f5f5 !important;
    border: 1px solid #ccc;
    color: #000;
  }
  .credentials label { color: #444; }

  /* Tabelas */
  .params { font-size: 9pt; }
  .params th { background: #eee !important; color: #000; }

  /* Links: mostrar URL em parentesis ao lado do texto */
  a[href]:not([href^="#"])::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #666;
    word-break: break-all;
  }
  a { color: #000; text-decoration: underline; }

  /* Method badges */
  .method {
    background: none !important;
    color: #000 !important;
    border: 1px solid #000;
    padding: 1px 4px;
  }

  /* Garante quebra de pagina razoavel */
  h2 { page-break-before: auto; page-break-after: avoid; }
  h3 { page-break-after: avoid; }
}
