/* Agent Mailbox. One conversation (/) and the sign-in page (/login).

   "Logbook": the conversation is kept like a ship's log. Every entry is
   a ruled row; who, to whom and when are in small monospace, the words
   in plain sans. On a wide screen the monospace runs down a left column
   and the words down the right. Square corners, black rules, no fills
   except the chosen recipient. Spacing is in steps of 4px. */

:root {
  color-scheme: light;
  --bg: #fff;
  --ink: #141414;
  --muted: #666;         /* 5.7:1 on white */
  --line: #e5e5e5;
  --wash: #f5f5f5;
  --err: #a23b22;

  --n1: #a23b22;         /* brick */
  --n2: #1f6d66;         /* sea green */
  --n3: #86610f;         /* ochre */
  --n4: #3d6590;         /* slate blue */
  --n5: #58702c;         /* moss */

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --edge: 20px;
  --side: 0px;           /* width of the left column on wide screens */
  --measure: 36rem;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-bottom: 12rem; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 var(--edge);
  background: var(--bg);
  color: var(--ink);
  font: 16px/24px var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p { margin: 0; font-size: inherit; font-weight: inherit; }

button, input, textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 0;
  margin: 0;
  padding: 0;
}
button { cursor: pointer; font: 12px/20px var(--mono); }

a { color: inherit; text-decoration-color: #b5b5b5; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.vh {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

#top, #status, #app, .signin main { width: 100%; max-width: calc(var(--side) + var(--measure)); margin-left: auto; margin-right: auto; }

/* -- top -------------------------------------------------------------- */

#top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0 12px;
  border-bottom: 1px solid var(--ink);
  font: 12px/20px var(--mono);
}
#top h1 { font-weight: 700; }
#session button { color: var(--muted); min-height: 44px; margin: -12px 0; padding: 0 0 0 12px; }
#session button:hover, #session button:active { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }

#status { font: 12px/20px var(--mono); color: var(--err); }
#status:not(:empty) { padding-top: 8px; }

/* -- signing in (/login) --------------------------------------------- */

/* The same page, with the first line of the log being the password. */
.signin form { padding: 48px 0 0 var(--side); max-width: calc(var(--side) + 22rem); }
.signin label { display: block; font: 12px/20px var(--mono); color: var(--muted); }
.signin .c-line { margin-top: 4px; }
.signin input[type="password"] {
  flex: 1;
  min-width: 0;
  height: 48px;
  letter-spacing: 0.12em;
}
.signin input[type="password"]:focus { outline: none; }
#login-error { margin-top: 12px; font: 12px/20px var(--mono); color: var(--err); }

/* -- the conversation ------------------------------------------------- */

#app { flex: 1; display: flex; flex-direction: column; }
#timeline { flex: 1; padding: 0 0 32px; }

.empty { padding: 24px 0 0 var(--side); color: var(--muted); }

.day {
  margin-top: 32px;
  padding: 12px 0 0 var(--side);
  border-top: 1px solid var(--ink);
  font: 700 12px/20px var(--mono);
}
.day span { font-weight: 400; color: var(--muted); margin-left: 8px; }
.day:first-child { margin-top: 0; border-top: 0; }

/* An entry. Phone: one monospace line (time, who), then the words.
   Columns are  time | who | Reply. */
.msg {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  column-gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 24px;
}
.day + .msg { border-top: 0; margin-top: 0; }
.msg.cont { margin-top: 4px; padding-top: 0; border-top: 0; }

.m-head { display: contents; }

.m-time {
  grid-column: 1; grid-row: 1;
  font: 12px/20px var(--mono);
  color: var(--muted);
  white-space: nowrap;
}
.m-who {
  grid-column: 2; grid-row: 1;
  font: 12px/20px var(--mono);
  color: var(--muted);
  min-width: 0;
}
.m-from { font-weight: 700; color: var(--muted); }
.msg.mine .m-from { color: var(--ink); }
.msg.c1 .m-from { color: var(--n1); }
.msg.c2 .m-from { color: var(--n2); }
.msg.c3 .m-from { color: var(--n3); }
.msg.c4 .m-from { color: var(--n4); }
.msg.c5 .m-from { color: var(--n5); }

.m-kind::before, .m-state::before { content: "\00b7\00a0"; color: var(--muted); }
.m-state { color: var(--ink); }

.m-reply {
  grid-column: 3; grid-row: 1;
  min-width: 44px; height: 44px;
  margin: -12px 0;
  color: var(--muted);
  text-align: right;
  text-transform: lowercase;
}
.m-reply:hover, .m-reply:active { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }

.quote, .m-body, .refs { grid-column: 1 / -1; min-width: 0; }

.quote {
  display: block;
  margin-top: 4px;
  font: 12px/20px var(--mono);
  color: var(--muted);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quote::before { content: "re  "; }
.quote::before { content: "re  " / ""; }
a.quote:hover { color: var(--ink); }

.m-body {
  margin-top: 4px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.m-body.data { font: 13px/20px var(--mono); margin-top: 6px; }

.refs { margin-top: 4px; font: 12px/20px var(--mono); }
.refs a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 2px 0; }

.msg.cont .m-who,
.msg.cont .m-time {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.msg.cont .quote, .msg.cont .m-body, .msg.cont .refs { grid-column: 1 / 3; }
.msg.cont .m-body { margin-top: 0; }
.msg.cont .m-reply { margin: -10px 0; }

.msg.flash .m-body { background: var(--wash); box-shadow: 0 0 0 4px var(--wash); }

/* -- paused ----------------------------------------------------------- */

#paused {
  margin: 0 0 16px;
  padding: 12px 0 0 var(--side);
  border-top: 1px solid var(--line);
  font: 12px/20px var(--mono);
  color: var(--muted);
}
#resume {
  margin-top: 8px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--ink);
  color: var(--ink);
  font-weight: 700;
}
#resume:hover, #resume:active { background: var(--ink); color: #fff; }

/* -- writing ---------------------------------------------------------- */

#compose {
  position: sticky;
  bottom: 0;
  z-index: 1;
  margin: 0 -4px;
  padding: 0 4px max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
}
#compose::before { content: ""; display: block; height: 1px; background: var(--ink); }
#replying, .c-top, #compose .c-line { margin-left: var(--side); }

#replying {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 36px;
  border-bottom: 1px solid var(--line);
  font: 12px/20px var(--mono);
  color: var(--muted);
}
#replying-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#cancel-reply { min-height: 36px; padding-left: 8px; color: var(--muted); text-transform: lowercase; }
#cancel-reply:hover, #cancel-reply:active { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }

/* Who it goes to. The names are radio buttons; the chosen one is
   printed white on black, the way a terminal shows a selection. */
.c-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; font: 12px/20px var(--mono); color: var(--muted); }
#compose-to { display: flex; align-items: center; min-width: 0; }
#compose-to-label { width: 2ch; margin-right: 4px; }
#compose-to label {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 44px;
  padding: 0 2px;
  cursor: pointer;
}
#compose-to input {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
  appearance: none; -webkit-appearance: none;
}
#compose-to label span { padding: 2px 8px; }
#compose-to label:hover span { color: var(--ink); }
#compose-to label:active span { background: var(--wash); }
#compose-to input:checked + span { background: var(--ink); color: #fff; }
#compose-to input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

.keys { display: none; white-space: nowrap; }

/* The line you write on: a prompt, the words, and the word that sends. */
.c-line {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  transition: border-color 0.12s;
}
.c-line:focus-within { border-bottom-color: var(--ink); }
.prompt { align-self: flex-start; width: 2ch; font: 700 12px/20px var(--mono); color: var(--muted); padding-top: 14px; }
.c-line:focus-within .prompt { color: var(--ink); }
.signin .prompt { display: block; color: var(--muted); }
#compose-body {
  flex: 1;
  min-width: 0;
  height: 48px;
  min-height: 48px;
  max-height: 40vh;
  padding: 12px 0;
  resize: none;
  field-sizing: content;
}
#compose-body::placeholder { color: var(--muted); opacity: 1; }
#compose-body:focus { outline: none; }
@supports not (field-sizing: content) {
  #compose-body:focus:not(:placeholder-shown) { min-height: 96px; }
}
#send, .signin button {
  height: 32px;
  margin: 8px 0;
  padding: 0 12px;
  border: 1px solid var(--ink);
  font-weight: 700;
  text-transform: lowercase;
  white-space: nowrap;
}
#send:hover, .signin button:hover { background: var(--ink); color: #fff; }
#send:active, .signin button:active { background: #444; border-color: #444; color: #fff; }
#compose-body:placeholder-shown + #send { border-color: var(--line); color: var(--muted); background: none; font-weight: 400; }
#send:disabled { border-color: var(--line); color: var(--muted); background: none; cursor: default; }

#compose[aria-busy="true"] #compose-body { color: var(--muted); }
#compose[aria-busy="true"] #send { font-size: 0; }
#compose[aria-busy="true"] #send::after { content: "sending"; font-size: 12px; font-weight: 400; }

/* -- wider than a phone ----------------------------------------------- */

@media (min-width: 720px) {
  :root { --side: 11rem; }

  #top { padding-top: 32px; }

  /* Columns are  time | who | words | Reply; who is stacked: the
     name, then whom it is to under it. */
  .msg {
    grid-template-columns: 3.5rem 7.5rem minmax(0, 1fr) auto;
    column-gap: 0;
    padding-top: 16px;
    margin-top: 16px;
  }
  .msg.cont { margin-top: 8px; padding-top: 0; }
  .m-time, .m-who { grid-row: 1 / span 3; padding-top: 2px; }
  .m-who { padding-right: 16px; }
  .m-from { display: block; }
  .m-kind, .m-state { display: block; }
  .m-kind::before, .m-state::before { content: none; }
  .m-time, .msg.cont .m-time {
    position: static; width: auto; height: auto; margin: 0; overflow: visible; clip: auto; clip-path: none;
    grid-column: 1;
  }
  .quote, .m-body, .refs,
  .msg.cont .quote, .msg.cont .m-body, .msg.cont .refs { grid-column: 3; }
  .quote, .m-body { margin-top: 0; }
  .quote + .m-body { margin-top: 2px; }
  .m-reply { grid-column: 4; min-width: 0; height: 24px; margin: 0; padding-left: 16px; }
  .msg.cont .m-reply { margin: 0; }

  #compose { padding-bottom: 24px; }
  /* "to" and the prompt hang in the margin, so the names and what you
     write start on the same edge as the words above. */
  #compose-to-label, #compose .prompt { margin-left: calc(-2ch - 8px); margin-right: 8px; }
  #compose .c-line { gap: 0; }
  #compose-to label:first-of-type { padding-left: 0; }
  #compose-to label span { margin-left: -8px; }
  #compose-to label:first-of-type span { margin-left: 0; }
  #compose-to label { padding: 0 10px; }
}

@media (min-width: 720px) and (hover: hover) {
  #compose:focus-within .keys { display: inline; }
  .m-reply { opacity: 0; }
  .msg:hover .m-reply, .m-reply:focus-visible { opacity: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
