:root {
  --sidebar-bg: #f9f9f9;
  --sidebar-border: #e5e5e5;
  --sidebar-hover: #ececec;
  --main-bg: #ffffff;
  --ink: #0d0d0d;
  --muted: #6e6e80;
  --bubble-user: #f4f4f4;
  --border: #e5e5e5;
  --accent: #10a37f;
  --accent-hover: #0e8f6f;
  --focus: #2d6cdf;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
}

* {
  box-sizing: border-box;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--main-bg);
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Сайдбар ---------- */

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 12px;
  transition: margin-left 0.18s ease;
}

.sidebar.collapsed {
  margin-left: -260px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--sidebar-border);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
}

.new-chat-btn:hover {
  background: var(--sidebar-hover);
}

.new-chat-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}

.sidebar-search {
  margin-top: 10px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 13px;
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  background: #fff;
}

.sidebar-search input:focus-visible {
  outline: 2px solid var(--focus);
}

.history {
  flex: 1;
  overflow-y: auto;
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 12px 8px 4px;
}

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 30px 8px 10px;
  border: none;
  background: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}

.history-item-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover {
  background: var(--sidebar-hover);
}

.history-item.active {
  background: var(--sidebar-hover);
  font-weight: 500;
}

.history-item:focus-visible {
  outline: 2px solid var(--focus);
}

/* ---------- Пункт истории: обёртка + кнопка "..." + меню ---------- */

.history-item-wrapper {
  position: relative;
}

.history-more-btn {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
}

.history-item-wrapper:hover .history-more-btn,
.history-more-btn.menu-open {
  opacity: 1;
}

.history-more-btn:hover {
  background: #e0e0e0;
  color: var(--ink);
}

.history-more-btn:focus-visible {
  outline: 2px solid var(--focus);
  opacity: 1;
}

.history-menu {
  position: absolute;
  top: calc(100% + 2px);
  right: 4px;
  background: #fff;
  border: 1px solid var(--sidebar-border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  padding: 4px;
  min-width: 170px;
  z-index: 30;
}

.history-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}

.history-menu-item:hover {
  background: var(--sidebar-hover);
}

.history-menu-item:focus-visible {
  outline: 2px solid var(--focus);
}

.history-menu-item--danger {
  color: #d0342c;
}

.history-menu-item--danger:hover {
  background: #fdeceb;
}

.history-rename-input {
  width: 100%;
  font-family: var(--font);
  font-size: 13.5px;
  border: 1px solid var(--focus);
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
  background: #fff;
  box-sizing: border-box;
}

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding-top: 10px;
  margin-top: 8px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  font-size: 13.5px;
  border-radius: 8px;
}

.user-chip:hover {
  background: var(--sidebar-hover);
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.avatar--user {
  background: var(--accent);
  color: #fff;
}

.avatar--assistant {
  background: #202123;
  color: #fff;
}

/* ---------- Основная область чата ---------- */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  display: flex;
}

.icon-btn:hover {
  background: var(--sidebar-hover);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--focus);
}

.chat-title {
  font-weight: 600;
  font-size: 15px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 8px;
}

.welcome {
  max-width: 640px;
  margin: 8vh auto 0;
  text-align: center;
}

.welcome h1 {
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 8px;
}

.welcome p {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 20px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestion-chip {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-family: var(--font);
  font-size: 13.5px;
  cursor: pointer;
  color: var(--ink);
}

.suggestion-chip:hover {
  background: var(--sidebar-hover);
}

.suggestion-chip:focus-visible {
  outline: 2px solid var(--focus);
}

.message-row {
  max-width: 768px;
  margin: 0 auto 20px;
  display: flex;
  gap: 12px;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.user .bubble {
  background: var(--bubble-user);
  border-radius: 18px;
  padding: 10px 16px;
  max-width: 70%;
}

.message-row.assistant .bubble {
  padding-top: 2px;
  max-width: 100%;
}

.bubble {
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.bubble p {
  margin: 0 0 10px;
}
.bubble p:last-child {
  margin-bottom: 0;
}

/* Мини-карточка купона внутри ответа ассистента */
.coupon-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 10px 0;
}

.coupon-card__top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.coupon-card__store {
  font-weight: 600;
  font-size: 14.5px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.coupon-card__logo {
  width: 20px;
  height: 20px;
  object-fit: contain;
  border-radius: 4px;
  flex-shrink: 0;
}

.coupon-card__discount {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--accent);
}

.coupon-card__desc {
  color: var(--muted);
  font-size: 13.5px;
  margin: 4px 0 10px;
}

.coupon-card__bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.coupon-card__code {
  font-family: ui-monospace, 'SF Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  border: 1px dashed var(--accent);
  color: var(--accent);
  padding: 5px 10px;
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.coupon-card__code:hover {
  background: var(--accent);
  color: #fff;
}

.coupon-card__code:focus-visible {
  outline: 2px solid var(--focus);
}

.coupon-card__code.copied {
  background: var(--accent);
  color: #fff;
}

.coupon-card__link {
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--ink);
}

.coupon-card__link:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 6px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--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.25; }
  40% { opacity: 1; }
}

/* ---------- Composer (поле ввода) ---------- */

.composer {
  flex-shrink: 0;
  padding: 8px 16px 14px;
}

#composerForm {
  max-width: 768px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 28px;
  padding: 11px 11px 11px 20px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.02), 0 4px 14px rgba(0,0,0,0.06);
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

#composerForm:focus-within {
  border-color: rgba(0,0,0,0.15);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.03), 0 6px 20px rgba(0,0,0,0.09);
}

#messageInput {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  max-height: 160px;
  padding: 4px 0;
  background: none;
}

#sendBtn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

#sendBtn:hover {
  background: var(--accent-hover);
}

#sendBtn:disabled {
  background: #d9d9e3;
  cursor: default;
}

#sendBtn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.disclaimer {
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  margin: 8px 0 0;
}

/* ---------- Мобильная адаптация ---------- */

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    z-index: 20;
    height: 100vh;
  }
  .sidebar.collapsed {
    margin-left: -260px;
  }
  .sidebar:not(.collapsed) {
    box-shadow: 0 0 0 100vmax rgba(0,0,0,0.3);
  }
  .message-row.user .bubble {
    max-width: 85%;
  }
}
