/* Tokens. Light is defined on bare :root so no colour is only defined inside a
   media query; dark redefines the same names. */
:root {
  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --border:    #e3e6ea;
  --text:      #16191d;
  --text-dim:  #5d6570;
  --accent:    #0f7a75;
  --accent-fg: #ffffff;
  --accent-bg: #e3f4f2;
  --danger:    #b4232b;
  --danger-bg: #fdeced;
  --warn:      #8a5a00;
  --warn-bg:   #fdf3e0;
  --warn-brd:  #e8cfa0;
  --ok:        #1d7a4d;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #14171a;
    --surface:   #1c2024;
    --border:    #2c3238;
    --text:      #e8eaed;
    --text-dim:  #9aa3ad;
    --accent:    #5fd3c8;
    --accent-fg: #0b1a18;
    --accent-bg: #16302d;
    --danger:    #f08a90;
    --danger-bg: #331d1f;
    --warn:      #e8c07a;
    --warn-bg:   #2e2617;
    --warn-brd:  #4a3d22;
    --ok:        #6fd3a1;
  }
}

* { box-sizing: border-box; }

/* The [hidden] attribute must win over any component's own display rule
   (e.g. .inline-form's display: flex) — otherwise toggling .hidden in JS on
   an element that also carries a layout class silently does nothing. */
[hidden] { display: none !important; }

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

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 56px; max-width: 720px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; }
.brand-mark { width: 14px; height: 14px; border-radius: 3px; background: var(--accent); }
.nav { display: flex; gap: 4px; margin-right: auto; }
.nav-link { color: var(--text-dim); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-weight: 500; }
.nav-link:hover { background: var(--accent-bg); color: var(--accent); }
.nav-link[aria-current="page"] { background: var(--accent-bg); color: var(--accent); }
.user { color: var(--text-dim); font-size: 13px; }

/* Page */
.view-head { margin: 28px 0 16px; }
h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 2px; }
.sub { margin: 0; color: var(--text-dim); font-size: 13px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

.notice {
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}
.notice-warn { background: var(--warn-bg); border-color: var(--warn-brd); color: var(--warn); }
.notice strong { display: block; }

/* Form */
.field { margin-bottom: 16px; }
label { display: block; font-weight: 500; margin-bottom: 5px; }
.optional { font-weight: 400; color: var(--text-dim); font-size: 12px; }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[aria-invalid="true"] { border-color: var(--danger); }
.hint { margin: 5px 0 0; font-size: 12px; color: var(--text-dim); }
.err { margin: 5px 0 0; font-size: 12px; color: var(--danger); }

.actions { display: flex; align-items: center; gap: 12px; margin-top: 20px; }
.btn {
  font: inherit;
  font-weight: 500;
  border-radius: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-quiet { color: var(--danger); border-color: transparent; background: transparent; padding: 6px 10px; }
.btn-quiet:hover { background: var(--danger-bg); }

.form-msg { font-size: 13px; }
.form-msg.ok { color: var(--ok); }
.form-msg.bad { color: var(--danger); }

.meta {
  display: grid; grid-template-columns: 110px 1fr; gap: 4px 16px;
  margin: 20px 0 0; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
}
.meta dd { margin: 0; }
.mono { font-family: var(--mono); }

@media (max-width: 520px) {
  .brand-name { display: none; }
  .meta { grid-template-columns: 1fr; }
}

/* Home */
a.brand { text-decoration: none; color: inherit; }

.statuses { list-style: none; margin: 0; padding: 0; }
.status {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.status:first-child { border-top: 0; }
.status-name { font-weight: 500; min-width: 90px; }
.status-detail { color: var(--text-dim); font-size: 13px; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-dim); }
.dot-ok   { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-bad  { background: var(--danger); }
.dot-idle { background: var(--border); }

.features { list-style: none; margin: 14px 0 0; padding: 0; }
.feature {
  display: flex; gap: 12px; align-items: baseline;
  padding: 9px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.feature strong { min-width: 130px; font-weight: 600; }
.feature span { color: var(--text-dim); }
.feature a { color: var(--accent); text-decoration: none; }
.feature-todo strong { color: var(--text-dim); font-weight: 500; }

/* Deployments */
.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;
}

.inline-form { display: flex; gap: 10px; align-items: flex-start; }
.field-grow { flex: 1; margin-bottom: 0; }
.inline-form .btn { flex: none; }

.repos { list-style: none; margin: 18px 0 0; padding: 0; }
.repo {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 0;
  border-top: 1px solid var(--border);
}
.repo-main { flex: 1; min-width: 0; }
.repo-path {
  font-family: var(--mono); font-size: 13px;
  background: none; border: 0; padding: 0;
  color: var(--text); cursor: pointer; text-align: left;
  display: block; width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.repo-path:hover { color: var(--accent); }
.repo[aria-selected="true"] .repo-path { color: var(--accent); font-weight: 600; }
.repo-meta { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.repo-actions { display: flex; gap: 4px; flex: none; }
.icon-btn {
  font: inherit; font-size: 12px;
  background: none; border: 1px solid transparent; border-radius: 6px;
  color: var(--text-dim); padding: 4px 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--accent-bg); color: var(--accent); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }

.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; flex: none; }
.seg-btn {
  font: inherit; font-size: 12px;
  background: var(--surface); color: var(--text-dim);
  border: 0; border-left: 1px solid var(--border);
  padding: 5px 11px; cursor: pointer;
}
.seg-btn:first-child { border-left: 0; }
.seg-btn[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent); font-weight: 500; }

.mr {
  display: flex; gap: 12px; align-items: baseline;
  padding: 11px 0; border-top: 1px solid var(--border);
}
.mr:first-child { border-top: 0; }
.mr-iid { font-family: var(--mono); font-size: 12px; color: var(--text-dim); flex: none; min-width: 42px; }
.mr-main { flex: 1; min-width: 0; }
.mr-title { text-decoration: none; color: var(--text); font-weight: 500; }
.mr-title:hover { color: var(--accent); }
.mr-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.mr-branch { font-family: var(--mono); }
.badge {
  font-size: 11px; padding: 2px 7px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--text-dim); flex: none;
}
.badge-opened { color: var(--ok); border-color: var(--ok); }
.badge-merged { color: var(--accent); border-color: var(--accent); }
.badge-closed { color: var(--text-dim); }
.badge-draft  { color: var(--warn); border-color: var(--warn-brd); }
.badge-active   { color: var(--ok); border-color: var(--ok); }
.badge-inactive { color: var(--text-dim); }

.state {
  padding: 26px; text-align: center; color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.state-error { color: var(--danger); border-color: var(--danger); }
.state a { color: var(--accent); }

@media (max-width: 560px) {
  .inline-form { flex-direction: column; }
  .inline-form .btn { width: 100%; }
  .panel-head { flex-direction: column; align-items: stretch; }
}

/* Inline help */
.help {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 16px;
  background: var(--bg);
}
.help summary {
  cursor: pointer;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
}
.help summary::-webkit-details-marker { display: none; }
.help summary::before { content: "▸ "; }
.help[open] summary::before { content: "▾ "; }
.help-body { padding: 0 12px 12px; font-size: 13px; }
.help-body p { margin: 0 0 10px; }

.scope-table { border-collapse: collapse; width: 100%; margin: 0 0 10px; font-size: 13px; }
.scope-table th, .scope-table td {
  text-align: left; padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.scope-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); }

/* Deployment progress toast — fixed to the viewport, not part of page flow.
   Capped height with its own scroll so a many-step deploy grows a scrollbar
   inside the toast rather than the toast itself off the bottom of the
   screen. z-index above .panel content but below <dialog>, which browsers
   already put in the top layer. */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 360px;
  max-width: calc(100vw - 40px);
  max-height: min(70vh, 480px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  z-index: 40;
}
.toast-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.toast .steps { margin-top: 4px; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in .18s ease-out; }
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px) {
  .toast { left: 16px; right: 16px; bottom: 16px; width: auto; }
}

/* Deployment progress */
.progress {
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  margin: 4px 0 16px;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width .35s ease;
}
.progress.is-failed .progress-bar { background: var(--danger); }
.progress.is-done   .progress-bar { background: var(--ok); }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.step {
  display: flex; gap: 10px; align-items: baseline;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.step:first-child { border-top: 0; }
.step-icon { flex: none; width: 16px; text-align: center; font-size: 12px; }
.step-main { flex: 1; min-width: 0; }
.step-label { color: var(--text-dim); }
.step-detail { font-size: 12px; color: var(--text-dim); margin-top: 2px; word-break: break-word; }
.step-detail a { color: var(--accent); }

.step-running .step-label { color: var(--text); font-weight: 500; }
.step-done    .step-label { color: var(--text); }
.step-done    .step-icon  { color: var(--ok); }
.step-failed  .step-label { color: var(--danger); font-weight: 500; }
.step-failed  .step-icon  { color: var(--danger); }
.step-failed  .step-detail { color: var(--danger); }
.step-skipped .step-label { color: var(--text-dim); }
.step-pending .step-icon  { color: var(--border); }

/* A spinner, not a fake progress animation: it says "working", which is true,
   rather than implying a known completion time, which would not be. */
.spinner {
  display: inline-block;
  width: 11px; height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -1px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .progress-bar { transition: none; }
}

.btn-deploy {
  font: inherit; font-size: 12px; font-weight: 500;
  background: var(--surface); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; flex: none; white-space: nowrap;
}
.btn-deploy:hover:not(:disabled) { background: var(--accent-bg); }
.btn-deploy:disabled { opacity: .5; cursor: default; }

/* Confirm dialog */
.dlg {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  max-width: 460px;
  width: calc(100% - 32px);
  font: inherit;
}
.dlg::backdrop { background: rgb(0 0 0 / .4); }
.dlg h2 { margin: 0 0 4px; font-size: 16px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.warn-list { list-style: none; margin: 14px 0 0; padding: 0; }
.warn {
  display: flex; gap: 8px; align-items: baseline;
  font-size: 13px; padding: 8px 10px; margin-bottom: 6px;
  border-radius: 6px;
  background: var(--warn-bg); border: 1px solid var(--warn-brd); color: var(--warn);
}
/* A failing pipeline is not the same kind of news as "no pipeline yet". */
.warn-danger { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }
.warn-icon { flex: none; }

.check-list { list-style: none; margin: 14px 0 0; padding: 0; }
.check {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 13px; padding: 6px 2px;
}
.check-icon {
  flex: none; width: 16px; text-align: center; font-weight: 600;
  line-height: 1.4;
}
.check-pass .check-icon { color: var(--ok); }
.check-fail .check-icon { color: var(--danger); }
.check-skip .check-icon { color: var(--warn); }
.check-body { display: flex; flex-direction: column; min-width: 0; }
.check-label { color: var(--text); }
.check-fail .check-label { color: var(--danger); font-weight: 600; }
.check-detail { font-size: 12px; color: var(--text-dim); }
.check-link { flex: none; text-decoration: none; }

#enroll-qr {
  /* White, not a theme token: a QR code needs light-on-dark contrast to
     scan regardless of the page's own dark mode. */
  display: inline-block; padding: 12px; margin: 12px 0;
  background: #fff; border-radius: 8px;
}
#enroll-qr svg { display: block; width: 220px; height: 220px; }

.token-row { display: flex; align-items: center; gap: 8px; margin: 8px 0 12px; }
.token-code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  word-break: break-all;
  flex: 1;
}
.token-row .icon-btn.copied { color: var(--ok); }
