:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1c2128;
  --muted: #5d6673;
  --border: #d8dde3;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --ok-bg: #e6f4ea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --bad: #c62828;
  --bad-bg: #fdecea;
  --radius: 12px;
  --bubble-theirs: #e9ecef;
  --bubble-mine: #1f6feb;
  --bubble-mine-text: #ffffff;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #181c22;
    --text: #e6e9ed;
    --muted: #9aa4b1;
    --border: #2d333b;
    --accent: #4c8dff;
    --ok: #57c26f;
    --ok-bg: #16281c;
    --warn: #e3b341;
    --warn-bg: #2b2412;
    --bad: #ff7b72;
    --bad-bg: #2d1717;
    --bubble-theirs: #262c35;
    --bubble-mine: #2f6fe0;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
}

#who { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }

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

h1 { font-size: 24px; margin: 0 0 8px; }
h2 { font-size: 18px; margin: 24px 0 8px; }
h3 { font-size: 16px; margin: 0 0 4px; }
p { margin: 8px 0; }

.muted { color: var(--muted); }
.small { font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }

button, .button {
  font: inherit;
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  min-height: 40px;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--bad); }
button.link { border: none; background: none; padding: 0 4px; min-height: 0; color: var(--accent); }
button:disabled { opacity: 0.55; cursor: progress; }

input[type=text], textarea, select {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
textarea { min-height: 120px; resize: vertical; }
label { display: block; font-size: 14px; color: var(--muted); margin-top: 8px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.tabs button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  padding: 8px 12px;
  color: var(--muted);
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.count {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
}

.content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0 0;
  font: 15px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  max-height: 360px;
  overflow: auto;
}

.badge { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 999px; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }

.notice { padding: 10px 12px; border-radius: 8px; margin-top: 8px; font-size: 14px; }
.notice.ok { color: var(--ok); background: var(--ok-bg); }
.notice.warn { color: var(--warn); background: var(--warn-bg); }
.notice.bad { color: var(--bad); background: var(--bad-bg); }

code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; overflow-wrap: anywhere; }
.copybox { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.copybox code { flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

details > summary { cursor: pointer; }
/* Conversations, as a chat: the other person on the left, you on the right. */
.thread > summary { list-style: none; }
.thread > summary::-webkit-details-marker { display: none; }
.chat-preview { font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); }
.chat-day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.bubble-row { display: flex; flex-direction: column; max-width: 82%; margin-bottom: 8px; }
.bubble-row.mine { align-self: flex-end; align-items: flex-end; }
.bubble-row.theirs { align-self: flex-start; align-items: flex-start; }
.bubble { padding: 8px 12px; border-radius: 18px; max-width: 100%; overflow-wrap: anywhere; }
.mine .bubble { background: var(--bubble-mine); color: var(--bubble-mine-text); border-bottom-right-radius: 6px; }
.theirs .bubble { background: var(--bubble-theirs); color: var(--text); border-bottom-left-radius: 6px; }
.mine .bubble.draft { background: transparent; color: var(--text); border: 1.5px dashed var(--accent); }
.bubble.unsent { opacity: 0.55; }
.bubble .content { margin: 0; padding: 0; border: 0; background: none; max-height: none; overflow: visible; color: inherit; }
.bubble pre.content { font-size: 13px; }
.bubble .md code, .bubble .md pre.md-code { background: rgb(0 0 0 / 0.12); border-color: rgb(0 0 0 / 0.12); }
.mine .bubble:not(.draft) .md a, .mine .bubble:not(.draft) .md .md-url, .mine .bubble:not(.draft) .md blockquote { color: inherit; }
.mine .bubble:not(.draft) .md a { text-decoration: underline; }
.mine .bubble:not(.draft) .md blockquote { border-left-color: rgb(255 255 255 / 0.5); opacity: 0.9; }
.mine .bubble:not(.draft) .invis { color: var(--warn); }
.bubble-meta { font-size: 12px; color: var(--muted); margin-top: 3px; padding: 0 6px; }
.bubble-meta button.link { font-size: 12px; padding: 0; }
.st-ok { color: var(--ok); }
.st-warn { color: var(--warn); }
.st-bad { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); color: #fff; }

/* An invisible character, shown so the person approving sees it. */
.invis {
  display: inline-block;
  margin: 0 1px;
  padding: 0 3px;
  border-radius: 4px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--warn);
  background: var(--warn-bg);
}
.hints { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.hints li { font-size: 13px; padding: 6px 10px; border-radius: 8px; overflow-wrap: anywhere; }
.hints li.info { color: var(--muted); }
.hints li.warn { color: var(--warn); background: var(--warn-bg); }
.hints li.bad { color: var(--bad); background: var(--bad-bg); }
.dest { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }

dialog.modal {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  padding: 20px;
}
dialog.modal::backdrop { background: rgb(0 0 0 / 0.5); }
dialog.modal h2 { margin-top: 0; }
dialog.modal .copybox code { overflow-wrap: anywhere; }

/* Formatted (Markdown) message content. */
div.content { padding: 10px 14px; white-space: normal; font-family: inherit; font-size: 15px; line-height: 1.55; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md .md-codeblock, .md .md-table { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; }
.md .md-h { margin: 14px 0 6px; line-height: 1.3; }
.md h3.md-h { font-size: 17px; }
.md h4.md-h { font-size: 15px; }
.md h5.md-h, .md h6.md-h { font-size: 14px; }
.md code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.md pre.md-code { margin: 0; padding: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; white-space: pre; }
.md pre.md-code code { padding: 0; background: none; }
.md .md-lang { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.md blockquote { margin-left: 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 12px 0; }
.md .md-table { overflow-x: auto; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.md a { color: var(--accent); }
.md .md-url { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.row.tight { gap: 8px; margin: 0; }

/* Messages waiting for you, actionable in the conversation: full width, with
   the gate's controls under the bubble. */
.bubble-row.pending { align-self: stretch; max-width: 100%; align-items: stretch; margin: 6px 0 14px; }
.bubble-row.mine.pending .bubble-meta { text-align: right; }
.bubble-row.pending .bubble { max-width: 100%; }
.bubble-row.pending .bubble textarea { width: 100%; margin: 0; background: var(--card); }
.bubble-row.pending .notice { margin: 4px 0; }
.bubble-row.pending .row { margin-top: 6px; }
.bubble-row.pending label { margin-top: 6px; }
.pending-label { font-size: 13px; font-weight: 600; color: var(--warn); margin-bottom: 2px; }
.bubble-row.mine.pending .pending-label, .bubble-row.mine.pending .pending-note { text-align: right; }
.pending-note { margin: 0 0 4px; }
.thread > summary .badge { font-size: 12px; padding: 1px 7px; vertical-align: 1px; }
.bubble-meta button.link + button.link { margin-left: 10px; }

/* An open conversation fits the window (fitChat sets the height); its
   messages scroll inside it. */
.thread { scroll-margin-top: 64px; }
.thread .chat { overflow-y: auto; overscroll-behavior: contain; max-height: calc(100dvh - 200px); padding-right: 4px; }
.auto-approve { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); }
.auto-approve h4 { margin: 0 0 6px; font-size: 15px; }
dialog.modal ul { padding-left: 20px; }
dialog.modal li { margin-bottom: 6px; }
.thread > summary .notice.unreviewed { margin: 8px 0 0; font-size: 13px; }
