/* Мини-приложение Telegram — стиль сайдбара/чата сознательно повторяет
   ChatGPT (тёмная тема, центральная колонка сообщений, ховер-меню у
   чата в списке), как и просил пользователь: "прям как сайт чата гпт". */

:root {
  --bg-sidebar: #171717;
  --bg-main: #212121;
  --bg-hover: #2a2a2a;
  --bg-active: #2f2f2f;
  --bg-input: #2f2f2f;
  --bg-bubble-user: #2f2f2f;
  --border: #2f2f2f;
  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #8e8ea0;
  --accent: #ffffff;
  --accent-text: #0f0f0f;
  --danger: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* Без этого явного правила атрибут [hidden] проигрывает display:flex/block
   ниже — авторские стили всегда сильнее дефолтного UA-стиля браузера,
   независимо от специфичности селектора. Без этой строки модалка профиля
   и меню чата были бы видны сразу при загрузке страницы. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

.app {
  display: flex;
  height: 100vh;
  height: var(--tg-viewport-stable-height, 100vh);
  overflow: hidden;
}

/* --- Сайдбар ---------------------------------------------------------- */

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 8px;
  transition: margin-left 0.2s ease;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  text-align: left;
}
.new-chat-btn:hover { background: var(--bg-hover); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
  white-space: nowrap;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }

.chat-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-menu-btn {
  opacity: 0;
  padding: 4px;
  border-radius: 6px;
  flex-shrink: 0;
}
.chat-item:hover .chat-item-menu-btn,
.chat-item-menu-btn.force-visible { opacity: 1; }
.chat-item-menu-btn:hover { background: var(--bg-active); }

.chat-list-empty {
  padding: 16px 10px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
}
.user-row:hover { background: var(--bg-hover); }

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #6b7280;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

.user-info { overflow: hidden; }
.user-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-tier {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 5;
}

/* --- Основная панель чата ---------------------------------------------- */

.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-main);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-toggle { display: none; }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-secondary);
}
.icon-btn:hover { background: var(--bg-hover); }

.chat-title {
  font-size: 14px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-header-spacer { flex: 1; }

.banner {
  margin: 10px auto 0;
  max-width: 700px;
  width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 10px;
  background: #3a2e12;
  color: #f5cf7e;
  font-size: 13px;
  text-align: center;
}
.banner.banner-error { background: #3a1414; color: #f8a4a4; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 8px;
}

.empty-state {
  max-width: 700px;
  margin: 10vh auto 0;
  text-align: center;
  padding: 0 16px;
}
.empty-state-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 10px;
}
.empty-state-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

.message-row {
  max-width: 700px;
  margin: 0 auto 18px;
  display: flex;
  gap: 12px;
}

.message-row.role-user { justify-content: flex-end; }

.message-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #10a37f;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  margin-top: 2px;
}

.message-bubble {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.role-user .message-bubble {
  background: var(--bg-bubble-user);
  padding: 10px 14px;
  border-radius: 18px;
  max-width: 80%;
}

.role-assistant .message-bubble { max-width: calc(100% - 38px); }

.message-bubble code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}

.message-bubble.typing { color: var(--text-muted); }
.typing-dots span {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 700px;
  width: calc(100% - 32px);
  margin: 0 auto 14px;
  padding: 8px 8px 8px 16px;
  background: var(--bg-input);
  border-radius: 24px;
  flex-shrink: 0;
}

.composer-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.4;
  max-height: 160px;
  padding: 8px 0;
  font-family: inherit;
}
.composer-input::placeholder { color: var(--text-muted); }

.composer-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.35;
  transition: opacity 0.15s ease;
}
.composer-send.enabled { opacity: 1; }

/* --- Модалка профиля ---------------------------------------------------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}

.modal {
  background: #2a2a2a;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 600; }

.modal-body { padding: 16px; }

.profile-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  gap: 12px;
}
.profile-row:last-of-type { border-bottom: none; }
.profile-label { color: var(--text-muted); }
.profile-value { text-align: right; }

.profile-hint {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}
.profile-hint code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
}

/* --- Меню чата ("...") --------------------------------------------------- */

.chat-menu {
  position: fixed;
  background: #2a2a2a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  min-width: 160px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.chat-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.chat-menu-item:hover { background: var(--bg-hover); }
.chat-menu-item-danger { color: var(--danger); }

/* --- Мобильная раскладка -------------------------------------------------- */

@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    margin-left: -260px;
  }
  .app.sidebar-open .sidebar { margin-left: 0; }
  .app.sidebar-open .sidebar-backdrop { display: block; }

  .empty-state { margin-top: 6vh; }
}
