*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface2: #eef0f6;
  --border: #d0d5e2;
  --accent: #c0392b;
  --accent2: #1a6db5;
  --text: #1a1e2e;
  --text-dim: #5a6080;
  --text-code: #1a5a9a;
  --error-tag: #c0392b;
  --rejection-tag: #b06800;
  --radius: 6px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

/* ── Top bar ─────────────────────────────────────────────────── */

#top-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.back-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.85rem;
  white-space: nowrap;
}
.back-link:hover { color: var(--text); }

#top-bar h1 {
  font-size: 1.1rem;
  font-weight: 600;
  flex: 1;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#total-count {
  font-size: 0.8rem;
  color: var(--text-dim);
}

#refresh-btn, #info-btn, #mark-all-btn, #show-fixed-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
  transition: background 0.15s;
}
#refresh-btn:hover, #mark-all-btn:hover { background: var(--border); }
#info-btn { color: var(--accent2); border-color: var(--accent2); }
#info-btn:hover { background: rgba(26,109,181,0.1); }
#show-fixed-btn { color: var(--text-dim); }
#show-fixed-btn.active { color: var(--accent2); border-color: var(--accent2); background: rgba(26,109,181,0.1); }
#show-fixed-btn:disabled { opacity: 0.45; cursor: default; }

/* ── Layout ──────────────────────────────────────────────────── */

#layout {
  display: flex;
  height: calc(100vh - 44px);
  overflow: hidden;
}

/* ── App nav sidebar ─────────────────────────────────────────── */

#app-list {
  width: 180px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.5rem 0;
}

.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 0.4rem 0.8rem 0.2rem;
}

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  border-radius: 0;
  font-size: 0.82rem;
  color: var(--text-dim);
  transition: background 0.1s, color 0.1s;
  gap: 0.4rem;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(192,57,43,0.1); color: var(--accent); }

.nav-item-count {
  background: var(--surface2);
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  min-width: 18px;
  text-align: center;
}
.nav-item.active .nav-item-count { background: rgba(192,57,43,0.15); color: var(--accent); }

/* ── Main panel ──────────────────────────────────────────────── */

#main-panel {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

#empty-state {
  margin-top: 3rem;
  text-align: center;
  color: var(--text-dim);
  font-size: 1rem;
}
.hidden { display: none !important; }

/* ── App section ─────────────────────────────────────────────── */

.app-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.app-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}
.app-section-header:hover { background: var(--surface2); }

.app-section-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.app-section-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.section-count {
  background: rgba(192,57,43,0.12);
  color: var(--accent);
  border-radius: 999px;
  padding: 0 0.5rem;
  font-weight: 600;
}

.section-toggle {
  color: var(--text-dim);
  font-size: 0.7rem;
}

.app-section-body {
  border-top: 1px solid var(--border);
}
.app-section-body.collapsed { display: none; }

/* ── Error entry ─────────────────────────────────────────────── */

.error-entry {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.8rem;
}
.error-entry:last-child { border-bottom: none; }

.error-entry.entry-fixed {
  opacity: 0.45;
}

.entry-top {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.mark-fixed-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: auto;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.mark-fixed-btn:hover {
  background: rgba(0,120,0,0.1);
  color: #3a7a3a;
  border-color: #3a7a3a;
}

.fixed-badge {
  font-size: 0.7rem;
  color: #4a7a4a;
  background: rgba(0,100,0,0.08);
  border: 1px solid rgba(0,100,0,0.2);
  border-radius: 3px;
  padding: 0.1rem 0.45rem;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: auto;
}

.type-tag {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: 3px;
  padding: 0.15rem 0.4rem;
  margin-top: 0.05rem;
}
.type-tag.error { background: rgba(192,57,43,0.12); color: #a02010; }
.type-tag.unhandledrejection { background: rgba(192,120,0,0.12); color: #8a5000; }

.entry-message {
  flex: 1;
  font-size: 0.85rem;
  word-break: break-word;
  line-height: 1.4;
}

.entry-meta {
  display: flex;
  gap: 0.8rem;
  margin-top: 0.3rem;
  font-size: 0.73rem;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.entry-meta code {
  color: var(--text-code);
  font-family: 'JetBrains Mono', monospace;
}

.stack-toggle {
  background: none;
  border: none;
  color: var(--accent2);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0;
  margin-top: 0.3rem;
}
.stack-toggle:hover { text-decoration: underline; }

.stack-trace {
  margin-top: 0.4rem;
  background: #eaf0f8;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.7rem;
  font-family: 'JetBrains Mono', 'Courier New', monospace;
  font-size: 0.72rem;
  color: var(--text-code);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 240px;
  overflow-y: auto;
}

/* ── Info overlay ─────────────────────────────────────────────── */

#info-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#info-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(640px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
}

#info-modal h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text);
}

.close-btn {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}
.close-btn:hover { background: var(--surface2); color: var(--text); }

.info-body { display: flex; flex-direction: column; gap: 1rem; }

.info-body section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent2);
  margin-bottom: 0.35rem;
}

.info-body p {
  font-size: 0.83rem;
  line-height: 1.6;
  color: var(--text-dim);
}

.info-body ul {
  margin: 0.3rem 0 0.3rem 1.2rem;
  font-size: 0.83rem;
  line-height: 1.6;
  color: var(--text-dim);
}

.info-body code {
  background: var(--surface2);
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-code);
}

.info-body strong { color: var(--text); }
