/* Dark mode and layout only.
 *
 * Everything visual here comes from one of two places: `color-scheme: dark`,
 * which flips the browser's own defaults (canvas, text, form controls,
 * scrollbars) to their dark variants, and CSS system colours, which are the
 * palette the browser is already using for those defaults. No hand-picked
 * colours, no fonts, no radii, no shadows - so every control looks exactly
 * like a plain unstyled HTML control that happens to be dark.
 *
 * The rest is positioning: a four-column grid that each scroll independently,
 * and the flex needed to pin a composer to the bottom of the middle column. */

:root {
  color-scheme: dark;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ chrome */

header {
  display: flex;
  align-items: center;
  gap: 1ch;
  flex-wrap: wrap;
  padding: 0.4em 0.6em;
  border-bottom: 1px solid ButtonBorder;
}

header .spacer {
  flex: 1;
}

#status {
  color: GrayText;
}

/* ------------------------------------------------------------------- shell */

#app {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 14em 15em minmax(0, 1fr) 14em;
}

#app > * {
  min-width: 0;
  overflow: auto;
  padding: 0.4em 0.6em;
  border-right: 1px solid ButtonBorder;
}

#app > :last-child {
  border-right: none;
}

/* the message column owns its own scrolling, inside the log */
#chat {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}

#chat > header {
  border-bottom: 1px solid ButtonBorder;
}

#log {
  flex: 1;
  overflow-y: auto;
  padding: 0.4em 0.6em;
}

#composer {
  border-top: 1px solid ButtonBorder;
  padding: 0.4em 0.6em;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

#composer form {
  display: flex;
  gap: 0.5ch;
  align-items: flex-end;
}

#composer textarea {
  flex: 1;
  resize: vertical;
  min-height: 2.4em;
}

/* ------------------------------------------------------------------- lists */

ul,
menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  margin: 0;
}

/* Rows that behave like links are buttons, so they stay keyboard reachable.
 * Stripping the button chrome is the one place we override a default, and only
 * because a sidebar of 200 bordered buttons is unreadable. */
.row {
  display: flex;
  align-items: center;
  gap: 0.6ch;
  width: 100%;
  padding: 0.15em 0.3em;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.row:hover {
  background: ButtonFace;
}

.row[aria-current='true'] {
  background: Highlight;
  color: HighlightText;
}

.row .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row .badge {
  background: Mark;
  color: MarkText;
  padding: 0 0.4ch;
}

.row.unread .name {
  font-weight: bold;
}

img.icon {
  width: 1.2em;
  height: 1.2em;
  object-fit: cover;
  flex: none;
}

.dot {
  flex: none;
}

/* ---------------------------------------------------------------- sections */

section.group > summary,
details > summary {
  cursor: pointer;
  color: GrayText;
}

h2,
h3 {
  font-size: 1em;
  margin: 0.8em 0 0.2em;
  color: GrayText;
}

h2:first-child,
h3:first-child {
  margin-top: 0.2em;
}

/* ---------------------------------------------------------------- messages */

.msg {
  display: flex;
  gap: 0.8ch;
  padding: 0.15em 0;
  align-items: flex-start;
}

.msg > .body {
  flex: 1;
  min-width: 0;
}

.msg .meta {
  color: GrayText;
}

.msg .text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg .tools {
  visibility: hidden;
  flex: none;
  display: flex;
  gap: 0.4ch;
}

.msg:hover .tools,
.msg:focus-within .tools {
  visibility: visible;
}

.msg blockquote {
  margin: 0 0 0.15em 0;
  padding-left: 0.8ch;
  border-left: 2px solid ButtonBorder;
  color: GrayText;
}

.msg .attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5ch;
  align-items: flex-start;
}

.msg img.media {
  max-width: min(100%, 24em);
  max-height: 18em;
  height: auto;
  display: block;
}

.msg .embed {
  border-left: 2px solid ButtonBorder;
  padding-left: 0.8ch;
  margin: 0.2em 0;
}

.msg .reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4ch;
  margin-top: 0.15em;
}

.mention {
  background: Mark;
  color: MarkText;
}

code {
  white-space: pre-wrap;
}

pre {
  margin: 0.2em 0;
  padding: 0.3em 0.5ch;
  border: 1px solid ButtonBorder;
  overflow-x: auto;
}

img.emoji {
  height: 1.2em;
  width: auto;
  vertical-align: -0.2em;
}

/* ------------------------------------------------------------------- forms */

#auth {
  max-width: 34em;
  margin: 2em auto;
  padding: 0 1em;
}

fieldset {
  margin: 0 0 1em;
}

label {
  display: block;
  margin: 0.4em 0;
}

label input,
label textarea,
label select {
  display: block;
  width: 100%;
  box-sizing: border-box;
}

.error {
  color: Mark;
  background: MarkText;
  padding: 0.2em 0.5ch;
}

.hint {
  color: GrayText;
}

dialog {
  min-width: min(30em, 90vw);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
}

.actions {
  display: flex;
  gap: 0.5ch;
  flex-wrap: wrap;
  align-items: center;
}

[hidden] {
  display: none !important;
}

/* A phone cannot hold four columns. Collapse to one and let a data-pane
 * attribute on <body> decide which is on screen. */
@media (max-width: 60em) {
  #app {
    grid-template-columns: minmax(0, 1fr);
  }

  #app > * {
    border-right: none;
  }

  body[data-pane='rail'] #channels,
  body[data-pane='rail'] #chat,
  body[data-pane='rail'] #members,
  body[data-pane='channels'] #rail,
  body[data-pane='channels'] #chat,
  body[data-pane='channels'] #members,
  body[data-pane='chat'] #rail,
  body[data-pane='chat'] #channels,
  body[data-pane='chat'] #members,
  body[data-pane='members'] #rail,
  body[data-pane='members'] #channels,
  body[data-pane='members'] #chat {
    display: none;
  }
}

@media (min-width: 60.01em) {
  #panes {
    display: none;
  }
}
