:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --bg-panel: #1b202a;
  --border: #262d3a;
  --text: #e6e9ef;
  --muted: #8b94a6;
  --accent: #4f8cff;
  --accent-soft: #24334f;
  --task: #f0b429;
  --task-soft: #3a2f13;
  --danger: #ff6b6b;
  --ok: #3ecf8e;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

/* Scrollbalken ausblenden - gescrollt wird weiterhin, nur sichtbar ist nichts.
   `scrollbar-width` deckt Firefox ab, der ::-webkit-Teil Chrome und Edge.     */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { width: 0; height: 0; display: none; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; }

button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 8px 14px;
  cursor: pointer;
  background: var(--bg-panel);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; }
button.tiny { padding: 3px 8px; font-size: 12px; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ----------------------------------------------------------------- Login */

.login-view {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 20px;
}

.login-card {
  width: min(380px, 100%);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; font-size: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* ------------------------------------------------------------------- App */

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.topbar { flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted);
  transition: background 0.2s;
}
.dot.online { background: var(--ok); }
.dot.offline { background: var(--danger); }

.layout {
  flex: 1;
  display: grid;
  /* minmax(0, 1fr) statt 1fr: sonst waechst die Chatspalte mit ihrem breitesten
     Inhalt und schiebt die Seitenleiste aus dem Fenster - etwa bei einer langen
     CSV-Zeile ohne Leerzeichen. Dasselbe gilt fuer min-width unten.          */
  grid-template-columns: minmax(0, 1fr) 300px;
  min-height: 0;
}

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.msg {
  max-width: min(760px, 90%);
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 13px;
}
.msg.own { align-self: flex-end; background: var(--accent-soft); border-color: #33507d; }
/* An mich gerichtet: deutlich, aber ohne den Verlauf zu zerreissen. */
.msg.addressed { border-left: 3px solid var(--task); background: var(--task-soft); }

.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.msg-author { font-weight: 600; color: var(--text); }

.msg-head .reply-button { margin-left: auto; opacity: 0; transition: opacity 0.15s; }
.msg:hover .reply-button, .reply-button:focus { opacity: 1; }

.msg-quote {
  border-left: 2px solid var(--border);
  padding: 3px 0 3px 9px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  gap: 6px;
}
.msg-quote:hover { border-left-color: var(--accent); }
.msg-quote .msg-author { font-size: 12px; }

.tag.addressed-tag { color: var(--task); border-color: #5c4a1a; }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-left: 2px solid var(--accent);
  background: var(--bg-panel);
  border-radius: 6px;
}
.reply-target { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-bar .tiny { margin-left: auto; flex: none; }

/* `anywhere` bricht auch Zeichenketten ohne Leerzeichen um - Logzeilen, CSV,
   lange Bezeichner. Ohne das laeuft der Text aus der Blase heraus.
   Zeilenumbrueche macht jetzt der Markdown-Renderer, nicht mehr pre-wrap.   */
.msg-body {
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

/* ------------------------------------------------------- Markdown im Chat */

.msg-body > *:first-child { margin-top: 0; }
.msg-body > *:last-child { margin-bottom: 0; }
.msg-body p { margin: 6px 0; }
.msg-body h2, .msg-body h3, .msg-body h4, .msg-body h5, .msg-body h6 {
  margin: 12px 0 6px;
  line-height: 1.3;
}
.msg-body h2 { font-size: 17px; }
.msg-body h3 { font-size: 15px; }
.msg-body h4, .msg-body h5, .msg-body h6 { font-size: 14px; color: var(--muted); }
.msg-body ul, .msg-body ol { margin: 6px 0; padding-left: 20px; }
.msg-body li { margin: 3px 0; }
.msg-body blockquote {
  margin: 8px 0;
  padding: 2px 0 2px 10px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.msg-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-body del { opacity: 0.6; }

/* Tabellen scrollen in sich selbst, statt die Blase aufzublaehen. */
.table-scroll { overflow-x: auto; margin: 8px 0; max-width: 100%; }
.msg-body table, .markdown table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 100%;
}
.msg-body th, .msg-body td, .markdown th, .markdown td {
  border: 1px solid var(--border);
  padding: 5px 9px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: normal;
  white-space: nowrap;
}
.msg-body th, .markdown th { background: rgba(255, 255, 255, 0.04); font-weight: 600; }
.msg-body code {
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
}
/* Codebloecke bleiben zeilentreu und scrollen stattdessen in sich selbst. */
.msg-body pre {
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.35);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre;
  overflow-wrap: normal;
  margin: 6px 0;
}
.msg-body code { overflow-wrap: anywhere; }
.msg-body a { color: var(--accent); }

.msg-foot { margin-top: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* -------------------------------------------------------------- Bilder im Chat */

.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.msg-image {
  display: block;
  line-height: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
}
.msg-image:hover { border-color: var(--accent); }
.msg-image img {
  display: block;
  max-width: min(420px, 100%);
  max-height: 320px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 5px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 260px;
}
.attachment.uploading { opacity: 0.55; }
.attachment img { width: 38px; height: 38px; object-fit: cover; border-radius: 5px; flex: none; }
.attachment-name {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat { position: relative; }
.drop-hint {
  position: absolute;
  inset: 10px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(79, 140, 255, 0.09);
  display: grid;
  place-items: center;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
  z-index: 10;
}

.tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.tag.role { color: var(--muted); }

.mention {
  color: var(--accent);
  background: rgba(79, 140, 255, 0.12);
  border-radius: 5px;
  padding: 0 4px;
  font-weight: 600;
}
.mention.me { color: var(--task); background: rgba(240, 180, 41, 0.16); }

/* Wer arbeitet gerade? Sitzt direkt ueber dem Eingabefeld, damit man es sieht. */
.activity-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 7px 16px;
  border-top: 1px solid var(--border);
  background: var(--task-soft);
  font-size: 13px;
}
.activity-item { display: flex; align-items: center; gap: 7px; }
.activity-item .pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--task);
  animation: pulse 1.4s ease-in-out infinite;
  flex: none;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}
.activity-name { font-weight: 600; }

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 16px 14px;
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.composer textarea { resize: vertical; min-height: 52px; }
.composer-field { position: relative; }
.composer-actions { display: flex; align-items: center; gap: 14px; }
.composer-actions .primary { margin-left: auto; }

/* Vorschlagsliste fuer @erwaehnungen */
.mention-list {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  max-height: 220px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 20;
}
.mention-list li { padding: 6px 9px; border-radius: 6px; cursor: pointer; }
.mention-list li.active { background: var(--accent-soft); }

.checkbox { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.checkbox input { width: auto; }

/* --------------------------------------------------------------- Sidebar */

.sidebar {
  min-width: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-soft);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.panel h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 7px;
  font-size: 11px;
}

.users { display: flex; flex-direction: column; gap: 8px; }

.hint { margin: 10px 0 0; line-height: 1.45; }
.hint code { font-family: var(--mono); font-size: 11px; background: rgba(255, 255, 255, 0.07); padding: 1px 4px; border-radius: 4px; }

.user-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-name { cursor: pointer; }
.user-name:hover { color: var(--accent); }
.avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  background: var(--accent-soft);
  color: #cfe0ff;
  flex: none;
}

/* ---------------------------------------------------------------- Dialog */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-soft);
  color: var(--text);
  padding: 22px;
  width: min(640px, 92vw);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dialog h2 { margin: 0 0 14px; font-size: 18px; }
.dialog h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); }

.admin-users { display: flex; flex-direction: column; gap: 8px; max-height: 40vh; overflow-y: auto; }
.admin-user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg-panel);
}
.admin-user .name { font-weight: 600; }
.admin-user .spacer { flex: 1; }

.create-user { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.create-user .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.create-user .row > * { flex: 1; min-width: 130px; }
.create-user .checkbox { flex: none; }
.create-user .primary { align-self: flex-start; }

.secret-box {
  margin-top: 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.secret-box code { font-family: var(--mono); font-size: 12px; word-break: break-all; flex: 1; }

.dialog-actions { margin-top: 16px; display: flex; justify-content: flex-end; }

/* --------------------------------------------------------- Anleitungsseite */

.linkbutton {
  display: inline-block;
  font: inherit;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
}
.linkbutton:hover { border-color: var(--accent); }

.doc { flex: 1; overflow-y: auto; padding: 26px 20px 60px; }

.doc-card {
  max-width: 820px;
  margin: 0 auto 18px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
}
.doc-card h1 { font-size: 22px; margin: 0 0 10px; }
.doc-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.doc-card textarea { font-family: var(--mono); font-size: 13px; margin-top: 12px; resize: vertical; }

.markdown h2 { font-size: 18px; margin: 22px 0 8px; }
.markdown h2:first-child { margin-top: 0; }
.markdown h3 { font-size: 15px; margin: 18px 0 6px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.markdown p { margin: 8px 0; }
.markdown ul { margin: 8px 0; padding-left: 22px; }
.markdown li { margin: 4px 0; }
.markdown code { font-family: var(--mono); font-size: 13px; background: rgba(255, 255, 255, 0.07); padding: 1px 5px; border-radius: 4px; }
.markdown pre {
  font-family: var(--mono);
  font-size: 13px;
  background: rgba(0, 0, 0, 0.35);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
}
.markdown pre code { background: none; padding: 0; }
.markdown a { color: var(--accent); }
.markdown blockquote {
  margin: 10px 0;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}
.markdown ol { margin: 8px 0; padding-left: 22px; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
}

@media (max-width: 520px) {
  /* Auf dem Telefon zaehlt der Verlauf, nicht die Beschriftung der Knoepfe. */
  body { font-size: 14px; }
  .topbar { padding: 8px 10px; }
  #me-label { display: none; }
  .messages { padding: 12px 10px; }
  .msg { max-width: 100%; }
  .composer { padding: 10px; }
}
