*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --accent: #4f8ef7;
  --text: #e8eaf0;
  --text-muted: #6b7280;
  --bubble-own: #1e3a5f;
  --bubble-other: #1e2130;
  --radius: 12px;
  --sidebar-w: 200px;
  --font: 'Segoe UI', 'Noto Sans JP', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---- Login / Setup shared ---- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
  padding: 1rem;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.login-box h1 { font-size: 1.8rem; text-align: center; color: var(--accent); }
.login-box .subtitle { text-align: center; color: var(--text-muted); font-size: 0.9rem; }

.login-box input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  outline: none;
  width: 100%;
}
.login-box input:focus { border-color: var(--accent); }

.lang-select label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.4rem; display: block; }
.lang-select label .hint { font-size: 0.7rem; opacity: 0.6; }
.lang-buttons { display: flex; gap: 0.5rem; }

.lang-btn {
  flex: 1;
  padding: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
  font-family: var(--font);
}
.lang-btn:hover { border-color: var(--accent); background: rgba(79,142,247,0.08); }
.lang-btn.active { border-color: var(--accent); background: rgba(79,142,247,0.2); color: #fff; }

#join-btn, .login-box button[type="submit"], #submit-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 0.75rem;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.15s;
  width: 100%;
}
#join-btn:hover, #submit-btn:hover { opacity: 0.85; }

/* ---- Chat layout ---- */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.chat-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 0.5rem;
}

.header-left { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
#sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem 0.5rem;
  flex-shrink: 0;
}
#sidebar-toggle:hover { border-color: var(--accent); }
#room-label { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-right { display: flex; align-items: center; gap: 0.4rem; flex-shrink: 0; }
.header-hint { font-size: 0.7rem; color: var(--text-muted); }
.header-divider { width: 1px; height: 18px; background: var(--border); margin: 0 0.2rem; }

.lang-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.45rem;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s;
  opacity: 0.35;
  user-select: none;
}
.lang-toggle:hover { opacity: 0.7; }
.lang-toggle.active { opacity: 1; border-color: var(--accent); background: rgba(79,142,247,0.15); }

#cache-badge {
  font-size: 0.7rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
}

/* ---- Sidebar + main ---- */
.chat-layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.sidebar-section { padding: 0.5rem 0; }
.sidebar-section + .sidebar-section { border-top: 1px solid var(--border); margin-top: 0.25rem; }

.sidebar-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 0.75rem 0.35rem;
}

.room-btn, .dm-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem 0.75rem;
  font-size: 0.88rem;
  font-family: var(--font);
  text-align: left;
  border-radius: 6px;
  margin: 0 0.25rem;
  width: calc(100% - 0.5rem);
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-btn:hover, .dm-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.room-btn.active, .dm-btn.active { background: rgba(79,142,247,0.15); color: var(--text); }
.dm-btn.unread { color: var(--text); font-weight: 600; }

.room-icon { font-size: 0.85rem; color: var(--text-muted); }

.online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.online-dot.is-online { background: #22c55e; }

.sidebar-empty { font-size: 0.8rem; color: var(--text-muted); padding: 0.3rem 0.75rem; font-style: italic; }

/* ---- Messages ---- */
.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg {
  max-width: 72%;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  animation: fadeIn 0.15s ease;
}
.msg.own  { align-self: flex-end;  background: var(--bubble-own);   border-bottom-right-radius: 3px; }
.msg.other { align-self: flex-start; background: var(--bubble-other); border-bottom-left-radius: 3px; }

.msg-header { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.25rem; }
.msg-username { font-size: 0.75rem; font-weight: 600; color: var(--accent); }
.msg-lang-badge { font-size: 0.65rem; color: var(--text-muted); background: rgba(255,255,255,0.05); border-radius: 4px; padding: 0 0.4rem; }
.msg-cache { font-size: 0.65rem; color: #22c55e; margin-left: auto; }

.msg-translations { display: flex; flex-direction: column; gap: 0.35rem; }
.msg-translation { display: flex; align-items: baseline; gap: 0.45rem; font-size: 0.93rem; line-height: 1.45; word-break: break-word; }
.msg-translation.is-source .msg-translation-text { color: var(--text); }
.msg-translation:not(.is-source) .msg-translation-text { color: rgba(232,234,240,0.65); }
.msg-translation-flag { font-size: 1rem; flex-shrink: 0; }
.msg-translation + .msg-translation { border-top: 1px solid rgba(255,255,255,0.06); padding-top: 0.3rem; }

.msg-time { font-size: 0.65rem; color: var(--text-muted); margin-top: 0.4rem; text-align: right; }

#typing-indicator { padding: 0.4rem 1rem; font-size: 0.8rem; color: var(--text-muted); font-style: italic; flex-shrink: 0; }

/* ---- Message input ---- */
#message-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#write-lang-indicator { font-size: 1.2rem; flex-shrink: 0; cursor: default; }

#message-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 1rem;
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
}
#message-input:focus { border-color: var(--accent); }

#message-form button[type="submit"] {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.1rem;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  transition: opacity 0.15s;
  width: auto;
}
#message-form button[type="submit"]:hover { opacity: 0.85; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.88rem;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 999;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-error { background: #7f1d1d; border: 1px solid #ef4444; color: #fca5a5; }
.toast-warn  { background: #78350f; border: 1px solid #f59e0b; color: #fcd34d; }

/* ---- Reactions ---- */
.msg-reactions { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.react-btn {
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; padding: 2px 8px; cursor: pointer; font-size: 0.82rem;
  color: inherit; display: flex; align-items: center; gap: 3px; transition: background 0.15s;
  font-family: var(--font);
}
.react-btn:hover { background: rgba(255,255,255,0.14); }
.react-btn.reacted { background: rgba(79,142,247,0.2); border-color: rgba(79,142,247,0.5); }
.react-btn span { font-size: 0.78rem; color: #a0aec0; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---- Mobile ---- */
@media (max-width: 700px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 220px;
  }
  #sidebar.open { transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,0.5); }
  .msg { max-width: 88%; }
  .header-hint { display: none; }
}

/* Anmeldefehler direkt im Login-Kasten, nicht als fluechtiger Toast */
.auth-error {
  margin: .5rem 0 0;
  padding: .55rem .7rem;
  border-radius: 6px;
  background: rgba(220, 60, 60, .12);
  border: 1px solid rgba(220, 60, 60, .35);
  color: #ff9c9c;
  font-size: .88rem;
  line-height: 1.35;
}
#register-btn {
  margin-top: .5rem;
  background: transparent;
  border: 1px solid currentColor;
  opacity: .85;
}


/* "Konto angelegt, wartet auf Freigabe" ist eine Erfolgsmeldung -- sie lief
   vorher durch die rote Fehler-Optik und sah aus wie ein Fehlschlag. */
.auth-error.auth-pending {
  background: rgba(60, 180, 110, .12);
  border-color: rgba(60, 180, 110, .40);
  color: #8fe0b0;
}
