:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #d52b1e;   /* Swiss red */
  --panel: #fafafa;
  --ok: #15803d;
  --warn: #b45309;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --fg: #e8e8e8;
    --muted: #9ca3af;
    --line: #2a2e35;
    --panel: #1a1d22;
    --ok: #4ade80;
    --warn: #fbbf24;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; letter-spacing: -.01em; font-size: 1.25rem; }
.brand::before {
  content: "";
  display: inline-block;
  width: .6rem; height: .6rem;
  margin-right: .5rem;
  background: var(--accent);
  border-radius: 2px;
}
.env { color: var(--muted); font-size: .8rem; text-transform: uppercase; }

/* Nav mirrors the three layers of the data model, so the app is navigated the
   way it is designed: compose, author, inspect. */
.nav { display: flex; gap: .25rem; margin-left: auto; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: .85rem;
  padding: .25rem .6rem;
  border-radius: 4px;
}
.nav a:hover { color: var(--fg); background: var(--panel); }
.nav a.on { color: var(--fg); background: var(--panel); font-weight: 600; }

main { padding: 1.5rem; max-width: 960px; }

h1 { font-size: 1.25rem; margin: 0 0 .25rem; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
h3 { font-size: .9rem; margin: 0 0 .5rem; }

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-head .grow { flex: 1; min-width: 0; }
.lede { color: var(--muted); font-size: .875rem; margin: 0; max-width: 60ch; }

.back {
  display: inline-block;
  color: var(--muted);
  text-decoration: none;
  font-size: .8rem;
  margin-bottom: .5rem;
}
.back:hover { color: var(--fg); }

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: .6rem .5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}

td.id, th.id { width: 4rem; color: var(--muted); font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions, th.actions { width: 1%; white-space: nowrap; text-align: right; }

td.avatar, th.avatar { width: 3rem; }
td.chips { color: var(--muted); }
.chip {
  display: inline-block;
  margin: .1rem .25rem .1rem 0;
  padding: .1rem .45rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: .8rem;
  white-space: nowrap;
}
td.avatar img {
  display: block;
  width: 2.25rem; height: 2.25rem;
  border-radius: 50%;
  background: var(--line);   /* holds the row's height if the file 404s */
}

tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--panel); }

/* --- agents table (dashboard) -------------------------------------------- */
/* The landing table is the first thing you see, so it gets a card-like frame:
   a rounded border around the whole thing, a tinted header row, and gentle
   zebra striping so a long roster stays easy to scan. Scoped to #agents so the
   plainer tables elsewhere keep their look. */

#agents {
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
#agents th, #agents td {
  padding: .7rem .75rem;
  border-bottom: 1px solid var(--line);
}
#agents thead th { background: var(--panel); }
#agents tbody tr:last-child td { border-bottom: none; }
#agents tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--panel) 55%, transparent);
}
#agents tbody tr.clickable:hover td { background: var(--panel); }

.placeholder td { color: var(--muted); }
.placeholder.error td { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .8rem; }

/* --- buttons ------------------------------------------------------------- */

button {
  font: inherit;
  font-size: .85rem;
  padding: .35rem .75rem;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
button:hover { background: var(--panel); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--fg); }
button.danger { color: var(--accent); }
button.tiny { font-size: .75rem; padding: .15rem .45rem; }

/* --- sections and cards -------------------------------------------------- */

section.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
  background: var(--bg);
}
section.card > header {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: .75rem;
}
section.card > header .grow { flex: 1; min-width: 0; }
section.card > header h2 { margin: 0; }
section.card > header .note { color: var(--muted); font-size: .8rem; }

.empty {
  color: var(--muted);
  font-size: .875rem;
  padding: .75rem 0;
}

/* --- forms --------------------------------------------------------------- */

.field { display: block; margin-bottom: .85rem; }
.field-label {
  display: block;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: .25rem;
}
.hint { display: block; font-size: .78rem; color: var(--muted); margin-top: .25rem; }

input[type=text], input[type=number], input:not([type]), textarea, select {
  width: 100%;
  font: inherit;
  font-size: .9rem;
  padding: .4rem .55rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  color: var(--fg);
}
textarea { resize: vertical; min-height: 4.5rem; line-height: 1.55; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.row { display: flex; gap: .75rem; }
.row > * { flex: 1; min-width: 0; }

.checklist {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .6rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .5rem .6rem;
  max-height: 11rem;
  overflow-y: auto;
}
.check { display: flex; align-items: center; gap: .35rem; font-size: .85rem; }
.check input { margin: 0; }

/* --- dialog -------------------------------------------------------------- */

dialog.editor {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  padding: 0;
  width: min(34rem, calc(100vw - 2rem));
}
dialog.editor::backdrop { background: rgba(0, 0, 0, .45); }
dialog.editor form { padding: 1.1rem 1.25rem 1rem; }
dialog.editor h2 { margin: 0 0 1rem; }
dialog.editor menu {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin: 1rem 0 0;
  padding: 0;
}
.dialog-error {
  color: var(--accent);
  font-size: .85rem;
  margin: .5rem 0 0;
}

/* --- toasts -------------------------------------------------------------- */

.toasts {
  position: fixed;
  bottom: 1rem; right: 1rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
  z-index: 50;
}
.toast {
  background: var(--fg);
  color: var(--bg);
  font-size: .85rem;
  padding: .5rem .8rem;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .18);
  transition: opacity .35s, transform .35s;
}
.toast.error { background: var(--accent); color: #fff; }
.toast.out { opacity: 0; transform: translateY(.35rem); }

/* --- badges -------------------------------------------------------------- */

.badge {
  display: inline-block;
  font-size: .72rem;
  padding: .05rem .4rem;
  border-radius: 4px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.risk-high { color: var(--accent); border-color: currentColor; }
.badge.risk-medium { color: var(--warn); border-color: currentColor; }
.badge.risk-low { color: var(--muted); }

/* A proposed grant must not look like an approved one at a glance - the whole
   safety model rests on that difference being visible. */
tr.proposed td { background: color-mix(in srgb, var(--warn) 7%, transparent); }

code.hash {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem;
  color: var(--muted);
}


/* --- account menu -------------------------------------------------------- */

.account { margin-left: .75rem; }
.account-menu { position: relative; }
.account-menu summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .85rem;
  padding: .25rem .6rem;
  border-radius: 4px;
  color: var(--muted);
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary:hover { background: var(--panel); color: var(--fg); }
.account-menu[open] summary { background: var(--panel); color: var(--fg); }
.account-menu .who { max-width: 14rem; overflow: hidden; text-overflow: ellipsis; }

.account-panel {
  position: absolute;
  right: 0;
  top: calc(100% + .35rem);
  min-width: 15rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .12);
  z-index: 40;
}
.account-panel .field { margin-bottom: .6rem; }
.account-link {
  display: block;
  padding: .3rem 0;
  font-size: .85rem;
  color: var(--fg);
  text-decoration: none;
  border-top: 1px solid var(--line);
}
.account-link:hover { color: var(--accent); }

/* --- sign in ------------------------------------------------------------- */

.signin { max-width: 22rem; margin: 3rem auto; }
.signin h1 { margin-bottom: .25rem; }
.signin .lede { margin-bottom: 1.5rem; }
.signin button { width: 100%; margin-top: .5rem; }
.signin .hint { margin-top: 1.5rem; }

/* --- one-time secret ----------------------------------------------------- */

textarea.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .8rem;
  word-break: break-all;
}
pre.snippet {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .6rem .7rem;
  font-size: .75rem;
  overflow-x: auto;      /* the page itself must never scroll sideways */
  margin: .25rem 0 0;
}

/* --- connection status ---------------------------------------------------- */
/* A read-only pair list for facts a form cannot edit: the accountId Jira
   returned, and the reference the credential was stored under. Monospaced
   because both are identifiers that get compared character by character. */

dl.kv {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: .25rem .75rem;
  margin: 0 0 1rem;
  font-size: .8rem;
}
dl.kv dt { color: var(--muted); }
dl.kv dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;   /* a secret reference is long and must not widen the page */
}
