/* Audit log (web/audit.mjs), shown in Info › Audit log (adaptive.css puts it in the sheet).
 * DESIGN.md: rows with hairline separators, caption column heads, data in Plex Mono, a quiet
 * disclosure button in sentence case, and a plain empty state. audit.mjs writes some labels
 * in capitals or lower case ("AUDIT", "no entries"); the ::first-letter rules below show them
 * in sentence case without touching the module.
 * Tokens: --cx-* with DESIGN.md fallbacks; body.nvg re-points them (theme.css palette). */

body {
  --pb-panel: var(--cx-panel, #1c2127);
  --pb-hover: var(--cx-hover, #2f343c);
  --pb-line: var(--cx-line, rgba(255, 255, 255, .10));
  --pb-line-hi: var(--cx-line-hi, rgba(255, 255, 255, .22));
  --pb-ink: var(--cx-ink, #f6f7f9);
  --pb-dim: var(--cx-dim, #abb3bf);
  --pb-mute: var(--cx-mute, #8f99a8);
  --pb-focus: var(--cx-focus, #4c90f0);
  --pb-ok: var(--cx-ok, #32a467);
  --pb-bad: var(--cx-bad, #e76a6e);
  --pb-font: var(--cx-font, "Public Sans", system-ui, sans-serif);
  --pb-mono: var(--cx-mono, "IBM Plex Mono", ui-monospace, monospace);
  --pb-r: var(--cx-r, 2px);
  --pb-shadow: var(--cx-shadow, 0 6px 20px rgba(0, 0, 0, .45));
}
body.nvg {
  --pb-panel: var(--cx-panel, var(--panel)); --pb-raised: var(--cx-raised, var(--panel-2)); --pb-hover: var(--cx-hover, var(--hover));
  --pb-line: var(--cx-line, var(--line)); --pb-line-hi: var(--cx-line-hi, var(--line-hi));
  --pb-ink: var(--cx-ink, var(--text)); --pb-dim: var(--cx-dim, var(--dim)); --pb-mute: var(--cx-mute, var(--mute));
  --pb-sel: var(--cx-select, var(--hi)); --pb-sel-ink: var(--cx-select-ink, var(--hi-ink)); --pb-focus: var(--cx-focus, var(--hi));
  --pb-ok: var(--cx-ok, var(--ok)); --pb-warn: var(--cx-warn, var(--warn)); --pb-bad: var(--cx-bad, var(--bad));
  --pb-field: #000; --pb-shadow: none;
}

/* Floating corner panel when mounted outside Info (classic layout). */
.aud {
  position: fixed;
  z-index: 28;
  right: calc(var(--panel-w, 0px) + var(--safe-r, 0px) + 8px);
  bottom: calc(var(--dock-h, 0px) + var(--safe-b, 0px) + 8px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  width: max-content;
  max-width: calc(100vw - var(--tool-w, 0px) - var(--panel-w, 0px) - var(--safe-l, 0px) - var(--safe-r, 0px) - 16px);
  pointer-events: none;
  color: var(--pb-ink);
  font: 400 13px/1.35 var(--pb-font);
}
.aud-btn, .aud-panel { pointer-events: auto; }

/* Disclosure: a quiet row with a chevron, "Audit" in sentence case. A block box (not flex)
 * so ::first-letter applies; the chevron is positioned out of flow for the same reason. */
.aud-btn {
  appearance: none;
  position: relative;
  display: block;
  margin: 0;
  height: var(--cx-row, 32px);
  padding: 0 8px 0 24px;
  cursor: pointer;
  touch-action: manipulation;
  color: var(--pb-ink);
  background: transparent;
  border: 0;
  border-radius: var(--pb-r);
  font: 500 13px/1 var(--pb-font);
  letter-spacing: 0;
  text-align: left;
  text-transform: lowercase;
}
.aud-btn::first-letter { text-transform: uppercase; }
.aud-btn::after {
  content: "";
  position: absolute;
  left: 9px;
  top: calc(50% - 4px);
  width: 5px;
  height: 5px;
  border-right: 1.5px solid var(--pb-dim);
  border-bottom: 1.5px solid var(--pb-dim);
  transform: rotate(-45deg);
}
.aud-btn[aria-expanded="true"]::after { transform: rotate(45deg); top: calc(50% - 5px); }
.aud-btn:hover { background: var(--pb-hover); color: var(--pb-ink); }
.aud-btn[aria-expanded="true"] { color: var(--pb-ink); background: transparent; box-shadow: none; }
.aud-btn[aria-expanded="true"]:hover { background: var(--pb-hover); }
.aud[data-state="offline"] .aud-btn,
.aud[data-state="offline"] .aud-btn[aria-expanded="true"] { color: var(--pb-ink); box-shadow: none; }
.aud-btn:focus-visible { outline: 2px solid var(--pb-focus); outline-offset: 2px; }
/* Touch: taller, and the left padding still clears the chevron. */
@media (pointer: coarse) { .aud-btn { height: var(--tap, 44px); padding: 0 12px 0 24px; } }
:root:is([data-input="touch"], [data-input="pen"]) .aud-btn { padding-left: 24px; }

.aud-panel {
  display: flex;
  flex-direction: column;
  width: min(420px, calc(100vw - var(--tool-w, 0px) - var(--panel-w, 0px) - var(--safe-l, 0px) - var(--safe-r, 0px) - 16px));
  max-height: min(260px, 36dvh);
  background: var(--pb-panel);
  border: 1px solid var(--pb-line);
  border-radius: var(--pb-r);
  box-shadow: var(--pb-shadow);
  overflow: hidden;
}
.aud-panel[hidden] { display: none; }
/* Inside the Info panel: plain rows, no box in the box. */
#info-audit .aud-panel { background: transparent; border: 0; border-radius: 0; box-shadow: none; max-height: min(320px, 40dvh); }
#info-audit { border-top-color: var(--pb-line); }

.aud-cols,
.aud-row {
  display: grid;
  /* fixed tracks so the caption row lines up with every data row */
  grid-template-columns: 68px minmax(0, 56px) minmax(0, 1fr) minmax(0, 1fr);
  column-gap: 8px;
  align-items: baseline;
  padding: 0 8px;
}
.aud-cols {
  flex: none;
  min-height: 24px;
  align-items: center;
  color: var(--pb-mute);
  background: transparent;
  border-bottom: 1px solid var(--pb-line-hi);
  font: 600 11px/1.2 var(--pb-font);
  letter-spacing: .06em;
  text-transform: uppercase;
}

.aud-list {
  overflow: auto;
  min-height: 0;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--pb-line-hi) transparent;
}
.aud-list::-webkit-scrollbar { width: 8px; }
.aud-list::-webkit-scrollbar-thumb { background: var(--pb-line-hi); border-radius: 2px; }

.aud-row {
  min-height: 28px;
  align-items: center;
  font: 400 12px/1.35 var(--pb-mono);
  font-variant-numeric: tabular-nums slashed-zero;
  letter-spacing: 0;
  color: var(--pb-ink);
  border-bottom: 1px solid var(--pb-line);
  user-select: text;
}
.aud-row:nth-child(even) { background: transparent; }
.aud-row:hover { background: var(--pb-hover); }
/* Own entries: the callsign carries the weight (no coloured side bar). */
.aud-row[data-mine="true"] { box-shadow: none; }
.aud-row[data-mine="true"] .aud-cs { font-weight: 600; }

.aud-ts,
.aud-cs,
.aud-act,
.aud-dtl {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.aud-ts { color: var(--pb-mute); }
.aud-cs { color: var(--pb-ink); }
.aud-act { color: var(--pb-dim); }
.aud-dtl { color: var(--pb-dim); }
.aud-row[data-k="del"] .aud-act { color: var(--pb-bad); }
.aud-row[data-k="ok"] .aud-act { color: var(--pb-ok); }
.aud-row[data-k="leave"] .aud-act { color: var(--pb-mute); }
.aud-row[data-k="ew"] .aud-act { color: var(--pb-ink); }
.aud-row[data-k="mission"] .aud-act { color: var(--pb-dim); }

/* Empty, signed-out and offline states: one plain sentence. */
.aud-msg {
  margin: 0;
  padding: 12px 8px;
  color: var(--pb-dim);
  font: 400 13px/1.4 var(--pb-font);
  letter-spacing: 0;
}
.aud-msg::first-letter { text-transform: uppercase; }
.aud-msg[data-k="off"] { color: var(--pb-bad); }

/* F11 hash-chain state under the list: quiet when verified, the bad colour when broken. */
.aud-chain {
  flex: none;
  margin: 0;
  padding: 6px 8px;
  border-top: 1px solid var(--pb-line);
  color: var(--pb-mute);
  font: 400 12px/1.3 var(--pb-font);
  letter-spacing: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.aud-chain[data-k="bad"] { color: var(--pb-bad); white-space: normal; }
.aud-chain[hidden] { display: none; }

@media (max-width: 1099px) {
  body.mode-draw .aud {
    bottom: calc(var(--dock-h, 0px) + var(--safe-b, 0px) + 56px);
  }
}
@media (max-height: 500px) {
  .aud-panel { max-height: min(140px, 28dvh); }
}
