:root {
  --bg: #1a2332;
  --bg-elevated: #222d40;
  --bg-rail: #151c28;
  --border: #2c3a50;
  --text: #e6eef5;
  --muted: #8b9bb0;
  --accent: #f5a524;
  --accent-dim: rgba(245, 165, 36, 0.18);
  --online: #3ecf8e;
  --danger: #e85d4c;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

button,
a,
input,
select {
  touch-action: manipulation;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.shell {
  display: grid;
  grid-template-columns: 216px 1fr;
  min-height: 100vh;
}

.rail {
  background: var(--bg-rail);
  border-right: 1px solid var(--border);
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  line-height: 1.25;
}

.brand span {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav a {
  color: var(--muted);
  padding: 10px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 500;
}

.nav a:hover {
  background: var(--bg-elevated);
  color: var(--text);
  text-decoration: none;
}

.nav a.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.logout {
  margin-top: auto;
}

.main {
  padding: 28px 32px 40px;
  max-width: 1200px;
  min-width: 0;
}

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

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  font-family: var(--mono);
}

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

.metric {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.metric .value {
  font-size: 28px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.metric .value.accent {
  color: var(--accent);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 12px;
  margin-bottom: 12px;
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 0;
}

.panel h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.online-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.online-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.online-list li span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  background: var(--muted);
}

.dot.on {
  background: var(--online);
}

.dot.off {
  background: #4a5568;
}

.dot.warn {
  background: var(--danger);
}

.dot.idle {
  background: var(--accent);
}

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

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.table-scroll table.data {
  min-width: 640px;
}

table.data th,
table.data td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

table.data th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  white-space: nowrap;
}

table.data tr:last-child td {
  border-bottom: none;
}

.bar {
  height: 6px;
  background: #2a3648;
  border-radius: 3px;
  overflow: hidden;
  min-width: 80px;
}

.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.35s ease;
}

.performance-panel .bar > i {
  background: var(--online);
}

.bar > i.warn {
  background: var(--accent);
}

.bar > i.hot {
  background: var(--danger);
}

.htop-panel {
  margin-bottom: 12px;
}

.performance-panel {
  margin-bottom: 12px;
}

.perf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.perf-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.perf-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.perf-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}

.perf-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.perf-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.perf-card .bar {
  margin-bottom: 14px;
}

.perf-caption {
  margin: 0;
  font-size: 12px;
}

.htop-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.htop-head h2 {
  margin: 0;
}

.htop {
  background: #0f1520;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  overflow: auto;
}

.htop-meters {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  color: var(--text);
}

.htop-k {
  display: inline-block;
  min-width: 4.5em;
  color: var(--accent);
  font-weight: 600;
}

.htop-meter {
  color: var(--online);
  white-space: pre;
}

.htop-n {
  font-variant-numeric: tabular-nums;
}

.htop-awg {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}

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

.htop-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.htop-table th,
.htop-table td {
  text-align: left;
  padding: 3px 8px 3px 0;
  white-space: nowrap;
}

.htop-table th {
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.htop-table td {
  border-bottom: 1px solid rgba(44, 58, 80, 0.45);
}

.htop-table tr.htop-hi td {
  color: var(--accent);
}

.htop-cmd {
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
}

.btn:hover {
  border-color: var(--muted);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a2332;
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn.sm {
  padding: 4px 10px;
  font-size: 12px;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
}

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

input,
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
  font: inherit;
  min-width: 140px;
}

input:focus,
select:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge.on {
  color: var(--online);
  border-color: rgba(62, 207, 142, 0.35);
}

.badge.off {
  color: var(--danger);
  border-color: rgba(232, 93, 76, 0.35);
}

.badge.idle {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.error-banner {
  background: rgba(232, 93, 76, 0.12);
  border: 1px solid rgba(232, 93, 76, 0.35);
  color: #ffb4ab;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}

.ok-banner {
  background: rgba(62, 207, 142, 0.12);
  border: 1px solid rgba(62, 207, 142, 0.35);
  color: #9be7c4;
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}

.account-panel {
  max-width: 420px;
}

.account-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.account-form .field {
  width: 100%;
}

.account-form input {
  width: 100%;
}

.account-form .btn {
  align-self: flex-start;
  margin-top: 4px;
}

.account-hint {
  margin: 14px 0 0;
  font-size: 12px;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(245, 165, 36, 0.08), transparent 50%),
    var(--bg);
}

.login-card {
  width: min(360px, 92vw);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

.login-card .field {
  margin-bottom: 12px;
  width: 100%;
}

.login-card input {
  width: 100%;
}

.login-card .btn {
  width: 100%;
  margin-top: 8px;
}

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

.chart-wrap {
  position: relative;
  height: 220px;
}

@media (max-width: 960px) {
  .shell {
    grid-template-columns: 1fr;
    min-height: 100dvh;
  }

  .rail {
    position: sticky;
    top: 0;
    z-index: 40;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
    padding: max(10px, env(safe-area-inset-top)) 12px 10px
      max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    border-right: none;
    border-bottom: 1px solid var(--border);
    background: var(--bg-rail);
  }

  .brand {
    font-size: 14px;
    line-height: 1.2;
  }

  .nav {
    flex: 1 1 auto;
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    min-width: 0;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a {
    flex: 0 0 auto;
    padding: 10px 12px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
  }

  .logout {
    margin-top: 0;
    margin-left: auto;
  }

  .logout .btn {
    min-height: 40px;
    padding: 8px 12px;
  }

  .main {
    padding: 16px 14px max(28px, env(safe-area-inset-bottom));
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }

  .topbar {
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 20px;
  }

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

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

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

  .metric {
    padding: 12px 14px;
  }

  .metric .value {
    font-size: 22px;
  }

  .chart-wrap {
    height: 180px;
  }

  .form-row .field,
  .form-row .btn {
    flex: 1 1 100%;
  }

  .form-row input,
  .form-row select {
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 560px) {
  .brand {
    flex: 1 1 100%;
    font-size: 14px;
    white-space: nowrap;
  }

  .brand span {
    display: inline;
    margin-top: 0;
    margin-left: 0.35em;
    font-size: inherit;
    font-weight: 600;
    letter-spacing: inherit;
    text-transform: none;
    color: var(--accent);
  }

  .metrics {
    gap: 8px;
  }

  .metric .label {
    font-size: 11px;
  }

  .metric .value {
    font-size: 20px;
  }

  .panel {
    padding: 12px 12px;
  }

  .table-scroll table.data {
    min-width: 720px;
  }

  table.data th,
  table.data td {
    padding: 12px 10px;
    font-size: 13px;
  }

  input,
  select,
  .btn {
    font-size: 16px;
  }

  .btn.sm {
    font-size: 14px;
  }

  .login-wrap {
    padding: max(16px, env(safe-area-inset-top)) 16px
      max(16px, env(safe-area-inset-bottom));
  }

  .login-card {
    width: 100%;
    padding: 22px 18px;
  }
}
