:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --line: #d7dee7;
  --text: #152032;
  --muted: #627085;
  --blue: #1d5fd1;
  --green: #167a4a;
  --red: #b42318;
  --amber: #946200;
}

* {
  box-sizing: border-box;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
}

.topbar-spacer {
  width: 1px;
  height: 1px;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.auth-box {
  width: min(420px, 100%);
  margin: 14vh auto 0;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.auth-box h1,
.section-head h1 {
  margin: 0;
  font-size: 22px;
}

.stack,
.create-grid {
  display: grid;
  gap: 14px;
}

label span,
.label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: #fff;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.danger {
  border-color: #f0b8b2;
  color: var(--red);
}

.icon-button {
  width: 36px;
  padding: 0;
}

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

.summary > div,
.panel,
.user-card,
.empty {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary > div {
  min-width: 0;
  padding: 14px;
}

.summary strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.panel {
  padding: 18px;
}

.live-peers {
  margin-bottom: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.create-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: end;
}

.create-grid .wide {
  grid-column: span 2;
}

.live-state {
  border-radius: 999px;
  padding: 4px 10px;
  background: #e4f5ec;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.live-state.error {
  background: #fff0ee;
  color: var(--red);
}

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

.live-metrics > div {
  min-width: 0;
  border-left: 3px solid #dce4ee;
  padding: 4px 12px;
}

.live-metrics strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 18px;
}

.history-strip {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 38px;
  margin: 0 0 14px;
  border-bottom: 1px solid #dce4ee;
}

.history-bar {
  width: 8px;
  min-height: 3px;
  border-radius: 2px 2px 0 0;
  background: var(--blue);
  opacity: 0.8;
}

.history-empty {
  align-self: center;
  color: var(--muted);
  font-size: 13px;
}

.live-table-wrap {
  overflow-x: auto;
  border: 1px solid #dce4ee;
  border-radius: 6px;
}

.live-table {
  width: 100%;
  min-width: 460px;
  border-collapse: collapse;
  font-size: 13px;
}

.live-table th,
.live-table td {
  border-bottom: 1px solid #e8eef5;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

.live-table th {
  background: #f7f9fc;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.live-table tr:last-child td {
  border-bottom: 0;
}

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

.user-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.user-card {
  padding: 16px;
}

.user-main,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.user-main h2 {
  margin: 0;
  font-size: 18px;
}

.user-main p {
  margin: 3px 0 0;
  color: var(--muted);
}

.status {
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 800;
}

.status.on {
  background: #e4f5ec;
  color: var(--green);
}

.status.off {
  background: #fff3d6;
  color: var(--amber);
}

.credentials {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 14px;
}

.actions form {
  margin: 0;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.message {
  border-radius: 6px;
  padding: 10px 12px;
  background: #eef4ff;
  color: #174a9c;
}

.message.error {
  background: #fff0ee;
  color: var(--red);
}

.message.success {
  background: #eaf7ef;
  color: var(--green);
}

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

@media (max-width: 860px) {
  .summary,
  .credentials,
  .create-grid,
  .live-metrics {
    grid-template-columns: 1fr;
  }

  .create-grid .wide {
    grid-column: auto;
  }

  .topbar {
    padding: 0 16px;
  }
}
