:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --hover: #f6f7f9;
  --accent: #2563eb;
  --error: #b91c1c;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e6e8eb;
    --muted: #9aa3af;
    --line: #262b33;
    --hover: #171a20;
    --accent: #60a5fa;
    --error: #f87171;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1.5rem;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
  flex-wrap: wrap;
}

input[type="search"] {
  min-width: 18rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}

input[type="search"]:focus-visible,
select:focus-visible,
button:focus-visible,
tbody tr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.per-page {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  white-space: nowrap;
}

select,
button {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--hover);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
}

.status {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* -- table --------------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  transition: opacity 120ms ease;
}

table.stale {
  opacity: 0.6;
}

th,
td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
}

th.sortable {
  cursor: pointer;
}

th.sortable:hover {
  color: var(--fg);
}

.arrow {
  margin-left: 0.3rem;
  font-size: 0.7em;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: var(--hover);
}

tr.expanded {
  background: var(--hover);
}

td.time {
  white-space: nowrap;
  color: var(--muted);
}

td.num {
  font-family: var(--mono);
  font-size: 0.9em;
  white-space: nowrap;
}

td.msg {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  border-bottom: none;
}

.msg-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
}

button.copy {
  padding: 0.1rem 0.35rem;
  border-color: transparent;
  color: var(--muted);
  line-height: 1.2;
}

td.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

/* -- detail panel -------------------------------------------------------- */

tr.detail-row td {
  background: var(--hover);
  padding: 0;
}

.detail {
  padding: 0.9rem 1rem;
}

.detail dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1rem;
  margin: 0 0 0.75rem;
}

.detail dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.detail dd {
  margin: 0;
}

.full-message {
  white-space: pre-wrap;
  word-break: break-word;
}

.detail pre {
  margin: 0.5rem 0 0;
  padding: 0.65rem;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 0.85em;
}

.detail summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

code {
  font-family: var(--mono);
  font-size: 0.9em;
}

/* -- pager --------------------------------------------------------------- */

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: center;
  margin: 1rem 0;
}

.pager button {
  min-width: 2.2rem;
  text-align: center;
}

.pager button.current {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

.pager .gap {
  padding: 0.35rem 0.2rem;
  color: var(--muted);
}

/* -- misc ---------------------------------------------------------------- */

.centered {
  max-width: 24rem;
  margin: 15vh auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.muted {
  color: var(--muted);
}

.error {
  color: var(--error);
}

@media (max-width: 640px) {
  body {
    padding: 1rem 0.75rem;
  }

  .controls {
    width: 100%;
  }

  input[type="search"] {
    min-width: 0;
    flex: 1;
  }
}
