:root {
  --bg: #f5f1e8;          /* parchment */
  --surface: #ffffff;
  --nav: #1f2937;         /* slate */
  --nav-text: #e5e7eb;
  --border: #e5e0d3;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #0f766e;      /* teal */
  --accent-hover: #115e59;
  --accent-soft: #ccfbf1;
  --danger: #b91c1c;
  --warn: #b45309;
  --info: #1d4ed8;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

.mono, code, pre { font-family: 'JetBrains Mono', ui-monospace, monospace; }

nav {
  background: var(--nav);
  color: var(--nav-text);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 52px;
  box-shadow: 0 1px 0 rgba(0,0,0,.1);
}
nav .brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.2px;
}
nav .links a {
  color: var(--nav-text);
  text-decoration: none;
  font-size: .9rem;
  padding: .35rem .7rem;
  border-radius: 6px;
}
nav .links a:hover, nav .links a.active {
  background: rgba(255,255,255,.08);
  color: #fff;
}
nav .meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .75rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: .75rem;
  color: #9ca3af;
}
nav .meta .user { color: #e5e7eb; }
nav .meta .logout {
  color: #9ca3af;
  text-decoration: none;
  padding: .25rem .55rem;
  border: 1px solid #374151;
  border-radius: 5px;
  /* Also applied to the logout <button> (POST form), which needs the
     browser button chrome stripped to look like the old link. */
  background: none;
  font: inherit;
  cursor: pointer;
}
nav .meta .logout:hover { color: #fff; border-color: #6b7280; text-decoration: none; }

.card.auth { max-width: 28rem; margin: 0 auto; }
.card.auth h1 { margin-bottom: 1rem; }
.card.auth form label { display: block; font-weight: 600; font-size: .85rem; margin: .8rem 0 .35rem; }
.card.auth form input[type="text"],
.card.auth form input[type="password"] {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafaf7;
  font-family: inherit;
  font-size: 1rem;
}
.card.auth form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.card.auth .actions { margin-top: 1.2rem; }
.card.auth p.error {
  background: #fee2e2;
  color: var(--danger);
  padding: .55rem .75rem;
  border-radius: 6px;
  font-size: .9rem;
  margin-bottom: 1rem;
}
.card.auth .qr {
  display: flex;
  justify-content: center;
  background: #fff;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 1rem 0;
}
.card.auth .qr svg { width: 14rem; height: 14rem; }
.totp-secret {
  display: inline-block;
  padding: .15rem .4rem;
  font-size: .85rem;
  letter-spacing: .05em;
  background: #fafaf7;
  border: 1px solid var(--border);
  border-radius: 4px;
  user-select: all;
}

/* Admin page */
.flash {
  padding: .65rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: .9rem;
}
.flash-ok  { background: var(--accent-soft); color: var(--accent-hover); }
.flash-err { background: #fee2e2; color: var(--danger); }

table.admin-users, table.admin-invites { font-size: .85rem; }
table.admin-users td, table.admin-invites td { vertical-align: middle; }
.actions-col { text-align: right; white-space: nowrap; }
.actions-col form.inline { display: inline; margin-left: .35rem; }
button.btn-link {
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-size: .85rem;
  font-weight: 500;
  border: 0;
  cursor: pointer;
}
button.btn-link:hover { color: var(--accent-hover); background: transparent; text-decoration: underline; }
button.btn-link.danger { color: var(--danger); }
button.btn-link.danger:hover { color: #7f1d1d; }

.invite-form {
  display: flex;
  align-items: end;
  gap: .75rem;
  margin: .5rem 0 1rem;
  flex-wrap: wrap;
}
.invite-form label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .8rem;
  color: var(--muted);
  font-weight: 500;
}
.invite-form input {
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafaf7;
  font-family: inherit;
  width: 9rem;
}
.invite-form button { padding: .5rem 1rem; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 1rem 0; }
dl.kv dt { font-weight: 600; color: var(--muted); font-size: .85rem; }
dl.kv dd code.copy-me {
  display: inline-block;
  padding: .25rem .55rem;
  background: #fafaf7;
  border: 1px solid var(--border);
  border-radius: 4px;
  user-select: all;
  word-break: break-all;
  font-size: .9rem;
}

main {
  max-width: 64rem;
  margin: 1.5rem auto;
  padding: 0 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

footer {
  max-width: 64rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
  font-size: .8rem;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--border);
}
footer a { color: var(--muted); text-decoration: underline; text-decoration-color: var(--border); }
footer a:hover { color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
}
.card + .card { margin-top: 0; }

h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: .35rem; }
h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: .75rem; }
p { margin-bottom: .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

form label {
  display: block;
  font-weight: 600;
  font-size: .9rem;
  margin: .9rem 0 .35rem;
}
textarea {
  width: 100%;
  font-family: 'JetBrains Mono', monospace;
  font-size: .9rem;
  padding: .65rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafaf7;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

fieldset.kinds {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .75rem 1rem;
  margin-top: 1rem;
}
fieldset.kinds legend {
  padding: 0 .35rem;
  font-weight: 600;
  font-size: .85rem;
  color: var(--muted);
}
fieldset.kinds label {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  margin: .25rem 0;
  font-weight: 400;
}
fieldset.kinds label em {
  color: var(--muted);
  font-style: normal;
  font-size: .85rem;
}

.actions { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; }
button, .button {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: .55rem 1.2rem;
  font-family: inherit;
  font-size: .95rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover, .button:hover {
  background: var(--accent-hover);
  text-decoration: none;
  color: #fff;
}
.button-secondary {
  background: #e5e7eb;
  color: #374151;
}
.button-secondary:hover { background: #d1d5db; color: #1f2937; }
.button-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}
.button-danger:hover { background: var(--danger); color: #fff; }
.inline-form { display: inline; margin: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); }
th { background: #fafaf7; font-weight: 600; color: #374151; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:hover td { background: #fafaf7; }

.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-family: 'JetBrains Mono', monospace;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  background: #e5e7eb;
  color: #374151;
}
.badge-queued  { background: #e5e7eb;  color: #374151; }
.badge-running {
  background: #fef3c7;
  color: #92400e;
  animation: badge-pulse 1.8s ease-in-out infinite;
}
@keyframes badge-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: .45; }
}
@media (prefers-reduced-motion: reduce) {
  .badge-running { animation: none; }
}
.badge-done    { background: var(--accent-soft); color: var(--accent-hover); }
.badge-failed  { background: #fee2e2;  color: var(--danger); }
.badge-cancelled { background: #e5e7eb; color: #6b7280; }

.job-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.job-head .actions { margin-top: 0; }

a.dl {
  font-weight: 600;
  font-size: .85rem;
}

details.log {
  margin-top: 1rem;
  background: #fafaf7;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .5rem .75rem;
}
details.log[open] { padding-bottom: .75rem; }
details.log summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .85rem;
  color: var(--muted);
}
details.log pre {
  font-size: .8rem;
  white-space: pre-wrap;
  margin-top: .5rem;
  padding: .5rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  max-height: 20rem;
  overflow: auto;
}
details.log.failed pre { border-color: #fecaca; background: #fff5f5; }

/* Inline related-apps card */
.related-card {
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
  background: #fafaf7;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.related-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: .75rem;
  color: #374151;
}
.related-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: .75rem;
}
.related-head h3 { margin-bottom: 0; }
.related-head .button { padding: .35rem .75rem; font-size: .8rem; }
table.related { font-size: .85rem; }
table.related td, table.related th { padding: .35rem .55rem; }
table.related a.dl { font-weight: 600; }
.related-sub {
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #6b7280;
  margin: 0;
}
.related-sub-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0 .35rem;
}
.related-sub-head:first-of-type { margin-top: 0; }
.related-sub-head .button { padding: .3rem .7rem; font-size: .75rem; }

code { background: #fafaf7; padding: 0 .25rem; border-radius: 3px; font-size: .85em; }
