:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16191d;
  --muted: #6a717c;
  --accent: #0f766e;
  --up: #16a34a;
  --warn: #d97706;
  --down: #dc2626;
  --off: #a3a9b2;
  --busy: #2563eb;
  --none: #e7e9ed;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --surface: #171a1f;
    --surface-2: #1e2228;
    --border: #2a2f36;
    --text: #e8eaed;
    --muted: #9198a3;
    --accent: #2dd4bf;
    --up: #22c55e;
    --warn: #f59e0b;
    --down: #f87171;
    --off: #5d636c;
    --busy: #60a5fa;
    --none: #262a31;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
h3 { font-size: 15px; font-weight: 600; margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.mono { font-family: var(--mono); font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* Buttons */
.btn {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn.sm { font-size: 12px; padding: 3px 8px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .switch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type=search], input[type=password], input[type=email], input[type=text], select {
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 7px;
  padding: 5px 9px;
}

/* Switch */
.switch {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  border: 0;
  background: var(--off);
  cursor: pointer;
  flex: none;
  transition: background .15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.switch[aria-checked=true] { background: var(--up); }
.switch[aria-checked=true]::after { transform: translateX(14px); }
.switch:disabled { opacity: .4; cursor: not-allowed; }
.switch.busy { opacity: .6; cursor: progress; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(340px, 100%);
  display: grid;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 8px; }
.login-card label { font-size: 13px; color: var(--muted); }
.error { color: var(--down); margin: 0; font-size: 13px; }

.link-btn { font: inherit; font-size: 13px; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; justify-self: start; }
.link-btn:hover { text-decoration: underline; }

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.brand .muted { font-weight: 450; }
.brand-mark { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.auto { display: flex; align-items: center; gap: 5px; color: var(--muted); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 550;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.up { color: var(--up); }
.pill.warn { color: var(--warn); }
.pill.down { color: var(--down); }
.pill.busy { color: var(--busy); }

.tabs { display: flex; gap: 2px; }
.tabs a { padding: 5px 10px; border-radius: 7px; color: var(--muted); font-weight: 550; font-size: 13px; }
.tabs a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.tabs a[aria-current=page] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.page { display: grid; gap: 28px; align-content: start; }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 60px; display: grid; gap: 28px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.section-head .filter { margin-left: auto; width: 200px; }

.banner { padding: 10px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--down); margin-bottom: 10px; }

/* Host tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 6px;
  align-content: start;
  min-width: 0;
}
.tile-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.tile-value { font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.tile-value small { font-size: 13px; font-weight: 450; color: var(--muted); margin-left: 4px; }
.tile-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.meter { height: 5px; border-radius: 99px; background: var(--none); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.warn > span { background: var(--warn); }
.meter.down > span { background: var(--down); }
.spark { width: 100%; height: 28px; display: block; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark path.area { fill: color-mix(in srgb, var(--accent) 12%, transparent); stroke: none; }
.tile .btn { justify-self: start; }

/* Groups and rows */
.group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.group-head h3 { font-size: 13px; }
.group-head .actions { margin-left: auto; display: flex; gap: 6px; }

.row {
  display: grid;
  grid-template-columns: 14px minmax(160px, 1.6fr) minmax(130px, 1.3fr) 64px 84px 150px auto;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.group-head + .row { border-top: 0; }
.row .name { font-weight: 550; overflow-wrap: anywhere; }
.row .sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.row .metric { font-size: 12px; text-align: right; font-variant-numeric: tabular-nums; }
.row .metric .muted { display: block; font-size: 11px; }
.row .actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.checks .row { grid-template-columns: 14px minmax(160px, 1.3fr) minmax(160px, 2fr) 64px 150px auto; }

.ep {
  display: grid;
  grid-template-columns: 14px minmax(160px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 8px 14px 8px 42px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
}
.neon-meta { padding: 0 14px 10px 42px; display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.neon-meta b { color: var(--text); font-weight: 550; }
.note { padding: 0 14px 10px 42px; font-size: 12px; color: var(--muted); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--off); }
.dot.up { background: var(--up); box-shadow: 0 0 0 3px color-mix(in srgb, var(--up) 18%, transparent); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.dot.down { background: var(--down); box-shadow: 0 0 0 3px color-mix(in srgb, var(--down) 18%, transparent); }
.dot.pending { background: var(--none); }
.dot.busy { background: var(--busy); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--busy) 25%, transparent); } }
@media (prefers-reduced-motion: reduce) { .dot.busy { animation: none; } }

.deploys .group-head .dot { flex: none; }
.deploys .group-head h3 { font-size: 14px; }
.run-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 10px 14px; }
.run-row .sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.run-row .msg { display: inline; }
.runs { display: flex; gap: 3px; justify-content: flex-end; }
.runs a { width: 12px; height: 18px; border-radius: 2px; background: var(--none); display: block; }
.runs a.success { background: var(--up); }
.runs a.failed { background: var(--down); }
.runs a.running { background: var(--busy); }
.runs a.skipped { background: var(--off); }
.runs-wrap { display: grid; gap: 2px; }
.msg { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.runs-wrap .small { text-align: right; }
.state-success { color: var(--up); }
.state-failed { color: var(--down); }
.state-running { color: var(--busy); }
.log-list { padding: 4px 14px 10px; display: grid; gap: 3px; font-size: 12px; }
.log-list .muted { margin-right: 6px; }
.subhead { padding: 10px 14px 2px; font-size: 12px; font-weight: 600; color: var(--muted); border-top: 1px solid var(--border); }

.builds { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; padding: 0 14px 14px; }
.build {
  display: grid;
  align-content: start;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.build.down { border-color: color-mix(in srgb, var(--down) 55%, var(--border)); }
.build.warn { border-color: color-mix(in srgb, var(--warn) 55%, var(--border)); }
.shot {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.shot img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.shot:hover { opacity: .92; }
.shot-empty { padding: 12px; font-size: 12px; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.build-body { padding: 9px 11px 11px; display: grid; gap: 3px; font-size: 13px; min-width: 0; }
.build-body .cap { display: flex; align-items: center; gap: 7px; min-width: 0; flex-wrap: wrap; margin-bottom: 2px; }
.build-body .sub { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px 6px; flex-wrap: wrap; overflow-wrap: anywhere; }
.build-body .sub .btn { margin-left: auto; }
.build .dot, .branches .dot { flex: none; }
.branches { min-width: 0; padding: 10px 14px 12px; border-top: 1px solid var(--border); }
.branches ul { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.branches li { display: flex; align-items: center; gap: 6px 12px; flex-wrap: wrap; min-width: 0; }
.branches .where { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.banner.warn { border-color: var(--warn); }

.bars { display: flex; gap: 1px; height: 18px; align-items: stretch; }
.bars span { flex: 1; border-radius: 1.5px; background: var(--none); }
.bars span.up { background: var(--up); }
.bars span.warn { background: var(--warn); }
.bars span.down { background: var(--down); }
.bars span.off { background: var(--off); }
.bars-wrap { display: grid; gap: 2px; }
.bars-wrap .small { text-align: right; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  margin-left: 6px;
  font-weight: 500;
  vertical-align: 1px;
}
.badge.down { color: var(--down); }
.badge.warn { color: var(--warn); }
.empty { padding: 18px 14px; color: var(--muted); }

/* Users */
.user-row { grid-template-columns: 14px minmax(180px, 1.2fr) minmax(150px, 1.2fr) minmax(150px, 210px) 360px 34px; }
.user-row .added { display: block; }
#apps .builds { padding-top: 14px; }
.badge.group { margin: 0 4px 2px 0; }
.badge.admin { color: var(--accent); }
.danger-text { color: var(--down); }
.section-head select { width: auto; }

/* Dialogs */
dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 12, 16, .45); }
.logs { width: min(1100px, calc(100vw - 32px)); height: min(80vh, 900px); }
.logs[open] { display: flex; flex-direction: column; }
.dialog-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.dialog-head .filter { width: 180px; }
.logs-body {
  flex: 1;
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  font: 12px/1.5 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
}
.logs-body .ts { color: var(--muted); }
.confirm { width: min(420px, calc(100vw - 32px)); }
.confirm form { padding: 18px 18px 14px; display: grid; gap: 10px; }
.confirm p { margin: 0; }
.form { padding: 18px 18px 14px; display: grid; gap: 8px; }
.form > label { font-size: 13px; color: var(--muted); }
.form fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 4px 0 0; display: grid; gap: 6px; }
.form legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.form .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.choice { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; }
.choice input { margin-top: 3px; flex: none; }
.checks-list { display: grid; gap: 6px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; min-width: 0; font-family: var(--mono); }
.confirm .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 20; max-width: calc(100vw - 32px); }
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  max-width: 420px;
}
.toast.error { background: var(--down); color: #fff; }

@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row, .checks .row { grid-template-columns: 14px minmax(0, 1fr) auto; row-gap: 6px; }
  .row .status, .row .bars-wrap { grid-column: 2 / -1; }
  .run-row { grid-template-columns: minmax(0, 1fr); row-gap: 8px; }
  .runs, .runs-wrap .small { justify-content: flex-start; text-align: left; }
  .row .metric { display: none; }
  .row .actions { grid-column: 3; grid-row: 1; }
  /* Users become cards: name and the enable switch on top, then groups, status and actions. */
  .user-row {
    grid-template-columns: 14px minmax(0, 1fr) auto;
    grid-template-areas: "dot who switch" ". groups groups" ". state state" ". actions actions";
    align-items: start;
    row-gap: 8px;
  }
  .user-row > .dot { grid-area: dot; margin-top: 6px; }
  .user-row > .who { grid-area: who; min-width: 0; }
  .user-row > .groups { grid-area: groups; }
  .user-row > .state { grid-area: state; }
  .user-row > .switch { grid-area: switch; margin-top: 1px; }
  .user-row > .actions { grid-area: actions; justify-content: flex-start; flex-wrap: wrap; }
  .user-row .added { display: inline; }
  .user-row .added::before { content: " · "; }
  .user-row .groups:has(.badge) { margin-bottom: -2px; }
}
@media (max-width: 640px) {
  /* The header wraps to three rows on phones; let it scroll away instead of pinning a fifth of the screen. */
  .top { padding: 10px 16px; position: static; }
  main { padding: 16px 16px 48px; }
  .tiles { grid-template-columns: minmax(0, 1fr); }
  .section-head .filter { width: 140px; }
  .builds { grid-template-columns: minmax(0, 1fr); }
  .deploys .group-head .actions { margin-left: 0; width: 100%; }
  .ep { padding-left: 28px; grid-template-columns: 14px minmax(0, 1fr); }
  .ep .actions { grid-column: 2; justify-content: flex-start; }
  .neon-meta, .note { padding-left: 28px; }
  #updated, #me { display: none; }
  .tabs { order: 10; width: 100%; overflow-x: auto; }
  .section-head { flex-wrap: wrap; }
  /* Users head: title, count and Add user on one line; group filter and search share the next. */
  #page-users .section-head { display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; }
  #page-users .section-head .spacer { display: none; }
  #user-add { grid-column: 4; grid-row: 1; }
  #users-group { grid-column: 1 / 3; grid-row: 2; }
  #page-users .section-head .filter { grid-column: 3 / -1; grid-row: 2; width: 100%; margin: 0; }
  .user-row { padding: 12px 14px; }
  .user-row > .actions { gap: 8px; }
  .user-row > .actions .danger-text { margin-left: auto; }
}

/* Touch screens: larger tap targets, and 16px inputs so iOS does not zoom in on focus. */
@media (pointer: coarse) {
  input[type=search], input[type=password], input[type=email], input[type=text], select { font-size: 16px; padding: 7px 10px; }
  .btn { padding: 8px 12px; }
  .btn.sm { font-size: 13px; padding: 7px 11px; }
  .switch { width: 44px; height: 26px; }
  .switch::after { width: 22px; height: 22px; }
  .switch[aria-checked=true]::after { transform: translateX(18px); }
  .choice { padding: 4px 0; }
  .choice input, .checks-list input { width: 18px; height: 18px; }
}
