:root {
  color-scheme: light dark;
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #efede7;
  --text: #1c1b18;
  --muted: #67625a;
  --border: #e2dfd7;
  --ok: #18794e;
  --ok-soft: #e3f3ea;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --on-bad: #ffffff;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --idle: #b9b4aa;
  --meter: #8a8478;
  --primary: #1c1b18;
  --primary-text: #ffffff;
  --focus: #2563eb;
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --surface: #1d1c19;
    --surface-2: #272521;
    --text: #eceae4;
    --muted: #a39e94;
    --border: #34312c;
    --ok: #4cc38a;
    --ok-soft: #16301f;
    --bad: #ff7a6e;
    --bad-soft: #3a1714;
    --on-bad: #1d0907;
    --warn: #f0b545;
    --warn-soft: #33270f;
    --idle: #57534b;
    --meter: #7d776d;
    --primary: #eceae4;
    --primary-text: #141311;
    --focus: #7aa2ff;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
code, pre { font-family: var(--mono); font-size: 0.86em; }
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted { color: var(--muted); }
.wrap { max-width: 1040px; margin: 0 auto; padding-inline: 16px; }

/* Buttons and inputs */

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: var(--primary); opacity: 0.88; }
.btn-quiet { border-color: transparent; background: transparent; }
.btn-sm { padding: 3px 8px; font-size: 13px; }

input[type="email"], input[type="password"] {
  font: inherit;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}

.form-error { color: var(--bad); font-size: 14px; }
.form-error:empty { display: none; }

/* Login */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 340px;
  display: grid;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}
.login-card h1 { font-size: 20px; margin-bottom: 8px; }
.login-card label { font-size: 14px; font-weight: 500; }

/* Layout */

.topbar { border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; flex-wrap: wrap; padding-block: 8px; }
.brand { font-weight: 650; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#last-cycle { font-size: 14px; margin-right: 4px; }

main { padding-block: 36px 64px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 48px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.panel-pad { padding: 18px 20px; }

.section-head { display: grid; gap: 4px; margin-bottom: 14px; }
.section-head h2 { font-size: 17px; }
.section-head p { font-size: 14px; }

.columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px; align-items: start; }

/* Overview */

.overview { display: grid; gap: 6px; }
.summary { font-size: 28px; line-height: 1.2; letter-spacing: -0.01em; }
.summary[data-tone="ok"] { color: var(--ok); }
.summary[data-tone="bad"] { color: var(--bad); }
.summary[data-tone="warn"] { color: var(--warn); }
#check-rules { font-size: 14px; margin-bottom: 14px; }

.services { list-style: none; margin: 0; padding: 0; overflow: hidden; }

.service {
  display: grid;
  /* Fixed metrics width keeps the check strips aligned whether or not a row has a Local metric */
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 1.6fr) 300px minmax(150px, auto);
  align-items: center;
  gap: 12px 24px;
  padding: 18px 20px;
}
.service + .service { border-top: 1px solid var(--border); }
.service.is-down { background: var(--bad-soft); }

.service-id { display: flex; align-items: flex-start; gap: 12px; }
.service-id h3 { font-size: 16px; line-height: 1.3; }
.service-id > div { min-width: 0; }
.service-id a { font-size: 13px; color: var(--muted); text-decoration: none; overflow-wrap: anywhere; }
.service-id a:hover { text-decoration: underline; }

.status {
  display: inline-block;
  min-width: 62px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  padding: 0 8px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  margin-top: 1px;
}
.status-up, .status-online { background: var(--ok-soft); color: var(--ok); }
.status-down, .status-stopped, .status-errored, .status-missing { background: var(--bad); color: var(--on-bad); }
.status-failing, .status-slow, .status-warning, .status-mixed, .status-launching, .status-stopping { background: var(--warn-soft); color: var(--warn); }

.tone-warn { color: var(--warn); }
.tone-bad { color: var(--bad); }

/* Newest check on the right. Failed checks are taller as well as red, so they read without color. */
.strip { display: flex; align-items: flex-end; gap: 2px; height: 28px; }
.bar { flex: 1; min-width: 2px; height: 55%; border-radius: 1px; background: var(--ok); opacity: 0.6; }
.bar.fail { height: 100%; background: var(--bad); opacity: 1; }
.bar.empty { background: var(--idle); opacity: 0.35; }
.strip-caption { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

.metrics { display: flex; gap: 22px; margin: 0; }
.metrics div { display: grid; }
.metrics dt { font-size: 12px; color: var(--muted); }
.metrics dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.service-action { justify-self: end; }
.service-detail { grid-column: 1 / -1; font-size: 14px; color: var(--bad); }
.service.is-failing .service-detail, .service.is-slow .service-detail { color: var(--warn); }

/* Active alerts other than service outages */

.alerts { list-style: none; margin: 0 0 14px; padding: 4px 0; }
.alerts li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 9px 18px; font-size: 14px; }
.alerts li + li { border-top: 1px solid var(--border); }
.alert-text { overflow-wrap: anywhere; }
.alert-since { font-size: 13px; white-space: nowrap; }

/* Server */

.server-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) auto; gap: 8px 20px; align-items: center; padding: 14px 20px; }
.server-row + .server-row { border-top: 1px solid var(--border); }
.server-label { font-size: 14px; font-weight: 600; }
.server-value { display: grid; gap: 6px; min-width: 0; }
.server-text { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.server-text strong { color: var(--text); font-weight: 600; }
.server-text.tone-warn { color: var(--warn); }
.server-text.tone-bad { color: var(--bad); }

/* The mark shows where the warning starts */
.meter { position: relative; height: 8px; max-width: 560px; border-radius: 4px; background: var(--surface-2); }
.meter-fill { display: block; height: 100%; border-radius: 4px; background: var(--meter); }
.meter-fill.warn { background: var(--warn); }
.meter-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--muted); }

/* PM2 table */

.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 11px 16px; white-space: nowrap; }
th { font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
tbody tr + tr td { border-top: 1px solid var(--border); }
td.num, th.num { text-align: right; }
td.action { text-align: right; width: 1%; }
.restarts-high { color: var(--warn); font-weight: 600; }
.pm2-mode { font-size: 13px; color: var(--muted); margin-left: 6px; }
.pm2-problem { display: block; max-width: 340px; margin-top: 2px; font-size: 13px; white-space: normal; }

.panel-message { padding: 18px 20px; font-size: 14px; }
.panel-message.error { color: var(--bad); }

/* Alerts */

.callout {
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  margin-bottom: 14px;
}

.receivers { list-style: none; margin: 0 0 14px; padding: 0; }
.receivers li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; overflow-wrap: anywhere; }
.receivers li + li { border-top: 1px solid var(--border); }
.receivers li.empty { color: var(--muted); font-size: 14px; display: block; }

.receiver-form { display: flex; gap: 8px; }
.receiver-form input { flex: 1; }
.receiver-form + .form-error { margin-top: 8px; }

.test-email { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 14px; }

/* Activity */

.events { list-style: none; margin: 0; padding: 6px 0; max-height: 460px; overflow-y: auto; }
.events li { display: grid; grid-template-columns: 8px auto 1fr; gap: 10px; align-items: baseline; padding: 8px 18px; font-size: 14px; }
.events li.empty { display: block; color: var(--muted); }
.events time { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.events .text { overflow-wrap: anywhere; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--idle); transform: translateY(-1px); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--warn); }

/* Result panel for reloads and test emails */

.notice {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.18);
  padding: 14px 16px;
}
.notice[data-tone="bad"] { border-color: var(--bad); }
.notice-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.notice[data-tone="bad"] #notice-title { color: var(--bad); }
.notice pre { margin: 10px 0 0; max-height: 240px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); }
.notice pre:empty { display: none; }

/* Below this width the four service columns no longer fit side by side */
@media (max-width: 1020px) {
  .service { grid-template-columns: 1fr auto; }
  .service-id { grid-column: 1 / -1; }
  .strip-wrap { grid-column: 1 / -1; }
  .metrics { grid-column: 1; }
  .service-action { grid-column: 2; }
}

@media (max-width: 860px) {
  .columns { grid-template-columns: minmax(0, 1fr); gap: 48px; }
}

/* On phones each process becomes a card so the reload button stays in view. */
@media (max-width: 620px) {
  .pm2-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .pm2-table tbody { display: block; }
  .pm2-table tr { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; padding: 14px 16px; }
  .pm2-table tbody tr + tr { border-top: 1px solid var(--border); }
  .pm2-table td { padding: 0; border: 0 !important; text-align: left; white-space: normal; }
  .pm2-table td.name { grid-column: 1 / 4; }
  .pm2-table td.state { grid-column: 4; justify-self: end; }
  .pm2-table td.num::before { content: attr(data-label); display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
  .pm2-table td.action { grid-column: 1 / -1; width: auto; }
  .pm2-table td.action:empty { display: none; }
  .pm2-table td.action .btn { width: 100%; }
}

@media (max-width: 520px) {
  .alerts li { grid-template-columns: auto minmax(0, 1fr); }
  .alert-since { grid-column: 2; }
  .server-row { grid-template-columns: minmax(0, 1fr) auto; }
  .server-state { grid-row: 1; grid-column: 2; }
  .server-value { grid-row: 2; grid-column: 1 / -1; }
  main { padding-block: 24px 48px; gap: 40px; }
  .summary { font-size: 23px; }
  .service { grid-template-columns: 1fr; padding: 16px; }
  .metrics, .service-action { grid-column: 1; }
  .service-action { justify-self: stretch; }
  .service-action .btn { width: 100%; }
  #last-cycle { flex-basis: 100%; order: 3; }
}
