/* ===== Team Nexilant — Messenger Theme (Orange / Black / White) ===== */
:root,
.theme-dark {
  --bg-app: #0a0a0b;
  --bg-panel: #141415;
  --bg-header: #1c1c1e;
  --bg-composer: #1c1c1e;
  --bg-bubble-in: #232325;
  --bg-bubble-out: #ff7a1a;
  --bg-bubble-out-grad: linear-gradient(135deg,#ff9d4d,#f0670a);
  --bg-hover: #232325;
  --text-primary: #f5f5f5;
  --text-secondary: #9a9a9d;
  --text-on-accent: #ffffff;
  --accent: #ff7a1a;
  --accent-soft: rgba(255,122,26,.15);
  --border: #2a2a2c;
  --shadow: 0 8px 30px rgba(0,0,0,.5);
  --tick-read: #4fc3f7;
  --danger: #e0586b;
  --chat-bg-pattern: radial-gradient(circle at 20% 20%, rgba(255,122,26,.07), transparent 40%), radial-gradient(circle at 80% 60%, rgba(255,122,26,.05), transparent 35%);
}
.theme-light {
  --bg-app: #f2f2f2;
  --bg-panel: #ffffff;
  --bg-header: #ffffff;
  --bg-composer: #ffffff;
  --bg-bubble-in: #ffffff;
  --bg-bubble-out: #ff7a1a;
  --bg-bubble-out-grad: linear-gradient(135deg,#ff9d4d,#f0670a);
  --bg-hover: #f0f0f0;
  --text-primary: #161616;
  --text-secondary: #6c6c6c;
  --text-on-accent: #ffffff;
  --accent: #ff7a1a;
  --accent-soft: rgba(255,122,26,.12);
  --border: #e6e6e6;
  --shadow: 0 8px 30px rgba(0,0,0,.12);
  --tick-read: #1ea7e0;
  --danger: #e0586b;
  --chat-bg-pattern: radial-gradient(circle at 20% 20%, rgba(255,122,26,.05), transparent 40%), radial-gradient(circle at 80% 60%, rgba(255,122,26,.04), transparent 35%);
}

[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font-family: inherit; }
textarea, input { font-family: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== App Shell ===== */
#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg-panel);
  overflow: hidden;
}
@media (min-width: 900px) {
  body { display: flex; align-items: center; justify-content: center; }
  #app {
    height: 92vh;
    max-height: 920px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
  }
}

/* ===== Header ===== */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 5;
}
.only-mobile { display: none; }
@media (max-width: 899px) {
  .only-mobile { display: inline-flex; }
}
.header-peer {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.header-info { min-width: 0; }
.header-name {
  font-weight: 600;
  font-size: 15.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-status {
  font-size: 12.5px;
  color: var(--text-secondary);
}
.header-status.online { color: var(--accent); }
.header-actions { display: flex; gap: 2px; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn:active { transform: scale(.94); }

/* ===== Avatar ===== */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  background: var(--accent);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ===== Search bar ===== */
.search-bar {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
}
.search-bar.open { display: flex; }
.search-bar input {
  flex: 1;
  background: var(--bg-hover);
  border: none;
  border-radius: 20px;
  padding: 9px 14px;
  color: var(--text-primary);
  outline: none;
  font-size: 14px;
}
.search-bar button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
}
.search-hit { background: rgba(255,210,80,.35) !important; }

/* ===== Messages ===== */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  position: relative;
  background: var(--bg-app);
  background-image: var(--chat-bg-pattern);
  padding: 14px 10px 6px;
  -webkit-overflow-scrolling: touch;
}
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 100%;
  justify-content: flex-end;
}
.day-sep {
  align-self: center;
  background: var(--bg-hover);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 12px;
  margin: 12px 0;
}
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
  padding: 40px;
}
.empty-state .big { font-size: 46px; margin-bottom: 10px; }

.msg-row {
  position: relative;
  display: flex;
  max-width: 78%;
  margin: 2px 0;
  align-self: flex-start;
  animation: pop .15s ease;
}
.msg-row.out { align-self: flex-end; flex-direction: row-reverse; }
@keyframes pop { from { opacity:0; transform: translateY(6px);} to {opacity:1; transform:none;} }

.bubble {
  position: relative;
  padding: 7px 9px 6px 10px;
  border-radius: 14px;
  background: var(--bg-bubble-in);
  color: var(--text-primary);
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  min-width: 56px;
}
.msg-row.out .bubble {
  background: var(--bg-bubble-out-grad);
  color: #fff;
}
.msg-row.in .bubble { border-top-left-radius: 4px; }
.msg-row.out .bubble { border-top-right-radius: 4px; }

.bubble-reply {
  display: block;
  background: rgba(0,0,0,.18);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 4px 8px;
  margin-bottom: 5px;
  font-size: 12.5px;
  cursor: pointer;
}
.msg-row.out .bubble-reply { background: rgba(255,255,255,.16); }
.bubble-reply-name { font-weight: 700; color: var(--accent); }
.msg-row.out .bubble-reply-name { color: #fff; }
.bubble-reply-text { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.4;
  padding-right: 46px;
}
.bubble-meta {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--text-secondary);
  float: right;
  margin-top: 2px;
  margin-left: 6px;
  position: relative;
  top: 2px;
}
.msg-row.out .bubble-meta { color: rgba(255,255,255,.75); }
.tick { display: inline-flex; }
.tick.read svg path { fill: var(--tick-read); }

.bubble.sticker-bubble {
  background: transparent;
  box-shadow: none;
  padding: 0;
}
.sticker-emoji { font-size: 84px; line-height: 1; filter: drop-shadow(0 3px 6px rgba(0,0,0,.25)); }

.bubble-media img, .bubble-media video {
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  display: block;
  cursor: pointer;
  margin-bottom: 4px;
}
.bubble-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  min-width: 200px;
  cursor: pointer;
}
.bubble-file-icon {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.bubble-file-name { font-size: 13.5px; font-weight: 600; word-break: break-all; }
.bubble-file-size { font-size: 11.5px; color: var(--text-secondary); }
.msg-row.out .bubble-file-size { color: rgba(255,255,255,.75); }

/* voice message bubble */
.voice-msg {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  padding: 2px;
}
.voice-play-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.msg-row.out .voice-play-btn { background: rgba(255,255,255,.25); }
.voice-wave {
  flex: 1;
  height: 24px;
  border-radius: 4px;
  position: relative;
  cursor: pointer;
}
.voice-wave-track { display:flex; align-items:center; gap:2px; height:100%; }
.voice-wave-bar { width: 2.5px; background: var(--text-secondary); border-radius: 2px; opacity:.5; }
.msg-row.out .voice-wave-bar { background: rgba(255,255,255,.6); }
.voice-wave-bar.played { opacity: 1; background: var(--accent); }
.msg-row.out .voice-wave-bar.played { background: #fff; }
.voice-time { font-size: 11px; color: var(--text-secondary); min-width: 32px; }
.msg-row.out .voice-time { color: rgba(255,255,255,.8); }

.reactions-row {
  display: flex;
  gap: 3px;
  margin-top: 3px;
  flex-wrap: wrap;
}
.reaction-pill {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 12px;
  cursor: pointer;
}

.msg-deleted { font-style: italic; color: var(--text-secondary); font-size: 13.5px; }

/* context menu on long-press / hover */
.msg-actions {
  position: absolute;
  top: -34px;
  right: 4px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  display: none;
  box-shadow: var(--shadow);
  padding: 2px;
  z-index: 3;
}
.msg-row.out .msg-actions { right: auto; left: 4px; }
.msg-row:hover .msg-actions { display: flex; }
.msg-actions button {
  background: none; border: none; color: var(--text-secondary);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
.msg-actions button:hover { background: var(--bg-hover); color: var(--text-primary); }

.typing-indicator { padding: 2px 10px 8px; }
.typing-bubble { width: fit-content; padding: 12px 14px; display: flex; gap: 4px; }
.typing-bubble span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary);
  animation: blink 1.2s infinite;
}
.typing-bubble span:nth-child(2) { animation-delay: .2s; }
.typing-bubble span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.3; transform: translateY(0);} 40%{opacity:1; transform:translateY(-3px);} }

.scroll-bottom-btn {
  position: absolute;
  right: 16px;
  bottom: 86px;
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-primary);
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 4;
}

/* ===== Reply preview ===== */
.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-composer);
  border-top: 1px solid var(--border);
}
.reply-preview-bar { width: 3px; align-self: stretch; background: var(--accent); border-radius: 2px; }
.reply-preview-content { flex: 1; min-width: 0; }
.reply-preview-name { font-size: 12.5px; font-weight: 700; color: var(--accent); }
.reply-preview-text { font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-preview button { background: none; border: none; color: var(--text-secondary); font-size: 20px; cursor: pointer; }

/* ===== Attach menu ===== */
.attach-menu {
  position: absolute;
  bottom: 64px;
  left: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 8px;
  display: flex;
  flex-direction: column;
  z-index: 20;
  min-width: 190px;
}
.attach-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  color: var(--text-primary);
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  text-align: left;
}
.attach-menu button:hover { background: var(--bg-hover); }
.attach-icon {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

/* ===== Emoji / sticker panel ===== */
.emoji-panel {
  position: absolute;
  bottom: 64px;
  left: 0; right: 0;
  margin: 0 8px;
  height: 320px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 20;
  overflow: hidden;
}
.picker-tabs { display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.picker-tab {
  flex: 1; padding: 10px; background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 13.5px; font-weight: 600; border-bottom: 2px solid transparent;
}
.picker-tab.active { color: var(--accent); border-color: var(--accent); }
.picker-body { flex: 1; overflow-y: auto; padding: 8px; }
.emoji-cat-label { font-size: 11.5px; color: var(--text-secondary); margin: 6px 4px 2px; text-transform: uppercase; letter-spacing: .04em; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); gap: 2px; }
.emoji-grid button {
  background: none; border: none; font-size: 22px; padding: 5px; border-radius: 8px; cursor: pointer; line-height: 1;
}
.emoji-grid button:hover { background: var(--bg-hover); }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.sticker-grid button {
  background: none; border: none; font-size: 44px; padding: 6px; border-radius: 10px; cursor: pointer; line-height: 1;
}
.sticker-grid button:hover { background: var(--bg-hover); }

/* ===== Composer ===== */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 8px 10px;
  background: var(--bg-composer);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.composer-input-wrap { flex: 1; }
#messageInput {
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: var(--bg-hover);
  color: var(--text-primary);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 14.5px;
  max-height: 120px;
  line-height: 1.35;
}
.send-btn { background: var(--accent); color: #fff; }
.send-btn:hover { background: var(--accent); filter: brightness(1.1); color: #fff; }
.voice-btn.recording { color: var(--danger); }

/* ===== Voice record bar ===== */
.voice-record-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-composer);
  border-top: 1px solid var(--border);
}
.voice-record-dot {
  width: 11px; height: 11px; border-radius: 50%; background: var(--danger);
  animation: recpulse 1s infinite;
}
@keyframes recpulse { 50% { opacity: .3; } }
.voice-record-time { font-variant-numeric: tabular-nums; font-size: 14px; }
.voice-record-hint { color: var(--text-secondary); font-size: 13px; flex: 1; }

/* ===== Lightbox ===== */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.lightbox-content img, .lightbox-content video { max-width: 92vw; max-height: 88vh; border-radius: 6px; }
.lightbox-close {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,.1); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 50%; font-size: 22px; cursor: pointer;
}

.toast {
  position: absolute;
  bottom: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2c38;
  color: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow);
}

/* ===== Auth pages ===== */
.auth-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #08080a;
  background-image:
    radial-gradient(circle at 18% 15%, rgba(255,122,26,.16), transparent 42%),
    radial-gradient(circle at 85% 85%, rgba(255,122,26,.1), transparent 40%),
    radial-gradient(circle at 90% 10%, rgba(255,255,255,.04), transparent 30%);
  padding: 20px;
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: #141415;
  border: 1px solid #2a2a2c;
  border-radius: 22px;
  padding: 40px 32px;
  box-shadow: 0 25px 70px rgba(0,0,0,.6), 0 0 0 1px rgba(255,122,26,.04);
  color: #f5f5f5;
}
.auth-logo { text-align: center; margin-bottom: 30px; }
.logo-circle {
  width: 62px; height: 62px; border-radius: 18px;
  background: linear-gradient(135deg,#ff9d4d,#f0670a);
  color: #fff; font-size: 28px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 10px 28px rgba(255,122,26,.35);
}
.auth-logo h1 { font-size: 21px; margin: 0 0 6px; letter-spacing: -.01em; }
.auth-logo p { font-size: 13px; color: #9a9a9d; margin: 0; }
.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 12px;
  background: rgba(255,122,26,.1);
  border: 1px solid rgba(255,122,26,.25);
  color: #ff9d4d;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
}
.auth-error {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(224,88,107,.1);
  border: 1px solid rgba(224,88,107,.35);
  color: #f29aa6;
  padding: 11px 13px;
  border-radius: 12px;
  font-size: 13px;
  margin-bottom: 18px;
}
.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 12px; font-weight: 600; color: #9a9a9d; margin-top: 14px; text-transform: uppercase; letter-spacing: .03em; }
.auth-field { position: relative; }
.auth-field svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: #6c6c6e; pointer-events: none; }
.auth-form input {
  width: 100%;
  background: #0c0c0d;
  border: 1.5px solid #2a2a2c;
  border-radius: 12px;
  padding: 13px 13px 13px 40px;
  color: #f5f5f5;
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.auth-field.has-toggle input { padding-right: 42px; }
.auth-form input:focus { border-color: #ff7a1a; box-shadow: 0 0 0 3px rgba(255,122,26,.15); }
.auth-toggle-pass {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: #6c6c6e; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center;
}
.auth-toggle-pass:hover { background: #202022; color: #f5f5f5; }
.auth-form button {
  margin-top: 24px;
  background: linear-gradient(135deg,#ff9d4d,#f0670a);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255,122,26,.3);
  transition: transform .12s, box-shadow .12s, filter .12s;
}
.auth-form button:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 14px 30px rgba(255,122,26,.4); }
.auth-form button:active { transform: translateY(0); }
.auth-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 12px;
  color: #6c6c6e;
}

@media (max-width: 380px) {
  .auth-card { padding: 30px 22px; border-radius: 16px; }
}
