/* StasGPT — claude.ai-inspired theme */

:root {
  --bg: #262624;
  --bg-sidebar: #1f1f1d;
  --bg-elev: #30302e;
  --bg-hover: #35343100;
  --bg-hover-strong: #3a3a37;
  --border: #3a3936;
  --border-soft: #2e2d2b;
  --text: #f5f4ed;
  --text-muted: #b8b5a8;
  --text-dim: #8a8679;
  --accent: #d97757;
  --accent-hover: #c86844;
  --accent-soft: rgba(217, 119, 87, 0.12);
  --bubble-user: #3a3633;
  --bubble-ai: transparent;
  --danger: #e06c5a;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

textarea {
  font: inherit;
  color: inherit;
}

body {
  display: flex;
}

/* ---------- sidebar ---------- */

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
  transition: transform 0.25s ease, width 0.25s ease, padding 0.25s ease;
  z-index: 20;
}

.sidebar.collapsed {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 14px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.1px;
}

.logo-mark {
  font-size: 20px;
}

.logo-text {
  color: var(--text);
}

.sidebar-toggle {
  display: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-hover-strong);
  color: var(--text);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  margin-bottom: 20px;
  transition: background 0.15s, border-color 0.15s;
}

.new-chat-btn:hover {
  background: var(--bg-hover-strong);
  border-color: var(--text-dim);
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
}

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dim);
  padding: 6px 10px;
  margin-bottom: 4px;
}

.modes-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mode-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  text-align: left;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.mode-item:hover {
  background: var(--bg-hover-strong);
  color: var(--text);
}

.mode-item.active {
  background: var(--accent-soft);
  color: var(--text);
}

.mode-item.active .mode-sub {
  color: var(--text-muted);
}

.mode-emoji {
  font-size: 17px;
  line-height: 1.2;
  flex-shrink: 0;
}

.mode-avatar {
  position: relative;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent), #b8583a);
}

.mode-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.mode-avatar .mode-emoji-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.mode-body {
  flex: 1;
  min-width: 0;
}

.mode-title {
  font-weight: 500;
  font-size: 14px;
  color: inherit;
}

.mode-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 2px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-foot {
  border-top: 1px solid var(--border-soft);
  padding: 14px 6px 4px;
  margin-top: 8px;
}

.foot-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #b8583a);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  color: #fff;
  letter-spacing: 0.5px;
}

.foot-info {
  min-width: 0;
}

.foot-name {
  font-size: 13.5px;
  font-weight: 500;
}

.foot-sub {
  font-size: 11px;
  color: var(--text-dim);
}

.foot-note {
  font-size: 11px;
  color: var(--text-dim);
  padding: 10px 2px 2px;
}

/* ---------- main ---------- */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  z-index: 5;
}

/* Название режима в topbar — видно только на мобильном (topbar скрыт на десктопе).
   Это кнопка, по тапу открывается sidebar со списком режимов. */
.topbar-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  max-width: 62%;
  overflow: hidden;
}

.topbar-title:hover,
.topbar-title:active {
  background: var(--bg-hover-strong);
  border-color: var(--text-dim);
}

.topbar-title-emoji {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, var(--accent), #b8583a);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar-title-emoji img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topbar-title-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.topbar-title-chev {
  flex-shrink: 0;
  color: var(--text-dim);
  margin-left: -2px;
}

.menu-btn {
  display: none;
}

/* ---------- chat ---------- */

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 120px;
}

.messages {
  max-width: 740px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.welcome {
  text-align: center;
  padding: 8px 16px 10px;
  animation: fadeIn 0.4s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.welcome-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(217, 119, 87, 0.2);
  animation: avatarIn 0.5s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}

.welcome-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@keyframes avatarIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 620px;
  margin: 0 auto;
}

.chip {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-muted);
  background: transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.chip:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: slideUp 0.35s ease;
  min-width: 0;
  max-width: 100%;
}

.msg-user {
  justify-content: flex-end;
}

.msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 0;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, var(--accent), #b8583a);
}

.msg-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.msg-avatar-fallback {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: linear-gradient(135deg, var(--accent), #b8583a);
  color: #fff;
}

.msg-bubble {
  max-width: min(640px, 100%);
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  min-width: 0;
}

.msg-user .msg-bubble {
  background: var(--bubble-user);
  color: var(--text);
  border-bottom-right-radius: 6px;
}

.msg-ai .msg-bubble {
  background: var(--bubble-ai);
  padding: 0;
  color: var(--text);
  flex: 1 1 0;
  min-width: 0;
  max-width: calc(100% - 40px);
}

.msg-ai .msg-bubble p {
  margin: 0 0 10px;
}

.msg-ai .msg-bubble p:last-child {
  margin-bottom: 0;
}

.stream-cursor {
  display: inline-block;
  width: 8px;
  height: 1.1em;
  vertical-align: text-bottom;
  margin-left: 2px;
  background: var(--accent);
  border-radius: 1px;
  animation: blink 1s steps(2, start) infinite;
  opacity: 0.85;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

.typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 8px 0 0;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--text-dim);
  border-radius: 50%;
  animation: pulse 1.2s ease infinite;
}
.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ---------- composer ---------- */

.composer-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 20px calc(24px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 60%, rgba(38, 38, 36, 0));
  pointer-events: none;
}

.composer {
  max-width: 740px;
  margin: 0 auto;
  pointer-events: auto;
  min-width: 0;
}

.composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 6px 6px 6px 18px;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.composer-inner:focus-within {
  border-color: var(--accent);
  background: #363432;
}

#input {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px; /* 16+ чтобы iOS не зумил при фокусе */
  max-height: 200px;
  line-height: 1.5;
  /* Высота textarea = line-height; send-btn 36px выше на 12px, поэтому
     добавляем вертикальный padding, чтобы текст был симметрично
     центрирован относительно кнопки: 6 (композер) + 6 (textarea) = 12. */
  padding: 6px 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

#input::placeholder {
  color: var(--text-dim);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-hover);
}

.send-btn:active {
  transform: scale(0.95);
}

.send-btn:disabled {
  background: var(--border);
  color: var(--text-dim);
  cursor: not-allowed;
}

.composer-hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 8px 4px 0;
}

/* ---------- scrollbars ---------- */

.chat::-webkit-scrollbar,
.sidebar-section::-webkit-scrollbar {
  width: 8px;
}

.chat::-webkit-scrollbar-thumb,
.sidebar-section::-webkit-scrollbar-thumb {
  background: #3a3936;
  border-radius: 4px;
}

.chat::-webkit-scrollbar-thumb:hover,
.sidebar-section::-webkit-scrollbar-thumb:hover {
  background: #4a4845;
}

/* ---------- backdrop ---------- */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 15;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.sidebar-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ---------- animations ---------- */

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: scale(0.9);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---------- mobile ---------- */

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    width: 280px;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    width: 100%;
  }

  .menu-btn {
    display: inline-flex;
  }

  .chat {
    padding: 14px 14px calc(160px + env(safe-area-inset-bottom, 0px));
  }

  .composer-wrap {
    padding: 0 12px calc(18px + env(safe-area-inset-bottom, 0px));
  }

  .composer-hint {
    font-size: 10.5px;
    padding: 6px 4px 0;
  }

  .msg-bubble {
    font-size: 14.5px;
  }

  .message {
    gap: 10px;
  }

  .msg-ai .msg-bubble {
    max-width: calc(100% - 36px);
  }
}

@media (min-width: 821px) {
  .sidebar-toggle {
    display: inline-flex;
  }

  /* На десктопе topbar не нужен: sidebar уже содержит "Новый разговор"
     и список режимов с активным элементом. */
  .topbar {
    display: none;
  }
}
