/* ---------------------------------------------------------------------------
   Tokens
--------------------------------------------------------------------------- */
:root {
  --font-ui: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
}

[data-bs-theme='dark'] {
  --wc-bg: #0d1417;
  --wc-surface: #131d21;
  --wc-surface-2: #1a272c;
  --wc-line: #243339;
  --wc-guide: #2a3c43;
  --wc-text: #dbe6e9;
  --wc-muted: #7f949b;
  --wc-accent: #e4f0f2;
  --wc-accent-ink: #0d1417;

  --t-key: #86d0e6;
  --t-str: #b5dc8a;
  --t-num: #f2a86e;
  --t-bool: #d5a1f2;
  --t-null: #7f949b;
  --t-punc: #8fa2a9;

  --m-get: #5aa9ff;
  --m-post: #3fbf82;
  --m-put: #f0a04b;
  --m-patch: #b990f2;
  --m-delete: #f47474;
  --m-other: #8b9ca2;

  --wc-live: #3fbf82;
  --wc-warn: #f0b455;
}

[data-bs-theme='light'] {
  --wc-bg: #f2f5f5;
  --wc-surface: #ffffff;
  --wc-surface-2: #e9eff0;
  --wc-line: #d8e1e3;
  --wc-guide: #d0dadd;
  --wc-text: #16272c;
  --wc-muted: #58707a;
  --wc-accent: #12262b;
  --wc-accent-ink: #f2f5f5;

  --t-key: #0a6c8b;
  --t-str: #3b7a1c;
  --t-num: #b0530a;
  --t-bool: #8a3dbc;
  --t-null: #6b8189;
  --t-punc: #5c727a;

  --m-get: #1d6fd6;
  --m-post: #1f8a58;
  --m-put: #b86a12;
  --m-patch: #7b46c4;
  --m-delete: #c73d3d;
  --m-other: #5c727a;

  --wc-live: #1f8a58;
  --wc-warn: #a86a00;
}

/* Bootstrap lê estas variáveis; apontamos para os nossos tokens */
[data-bs-theme] {
  --bs-body-bg: var(--wc-bg);
  --bs-body-color: var(--wc-text);
  --bs-body-font-family: var(--font-ui);
  --bs-border-color: var(--wc-line);
  --bs-secondary-color: var(--wc-muted);
  --bs-tertiary-bg: var(--wc-surface-2);
  --bs-secondary-bg: var(--wc-surface-2);
  --bs-emphasis-color: var(--wc-text);
}

/* Botões do Bootstrap com a nossa paleta */
.btn-outline-secondary {
  --bs-btn-color: var(--wc-text);
  --bs-btn-border-color: var(--wc-line);
  --bs-btn-hover-color: var(--wc-text);
  --bs-btn-hover-bg: var(--wc-surface-2);
  --bs-btn-hover-border-color: var(--wc-guide);
  --bs-btn-active-color: var(--wc-accent-ink);
  --bs-btn-active-bg: var(--wc-accent);
  --bs-btn-active-border-color: var(--wc-accent);
  --bs-btn-focus-shadow-rgb: 127, 148, 155;
}

/* ---------------------------------------------------------------------------
   Base
--------------------------------------------------------------------------- */
html, body { height: 100%; }
body { font-family: var(--font-ui); background: var(--wc-bg); color: var(--wc-text); font-size: 0.95rem; }
.mono, code, pre { font-family: var(--font-mono); }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* ---------------------------------------------------------------------------
   Barra superior
--------------------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--wc-line);
  background: var(--wc-surface);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand svg { color: var(--wc-live); }

.status { display: flex; align-items: center; gap: 0.45rem; font-size: 0.85rem; color: var(--wc-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--wc-warn); }
.dot.live { background: var(--wc-live); animation: pulse 2.4s ease-out infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--wc-live) 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 7px transparent; }
}

.endpoint { flex: 1 1 320px; max-width: 560px; }
.endpoint .input-group-text,
.endpoint .form-control { background: var(--wc-bg); border-color: var(--wc-line); color: var(--wc-muted); }
.endpoint .form-control { color: var(--wc-text); font-size: 0.82rem; }
.endpoint .form-control:focus { box-shadow: none; border-color: var(--wc-guide); }

.actions { display: flex; align-items: center; gap: 0.6rem; margin-left: auto; flex-wrap: wrap; }
.actions .form-check-input { cursor: pointer; }
.actions .form-check-input:checked { background-color: var(--wc-live); border-color: var(--wc-live); }
.actions .form-check-label { cursor: pointer; font-size: 0.85rem; user-select: none; }
.icon-btn { display: inline-flex; align-items: center; padding: 0.25rem 0.5rem; }

/* ---------------------------------------------------------------------------
   Layout principal
--------------------------------------------------------------------------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(270px, 340px) minmax(0, 1fr);
}

.sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--wc-line); background: var(--wc-surface); }
.side-head { display: flex; align-items: center; gap: 0.5rem; padding: 0.7rem 1rem; border-bottom: 1px solid var(--wc-line); }
.count-pill { font-size: 0.75rem; padding: 0.05rem 0.5rem; border-radius: 999px; background: var(--wc-surface-2); color: var(--wc-muted); font-variant-numeric: tabular-nums; }
.ev-list { flex: 1; overflow-y: auto; }
.side-empty { margin: 0; padding: 1.25rem 1rem; color: var(--wc-muted); font-size: 0.88rem; }

.detail { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

@media (max-width: 991.98px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(110px, 32%) minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--wc-line); }
  .endpoint { max-width: none; order: 5; flex-basis: 100%; }
  .actions { margin-left: 0; }
}

/* ---------------------------------------------------------------------------
   Lista de requests
--------------------------------------------------------------------------- */
.ev {
  --mc: var(--m-other);
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 1rem 0.6rem calc(1rem - 3px);
  border: 0;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--wc-line);
  background: transparent;
  color: inherit;
}
.ev:hover { background: var(--wc-surface-2); }
.ev.active { background: var(--wc-surface-2); border-left-color: var(--mc); }
.ev:focus-visible { outline: 2px solid var(--wc-muted); outline-offset: -2px; }
.ev.is-new { animation: arrive 1.4s ease-out; }
@keyframes arrive { from { background: color-mix(in srgb, var(--mc) 22%, transparent); } }
.ev.unread .ev-path::after { content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 0.4rem; border-radius: 50%; background: var(--wc-live); vertical-align: middle; }
.ev-top { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }
.ev-path { font-size: 0.8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ev-sub { display: flex; justify-content: space-between; margin-top: 0.2rem; padding-left: 0; font-size: 0.75rem; color: var(--wc-muted); font-variant-numeric: tabular-nums; }

.method {
  --mc: var(--m-other);
  flex: none;
  min-width: 3.4rem;
  text-align: center;
  padding: 0.08rem 0.4rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--mc);
  background: color-mix(in srgb, var(--mc) 15%, transparent);
  border: 1px solid color-mix(in srgb, var(--mc) 35%, transparent);
}
.m-GET { --mc: var(--m-get); }
.m-POST { --mc: var(--m-post); }
.m-PUT { --mc: var(--m-put); }
.m-PATCH { --mc: var(--m-patch); }
.m-DELETE { --mc: var(--m-delete); }

/* ---------------------------------------------------------------------------
   Detalhe
--------------------------------------------------------------------------- */
.d-head { padding: 1rem 1.25rem 0.75rem; }
.d-title { display: flex; align-items: center; gap: 0.75rem; }
.d-url { margin: 0; font-size: 1.05rem; font-weight: 500; word-break: break-all; min-width: 0; flex: 1; }
.d-q { color: var(--wc-muted); }
.d-meta { display: flex; flex-wrap: wrap; gap: 0.3rem 1.5rem; margin: 0.6rem 0 0; font-size: 0.82rem; }
.d-meta div { display: flex; gap: 0.4rem; }
.d-meta dt { font-weight: 400; color: var(--wc-muted); }
.d-meta dd { margin: 0; font-variant-numeric: tabular-nums; }

.d-tabs { padding: 0 1.25rem; border-bottom: 1px solid var(--wc-line); gap: 1.25rem; }
.d-tabs .nav-link { padding: 0.5rem 0; color: var(--wc-muted); font-weight: 500; border-bottom-width: 2px; background: none; border-top: 0; border-left: 0; border-right: 0; }
.d-tabs .nav-link:hover { color: var(--wc-text); }
.d-tabs .nav-link.active { color: var(--wc-text); border-bottom-color: var(--wc-text); font-weight: 500; }
.d-tabs .tab-count { margin-left: 0.3rem; font-size: 0.72rem; padding: 0.02rem 0.4rem; border-radius: 999px; background: var(--wc-surface-2); color: var(--wc-muted); }

.d-panel { flex: 1; min-height: 0; overflow: auto; padding: 0 1.25rem 1.5rem; }

.b-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 0;
  background: var(--wc-bg);
}
.b-bar .spacer { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.b-bar .btn { font-size: 0.8rem; }
.hint { align-self: center; font-size: 0.75rem; color: var(--wc-muted); }
@media (max-width: 1199.98px) { .hint { display: none; } }
.tag { font-size: 0.75rem; padding: 0.12rem 0.5rem; border-radius: 4px; background: var(--wc-surface-2); color: var(--wc-muted); }
.tag.warn { background: color-mix(in srgb, var(--wc-warn) 16%, transparent); color: var(--wc-warn); cursor: help; }

.b-body { border: 1px solid var(--wc-line); border-radius: 8px; background: var(--wc-surface); overflow: hidden; }
.code { margin: 0; padding: 1rem 1.1rem; font-size: 0.82rem; line-height: 1.65; overflow: auto; white-space: pre; color: var(--wc-text); background: transparent; border: 0; }
.code.wrap { white-space: pre-wrap; word-break: break-word; }
.b-empty { padding: 1.5rem 1.1rem; color: var(--wc-muted); }
.alert { --bs-alert-bg: color-mix(in srgb, var(--wc-warn) 12%, transparent); --bs-alert-color: var(--wc-text); --bs-alert-border-color: color-mix(in srgb, var(--wc-warn) 35%, transparent); font-size: 0.85rem; }

.wc-table { --bs-table-bg: transparent; --bs-table-color: var(--wc-text); --bs-table-border-color: var(--wc-line); margin: 0; font-size: 0.82rem; }
.wc-table th { width: 32%; max-width: 320px; font-weight: 500; color: var(--t-key); font-family: var(--font-mono); word-break: break-all; vertical-align: top; padding: 0.55rem 1.1rem; }
.wc-table td { font-family: var(--font-mono); word-break: break-all; padding: 0.55rem 1.1rem; }
.wc-table tr:last-child > * { border-bottom: 0; }

/* Estado vazio */
.empty { max-width: 640px; margin: auto; padding: 2rem 1.5rem; }
.empty h2 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
.empty p { color: var(--wc-muted); }
.empty .code { margin-bottom: 1rem; border: 1px solid var(--wc-line); border-radius: 8px; background: var(--wc-surface); font-size: 0.8rem; }
.btn-primary { --bs-btn-bg: var(--wc-accent); --bs-btn-border-color: var(--wc-accent); --bs-btn-color: var(--wc-accent-ink); --bs-btn-hover-bg: var(--wc-text); --bs-btn-hover-border-color: var(--wc-text); --bs-btn-hover-color: var(--wc-accent-ink); --bs-btn-active-bg: var(--wc-text); --bs-btn-active-color: var(--wc-accent-ink); --bs-btn-focus-shadow-rgb: 127, 148, 155; }

/* ---------------------------------------------------------------------------
   Árvore JSON
--------------------------------------------------------------------------- */
.tree { padding: 0.85rem 1rem 1.1rem; font-family: var(--font-mono); font-size: 0.83rem; line-height: 1.7; overflow-x: auto; }

/* toda linha reserva a "calha" do caret, para as chaves ficarem alinhadas */
.jrow, .jhead { position: relative; padding-left: 1.15rem; white-space: pre-wrap; word-break: break-word; }
.jkids { margin-left: 0.5rem; padding-left: 0.65rem; border-left: 1px solid var(--wc-guide); }

.jhead { cursor: pointer; border-radius: 4px; }
.jhead:hover { background: color-mix(in srgb, var(--wc-text) 6%, transparent); }
.jhead:focus-visible { outline: 2px solid var(--wc-muted); outline-offset: 1px; }

.caret { position: absolute; left: 0; top: 0; width: 1.15rem; height: 1.7em; display: flex; align-items: center; justify-content: center; }
.caret::before {
  content: '';
  border-left: 5px solid var(--wc-muted);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.12s ease;
}
.jn:not(.collapsed) > .jhead .caret::before { transform: rotate(90deg); }

/* recolhido: uma linha só, com um resumo. aberto: some o resumo. */
.jn.collapsed > .jkids,
.jn.collapsed > .jend { display: none; }
.jn:not(.collapsed) > .jhead .jinline,
.jn:not(.collapsed) > .jhead .jsum { display: none; }
.jsum { margin-left: 0.5rem; padding: 0 0.45rem; border-radius: 4px; font-family: var(--font-ui); font-size: 0.72rem; color: var(--wc-muted); background: var(--wc-surface-2); }
.jtag { margin-left: 0.5rem; padding: 0 0.4rem; border-radius: 4px; font-family: var(--font-ui); font-size: 0.68rem; color: var(--wc-warn); background: color-mix(in srgb, var(--wc-warn) 14%, transparent); }

.t-key { color: var(--t-key); }
.t-str { color: var(--t-str); }
.t-num { color: var(--t-num); }
.t-bool { color: var(--t-bool); }
.t-null { color: var(--t-null); font-style: italic; }
.t-punc { color: var(--t-punc); }
.t-idx { color: var(--wc-muted); }

/* ---------------------------------------------------------------------------
   Toast
--------------------------------------------------------------------------- */
.toast { --bs-toast-bg: var(--wc-accent); --bs-toast-color: var(--wc-accent-ink); --bs-toast-font-size: 0.85rem; }

@media (prefers-reduced-motion: reduce) {
  .dot.live, .ev.is-new { animation: none; }
  .caret::before { transition: none; }
}
