
.dbg {
  --dbg-ok: var(--success);
  --dbg-warn: var(--gold);
  --dbg-bad: var(--danger);
  position: fixed;
  z-index: 500;
  inset-inline-end: 10px;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 10px);
  width: min(320px, calc(100vw - 20px));
  max-height: min(62vh, 520px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--bg-panel);
  box-shadow: 0 10px 28px -12px color-mix(in srgb, var(--black) 75%, transparent);
  color: var(--text-hi);
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  touch-action: manipulation;
}
.dbg.is-dragging { opacity: 0.92; }

.dbg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding-block: 4px;
  padding-inline: 12px 4px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.dbg.is-dragging .dbg-head { cursor: grabbing; }
.dbg-head strong { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.dbg-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.dbg-dot[data-level="ok"] { background: var(--dbg-ok); }
.dbg-dot[data-level="warn"] { background: var(--dbg-warn); }
.dbg-dot[data-level="bad"] { background: var(--dbg-bad); }
.dbg-status { flex: 0 1 auto; min-width: 0; color: var(--text-faint); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dbg-status:empty { display: none; }
.dbg-live { display: inline-flex; gap: 6px; margin-inline-start: auto; white-space: nowrap; font: 600 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.dbg-live b:empty { display: none; }
.dbg-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-mid);
}
.dbg-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.dbg-icon:active { background: var(--glass-2); }

.dbg-body { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.dbg.is-min .dbg-body { display: none; }
.dbg.is-min .dbg-head { border-bottom: 0; }
.dbg details { border-bottom: 1px solid var(--line); }
.dbg summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-low);
  cursor: pointer;
  list-style: none;
}
.dbg summary::-webkit-details-marker { display: none; }
.dbg summary::after {
  content: '';
  width: 6px; height: 6px;
  border-inline-end: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 160ms ease;
}
[dir="rtl"] .dbg summary::after { transform: rotate(45deg); }
.dbg details[open] > summary::after { transform: rotate(45deg); }
.dbg summary span { flex: 1 1 auto; }
.dbg summary em { font: 500 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace; font-style: normal; letter-spacing: 0; text-transform: none; color: var(--text-mid); }
.dbg-sec { padding: 0 12px 10px; }

.dbg dl { margin: 0; }
.dbg-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.dbg-row dt { color: var(--text-low); }
.dbg-row dd { margin: 0; text-align: end; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-variant-numeric: tabular-nums; }
.dbg-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.dbg-table th { padding: 2px 0; font-weight: 500; color: var(--text-low); text-align: end; }
.dbg-table th:first-child, .dbg-table td:first-child { text-align: start; }
.dbg-table td { padding: 2px 0; text-align: end; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.dbg-note, .dbg-empty { margin: 4px 0 0; color: var(--text-faint); }
.dbg-list { margin: 0; padding: 0; list-style: none; }
.dbg-list li { position: relative; padding: 4px 0 4px; padding-inline-end: 34px; border-bottom: 1px solid var(--line); word-break: break-word; }
.dbg-list li:last-child { border-bottom: 0; }
.dbg-list small { display: block; color: var(--text-faint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.dbg-list time { position: absolute; inset-inline-end: 0; top: 4px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.dbg-tag { margin-inline-end: 6px; padding: 0 5px; border-radius: 4px; background: color-mix(in srgb, var(--dbg-bad) 16%, transparent); color: var(--dbg-bad); font-size: 10.5px; }

.dbg [data-level="ok"] { color: var(--dbg-ok); }
.dbg [data-level="warn"] { color: var(--dbg-warn); }
.dbg [data-level="bad"] { color: var(--dbg-bad); }
.dbg-list li[data-level] { color: var(--text-hi); }
.dbg-list li[data-level="bad"]::before, .dbg-list li[data-level="ok"]::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-inline-end: 6px;
  border-radius: 50%;
  vertical-align: 1px;
  background: currentColor;
}
.dbg-list li[data-level="bad"]::before { background: var(--dbg-bad); }
.dbg-list li[data-level="ok"]::before { background: var(--dbg-ok); }

.dbg-actions { display: flex; gap: 8px; padding: 10px 12px 12px; }
.dbg-actions button {
  flex: 1;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-raised);
  color: inherit;
  font: inherit;
  font-weight: 600;
}
.dbg-actions button:last-child { flex: 0 0 auto; padding: 0 14px; background: transparent; }
.dbg-actions button:active { transform: scale(0.98); }
