/* The keyboard: the mark on the row it is on, the caps that say which key answers,
   the small notice while a sequence is under way, and the sheet behind "?".
   What the keys do is declared in js/keys.js. */

/* ---- the row the keyboard is on ---- */
/* Unmistakable, in ink: a thick frame, a scribbled arrow in the margin, and on each of its
   controls the key that presses it. The other rows stay as they are. */
.inbox-row { scroll-margin: 72px 0 28px; }
.inbox-row:focus { outline: none; }
.inbox-row.is-current, .inbox-done.is-current { outline: 3px solid var(--fg); outline-offset: 3px; z-index: 1; }
.inbox-row.is-current::before, .inbox-done.is-current::before {
  content: ""; position: absolute; right: calc(100% + 14px); top: 50px; width: 46px; height: 46px; background: var(--fg); pointer-events: none;
  -webkit-mask: var(--keys-arrow) center / contain no-repeat; mask: var(--keys-arrow) center / contain no-repeat;
  animation: keys-point 320ms cubic-bezier(.25, 1.4, .5, 1);
}
:root { --keys-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 46 46' fill='none' stroke='%23000' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 25c9-3.500 19-1 33-3.200'/%3E%3Cpath d='M27.500 11.500c3.800 4.200 6.800 7.300 11.500 10-4.600 2.600-8.300 6.700-10.800 12.500'/%3E%3C/svg%3E"); }
@keyframes keys-point { from { translate: -14px 0; opacity: 0; } }
/* No margin to point from: a narrow window, or a list inside a session's column. */
/* An answered row is slim: the arrow stands at its middle. */
.inbox-done.is-current::before { top: 7px; }
@media (max-width: 1180px) { .inbox-row.is-current::before, .inbox-done.is-current::before { display: none; } }
.pane-list .inbox-row.is-current::before { display: none; }

/* A key cap: paper, a line, a little weight below. */
.keys-sheet kbd, .keys-pending kbd, .inbox-row.is-current [data-cap]::after, .inbox-done.is-current [data-cap]::after {
  display: inline-block; min-width: 24px; padding: 5px 7px; border-radius: 6px; background: var(--surface); color: var(--fg);
  box-shadow: 0 0 0 1px var(--line-strong), 0 2px 0 var(--line-strong);
  font: 500 .74rem/1 var(--mono); letter-spacing: 0; text-align: center; text-transform: none; white-space: nowrap;
}
/* On the marked row every control wears its key, so the next move needs no legend. */
.inbox-row.is-current .inbox-answer { position: relative; }
.inbox-row.is-current [data-cap]::after { content: attr(data-cap); position: absolute; top: 7px; right: 7px; rotate: 3deg; }
.inbox-done.is-current [data-cap]::after { content: attr(data-cap); margin-left: 8px; min-width: 20px; padding: 3px 5px; box-shadow: 0 0 0 1px var(--line-strong); }
.inbox-row.is-current .inbox-later[data-cap]::after { position: static; margin-left: 7px; rotate: 0deg; min-width: 20px; padding: 3px 5px; box-shadow: 0 0 0 1px var(--line-strong); }
/* A finger has no keys. */
@media (pointer: coarse) { .inbox-row.is-current [data-cap]::after, .inbox-done.is-current [data-cap]::after { content: none; } }
/* The option the arrows are on, among the choices of the marked row. */

/* ---- a sequence under way: "g", then where to ---- */
.keys-pending {
  position: fixed; z-index: 60; left: 50%; bottom: 76px; translate: -50% 0; max-width: calc(100vw - 2 * var(--s-4));
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-4); padding: 10px var(--s-4);
  border-radius: var(--r-md); background: var(--fg); color: var(--bg); box-shadow: var(--shadow-lg);
  font: 600 var(--t-xs)/1 var(--font); letter-spacing: .07em; text-transform: uppercase;
  animation: keys-rise 140ms ease-out;
}
.keys-pending[hidden] { display: none; }
.keys-pending span { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.keys-pending > kbd:first-child { margin-right: var(--s-1); }
.keys-pending kbd { box-shadow: none; }
@keyframes keys-rise { from { translate: -50% 8px; opacity: 0; } }
/* While "g" waits, the sessions in the sidebar show their numbers. */
body[data-keys="g"] #agents { counter-reset: place; }
body[data-keys="g"] .agent-row[data-unit] { counter-increment: place; position: relative; }
body[data-keys="g"] .agent-row[data-unit]:nth-of-type(-n+10)::before {
  content: counter(place); position: absolute; z-index: 2; left: 2px; top: 2px; min-width: 20px; padding: 4px 5px; border-radius: 6px;
  background: var(--fg); color: var(--bg); font: 500 .72rem/1 var(--mono); text-align: center; pointer-events: none;
}

/* ---- the sheet behind "?" ---- */
.keys-sheet {
  width: min(760px, calc(100vw - 2 * var(--s-4))); max-height: min(86vh, 860px); margin: auto; padding: var(--s-6) var(--s-8) var(--s-6);
  border: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--fg); box-shadow: var(--shadow-lg); overflow-y: auto;
}
/* No veil over the page: the sheet lies on it with a line and a shadow; Escape, "?" or a click beside it closes. */
.keys-sheet { box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-lg); }
.keys-sheet::backdrop { background: transparent; }
.keys-sheet header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-5); }
.keys-sheet h2 { font: 800 2rem/1.05 var(--display); letter-spacing: -.02em; }
.keys-close { display: inline-flex; align-items: center; gap: var(--s-2); min-height: 36px; padding: 0 var(--s-3); border: 0; border-radius: var(--r-pill); background: none; color: var(--muted); font-weight: 600; font-size: var(--t-sm); }
.keys-close:hover { background: var(--sunken); color: var(--fg); }
.keys-groups { columns: 2 300px; column-gap: var(--s-10); }
.keys-groups section { break-inside: avoid; margin-bottom: var(--s-6); }
/* The heading is the divider, as for the senders in the inbox. */
.keys-sheet h3 { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); font: 600 var(--t-xs)/1 var(--font); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.keys-sheet h3::after { content: ""; flex: 1; border-top: 1px solid var(--line-strong); }
.keys-sheet dl { display: grid; gap: 9px; }
.keys-sheet dl > div { display: grid; grid-template-columns: 7rem minmax(0, 1fr); align-items: baseline; gap: var(--s-3); }
.keys-sheet dt { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.keys-sheet dd { font-size: var(--t-sm); line-height: 1.35; color: var(--fg); }
.keys-caps { display: inline-flex; align-items: center; gap: 4px; }
.keys-sheet dt i { font: 500 .68rem/1 var(--font); font-style: normal; color: var(--faint); }
.keys-foot { margin-top: var(--s-2); padding-top: var(--s-4); border-top: 1px dashed var(--line-strong); font-size: var(--t-sm); color: var(--muted); }
@media (max-width: 700px) { .keys-sheet { padding: var(--s-5); } }

/* In a pair, the column the keyboard is on (P moves it) carries a rule under its name. */
body[data-pair] .chat-pane.is-member .chat-pane-head { box-shadow: inset 0 -2px 0 var(--fg); }

@media (prefers-reduced-motion: reduce) { .inbox-row.is-current::before, .keys-pending { animation: none; } }

/* Every stop of the Tab key shows a ring, the Snooze tab of a row included. */
.inbox-later:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
