:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #f0f3f5;
  --text: #172026;
  --muted: #66727f;
  --line: #d9e0e6;
  --accent: #6f2dbd;
  --accent-soft: rgba(111, 45, 189, 0.22);
  --danger: #b42318;
  --warning: #a15c07;
  --ok: #067647;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #171923;
    --surface-strong: #202433;
    --text: #f5f7fb;
    --muted: #a9b4c0;
    --line: #2b3240;
    --accent: #c084fc;
    --accent-soft: rgba(192, 132, 252, 0.34);
    --danger: #ff8a80;
    --warning: #f6bd60;
    --ok: #62d9a2;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  transition: background-color 180ms ease, color 180ms ease;
}

button,
select,
textarea {
  font: inherit;
}

button,
select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

button {
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

.environment-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.status.live {
  color: var(--ok);
  border-color: rgba(6, 118, 71, 0.35);
}

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

.guide-panel {
  border: 1px solid var(--accent-soft);
  border-radius: 8px;
  background: var(--surface);
  margin-bottom: 12px;
  overflow: hidden;
}

.guide-panel summary {
  cursor: pointer;
  padding: 13px 14px;
  color: var(--accent);
  font-weight: 800;
  list-style-position: inside;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
}

.guide-grid > div {
  min-width: 0;
  padding: 14px;
  background: var(--surface);
}

.guide-grid h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.guide-grid p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.guide-grid code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  transition: background-color 180ms ease, border-color 180ms ease;
}

.metric {
  padding: 14px;
}

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

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 26px;
}

.metric.danger strong {
  color: var(--danger);
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(360px, 0.8fr);
  gap: 12px;
}

.panel {
  min-width: 0;
}

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

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

td .user-cell {
  min-width: 190px;
  max-width: 280px;
  white-space: normal;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-strong);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
}

.badge.online {
  background: rgba(6, 118, 71, 0.1);
  color: var(--ok);
}

.badge.new,
.badge.alert {
  background: rgba(180, 35, 24, 0.1);
  color: var(--danger);
}

.badge.dispatched {
  background: rgba(161, 92, 7, 0.12);
  color: var(--warning);
}

.alert-list {
  display: grid;
  gap: 10px;
  padding: 12px;
  max-height: 560px;
  overflow: auto;
}

.alert-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
}

.alert-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-weight: 700;
}

.alert-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.alert-user {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 10px;
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.alert-user strong,
.user-cell strong {
  display: block;
  font-size: 13px;
}

.contact-list {
  display: grid;
  gap: 2px;
  margin: 2px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  list-style: none;
}

.alert-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.import-panel textarea {
  display: block;
  width: calc(100% - 24px);
  min-height: 220px;
  margin: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.form-result {
  min-height: 20px;
  margin: 0 12px 12px;
  color: var(--muted);
}

pre {
  min-height: 220px;
  max-height: 360px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text);
  background: var(--surface);
}

a {
  color: var(--accent);
}

@media (max-width: 900px) {
  .shell {
    width: min(100vw - 20px, 720px);
    padding-top: 16px;
  }

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

  .metrics,
  .grid,
  .guide-grid,
  .alert-user {
    grid-template-columns: 1fr;
  }

  th,
  td {
    padding: 10px;
  }
}
