:root {
  --bg: #12181a;
  --panel: #1a2224;
  --panel-2: #212b2e;
  --line: #2c3a3d;
  --text: #e8ece9;
  --muted: #8b9a96;
  --accent: #c9974a;
  --accent-glow: rgba(201, 151, 74, 0.45);
  /* Semantic status stays a separate, cooler family from the copper accent
     so "this needs attention" never competes visually with "this is the
     brand colour". */
  --up: #4fae8c;
  --down: #b5524a;
  --partial: #b6a15a;
  --host: #9b93c9;
  --mono: 'Space Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius: 12px;
  font-family: 'Sora', ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Noto Sans TC", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2426 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.muted { color: var(--muted); }
.error { color: var(--down); font-size: 0.85rem; margin: 6px 0 0; }

.brand {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.5px;
}
.brand .w {
  color: var(--accent);
  text-shadow: 0 0 18px var(--accent-glow);
}
.brand--lg { font-size: 2.4rem; margin-bottom: 4px; }

/* login */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}

/* the signature — a physical rocker switch. Off by default; flips to on the
   instant Pocket ID hands control back, then the app fades in behind it.
   One bold gesture here, everything else on the page stays quiet. */
.switch-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 22px;
}
.switch-text {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--muted);
  opacity: 0.4;
  transition: opacity 0.35s ease, color 0.35s ease;
}
.switch-unit:has(.switch-rocker[data-state="on"]) .switch-text-on {
  opacity: 1;
  color: var(--accent);
}
.switch-unit:has(.switch-rocker[data-state="off"]) .switch-text-off {
  opacity: 1;
  color: var(--text);
}
.switch-plate {
  width: 72px;
  height: 116px;
  background: linear-gradient(180deg, #0d1213, #171f21);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.55),
    0 10px 26px rgba(0, 0, 0, 0.35);
}
.switch-rocker {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: var(--bg);
  box-shadow: inset 0 0 0 1px var(--line);
}
.switch-nub {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 6px;
  height: calc(50% - 9px);
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  /* A whisper of overshoot, not a cartoon bounce — a spring-loaded rocker
     snaps and settles, it doesn't wobble. Kept well short of a full
     easeOutBack curve on purpose. */
  transition: transform 0.5s cubic-bezier(0.3, 1.1, 0.5, 1), background 0.4s ease, box-shadow 0.4s ease,
    border-color 0.4s ease;
}
.switch-rocker[data-state="on"] .switch-nub {
  transform: translateY(calc(-100% - 6px));
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 22px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.login-card input {
  width: 100%;
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-card button {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.08); }
.btn-oidc {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  text-align: center;
  box-sizing: border-box;
}
.btn-oidc:hover { filter: brightness(1.08); }
.btn-oidc:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(12, 14, 18, 0.82);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.topbar .brand { flex: none; }
.filter {
  flex: 0 1 200px;
  min-width: 80px;
  padding: 7px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font-size: 0.85rem;
}
.filter::placeholder { color: var(--muted); }
.filter:focus { outline: 2px solid var(--accent); border-color: transparent; }
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}
.summary {
  font-size: 0.85rem;
  color: var(--muted);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ghost {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  width: 34px;
  height: 34px;
  flex: none;
  font-size: 1rem;
  cursor: pointer;
}
.ghost:hover { border-color: var(--accent); }

/* board + groups */
.board {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 22px 30px;
}

.mem-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 2px 18px;
}
.mem-bar-track {
  flex: 1;
  max-width: 260px;
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
}
.mem-bar-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  border-radius: 999px;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.4s ease;
}
.mem-bar-text {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mem-bar-sep { color: var(--line); margin: 0 8px; }

@media (max-width: 520px) {
  .mem-bar { flex-wrap: wrap; }
  .mem-bar-track { flex-basis: 100%; max-width: none; order: 2; }
}
.grp + .grp { margin-top: 26px; }
.grp-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 16px 2px 8px;
  border-bottom: 1px solid var(--line);
}
.grp-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text);
}
.grp-count {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 4px;
  gap: 10px;
}
.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.03);
}
.dot.up { background: var(--up); box-shadow: 0 0 12px var(--up); }
.dot.down { background: var(--down); }
.dot.partial { background: var(--partial); box-shadow: 0 0 12px var(--partial); }
.card-title { font-weight: 700; font-size: 1.05rem; }
.card-sub { font-size: 0.78rem; color: var(--muted); margin-left: auto; text-align: right; }
.card-path {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: -4px;
}

.meta { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 0.75rem;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.chip:hover { border-color: var(--accent); }
.chip .pdot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.chip .pdot.live { background: var(--up); }
.chip .pdot.dead { background: var(--down); }
.chip.domain { color: var(--accent); }

/* source tag — typographic label, not a chip: weight + tracking + an
   underline rule carry the distinction, no fill, no border. */
.tag {
  flex: none;
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  line-height: 1;
  padding-bottom: 3px;
  border-bottom: 1.5px solid currentColor;
  white-space: nowrap;
}
.tag--docker { color: var(--accent); }
/* A dedicated neutral, not --partial: that amber is reserved for the
   degraded-status dot, and Host being fully up shouldn't borrow it. */
.tag--host { color: var(--host); }

.services { display: flex; flex-direction: column; gap: 4px; }
.svc {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
}
.svc .s-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--down); flex: none; }
.svc .s-dot.running { background: var(--up); }
.svc .s-name { color: var(--text); }

.hint { font-size: 0.68rem; color: var(--muted); line-height: 1.4; }

.actions { display: flex; gap: 8px; margin-top: 2px; }
.btn {
  flex: 1;
  padding: 9px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.up { color: var(--up); }
.btn.down { color: var(--down); }

.btn:focus-visible,
.ghost:focus-visible,
.chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.foot { padding: 14px 22px 30px; text-align: center; font-size: 0.78rem; }

@media (max-width: 520px) {
  .board { padding: 8px 14px 24px; }
  .grid { gap: 12px; }
  .topbar { padding: 14px 16px; flex-wrap: wrap; }
  .filter { order: 3; flex-basis: 100%; }
}

.empty {
  padding: 40px 12px;
  text-align: center;
  font-size: 0.85rem;
}

/* tabs */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 2px;
  flex: none;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--text); }
/* a faint echo of the login switch's pressed-in feel, not a full reskin —
   the boldness is spent once, on the switch itself. */
.tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4), inset 0 -1px 0 rgba(255, 255, 255, 0.03);
  transform: translateY(0.5px);
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* residents — the homepage. A list, not a card grid: these are one kind of
   thing (a long-lived conversation pinned to a project), so a dense,
   scannable row tells the truth about the data better than a grid of
   equal-height boxes built for heterogeneous services. */
.residents-board {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 22px 40px;
}

/* heartbeat — one segment per resident, coloured by health. Not load-bearing
   information (the list below already has it precisely), it's there so the
   system reads as alive at a glance, the way a rack of blinking lights does. */
.heartbeat {
  display: flex;
  gap: 3px;
  height: 30px;
  margin-bottom: 22px;
}
.hb-seg {
  flex: 1;
  border-radius: 3px;
  background: var(--up);
  opacity: 0.55;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.hb-seg.restarting { background: var(--partial); }
.hb-seg:hover {
  opacity: 1;
  transform: scaleY(1.15);
}

.r-list {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}
.r-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--line);
}
.r-row:hover { background: var(--panel); }

/* First paint only (see app.js) — each row reports in with a small stagger,
   echoing the heartbeat's "this is alive" idea without replaying on every
   4s poll, which would just read as flicker. */
@keyframes r-row-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.r-row-enter { animation: r-row-in 0.4s ease both; }

.r-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--up);
  box-shadow: 0 0 10px var(--up);
}
.r-dot.restarting { background: var(--partial); box-shadow: 0 0 10px var(--partial); }

.r-name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.88rem;
  flex: none;
}
.r-title {
  color: var(--muted);
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.r-title.pending { font-style: italic; }

.r-folder {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.75;
  flex: none;
  display: none; /* shown from tablet width up — see media query */
}

.r-sessionid {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.75;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  flex: none;
  display: none; /* shown from a wider breakpoint than r-folder — it's the longer of the two */
}
.r-sessionid:hover { color: var(--text); opacity: 1; }

.r-copy {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  flex: none;
  cursor: pointer;
}
.r-copy:hover { color: var(--text); border-color: var(--muted); }

.r-open {
  flex: none;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 11px;
  white-space: nowrap;
}
.r-open:hover { border-color: var(--accent); }
.r-open[aria-disabled="true"] { color: var(--muted); pointer-events: none; }

.r-copy:focus-visible, .r-open:focus-visible, .r-sessionid:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (min-width: 640px) {
  .r-folder { display: block; }
}
@media (min-width: 900px) {
  .r-sessionid { display: block; }
}
@media (max-width: 480px) {
  .r-row { flex-wrap: wrap; }
  .r-title { flex-basis: 100%; order: 3; }
}

@media (prefers-reduced-motion: reduce) {
  .switch-nub,
  .switch-text,
  .tab,
  .hb-seg,
  .mem-bar-fill { transition-duration: 0.01ms !important; }
  .r-row-enter { animation: none; }
}
