/* Telegram-like theme variables */
:root {
  --tg-bg: #0e1621;
  --tg-bg-secondary: #17212b;
  --tg-header: #1a2332;
  --tg-header-border: #2d3748;
  --tg-list-item: #1a2332;
  --tg-list-item-active: #252f3d;
  --tg-bubble-in: #2b5278;
  --tg-bubble-out: #2b5278;
  --tg-accent: #5288c1;
  --tg-text: #fff;
  --tg-text-muted: #8b95a5;
  --tg-input-bg: #242f3d;
  --tg-radius: 12px;
  --tg-radius-bubble: 18px;
  --tg-safe-top: env(safe-area-inset-top, 0);
  --tg-safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  font-size: 16px;
}

@media (max-width: 768px) {
  html {
    font-size: 14px;
  }
}

@media (max-width: 380px) {
  html {
    font-size: 13px;
  }
}

html, body {
  width: 100%;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  position: fixed;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* iOS: убрать callout и выделение при долгом нажатии */
@supports (-webkit-touch-callout: none) {
  body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  input, textarea {
    -webkit-user-select: text;
    user-select: text;
  }
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
}

input, textarea, button {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

#app {
  width: 100%;
  height: 100%;
  min-height: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

@supports (-webkit-touch-callout: none) {
  #app {
    min-height: -webkit-fill-available;
    height: -webkit-fill-available;
  }
}

@supports (height: 100svh) {
  #app {
    height: 100svh;
    min-height: 100svh;
  }
}

.auth-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  padding: max(env(safe-area-inset-top), 20px) max(env(safe-area-inset-right), 20px) max(env(safe-area-inset-bottom), 20px) max(env(safe-area-inset-left), 20px);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-box {
  background: rgba(255, 255, 255, 0.98);
  padding: clamp(24px, 5vw, 32px);
  border-radius: 24px;
  width: 100%;
  max-width: min(400px, 90vw);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25), 0 0 0 1px rgba(255,255,255,0.1);
  backdrop-filter: blur(12px);
}

.auth-box h1 {
  color: #333;
  margin-bottom: clamp(20px, 4vw, 25px);
  text-align: center;
  font-size: clamp(24px, 5vw, 28px);
}

.auth-box input {
  width: 100%;
  padding: clamp(12px, 3vw, 15px);
  margin-bottom: 15px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: max(16px, 1rem);
  transition: border 0.3s;
}

.auth-box input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.25);
}
.auth-box input:focus-visible,
.auth-box button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.4);
}

.auth-box button {
  width: 100%;
  padding: clamp(12px, 3vw, 15px);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: max(16px, 1rem);
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: transform 0.2s;
  min-height: 44px;
  position: relative;
  overflow: hidden;
}

.auth-box button:active {
  transform: scale(0.98);
}

.auth-box .link-btn {
  background: transparent;
  color: #667eea;
  text-decoration: underline;
}

.error {
  color: #e74c3c;
  margin-bottom: 15px;
  text-align: center;
  font-size: 14px;
}

.header {
  background: var(--tg-header);
  padding: 12px 16px;
  padding-top: max(var(--tg-safe-top), 12px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--tg-header-border);
  flex-shrink: 0;
  min-height: 56px;
}

.header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.header button {
  background: #667eea;
  color: white;
  border: none;
  padding: clamp(6px, 1.5vw, 8px) clamp(12px, 2.5vw, 16px);
  border-radius: 8px;
  font-size: clamp(12px, 2.5vw, 14px);
  cursor: pointer;
  min-height: 36px;
  min-width: 60px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s;
}

.header button:active {
  transform: scale(0.95);
}
.header button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.6);
}

/* Кнопки-иконки в шапке (единый стиль) */
.header-btn-icon {
  background: #2d3748 !important;
  color: white !important;
  border: none !important;
  border-radius: 8px !important;
  padding: 8px !important;
  margin-right: 6px !important;
  min-width: 40px;
  min-height: 40px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.header-btn-icon:hover {
  background: #3d4758 !important;
}
.header-btn-icon:active {
  transform: scale(0.95);
}
.header-btn-icon:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.5);
}

.rooms-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.rooms-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0;
  -webkit-overflow-scrolling: touch;
  background: var(--tg-bg);
  overscroll-behavior: contain;
}

/* Telegram-style chat list: flat rows, dividers */
.room-item {
  background: var(--tg-list-item);
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  min-height: 72px;
  border-bottom: 1px solid var(--tg-header-border);
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.room-item:hover {
  background: var(--tg-list-item-active);
}

.room-item:active {
  background: var(--tg-list-item-active);
}

.room-avatar {
  width: 50px;
  height: 50px;
  min-width: 50px;
  border-radius: 50%;
  background: var(--tg-bubble-in);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 600;
  flex-shrink: 0;
  position: relative;
}

.room-info {
  flex: 1;
  min-width: 0;
  padding-right: 60px;
}

.room-name {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
  letter-spacing: -0.01em;
}

.room-preview {
  font-size: 0.875rem;
  color: var(--tg-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-time {
  position: absolute;
  top: 12px;
  right: 16px;
  font-size: 0.75rem;
  color: var(--tg-text-muted);
}

.unread-badge {
  position: absolute;
  top: 34px;
  right: 16px;
  background: var(--tg-accent);
  color: white;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.online-indicator {
  width: 12px;
  height: 12px;
  background: #10b981;
  border-radius: 50%;
  position: absolute;
  bottom: 2px;
  right: 2px;
  border: 2px solid var(--tg-header);
}

/* Chat screen header: back left, title, menu right (Telegram-like) */
.chat-screen .header {
  padding: 10px 8px 10px 4px;
  min-height: 52px;
}
.chat-screen .header .header-btn-icon:first-of-type {
  margin-right: 4px;
}
.chat-screen .header > div {
  flex: 1;
  min-width: 0;
  text-align: left;
}
.chat-screen .header h2 {
  font-size: 1rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-status {
  font-size: 0.75rem;
  color: var(--tg-text-muted);
  margin-top: 0;
}

.fab {
  position: fixed;
  bottom: max(var(--tg-safe-bottom), 24px);
  right: max(16px, env(safe-area-inset-right));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: transform 0.2s, background 0.2s;
  box-shadow: 0 4px 14px rgba(82, 136, 193, 0.4);
}

.fab:hover {
  transform: scale(1.05);
  background: #6b9ed4;
}

.fab:active {
  transform: scale(0.95);
}

.fab:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--tg-accent);
}

/* Доп. FAB кнопки (поиск пользователя, по ссылке) — над основной */
.rooms-screen .fab:nth-of-type(2) {
  bottom: max(var(--tg-safe-bottom), 92px) !important;
  width: 48px;
  height: 48px;
  font-size: 1.25rem;
}
.rooms-screen .fab:nth-of-type(3) {
  bottom: max(var(--tg-safe-bottom), 152px) !important;
  width: 48px;
  height: 48px;
  font-size: 1.25rem;
}

.chat-screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.messages-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px 16px;
  background: var(--tg-bg);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.message {
  margin-bottom: 6px;
  display: flex;
  flex-direction: column;
  animation: messageSlideIn 0.2s ease-out;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: scale(0.96);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.message.own {
  align-items: flex-end;
}

.message-author {
  font-size: 0.75rem;
  color: var(--tg-text-muted);
  margin-bottom: 2px;
  padding: 0 4px;
}

/* Telegram-style bubbles */
.message-bubble {
  background: var(--tg-bubble-in);
  padding: 8px 12px 10px;
  border-radius: var(--tg-radius-bubble);
  border-top-left-radius: 4px;
  max-width: min(85%, 320px);
  word-wrap: break-word;
  word-break: break-word;
  position: relative;
  font-size: 1rem;
  line-height: 1.4;
  letter-spacing: -0.01em;
}

.message.own .message-bubble {
  border-top-left-radius: var(--tg-radius-bubble);
  border-top-right-radius: 4px;
  background: var(--tg-bubble-out);
}

.message-bubble strong {
  font-weight: 700;
}

.message-bubble em {
  font-style: italic;
}

.message-bubble code {
  background: rgba(0,0,0,0.25);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.message-reply {
  background: rgba(0,0,0,0.2);
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 8px;
  border-left: 3px solid #667eea;
  font-size: 13px;
  color: #8b95a5;
}

.message-actions {
  position: absolute;
  top: -35px;
  right: 0;
  background: #2d3748;
  border-radius: 8px;
  display: flex;
  gap: 5px;
  padding: 5px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 10;
}

.message-actions button {
  background: transparent;
  border: none;
  color: white;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 14px;
}

.message-actions button:hover {
  background: #1a2332;
}
.message-actions button:focus-visible {
  outline: none;
  background: #1a2332;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.5);
}

.typing-indicator {
  padding: 10px 20px;
  color: #8b95a5;
  font-size: 14px;
  font-style: italic;
}

.message-status {
  font-size: 16px;
  margin-left: 5px;
  color: #10b981;
}

.message-time {
  font-size: 0.6875rem;
  color: var(--tg-text-muted);
  margin-top: 2px;
  padding: 0 4px;
  opacity: 0.9;
}

/* Telegram-style input bar */
.message-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 8px 12px;
  padding-bottom: max(var(--tg-safe-bottom), 8px);
  background: var(--tg-header);
  border-top: 1px solid var(--tg-header-border);
  gap: 6px;
  flex-shrink: 0;
  min-height: 56px;
}

.message-input input {
  flex: 1;
  min-width: 0;
  padding: 10px 16px;
  background: var(--tg-input-bg);
  border: none;
  border-radius: 20px;
  color: var(--tg-text);
  font-size: 1rem;
  outline: none;
  min-height: 40px;
}

.message-input input::placeholder {
  color: var(--tg-text-muted);
}

.message-input input:focus {
  background: var(--tg-list-item-active);
}

.message-input button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: white;
  border: none;
  font-size: 1.125rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
  position: relative;
  overflow: hidden;
}

.message-input button:hover {
  transform: scale(1.05);
}

.message-input button:active {
  transform: scale(0.95);
}
.message-input button:focus-visible,
.attach-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--tg-accent);
}
.message-input input:focus-visible {
  outline: none;
}

.attach-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  background: var(--tg-input-bg);
  color: var(--tg-text);
  border: none;
  font-size: 1.125rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s, background 0.15s;
}

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

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(env(safe-area-inset-top), 20px) max(env(safe-area-inset-right), 20px) max(env(safe-area-inset-bottom), 20px) max(env(safe-area-inset-left), 20px);
  z-index: 1000;
  animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: #1a2332;
  padding: clamp(24px, 4vw, 28px);
  border-radius: 24px;
  width: 100%;
  max-width: min(400px, 90vw);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  animation: modalSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-content h3 {
  margin-bottom: clamp(15px, 3vw, 20px);
  font-size: clamp(18px, 4vw, 20px);
}

.modal-content input {
  width: 100%;
  padding: clamp(10px, 2.5vw, 12px) clamp(12px, 3vw, 16px);
  background: #0e1621;
  border: 1px solid #2d3748;
  border-radius: 12px;
  color: white;
  font-size: max(16px, 1rem);
  margin-bottom: 15px;
  outline: none;
  min-height: 44px;
}

.modal-content input:focus {
  border-color: #667eea;
}

.modal-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 5px;
}
.modal-buttons button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.5);
}

.modal-buttons button {
  flex: 1;
  padding: clamp(10px, 2.5vw, 12px);
  border: none;
  border-radius: 12px;
  font-size: max(16px, 1rem);
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  position: relative;
  overflow: hidden;
  transition: all 0.2s;
}

.modal-buttons button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.modal-buttons .btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.modal-buttons .btn-secondary {
  background: #2d3748;
  color: white;
}

.modal-buttons button:active {
  transform: scale(0.95);
  opacity: 0.9;
}

/* Единые кнопки: primary / secondary по всему приложению */
.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  min-height: 44px;
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}
.btn-primary:disabled,
.btn-primary.loading {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}
.btn-primary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.5);
}

.btn-secondary {
  background: #2d3748;
  color: white;
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  min-height: 44px;
}
.btn-secondary:hover:not(:disabled) {
  background: #3d4758;
  transform: translateY(-1px);
}
.btn-secondary:active:not(:disabled) {
  transform: scale(0.98);
}
.btn-secondary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-secondary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.5);
}

.invite-link {
  background: #0e1621;
  padding: 12px;
  border-radius: 12px;
  margin: 15px 0;
  word-break: break-all;
  font-size: 14px;
  color: #8b95a5;
}

.admin-tabs {
  display: flex;
  background: #1a2332;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
}

.admin-tabs button {
  flex: 1;
  padding: 15px;
  background: transparent;
  border: none;
  color: #8b95a5;
  font-size: 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.admin-tabs button.active {
  color: #667eea;
  border-bottom-color: #667eea;
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 15px;
  -webkit-overflow-scrolling: touch;
}

.user-item, .room-item-admin {
  background: #1a2332;
  padding: 15px;
  margin-bottom: 10px;
  border-radius: 12px;
}

.user-item h4, .room-item-admin h4 {
  margin-bottom: 5px;
}

.user-item p, .room-item-admin p {
  font-size: 14px;
  color: #8b95a5;
}

.messages-admin {
  background: #1a2332;
  padding: 15px;
  margin-bottom: 10px;
  border-radius: 12px;
}

.messages-admin h4 {
  margin-bottom: 10px;
  color: #667eea;
}

.admin-message {
  background: #0e1621;
  padding: 10px;
  margin-bottom: 8px;
  border-radius: 8px;
  font-size: 14px;
}

.admin-message strong {
  color: #667eea;
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #0e1621;
}

::-webkit-scrollbar-thumb {
  background: #2d3748;
  border-radius: 3px;
}

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

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

@media (max-width: 768px) {
  .message-bubble {
    max-width: min(88%, 300px);
  }
  .room-item {
    min-height: 76px;
    padding: 14px 16px;
  }
  .header-btn-icon {
    min-width: 44px;
    min-height: 44px;
  }
}

@media (max-width: 480px) {
  .message-input {
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: max(var(--tg-safe-bottom), 10px);
  }
  .message-input input {
    min-height: 44px;
    font-size: 16px; /* отключает зум на iOS при фокусе */
  }
  .message-input button,
  .attach-btn {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 380px) {
  .message-bubble {
    max-width: min(92%, 260px);
  }
  .message-input {
    gap: 6px;
  }
}

@media (min-width: 769px) and (max-width: 1024px) {
  #app {
    max-width: 700px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
  }
}

@media (min-width: 1025px) {
  #app {
    max-width: 600px;
    margin: 0 auto;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .header {
    min-height: 50px;
    padding: 8px 15px;
    padding-top: max(env(safe-area-inset-top), 8px);
  }

  .messages-container {
    min-height: 120px;
  }
  
  .message-input {
    min-height: 50px;
    padding: 8px;
    padding-bottom: max(env(safe-area-inset-bottom), 8px);
  }
  
  .fab {
    bottom: max(env(safe-area-inset-bottom), 60px);
    width: 50px;
    height: 50px;
    font-size: 24px;
  }
}

/* Низкий viewport (клавиатура открыта, ландшафт на телефоне) */
@media (max-height: 500px) {
  .messages-container {
    min-height: 120px;
  }
}

/* Светлая тема */
body[data-theme="light"] {
  background: #f5f7fa;
  color: #1a202c;
}

body[data-theme="light"] .auth-screen {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

body[data-theme="light"] .header {
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  color: #1a202c;
}

body[data-theme="light"] .rooms-list,
body[data-theme="light"] .messages-container,
body[data-theme="light"] .admin-content {
  background: #f5f7fa;
}

body[data-theme="light"] .room-item,
body[data-theme="light"] .user-item,
body[data-theme="light"] .room-item-admin,
body[data-theme="light"] .messages-admin {
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
}
body[data-theme="light"] .room-item:last-child {
  border-bottom: none;
}

body[data-theme="light"] .room-item:active {
  background: #edf2f7;
}

body[data-theme="light"] .room-preview,
body[data-theme="light"] .room-time,
body[data-theme="light"] .chat-status,
body[data-theme="light"] .message-author,
body[data-theme="light"] .message-time,
body[data-theme="light"] .typing-indicator {
  color: #718096;
}

body[data-theme="light"] .message-bubble {
  background: #ffffff;
  color: #1a202c;
  border: 1px solid #e2e8f0;
}

body[data-theme="light"] .message.own .message-bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
}

/* Синяя тема (акцент) */
body[data-theme="blue"] .auth-screen { background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); }
body[data-theme="blue"] .message.own .message-bubble { background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); }
body[data-theme="blue"] .btn-primary { background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%); }
body[data-theme="blue"] .fab { background: #2563eb; }

/* Зелёная тема (акцент) */
body[data-theme="green"] .auth-screen { background: linear-gradient(135deg, #059669 0%, #047857 100%); }
body[data-theme="green"] .message.own .message-bubble { background: linear-gradient(135deg, #059669 0%, #047857 100%); }
body[data-theme="green"] .btn-primary { background: linear-gradient(135deg, #059669 0%, #047857 100%); }
body[data-theme="green"] .fab { background: #059669; }

body[data-theme="light"] .message-input {
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

body[data-theme="light"] .message-input input {
  background: #f5f7fa;
  border: 1px solid #e2e8f0;
  color: #1a202c;
}

body[data-theme="light"] .message-input input:focus {
  border-color: #667eea;
}

body[data-theme="light"] .attach-btn,
body[data-theme="light"] #voiceBtn {
  background: #edf2f7;
  color: #1a202c;
}

body[data-theme="light"] .modal {
  background: rgba(0, 0, 0, 0.5);
}

body[data-theme="light"] .modal-content {
  background: #ffffff;
  color: #1a202c;
}

body[data-theme="light"] .modal-content input,
body[data-theme="light"] .modal-content textarea {
  background: #f5f7fa;
  border: 1px solid #e2e8f0;
  color: #1a202c;
}

body[data-theme="light"] .modal-content input:focus,
body[data-theme="light"] .modal-content textarea:focus {
  border-color: #667eea;
}

body[data-theme="light"] .modal-buttons .btn-secondary {
  background: #edf2f7;
  color: #1a202c;
}

body[data-theme="light"] .invite-link {
  background: #f5f7fa;
  color: #718096;
}

body[data-theme="light"] .admin-tabs {
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
}

body[data-theme="light"] .admin-tabs button {
  color: #718096;
}

body[data-theme="light"] .admin-tabs button.active {
  color: #667eea;
}

body[data-theme="light"] .admin-message {
  background: #f5f7fa;
  color: #1a202c;
}

body[data-theme="light"] .message-actions {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

body[data-theme="light"] .message-actions button {
  color: #1a202c;
}

body[data-theme="light"] .message-actions button:hover {
  background: #f5f7fa;
}

body[data-theme="light"] .empty-state-title {
  color: #1a202c;
}
body[data-theme="light"] .empty-state-text {
  color: #718096;
}
body[data-theme="light"] .btn-secondary {
  background: #e2e8f0;
  color: #1a202c;
}
body[data-theme="light"] .btn-secondary:hover:not(:disabled) {
  background: #cbd5e0;
}

body[data-theme="light"] .message-reply {
  background: rgba(102, 126, 234, 0.1);
  color: #4a5568;
}

body[data-theme="light"] #replyPreview,
body[data-theme="light"] #forwardPreview,
body[data-theme="light"] #emojiPicker {
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
}

body[data-theme="light"] #replyText,
body[data-theme="light"] #forwardText {
  color: #718096;
}

body[data-theme="light"] ::-webkit-scrollbar-track {
  background: #f5f7fa;
}

body[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #cbd5e0;
}

/* Анимации */
.fade-in {
  animation: fadeIn 0.3s ease;
}

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

/* Ripple эффект */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: scale(0);
  animation: rippleEffect 0.6s ease-out;
  pointer-events: none;
}

@keyframes rippleEffect {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* Тост уведомления */
.toast {
  position: fixed;
  top: max(env(safe-area-inset-top), 20px);
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: #1a2332;
  color: white;
  padding: 12px 24px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  animation: toastSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  max-width: min(90vw, 400px);
}

.toast.success { background: #10b981; }
.toast.error { background: #ef4444; }
.toast.info { background: #3b82f6; }
.toast.warning { background: #f59e0b; }

.toast.hide {
  animation: toastSlideOut 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes toastSlideIn {
  to {
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes toastSlideOut {
  to {
    transform: translateX(-50%) translateY(-100px);
    opacity: 0;
  }
}

/* Прогресс бар загрузки */
.upload-progress {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a2332;
  padding: 15px 20px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 1000;
  min-width: 280px;
  max-width: 90vw;
}

.upload-progress-text {
  font-size: 14px;
  margin-bottom: 8px;
  font-weight: 500;
}

.upload-progress-bar {
  width: 100%;
  height: 6px;
  background: #2d3748;
  border-radius: 3px;
  overflow: hidden;
}

.upload-progress-fill {
  height: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 3px;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}

/* Индикатор записи голоса */
.voice-recording {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  padding: 15px 25px;
  border-radius: 24px;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  animation: voicePulse 1.5s ease-in-out infinite;
}

.voice-recording-dot {
  width: 12px;
  height: 12px;
  background: white;
  border-radius: 50%;
  animation: dotPulse 1.5s ease-in-out infinite;
}

@keyframes voicePulse {
  0%, 100% {
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.8);
  }
}

@keyframes dotPulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.3);
    opacity: 0.7;
  }
}

/* Пустое состояние */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: #8b95a5;
  height: 100%;
  min-height: 120px;
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 20px;
  opacity: 0.6;
  line-height: 1;
}

.empty-state-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #e2e8f0;
}

.empty-state-text {
  font-size: 14px;
  line-height: 1.5;
  max-width: 280px;
}

/* Пустое состояние внутри чата (меньше отступы) */
.chat-empty-state {
  padding: 24px 16px;
  min-height: 80px;
}
.chat-empty-state .empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.chat-empty-state .empty-state-title {
  font-size: 16px;
}
.chat-empty-state .empty-state-text {
  font-size: 13px;
}

/* Splash screen */
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: splashFadeOut 0.5s ease 1.5s forwards;
}

.splash-logo {
  font-size: 80px;
  margin-bottom: 20px;
  animation: splashBounce 1s ease infinite;
}

.splash-text {
  font-size: 24px;
  font-weight: 700;
  color: white;
  margin-bottom: 30px;
}

.splash-loader {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes splashBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes splashFadeOut {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Разделитель дат */
.date-divider {
  display: flex;
  align-items: center;
  margin: 20px 0;
  color: #8b95a5;
  font-size: 12px;
  font-weight: 500;
}

.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #2d3748;
}

.date-divider span {
  padding: 0 15px;
  background: #0e1621;
  border-radius: 12px;
}

/* Счетчик символов */
.char-counter {
  position: absolute;
  bottom: 5px;
  right: 60px;
  font-size: 11px;
  color: #8b95a5;
  pointer-events: none;
}

.char-counter.warning {
  color: #f59e0b;
}

.char-counter.error {
  color: #ef4444;
}

/* Превью изображений */
.image-placeholder {
  background: linear-gradient(135deg, #2d3748 0%, #1a2332 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8b95a5;
  font-size: 48px;
  min-height: 200px;
  position: relative;
  overflow: hidden;
}

.image-placeholder::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  animation: shimmer 2s infinite;
}

/* Свайп индикатор */
.swipe-indicator {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  opacity: 0;
  transition: opacity 0.2s;
}

.swipe-indicator.reply {
  background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.2));
  color: #667eea;
}

.swipe-indicator.delete {
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.2));
  color: #ef4444;
  left: auto;
  right: 0;
}

/* Анимация эмодзи панели */
#emojiPicker {
  animation: emojiSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#emojiPicker.hiding {
  animation: emojiSlideDown 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

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

/* Онлайн индикатор с анимацией */
.online-indicator {
  animation: onlinePulse 2s ease-in-out infinite;
}

@keyframes onlinePulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0);
  }
}

body[data-theme="light"] .toast {
  background: #ffffff;
  color: #1a202c;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

body[data-theme="light"] .toast.success { background: #10b981; color: white; }
body[data-theme="light"] .toast.error { background: #ef4444; color: white; }
body[data-theme="light"] .toast.info { background: #3b82f6; color: white; }
body[data-theme="light"] .toast.warning { background: #f59e0b; color: white; }

body[data-theme="light"] .upload-progress {
  background: #ffffff;
  color: #1a202c;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

body[data-theme="light"] .upload-progress-bar {
  background: #e2e8f0;
}

body[data-theme="light"] .voice-recording {
  background: #ef4444;
  color: white;
}

body[data-theme="light"] .date-divider {
  color: #718096;
}

body[data-theme="light"] .date-divider::before,
body[data-theme="light"] .date-divider::after {
  background: #e2e8f0;
}

body[data-theme="light"] .date-divider span {
  background: #f5f7fa;
}

body[data-theme="light"] .char-counter {
  color: #718096;
}

body[data-theme="light"] .swipe-indicator.reply {
  background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.15));
}

body[data-theme="light"] .swipe-indicator.delete {
  background: linear-gradient(90deg, transparent, rgba(239, 68, 68, 0.15));
}

/* Скелетоны */
.skeleton-item {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 15px 20px;
  margin-bottom: 10px;
  background: #1a2332;
  border-radius: 12px;
}

.skeleton-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: linear-gradient(90deg, #2d3748 25%, #3d4758 50%, #2d3748 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-line {
  height: 12px;
  background: linear-gradient(90deg, #2d3748 25%, #3d4758 50%, #2d3748 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Реакции */
.reaction-picker {
  position: absolute;
  bottom: -40px;
  left: 0;
  background: #2d3748;
  border-radius: 20px;
  padding: 5px;
  display: flex;
  gap: 5px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  z-index: 10;
}

.reaction-picker button {
  background: transparent;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 5px 8px;
  border-radius: 12px;
  transition: transform 0.2s;
}

.reaction-picker button:hover {
  transform: scale(1.2);
  background: #1a2332;
}

.message-reactions {
  display: flex;
  gap: 5px;
  margin-top: 5px;
  flex-wrap: wrap;
}

.reaction-item {
  background: rgba(102, 126, 234, 0.2);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Закрепленные */
.pinned-message {
  background: #2d3748;
  padding: 10px 15px;
  border-left: 3px solid #667eea;
  margin-bottom: 10px;
  border-radius: 8px;
  cursor: pointer;
}

.pinned-message:hover {
  background: #3d4758;
}

body[data-theme="light"] .skeleton-item {
  background: #ffffff;
  border: 1px solid #e2e8f0;
}

body[data-theme="light"] .skeleton-avatar,
body[data-theme="light"] .skeleton-line {
  background: linear-gradient(90deg, #e2e8f0 25%, #f5f7fa 50%, #e2e8f0 75%);
  background-size: 200% 100%;
}

body[data-theme="light"] .reaction-picker {
  background: #ffffff;
  border: 1px solid #e2e8f0;
}

body[data-theme="light"] .reaction-picker button:hover {
  background: #f5f7fa;
}

body[data-theme="light"] .pinned-message {
  background: #f5f7fa;
  border-left-color: #667eea;
}

body[data-theme="light"] .pinned-message:hover {
  background: #edf2f7;
}
