/* static/design/chat.css — MOREMEDIA App: Chat (Learning #8190).
   Nur Tokens aus tokens.css (Farben, Abstände, Radien, Schrift); Maße in rem.
   Mobil: Liste → Channel → Thread als Ebenen; ab 48rem nebeneinander. */

.mmchat-body { margin: 0; height: 100dvh; overflow: hidden; background: var(--bg-base); }
/* Vollbild-App: die Seite selbst scrollt nie (sonst schiebt iOS sie beim Tippen weg) */
.mmchat-body { position: fixed; inset: 0; overscroll-behavior: none; }
.mmchat, .mmchat * { box-sizing: border-box; }
/* Reset ohne Spezifität (:where), damit die Bausteine unten nichts mit erzwingen müssen */
:where(.mmchat) button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:where(.mmchat) p { margin: 0; }
.mmchat input, .mmchat textarea { font: inherit; color: var(--tx-0); }

.mmchat {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  background: var(--bg-base);
  color: var(--tx-0);
  font-family: var(--font-ui);
  font-size: var(--t-base);
  line-height: 1.5;
}
.mmchat--app { height: 100%; }
.mmchat-body #root { height: 100%; }
.mmchat--surface {
  height: calc(100dvh - 8rem);
  border: 1px solid var(--bdr-def);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* ── Channel-Liste ─────────────────────────────── */
.mmchat-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--bdr-def);
}
.mmchat--app .mmchat-side { padding-top: env(safe-area-inset-top); }
.mmchat-side__head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-md) var(--sp-md) var(--sp-md) var(--sp-lg);
  border-bottom: 1px solid var(--bdr-faint);
}
.mmchat-brand { flex: 1; font-weight: 700; letter-spacing: 0.18em; font-size: var(--t-sm); }
.mmchat-dot { width: 0.5rem; height: 0.5rem; border-radius: var(--r-full); background: var(--tx-2); }
.mmchat-dot--on { background: var(--ok); }
.mmchat-side__scroll { flex: 1; overflow-y: auto; padding: var(--sp-sm) var(--sp-md) calc(var(--sp-lg) + env(safe-area-inset-bottom)); }

.mmchat-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-lg) var(--sp-md) var(--sp-sm);
  font-size: var(--t-xs);
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--tx-2);
}
.mmchat-empty-line { padding: var(--sp-sm) var(--sp-md); color: var(--tx-2); font-size: var(--t-sm); }

.mmchat-chan {
  display: flex;
  align-items: center;
  gap: var(--sp-2-5);
  width: 100%;
  min-height: 2.75rem;
  padding: 0 var(--sp-md);
  border-radius: var(--r-md);
  color: var(--tx-1);
  font-size: var(--t-md);
  text-align: left;
}
.mmchat-chan:hover { background: var(--ac-bg); }
.mmchat-chan.is-active { background: var(--bg-el); color: var(--tx-0); }
.mmchat-chan.is-unread { color: var(--tx-0); font-weight: 500; }
.mmchat-chan__hash { width: 1.4rem; text-align: center; color: var(--tx-2); }
.mmchat-chan__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mmchat-chan__muted { font-size: var(--t-xs); color: var(--tx-2); }
.mmchat-badge {
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 var(--sp-sm);
  border-radius: var(--r-full);
  background: var(--tx-0);
  color: var(--bg-surface);
  font-size: var(--t-xs);
  font-weight: 700;
  line-height: 1.25rem;
  text-align: center;
}

/* ── Grundbausteine ────────────────────────────── */
.mmchat-icon { width: 1.15rem; height: 1.15rem; display: block; }
.mmchat-iconbtn { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: var(--r-md); color: var(--tx-1); }
.mmchat-iconbtn:hover { background: var(--ac-bg); }
.mmchat-iconbtn--s { width: 1.75rem; height: 1.75rem; }
.mmchat-avatar {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--r-full);
  background: var(--bg-ov);
  color: var(--tx-1);
  font-size: var(--t-xs);
  font-weight: 700;
}
.mmchat-avatar--s { width: 1.4rem; height: 1.4rem; font-size: var(--t-eyebrow); }
.mmchat-avatar--bot { background: var(--tx-0); color: var(--bg-surface); }
.mmchat-tag {
  padding: 0 var(--sp-1);
  border: 1px solid var(--bdr-str);
  border-radius: var(--r-xs);
  font-size: var(--t-eyebrow);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tx-2);
}
.mmchat-btn {
  padding: var(--sp-2) var(--sp-md);
  border: 1px solid var(--bdr-def);
  border-radius: var(--r-md);
  font-weight: 500;
}
.mmchat-btn--primary { background: var(--tx-0); color: var(--bg-surface); border-color: var(--tx-0); }
.mmchat-btn:disabled { opacity: 0.35; cursor: default; }
.mmchat-btn--block { display: block; width: 100%; margin-top: var(--sp-md); padding: var(--sp-3); }

/* ── Channel-Ansicht ───────────────────────────── */
.mmchat-view { display: none; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg-base); }
.mmchat.has-channel .mmchat-side { display: none; }
.mmchat.has-channel .mmchat-view { display: flex; }
.mmchat-view--empty { align-items: center; justify-content: center; color: var(--tx-2); }
.mmchat-view__head {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  padding: var(--sp-md);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--bdr-def);
}
.mmchat--app .mmchat-view > .mmchat-view__head,
.mmchat--app .mmchat-thread > .mmchat-view__head { padding-top: calc(var(--sp-md) + env(safe-area-inset-top)); }
.mmchat-view__title {
  flex: 1;
  margin: 0;
  font-size: var(--t-lg);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mmchat-scroll { flex: 1; overflow-y: auto; padding: var(--sp-md) 0; -webkit-overflow-scrolling: touch; }
.mmchat-empty { padding: var(--sp-2xl) var(--sp-lg); text-align: center; color: var(--tx-2); }
.mmchat-older { display: block; margin: 0 auto var(--sp-md); padding: var(--sp-sm) var(--sp-md); color: var(--inf); font-size: var(--t-sm); }

/* ── Nachrichten ───────────────────────────────── */
.mmchat-msg { position: relative; display: flex; gap: var(--sp-3); padding: var(--sp-2) var(--sp-lg) var(--sp-1); }
.mmchat-msg.is-grouped { padding-top: 0; }
.mmchat-msg.is-high { background: var(--er-bg); box-shadow: inset var(--sp-xs) 0 0 var(--er); }
.mmchat-msg:hover { background: var(--ac-bg); }
.mmchat-msg__gutter { flex: none; width: 2rem; }
.mmchat-msg__time-inline { display: block; padding-top: var(--sp-xs); font-size: var(--t-eyebrow); color: var(--tx-2); opacity: 0; }
.mmchat-msg:hover .mmchat-msg__time-inline { opacity: 1; }
.mmchat-msg__body { min-width: 0; flex: 1; }
.mmchat-msg__head { display: flex; align-items: baseline; gap: var(--sp-2); }
.mmchat-msg__author { font-weight: 700; color: var(--tx-0); }
.mmchat-msg__time { font-size: var(--t-xs); color: var(--tx-2); }
.mmchat-msg__text { color: var(--tx-0); font-size: var(--t-md); line-height: 1.5; overflow-wrap: anywhere; white-space: pre-wrap; }
.mmchat-msg__text code { font-family: var(--font-mono); color: var(--tx-1); background: var(--bg-el); padding: 0 var(--sp-1); border-radius: var(--r-xs); }
.mmchat-msg__text a { color: var(--inf); }
.mmchat-msg__text.is-deleted { color: var(--tx-2); font-style: italic; }
.mmchat-msg__edited { font-size: var(--t-xs); color: var(--tx-2); }
.mmchat-msg__thread { margin-top: var(--sp-1); font-size: var(--t-sm); font-weight: 500; color: var(--inf); }
.mmchat-mention { color: var(--inf); font-weight: 500; }
.mmchat-mention--self { background: var(--wa-bg); color: var(--wa); padding: 0 var(--sp-xs); border-radius: var(--r-xs); }
.mmchat-prio {
  display: inline-block;
  margin-right: var(--sp-sm);
  padding: 0 var(--sp-1);
  border-radius: var(--r-xs);
  font-size: var(--t-eyebrow);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  vertical-align: 0.1em;
}
.mmchat-prio--high { color: var(--er); background: var(--er-bg); border: 1px solid var(--er-bd); }
.mmchat-prio--low { color: var(--tx-2); border: 1px solid var(--bdr-def); }

.mmchat-msg__menu { position: relative; align-self: flex-start; opacity: 0; }
.mmchat-msg:hover .mmchat-msg__menu, .mmchat-msg__menu--head { opacity: 1; }
@media (pointer: coarse) { .mmchat-msg__menu { opacity: 1; } }
.mmchat-menu {
  position: absolute;
  z-index: 5;
  top: 100%;
  right: 0;
  min-width: 13rem;
  padding: var(--sp-1);
  background: var(--bg-surface);
  border: 1px solid var(--bdr-str);
  border-radius: var(--r-md);
  box-shadow: 0 0.5rem 1.5rem var(--bdr-def);
}
.mmchat-menu button { display: block; width: 100%; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); text-align: left; }
.mmchat-menu button:hover { background: var(--ac-bg); }
.mmchat-menu button.is-on { font-weight: 700; }
.mmchat-menu button.is-danger { color: var(--er); }

.mmchat-edit textarea { width: 100%; padding: var(--sp-2); border: 1px solid var(--bdr-str); border-radius: var(--r-md); background: var(--bg-surface); resize: vertical; }
.mmchat-edit__actions { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-1); }

/* ── Eingabe ───────────────────────────────────── */
.mmchat-composer {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-2-5) var(--sp-md) calc(var(--sp-2-5) + env(safe-area-inset-bottom));
  background: var(--bg-surface);
  border-top: 1px solid var(--bdr-def);
}
.mmchat-composer--ro { justify-content: center; color: var(--tx-2); font-size: var(--t-sm); }
.mmchat-composer__input {
  flex: 1;
  min-height: 2.5rem;
  max-height: 10rem;
  padding: var(--sp-2) var(--sp-md);
  border: 1px solid var(--bdr-def);
  border-radius: var(--r-lg);
  background: var(--bg-base);
  font-size: 1rem; /* verhindert Auto-Zoom in iOS */
  resize: none;
  outline: none;
}
.mmchat-composer__input:focus { border-color: var(--bdr-str); }
.mmchat-prio-btn {
  height: 2.5rem;
  padding: 0 var(--sp-2-5);
  border: 1px solid var(--bdr-def);
  border-radius: var(--r-lg);
  font-size: var(--t-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tx-2);
}
.mmchat-prio-btn--high { color: var(--er); background: var(--er-bg); border-color: var(--er-bd); }
.mmchat-prio-btn--low { background: var(--bg-el); }
.mmchat-send {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--r-lg);
  background: var(--tx-0);
  color: var(--bg-surface);
}
.mmchat-send:disabled { opacity: 0.3; cursor: default; }

/* ── Thread ────────────────────────────────────── */
.mmchat-thread { display: none; flex-direction: column; min-height: 0; background: var(--bg-base); border-left: 1px solid var(--bdr-def); }
.mmchat.has-thread .mmchat-thread { display: flex; }
.mmchat-thread__root { border-bottom: 1px solid var(--bdr-faint); padding: var(--sp-sm) 0; }

/* ── Dialoge ───────────────────────────────────── */
.mmchat-sheet-bg {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--bdr-str);
}
.mmchat-sheet {
  width: 100%;
  max-width: 30rem;
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.mmchat-sheet__head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-md) var(--sp-md) var(--sp-sm) var(--sp-lg); }
.mmchat-sheet__head h2 { margin: 0; font-size: var(--t-lg); font-weight: 700; }
.mmchat-sheet__body { overflow-y: auto; padding: 0 var(--sp-lg) var(--sp-lg); }
.mmchat-pick { display: flex; align-items: center; gap: var(--sp-2-5); padding: var(--sp-2) 0; cursor: pointer; }
.mmchat-pick input { width: 1.1rem; height: 1.1rem; accent-color: var(--tx-0); }
.mmchat-field { display: block; margin-bottom: var(--sp-md); }
.mmchat-field span { display: block; margin-bottom: var(--sp-1); font-size: var(--t-sm); color: var(--tx-2); }
.mmchat-field input, .mmchat-row input {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--bdr-def);
  border-radius: var(--r-md);
  background: var(--bg-base);
  font-size: 1rem;
}
.mmchat-row { display: flex; align-items: center; gap: var(--sp-2); }
.mmchat-row input { width: auto; flex: 1; }
.mmchat-seg { display: flex; gap: var(--sp-1); padding: var(--sp-1); margin-bottom: var(--sp-md); background: var(--bg-el); border-radius: var(--r-md); }
.mmchat-seg button { flex: 1; padding: var(--sp-2); border-radius: var(--r-sm); }
.mmchat-seg button.is-on { background: var(--bg-surface); font-weight: 700; }
.mmchat-hint { margin: var(--sp-sm) 0; color: var(--tx-2); font-size: var(--t-sm); }
.mmchat-error { margin: var(--sp-sm) 0; color: var(--er); font-size: var(--t-sm); }
.mmchat-toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  top: calc(var(--sp-md) + env(safe-area-inset-top));
  transform: translateX(-50%);
  max-width: 90%;
  padding: var(--sp-2) var(--sp-md);
  background: var(--er-bg);
  color: var(--er);
  border: 1px solid var(--er-bd);
  border-radius: var(--r-md);
  cursor: pointer;
}

/* ── Mobil: Thread als eigene Ebene ────────────── */
@media (max-width: 47.99rem) {
  .mmchat.has-thread .mmchat-view { display: none; }
  .mmchat-thread { border-left: 0; }
}

/* ── Desktop / Admin-Surface ───────────────────── */
@media (min-width: 48rem) {
  .mmchat { grid-template-columns: 17.5rem 1fr; }
  .mmchat.has-thread { grid-template-columns: 17.5rem 1fr 22rem; }
  .mmchat.has-channel .mmchat-side, .mmchat-side { display: flex; }
  .mmchat-view { display: flex; }
  .mmchat-back { display: none; }
  .mmchat-sheet-bg { align-items: center; }
  .mmchat-sheet { border-radius: var(--r-lg); }
}
