:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-muted: #f1f4f6;
  --line: #dbe2e7;
  --line-strong: #b8c4cc;
  --text: #172026;
  --muted: #687782;
  --brand: #2563eb;
  --brand-soft: #e8f0ff;
  --good: #067647;
  --good-soft: #e8f8ef;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --bad: #b42318;
  --bad-soft: #fff0ee;
  --violet: #6d28d9;
  --violet-soft: #f0eafe;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.top-actions form {
  margin: 0;
}

.topbar {
  height: 68px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.title-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 16px;
}

h3 {
  font-size: 14px;
}

p {
  margin: 0;
}

.chips,
.top-actions,
.tab-row,
.log-tabs,
.log-actions,
.badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chip,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.chip-ok,
.badge.good {
  color: var(--good);
  border-color: #97d8b4;
  background: var(--good-soft);
}

.badge.bad {
  color: var(--bad);
  border-color: #f2afa8;
  background: var(--bad-soft);
}

.badge.warn {
  color: var(--warn);
  border-color: #f0c56d;
  background: var(--warn-soft);
}

.badge.blue {
  color: var(--brand);
  border-color: #a9c5ff;
  background: var(--brand-soft);
}

.badge.violet {
  color: var(--violet);
  border-color: #cab6f5;
  background: var(--violet-soft);
}

.search,
.date-input,
.log-input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--panel);
  color: var(--text);
}

.overview {
  display: grid;
  grid-template-columns: minmax(180px, 250px) minmax(0, 1fr) minmax(280px, 420px);
  gap: 12px;
  align-items: stretch;
  padding: 10px 12px 0;
}

.overview-head,
.overview-cards,
.overview-latency {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
}

.overview-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.overview-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.overview-head select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 6px 8px;
}

.overview-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 8px;
}

.overview-stat {
  min-width: 0;
  padding-right: 8px;
  border-right: 1px solid var(--line);
}

.overview-stat:last-child {
  border-right: 0;
}

.overview-stat b {
  display: block;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.overview-stat span,
.overview-latency li {
  color: var(--muted);
  font-size: 11px;
}

.overview-latency ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 18px;
}

.login-panel label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.login-panel input,
.login-panel button {
  width: 100%;
  min-height: 44px;
}

.login-panel button {
  margin-top: 16px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
}

.login-panel .error {
  color: var(--bad);
  margin-bottom: 12px;
}

.search {
  width: min(360px, 36vw);
}

.date-controls {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.icon-button,
.tab,
.small-button,
.quick-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.icon-button {
  width: 38px;
  height: 38px;
}

.tab,
.small-button,
.quick-button {
  padding: 8px 10px;
  font-size: 13px;
}

.tab.active,
.small-button.primary,
.quick-button.active {
  background: var(--text);
  border-color: var(--text);
  color: #ffffff;
}

.layout {
  height: calc(100vh - 180px);
  display: grid;
  grid-template-columns: 300px minmax(380px, 480px) minmax(520px, 1fr);
  gap: 12px;
  padding: 12px;
  overflow: hidden;
}

.pane {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.reports-pane {
  display: flex;
  flex-direction: column;
}

.users-pane {
  display: flex;
  flex-direction: column;
}

.users-pane .scroll {
  flex: 1;
  min-height: 0;
  height: auto;
}

.pane-head {
  min-height: 70px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.pane-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.reports-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.tab-row {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-muted);
}

.scroll {
  overflow: auto;
  height: calc(100% - 70px);
}

.reports-list {
  flex: 1;
  min-height: 0;
  height: auto;
  padding: 10px;
}

.report-more-row {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-muted);
}

.user-more-row {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-muted);
}

.user-more-row .small-button {
  width: 100%;
}

.report-more-row .small-button {
  width: 100%;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid #7aa7ff;
  outline-offset: 2px;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.user-row,
.report-card {
  width: 100%;
  display: block;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.user-row {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.user-row:hover,
.user-row.active,
.report-card:hover,
.report-card.active {
  border-color: #9cb8f8;
  background: var(--brand-soft);
}

.user-main,
.report-main,
.event-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.label {
  font-weight: 700;
  overflow-wrap: anywhere;
  white-space: normal;
}

.meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
  white-space: normal;
}

.report-card {
  margin-bottom: 10px;
  padding: 12px;
  border-color: var(--line);
  background: var(--panel);
}

.report-time {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.metric-grid.four {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.metric {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
  overflow-wrap: anywhere;
}

.metric.wide {
  grid-column: 1 / -1;
}

.metric b {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.metric span {
  display: block;
  margin-top: 4px;
  font-weight: 700;
  overflow: visible;
  overflow-wrap: anywhere;
  white-space: normal;
  word-break: break-word;
}

.metric-json {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: #172026;
  color: #e6edf2;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

.log-help {
  margin-top: -2px;
}

.detail-body {
  height: calc(100% - 70px);
  overflow: auto;
  padding: 12px;
}

.empty {
  color: var(--muted);
  padding: 22px;
  text-align: center;
}

.section {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.section-body {
  padding: 12px;
}

.timeline {
  display: grid;
  gap: 8px;
}

.stage-flow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.stage-chip {
  min-height: 52px;
  display: grid;
  justify-items: start;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.stage-chip span {
  color: var(--muted);
  font-size: 11px;
}

.timeline-item {
  display: grid;
  grid-template-columns: minmax(86px, auto) minmax(0, 1fr);
  gap: 10px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.timeline-item time {
  color: var(--brand);
  font-weight: 700;
}

.log-toolbar {
  display: grid;
  gap: 10px;
}

.log-filters {
  display: grid;
  grid-template-columns: 1.4fr repeat(4, minmax(90px, 1fr)) auto;
  gap: 8px;
}

.event-list {
  border-top: 1px solid var(--line);
}

.event-row {
  border-bottom: 1px solid var(--line);
}

.event-summary {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 86px 64px minmax(0, 1fr);
  gap: 8px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.event-summary:hover {
  background: var(--panel-muted);
}

.event-time,
.event-level {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.event-message {
  word-break: break-word;
}

.event-raw {
  margin: 0;
  padding: 12px 12px 12px 198px;
  background: #172026;
  color: #e6edf2;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

.hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #172026;
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.24);
  transform: translateY(120%);
  transition: transform 160ms ease;
  z-index: 20;
}

.toast.visible {
  transform: translateY(0);
}

@media (max-width: 1200px) {
  .overview {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .overview-latency {
    grid-column: 1 / -1;
  }

  .layout {
    grid-template-columns: 260px 380px 1fr;
  }

  .metric-grid.four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .topbar {
    height: auto;
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .search {
    width: 100%;
  }

  .layout {
    height: auto;
    min-height: calc(100vh - 110px);
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .pane {
    min-height: 360px;
  }

  .scroll,
  .reports-list,
  .detail-body {
    max-height: 70vh;
  }

  .overview {
    grid-template-columns: 1fr;
  }

  .overview-latency {
    grid-column: auto;
  }

  .overview-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .date-controls {
    justify-items: stretch;
  }

  .quick-row {
    justify-content: flex-start;
  }

  .log-filters {
    grid-template-columns: 1fr;
  }

  .event-summary {
    grid-template-columns: 24px 74px minmax(0, 1fr);
  }

  .event-level {
    display: none;
  }

  .event-raw {
    padding-left: 12px;
  }
}
