:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --accent: #5b9dff;
  --accent-dim: #2f4a73;
  --green: #4ec988;
  --amber: #e8b84b;
  --red: #ef6c6c;
  --zebra: #14171d;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must always win, even over component rules that set an
   explicit display (e.g. .state-overlay { display:flex }). Without this the JS
   toggling el.hidden has no visual effect and the table overlays stay painted
   on top of the data. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
}

h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; letter-spacing: 0.01em; }

button { font-family: inherit; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--accent), #7c5bff);
  color: #fff;
  font-weight: 700;
  border-radius: 9px;
  letter-spacing: 0.02em;
}
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.health { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.bad { background: var(--red); box-shadow: 0 0 8px var(--red); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 63px);
}
.rail { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.panel-context { color: var(--muted); font-size: 12px; margin: 0 0 10px; word-break: break-all; }

.list { display: flex; flex-direction: column; gap: 6px; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.list-item:hover { border-color: var(--accent-dim); }
.list-item.active { border-color: var(--accent); background: #1b2433; }
.list-item .name { font-weight: 600; }
.list-item .meta { color: var(--muted); font-size: 12px; }
.list-empty { color: var(--muted); font-size: 13px; padding: 8px 2px; }

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.running { background: rgba(232,184,75,.15); color: var(--amber); }
.badge.ready { background: rgba(78,201,136,.15); color: var(--green); }
.badge.error { background: rgba(239,108,108,.15); color: var(--red); }

/* ---------- Buttons + inputs ---------- */
.btn {
  background: var(--accent);
  color: #06101f;
  border: none;
  border-radius: 6px;
  padding: 7px 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 4px 9px; font-size: 12px; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.small:hover { border-color: var(--accent-dim); filter: none; }

input, textarea, select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font-family: inherit;
  font-size: 13px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { width: 100%; font-family: var(--mono); font-size: 12px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label input { width: 100%; }

.row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.row.gap { gap: 12px; }
.inline-status { font-size: 12px; color: var(--muted); }
.inline-status.ok { color: var(--green); }
.inline-status.bad { color: var(--red); }

.deploy { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.deploy summary { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 600; }
.deploy .hint { color: var(--muted); font-size: 12px; margin: 8px 0; }

/* ---------- Content head + tabs ---------- */
.content-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.type-tabs { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 60%; }
.type-tab {
  padding: 5px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}
.type-tab:hover { border-color: var(--accent-dim); }
.type-tab.active { border-color: var(--accent); background: #1b2433; color: var(--accent); }
.type-tab .count { color: var(--muted); margin-left: 5px; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.toolbar #filter { width: 320px; max-width: 50%; }
.toolbar-right { display: flex; align-items: center; gap: 16px; }
.rowcount { color: var(--muted); font-size: 13px; }
.pagesize { flex-direction: row; align-items: center; gap: 6px; }
.pagesize select { padding: 4px 6px; }

/* ---------- Table ---------- */
.table-wrap { position: relative; flex: 1; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--panel-2);
  text-align: left;
  padding: 9px 12px;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th .arrow { color: var(--accent); margin-left: 4px; }
tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
}
tbody tr:nth-child(even) { background: var(--zebra); }
tbody tr:hover { background: #1b2433; cursor: pointer; }
td.col-state .state-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-dim);
  color: #cfe0ff;
  font-size: 12px;
}
td.num { font-variant-numeric: tabular-nums; }

/* ---------- State overlays ---------- */
.state-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(15,17,21,.85);
  color: var(--muted);
  font-size: 14px;
  z-index: 8;
  padding: 24px;
  text-align: center;
}
.state-overlay.error { color: var(--red); white-space: pre-wrap; }
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pager ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
}
.pager #pageInfo { color: var(--muted); font-size: 13px; }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: 460px;
  max-width: 92vw;
  height: 100vh;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 30px rgba(0,0,0,.4);
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-body { padding: 8px 16px 24px; overflow-y: auto; }
.detail-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.detail-row .k { color: var(--muted); font-size: 12px; word-break: break-word; }
.detail-row .v { font-family: var(--mono); font-size: 12.5px; word-break: break-word; }
