/* Maity dashboard. Light and dark through prefers-color-scheme; every
   colour is a token on :root. */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #eef0f2;
  --text: #1d2125;
  --muted: #5e6670;
  --border: #d5d9de;
  --accent: #1a66d9; /* 4.96:1 on --bg, 5.32:1 on --surface (WCAG AA) */
  --accent-text: #ffffff;
  --high: #b42318;
  --normal: #8a5a00;
  --low: #4a5a6a;
  --ok: #1a7f37;
  --warn: #9a6700;
  --bad: #b42318;
  --flag-bg: #fff6dd;
  --error-bg: #fde8e7;
  --out-bg: #dbe9ff;
  --radius: 8px;
  --gap: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1f24;
    --surface-2: #232a31;
    --text: #e6e9ec;
    --muted: #9aa4ae;
    --border: #333c45;
    --accent: #4c8dff;
    --accent-text: #0b0f14;
    --high: #ff7b72;
    --normal: #e3b341;
    --low: #9aa4ae;
    --ok: #3fb950;
    --warn: #d29922;
    --bad: #ff7b72;
    --flag-bg: #2d2610;
    --error-bg: #3a1716;
    --out-bg: #1b3050;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}

a { color: var(--accent); }

h2 { font-size: 1.25rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 4px 0; }
h4, h3.sub { font-size: 0.85rem; margin: 12px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

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

.muted { color: var(--muted); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

button, select, textarea, input {
  font: inherit;
  color: inherit;
  max-width: 100%;
}

button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: default; }
button.danger { color: var(--bad); }

select, textarea, input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
}

textarea { width: 100%; resize: vertical; }
input { min-width: 0; }
button.small { padding: 2px 8px; font-size: 0.82rem; }

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

/* ---- shell ---------------------------------------------------------- */

#header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px var(--gap) 0;
  position: sticky;
  top: 0;
  z-index: 1;
}

.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* The page's one h1: the product name, at the size of the header line. */
.brand { font-weight: 700; font-size: inherit; margin: 0; }
.me { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.88rem; }
.project { color: var(--muted); }

.state, .source, .badge, .prio, .kind, .presence, .count {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid currentColor;
  white-space: nowrap;
}

.state-build { color: var(--accent); }
.state-freeze, .state-fixes-only { color: var(--warn); }
.state-accepted { color: var(--ok); }
.state-archived { color: var(--muted); }
.source { color: var(--warn); border-style: dashed; }

.state-note { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }

nav { display: flex; gap: 4px; overflow-x: auto; margin-top: 8px; }
/* Set by app.js when a row is wider than the screen: fade the cut-off side. */
nav.more-after { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); }
nav.more-before { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent); }
nav.more-before.more-after { -webkit-mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, transparent, #000 32px, #000 calc(100% - 32px), transparent); }

nav a {
  padding: 8px 10px;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

nav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }
nav .count { margin-left: 6px; color: var(--accent); }

/* The project switcher: always visible, one chip per project. */
.switcher { gap: 6px; padding-bottom: 2px; }

.switcher a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.88rem;
}

.switcher a[aria-current="page"] { border-color: var(--accent); background: var(--surface-2); }
.switcher .count { margin-left: 0; }

.dot.state-dot-build { background: var(--accent); }
.dot.state-dot-freeze, .dot.state-dot-fixes-only { background: var(--warn); }
.dot.state-dot-accepted { background: var(--ok); }
.dot.state-dot-archived { background: var(--muted); }

main { padding: var(--gap); max-width: 1200px; margin: 0 auto; }

.error {
  background: var(--error-bg);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  padding: 12px;
}

.error p { margin: 4px 0 0; }

.flag {
  background: var(--flag-bg);
  border-left: 3px solid var(--warn);
  padding: 6px 10px;
  border-radius: 4px;
}

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar h2 { margin: 0 auto 0 0; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 8px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.send-status { min-height: 1.2em; margin: 6px 0 0; color: var(--muted); }
.send-status.failed { color: var(--bad); }

/* ---- inbox ---------------------------------------------------------- */

.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.entry.current { border-color: var(--accent); }
.entry.done { opacity: 0.75; }
.entry.empty, .empty { padding: 16px; color: var(--muted); list-style: none; }
.first-hint { max-width: 40rem; margin: 6px 0 12px; font-size: 0.88rem; color: var(--muted); }

.entry-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 12px;
}

.entry-head .title { font-weight: 600; flex: 1 1 16rem; }

/* Agent-written tokens (paths, hashes, URLs) can be long and unbroken. */
.entry-head .title, .entry-body, .card, .profile, .msg, .org-node, .joins li { overflow-wrap: anywhere; min-width: 0; }
.entry-head .meta { color: var(--muted); font-size: 0.85rem; }

.project-label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; font-weight: 600; }

.prio-high { color: var(--high); }
.prio-normal { color: var(--normal); }
.prio-low { color: var(--low); }
.kind { color: var(--muted); font-weight: 400; }

.entry-body { padding: 0 12px 12px; border-top: 1px solid var(--border); }
.summary { margin: 8px 0; }
.options { margin: 0; padding-left: 20px; }
.answered { color: var(--ok); }

.replies { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.reply { min-width: 5rem; }
.reply.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.reply.talk { border-style: dashed; }

.free-text { margin-top: 12px; display: grid; gap: 6px; }
.free-text label { font-size: 0.85rem; color: var(--muted); }
.free-text button { justify-self: start; }
.chat-link { margin: 10px 0 0; }

/* ---- board ---------------------------------------------------------- */

.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--gap);
  align-items: start;
}

.column { display: grid; gap: 8px; }
.column-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); }

.card, .profile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-width: 0;
}

.card header, .profile header { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.card-id, .handle { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.request-id { white-space: nowrap; }
.area, .label-tag { font-family: var(--mono); font-size: 0.8rem; background: var(--surface-2); border-radius: 4px; padding: 0 6px; }
.card-release { border-left: 3px solid var(--accent); }
.badge.release { color: var(--accent); }
.badge.contract { color: var(--warn); }
.badge.maintenance_round { color: var(--muted); }
.expired { color: var(--bad); }
.checkpoint, .report { margin-top: 6px; font-size: 0.88rem; }
.checkpoint p, .report p { margin: 2px 0; }
.report.mismatch { border-left: 3px solid var(--bad); padding-left: 6px; }
.checklist { list-style: none; margin: 6px 0 0; padding: 0; font-size: 0.88rem; }
.checklist .met { color: var(--ok); }
.checklist .unmet { color: var(--warn); }

.claim { margin: 4px 0; font-size: 0.9rem; }
.claim.unclaimed { color: var(--muted); }
.lease { color: var(--muted); }

.deps .label { font-size: 0.8rem; color: var(--muted); }
.deps ul { margin: 2px 0 0; padding-left: 18px; font-size: 0.88rem; }
.deps .met { color: var(--ok); }
.deps .unmet { color: var(--warn); }

.prs { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 8px; display: block; overflow-x: auto; }
.prs th, .prs td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--border); }
.pr-merged, .checks-success { color: var(--ok); }
.pr-open, .checks-pending { color: var(--warn); }
.pr-closed, .checks-failure, .pr-missing { color: var(--bad); }
.pr-unverified { color: var(--muted); font-style: italic; }
/* The card wraps anywhere; the PR table's words and headers do not. */
.prs th, .prs td { overflow-wrap: normal; }
.prs td:first-child { overflow-wrap: break-word; }
.groups .unknown { color: var(--muted); }
.release-edit { margin-top: 6px; }
.release-edit .row, .rows-form .row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.checklist.editable li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px; }
.checklist.editable label { color: inherit; }
.rows-form h4 { margin: 6px 0 4px; }
.edit-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.edit-rows li { display: flex; align-items: center; gap: 6px; min-width: 0; }
.edit-rows input.item-text { flex: 1 1 auto; min-width: 0; }
.edit-rows input.pr-number { width: 6rem; }

.readiness { margin-top: 8px; font-size: 0.88rem; }
.readiness.ready { color: var(--ok); }
.readiness.not-ready { color: var(--warn); }
.readiness ul { margin: 4px 0 0; padding-left: 18px; }

/* ---- agents --------------------------------------------------------- */

.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--gap); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.online { background: var(--ok); }
.dot.away { background: var(--warn); opacity: 0.6; }
.dot.paused { background: var(--warn); }
.dot.human { background: var(--accent); }

.presence.online { color: var(--ok); }
.presence.away { color: var(--warn); }
.presence.paused { color: var(--warn); }
.presence.offline { color: var(--muted); }

.credentials ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.credentials li { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; }
.credential-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.credentials button { margin-left: auto; padding: 2px 10px; flex: none; white-space: nowrap; }
.credentials .revoked { color: var(--muted); }
.credentials .never { color: var(--warn); }

.pause { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.pause input { flex: 1 1 10rem; }
.pause .hint { flex: 1 1 100%; }
.hint { margin: 0; font-size: 0.8rem; color: var(--muted); }
.flag .hint { display: block; margin-top: 4px; }
.briefing { margin-top: 10px; }
.inline-form label.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
.signing-impact ul { margin: 4px 0; padding-left: 18px; }
.briefing h4 { margin: 0 0 4px; }
.briefing .pre { margin: 0 0 6px; max-height: 12rem; overflow: auto; }
.briefing-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.briefing-form label { font-size: 0.85rem; color: var(--muted); }
.briefing-form .row { display: flex; gap: 6px; }

/* ---- organisation --------------------------------------------------- */

.org-tree, .org-tree ul { list-style: none; margin: 0; padding-left: 0; }
.org-tree ul { padding-left: 20px; border-left: 1px solid var(--border); margin-left: 4px; }
.org-node { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 0; }
.role { color: var(--muted); }

/* ---- chat ----------------------------------------------------------- */

.chat-picker { padding-left: 20px; }

.messages { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }

.msg {
  max-width: min(36rem, 90%);
  padding: 8px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.msg p { margin: 0; }
.msg.out { justify-self: end; background: var(--out-bg); }
.msg .meta { display: block; margin-top: 4px; font-size: 0.78rem; color: var(--muted); }

.compose { display: grid; gap: 6px; }
.compose label { font-size: 0.85rem; color: var(--muted); }
.compose button { justify-self: start; }

.absence { margin: 6px 0 0; font-size: 0.88rem; }

.panel { display: grid; gap: 12px; margin: 8px 0; padding: 10px; background: var(--surface-2); border-radius: var(--radius); }
/* minmax(0, 1fr): a select is as wide as its longest option otherwise, and
   "Agent Name (@handle) · already a member" pushed the page past 390 px. */
.inline-form, .login, .join-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; max-width: 32rem; }
.inline-form h3 { margin: 0; }
.inline-form label, .login label, .join-form label, .new-agent label { font-size: 0.85rem; color: var(--muted); }
.inline-form button, .login button, .join-form button { justify-self: start; }
.new-agent { display: grid; gap: 6px; }
.new-agent[hidden] { display: none; }
.login { margin: 10vh auto 0; }

.join-result { margin: 12px 0; }
.join-result button + button { margin-left: 6px; }
.paste-line { display: block; padding: 8px; background: var(--surface); border-radius: 4px; overflow-wrap: anywhere; user-select: all; }
.joins { list-style: none; padding: 0; display: grid; gap: 6px; }
.joins li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.joins button { margin-left: auto; padding: 2px 10px; flex: none; white-space: nowrap; }
.project-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; max-width: 32rem; }
.project-form label { font-size: 0.85rem; color: var(--muted); }
.project-form label.check { display: flex; align-items: center; gap: 6px; color: var(--text); margin-top: 6px; }
.project-form button { justify-self: start; margin-top: 6px; }
.field-error { margin: 0; font-size: 0.85rem; color: var(--bad); }
.field-error:empty { display: none; }
.me .small-link { font-size: 0.82rem; margin: 0 4px; }
.send-status .ok { color: var(--ok); }
[aria-invalid="true"] { border-color: var(--bad); }
.empty-state { max-width: 32rem; margin: 8vh auto 0; }
a.button { display: inline-block; padding: 6px 14px; border-radius: var(--radius); background: var(--accent); color: var(--accent-text); text-decoration: none; }
.switcher .new-project { color: var(--muted); }
.reply.later { color: var(--muted); }
.notice:empty { display: none; }

/* ---- phone width ---------------------------------------------------- */

@media (max-width: 600px) {
  main { padding: 12px; }
  .toolbar h2 { flex-basis: 100%; }
  .profiles { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { margin-top: 4px; }
  .reply { flex: 1 1 40%; }
}
