/* RNDV browser client. Plain CSS, no framework, no external fonts. */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #5c6470;
  --line: #d9dee5;
  --accent: #2456c9;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --ok: #1d7f4e;
  --mine: #dfe9ff;
  --theirs: #eef0f3;
  --radius: 10px;
  --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: #0f1216;
    --panel: #171b21;
    --ink: #e8ecf1;
    --muted: #9aa4b1;
    --line: #2a313b;
    --accent: #6f9bff;
    --accent-ink: #0b1220;
    --danger: #ff7b72;
    --ok: #5ccb8a;
    --mine: #203457;
    --theirs: #232a34;
  }
}

* { box-sizing: border-box; }

/* The panels are shown and hidden with the hidden attribute; keep it
   winning over the display rules below. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}

/* Two panes: the conversations on the left (inline start), the selected
   one on the right. On a narrow screen only one shows at a time and
   data-view on .app says which. */
.app {
  display: grid;
  grid-template-columns: minmax(15rem, 21rem) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  max-width: 78rem;
  margin: 0 auto;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  min-height: 0;
  border-inline-end: 1px solid var(--line);
}

.side-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.side-top .logo { flex: none; line-height: 0; }
.side-top .logo img { width: 32px; height: 32px; }
.side-top h1 {
  margin: 0;
  margin-inline-end: auto;
  font-size: 1.15rem;
  min-width: 0;
}

.lang {
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  flex-shrink: 0;
  max-width: 50%;
}

.chats {
  list-style: none;
  margin: 0 -8px;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "dot name badge" "dot preview badge";
  column-gap: 10px;
  align-items: center;
  width: 100%;
  text-align: start;
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
}
.chat-item:hover { background: var(--theirs); }
.chat-item[aria-current="true"] { background: var(--mine); }
.chat-item .dot {
  grid-area: dot;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}
.chat-item[data-state="secure"] .dot { background: var(--ok); }
.chat-item[data-state="ended"] .dot,
.chat-item[data-state="error"] .dot { background: var(--danger); }
.chat-item[data-state="ready"] .dot { background: transparent; border: 2px solid var(--muted); }
.chat-item .name,
.chat-item .preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-item .name { grid-area: name; font-weight: 600; }
.chat-item .preview { grid-area: preview; color: var(--muted); font-size: 0.85rem; }
.chat-item .badge {
  grid-area: badge;
  min-width: 1.5em;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.8rem;
  text-align: center;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
}

.pane-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.pane-top .who { flex: 1; min-width: 0; }
.pane-top .name-row { display: flex; align-items: center; gap: 4px; }
/* The field is as wide as the name where the browser can do that, so the
   pencil sits right after it. */
.pane-top .name {
  flex: 0 1 auto;
  min-width: 6ch;
  max-width: 100%;
  field-sizing: content;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 2px 6px;
  margin-inline-start: -6px;
  text-overflow: ellipsis;
}
.pane-top .name:hover:enabled { border-color: var(--line); }
.pane-top .name:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.pane-top .name::placeholder { color: var(--ink); opacity: 1; }
.pane-top .name:focus::placeholder { color: var(--muted); }
.pane-top button { flex-shrink: 0; padding: 6px 12px; }
.pane-top .rename {
  padding: 2px 6px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}
.pane-top .rename:hover:enabled, .pane-top .rename:focus-visible { color: var(--ink); border-color: var(--line); }
.back { display: none; font-size: 1.4rem; line-height: 1; }

.status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.pane[data-state="secure"] .status { color: var(--ok); }
.pane[data-state="error"] .status,
.pane[data-state="ended"] .status { color: var(--danger); }

.body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}
#setup > * { max-width: 42rem; }

.body h2 {
  font-size: 1.3rem;
  margin: 8px 0 6px;
}
.lead { color: var(--muted); margin: 0 0 10px; }

/* Link to the animated explainer (client/help/). */
.watch { margin: 0 0 16px; }
.watch a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
/* A play triangle, drawn with borders (the CSP allows no inline image). */
.watch a::before {
  content: "";
  flex: none;
  border-style: solid;
  border-width: 6px 0 6px 10px;
  border-color: transparent transparent transparent currentColor;
}
.watch a:hover, .watch a:focus-visible { text-decoration: underline; }

/* The animation's pop-up. Padding is zero so that a click on the dialog
   element itself can only be a click on the backdrop. */
.how {
  width: min(960px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  overflow: auto;
}
.how::backdrop { background: rgba(0, 0, 0, 0.55); }
.how img { display: block; width: 100%; height: auto; }
.how button { display: block; margin: 10px auto; }

/* The two steps of starting a conversation, as numbered cards. */
.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: step;
  display: grid;
  gap: 12px;
}
.step {
  counter-increment: step;
  position: relative;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  padding-inline-start: 58px;
}
.step::before {
  content: counter(step);
  position: absolute;
  inset-inline-start: 16px;
  top: 14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  display: grid;
  place-items: center;
}
.step h3 { font-size: 1.05rem; margin: 2px 0 4px; }
.step p { margin: 0 0 10px; color: var(--muted); font-size: 0.95rem; }
.step .key { display: block; margin-bottom: 10px; font-size: 0.95rem; }
.step .error { margin: 6px 0 10px; color: var(--danger); }
.step .error:empty { min-height: 0; margin: 0 0 10px; }

.more { margin-top: 12px; }
.more summary { cursor: pointer; color: var(--muted); font-size: 0.95rem; padding: 4px 0; }
.more[open] summary { color: var(--ink); }
.more > :not(summary) { margin-inline-start: 18px; }

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.hint.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 10px 0;
  cursor: pointer;
}
.hint.check input {
  margin-top: 2px;
}

/* Codes and the core hash are Latin text: keep them
   left-to-right inside right-to-left pages. */
.key {
  flex: 1;
  text-align: left;
  font-family: var(--mono);
  font-size: 1rem;
  background: var(--theirs);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  word-break: break-all;
  user-select: all;
}

textarea {
  width: 100%;
  font: inherit;
  font-family: var(--mono);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 10px 16px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.secondary { white-space: nowrap; }

.error {
  color: var(--danger);
  min-height: 1.5em;
  margin: 4px 0;
}

/* chat */
#chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.details {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  max-height: 50%;
  overflow-y: auto;
  flex-shrink: 0;
}
/* The summary stays in view while the panel scrolls: it is what closes it. */
.details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  background: var(--panel);
  padding: 2px 0;
}
.details .key { display: block; font-size: 0.9rem; padding: 6px 10px; }
.details p.hint { margin: 8px 0 2px; }

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  /* Room for the scrollbar beside the bubbles, not over them. */
  padding-inline-end: 6px;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.log li {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.log li.mine { align-self: flex-end; background: var(--mine); }
.log li.theirs { align-self: flex-start; background: var(--theirs); }

/* Delivery state of our own lines: queued/sent, acknowledged by the peer,
   or still unacknowledged when the conversation ended. */
.log li.mine::after {
  display: inline-block;
  margin-inline-start: 0.5em;
  font-size: 0.8em;
  opacity: 0.6;
  content: "\2026"; /* … */
}
.log li.mine.delivered::after { content: "\2713"; } /* ✓ */
.log li.mine.undelivered::after { content: "!"; color: var(--danger, #b00020); opacity: 1; }

.compose {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
/* Messages are prose: the page's own typeface, not the codes' monospace.
   The box grows with what is typed (app.js), up to a few lines. */
.compose textarea {
  flex: 1;
  font-family: var(--font);
  resize: none;
  max-height: 9rem;
  overflow-y: auto;
}
.compose .count {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ended {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}
.ended p { margin: 0; flex: 1; min-width: 12rem; }
#storage-error { margin: 0; min-height: 0; }

.foot {
  color: var(--muted);
  font-size: 0.8rem;
}
.foot p { margin: 4px 0; }
.foot .core {
  font-family: var(--mono);
  text-align: left;
  font-size: 0.7rem;
  word-break: break-all;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app[data-view="list"] .pane { display: none; }
  .app[data-view="chat"] .side { display: none; }
  .side { border-inline-end: 0; }
  .pane { border-inline-end: 0; }
  .back { display: block; }
  .log li { max-width: 88%; }

  /* The top of a conversation in two rows: back, name and the end button
     share the first; the status line gets the second to itself. */
  .pane-top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "back name end" ". status status";
    align-items: center;
    column-gap: 8px;
    row-gap: 2px;
    padding: 8px 12px;
  }
  .pane-top .back { grid-area: back; min-width: 40px; min-height: 40px; }
  .pane-top .who { display: contents; }
  .pane-top .name-row { grid-area: name; min-width: 0; }
  .pane-top .name { font-size: 1rem; }
  .pane-top .status { grid-area: status; font-size: 0.85rem; line-height: 1.3; }
  .pane-top #end { grid-area: end; font-size: 0.85rem; padding: 6px 8px; }

  .body { padding: 12px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  #chat { gap: 8px; }
  /* Open, the details take what they need but never most of the screen;
     writing a message closes them (app.js). */
  .details { max-height: 45%; padding-bottom: 6px; }
  .details .key { font-size: 0.8rem; }
  .details label.check { font-size: 0.85rem; }

  /* Setup cards use the full width: the step number sits beside the
     heading instead of taking a column of its own. */
  .step { padding: 12px; padding-inline-start: 12px; }
  .step::before { inset-inline-start: 12px; top: 12px; }
  .step h3 { min-height: 28px; padding-inline-start: 38px; margin: 0 0 6px; display: flex; align-items: center; }
}
