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

:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --text-sub: #64748b;
  --border: #e2e8f0;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ===== Layout ===== */
.chat-container {
  width: 100%;
  max-width: 640px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

/* ===== Header ===== */
.header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-icon {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.header-text h1 {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.header-text p {
  font-size: 0.75rem;
  opacity: 0.85;
}

.header-manual-btn {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 20px;
  white-space: nowrap;
  transition: background 0.2s;
}

.header-manual-btn:hover {
  background: rgba(255, 255, 255, 0.35);
}

/* ===== Categories ===== */
.categories {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.categories::-webkit-scrollbar {
  display: none;
}

.cat-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text-sub);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.cat-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.cat-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Chat Area ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ===== Messages ===== */
.message {
  max-width: 88%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  line-height: 1.7;
  animation: fadeIn 0.2s ease;
}

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

.message.bot {
  align-self: flex-start;
  background: #f1f5f9;
  border-bottom-left-radius: 4px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Answer card inside bot message */
.answer-card {
  margin-top: 8px;
}

.answer-card .answer-text {
  white-space: pre-line;
}

.answer-card .answer-link {
  display: inline-block;
  margin-top: 10px;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  overflow-wrap: break-word;
  word-break: break-word;
  max-width: 100%;
}

.answer-card .answer-link:hover {
  text-decoration: underline;
}

/* ===== Feedback ===== */
.feedback {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.feedback-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
}

.feedback-btn:hover {
  transform: scale(1.03);
}

.feedback-btn.resolve {
  border-color: var(--success);
  color: var(--success);
}

.feedback-btn.resolve:hover {
  background: var(--success);
  color: #fff;
}

.feedback-btn.not-resolve {
  border-color: var(--danger);
  color: var(--danger);
}

.feedback-btn.not-resolve:hover {
  background: var(--danger);
  color: #fff;
}

.feedback-btn:disabled {
  opacity: 0.5;
  cursor: default;
  transform: none;
}

.feedback-done {
  font-size: 0.8125rem;
  color: var(--text-sub);
  margin-top: 6px;
}

/* ===== Suggestions ===== */
.suggestions {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  display: none;
  z-index: 5;
}

.suggestions.show {
  display: block;
}

.suggestion-item {
  padding: 10px 16px;
  font-size: 0.8125rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover {
  background: var(--primary-light);
}

.suggestion-item .cat-label {
  flex-shrink: 0;
  font-size: 0.6875rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: #f1f5f9;
  color: var(--text-sub);
}

/* ===== Input Area ===== */
.input-area {
  position: sticky;
  bottom: 0;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.input-wrapper {
  position: relative;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-wrapper input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.input-wrapper input:focus {
  border-color: var(--primary);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

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

.send-btn:disabled {
  background: #cbd5e1;
  cursor: default;
}

/* ===== Welcome ===== */
.welcome {
  text-align: center;
  padding: 24px 16px;
  color: var(--text-sub);
}

.welcome h2 {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 4px;
}

.welcome p {
  font-size: 0.8125rem;
}

/* ===== Popular FAQs ===== */
.popular-faqs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 16px 12px;
}

.popular-faq-btn {
  text-align: left;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
}

.popular-faq-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ===== Typing indicator ===== */
.typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--text-sub);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

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

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

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-6px);
  }
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .chat-container {
    box-shadow: none;
  }
}
