:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee5;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --blue: #2563eb;
  --green: #15803d;
  --red: #b42318;
  --amber: #b7791f;
  --shadow: 0 8px 24px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

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

.brand h1,
.page-title h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.brand p,
.page-title p {
  margin: 6px 0 0;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.nav a,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.nav a:hover,
.btn:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

.btn-primary:hover {
  background: var(--accent-strong);
  color: #fff;
}

.btn-success {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}

.btn-danger {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.btn-secondary {
  background: var(--surface-2);
}

.btn-sm {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.control-row,
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

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

.summary-grid.summary-grid-5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.metric {
  min-height: 98px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.metric .value {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}

.metric.ok .value,
.text-ok {
  color: var(--green);
}

.metric.bad .value,
.text-bad {
  color: var(--red);
}

.metric.warn .value,
.text-warn {
  color: var(--amber);
}

.panel {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 17px;
}

.panel-body {
  padding: 18px;
}

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

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

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

th {
  background: var(--surface-2);
  color: #344054;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

td {
  overflow-wrap: anywhere;
}

tbody tr:hover {
  background: #f8fafb;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.empty,
.loading {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: #344054;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: #dcfce7;
  color: var(--green);
}

.badge-danger {
  background: #fee4e2;
  color: var(--red);
}

.badge-warning {
  background: #fef3c7;
  color: var(--amber);
}

.badge-info {
  background: #dbeafe;
  color: var(--blue);
}

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

.status-online {
  background: var(--green);
}

.status-offline {
  background: var(--red);
}

.status-unknown {
  background: var(--amber);
}

.input,
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

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

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.form-group textarea {
  min-height: 160px;
  resize: vertical;
}

.check-label {
  display: flex;
  gap: 8px;
  align-items: center;
}

.check-label input {
  width: auto;
  min-height: auto;
}

.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 12px;
}

.node-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.node-card:hover {
  border-color: var(--accent);
}

.node-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.node-name {
  min-width: 0;
  font-weight: 700;
}

.node-kv {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
}

.node-kv .k {
  color: var(--muted);
  font-size: 12px;
}

.node-kv .v {
  margin-top: 2px;
  font-weight: 600;
}

.bar {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.bar-fill {
  height: 100%;
  min-width: 0;
  border-radius: 999px;
}

.bar-ok {
  background: var(--green);
}

.bar-warn {
  background: var(--amber);
}

.bar-bad {
  background: var(--red);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  padding: 28px;
  overflow-y: auto;
  background: rgba(17, 24, 39, 0.58);
}

.modal-content {
  width: min(900px, 100%);
  margin: 0 auto;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  padding: 18px;
}

.close {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2000;
  display: none;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.show {
  display: block;
}

.toast.error {
  background: var(--red);
}

.preview-box,
.link-box {
  max-height: 340px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}

.chart-panel {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 12px;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

@media (max-width: 860px) {
  .shell {
    padding: 16px;
  }

  .topbar,
  .panel-header,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .nav,
  .actions,
  .control-row {
    justify-content: flex-start;
  }

  .summary-grid,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-grid.summary-grid-5 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .summary-grid,
  .node-grid,
  .node-kv,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    padding: 12px;
  }

  .summary-grid.summary-grid-5 {
    grid-template-columns: 1fr;
  }
}
