:root {
  color-scheme: dark;
  --accent: #0163de;
  --text: #e5e5e5;
  --bg: #111217;
  --surface: #1b1e27;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1540px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar,
.topbar-actions,
.logs-toolbar,
.panel-title,
.filters,
.inline-toggle {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.topbar h1,
.panel h2 {
  margin: 0;
  color: var(--text);
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge,
.button,
.select,
.input,
.inline-toggle,
.method-pill,
.status-pill,
.cache-pill {
  border: 0;
  border-radius: var(--radius);
}

.badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  padding: 0 12px;
  color: var(--text);
  background: var(--surface);
  white-space: nowrap;
}

.badge::before,
.health-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--accent);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.card {
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-card {
  min-height: 116px;
  padding: 16px;
  overflow: hidden;
}

.metric-label,
.metric-caption {
  display: block;
  color: var(--text);
  font-size: 13px;
}

.metric-label {
  color: var(--accent);
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin: 12px 0 7px;
  color: var(--text);
  font-size: clamp(24px, 2.5vw, 32px);
  line-height: 1;
  white-space: nowrap;
}

.metric-card.is-updating {
  animation: updatePulse 320ms ease;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(260px, 0.8fr);
  gap: 10px;
  margin-bottom: 10px;
}

.panel {
  padding: 16px;
}

.panel-title {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 18px;
}

.slow-panel {
  grid-column: span 2;
}

canvas {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  background: var(--bg);
}

.top-ips,
.rank-list {
  display: grid;
  gap: 8px;
}

.top-ip-row,
.rank-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--bg);
}

.rank-row-stacked {
  min-height: 44px;
}

.top-ip-address,
.rank-main {
  overflow: hidden;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.top-ip-count,
.rank-value,
.rank-method {
  color: var(--accent);
  font-weight: 700;
}

.logs-panel {
  padding: 0;
  overflow: hidden;
}

.logs-toolbar {
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
}

.field-control {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field-control-sm {
  width: 116px;
}

.field-control-period {
  width: 148px;
}

.field-control-lg {
  width: min(340px, 32vw);
}

.field-control-date {
  width: 132px;
}

.is-hidden {
  display: none;
}

.field-label,
.inline-toggle span {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.select,
.input {
  min-height: 40px;
  color: var(--text);
  background: var(--bg);
  outline: none;
}

.select {
  width: 100%;
  min-width: 0;
  padding: 0 12px;
}

.input {
  width: 100%;
  padding: 0 12px;
}

.select:focus,
.input:focus,
.button:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  color: var(--text);
  background: var(--accent);
  cursor: pointer;
}

.button.is-active {
  color: var(--text);
  background: var(--bg);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
}

.inline-toggle {
  min-height: 40px;
  gap: 8px;
  padding: 0 10px;
  color: var(--text);
  background: var(--bg);
}

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

.logs-viewport {
  max-height: min(58vh, 700px);
  overflow: auto;
  background: var(--bg);
}

.logs-table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.logs-table th,
.logs-table td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

.logs-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--accent);
  background: var(--surface);
  font-weight: 700;
}

.logs-table tbody tr:nth-child(even) {
  background: var(--surface);
}

.logs-table tbody tr:hover {
  background: var(--surface);
}

.log-url {
  max-width: 560px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.method-pill,
.status-pill,
.cache-pill {
  display: inline-flex;
  align-items: center;
  min-width: 54px;
  justify-content: center;
  padding: 4px 8px;
  color: var(--text);
  background: var(--surface);
  font-weight: 700;
}

.status-pill,
.cache-pill.cache-hit,
.cache-pill.cache-miss,
.cache-pill.cache-bypass {
  color: var(--accent);
}

.empty-row td,
.empty-state {
  padding: 18px 10px;
  color: var(--text);
  text-align: center;
}

@keyframes updatePulse {
  0% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-2px);
  }

  100% {
    transform: translateY(0);
  }
}

@media (max-width: 1300px) {
  .metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

  .slow-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 1540px);
    padding: 16px 0;
  }

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

  .topbar-actions,
  .filters {
    width: 100%;
  }

  .filters {
    display: grid;
    grid-template-columns: 1fr;
  }

  .metrics-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 104px;
  }

  .field-control,
  .field-control-sm,
  .field-control-period,
  .field-control-lg,
  .input,
  .select,
  .button,
  .inline-toggle,
  .toolbar-actions {
    width: 100%;
  }

  .toolbar-actions {
    height: auto;
    align-items: stretch;
    flex-direction: column;
  }

  .input {
    max-width: none;
  }
}
