:root {
  --bg: #0b0f15;
  --bg-elev: #121821;
  --bg-elev2: #1a222e;
  --border: #232d3d;
  --text: #f0f3f8;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-2: #10b981;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --unknown: #64748b;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Topbar + nav */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 32px;
  background: rgba(11, 15, 21, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-wrap: wrap;
}
.topbar-start {
  display: flex;
  align-items: center;
  gap: 32px;
  flex-wrap: wrap;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.logo { height: 32px; width: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 15px; letter-spacing: -0.01em; }
.brand-text span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elev2);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.nav-link {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: var(--transition);
}
.nav-link:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.nav-link.is-active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,0.2); }

@media (max-width: 720px) {
  .topbar { padding: 12px 16px; }
  .topbar-start { flex-direction: column; align-items: flex-start; gap: 12px; width: 100%; }
  .main-nav { width: 100%; overflow-x: auto; }
}

/* Pills + buttons */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--unknown); }
.pill-ok .dot { background: var(--ok); }
.pill-bad .dot { background: var(--bad); }
.pill-muted .dot { background: var(--unknown); }

.btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--bg-elev2); }

/* Layout */
.container { max-width: 1560px; margin: 0 auto; padding: 32px; }

/* Dashboard — Metrics only */
.dash-hero {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}
@media (max-width: 1200px) { .dash-hero { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 800px) { .dash-hero { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 500px) { .dash-hero { grid-template-columns: 1fr; } }

.hero-card {
  background: linear-gradient(135deg, var(--bg-elev), var(--bg-elev2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  border: 1px solid var(--border);
}
.hero-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 12px 24px -8px rgba(0,0,0,0.5);
}
.hero-card-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; }
.hero-card-value { font-size: 40px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.hero-card-sub { color: var(--muted); font-size: 13px; min-height: 1.5em; }
.hero-card-cta { margin-top: 12px; font-size: 12px; color: var(--accent); font-weight: 600; }

.dash-alerts {
  margin-bottom: 32px;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid rgba(239, 68, 68, 0.2);
  background: rgba(239, 68, 68, 0.03);
}
.dash-alerts-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.dash-alerts-head strong { font-size: 14px; color: var(--bad); }

.alert-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  list-style: none;
  padding: 0;
  margin: 0;
}
.alert-item .alert-btn {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
}
.alert-item.alert-error .alert-btn { border-left: 4px solid var(--bad); }
.alert-item.alert-warn .alert-btn { border-left: 4px solid var(--warn); }
.alert-item .alert-btn:hover { border-color: var(--accent); background: var(--bg-elev2); }
.alert-title { font-weight: 600; font-size: 13px; }
.alert-detail { font-size: 12px; color: var(--muted); }

.dash-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
}
.metric-panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.metric-panel-wide { grid-column: 1 / -1; }
.metric-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.metric-panel-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.panel-link-btn { background: transparent; border: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; }

.breakdown { display: flex; flex-direction: column; gap: 14px; }
.breakdown-row { display: flex; flex-direction: column; gap: 6px; }
.breakdown-meta { display: flex; align-items: center; justify-content: space-between; font-size: 12px; }
.breakdown-count strong { font-size: 14px; }
.breakdown-bar { height: 6px; background: var(--bg-elev2); border-radius: 999px; overflow: hidden; }
.breakdown-fill { height: 100%; border-radius: 999px; background: var(--accent); transition: width 1s ease-out; }

.coverage-grid, .ops-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
@media (max-width: 800px) { .coverage-grid, .ops-tiles { grid-template-columns: repeat(2, 1fr); } }

.coverage-tile, .ops-tile {
  padding: 20px;
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}
.coverage-value, .ops-value { display: block; font-size: 32px; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.coverage-label, .ops-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Pages: Common */
.page-toolbar { margin-bottom: 24px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.input {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  transition: var(--transition);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }

/* Table styling */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
}
.grid { width: 100%; border-collapse: collapse; font-size: 13px; text-align: left; }
.grid th {
  padding: 16px 20px;
  background: var(--bg-elev2);
  color: var(--muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}
.grid th:hover { color: var(--text); background: var(--border); }
.grid td { padding: 16px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.grid tr:last-child td { border-bottom: none; }
.grid tr:hover td { background: rgba(255,255,255,0.015); }

.grid .mono { font-size: 12px; }

/* Machine Cards */
.machine-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}
.machine-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.machine-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.machine-card-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  background: rgba(255,255,255,0.01);
}
.machine-card-id-area { display: flex; flex-direction: column; gap: 2px; }
.machine-card-id { font-size: 16px; font-weight: 700; color: var(--accent); margin: 0; }
.machine-card-name { font-size: 12px; }
.machine-card-actions { display: flex; align-items: center; gap: 8px; }

.machine-card-body { padding: 20px 24px; flex: 1; }
.machine-specs { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.spec-item { display: flex; justify-content: space-between; font-size: 12px; }
.spec-label { color: var(--muted); }
.spec-value { font-weight: 500; }

.machine-tags-area { display: flex; flex-direction: column; gap: 16px; }
.tag-group { display: flex; flex-direction: column; gap: 6px; }
.tag-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.tags-list { display: flex; flex-wrap: wrap; gap: 6px; }

.machine-card-footer {
  padding: 16px 24px;
  background: var(--bg-elev2);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.machine-health { font-size: 11px; }

.btn-icon {
  background: var(--bg-elev2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.btn-icon:hover { background: var(--border); border-color: var(--muted); }

/* Project Overview Stats */
.proj-overview, .host-overview {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.proj-stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 140px;
}
.proj-stat strong { font-size: 24px; font-weight: 800; color: var(--text); line-height: 1; }
.proj-stat span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.proj-stat.warn { border-color: rgba(245, 158, 11, 0.3); }
.proj-stat.warn strong { color: var(--warn); }

/* Project Cards */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
  gap: 24px;
}
.project-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: var(--transition);
}
.project-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.project-card-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.01);
}
.project-info { display: flex; flex-direction: column; gap: 4px; }
.project-title-row { display: flex; align-items: center; gap: 12px; }
.project-name { font-size: 16px; font-weight: 700; margin: 0; }
.project-meta { display: flex; align-items: center; gap: 8px; }
.bullet { width: 3px; height: 3px; border-radius: 50%; background: var(--border); }

.project-card-grid {
  padding: 20px 24px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  flex: 1;
}
.deploy-unit { display: flex; flex-direction: column; gap: 6px; }
.unit-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.unit-content { font-size: 13px; font-weight: 500; }

.project-card-footer {
  padding: 16px 24px;
  background: var(--bg-elev2);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.footer-left { display: flex; align-items: center; gap: 10px; }
.footer-right { max-width: 200px; text-align: right; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.tag-outline { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.deploy-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; background: var(--bg-elev); border: 1px solid var(--border); }
.d-machine { color: var(--accent); border-color: var(--accent); }
.d-domain { color: var(--accent-2); border-color: var(--accent-2); }
.d-repo { color: var(--warn); border-color: var(--warn); }

.project-group { margin-bottom: 40px; }
.group-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; border-left: 4px solid var(--accent); padding-left: 16px; }
.group-head h3 { margin: 0; font-size: 18px; }
.count-badge { background: var(--bg-elev2); color: var(--muted); padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }

/* Badges & Tags */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--bg-elev2); border: 1px solid var(--border);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--unknown); }
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  background: var(--bg-elev2); border: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
}

/* Config / Settings */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 24px;
}
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
}
.panel-wide { grid-column: 1 / -1; }
.panel-head {
  padding: 16px 24px;
  background: var(--bg-elev2);
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.panel-body { padding: 24px; }

.settings-dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 16px;
  margin: 0;
  padding: 24px;
}
.settings-dl dt { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.settings-dl dd { margin: 0; font-weight: 500; }

.pip { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; }
.pip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--unknown); }
.pip.ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pip.fail .dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.pip.stale .dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
}
.modal-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; width: 480px; max-width: 90vw;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }

/* Footer */
.footer {
  margin-top: 64px; padding: 32px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; color: var(--muted); font-size: 12px;
}

/* Utils */
[hidden] { display: none !important; }
.link { color: var(--accent); text-decoration: none; transition: var(--transition); }
.link:hover { text-decoration: underline; color: #60a5fa; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }

/* Health styles */
.health-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); margin-right: 8px; }
.health-dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.health-dot.fail { background: var(--bad); box-shadow: 0 0 8px var(--bad); }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.page:not([hidden]) { animation: fadeIn 0.3s ease-out; }
