/*
 * Plain, high-contrast, and respectful of the reader's settings. Sizes are in
 * rem so browser zoom and OS text scaling work; nothing relies on colour alone
 * to convey meaning.
 */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --fg: #101418;
  --muted: #4a5560;
  --line: #c3ccd5;
  --accent: #12507a;
  --accent-fg: #ffffff;
  --error: #a11020;
  --mine: #eef4fa;
  --selected: #12507a;
  --selected-fg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181c;
    --fg: #e8edf2;
    --muted: #9aa7b3;
    --line: #39434d;
    --accent: #7fc3f0;
    --accent-fg: #10161c;
    --error: #ff8a92;
    --mine: #1d2731;
    --selected: #7fc3f0;
    --selected-fg: #10161c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip {
  position: absolute;
  left: -9999px;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--accent-fg);
}
.skip:focus { left: 0; top: 0; z-index: 100; }

/* A visible focus ring everywhere. Never remove this. */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

header {
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 1rem;
}
header nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.1rem; }
header ul { display: flex; gap: 1rem; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }

main { padding: 1rem; max-width: 78rem; margin: 0 auto; }

h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; margin-bottom: 0.25rem; }

a { color: var(--accent); }

button {
  font: inherit;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button[type="submit"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.field { margin-bottom: 1rem; max-width: 32rem; }
.field label { display: block; font-weight: 600; margin-bottom: 0.2rem; }
input, textarea, select {
  font: inherit;
  width: 100%;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
}
.hint { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 0; }
.error { color: var(--error); font-weight: 600; }

/* --- Chat --- */

.chat-layout {
  display: grid;
  grid-template-columns: 14rem minmax(0, 1fr) 16rem;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 60rem) {
  .chat-layout { grid-template-columns: 1fr; }
}

.groups ul { list-style: none; margin: 0; padding: 0; }
.groups li { margin-bottom: 0.25rem; }
.groups button { width: 100%; text-align: left; }
.groups button[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 700;
}

#message-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0.25rem;
  height: 26rem;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}
#message-list li {
  padding: 0.35rem 0.5rem;
  border-radius: 3px;
}
#message-list li.mine { background: var(--mine); }
#message-list li.deleted { color: var(--muted); font-style: italic; }
#message-list li[aria-selected="true"] {
  background: var(--selected);
  color: var(--selected-fg);
}

#compose textarea { margin-bottom: 0.5rem; }
#reply-banner, #edit-banner {
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.5rem;
  border-left: 4px solid var(--accent);
  background: var(--mine);
}
.typing { color: var(--muted); min-height: 1.5rem; margin: 0.25rem 0 0; }

.people ul { list-style: none; margin: 0 0 1rem; padding: 0; }
.people li { padding: 0.15rem 0; }

/* --- Tables (admin) --- */

table { border-collapse: collapse; width: 100%; margin-bottom: 1.5rem; }
th, td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line); }
th { font-weight: 700; }
caption { text-align: left; font-weight: 700; padding-bottom: 0.4rem; }

code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  background: var(--mine);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  word-break: break-all;
}

/* --- Administration --- */

section {
  margin-bottom: 2.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}
section:last-of-type { border-bottom: none; }

/* Row actions wrap rather than stretching the table off the page. */
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.actions button { white-space: nowrap; }

/* Destructive actions are marked by colour *and* by the confirmation they
   raise, never by colour alone. */
button.danger { border-color: var(--error); color: var(--error); }
button.danger:hover { background: var(--error); color: var(--bg); }

#new-invite code, #invites code {
  display: inline-block;
  padding: 0.3rem 0.5rem;
  font-size: 0.95rem;
}

#group-picker, #new-group, #new-role { max-width: 32rem; }

form[role="search"] { display: flex; gap: 0.6rem; align-items: flex-end; }
form[role="search"] .field { margin-bottom: 0; }
