:root {
  --bg: #f6f4ee;
  --bg-2: #efe8d8;
  --text: #1e2230;
  --muted: #5c6372;
  --surface: #fffdf8;
  --border: #d7ccb8;
  --accent: #c44f38;
  --accent-soft: #f6d8cf;
  --ok: #2f8f6a;
  --warn: #c98900;
  --bad: #a32833;
}

.loading-block {
  min-height: 140px;
  display: grid;
  place-items: center;
  gap: 0.5rem;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg), var(--bg-2));
  min-height: 100vh;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(rgba(30, 34, 48, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30, 34, 48, 0.04) 1px, transparent 1px);
  background-size: 24px 24px;
}

.topbar {
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(6px);
  background: rgba(246, 244, 238, 0.7);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 1rem;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.9rem;
  box-shadow: 0 6px 22px rgba(30, 34, 48, 0.08);
  animation: fadeIn 280ms ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.btn,
.input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  background: #fff;
  font-family: "IBM Plex Mono", monospace;
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.chip-toggle input {
  accent-color: var(--accent);
}

.input {
  min-width: 220px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin: 0.5rem 0 0.65rem;
}

.chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
}

.seg-control {
  display: inline-flex;
  background: var(--accent);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  font-family: "IBM Plex Mono", monospace;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
  line-height: 1.3;
}

.seg-btn:hover {
  color: #fff;
}

.seg-btn.seg-active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
}

.btn {
  cursor: pointer;
  transition: transform 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.panel-close {
  display: none;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.view-hidden {
  display: none !important;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  text-align: left;
  padding: 0.45rem;
}

.table th {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: var(--muted);
}

.table th.sortable {
  cursor: pointer;
  user-select: none;
}

.table th.sortable:hover {
  color: var(--text);
}

.table th.sortable.active {
  color: var(--accent);
}

.fleet-row {
  cursor: pointer;
}

.fleet-row:hover {
  background: #f8f0e5;
}

.fleet-row.active {
  background: #f6d8cf;
}

.host-name-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.host-warning-icon {
  font-size: 0.9rem;
  line-height: 1;
}

.inline-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.inline-link:hover {
  text-decoration: underline;
}

.table-pager {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.unstable-row {
  background: #fff4d3;
}

.client-row {
  cursor: pointer;
}

.client-row:hover {
  background: #f8f0e5;
}

.active-client-row {
  background: #f6d8cf;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.7rem;
  margin-top: 0.8rem;
}

.kpi {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  background: #fff;
}

.kpi h4 {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
}

.kpi p {
  margin: 0.35rem 0 0;
  font-weight: 700;
  font-size: 1.1rem;
}

.wan-issues {
  margin-top: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem;
  background: #fff;
}

.wan-issues-head {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: baseline;
}

.wan-issues h4 {
  margin: 0;
  font-size: 0.86rem;
  text-transform: uppercase;
  color: var(--muted);
}

.wan-issues-head .muted {
  margin: 0;
  text-align: right;
}

.wan-strip {
  margin-top: 0.55rem;
  display: grid;
  grid-template-columns: repeat(48, minmax(2px, 1fr));
  gap: 2px;
  align-items: end;
}

.wan-bar {
  display: block;
  height: 18px;
  border-radius: 3px;
  background: #e7e2d3;
}

.wan-bar.sev0 {
  background: #e7e2d3;
}

.wan-bar.sev1 {
  background: #f0d6a6;
}

.wan-bar.sev2 {
  background: #e8b26c;
}

.wan-bar.sev3 {
  background: #cf7c34;
}

.wan-bar.sev4 {
  background: #a32833;
}

.client-detail {
  margin-top: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 0.7rem;
}

.client-detail h3,
.client-detail h4 {
  margin: 0;
}

.client-logs {
  margin-top: 0.75rem;
}

.client-logs h4 {
  margin-bottom: 0.35rem;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 0.78rem;
}

.split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
}

.stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  padding: 0.2rem 0.45rem;
  font-size: 0.78rem;
  font-weight: 500;
}

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

.badge.warn {
  background: #fff4d3;
  color: var(--warn);
}

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

.muted {
  color: var(--muted);
  font-size: 0.88rem;
}

@media (min-width: 980px) {
  .split {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .input {
    min-width: 160px;
  }
}

.alert-badge {
  display: inline-block;
  min-width: 1.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  text-align: center;
  cursor: pointer;
  line-height: 1.3;
  transition: transform 120ms ease;
}

.alert-badge:hover {
  transform: scale(1.1);
}

.alert-badge-zero {
  color: var(--muted);
  font-size: 0.85rem;
}

.alert-popup {
  position: absolute;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  box-shadow: 0 6px 22px rgba(30, 34, 48, 0.14);
  font-size: 0.85rem;
  max-width: 380px;
  line-height: 1.5;
  color: var(--text);
}

.alert-line {
  padding: 0.2rem 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.alert-line::before {
  content: "•";
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

.alert-text {
  flex: 1;
}

.alert-time {
  color: var(--muted);
  font-size: 0.75rem;
  font-family: "IBM Plex Mono", monospace;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 980px) {
  .layout {
    padding: 0.75rem;
  }

  .panel-actions {
    width: 100%;
  }

  .panel-actions .input,
  .panel-actions .btn,
  .panel-actions .toggle {
    width: 100%;
    justify-content: center;
  }

  .host-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(96vw, 720px);
    height: 100vh;
    z-index: 30;
    border-radius: 0;
    border-right: 0;
    border-top: 0;
    border-bottom: 0;
    transform: translateX(100%);
    transition: transform 220ms ease;
    overflow-y: auto;
    padding-bottom: 2rem;
    background: var(--surface);
  }

  .host-panel.open {
    transform: translateX(0);
  }

  .client-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: min(94vw, 520px);
    height: 100vh;
    z-index: 40;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 220ms ease;
    overflow-y: auto;
    margin-top: 0;
  }

  .client-panel.open {
    transform: translateX(0);
  }

  .panel-close {
    display: inline-flex;
  }
}
