:root {
  color-scheme: light;
  --bg: #f5f7f9;
  --panel: #ffffff;
  --ink: #18212b;
  --muted: #667382;
  --line: #d8dee6;
  --accent: #18706d;
  --accent-dark: #0e5552;
  --bad: #b42318;
  --warn: #a15c07;
  --ok: #137333;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
  background: #18212b;
}

.login-panel {
  display: grid;
  width: min(420px, 100%);
  gap: 14px;
  padding: 22px;
  border: 1px solid #334155;
  border-radius: 8px;
  background: white;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}

.login-panel h1 {
  margin-bottom: 4px;
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: #18212b;
  color: white;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.topbar p {
  margin-top: 4px;
  color: #b8c2cf;
  font-size: 13px;
}

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px;
}

.token-box,
.actions,
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.stats div,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats div {
  padding: 14px 16px;
}

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

.stats strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

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

.panel {
  padding: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.wide {
  grid-column: 1 / -1;
}

input,
select,
textarea,
button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  background: white;
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 84px;
}

button {
  padding: 8px 12px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: #aab4c0;
  background: #f9fafb;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 700;
}

button.primary:hover {
  background: var(--accent-dark);
}

button.danger {
  color: var(--bad);
}

.table-panel {
  margin-top: 16px;
}

.section-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
}

td code {
  display: inline-block;
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  min-width: 74px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  text-align: center;
  background: #eef2f7;
  color: var(--muted);
}

.badge.online {
  background: #e6f4ea;
  color: var(--ok);
}

.badge.failed {
  background: #fce8e6;
  color: var(--bad);
}

.badge.starting,
.badge.rotating {
  background: #fff4e5;
  color: var(--warn);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.events {
  min-height: 120px;
  max-height: 260px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101820;
  color: #d7e3f0;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #18212b;
  color: white;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (max-width: 900px) {
  .topbar,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .stats,
  .layout,
  .form-grid {
    grid-template-columns: 1fr;
  }
}
