:root {
  --bg: #f2f3f0;
  --surface: #ffffff;
  --ink: #15181c;
  --muted: #5d646c;
  --line: #d8dbd5;
  --add: #1a7f4b;
  --add-soft: #e3f1e8;
  --del: #b8392a;
  --del-soft: #f7e6e3;
  --radius: 10px;
  --font-sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416;
    --surface: #181c1f;
    --ink: #e8eae6;
    --muted: #979ea5;
    --line: #2b3035;
    --add: #3fb67a;
    --add-soft: #16291f;
    --del: #e5705f;
    --del-soft: #2e1a17;
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--add);
  text-underline-offset: 3px;
}

code,
.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.sprite,
[hidden] {
  display: none !important;
}

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  padding: 0.5rem 0.75rem;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius);
  z-index: 10;
}
.skip-link:focus {
  top: 1rem;
}

:focus-visible {
  outline: 2px solid var(--add);
  outline-offset: 2px;
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
}
.icon-lg {
  width: 24px;
  height: 24px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
}

.brand-mark {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--add);
  box-shadow: 18px 0 0 -4px var(--ink);
  margin-right: 12px;
}

.brand-sep {
  color: var(--muted);
  padding: 0 1px;
}

.account {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
}
.account img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
}
.account-login {
  font-family: var(--font-mono);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Branch rail tabs — the signature element */
.rail {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 0.5rem;
}

.rail-track {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
.rail-track::before {
  content: "";
  position: absolute;
  left: 12.5%;
  right: 12.5%;
  top: 11px;
  height: 2px;
  background: var(--line);
}

.rail-tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0 0.5rem;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.02em;
  cursor: pointer;
  border-radius: var(--radius);
}
.rail-tab:hover {
  color: var(--ink);
}

.rail-node {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--line);
  transition: border-color 0.2s, background-color 0.2s, transform 0.2s;
}
.rail-tab:hover .rail-node {
  border-color: var(--muted);
}

.rail-tab[aria-selected="true"] {
  color: var(--ink);
  font-weight: 600;
}
.rail-tab[aria-selected="true"] .rail-node {
  border-color: var(--add);
  background: var(--add);
  box-shadow: inset 0 0 0 4px var(--bg);
  transform: scale(1.08);
}

/* Panels */
.panels {
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem 1.25rem 4rem;
}

.panel-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.panel-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.panel-sub {
  margin: 0.25rem 0 0;
  color: var(--muted);
  text-wrap: pretty;
}

.card-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-danger {
  border-color: color-mix(in srgb, var(--del) 45%, var(--line));
}
.card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.card-danger .card-title {
  color: var(--del);
}
.card-body {
  margin: -0.5rem 0 0;
  color: var(--muted);
  text-wrap: pretty;
}

.grid-2 {
  display: grid;
  gap: 1rem;
}
@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

/* Form controls */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}
.field-grow {
  flex: 1 1 220px;
}
.label {
  font-size: 13px;
  font-weight: 600;
  padding: 0;
}
.hint {
  font-size: 13px;
  color: var(--muted);
}
.hint-inline {
  color: var(--muted);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select {
  width: 100%;
  height: 40px;
  padding: 0 0.75rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
  font: inherit;
  font-size: 14px;
}
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--add);
  outline-offset: -1px;
  border-color: var(--add);
}
input.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}
input:user-invalid {
  border-color: var(--del);
}

.input-group {
  display: flex;
  gap: 0.5rem;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 14px;
  cursor: pointer;
}
.check input {
  margin: 3px 0 0;
  width: 16px;
  height: 16px;
  accent-color: var(--add);
  flex: none;
}
.check-danger input {
  accent-color: var(--del);
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border: 0;
  margin: 0;
  padding: 0;
}
.radio-group legend {
  margin-bottom: 0.5rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.toolbar .field:not(.field-grow) {
  flex: 0 1 180px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  height: 40px;
  padding: 0 1rem;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--ink);
  color: var(--bg);
}
.btn-primary:not(:disabled):hover {
  background: var(--add);
  color: var(--surface);
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}
.btn-ghost:not(:disabled):hover {
  background: var(--surface);
  border-color: var(--muted);
}
.btn-outline {
  background: var(--add-soft);
  color: var(--add);
  border-color: color-mix(in srgb, var(--add) 35%, transparent);
}
.btn-outline:not(:disabled):hover {
  background: var(--add);
  color: var(--surface);
}
.btn-danger {
  background: var(--del);
  color: var(--surface);
}
.btn-danger:not(:disabled):hover {
  background: color-mix(in srgb, var(--del) 85%, var(--ink));
}
.btn-sm {
  height: 32px;
  padding: 0 0.65rem;
  font-size: 13px;
  gap: 0.35rem;
}
.btn-icon {
  width: 40px;
  padding: 0;
  flex: none;
}
.btn[aria-busy="true"] {
  cursor: progress;
}

/* Repo list */
.list-meta {
  margin: 0 0 0.5rem;
  font-size: 13px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.repo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.repo-list:empty {
  display: none;
}

.repo {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--line);
}
.repo:first-child {
  border-top: 0;
}
@media (min-width: 720px) {
  .repo {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
  }
}

.repo-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.repo-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.repo-name {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  word-break: break-word;
}
.repo-name:hover {
  color: var(--add);
  text-decoration: underline;
}
.repo-desc {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-wrap: pretty;
}
.repo-desc:empty {
  display: none;
}
.repo-meta {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
.repo-actions {
  display: flex;
  gap: 0.4rem;
  flex: none;
}

.badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge[data-private="true"] {
  color: var(--del);
  border-color: color-mix(in srgb, var(--del) 40%, transparent);
}
.badge[data-private="false"] {
  color: var(--add);
  border-color: color-mix(in srgb, var(--add) 40%, transparent);
}

.agents-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
}
.agents-label {
  font-weight: 600;
}
.agents-label.agents-down {
  color: var(--del);
}
.agents-detail {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.journal {
  list-style: none;
  margin: 0;
  padding: 0;
}
.journal li {
  padding: 0.5rem 0;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.journal li:first-child {
  border-top: 0;
}

.skeleton {
  height: 74px;
  border-top: 1px solid var(--line);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--line) 50%, transparent), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}
.skeleton:first-child {
  border-top: 0;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: 3rem 1.5rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty-title {
  margin: 0;
  font-weight: 600;
}
.empty-body {
  margin: 0 0 0.5rem;
  color: var(--muted);
}

/* Dropzone */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 2rem 1rem;
  text-align: center;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
  margin-top: -0.5rem;
}
.dropzone:hover,
.dropzone.is-over,
.dropzone:focus-within {
  border-color: var(--add);
  background: var(--add-soft);
  color: var(--ink);
}
.dropzone-text strong {
  color: var(--ink);
}

.zip-summary {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.zip-summary-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 13px;
}
.diff-stat {
  color: var(--add);
  font-family: var(--font-mono);
  font-size: 13px;
}

.file-preview {
  list-style: none;
  margin: 0;
  padding: 0.75rem 1rem;
  max-height: 220px;
  overflow: auto;
  background: var(--bg);
  border-radius: calc(var(--radius) - 2px);
  font-size: 12px;
  line-height: 1.7;
}
.file-preview li::before {
  content: "+ ";
  color: var(--add);
}
.file-preview li.more::before {
  content: "";
}
.file-preview li.more {
  color: var(--muted);
}

/* Progress */
.progress-card {
  margin-top: 1rem;
}
.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
}
.progress {
  height: 6px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--add);
  transition: width 0.2s ease;
}
.progress[data-state="error"] .progress-fill {
  background: var(--del);
}
.log {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
  max-height: 180px;
  overflow: auto;
  line-height: 1.7;
}
.log .ok {
  color: var(--add);
}
.log .err {
  color: var(--del);
}

/* Settings */
.verify {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  background: var(--add-soft);
  font-size: 14px;
}
.verify[data-state="error"] {
  background: var(--del-soft);
  color: var(--del);
}
.verify img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}
.verify-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.verify-body span {
  color: var(--muted);
  font-size: 13px;
  word-break: break-word;
}

/* Transfer */
.conn-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}
.conn-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) - 2px);
}
.conn-row img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
}
.conn-row span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conn-empty {
  color: var(--muted);
  font-size: 14px;
}

.scopes {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.scopes th,
.scopes td {
  text-align: left;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.scopes th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.scopes tr:last-child td {
  border-bottom: 0;
}

/* Toasts */
.toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  left: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 20;
}
.toast {
  max-width: 420px;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}
.toast[data-kind="error"] {
  background: var(--del);
  color: var(--surface);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
