/* YoBuGram — минимальный Telegram-like UI (vanilla) */
:root {
  --bg: #0b1220;
  --panel: #111a2e;
  --panel2: #0f1730;
  --text: #e7eaf3;
  --muted: #95a0b7;
  --border: rgba(255,255,255,0.08);
  --primary: #4f8cff;
  --danger: #ff4f5e;
  --shadow: 0 12px 40px rgba(0,0,0,0.45);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 20% 10%, rgba(79,140,255,0.20), transparent 55%),
              radial-gradient(1000px 700px at 80% 90%, rgba(0,230,162,0.10), transparent 55%),
              var(--bg);
  color: var(--text);
  /* Важно: не даём скроллить всю страницу — скроллим только панели/списки */
  overflow: hidden;
}

.hidden { display: none !important; }
.mobile-only { display: none; }

.view { height: 100vh; height: 100dvh; }

/* Auth */
.auth {
  display: grid;
  place-items: center;
  padding: 20px;
  /* На маленьких экранах пусть скроллится именно auth-view, а не body */
  overflow: auto;
}
.auth-card {
  width: min(420px, 100%);
  background: rgba(17, 26, 46, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.brand-badge {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(79,140,255,1), rgba(0,230,162,0.85));
  font-weight: 800;
}
.brand-title { font-weight: 700; font-size: 18px; }
.brand-subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.tab.active { color: var(--text); border-color: rgba(79,140,255,0.6); }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; color: var(--muted); }
input, select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 48, 0.7);
  color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: rgba(79,140,255,0.8); }
.hint { font-size: 12px; color: var(--muted); margin-top: 12px; }
.hint.error { color: #ffb2b8; }

.btn {
  border: 1px solid var(--border);
  background: rgba(15, 23, 48, 0.7);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
}
.btn.primary { background: linear-gradient(135deg, rgba(79,140,255,1), rgba(79,140,255,0.75)); border: none; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(255,79,94,0.15); border-color: rgba(255,79,94,0.35); }

.icon-btn {
  border: 1px solid var(--border);
  background: rgba(15, 23, 48, 0.55);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 12px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Main layout */
.main {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.sidebar {
  background: rgba(17, 26, 46, 0.8);
  border-right: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto 1fr auto;
  backdrop-filter: blur(12px);
  min-height: 0;
}
.sidebar-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-title { font-weight: 700; }
.sidebar-search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sidebar-search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
}
.folder-bar {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  overflow: auto;
  padding-bottom: 4px;
}
.folder-chip {
  border: 1px solid var(--border);
  background: rgba(15, 23, 48, 0.35);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  font-size: 12px;
}
.folder-chip.active {
  color: var(--text);
  border-color: rgba(79,140,255,0.6);
  background: rgba(79,140,255,0.12);
}
.chat-list {
  padding: 10px;
  overflow: auto;
  min-height: 0;
  overscroll-behavior: contain;
}
.chat-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: rgba(15, 23, 48, 0.55);
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.chat-item.active { border-color: rgba(79,140,255,0.6); }
.chat-item-title { font-weight: 600; margin-bottom: 4px; }
.chat-item-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-content { min-width: 0; flex: 1; }

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  flex: 0 0 auto;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.me { color: var(--muted); font-size: 13px; }

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(11, 18, 32, 0.5);
  min-height: 0;
  overflow: hidden;
}
.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(17, 26, 46, 0.4);
  backdrop-filter: blur(10px);
}
.chat-title { font-weight: 700; }
.chat-subtitle { color: var(--muted); font-size: 12px; margin-top: 3px; }
.chat-actions { display: flex; gap: 8px; }

.panel {
  background: rgba(11, 18, 32, 0.5);
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  height: 100dvh;
}
.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 26, 46, 0.4);
  backdrop-filter: blur(10px);
}
.panel-title { font-weight: 700; }
.panel-search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.panel-search input { width: 100%; padding: 10px 12px; border-radius: 12px; }
.panel-list { padding: 10px; overflow: auto; }
.panel-body { padding: 12px; overflow: auto; display: grid; gap: 12px; }
.card {
  border: 1px solid var(--border);
  background: rgba(17, 26, 46, 0.6);
  border-radius: 14px;
  padding: 12px;
}
.card-title { font-weight: 700; margin-bottom: 8px; }

.profile-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--border);
  background: rgba(17, 26, 46, 0.6);
  border-radius: 14px;
  padding: 12px;
}
.avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(79,140,255,1), rgba(0,230,162,0.55));
  font-weight: 800;
}
.profile-name { font-weight: 800; }
.profile-username { color: var(--muted); font-size: 13px; margin-top: 2px; }
.profile-bio { color: var(--muted); font-size: 13px; margin-top: 6px; }

.mobile-tabs {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 60px;
  background: rgba(17, 26, 46, 0.92);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
  z-index: 1500;
  grid-template-columns: repeat(4, 1fr);
}
.mobile-tab {
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.mobile-tab.active { color: var(--text); }

.message-list {
  padding: 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overscroll-behavior: contain;
}
.msg {
  max-width: 76ch;
  background: rgba(17, 26, 46, 0.75);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  align-self: flex-start;
}
.msg.mine {
  align-self: flex-end;
  background: rgba(79,140,255,0.18);
  border-color: rgba(79,140,255,0.35);
}
.msg-meta { color: var(--muted); font-size: 11px; margin-bottom: 6px; }
.msg-text { white-space: pre-wrap; word-wrap: break-word; }

.msg-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}
.reactions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.reaction {
  border: 1px solid var(--border);
  background: rgba(15, 23, 48, 0.5);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
}
.react-btn {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 10px;
  padding: 4px 8px;
  color: var(--muted);
  cursor: pointer;
}
.emoji-popover {
  display: flex;
  gap: 6px;
}
.emoji-popover button {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 48, 0.55);
  color: var(--text);
  cursor: pointer;
}

.typing {
  padding: 0 16px 10px 16px;
  color: var(--muted);
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: rgba(17, 26, 46, 0.35);
  backdrop-filter: blur(10px);
}

.empty { color: var(--muted); padding: 14px; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 1000;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
}
.modal-card {
  position: relative;
  width: min(520px, 92vw);
  background: rgba(17, 26, 46, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  z-index: 1;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px 12px; }
.modal-title { font-weight: 700; }
.modal-body { padding: 4px; }
.row { display: flex; gap: 10px; }
.stack { display: grid; gap: 12px; }

/* Call overlay */
.call-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.65);
  z-index: 1200;
}
.call-card {
  width: min(980px, 95vw);
  background: rgba(17, 26, 46, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.call-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.call-status { color: var(--muted); }
.call-videos {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 12px;
}
.call-videos video {
  width: 100%;
  height: 420px;
  background: rgba(15,23,48,0.7);
  border-radius: 14px;
  object-fit: cover;
}

@media (max-width: 900px) {
  .mobile-only { display: grid; place-items: center; }

  .main {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }

  .mobile-tabs { display: grid; }

  /* leave space for tabs */
  #panelChats, #panelChat, #panelContacts, #panelSettings, #panelProfile { padding-bottom: 70px; }

  /* default: chats list */
  body[data-mobile-tab="chats"] #panelChats { display: grid; }
  body[data-mobile-tab="chats"] #panelChat,
  body[data-mobile-tab="chats"] #panelContacts,
  body[data-mobile-tab="chats"] #panelSettings,
  body[data-mobile-tab="chats"] #panelProfile { display: none; }

  body[data-mobile-tab="contacts"] #panelContacts { display: grid; }
  body[data-mobile-tab="contacts"] #panelChats,
  body[data-mobile-tab="contacts"] #panelChat,
  body[data-mobile-tab="contacts"] #panelSettings,
  body[data-mobile-tab="contacts"] #panelProfile { display: none; }

  body[data-mobile-tab="settings"] #panelSettings { display: grid; }
  body[data-mobile-tab="settings"] #panelChats,
  body[data-mobile-tab="settings"] #panelChat,
  body[data-mobile-tab="settings"] #panelContacts,
  body[data-mobile-tab="settings"] #panelProfile { display: none; }

  body[data-mobile-tab="profile"] #panelProfile { display: grid; }
  body[data-mobile-tab="profile"] #panelChats,
  body[data-mobile-tab="profile"] #panelChat,
  body[data-mobile-tab="profile"] #panelContacts,
  body[data-mobile-tab="profile"] #panelSettings { display: none; }

  /* open chat full screen */
  body.mobile-chat-open[data-mobile-tab="chats"] #panelChat { display: grid; }
  body.mobile-chat-open[data-mobile-tab="chats"] #panelChats { display: none; }

  .sidebar-footer { display: none; }

  .call-videos { grid-template-columns: 1fr; }
  .call-videos video { height: 280px; }
}
