/* ============================================================
   AI Chat Widget — styles.css
   Palette: white #FFFFFF / black #111111 / blue #00A6E1
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600&display=swap');

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --blue:       #00A6E1;
  --blue-dark:  #0090c5;
  --blue-light: #e6f6fc;
  --black:      #111111;
  --gray-900:   #222222;
  --gray-500:   #888888;
  --gray-200:   #e8e8e8;
  --gray-100:   #f5f5f5;
  --white:      #ffffff;
  --error-bg:   #fff0f0;
  --error-text: #c0392b;
  --radius-bubble: 18px;
  --radius-sm:  6px;
  --font:       'Manrope', sans-serif;
  --shadow:     0 2px 16px rgba(0,166,225,0.10);
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--white);
  font-family: var(--font);
  font-size: 14px;
  color: var(--black);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────────────── */
.chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  background: var(--white);
}

/* ── Header ───────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.header-icon {
  width: 34px;
  height: 34px;
  background: var(--blue);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-icon svg {
  width: 18px;
  height: 18px;
  fill: var(--white);
}

.header-text {
  display: flex;
  flex-direction: column;
}

.header-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--black);
  line-height: 1.2;
}

.header-subtitle {
  font-size: 11px;
  color: var(--blue);
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Online dot */
.header-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--gray-500);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2ecc71;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Clear button */
.clear-btn {
  margin-left: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--gray-500);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.clear-btn:hover {
  background: var(--gray-100);
  color: var(--blue);
}

.clear-btn:active {
  transform: scale(0.9);
}

.clear-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ── Messages Area ────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Scrollbar */
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 4px; }

/* ── Message Bubbles ──────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
}

.message.assistant,
.message.error-msg {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  line-height: 1.55;
  font-size: 13.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Ссылки внутри сообщений */
.bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: opacity 0.2s;
}

.bubble a:hover {
  opacity: 0.8;
}

.message.user .bubble a {
  color: var(--white);
  text-decoration-color: rgba(255, 255, 255, 0.6);
}

.message.assistant .bubble a {
  color: var(--blue);
  font-weight: 500;
  text-decoration-color: var(--blue);
}

.message.user .bubble {
  background: var(--blue);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: var(--gray-100);
  color: var(--black);
  border-bottom-left-radius: 4px;
}

.message.error-msg .bubble {
  background: var(--error-bg);
  color: var(--error-text);
  border-bottom-left-radius: 4px;
  font-size: 12px;
}

.msg-time {
  font-size: 10px;
  color: var(--gray-500);
  margin-top: 3px;
  padding: 0 4px;
}

/* ── Animate in ───────────────────────────────────────────── */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.animate-in {
  animation: slideUp 0.2s ease forwards;
}

/* ── Typing Indicator ─────────────────────────────────────── */
#typing-indicator {
  display: none;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--blue-light);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(0, 166, 225, 0.2);
}

.typing-text {
  font-size: 13px;
  color: var(--blue-dark);
  font-weight: 500;
  animation: pulse-text 1.5s ease-in-out infinite;
}

@keyframes pulse-text {
  0%, 100% { opacity: 0.7; }
  50%      { opacity: 1; }
}

/* ── Input Area ───────────────────────────────────────────── */
.chat-input-area {
  padding: 10px 14px 12px;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  resize: none;
  border: 1.5px solid var(--gray-200);
  border-radius: 20px;
  padding: 9px 14px;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--black);
  background: var(--white);
  outline: none;
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.2s;
}

#message-input::placeholder { color: var(--gray-500); }

#message-input:focus {
  border-color: var(--blue);
}

#message-input:disabled {
  background: var(--gray-100);
  cursor: not-allowed;
}

/* Send button */
#send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--blue);
  color: var(--white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
}

#send-btn:hover:not(:disabled) {
  background: var(--blue-dark);
}

#send-btn:active:not(:disabled) {
  transform: scale(0.93);
}

#send-btn:disabled {
  background: var(--gray-200);
  cursor: not-allowed;
}

#send-btn svg {
  width: 17px;
  height: 17px;
  fill: var(--white);
  transform: translateX(1px); /* оптическое выравнивание */
}

#send-btn:disabled svg {
  fill: var(--gray-500);
}

/* ── Error Toast ──────────────────────────────────────────── */
#error-toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid #f5c6cb;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  max-width: calc(100% - 28px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#error-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 360px) {
  .bubble { font-size: 13px; padding: 9px 12px; }
  .chat-header { padding: 12px 14px; }
}
