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

:root {
  --bg: #0a1018;
  --bg-secondary: #131c27;
  --bg-chat: #0a1018;
  --accent: #6ab3f3;
  --accent-soft: #3a4a5c;
  --text: #f5f5f5;
  --text-muted: #6d7f8e;
  --bubble-mine: #2b5278;
  --bubble-theirs: #182533;
  --border: #1f2936;
  --success: #4dcd5e;
  --radius: 12px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: 100%;
  overflow: hidden;
}

/* ============ LAYOUT ============ */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ============ LOGIN SCREEN ============ */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-secondary) 100%);
}

.login-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 16px;
}

.login-title {
  font-size: 1.6rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 0.9rem;
}

.user-select {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}

.user-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 24px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.95rem;
}

.user-btn:hover,
.user-btn.active {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
}

.user-btn .avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 300px;
}

.login-form input {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-secondary);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.login-form input:focus {
  border-color: var(--accent);
}

.login-form button {
  padding: 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-form button:hover {
  opacity: 0.9;
}

.login-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-error {
  color: var(--accent);
  font-size: 0.85rem;
  text-align: center;
  min-height: 20px;
}

.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.remember-row input[type="checkbox"] {
  accent-color: var(--accent);
}

/* ============ CHAT SCREEN ============ */
.chat-screen {
  display: none;
  flex-direction: column;
  height: 100%;
}

.chat-screen.visible {
  display: flex;
}

.chat-screen {
  overflow: hidden;
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-photo {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-header .name {
  font-weight: 600;
  font-size: 1rem;
}

.chat-header .status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status.online {
  color: var(--success);
}

.chat-tabs {
  display: flex;
  gap: 4px;
}

.chat-tab {
  padding: 8px 20px;
  border: none;
  border-radius: 22px;
  background: rgba(255,255,255,0.06);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}

.chat-tab:hover {
  background: rgba(255,255,255,0.1);
}

.chat-tab.active {
  color: #fff;
  background: var(--accent);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.1);
}

/* Messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  background: var(--bg-chat);
  padding: 8px calc(50% - 340px);
}

@media (max-width: 720px) {
  .messages-area {
    padding: 8px 10px;
  }
}

/* Ограничиваем ширину контейнера сообщений, не самих пузырей */

.message {
  max-width: 75%;
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 0.93rem;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
  margin: 1px 0;
}

.message.mine {
  align-self: flex-end;
  background: var(--bubble-mine);
  border-top-right-radius: 12px;
  border-bottom-right-radius: 4px;
  border-top-left-radius: 12px;
  border-bottom-left-radius: 12px;
}

.message.theirs {
  align-self: flex-start;
  background: var(--bubble-theirs);
  border-top-left-radius: 12px;
  border-bottom-left-radius: 4px;
  border-top-right-radius: 12px;
  border-bottom-right-radius: 12px;
}

.message .text {
  display: inline;
}

.message .meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  font-size: 0.68rem;
  color: rgba(255,255,255,0.45);
  float: right;
  margin-top: 4px;
}

.message-del {
  position: absolute;
  top: 4px;
  right: -22px;
  width: 18px;
  height: 18px;
  border: none;
  border-radius: 50%;
  background: rgba(233,69,96,0.75);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0;
}

.message.mine:hover .message-del {
  opacity: 1;
}

.message .status-icon {
  font-size: 0.75rem;
}

.status-icon.delivered { color: rgba(255,255,255,0.45); }
.status-icon.read { color: #4dcd5e; }

.message .media-content img,
.message .media-content video {
  max-width: 100%;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 4px;
}

.typing-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 4px 16px;
  min-height: 24px;
  flex-shrink: 0;
}

/* Date separator */
.date-separator {
  text-align: center;
  padding: 6px 0;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.date-separator span {
  background: rgba(0,0,0,0.3);
  padding: 3px 10px;
  border-radius: 10px;
  font-weight: 500;
}

/* Input area */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-area .attach-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  flex-shrink: 0;
}

.input-area .attach-btn:hover {
  color: var(--accent);
}

.msg-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}

.msg-input:focus {
  border-color: var(--accent);
}

.send-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Connection bar */
.connection-bar {
  display: none;
  padding: 6px;
  text-align: center;
  font-size: 0.8rem;
  background: #c62828;
  color: #fff;
}

.connection-bar.visible {
  display: block;
}

/* ============ TELEGRAM FEED ============ */
.telegram-feed {
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.telegram-feed.visible {
  display: block;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tg-posts {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 8px 20px;
}

.tg-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 20px;
  font-size: 0.9rem;
}

.tg-post {
  background: var(--bg-secondary);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
  padding: 8px;
}

.tg-post-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 0 4px;
}

.tg-post-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6ab3f3, #5199d9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.tg-post-avatar-img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.tg-post-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.tg-post-channel {
  font-size: 0.8rem;
  font-weight: 600;
  color: #6ab3f3;
}

.tg-post-date {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.tg-post-media {
  margin: 2px 0;
}

.tg-post-media img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
}

.tg-post-media video {
  width: 100%;
  height: auto;
  display: block;
}

/* Альбомы */
.tg-post-album {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 2px;
  margin: 2px 0;
}

.tg-post-album img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  border-radius: 2px;
}

.tg-post-text {
  padding: 4px 0 6px;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
  word-break: break-word;
}

.tg-post-text a {
  color: #6ab3f3;
  text-decoration: none;
}

.tg-post-text a:hover {
  text-decoration: underline;
}

/* Post footer — реакции + лайк */
.tg-post-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 0 4px;
}

.tg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tg-reaction {
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 2px 7px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tg-like-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s, transform 0.15s;
  padding: 4px;
  line-height: 1;
}

.tg-like-btn:hover {
  opacity: 0.8;
}

.tg-like-btn.liked {
  opacity: 1;
  transform: scale(1.15);
}

/* Комментарии */
.tg-comments-section {
  border-top: 1px solid var(--border);
  margin: 0 -8px -8px;
}

.tg-comments-toggle {
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}

.tg-comments-toggle:hover {
  background: rgba(123,104,238,0.08);
}

.tg-comments-body {
  padding: 0 10px 10px;
}

.tg-comments-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 6px;
}

.tg-comment {
  padding: 2px 0;
  font-size: 0.8rem;
  line-height: 1.3;
}

.tg-comment-name {
  font-weight: 600;
  color: #6ab3f3;
  margin-right: 4px;
}

.tg-comment-tg .tg-comment-name {
  color: #4fc3f7;
}

.tg-comment.mine .tg-comment-name {
  color: #4dcd5e;
}

.tg-comment-reply {
  font-size: 0.7rem;
  color: var(--text-muted);
  border-left: 2px solid var(--accent);
  padding-left: 6px;
  margin-bottom: 2px;
}

.tg-comment-text {
  color: var(--text);
}

.tg-comment-time {
  color: var(--text-muted);
  font-size: 0.68rem;
  margin-left: 4px;
}

.tg-comment-del {
  color: var(--accent);
  cursor: pointer;
  font-size: 0.7rem;
  margin-left: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.tg-comment:hover .tg-comment-del {
  opacity: 1;
}

.tg-cbtn-count {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.tg-comment-input {
  display: flex;
  gap: 4px;
}

.tg-comment-input input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  outline: none;
}

.tg-comment-input input:focus {
  border-color: #6ab3f3;
}

.tg-comment-input button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #6ab3f3;
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
  flex-shrink: 0;
}

/* Кружочки — Telegram style */
.tg-round-player {
  padding: 8px 10px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
}

.tg-round-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  flex-shrink: 0;
  cursor: pointer;
}

.tg-round-wrap video,
.tg-round-wrap img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.tg-round-border {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.15);
  pointer-events: none;
}

/* SVG прогресс по кругу */
.tg-round-progress {
  position: absolute;
  inset: -2px;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  transform: rotate(-90deg);
  pointer-events: none;
}

.tg-round-progress circle {
  fill: none;
  stroke: #e94560;
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s linear;
}

/* Play overlay (показывается при паузе) */
.tg-round-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  pointer-events: none;
}

.tg-round-play-icon {
  font-size: 2rem;
  color: rgba(255,255,255,0.9);
}

/* Mute badge (пока autoplay muted) */
.tg-round-mute-badge {
  position: absolute;
  bottom: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  pointer-events: none;
}

/* Время */
.tg-round-time {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 7px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 480px) {
  .tg-round-wrap {
    width: 180px;
    height: 180px;
  }
}

/* ============ LIGHTBOX ============ */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lightbox.visible {
  display: flex;
}

.lightbox img,
.lightbox video {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 480px) {
  .user-select {
    gap: 16px;
  }

  .user-btn {
    padding: 12px 18px;
  }

  .user-btn .avatar {
    width: 56px;
    height: 56px;
    font-size: 1.5rem;
  }

  .message {
    max-width: 85%;
  }

  .chat-header {
    padding: 10px 12px;
  }

  .input-area {
    padding: 8px 12px;
  }
}
