:root {
  color-scheme: dark;
  --bg: #0a0c0f;
  --sidebar: #0e1115;
  --surface: #12161b;
  --surface-raised: #171c22;
  --surface-hover: #1c2229;
  --line: #29313a;
  --line-strong: #3a4550;
  --text: #f1f4f6;
  --muted: #a4adb7;
  --quiet: #78838e;
  --accent: #4c8dff;
  --accent-hover: #6ca1ff;
  --good: #40c983;
  --good-bg: #11271d;
  --warn: #e9b44c;
  --warn-bg: #2b2110;
  --bad: #f06d75;
  --bad-bg: #2d1518;
  --radius: 12px;
  --radius-sm: 8px;
  --z-sticky: 20;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

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

button, input { font: inherit; }
button { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

.shell {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 24px 16px 18px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  z-index: var(--z-sticky);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 26px;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: #07111f;
  font-size: 17px;
  font-weight: 900;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand div > span { margin-top: 1px; color: var(--muted); font-size: 12px; }

.nav { display: grid; gap: 4px; }

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  font-weight: 600;
  transition: color 180ms ease, background 180ms ease;
}

.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface-raised); color: var(--text); }
.nav-item:focus-visible, .button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding: 14px 8px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.live-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--good);
}

.main { min-width: 0; padding: 26px 32px 48px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto 28px;
}

h1 { font-size: 24px; line-height: 1.2; letter-spacing: -0.025em; }
h2 { font-size: 17px; line-height: 1.25; letter-spacing: -0.015em; }
h3 { font-size: 14px; line-height: 1.3; }

.topbar p { margin-top: 4px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 14px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  font-weight: 650;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

.button:hover { background: var(--surface-hover); border-color: #54616e; }
.button:active { background: #222932; }
.button:disabled { cursor: wait; opacity: .58; }
.button.primary { border-color: var(--accent); background: var(--accent); color: #07111f; }
.button.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.button.danger { border-color: #7b3940; background: var(--bad-bg); color: #ffb4b9; }
.button.danger:hover { border-color: var(--bad); background: #3a1a1e; }

.content, .panel-view { min-width: 0; }
.content { max-width: 1400px; margin: 0 auto; }
.panel-view { display: none; }
.panel-view.active { display: block; }

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: 760px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.auth-panel p { max-width: 55ch; margin-top: 5px; color: var(--muted); }
.auth-row { display: flex; gap: 8px; }

input {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #0d1014;
  color: var(--text);
}

input::placeholder { color: #8c96a0; }

.state-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 96px;
  padding: 22px 24px;
  border-radius: var(--radius);
  background: var(--surface);
}

.state-banner.good { background: var(--good-bg); }
.state-banner.warning { background: var(--warn-bg); }
.state-banner.critical { background: var(--bad-bg); }
.state-copy { display: flex; align-items: center; gap: 16px; }
.state-indicator { width: 13px; height: 13px; flex: 0 0 auto; border-radius: 50%; background: currentColor; }
.state-banner.good .state-indicator { color: var(--good); }
.state-banner.warning .state-indicator { color: var(--warn); }
.state-banner.critical .state-indicator { color: var(--bad); }
.state-copy strong { display: block; font-size: 19px; letter-spacing: -.015em; }
.state-copy span { display: block; margin-top: 3px; color: var(--muted); }
.state-counts { display: flex; gap: 22px; color: var(--muted); white-space: nowrap; }
.state-counts b { color: var(--text); font-size: 16px; }

.overview-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, .8fr);
  gap: 32px;
  margin-top: 32px;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.section-head p { margin-top: 3px; color: var(--muted); }
.page-head { align-items: center; margin-bottom: 20px; }

.host-list, .issue-list, .nodes-list, .incident-list { border-top: 1px solid var(--line); }

.host-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) minmax(160px, 1fr) auto;
  align-items: center;
  gap: 18px;
  min-height: 66px;
  border-bottom: 1px solid var(--line);
}
.host-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.host-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host-meta { color: var(--muted); font-size: 12px; }
.host-metrics { color: var(--muted); font-variant-numeric: tabular-nums; }

.status-dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--quiet); }
.status-dot.up { background: var(--good); }
.status-dot.warning { background: var(--warn); }
.status-dot.down { background: var(--bad); }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.badge.up { background: var(--good-bg); color: #75dda8; }
.badge.warning { background: var(--warn-bg); color: #f4cc79; }
.badge.down { background: var(--bad-bg); color: #ff9aa1; }

.issue-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.issue-row strong, .issue-row span { display: block; }
.issue-row span { margin-top: 2px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.empty-state { padding: 22px 0; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); margin-bottom: 4px; }

.recent-section { margin-top: 34px; }
.incident-row {
  display: grid;
  grid-template-columns: 130px minmax(180px, 1fr) minmax(180px, 2fr);
  gap: 18px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}
.incident-row strong { color: var(--text); }

.search { width: min(320px, 100%); }

.node-group { border-bottom: 1px solid var(--line); }
.node-group summary {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(200px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  cursor: pointer;
  list-style: none;
}
.node-group summary::-webkit-details-marker { display: none; }
.node-group summary::after { content: "＋"; color: var(--muted); font-size: 17px; }
.node-group[open] summary::after { content: "−"; }
.node-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.node-title div { min-width: 0; }
.node-title strong, .node-title span { display: block; }
.node-title span { margin-top: 2px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-address { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.node-body { padding: 2px 0 20px 18px; }
.metrics-line { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.checks-list { border-top: 1px solid var(--line); }
.check-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr) auto;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.check-detail { color: var(--muted); overflow-wrap: anywhere; }

.btc-layout { display: grid; gap: 28px; }
.btc-section { min-width: 0; }
.btc-section > h3 { margin-bottom: 9px; }

.openclaw-summary { min-height: 120px; }
.model-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.model-line strong { font-size: 17px; overflow-wrap: anywhere; }
.quota-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-top: 22px; }
.quota { padding: 14px 0; border-bottom: 1px solid var(--line); }
.quota-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
.quota-track { height: 7px; overflow: hidden; border-radius: 99px; background: var(--surface-raised); }
.quota-track span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.quota small { display: block; margin-top: 7px; color: var(--muted); }

.action-section { margin-top: 30px; }
.action-section > h3 { margin-bottom: 12px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; }
.danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding-top: 22px;
  border-top: 1px solid #4b272b;
}
.danger-zone p { margin-top: 4px; color: var(--muted); }
.action-output {
  max-height: 320px;
  margin: 18px 0 0;
  padding: 14px;
  overflow: auto;
  border-radius: var(--radius-sm);
  background: #07090b;
  color: #d7dde2;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap;
}

.loading-row { padding: 24px 0; color: var(--muted); }
.skeleton-block, .skeleton-lines { position: relative; overflow: hidden; }
.skeleton-lines:empty { min-height: 154px; }
.skeleton-lines:empty::before,
.skeleton-block:empty::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-raised) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.3s linear infinite;
}

@keyframes skeleton { to { background-position: -200% 0; } }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar {
    position: sticky;
    height: auto;
    padding: 12px 16px 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 0 10px; }
  .brand-mark { width: 31px; height: 31px; }
  .nav { display: flex; gap: 2px; overflow-x: auto; }
  .nav-item { width: auto; min-width: max-content; padding: 0 12px; }
  .sidebar-foot { display: none; }
  .main { padding: 20px 18px 40px; }
  .overview-layout { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { align-items: flex-start; margin-bottom: 20px; }
  .top-actions { gap: 8px; }
  #lastUpdated { display: none; }
  .state-banner { align-items: flex-start; flex-direction: column; min-height: 126px; padding: 18px; }
  .state-counts { width: 100%; justify-content: space-between; }
  .host-row { grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
  .host-metrics { display: none; }
  .incident-row { grid-template-columns: 92px minmax(0, 1fr); }
  .incident-row span:last-child { grid-column: 2; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .search { width: 100%; }
  .node-group summary { grid-template-columns: minmax(0, 1fr) auto auto; gap: 9px; }
  .node-address { display: none; }
  .node-body { padding-left: 0; }
  .check-row { grid-template-columns: minmax(0, 1fr) auto; }
  .check-detail { grid-column: 1 / -1; font-size: 12px; }
  .danger-zone, .auth-panel { align-items: stretch; flex-direction: column; }
  .auth-row { flex-direction: column; }
  .action-row .button { flex: 1 1 130px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
