:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-border: #2d3a4d;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --ok: #3dd68c;
  --warn: #f5a524;
  --fail: #f87171;
  --accent: #60a5fa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--panel-border);
  background: #121a24;
}

.topnav {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
  margin-left: 0.25rem;
}

.lang-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
}

.lang-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.lang-btn.active {
  color: var(--accent);
  background: rgba(96, 165, 250, 0.12);
}

.topnav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  border: 1px solid transparent;
}

.topnav-link:hover {
  color: var(--text);
  border-color: var(--panel-border);
}

.topnav-link.active {
  color: var(--accent);
  border-color: rgba(96, 165, 250, 0.35);
  background: rgba(96, 165, 250, 0.08);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.subtitle {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.meta {
  text-align: right;
  color: var(--muted);
  font-size: 0.8rem;
}

.container {
  max-width: min(100%, 1540px);
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}

.card .label {
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card .value {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 0.25rem;
}

.card.ok .value {
  color: var(--ok);
}

.card.fail .value {
  color: var(--fail);
}

.card.warn .value {
  color: var(--warn);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--panel-border);
}

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}

.filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.filters input,
.filters select {
  background: var(--bg);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
}

.alerts {
  padding: 0.75rem 1.1rem 1rem;
}

.alert {
  padding: 0.55rem 0.75rem;
  border-radius: 6px;
  margin-bottom: 0.4rem;
  font-size: 0.875rem;
}

.alert.critical {
  background: rgba(248, 113, 113, 0.12);
  border-left: 3px solid var(--fail);
}

.alert.p0 {
  background: rgba(248, 113, 113, 0.22);
  border-left: 4px solid #ef4444;
  font-weight: 500;
}

.alert.p0 .p0-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #ef4444;
  color: #fff;
  vertical-align: middle;
}

.alerts-p0-head {
  font-size: 0.8rem;
  font-weight: 600;
  color: #fca5a5;
  margin-bottom: 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.alerts-other-head {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin: 0.75rem 0 0.45rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.card.p0 {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.15);
}

.card.p0 .value {
  color: #fca5a5;
}

tr.row-p0 {
  background: rgba(239, 68, 68, 0.08);
}

tr.row-p0 td:first-child {
  box-shadow: inset 3px 0 0 #ef4444;
}

.alert.warning {
  background: rgba(245, 165, 36, 0.12);
  border-left: 3px solid var(--warn);
}

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

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

#hosts-table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

#hosts-table th,
#hosts-table td {
  padding: 0.38rem 0.45rem;
  text-align: left;
  border-bottom: 1px solid var(--panel-border);
  vertical-align: top;
  overflow: hidden;
}

#hosts-table .col-host {
  width: 8%;
  min-width: 5.5rem;
}

#hosts-table .col-region {
  width: 4.5%;
  min-width: 3rem;
}

#hosts-table .col-ec2 {
  width: 7%;
  min-width: 4.5rem;
}

#hosts-table .col-cost {
  width: 5%;
  min-width: 3.5rem;
}

#hosts-table .col-status {
  width: 4%;
  min-width: 3rem;
}

#hosts-table .col-num {
  width: 4%;
  min-width: 2.6rem;
}

#hosts-table .col-db {
  width: 5.5%;
  min-width: 3.5rem;
}

#hosts-table .col-date {
  width: 5.5%;
  min-width: 4.5rem;
}

#hosts-table .col-detail {
  width: 3.5%;
  min-width: 2.5rem;
}

.cell-clip {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.host-short {
  font-size: 0.8rem;
  font-weight: 600;
  word-break: break-all;
}

.host-labels {
  margin-top: 0.12rem;
  line-height: 1.15;
}

.host-labels .badge {
  font-size: 0.58rem;
  padding: 0.06rem 0.28rem;
  margin-right: 0.1rem;
}

#hosts-table .metric {
  padding: 0.06rem 0.3rem;
  font-size: 0.76rem;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hosts-table .badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
}

#hosts-table details summary {
  font-size: 0.78rem;
}

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

th,
td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--panel-border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}

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

th.sortable:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

th.sortable::after {
  content: " ⇅";
  opacity: 0.35;
  font-size: 0.68em;
}

th.sortable.sort-asc::after {
  content: " ↑";
  opacity: 1;
  color: var(--accent);
}

th.sortable.sort-desc::after {
  content: " ↓";
  opacity: 1;
  color: var(--accent);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge.ok {
  background: rgba(61, 214, 140, 0.15);
  color: var(--ok);
}

.badge.fail {
  background: rgba(248, 113, 113, 0.15);
  color: var(--fail);
}

.badge.warn {
  background: rgba(245, 165, 36, 0.15);
  color: var(--warn);
}

.badge.local {
  background: rgba(96, 165, 250, 0.15);
  color: var(--accent);
}

.badge.airflow {
  background: rgba(167, 139, 250, 0.15);
  color: #a78bfa;
}

.badge.label {
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}

details {
  cursor: pointer;
}

details summary {
  color: var(--accent);
  user-select: none;
}

.detail-block {
  margin-top: 0.5rem;
  padding: 0.6rem;
  background: var(--bg);
  border-radius: 6px;
  max-height: 280px;
  overflow: auto;
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--panel-border);
}

.footer code {
  color: var(--accent);
}

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

.metric {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.metric.ok {
  color: var(--ok);
  background: rgba(61, 214, 140, 0.14);
  box-shadow: inset 0 0 0 1px rgba(61, 214, 140, 0.25);
}

.metric.warn {
  color: #fbbf24;
  background: rgba(245, 165, 36, 0.16);
  box-shadow: inset 0 0 0 1px rgba(245, 165, 36, 0.3);
}

.metric.fail {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.18);
  box-shadow: inset 0 0 0 1px rgba(248, 113, 113, 0.35);
}

.metric.neutral {
  color: var(--muted);
  font-weight: 400;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.metric-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  padding: 0.55rem 1.1rem;
  border-bottom: 1px solid var(--panel-border);
  font-size: 0.75rem;
  color: var(--muted);
}

.metric-legend .metric {
  font-size: 0.72rem;
  padding: 0.08rem 0.38rem;
}

.metric-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

@media (max-width: 768px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .meta {
    text-align: left;
  }
}
