:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --info: #0891b2;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  height: 48px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand { font-weight: 600; color: var(--text); }
.topbar .user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }

.layout {
  display: flex;
  min-height: calc(100vh - 48px);
}

.sidebar {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  flex-shrink: 0;
}
.sidebar a {
  display: block;
  padding: 8px 16px;
  color: var(--text);
  border-left: 3px solid transparent;
}
.sidebar a:hover, .sidebar a.active {
  background: #f9fafb;
  border-left-color: var(--primary);
  text-decoration: none;
}

.main {
  flex: 1;
  padding: 20px;
  min-width: 0;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 16px 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card-title { font-weight: 600; margin: 0; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.compact-grid { margin-bottom: 12px; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.summary-card .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.summary-card .value { font-size: 22px; font-weight: 700; }
.summary-card .value.online { color: var(--success); }
.summary-card .value.offline { color: var(--danger); }
.summary-card .value.warning { color: var(--warning); }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
tr:hover td { background: #fafafa; }
.subrow td { background: #fcfcfd; }
.subtable th, .subtable td { font-size: 12px; }
.command-events summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.command-events[open] summary { margin-bottom: 12px; }
.placeholder.compact {
  padding: 8px 0;
  border: none;
  background: transparent;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
}
.badge.online { background: #dcfce7; color: #166534; }
.badge.offline { background: #fee2e2; color: #991b1b; }
.badge.warning { background: #fef3c7; color: #92400e; }
.badge.unknown { background: #f3f4f6; color: var(--muted); }
.badge.queued { background: #e0f2fe; color: #075985; }
.badge.claimed { background: #fef9c3; color: #854d0e; }
.badge.completed { background: #dcfce7; color: #166534; }
.badge.failed { background: #fee2e2; color: #991b1b; }
.badge.expired { background: #f3f4f6; color: var(--muted); }
.badge.draft { background: #f3f4f6; color: var(--muted); }
.badge.published { background: #dcfce7; color: #166534; }
.badge.pending { background: #fef9c3; color: #854d0e; }
.badge.downloaded { background: #e0f2fe; color: #075985; }
.badge.applied { background: #dcfce7; color: #166534; }
.badge.created { background: #e0f2fe; color: #075985; }
.badge.claimed { background: #fef9c3; color: #854d0e; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 3px 8px; font-size: 12px; }

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 12px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}
.form-group label { font-size: 12px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
input, select, textarea {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.empty { color: var(--muted); padding: 24px; text-align: center; }
.placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: #fafafa;
}
.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.map-stage {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.map-svg {
  width: 100%;
  min-height: 360px;
  display: block;
}
.map-bg {
  fill: #eff6ff;
  stroke: #bfdbfe;
  stroke-width: 1;
}
.map-point {
  stroke: #ffffff;
  stroke-width: 0.6;
  cursor: pointer;
}
.map-point.online { fill: #16a34a; }
.map-point.offline { fill: #dc2626; }
.map-point.warning { fill: #d97706; }
.map-point.unknown { fill: #64748b; }
.map-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.map-kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}
.map-kpi > div {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.map-card-inline {
  display: grid;
  gap: 12px;
}
.trend-summary {
  margin-bottom: 12px;
}
.trend-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
  gap: 12px;
  align-items: end;
  min-height: 220px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f9fafb;
}
.trend-bar-wrap {
  display: grid;
  gap: 8px;
  justify-items: center;
  min-width: 0;
}
.trend-value {
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
  text-align: center;
}
.trend-bar-track {
  width: 100%;
  max-width: 56px;
  height: 120px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #eff6ff, #dbeafe);
  border: 1px solid #bfdbfe;
}
.trend-bar-fill {
  width: 100%;
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(180deg, #60a5fa, #2563eb);
  min-height: 4px;
}
.trend-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 520px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-body { padding: 16px; }
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); }

.toast {
  position: fixed;
  top: 60px;
  right: 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  display: none;
  z-index: 200;
  max-width: 360px;
}
.toast.show { display: block; }
.toast.error { border-left: 4px solid var(--danger); }
.toast.success { border-left: 4px solid var(--success); }

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-card h1 { font-size: 18px; margin: 0 0 20px 0; text-align: center; }

.dl-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 12px;
  font-size: 13px;
}
.dl-grid dt { color: var(--muted); }
.dl-grid dd { margin: 0; }

.section-title {
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 8px 0;
  color: var(--muted);
}

pre.json {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  font-size: 12px;
  overflow-x: auto;
  max-height: 160px;
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .map-layout { grid-template-columns: 1fr; }
  .trend-chart { grid-template-columns: repeat(3, 1fr); }
}
