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

:root {
  --tg-bg: #0e1621;
  --tg-chat-bg: #0e1621;
  --tg-surface: #17212b;
  --tg-surface-hover: #202b36;
  --tg-bubble-in: #182533;
  --tg-bubble-out: #2b5278;
  --tg-bubble-out-hover: #315d86;
  --tg-accent: #5288c1;
  --tg-accent-hover: #659dd6;
  --tg-text: #f5f5f5;
  --tg-subtext: #7e8c9a;
  --tg-time-out: rgba(255, 255, 255, 0.75);
  --tg-time-in: #7e8c9a;
  --tg-border: #131c26;
  --tg-danger: #e53935;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
  font-family: var(--font-family);
  background: var(--tg-bg);
  color: var(--tg-text);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  user-select: text;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
}

/* ========================================================
   AUTH SCREEN (Telegram Style)
   ======================================================== */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: radial-gradient(circle at center, #17212b 0%, #0e1621 100%);
  padding: 20px;
}

.auth-card {
  background: var(--tg-surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeIn 0.3s ease-out;
}

.tg-logo-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2aabee 0%, #229ed9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  margin-bottom: 20px;
  box-shadow: 0 8px 24px rgba(42, 171, 238, 0.35);
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 6px;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--tg-subtext);
  margin-bottom: 24px;
  text-align: center;
}

.auth-tabs {
  display: flex;
  width: 100%;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 24px;
}

.tab-btn {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  color: var(--tg-subtext);
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--tg-accent);
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

form {
  width: 100%;
}

.input-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
}

.input-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--tg-subtext);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  background: #0e1621;
  border: 1px solid #232e3c;
  border-radius: 10px;
  padding: 12px 14px;
  color: #fff;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group input:focus {
  border-color: var(--tg-accent);
  box-shadow: 0 0 0 2px rgba(82, 136, 193, 0.25);
}

.btn-primary {
  width: 100%;
  background: var(--tg-accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 13px 0;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  margin-top: 8px;
}

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

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

.error-badge {
  color: var(--tg-danger);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  min-height: 18px;
}

/* ========================================================
   CHAT CONTAINER & HEADER (Telegram Style)
   ======================================================== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  background: var(--tg-chat-bg);
}

.tg-header {
  height: 56px;
  background: var(--tg-surface);
  border-bottom: 1px solid var(--tg-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 10;
  flex-shrink: 0;
}

.header-chat-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #439cfb 0%, #2a72d4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: white;
  font-size: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.chat-meta {
  display: flex;
  flex-direction: column;
}

.chat-title {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--tg-subtext);
  line-height: 1.2;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4caf50;
  display: inline-block;
  box-shadow: 0 0 6px rgba(76, 175, 80, 0.6);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
}

.user-pill-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: white;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-pill-name {
  font-size: 13px;
  color: #fff;
  font-weight: 500;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--tg-subtext);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--tg-danger);
}

/* ========================================================
   CHAT HISTORY & MESSAGES (Telegram Pattern & Bubbles)
   ======================================================== */
.tg-chat-history {
  flex: 1;
  overflow-y: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  background-color: #0e1621;
  background-image: 
    radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 0),
    radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 0);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

.messages-wrap {
  width: 100%;
  max-width: 740px;
  margin: 0 auto;
  padding: 16px 16px 20px 16px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.date-badge {
  align-self: center;
  background: rgba(14, 22, 33, 0.7);
  backdrop-filter: blur(4px);
  color: var(--tg-subtext);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 12px;
  margin: 8px 0 16px 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

/* Message Bubble */
.message {
  max-width: 480px;
  padding: 7px 12px 6px 12px;
  font-size: 15px;
  line-height: 1.35;
  word-wrap: break-word;
  position: relative;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  animation: slideIn 0.15s ease-out;
}

.message.incoming {
  align-self: flex-start;
  background: var(--tg-bubble-in);
  color: var(--tg-text);
  border-radius: 14px 14px 14px 2px;
  margin-right: 48px;
}

.message.outgoing {
  align-self: flex-end;
  background: var(--tg-bubble-out);
  color: #fff;
  border-radius: 14px 14px 2px 14px;
  margin-left: 48px;
}

.message-sender {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 3px;
  line-height: 1.2;
}

/* Telegram sender colors */
.color-0 { color: #e17076; }
.color-1 { color: #faa774; }
.color-2 { color: #a695e7; }
.color-3 { color: #7bc862; }
.color-4 { color: #6ec9cb; }
.color-5 { color: #65aadd; }
.color-6 { color: #ee7aae; }

.message-text {
  word-break: break-word;
  white-space: pre-wrap;
}

.message-meta {
  float: right;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  margin-top: 4px;
  user-select: none;
  font-size: 11px;
}

.incoming .message-meta {
  color: var(--tg-time-in);
}

.outgoing .message-meta {
  color: var(--tg-time-out);
}

.check-marks {
  width: 15px;
  height: 15px;
  display: inline-block;
  vertical-align: middle;
}

/* ========================================================
   MEDIA COMPONENTS (Telegram Style)
   ======================================================== */
.media-container {
  margin-top: 4px;
  margin-bottom: 4px;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

/* Photos */
.tg-photo {
  display: block;
  max-width: 100%;
  max-height: 380px;
  border-radius: 8px;
  cursor: zoom-in;
  object-fit: cover;
  transition: transform 0.15s ease, filter 0.15s;
}

.tg-photo:hover {
  filter: brightness(1.05);
}

/* Videos */
.tg-video-player {
  width: 100%;
  max-width: 380px;
  max-height: 380px;
  border-radius: 8px;
  display: block;
  background: #000;
  outline: none;
}

/* VIDEO NOTES (КРУЖОЧКИ) - Iconic Telegram Round Video Notes */
.tg-video-note-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  margin: 4px auto;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  border: 3px solid rgba(82, 136, 193, 0.55);
  background: #000;
  cursor: pointer;
}

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

.video-note-badge {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  pointer-events: none;
}

/* Voice Messages */
.tg-voice-player {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.15);
  padding: 8px 12px;
  border-radius: 20px;
  min-width: 220px;
}

.voice-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.voice-play-btn:hover {
  background: var(--tg-accent-hover);
}

.voice-waveform-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.voice-progress-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}

.voice-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--tg-accent);
  border-radius: 2px;
  transition: width 0.1s linear;
}

.voice-time {
  font-size: 11px;
  color: var(--tg-subtext);
}

/* Audio Player */
.tg-audio-player {
  width: 100%;
  min-width: 240px;
  margin-top: 4px;
  outline: none;
  border-radius: 8px;
}

/* Documents */
.tg-doc-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.18);
  padding: 10px 14px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s;
}

.tg-doc-card:hover {
  background: rgba(0, 0, 0, 0.28);
}

.tg-doc-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tg-doc-details {
  flex: 1;
  overflow: hidden;
}

.tg-doc-name {
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-doc-action {
  font-size: 12px;
  color: var(--tg-accent);
}

/* Stickers */
.tg-sticker {
  max-width: 180px;
  max-height: 180px;
  display: block;
  user-select: none;
}

.sticker-msg {
  background: transparent !important;
  box-shadow: none !important;
  padding: 4px !important;
}

/* Contact card */
.tg-contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.18);
  padding: 10px 12px;
  border-radius: 10px;
  margin-top: 4px;
}

.tg-contact-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #6ec9cb;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* Location */
.tg-location-card {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--tg-accent);
  text-decoration: none;
  font-weight: 500;
  margin-top: 4px;
}

.tg-location-card:hover {
  text-decoration: underline;
}

/* ========================================================
   CHAT FOOTER / INPUT (Telegram Style)
   ======================================================== */
.tg-footer {
  background: var(--tg-surface);
  border-top: 1px solid var(--tg-border);
  padding: 8px 16px;
  flex-shrink: 0;
}

.tg-input-box {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #0e1621;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 6px 6px 6px 14px;
  transition: border-color 0.2s;
}

.tg-input-box:focus-within {
  border-color: rgba(82, 136, 193, 0.5);
}

.attach-btn {
  color: var(--tg-subtext);
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.2s;
}

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

#message-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 7px 0;
}

#message-input::placeholder {
  color: var(--tg-subtext);
}

.send-button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--tg-accent);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.send-button:hover {
  background: var(--tg-accent-hover);
}

.send-button:active {
  transform: scale(0.94);
}

/* ========================================================
   LIGHTBOX MODAL
   ======================================================== */
.media-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  cursor: zoom-out;
}

.modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal-content img,
.modal-content video {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
}

.modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  color: white;
  font-size: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  line-height: 1;
}

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

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

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

@media (max-width: 600px) {
  .message {
    max-width: 88%;
  }
  .tg-header {
    padding: 0 12px;
  }
  .tg-footer {
    padding: 6px 10px;
  }
}

/* ========================================================
   VIDEO NOTE RECORDER MODAL & CONTROLS
   ======================================================== */
.round-cam-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--tg-accent);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.round-cam-btn:hover {
  background: rgba(82, 136, 193, 0.2);
  color: #fff;
  transform: scale(1.05);
}

.record-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.record-modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
}

.record-modal-content {
  position: relative;
  z-index: 2001;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: fadeIn 0.25s ease-out;
}

.record-header {
  display: flex;
  align-items: center;
  justify-content: center;
}

.record-badge {
  background: rgba(229, 57, 53, 0.2);
  border: 1px solid rgba(229, 57, 53, 0.5);
  color: #ff5252;
  font-weight: 700;
  font-size: 14px;
  padding: 6px 16px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.5px;
}

.rec-red-dot {
  width: 10px;
  height: 10px;
  background: #ff5252;
  border-radius: 50%;
  box-shadow: 0 0 10px #ff5252;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}

.record-circle-container {
  width: 250px;
  height: 250px;
  border-radius: 50%;
  overflow: hidden;
  border: 4px solid #ff5252;
  box-shadow: 0 0 30px rgba(255, 82, 82, 0.45);
  background: #000;
  position: relative;
}

#record-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror camera for natural feel */
}

.record-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.btn-cancel-record {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  padding: 10px 22px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-cancel-record:hover {
  background: rgba(255, 255, 255, 0.22);
}

.btn-stop-send-record {
  background: #2aabee;
  color: white;
  border: none;
  padding: 10px 26px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(42, 171, 238, 0.4);
  transition: all 0.2s;
}

.btn-stop-send-record:hover {
  background: #229ed9;
  transform: scale(1.03);
}
