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

/* --- Theme Variables --- */
:root {
  /* Light mode (default) */
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #e8e8e8;
  --bg-input: #ffffff;
  --border: #e0e0e0;
  --text-primary: #1a1a1a;
  --text-secondary: #666666;
  --text-muted: #999999;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --accent-light: rgba(34, 197, 94, 0.1);
  --own-bubble: #22c55e;
  --own-bubble-text: #ffffff;
  --peer-bubble: #f0f0f0;
  --peer-bubble-text: #1a1a1a;
  --header-bg: #ffffff;
  --input-bg: #f5f5f5;
  --input-border: #e0e0e0;
  --system-text: #999999;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg-primary: #1e1e2e;
  --bg-secondary: #181825;
  --bg-tertiary: #313244;
  --bg-input: #1e1e2e;
  --border: #313244;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0a0;
  --text-muted: #777777;
  --accent: #4ade80;
  --accent-hover: #22c55e;
  --accent-light: rgba(74, 222, 128, 0.1);
  --own-bubble: #1e5a35;
  --own-bubble-text: #e8e8e8;
  --peer-bubble: #353548;
  --peer-bubble-text: #e8e8e8;
  --header-bg: #181825;
  --input-bg: #181825;
  --input-border: #313244;
  --system-text: #8b8b8b;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  transition: background 0.2s, color 0.2s;
  overscroll-behavior: none; /* Prevent pull-to-refresh on mobile */
}

.screen { min-height: 100vh; min-height: 100dvh; overflow-y: auto; }
#chat.screen { display: flex; flex-direction: column; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; position: relative; }

/* Chat body: side-by-side layout for chat + video */
.chat-body { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.chat-main { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }

/* Landing */
.landing-box {
  max-width: 400px;
  margin: 0 auto;
  padding: 60px 24px;
}

.landing-box h1 {
  font-size: 2rem;
  margin-bottom: 4px;
}

.landing-box p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 1rem;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--accent);
}

.button-group { margin-top: 12px; }

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

[data-theme="dark"] .btn-primary {
  color: #000;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-secondary:hover { opacity: 0.85; }

.divider {
  text-align: center;
  color: var(--text-muted);
  margin: 20px 0;
  position: relative;
}

.divider::before,
.divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}

.divider::before { left: 0; }
.divider::after { right: 0; }

/* Chat */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  gap: 8px;
  min-height: 48px;
}

.chat-header > span:first-child {
  overflow: hidden;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

#roomInfo {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.9rem;
}

.chat-header > span:last-child {
  flex-shrink: 0;
}

.room-code {
  background: var(--bg-tertiary);
  padding: 4px 12px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-primary);
  transition: background 0.15s;
}

.room-code:hover { opacity: 0.8; }

.share-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--accent, #22c55e);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s;
  min-height: 44px;
}

.share-btn:hover { opacity: 0.85; }

.share-btn-icon { display: inline-flex; align-items: center; }

.share-btn-label { white-space: nowrap; }

/* Charge indicator (circular arc) */
.charge-indicator {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.charge-indicator:hover {
  background: var(--bg-tertiary);
}

.charge-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: 700;
  color: var(--text-primary);
  pointer-events: none;
  line-height: 1;
}

/* Charge detail popup */
.charge-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.charge-popup-content {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  text-align: center;
  max-width: 300px;
  width: 90%;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  font-size: 0.9rem;
}

/* Theme toggle */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  margin-right: 4px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover { background: var(--bg-tertiary); }

.messages {
  flex: 1;
  overflow-y: auto;
  overflow-anchor: auto;
  padding: 16px;
  background: var(--bg-secondary);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.messages::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.msg {
  margin-bottom: 12px;
  max-width: min(70%, 600px);
  animation: msgIn 0.2s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.own {
  margin-left: auto;
}

.msg-name {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.msg.own .msg-name { text-align: right; }

.msg-bubble {
  padding: 8px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-wrap: break-word;
  box-shadow: var(--shadow);
}

.msg-bubble.msg-collapsed,
.msg-original.msg-collapsed {
  max-height: 150px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}

.msg-expand-toggle {
  display: block;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 0;
  font-weight: 600;
}

.msg-bubble.msg-collapsed .msg-expand-toggle {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, var(--peer-bubble) 50%);
  padding: 20px 14px 4px;
  text-align: center;
}

.msg-original.msg-collapsed .msg-expand-toggle {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, var(--bg-secondary) 50%);
  padding: 20px 14px 4px;
  text-align: center;
}

.msg.own .msg-bubble.msg-collapsed .msg-expand-toggle {
  background: linear-gradient(transparent, var(--own-bubble) 50%);
}

.msg.own .msg-expand-toggle {
  color: #000;
}

[data-theme="dark"] .msg.own .msg-expand-toggle {
  color: var(--own-bubble-text);
}

/* Streaming translation cursor */
.msg-bubble.streaming::after {
  content: '|';
  animation: blink-cursor 0.7s infinite;
  color: var(--accent);
  font-weight: 300;
}
@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.inc-pending { opacity: 0.6; font-style: italic; }

.msg.own .msg-bubble {
  background: var(--own-bubble);
  color: var(--own-bubble-text);
  border-bottom-right-radius: 4px;
}

.msg.peer .msg-bubble {
  background: var(--peer-bubble);
  color: var(--peer-bubble-text);
  border-bottom-left-radius: 4px;
}

.msg-original {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 4px 14px;
  border-left: 2px solid var(--peer-bubble);
  line-height: 1.5;
}

.msg.own .msg-original {
  text-align: right;
  border-left: none;
  border-right: 2px solid var(--own-bubble);
}

.msg-solo-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  padding: 4px 14px;
  text-align: right;
  font-style: italic;
  border-right: 2px solid var(--accent);
  line-height: 1.4;
}
.msg-solo-preview.streaming::after {
  content: '|';
  animation: blink-cursor 0.7s infinite;
  color: var(--accent);
  font-weight: 300;
}

.msg-failed {
  font-size: 0.7rem;
  color: #e74c3c;
  margin-top: 4px;
  padding-left: 14px;
  font-style: italic;
}

.msg-system {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin: 4px 0;
  padding: 4px 16px;
  opacity: 0.8;
}

.empty-state-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 48px 24px;
  text-align: center;
  opacity: 0;
  animation: fadeInWelcome 0.6s 0.5s forwards;
}
.empty-state-welcome .welcome-icon { color: var(--text-muted); }
.empty-state-welcome .welcome-title { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); }
.empty-state-welcome .welcome-desc { font-size: 0.85rem; color: var(--text-muted); max-width: 320px; line-height: 1.5; }
@keyframes fadeInWelcome { to { opacity: 1; } }
@media (max-width: 480px) {
  .empty-state-welcome { padding: 24px 16px; gap: 6px; }
  .empty-state-welcome .welcome-title { font-size: 1rem; }
  .empty-state-welcome .welcome-desc { font-size: 0.8rem; max-width: 280px; }
}

/* Media control bar (Teams-style) */
.media-bar {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 6px 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.media-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.15s;
  min-width: 64px;
}

.media-btn:hover {
  background: var(--border);
}

.media-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.media-btn.muted {
  background: var(--bg-tertiary);
  border-color: var(--text-muted);
  opacity: 0.7;
}

.media-btn.speaking {
  /* No animation on mic button — avatar shows speaking state */
}

.media-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.media-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.media-btn.active .media-label {
  color: #fff;
}

.chat-input {
  display: flex;
  align-items: flex-end;
  padding: 8px 12px;
  gap: 8px;
  background: var(--header-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

/* ProseMirror editor container */
.chat-input #msgInput {
  flex: 1;
  min-width: 0;
  max-height: 120px;
}

.chat-input #msgInput .ProseMirror {
  padding: 10px 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  overflow-y: hidden;
  line-height: 1.4;
  max-height: 120px;
  outline: none;
  word-wrap: break-word;
  white-space: pre-wrap;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input #msgInput .ProseMirror:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.chat-input #msgInput .ProseMirror p {
  margin: 0;
}

/* Placeholder */
.chat-input #msgInput .ProseMirror.pm-empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  position: absolute;
  font-style: normal;
}

/* Disabled state */
.chat-input #msgInput .ProseMirror.pm-disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-input .btn { width: auto; border-radius: 20px; }

/* --- Voice Input Button --- */
.voice-input-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  padding: 0;
}
.voice-input-btn:hover {
  background: rgba(34, 197, 94, 0.1);
  color: var(--accent);
}
.voice-input-btn.recording {
  background: #ef4444;
  color: #fff;
  animation: voice-pulse-record 1.5s infinite;
}
.voice-input-btn.recording svg {
  display: none;
}
.voice-input-btn.recording::after {
  content: '';
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 2px;
}
@keyframes voice-pulse-record {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* --- Voice Recording Indicator Bar --- */
.voice-recording-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.voice-cancel-btn {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.voice-cancel-btn:hover {
  background: rgba(239, 68, 68, 0.1);
}
.voice-waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 24px;
}
.voice-wave-bar {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: voice-wave 0.8s ease-in-out infinite;
}
.voice-wave-bar:nth-child(1) { height: 8px; animation-delay: 0s; }
.voice-wave-bar:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.voice-wave-bar:nth-child(3) { height: 12px; animation-delay: 0.2s; }
.voice-wave-bar:nth-child(4) { height: 20px; animation-delay: 0.3s; }
.voice-wave-bar:nth-child(5) { height: 10px; animation-delay: 0.4s; }
.voice-wave-bar:nth-child(6) { height: 18px; animation-delay: 0.15s; }
.voice-wave-bar:nth-child(7) { height: 14px; animation-delay: 0.25s; }
.voice-wave-bar:nth-child(8) { height: 22px; animation-delay: 0.35s; }
.voice-wave-bar:nth-child(9) { height: 8px; animation-delay: 0.45s; }
.voice-wave-bar:nth-child(10) { height: 16px; animation-delay: 0.05s; }
@keyframes voice-wave {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1.2); }
}
.voice-timer {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Typing indicator */
.typing-indicator {
  padding: 4px 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Voice button */
.btn-voice {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: background 0.2s;
  flex-shrink: 0;
}

.btn-voice:hover { background: var(--bg-tertiary); }

/* Live mode toggle */
.btn-live-toggle {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  border: 2px solid var(--border);
  font-size: 0.7rem;
  font-weight: 800;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 20px;
  flex-shrink: 0;
  letter-spacing: 1px;
  transition: all 0.2s;
  text-transform: uppercase;
}

.btn-live-toggle:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.btn-live-toggle.active {
  background: #ef4444;
  color: #fff;
  border-color: #ef4444;
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
  animation: pulse-live 1.5s infinite;
}

@keyframes pulse-live {
  0%, 100% { box-shadow: 0 0 8px rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 16px rgba(239, 68, 68, 0.7); }
}

.btn-voice.recording {
  background: #ef4444;
  animation: pulse-voice 1s infinite;
}

.theme-toggle.recording {
  color: #ef4444;
  animation: pulse-voice 1s infinite;
}

@keyframes pulse-voice {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Custom tooltip — rendered via JS to avoid clipping */
.tip-popup {
  position: fixed;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 9999;
  line-height: 1.3;
}
[data-theme="dark"] .tip-popup {
  background: rgba(255, 255, 255, 0.9);
  color: #000;
}

/* Translation loading indicator */
@keyframes pulse-translating {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.msg-translating .msg-bubble {
  animation: pulse-translating 1.2s ease-in-out infinite;
}

/* Member count badge */
.member-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 10px;
  padding: 0 6px;
}

[data-theme="dark"] .member-badge {
  color: #000;
}

[data-theme="dark"] .media-btn:not(.active):not(.media-btn-leave) {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .media-btn:not(.active):not(.media-btn-leave):hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Timestamp */
.msg-time {
  display: block;
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.msg.own .msg-time {
  text-align: right;
}

/* Connection status banner */
.connection-banner {
  background: #f59e0b;
  color: #000;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
  animation: slideDown 0.3s ease-out;
  letter-spacing: 0.3px;
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Copy button */
.msg-copy {
  display: none;
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 6px;
  padding: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}

.msg-copy:hover { background: var(--border); color: var(--text-primary); }

.msg {
  position: relative;
}

.msg:hover .msg-copy {
  display: block;
}

.msg.own .msg-copy {
  right: auto;
  left: 4px;
}

/* --- Emoji Reactions --- */
.msg-reactions {
  display: none;
  position: absolute;
  top: -32px;
  right: 8px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 10;
  animation: popIn 0.15s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.9) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.msg.own .msg-reactions {
  right: auto;
  left: 8px;
}

.msg:hover .msg-reactions,
.msg.msg-touched .msg-reactions { display: flex; }

.react-btn {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  transition: transform 0.1s, background 0.1s;
}

.react-btn:hover { background: var(--bg-tertiary); transform: scale(1.2); }

.msg-reaction-display {
  display: flex;
  gap: 4px;
  padding: 4px 14px;
  flex-wrap: wrap;
}

.msg-reaction-display:empty { display: none; }

.reaction-badge {
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.reaction-badge:hover { transform: scale(1.05); }

/* --- Message Actions (reply, edit, delete) --- */
.msg-actions {
  display: none;
  position: absolute;
  top: -32px;
  left: 8px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 10;
  gap: 2px;
  animation: popIn 0.15s ease-out;
}

.msg.own .msg-actions {
  left: auto;
  right: 8px;
}

.msg:hover .msg-actions,
.msg.msg-touched .msg-actions { display: flex; }

.msg-action-btn {
  background: none;
  border: none;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--text-secondary);
  transition: background 0.1s, color 0.1s;
  display: inline-flex;
  align-items: center;
}

.msg-action-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* --- Image messages --- */
.msg-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  margin-top: 4px;
}

/* --- Reply quote --- */
.msg-reply-quote {
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  margin-bottom: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--accent-light);
  border-radius: 0 4px 4px 0;
  max-height: 60px;
  overflow: hidden;
}

.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  font-size: 0.85rem;
  color: var(--text-secondary);
  animation: slideDown 0.15s ease-out;
}

.reply-preview .reply-close {
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  border: none;
  background: none;
  color: var(--text-muted);
  transition: background 0.1s;
}

.reply-preview .reply-close:hover { background: var(--border); }

/* --- Edit indicator --- */
.msg-edited {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 2px;
  padding-left: 14px;
}

.msg.own .msg-edited {
  text-align: right;
  padding-left: 0;
  padding-right: 14px;
}

/* --- File attach button --- */
.btn-attach {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.btn-attach:hover { background: var(--bg-tertiary); }

/* --- Read Receipts (Seen) --- */
.msg-seen {
  font-size: 0.65rem;
  color: var(--accent);
  text-align: right;
  padding-right: 14px;
  margin-top: 2px;
}

/* --- @Mentions --- */
.mention {
  color: var(--accent);
  font-weight: 600;
  background: var(--accent-light);
  padding: 0 2px;
  border-radius: 2px;
}

.msg.mentioned {
  border-left: 3px solid var(--accent);
}

.mention-suggestions {
  position: absolute;
  bottom: 100%;
  left: 0;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 150px;
  overflow-y: auto;
  z-index: 20;
  display: none;
}

.mention-suggestion {
  padding: 6px 12px;
  cursor: pointer;
  font-size: 0.9rem;
}

.mention-suggestion:hover {
  background: var(--accent-light);
}

/* --- Message Search --- */
.search-bar {
  display: flex;
  padding: 6px 12px;
  gap: 8px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.search-bar input {
  flex: 1;
  padding: 8px 14px;
  border: 1px solid var(--input-border);
  border-radius: 20px;
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-bar button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
}

/* --- Search highlight --- */
.search-highlight {
  background: #ff8c00;
  color: #fff;
  border-radius: 3px;
  padding: 1px 3px;
  font-weight: 600;
}

/* --- Image download button --- */
.msg-download {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  padding: 2px 8px;
  margin-top: 4px;
}

.msg-download:hover {
  text-decoration: underline;
}

/* Tablet: slightly wider bubbles */
@media (max-width: 768px) {
  .msg {
    max-width: 85%;
  }
}

/* History sidebar (ChatGPT/Claude-style) */
.history-sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 300px;
  max-width: 85vw;
  background: var(--bg-primary, #fafafa);
  border-right: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 16px rgba(0,0,0,0.1);
  animation: slideInLeft 0.2s ease-out;
}

.history-sidebar.fullscreen {
  width: 100%;
  max-width: 100%;
  z-index: 50;
  border-right: none;
}

@keyframes slideInLeft {
  from { transform: translateX(-100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.history-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.history-sidebar-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.history-sidebar-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.history-sidebar-close:hover { background: var(--bg-tertiary); }

.history-sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.history-sidebar-loading {
  text-align: center;
  color: var(--text-muted);
  padding: 20px;
  font-size: 0.85rem;
}

.history-sidebar-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 16px;
  font-size: 0.85rem;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  margin: 2px 0;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}

.history-item:hover { background: var(--bg-tertiary, rgba(0,0,0,0.05)); }
.history-item.active { border-left-color: var(--accent, #22c55e); background: var(--bg-tertiary, rgba(0,0,0,0.05)); }
.history-item.selected { background: var(--accent-bg, rgba(34, 197, 94, 0.1)); border-left-color: var(--accent, #22c55e); }

.history-item-code {
  font-weight: 600;
  font-family: monospace;
  font-size: 0.9rem;
  color: var(--text-primary);
  letter-spacing: 1px;
}

.history-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.history-item-badge {
  display: inline-block;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--accent, #22c55e);
  color: #fff;
  font-weight: 600;
  margin-left: 6px;
}

/* History message viewer (replaces main messages area temporarily) */
.history-viewer {
  position: absolute;
  inset: 0;
  background: var(--bg-primary, #fafafa);
  z-index: 35;
  display: flex;
  flex-direction: column;
}

.history-viewer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary, #f0f0f0);
  flex-shrink: 0;
}

.history-viewer-back {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
}
.history-viewer-back:hover { background: var(--bg-tertiary); }

.history-viewer-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.history-viewer-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
}

.history-msg {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.history-msg.me {
  align-self: flex-end;
  background: var(--msg-own-bg, #dcfce7);
  border-bottom-right-radius: 4px;
}

.history-msg.them {
  align-self: flex-start;
  background: var(--bg-tertiary, #e8edf2);
  border-bottom-left-radius: 4px;
}

.history-msg-name {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.history-msg-text {
  color: var(--text-primary);
}

.history-msg-translations {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(0,0,0,0.06);
}

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

/* Mobile responsiveness */
/* Hamburger menu - hidden on desktop */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-primary);
  align-items: center;
  justify-content: center;
}

.hamburger-btn:hover { background: var(--bg-tertiary); }

@media (max-width: 480px) {
  .hamburger-btn { display: flex; align-items: center; }

  .header-actions {
    display: none;
    position: absolute;
    top: 100%;
    right: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 8px;
    flex-direction: column;
    gap: 4px;
    z-index: 50;
    min-width: 160px;
  }

  .header-actions.open {
    display: flex;
  }

  .header-actions .theme-toggle,
  .header-actions .charge-indicator {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.95rem;
    gap: 8px;
  }

  .header-actions .theme-toggle::after {
    font-size: 0.85rem;
    color: var(--text-secondary);
  }
  #profileBtn.theme-toggle::after { content: 'プロフィール'; }
  #searchBtn.theme-toggle::after { content: '検索'; }
  #summaryBtn.theme-toggle::after { content: '概要'; }
  #historyBtn.theme-toggle::after { content: '履歴'; }
  #logoutBtn.theme-toggle::after { content: 'ログアウト'; }
  #themeToggle.theme-toggle::after { content: 'テーマ切替'; }

  .header-actions .theme-toggle:hover,
  .header-actions .charge-indicator:hover {
    background: var(--bg-tertiary);
  }

  .chat-header {
    position: relative;
  }

  .stt-threshold-row {
    display: flex !important;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
  }

  .stt-threshold-row:hover {
    background: var(--bg-tertiary);
  }
}

/* STT Threshold Slider */
.stt-threshold-row {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.stt-threshold-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary, var(--text-muted));
  white-space: nowrap;
  cursor: default;
}

.stt-slider, .settings-slider {
  flex: 1;
  height: 6px;
  min-width: 80px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.stt-slider::-webkit-slider-thumb, .settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #22c55e);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.stt-slider::-moz-range-thumb, .settings-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #22c55e);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.stt-threshold-value {
  font-size: 0.8rem;
  font-family: monospace;
  color: var(--text-secondary, var(--text-muted));
  min-width: 2.5em;
  text-align: right;
}

@media (max-width: 480px) {
  .msg {
    max-width: 85%;
  }

  .btn, .btn-primary, .btn-secondary {
    min-height: 44px;
  }

  .chat-header {
    font-size: 0.85rem;
    padding: 10px 12px;
  }

  .btn-voice {
    font-size: 1.5rem;
    padding: 10px;
    min-width: 44px;
    min-height: 44px;
  }

  .btn-live-toggle {
    padding: 8px 12px;
    font-size: 0.75rem;
    min-height: 44px;
  }

  .chat-input .btn {
    min-height: 44px;
  }

  #roomInfo {
    font-size: 0.8rem;
  }

  .media-bar {
    gap: 4px;
    padding: 4px 8px;
  }

  .media-btn {
    font-size: 0.85rem;
    padding: 6px 10px;
    min-width: 52px;
    min-height: 44px;
    border-radius: 10px;
  }

  .media-label {
    font-size: 0.65rem;
  }

  .chat-input {
    gap: 4px;
    padding: 6px 8px;
  }

  .chat-input .btn-primary {
    padding: 8px 14px;
    font-size: 0.85rem;
    min-width: 52px;
  }

  /* Hide screen share on mobile (rarely used, saves space) */
  #screenShareBtn { display: none; }

  /* Larger translation text on mobile */
  .msg-original {
    font-size: 0.82rem;
    padding: 6px 14px;
  }

  .msg-solo-preview {
    font-size: 0.82rem;
    padding: 6px 14px;
  }

  /* Emoji button bigger tap target */
  .btn-attach {
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Input text slightly larger on mobile */
  .chat-input #msgInput .ProseMirror {
    font-size: 1rem;
    padding: 10px 14px;
  }
}

/* Participants panel */
.participants-panel {
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  max-height: 200px;
  overflow-y: auto;
}

.participant-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.participant-icons {
  display: flex;
  gap: 4px;
  font-size: 0.75rem;
  opacity: 0.6;
}

.participant-icons .active {
  opacity: 1;
}

/* ==============================
   Video Grid
   ============================== */

/* Video grid: right side panel on desktop, floating on mobile */
.video-grid {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  background: #000;
  width: 280px;
  min-width: 160px;
  max-width: 70vw;
  flex-shrink: 0;
  overflow-y: auto;
  position: relative;
}

/* Resize handle between chat and video panel */
.video-resize-handle {
  width: 8px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
}

.video-resize-handle:hover,
.video-resize-handle.dragging {
  background: var(--accent);
}

/* Presentation layout (screen share active) — wider panel */
.video-grid.presentation-layout {
  width: 380px;
}

.video-grid.presentation-layout .video-item.screen-share {
  aspect-ratio: auto;
}

.video-grid.presentation-layout .video-thumbnails {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.video-grid.presentation-layout .video-thumbnails .video-item {
  width: 100%;
  height: auto;
  aspect-ratio: 16/9;
}

.video-item {
  position: relative;
  background: #111;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16/9;
  min-height: 0;
}

.video-item video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.video-item {
  aspect-ratio: auto;
}

.video-item.local video {
  transform: scaleX(-1);
}

.video-item.audio-only {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a2e;
}

.audio-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  transition: box-shadow 0.2s;
}

.audio-avatar {
  position: relative;
  z-index: 2;
}

.video-name {
  position: absolute;
  bottom: 6px;
  left: 8px;
  color: #fff;
  font-size: 0.75rem;
  background: rgba(0,0,0,0.6);
  padding: 2px 8px;
  border-radius: 4px;
}

.video-subtitle {
  position: absolute;
  bottom: 30px;
  left: 8px;
  right: 8px;
  color: #fff;
  font-size: 0.85rem;
  background: rgba(0,0,0,0.7);
  padding: 4px 10px;
  border-radius: 6px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.video-subtitle:not(:empty) {
  opacity: 1;
}

/* Media control buttons (camera, screen share) */
.btn-media {
  background: none;
  border: 2px solid var(--border);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 50%;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-media:hover {
  background: var(--bg-tertiary);
}

.btn-media.active {
  background: #ef4444;
  border-color: #ef4444;
}

@media (max-width: 480px) {
  /* Mobile: floating PiP instead of side panel */
  .chat-body { flex-direction: column; }

  .video-grid {
    position: fixed;
    bottom: 140px;
    right: 8px;
    width: 120px !important;
    max-height: 200px;
    z-index: 100;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  }

  .video-grid.presentation-layout {
    width: 180px !important;
  }

  .video-item {
    aspect-ratio: 4/3;
  }

  .participants-panel {
    position: fixed;
    top: 48px;
    left: 0;
    right: 0;
    z-index: 100;
    max-height: 60vh;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  }

  .btn-media {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Pinned message */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--accent-light);
  border-bottom: 1px solid var(--accent);
  font-size: 0.85rem;
  color: var(--text-primary);
  flex-shrink: 0;
}

.pinned-bar .pin-icon {
  flex-shrink: 0;
}

.pinned-bar .pin-text {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.pinned-bar .pin-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0 4px;
}

/* KaTeX LaTeX rendering in messages */
.msg-bubble .katex {
  font-size: 1.1em;
}

.msg-bubble .katex-display {
  margin: 6px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.msg-bubble .katex-display > .katex {
  font-size: 1em;
}

.katex-error {
  color: #b91c1c;
  font-size: 0.85em;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
}

[data-theme="dark"] .katex-error {
  color: #f87171;
}

/* Inline code in messages */
.inline-code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  font-size: 0.85em;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

/* Auto-linked URLs in messages */
.msg-link {
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}

.msg.own .msg-link {
  color: #000;
  text-decoration: underline;
  font-weight: 600;
}

.msg.own .inline-code {
  background: rgba(0, 0, 0, 0.12);
  color: #000;
  border-color: rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .inline-code {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .msg.own .msg-link {
  color: var(--own-bubble-text);
}

[data-theme="dark"] .msg.own .inline-code {
  background: rgba(255, 255, 255, 0.15);
  color: var(--own-bubble-text);
  border-color: rgba(255, 255, 255, 0.2);
}

.msg.own .mention {
  color: #000;
  font-weight: 600;
}

[data-theme="dark"] .msg.own .mention {
  color: var(--own-bubble-text);
}

/* Emoji picker */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  left: 40px;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  z-index: 30;
  max-width: 280px;
}

.emoji-item {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  line-height: 1;
}

.emoji-item:hover {
  background: var(--bg-tertiary);
}

/* Font size options */
[data-fontsize="small"] { font-size: 14px; }
[data-fontsize="medium"] { font-size: 16px; }
[data-fontsize="large"] { font-size: 18px; }
[data-fontsize="xlarge"] { font-size: 20px; }

/* QR Code share modal */
.qr-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.qr-modal-content {
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 24px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

.qr-modal-content h3 {
  margin-bottom: 16px;
  color: var(--text-primary);
}

.qr-modal-content img {
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

/* Drag & drop indicator */
.messages.drag-over {
  outline: 3px dashed var(--accent);
  outline-offset: -3px;
  background: var(--accent-light) !important;
}

/* Typing animation dots */
.typing-dots::after {
  content: '';
  animation: typing-dots 1.2s infinite;
}

@keyframes typing-dots {
  0% { content: '.'; }
  33% { content: '..'; }
  66% { content: '...'; }
}

/* Online indicator dot */
.online-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 6px;
  vertical-align: middle;
}

/* Participant avatar circle */
.participant-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Message avatar */
.msg-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  margin-right: 4px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 12px 16px;
  letter-spacing: 0.5px;
}

.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* New message indicator */
.new-msg-indicator {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 50;
  animation: bounce-in 0.3s ease;
}

@keyframes bounce-in {
  0% { transform: translateX(-50%) translateY(20px); opacity: 0; }
  100% { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* Touch feedback for mobile */
.msg:active {
  opacity: 0.85;
  transition: opacity 0.1s;
}

.media-btn:active {
  transform: scale(0.95);
  transition: transform 0.1s;
}

.btn-primary:active {
  transform: scale(0.95);
}

/* Leave button (red) */
.media-btn-leave {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.media-btn-leave:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.media-btn-leave .media-label {
  color: #fff;
}

/* Extra-narrow phones (360px and below) */
@media (max-width: 380px) {
  .chat-header {
    font-size: 0.75rem;
    padding: 8px 8px;
    gap: 2px;
  }

  .charge-indicator {
    width: 28px;
    height: 28px;
  }

  .charge-text {
    font-size: 0.4rem;
  }

  .theme-toggle {
    font-size: 0.85rem;
    padding: 2px 4px;
  }

  .room-code {
    font-size: 0.65rem;
    padding: 2px 6px;
  }

  .media-btn {
    min-width: 44px;
    padding: 6px 6px;
  }

  .media-label {
    display: none;
  }

  .media-icon {
    font-size: 1.1rem;
  }

  .chat-input #msgInput .ProseMirror {
    font-size: 0.9rem;
    padding: 8px 10px;
  }

  .qr-modal-content {
    max-width: 280px;
    padding: 16px;
  }

  .landing-box {
    max-width: calc(100vw - 32px);
  }

  #roomInfo {
    font-size: 0.7rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* --- iOS Safari fixes --- */
input, select, textarea, button {
  -webkit-appearance: none;
}

/* Prevent iOS zoom on input focus & fix keyboard pushing content */
@supports (-webkit-touch-callout: none) {
  input, select, textarea {
    font-size: 16px !important;
  }

  .chat-input {
    position: sticky;
    bottom: 0;
  }
}

/* --- Print --- */
@media print {
  /* Hide everything */
  * { visibility: hidden !important; }
  /* Show only QR modal and its children */
  .qr-modal, .qr-modal * { visibility: visible !important; }
  .qr-modal {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: auto !important;
    background: #fff !important;
    display: block !important;
  }
  .qr-modal-content {
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
    border: none !important;
    padding: 40px !important;
    text-align: center !important;
    max-width: 100% !important;
    position: static !important;
  }
  .qr-modal-content h3 { color: #000 !important; font-size: 2rem !important; margin-bottom: 12px !important; }
  #qrRoomCode { color: #000 !important; font-size: 2.5rem !important; }
  #qrCode img { width: 300px !important; height: 300px !important; }
  #qrUrl { color: #333 !important; font-size: 1rem !important; }
  #qrCopyBtn, #qrClose { display: none !important; visibility: hidden !important; height: 0 !important; overflow: hidden !important; }
}

/* --- Wizard card layout (centered steps) --- */
.messages.wizard-active {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
}
.messages.wizard-active > * {
  flex-shrink: 0;
}

.wizard-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 28px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06);
}

[data-theme="dark"] .wizard-card {
  background: var(--bg-secondary);
  border-color: var(--border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

.wizard-card .wizard-heading {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
  color: var(--text-primary);
}

.wizard-card .wizard-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
  text-align: center;
  line-height: 1.5;
}

.wizard-card .wizard-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.wizard-card .wizard-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

.wizard-card .wizard-input::placeholder {
  color: var(--text-muted);
}

.wizard-card .wizard-btn {
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s, transform 0.1s;
  margin-top: 16px;
}

[data-theme="dark"] .wizard-card .wizard-btn {
  color: #000;
}

.wizard-card .wizard-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.wizard-card .wizard-btn:active {
  transform: scale(0.98);
}

.wizard-card .wizard-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

/* Wizard option cards (create/join step) */
.wizard-option-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wizard-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-primary);
}

[data-theme="dark"] .wizard-option {
  background: var(--bg-tertiary);
  border-color: var(--border);
}

.wizard-option:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.12);
}

.wizard-option-icon {
  font-size: 1.5rem;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border-radius: 10px;
}

[data-theme="dark"] .wizard-option-icon {
  background: var(--bg-primary);
}

.wizard-option-text h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--text-primary);
}

.wizard-option-text p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.wizard-option-arrow {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* Subscription card in lobby */
.sub-card {
  margin-top: 12px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  background: var(--bg-primary);
}
.sub-card--free {
  background: linear-gradient(135deg, rgba(34,197,94,0.04) 0%, rgba(34,197,94,0.01) 100%);
}
.sub-card--premium {
  border-color: rgba(34,197,94,0.3);
  background: linear-gradient(135deg, rgba(34,197,94,0.06) 0%, rgba(34,197,94,0.02) 100%);
}
[data-theme="dark"] .sub-card { background: var(--bg-tertiary); }
[data-theme="dark"] .sub-card--free { background: linear-gradient(135deg, rgba(74,222,128,0.06) 0%, rgba(74,222,128,0.02) 100%); }
[data-theme="dark"] .sub-card--premium { border-color: rgba(74,222,128,0.3); background: linear-gradient(135deg, rgba(74,222,128,0.08) 0%, rgba(74,222,128,0.03) 100%); }
.sub-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sub-header-text h4 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.sub-header-text p {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}
.sub-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.sub-icon--free { background: var(--bg-secondary); }
.sub-icon--premium { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; }
.sub-badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}
.sub-badge--free { background: var(--bg-secondary); color: var(--text-muted); }
.sub-badge--active { background: rgba(34,197,94,0.12); color: #16a34a; }
[data-theme="dark"] .sub-badge--active { color: #4ade80; }
.sub-usage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
}
.sub-usage-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  min-width: 90px;
  flex-shrink: 0;
}
.sub-usage-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
}
.sub-usage-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}
.sub-usage-bar-fill--voice { background: #3b82f6; }
.sub-usage-bar-fill--warning { background: #f59e0b; }
.sub-features {
  display: flex;
  gap: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.sub-feature {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.sub-feature-check { color: var(--accent); font-weight: 700; }
.sub-feature-lock { color: var(--text-muted); }
.sub-btn--upgrade {
  width: 100%;
  padding: 10px 20px;
  margin-top: 12px;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s;
}
[data-theme="dark"] .sub-btn--upgrade { color: #000; }
.sub-btn--upgrade:hover { background: var(--accent-hover); }
.sub-btn--manage {
  margin-left: auto;
  padding: 6px 14px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--accent);
  white-space: nowrap;
  transition: background 0.15s;
}
.sub-btn--manage:hover { background: var(--accent-light); }
.sub-btn--manage:disabled { opacity: 0.5; cursor: not-allowed; }

/* Promo code section */
.promo-section {
  margin-top: 12px;
  text-align: center;
}
.promo-toggle-link {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}
.promo-toggle-link:hover {
  color: var(--accent);
}
.promo-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
  justify-content: center;
}
.promo-input {
  flex: 1;
  max-width: 200px;
  padding: 8px 12px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  text-transform: uppercase;
}
.promo-input::placeholder {
  text-transform: none;
}
.promo-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 0.15s;
  white-space: nowrap;
}
[data-theme="dark"] .promo-btn { color: #000; }
.promo-btn:hover { background: var(--accent-hover); }
.promo-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.promo-message {
  font-size: 0.85rem;
  margin-top: 8px;
  min-height: 1.2em;
}
.promo-success { color: var(--accent); }
.promo-error { color: #ef4444; }

/* Wizard language list inside card */
.wizard-card .wizard-lang-item {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transition: all 0.15s;
  display: flex;
  align-items: center;
}

.wizard-card .wizard-lang-item:hover {
  opacity: 0.85;
}

.wizard-card .wizard-lang-item.selected {
  background: var(--accent);
  color: #000;
  font-weight: 600;
}

.wizard-lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.wizard-lang-detected {
  border: 2px solid var(--accent);
  font-weight: 600;
}

@media (max-width: 380px) {
  .wizard-lang-grid {
    grid-template-columns: 1fr;
  }
}

.wizard-card .wizard-back {
  font-size: 0.85rem;
  color: var(--accent);
  cursor: pointer;
  margin-bottom: 12px;
}

.wizard-card .wizard-back:hover {
  text-decoration: underline;
}

@media (max-width: 480px) {
  .wizard-card {
    padding: 24px 20px;
    margin: 0 8px;
    border-radius: 12px;
  }

  .wizard-card .wizard-heading {
    font-size: 1.2rem;
  }

  .wizard-option {
    padding: 14px 16px;
    gap: 12px;
  }

  .wizard-option-icon {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
  }
}

/* RTL support for Arabic/Persian */
[dir="rtl"] .msg.own { align-items: flex-start; }
[dir="rtl"] .msg.own .msg-bubble { margin-left: 0; margin-right: auto; }
[dir="rtl"] .msg.peer .msg-bubble { margin-right: 0; margin-left: auto; }
[dir="rtl"] .msg-name { text-align: right; }
[dir="rtl"] .msg.own .msg-name { text-align: left; }
[dir="rtl"] .msg-original { padding-left: 0; padding-right: 14px; }
[dir="rtl"] .msg.own .msg-original { padding-right: 0; padding-left: 14px; }
[dir="rtl"] .msg-solo-preview { text-align: left; padding-right: 0; padding-left: 14px; }
[dir="rtl"] .chat-input { direction: rtl; }
[dir="rtl"] .msg-time { direction: ltr; }
[dir="rtl"] .msg-edited { direction: ltr; }

/* --- Mobile mic recording: clean compact UI --- */
@media (max-width: 480px) {
  /* Hide local audio-only PiP on mobile (mic button is enough) */
  #video-local.audio-only {
    display: none !important;
  }

  /* When only local audio-only exists, hide the grid entirely */
  .video-grid:has(> #video-local.audio-only:only-child) {
    display: none !important;
  }

  /* Mic active: pulse animation on mic button */
  .media-btn.active#micBtn {
    animation: mic-pulse 2s ease-in-out infinite;
  }

  /* Mic active: collapse non-essential buttons */
  .media-bar.mic-recording #cameraBtn,
  .media-bar.mic-recording #screenShareBtn,
  .media-bar.mic-recording #raiseHandBtn {
    display: none;
  }

  /* Mic active: recording indicator label */
  .media-bar.mic-recording .mic-rec-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.75rem;
    letter-spacing: 0.5px;
  }

  .media-bar.mic-recording .mic-rec-indicator .rec-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    animation: rec-blink 1.2s ease-in-out infinite;
  }
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
}

@keyframes rec-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
