:root {
  --bg: #f2eee8;
  --panel: rgba(255, 253, 249, 0.9);
  --panel-strong: #fffdf9;
  --surface: #fffdf9;
  --surface-2: #eee7de;
  --message-user: linear-gradient(135deg, #d66a4d, #bd5260);
  --message-assistant: #f8f4ee;
  --border: rgba(73, 58, 45, 0.16);
  --text: #302923;
  --muted: #84776c;
  --accent: #c85c43;
  --shadow: 0 18px 48px rgba(73, 58, 45, 0.14);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: Georgia, "Times New Roman", serif;
  background: radial-gradient(circle at top left, #f5d8b2 0%, var(--bg) 42%, #e8d6d0 100%);
  color: var(--text);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.chat-shell {
  width: min(1100px, 100%);
  height: min(85vh, 880px);
  background: var(--panel);
  backdrop-filter: blur(24px);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 253, 249, 0.92);
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
}

.chat-badge {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #c85c43;
  box-shadow: 0 0 0 6px rgba(200, 92, 67, 0.14);
}

.chat-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chat-status {
  font-size: 0.8rem;
  color: var(--muted);
}

.chat-status.is-loading {
  color: #b9503b;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.clear-btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  padding: 8px 12px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.clear-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(200, 92, 67, 0.08);
  color: var(--accent);
}

.clear-btn:disabled {
  cursor: wait;
  opacity: 0.55;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 14px;
  background: rgba(248, 244, 238, 0.74);
  scroll-behavior: smooth;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100%;
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 9px;
}

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

.message-row.assistant {
  justify-content: flex-start;
}

.message-avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  object-fit: cover;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 6px 14px rgba(73, 58, 45, 0.18);
}

.message {
  max-width: min(72%, 680px);
  padding: 14px 16px 12px;
  border-radius: 18px;
  line-height: 1.5;
  font-size: 0.97rem;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.2);
}

.message-row.user .message {
  background: #e9edf0;
  color: var(--text);
  border: 1px solid rgba(73, 58, 45, 0.1);
  border-bottom-right-radius: 6px;
}

.message-row.assistant .message {
  background: var(--message-assistant);
  border: 1px solid rgba(73, 58, 45, 0.12);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.72rem;
  opacity: 0.8;
}

.assistant-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  min-height: 52px;
  background: var(--message-assistant);
  border: 1px solid rgba(73, 58, 45, 0.12);
  color: var(--text);
  border-bottom-left-radius: 6px;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 40px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typingPulse 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingPulse {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.chat-footer {
  border-top: 1px solid var(--border);
  background: rgba(255, 253, 249, 0.92);
  padding: 16px 18px 18px;
}

.message-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.input-wrap {
  flex: 1;
  position: relative;
}

.input-wrap textarea {
  width: 100%;
  min-height: 56px;
  max-height: 180px;
  resize: vertical;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(73, 58, 45, 0.16);
  border-radius: 18px;
  color: var(--text);
  font: inherit;
  padding: 15px 18px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-wrap textarea:focus {
  border-color: rgba(96, 165, 250, 0.9);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.18);
}

.input-wrap textarea::placeholder {
  color: var(--muted);
}

.send-btn {
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #a94f5c);
  color: white;
  font-weight: 700;
  min-width: 120px;
  min-height: 56px;
  padding: 0 20px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 30px 12px;
  font-size: 0.96rem;
}

@media (max-width: 768px) {
  body {
    padding: 12px;
  }

  .chat-shell {
    height: calc(100vh - 24px);
    border-radius: 18px;
  }

  .message {
    max-width: 88%;
  }

  .message-avatar {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .message-form {
    align-items: stretch;
  }

  .send-btn {
    min-width: 86px;
  }
}
