:root {
  color-scheme: dark;
  --bg: #101214;
  --surface: #171a1d;
  --surface-2: #1f2428;
  --surface-3: #252b30;
  --line: #30363d;
  --text: #eef2f5;
  --muted: #9aa5ad;
  --accent: #4fb477;
  --info: #5a9bdc;
  --warn: #e0a84f;
  --danger: #e06b6b;
  --debug: #9b87d4;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: #53616d;
  background: var(--surface-3);
}

input[type="search"] {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111417;
  color: var(--text);
  padding: 0 10px;
  outline: none;
  min-width: 0;
}

input[type="search"]:focus {
  border-color: var(--info);
}

.shell {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: clamp(24px, 3vw, 36px);
  font-weight: 720;
}

.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.top-actions,
.log-toolbar,
.level-toolbar,
.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--muted);
  user-select: none;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric,
.mini-metric {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  min-width: 0;
}

.metric {
  padding: 14px;
  min-height: 104px;
}

.metric span,
.mini-metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric span {
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 27px;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.tabs {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.layout {
  display: grid;
  gap: 14px;
}

.layout.two {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.layout.three {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1fr);
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  min-height: 54px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 680;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.kv {
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}

.kv-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
  min-height: 28px;
  align-items: start;
}

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

.kv-value {
  overflow-wrap: anywhere;
}

.code-block {
  margin: 0;
  padding: 14px;
  min-height: 360px;
  max-height: calc(100vh - 310px);
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  background: #0c0f11;
  color: #d9e1e7;
  white-space: pre;
}

.table {
  max-height: calc(100vh - 310px);
  min-height: 360px;
  overflow: auto;
}

.row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) 78px minmax(120px, 0.8fr) minmax(0, 1.8fr);
  gap: 12px;
  align-items: center;
  min-height: 46px;
  padding: 8px 14px;
  border-bottom: 1px solid #252b30;
}

.row.header {
  position: sticky;
  top: 0;
  background: #1c2024;
  color: var(--muted);
  font-size: 12px;
  z-index: 1;
}

.row:not(.header):hover {
  background: #1b2024;
}

.cell {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge,
.mini-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.badge {
  min-width: 54px;
  height: 24px;
  padding: 0 8px;
  font-size: 12px;
}

.mini-badge {
  min-width: 44px;
  height: 22px;
  padding: 0 7px;
  font-size: 12px;
}

.badge.ok,
.mini-badge.ok {
  border-color: rgba(79, 180, 119, 0.45);
  color: #83d09f;
}

.badge.warn,
.mini-badge.warn {
  border-color: rgba(224, 168, 79, 0.45);
  color: #f0c070;
}

.badge.bad,
.mini-badge.bad {
  border-color: rgba(224, 107, 107, 0.45);
  color: #ee8a8a;
}

.badge.debug,
.mini-badge.debug {
  border-color: rgba(155, 135, 212, 0.45);
  color: #b9a8ea;
}

.log-toolbar {
  margin-bottom: 10px;
}

.log-toolbar input {
  flex: 1 1 280px;
}

.source.active,
.level-filter.active {
  border-color: var(--accent);
  color: #9be0b2;
}

.level-toolbar {
  margin-bottom: 12px;
}

.log-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.mini-metric {
  padding: 12px 14px;
  min-height: 86px;
}

.mini-metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.mini-metric.danger strong {
  color: #ee8a8a;
}

.mini-metric.warn strong {
  color: #f0c070;
}

.log-visuals,
.log-sections {
  margin-bottom: 14px;
}

.bar-chart {
  padding: 14px;
  display: grid;
  gap: 12px;
  min-height: 204px;
}

.bar-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 10px;
  min-height: 24px;
}

.bar-label {
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  height: 12px;
  border-radius: 999px;
  background: #101417;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: var(--info);
}

.bar-fill.level-error {
  background: var(--danger);
}

.bar-fill.level-warn {
  background: var(--warn);
}

.bar-fill.level-info {
  background: var(--accent);
}

.bar-fill.level-debug,
.bar-fill.level-trace {
  background: var(--debug);
}

.bar-fill.level-other {
  background: #74808a;
}

.bar-fill.source-astrbot {
  background: var(--info);
}

.bar-fill.source-napcat {
  background: var(--accent);
}

.bar-row strong {
  text-align: right;
  font-size: 12px;
}

.timeline-chart {
  min-height: 204px;
  padding: 14px;
  display: flex;
  align-items: end;
  gap: 8px;
  overflow-x: auto;
}

.timeline-item {
  min-width: 42px;
  display: grid;
  gap: 7px;
  justify-items: center;
}

.timeline-bar {
  width: 22px;
  min-height: 8px;
  border-radius: 5px 5px 3px 3px;
  background: var(--info);
  overflow: hidden;
  display: flex;
  align-items: end;
}

.timeline-critical {
  width: 100%;
  min-height: 0;
  background: var(--danger);
}

.timeline-item span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
  writing-mode: vertical-rl;
  max-height: 72px;
}

.important-list,
.file-list {
  min-height: 278px;
  max-height: 390px;
  overflow: auto;
}

.important-item,
.file-row {
  padding: 10px 14px;
  border-bottom: 1px solid #252b30;
}

.important-item {
  border-left: 3px solid #74808a;
}

.important-item.level-error {
  border-left-color: var(--danger);
}

.important-item.level-warn {
  border-left-color: var(--warn);
}

.important-item.level-info {
  border-left-color: var(--accent);
}

.important-item.level-debug,
.important-item.level-trace {
  border-left-color: var(--debug);
}

.important-meta {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
  overflow-wrap: anywhere;
}

.important-text {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.file-row.ok {
  border-left: 3px solid var(--accent);
}

.file-row.bad {
  border-left: 3px solid var(--danger);
}

.file-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.file-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.file-main span {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.log-stream-panel {
  margin-bottom: 0;
}

.log-list {
  max-height: 660px;
  overflow: auto;
  background: #0c0f11;
}

.log-entry {
  border-left: 3px solid #74808a;
  border-bottom: 1px solid #20262b;
  padding: 10px 12px 11px;
  display: grid;
  gap: 8px;
}

.log-entry.level-error {
  border-left-color: var(--danger);
  background: rgba(224, 107, 107, 0.055);
}

.log-entry.level-warn {
  border-left-color: var(--warn);
  background: rgba(224, 168, 79, 0.055);
}

.log-entry.level-info {
  border-left-color: var(--accent);
}

.log-entry.level-debug,
.log-entry.level-trace {
  border-left-color: var(--debug);
}

.log-entry-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.log-time,
.log-source,
.log-scope,
.log-module,
.log-level-source {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid #2a3137;
  border-radius: 999px;
  background: #12171a;
  padding: 0 8px;
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 420px;
}

.log-source {
  color: #9fc5ef;
}

.log-scope {
  color: #9be0b2;
}

.log-module {
  color: #c9bdf1;
}

.log-level-source {
  color: #aab4bc;
}

.log-entry-summary {
  color: #e4ebf0;
  font-size: 13px;
  line-height: 1.58;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.log-entry-details {
  border-top: 1px solid #20262b;
  padding-top: 7px;
}

.log-entry-details summary {
  width: fit-content;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.log-entry-details summary:hover {
  color: var(--text);
}

.log-entry-text {
  margin: 8px 0 0;
  padding: 10px;
  border: 1px solid #20262b;
  border-radius: 6px;
  background: #090c0e;
  color: #d9e1e7;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
  overflow-x: auto;
}

.log-list.wrap .log-entry-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty {
  padding: 18px 14px;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #1c2024;
  color: var(--text);
  padding: 10px 12px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1120px) {
  .layout.three {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-grid,
  .log-metrics,
  .layout.two {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: minmax(0, 1fr) 72px;
  }

  .row .cell:nth-child(3),
  .row .cell:nth-child(4),
  .row.header .cell:nth-child(3),
  .row.header .cell:nth-child(4) {
    display: none;
  }

  .kv-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .code-block,
  .table {
    min-height: 300px;
    max-height: 520px;
  }

  .log-time,
  .log-source,
  .log-module {
    max-width: 100%;
  }

  .important-list,
  .file-list {
    min-height: 220px;
    max-height: 340px;
  }
}
