:root {
  --ink:    #12302a;
  --ink-2:  #1c4a41;
  --field:  #e9ebe7;
  --paper:  #ffffff;
  --own:    #21564b;
  --line:   #cfd5cf;
  --muted:  #5f6b64;
  --danger: #8c3b2f;
  --panic:  #d3382a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--field);
  color: var(--ink);
  font: 400 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app { height: 100dvh; }

/* ---------- login ---------- */

.login {
  height: 100dvh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1.5rem;
  padding: 2rem 1.25rem calc(2rem + env(safe-area-inset-bottom));
}

.login h1 {
  margin: 0;
  font: 600 1.5rem/1.2 Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
}

.login p { margin: -0.75rem 0 0; color: var(--muted); font-size: 0.9rem; }

.login form { width: min(24rem, 100%); display: grid; gap: 0.75rem; }

input[type="password"], input[type="text"] {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--paper);
  color: inherit;
  font-size: 1rem;
}

input:focus-visible, button:focus-visible, .thread:focus-visible {
  outline: 2px solid var(--ink-2);
  outline-offset: 2px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 0.5rem;
  padding: 0.85rem 1rem;
  background: var(--ink);
  color: var(--field);
}

button:disabled { opacity: 0.5; cursor: default; }

.error { color: var(--danger); font-size: 0.9rem; min-height: 1.2em; margin: 0; }

/* ---------- chat frame ---------- */

.chat {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--field);
}

/* grid items default to min-width:auto and refuse to shrink below their
   content - a long nowrap name in the header would widen the whole page */
.chat > * { min-width: 0; }

header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.7rem + env(safe-area-inset-top)) 1rem 0.7rem;
  background: var(--ink);
  color: var(--field);
}

header .who {
  flex: 1;
  min-width: 0;
  /* Georgia matches the login h1 and card headings; bumped up so the name
     reads as the title of the screen rather than a label between buttons. */
  font: 700 1.2rem/1.2 Georgia, "Times New Roman", serif;
  letter-spacing: 0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

header button {
  background: transparent;
  color: var(--field);
  border: 1px solid rgba(233, 235, 231, 0.35);
  padding: 0.55rem 1.2rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border-radius: 0.5rem;
}

header button.exit {
  background: var(--panic);
  color: #fff;
  border: 1px solid transparent;
}

header button.exit:active { background: #a92318; }

.stream {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 1rem 0.9rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.msg {
  max-width: 78%;
  padding: 0.55rem 0.75rem;
  background: var(--paper);
  border-radius: 1rem 1rem 1rem 0.25rem;
  align-self: flex-start;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.msg.mine {
  align-self: flex-end;
  background: var(--own);
  color: var(--paper);
  border-radius: 1rem 1rem 0.25rem 1rem;
}

.msg time {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.7rem;
  opacity: 0.6;
}

.msg img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 0.6rem;
  background: var(--line);
}

.empty { margin: auto; color: var(--muted); font-size: 0.9rem; }

.notice {
  position: fixed;
  left: 50%;
  bottom: calc(4.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(90vw, 22rem);
  background: var(--danger);
  color: #fff;
  padding: 0.5rem 0.9rem;
  border-radius: 0.5rem;
  font-size: 0.9rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

footer {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  background: var(--field);
  border-top: 1px solid var(--line);
}

footer textarea {
  flex: 1;
  resize: none;
  max-height: 7.5rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  background: var(--paper);
  color: inherit;
  font: inherit;
  line-height: 1.35;
}

footer button { border-radius: 1.2rem; padding: 0.7rem 1.1rem; }

.attach {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.7rem 0.8rem;
  border-radius: 1.2rem;
}

/* ---------- admin thread list ---------- */

.threads { overflow-y: auto; padding: 0.5rem 0.75rem calc(1rem + env(safe-area-inset-bottom)); }

.thread {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  background: var(--paper);
  color: var(--ink);
  border-radius: 0.6rem;
  padding: 0.9rem 1rem;
  margin-top: 0.4rem;
}

.thread .name { flex: 1; font-weight: 600; }
.thread .meta { font-size: 0.8rem; color: var(--muted); }
.thread .meta .at { font-weight: 700; color: #46534c; }

/* ---------- older-history marker ---------- */

/* The stream's own 16px top padding already sets the offset, so no
   margin here - adding one double-spaced the glyph away from the header.
   Padding is small and symmetric: with the 6.4px flex gap below, the ink
   ends up ~16px under the header and ~12px above the first bubble.
   The glyph rides high in its line box, so centre it explicitly. */
.older {
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.9rem;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  letter-spacing: 0.15em;
  user-select: none;
}

/* ---------- admin: people / passphrase panels ---------- */

.panel {
  overflow-y: auto;
  padding: 0.75rem 0.75rem calc(1.5rem + env(safe-area-inset-bottom));
}

.card {
  background: var(--paper);
  border-radius: 0.6rem;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font: 600 0.95rem/1.2 Georgia, "Times New Roman", serif;
}

/* A card whose whole content is one heading + one action: keep them on a
   single line so it does not read as heavy as the sections above it. */
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.card-row h2 { margin: 0; }

.card .row { display: flex; gap: 0.5rem; }
.card .row input { flex: 1; min-width: 0; }

.card input[type="text"],
.card input[type="number"],
.card input[type="password"] {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: var(--paper);
  color: inherit;
  font: inherit;
}

/* Every control inside a card is the same height as .small, so a row of
   input + button lines up instead of stair-stepping. */
.card input[type="text"],
.card input[type="number"],
.card input[type="password"],
.card button {
  min-height: 2.5rem;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  border-radius: 0.45rem;
}

.card form.row button { padding-inline: 1.1rem; }

.card form { display: grid; gap: 0.6rem; }
.card form.row { display: flex; }

button.small {
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  border-radius: 0.45rem;
}

.hint {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.ok { color: var(--own); font-size: 0.9rem; min-height: 1.2em; margin: 0; }

.person {
  border-top: 1px solid var(--line);
  padding: 0.7rem 0;
}
.person:first-child { border-top: 0; padding-top: 0; }

.person-top { display: flex; align-items: baseline; gap: 0.6rem; }
.person-top .name { flex: 1; min-width: 0; font-weight: 600; }

/* Role marker. Same muted 0.8rem as every other bit of secondary text in
   the app (.meta, .ctl-label, .thread .meta) - just not bold like the name. */
.person-top .tag {
  margin-left: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}
.person-top .meta { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.person-ctl {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.person-ctl .ctl-label { font-size: 0.8rem; color: var(--muted); }
.person-ctl input { width: 5rem; }

/* One-time passphrase. Deliberately loud - it is never shown again. */
.reveal {
  background: var(--own);
  color: var(--paper);
  border-radius: 0.6rem;
  padding: 0.9rem 1rem;
  margin-bottom: 0.75rem;
}
.reveal .reveal-who { margin: 0 0 0.4rem; font-weight: 600; }
.reveal code {
  display: block;
  font-size: 1.05rem;
  word-break: break-all;
  padding: 0.5rem 0.6rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 0.4rem;
}
.reveal .reveal-note { margin: 0.5rem 0 0.7rem; font-size: 0.8rem; opacity: 0.85; }
.reveal-btns { display: flex; gap: 0.5rem; }
.reveal button {
  background: var(--paper);
  color: var(--ink);
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  border-radius: 0.45rem;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
