/* Cores base extraídas do tema oficial "night.attheme" do repositório
   DrKLO/Telegram (chat_wallpaper, actionBarDefault, chat_messagePanelBackground,
   windowBackgroundWhite), com o acento violeta (#8774E1) usado nos elementos
   de destaque do app (padrão visto nos prints: bolha enviada, FAB de mic,
   badge de não lidos). */
:root {
  --bg-chat: #0f0f10;         /* chat_wallpaper */
  --bg-header: #232326;       /* actionBarDefault */
  --bg-panel: #1e1e1f;        /* chat_messagePanelBackground */
  --bg-surface: #181819;      /* windowBackgroundWhite (dark) */
  --accent-purple: #8774e1;
  --accent-purple-2: #a48bfa;
  --bubble-out: #6b5ce0;
  --bubble-in: #1f2123;       /* chat_inBubble (night) */
  --text-primary: #f2f2f5;
  --text-secondary: #9a9aa4;
  --pill-bg: #2b2b31;
  --danger: #f05454;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.phone {
  position: relative;
  width: 390px;
  height: 844px;
  max-height: 100vh;
  background: var(--bg-chat);
  overflow: hidden;
  border-radius: 0;
  box-shadow: 0 0 40px rgba(0,0,0,0.6);
}

@media (min-width: 500px) {
  .phone {
    border-radius: 28px;
    border: 1px solid #222;
  }
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg-chat);
}
.screen.active { display: flex; }

/* ============ HEADER (tela de chat) ============ */
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-header);
  border-bottom: 1px solid #232327;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
}
.icon-btn:active { background: rgba(255,255,255,0.08); }
.icon-btn svg { width: 22px; height: 22px; }
.btn-ico {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-color: var(--text-primary);
  -webkit-mask-image: var(--ico-src);
  mask-image: var(--ico-src);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.header-identity {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 4px;
  text-align: left;
  border-radius: 8px;
  min-width: 0;
}
.header-identity:active { background: rgba(255,255,255,0.06); }

.avatar {
  position: relative;
  border-radius: 50%;
  background: linear-gradient(135deg, #f78ca0, #f9748f);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}
.avatar-md { width: 40px; height: 40px; font-size: 18px; }
.avatar-lg { width: 96px; height: 96px; font-size: 40px; margin: 0 auto 12px; }

.badge-count {
  position: absolute;
  top: -6px;
  left: -6px;
  background: var(--accent-purple-2);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-header);
}

.identity-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.identity-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.identity-status {
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* ============ CHAT BODY ============ */
.chat-body {
  position: relative;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.chat-bg {
  position: absolute;
  inset: 0;
  background-color: #0a0a0d;
  background-image: url("assets/telegram-pattern.svg");
  background-repeat: repeat;
  background-size: 480px 986px;
  background-position: 0 0;
  opacity: 0.5;
  mix-blend-mode: screen;
}

.messages {
  position: relative;
  z-index: 1;
  padding: 16px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.date-pill {
  align-self: center;
  background: rgba(70, 55, 110, 0.55);
  color: #e4dcff;
  font-size: 12.5px;
  padding: 5px 14px;
  border-radius: 12px;
  margin: 8px 0;
  backdrop-filter: blur(4px);
}

.msg-row {
  display: flex;
  width: 100%;
}
.msg-row.outgoing { justify-content: flex-end; }
.msg-row.incoming { justify-content: flex-start; }

.bubble {
  max-width: 78%;
  padding: 8px 12px 6px;
  border-radius: 16px;
  font-size: 15.5px;
  line-height: 1.35;
  position: relative;
  word-wrap: break-word;
}

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

.bubble-out {
  background: linear-gradient(135deg, #8477d9, #6f5ecb);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  float: right;
  margin-left: 8px;
  margin-top: 2px;
  font-size: 11.5px;
  color: rgba(255,255,255,0.65);
}
.bubble-in .meta { color: var(--text-secondary); }
.check { width: 15px; height: 15px; }

/* ============ COMPOSER ============ */
.composer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-panel);
  border-top: 1px solid #232327;
  flex-shrink: 0;
}

.composer-input {
  flex: 1;
  background: #26262b;
  border-radius: 20px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  height: 40px;
}
.composer-input input {
  width: 100%;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
}
.composer-input input::placeholder { color: var(--text-secondary); }

.mic-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(160deg, #9b8cf0, #6f5ecb);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.mic-btn svg { width: 20px; height: 20px; }

/* ============ OVERLAYS / MENUS ============ */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: flex-start;
  justify-content: flex-end;
  z-index: 20;
}
.overlay.visible { display: flex; }

.menu-card {
  background: #232327;
  border-radius: 14px;
  padding: 6px;
  margin: 56px 10px 0;
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  animation: pop-in 0.12s ease-out;
}

.attach-menu {
  margin: 0 8px 74px auto;
  align-self: flex-end;
  margin-top: auto;
}
#attachMenuOverlay { align-items: flex-end; }

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  padding: 11px 12px;
  text-align: left;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
}
.menu-item:active { background: rgba(255,255,255,0.08); }
.menu-item.danger { color: var(--danger); }
.chevron { margin-left: auto; color: var(--text-secondary); }

/* Ícones extraídos diretamente do APK oficial do Telegram
   (assets/icons/*.png, convertidos de .webp reais do app — msg_search,
   msg_mute, msg_calls, msg_select, msg_shareout, msg_gift_premium,
   msg_block2, msg_delete, msg_autodelete, msg_gallery, msg_sendfile).
   São ícones brancos com máscara alpha; usamos CSS mask-image com
   background-color para tingir na cor exata (--text-primary / --danger),
   já que isso é mais preciso entre navegadores do que filter(). */
.line-ico {
  display: inline-block;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  background-color: var(--text-primary);
  -webkit-mask-image: var(--ico-src);
  mask-image: var(--ico-src);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}
.menu-item.danger .line-ico,
.ico-danger-tint {
  background-color: var(--danger);
}

/* ícones do menu de anexos: quadrados coloridos, como no app original */
.menu-ico {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.menu-ico-img {
  display: inline-block;
  width: 18px;
  height: 18px;
  background-color: #fff;
  -webkit-mask-image: var(--ico-src);
  mask-image: var(--ico-src);
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}
.ico-media { background: linear-gradient(135deg, #3fb2f0, #1e8fe0); }
.ico-doc   { background: linear-gradient(135deg, #f5a94e, #ef8b1f); }
.ico-gift  { background: linear-gradient(135deg, #c86bf0, #9a4fe0); }
.ico-task  { background: linear-gradient(135deg, #4cd07a, #29b85c); }

/* ============ TELA: DADOS DO CONTATO ============ */
.contact-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: var(--bg-header);
  border-bottom: 1px solid #232327;
  flex-shrink: 0;
}
.contact-title {
  flex: 1;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
}

.contact-body {
  flex: 1;
  overflow-y: auto;
  padding: 32px 20px;
  background: var(--bg-chat);
}

.contact-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 24px;
}
.contact-name {
  font-size: 20px;
  font-weight: 600;
}
.contact-status {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.info-card {
  background: #1c1c20;
  border-radius: 14px;
  overflow: hidden;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid #26262b;
}
.info-row:last-child { border-bottom: none; }

.info-ico {
  width: 22px;
  text-align: center;
  color: var(--accent-purple-2);
  font-size: 16px;
}
.info-ico-right {
  color: var(--text-secondary);
  font-size: 16px;
}

.info-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.info-value {
  font-size: 15.5px;
  color: var(--text-primary);
}
.info-label {
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #3a3a40;
  border-radius: 26px;
  transition: 0.2s;
}
.slider::before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider {
  background: var(--accent-purple);
}
.switch input:checked + .slider::before {
  transform: translateX(18px);
}
