:root {
  --bg: #0b1220;
  --bg-elev: #111a2b;
  --surface: #162033;
  --surface2: #1c2940;
  --border: #2a3a55;
  --border-soft: #223049;
  --text: #e8eef8;
  --text2: #8fa0bc;
  --accent: #2dd4bf;
  --accent-dim: #14b8a6;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --ok: #34d399;
  --err: #fb7185;
  --warn: #fbbf24;
  --info: #60a5fa;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; }
html, body { min-height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(45, 212, 191, 0.12), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(96, 165, 250, 0.08), transparent 50%),
    var(--bg);
}

button, input, textarea, select { font: inherit; color: inherit; }
button {
  cursor: pointer;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  transition: transform .15s ease, background .15s ease, border-color .15s ease, color .15s ease;
}
button:disabled { opacity: .45; cursor: default; transform: none; }

.btn-primary {
  background: linear-gradient(180deg, #3de0c8, var(--accent-dim));
  color: #042f2e;
  box-shadow: 0 8px 24px rgba(20, 184, 166, 0.25);
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost {
  background: transparent;
  color: var(--text2);
  padding: 8px 10px;
}
.btn-ghost:hover { color: var(--text); }
.btn-danger {
  background: rgba(251, 113, 133, 0.12);
  color: var(--err);
  border: 1px solid rgba(251, 113, 133, 0.35);
}
.btn-danger:hover { background: rgba(251, 113, 133, 0.22); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input, textarea, select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text2);
  letter-spacing: .04em;
  text-transform: uppercase;
}
label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
}
h1 { font-size: 28px; font-weight: 700; letter-spacing: -.03em; }
h2 { font-size: 17px; font-weight: 650; letter-spacing: -.02em; }
p { line-height: 1.55; }
.muted { color: var(--text2); font-size: 13px; }
code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 1px 6px;
  color: var(--accent);
}

.brand-mark {
  width: 52px; height: 52px;
  border-radius: 16px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 22px;
  color: #042f2e;
  background: linear-gradient(160deg, #5eead4, #2dd4bf 55%, #0ea5e9);
  box-shadow: 0 10px 30px rgba(45, 212, 191, 0.28);
}
.brand-mark.sm { width: 36px; height: 36px; font-size: 16px; border-radius: 11px; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
/* Class display rules must not override the HTML hidden attribute. */
[hidden] { display: none !important; }
.login-card {
  width: min(420px, 100%);
  background: rgba(22, 32, 51, 0.88);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  display: grid;
  gap: 14px;
}
.login-card h1 { margin-top: 4px; }
.login-card .subtitle { color: var(--text2); margin-bottom: 8px; }
.login-card form { display: grid; gap: 14px; }
.login-card .btn-primary { width: 100%; margin-top: 4px; }

#shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

#sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px 14px;
  background: rgba(11, 18, 32, 0.92);
  border-right: 1px solid var(--border-soft);
  backdrop-filter: blur(10px);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 10px;
}
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand .muted { display: block; font-size: 12px; }

#nav { display: grid; gap: 4px; flex: 1; }
#nav button {
  text-align: left;
  background: transparent;
  color: var(--text2);
  padding: 11px 14px;
  border-radius: 12px;
  font-weight: 550;
}
#nav button:hover { background: var(--surface); color: var(--text); }
#nav button.active {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(45, 212, 191, 0.25);
}

.sidebar-footer {
  display: grid;
  gap: 8px;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border-soft);
}
#worker-status {
  font-size: 12px;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
}
.worker-on { color: var(--ok); background: rgba(52, 211, 153, 0.1); }
.worker-off { color: var(--err); background: rgba(251, 113, 133, 0.1); }

main {
  padding: 22px 28px 40px;
  min-width: 0;
}
main > header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}
.header-actions { display: flex; align-items: center; gap: 10px; }

.notice {
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.25);
  color: #c7dbff;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  background: linear-gradient(180deg, rgba(28, 41, 64, 0.95), rgba(22, 32, 51, 0.95));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 96px;
}
.metric .label { color: var(--text2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.metric .value { font-size: 28px; font-weight: 700; margin-top: 8px; letter-spacing: -.03em; }
.metric .hint { color: var(--text2); font-size: 12px; margin-top: 4px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.panel {
  background: rgba(22, 32, 51, 0.86);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.panel + .panel { margin-top: 14px; }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.section-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}
.section-bar p { color: var(--text2); max-width: 720px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.card {
  background: rgba(22, 32, 51, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  gap: 10px;
}
.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.card h3 { font-size: 16px; }
.card .meta { color: var(--text2); font-size: 13px; word-break: break-all; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 650;
  border: 1px solid transparent;
}
.badge.ok, .badge.accepted, .badge.healthy, .badge.active { color: var(--ok); background: rgba(52,211,153,.12); border-color: rgba(52,211,153,.28); }
.badge.err, .badge.failed, .badge.unhealthy, .badge.cancelled { color: var(--err); background: rgba(251,113,133,.12); border-color: rgba(251,113,133,.28); }
.badge.warn, .badge.uncertain, .badge.degraded, .badge.paused { color: var(--warn); background: rgba(251,191,36,.12); border-color: rgba(251,191,36,.28); }
.badge.info, .badge.queued, .badge.sending, .badge.idle { color: var(--info); background: rgba(96,165,250,.12); border-color: rgba(96,165,250,.28); }
.badge.off { color: var(--text2); background: rgba(143,160,188,.1); border-color: var(--border); }

.legend {
  display: flex;
  gap: 14px;
  color: var(--text2);
  font-size: 12px;
  margin-bottom: 10px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.dot.ok { background: var(--ok); }
.dot.err { background: var(--err); }
.dot.warn { background: var(--warn); }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 180px;
  padding: 8px 0 4px;
}
.chart-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 1px;
  height: 100%;
}
.chart-seg { width: 100%; border-radius: 3px 3px 0 0; min-height: 0; }
.chart-seg.accepted { background: var(--ok); }
.chart-seg.failed { background: var(--err); }
.chart-seg.uncertain { background: var(--warn); }
.chart-labels {
  display: flex;
  justify-content: space-between;
  color: var(--text2);
  font-size: 12px;
  margin-top: 6px;
}

.health-row, .activity-row, .snap-row {
  display: grid;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
}
.health-row:last-child, .activity-row:last-child, .snap-row:last-child { border-bottom: 0; }
.health-top, .activity-top, .snap-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.bar {
  height: 6px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: inherit;
}

.table-wrap { overflow: auto; padding: 0; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
th {
  color: var(--text2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 650;
}
td .meta { color: var(--text2); font-size: 12px; }
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.search-bar input { max-width: 360px; }
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 12px;
}
.form-grid .wide { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.check-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
}
.check-list label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}
.preview-box {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  max-height: 280px;
  overflow: auto;
}
.empty {
  color: var(--text2);
  padding: 24px 8px;
  text-align: center;
}

dialog#editor {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  box-shadow: var(--shadow);
}
dialog#editor::backdrop {
  background: rgba(4, 10, 20, 0.72);
  backdrop-filter: blur(4px);
}
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
#editor-content { padding: 18px; }

#toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  max-width: min(420px, calc(100vw - 32px));
}
#toast.ok { border-color: rgba(52, 211, 153, 0.45); }
#toast.err { border-color: rgba(251, 113, 133, 0.45); }

#pause-status {
  font-size: 12px;
  font-weight: 650;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
#pause-status.on { color: var(--warn); background: rgba(251,191,36,.1); }
#pause-status.off { color: var(--ok); background: rgba(52,211,153,.1); }

@media (max-width: 1100px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  #shell { grid-template-columns: 1fr; }
  #sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
  }
  #nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .section-bar { flex-direction: column; }
}
