/* ==========================================================
   Somgram — style.css
   Telegram-inspired visual language on top of Bootstrap 5.
   Color system, layout, chat bubbles, and component styling.
   Dark mode overrides live in dark-mode.css.
   ========================================================== */

:root {
  --sg-primary: #2AABEE;
  --sg-primary-dark: #229ED9;
  --sg-accent-gradient: linear-gradient(135deg, #2AABEE 0%, #229ED9 100%);
  --sg-bg: #f4f4f5;
  --sg-panel: #ffffff;
  --sg-border: #e6e6e6;
  --sg-text: #17212b;
  --sg-text-secondary: #707579;
  --sg-bubble-out: #effdde;
  --sg-bubble-in: #ffffff;
  --sg-bubble-out-dark-text: #0d2b12;
  --sg-sidebar-width: 380px;
  --sg-radius: 14px;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  background: var(--sg-bg);
  color: var(--sg-text);
  overflow: hidden;
  height: 100vh;
  margin: 0;
}

/* ---------------- Auth pages ---------------- */
.auth-body {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--sg-accent-gradient);
}
.auth-wrap { width: 100%; max-width: 420px; padding: 1rem; }
.auth-card { border-radius: 20px; }
.brand-mark {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--sg-accent-gradient);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.75rem;
}
.letter-spaced { letter-spacing: 0.5em; }
.auth-step { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px);} to { opacity:1; transform:none; } }

/* ---------------- App shell ---------------- */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---------------- Sidebar ---------------- */
.sidebar {
  width: var(--sg-sidebar-width);
  min-width: 300px;
  max-width: 420px;
  background: var(--sg-panel);
  border-right: 1px solid var(--sg-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-top {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--sg-border);
}
.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--sg-bg);
  border-radius: 20px;
  padding: .45rem .9rem;
}
.search-box input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  color: var(--sg-text);
  font-size: .9rem;
}
.search-box i { color: var(--sg-text-secondary); }

.icon-btn {
  border: none;
  background: transparent;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--sg-text-secondary);
  font-size: 1.1rem;
  transition: background .15s;
}
.icon-btn:hover { background: var(--sg-bg); color: var(--sg-text); }

.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .9rem;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  transition: background .12s;
}
.chat-item:hover { background: var(--sg-bg); }
.chat-item.active { background: rgba(42,171,238,.12); }
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item-title { font-weight: 600; font-size: .93rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: .72rem; color: var(--sg-text-secondary); flex-shrink: 0; }
.chat-item-preview { font-size: .84rem; color: var(--sg-text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-badge {
  background: var(--sg-primary);
  color: #fff; font-size: .7rem; font-weight: 600;
  border-radius: 10px; padding: 1px 7px; min-width: 20px; text-align: center;
}

/* ---------------- Avatars ---------------- */
.avatar {
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.avatar-sm { width: 42px; height: 42px; }
.avatar-lg { width: 96px; height: 96px; }
.avatar-fallback {
  background: var(--sg-accent-gradient);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.avatar-lg.avatar-fallback { font-size: 2.25rem; }

/* ---------------- Chat window ---------------- */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--sg-bg);
  background-image: radial-gradient(circle at 25% 15%, rgba(42,171,238,.05), transparent 40%);
}
.chat-placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
}
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .55rem .9rem;
  background: var(--sg-panel);
  border-bottom: 1px solid var(--sg-border);
}
.chat-header-info { min-width: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 6%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }
.msg-bubble {
  max-width: 70%;
  padding: .5rem .75rem .35rem;
  border-radius: var(--sg-radius);
  background: var(--sg-bubble-in);
  box-shadow: 0 1px 1px rgba(0,0,0,.05);
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg-row.out .msg-bubble { background: var(--sg-bubble-out); }
.msg-row.in .msg-bubble { border-top-left-radius: 4px; }
.msg-row.out .msg-bubble { border-top-right-radius: 4px; }
.msg-text { font-size: .93rem; line-height: 1.4; }
.msg-meta { font-size: .68rem; color: var(--sg-text-secondary); text-align: right; margin-top: 2px; }
.msg-media { max-width: 280px; border-radius: 10px; margin-bottom: 4px; display: block; }
.msg-file {
  display: flex; align-items: center; gap: .5rem;
  background: rgba(0,0,0,.03); border-radius: 10px; padding: .5rem .75rem; margin-bottom: 4px;
}

/* ---------------- Composer ---------------- */
.composer {
  display: flex; align-items: flex-end; gap: .35rem;
  padding: .6rem .9rem;
  background: var(--sg-panel);
  border-top: 1px solid var(--sg-border);
}
.composer-input {
  flex: 1;
  border: 1px solid var(--sg-border);
  border-radius: 20px;
  padding: .55rem 1rem;
  resize: none;
  max-height: 140px;
  outline: none;
  font-size: .93rem;
  background: var(--sg-bg);
  color: var(--sg-text);
}
.send-btn { background: var(--sg-primary); color: #fff; }
.send-btn:hover { background: var(--sg-primary-dark); color: #fff; }

.emoji-picker {
  position: absolute;
  bottom: 70px;
  left: 20px;
  width: 320px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--sg-panel);
  border: 1px solid var(--sg-border);
  border-radius: 12px;
  padding: .5rem;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  box-shadow: 0 6px 24px rgba(0,0,0,.15);
  z-index: 20;
}
.emoji-picker span { cursor: pointer; font-size: 1.3rem; text-align: center; border-radius: 6px; padding: 3px; }
.emoji-picker span:hover { background: var(--sg-bg); }

.upload-preview {
  position: absolute; bottom: 70px; left: 20px; right: 20px;
  background: var(--sg-panel); border: 1px solid var(--sg-border);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.12);
}

/* ---------------- Scrollbars ---------------- */
.chat-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .emoji-picker::-webkit-scrollbar { width: 6px; }
.chat-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }

/* ---------------- Avatar edit (profile) ---------------- */
.avatar-edit-btn {
  position: absolute; bottom: 0; right: 0;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--sg-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border: 2px solid var(--sg-panel);
}

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
  .sidebar { position: absolute; inset: 0; z-index: 5; width: 100%; max-width: none; }
  .chat-window { width: 100%; }
  .app-shell.chat-open .sidebar { display: none; }
  .app-shell:not(.chat-open) .chat-window { display: none; }
  #backToListBtn { display: inline-flex !important; }
}
@media (min-width: 901px) {
  #backToListBtn { display: none !important; }
}
