/* ── CSS 커스텀 프로퍼티 ── */
:root {
  --color-primary: #f59f00;
  --color-primary-light: #fff3d0;
  --color-bg: #faf8f5;
  --color-surface: #ffffff;
  --color-border: #e9e5df;
  --color-text: #3d3929;
  --color-text-muted: #8a8474;
  --color-user-bubble: #f59f00;
  --color-user-text: #ffffff;
  --color-bot-bubble: #f5f2ed;
  --color-bot-text: #3d3929;
  --radius: 12px;
  --radius-sm: 8px;
}

/* ── 리셋 ── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  display: flex;
  justify-content: center;
  padding: 20px;
  min-height: 100dvh;
}

/* ── 레이아웃 ── */
.container {
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── 헤더 ── */
.header {
  text-align: center;
}

.header-icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 8px;
}

.header h1 {
  font-size: 24px;
  color: var(--color-text);
  margin-bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
}

/* ── 정보 툴팁 ── */
.info-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
}

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: var(--color-border);
  color: var(--color-text-muted);
  border-radius: 50%;
  font-size: 12px;
  font-weight: bold;
  transition: all 0.2s;
}

.info-tooltip:hover .info-icon,
.info-tooltip:focus .info-icon {
  background: var(--color-primary);
  color: white;
}

.tooltip-content {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 8px;
  background: var(--color-text);
  color: var(--color-surface);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: normal;
  line-height: 1.6;
  width: 280px;
  text-align: left;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tooltip-content::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-bottom-color: var(--color-text);
}

.tooltip-content strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
}

.tooltip-content ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.tooltip-content li {
  padding-left: 12px;
  position: relative;
  margin-top: 4px;
}

.tooltip-content li::before {
  content: '•';
  position: absolute;
  left: 2px;
  color: var(--color-primary);
}

.info-tooltip:hover .tooltip-content,
.info-tooltip:focus .tooltip-content {
  opacity: 1;
  visibility: visible;
}

/* 모바일에서는 툴팁이 화면 밖으로 나가지 않도록 */
@media (max-width: 600px) {
  .tooltip-content {
    width: 240px;
  }
}

.header p {
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ── 채팅 박스 ── */
.chat-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 300px;
  max-height: 60vh;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* ── 시작 화면 ── */
.start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  text-align: center;
}

.start-icon {
  font-size: 56px;
  line-height: 1;
}

.start-desc {
  font-size: 14px;
  color: var(--color-text-muted);
  line-height: 1.6;
}

.start-desc strong {
  color: var(--color-text);
}

.start-btn {
  padding: 12px 32px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-top: 8px;
}

.start-btn:hover {
  opacity: 0.9;
}

/* ── 로딩 ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 60px 20px;
  color: var(--color-text-muted);
}

.loading p {
  font-size: 14px;
}

/* ── 진행률 바 ── */
.progress-bar {
  width: 100%;
  max-width: 280px;
  height: 8px;
  background: var(--color-border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 0.2s ease;
}

.progress-text {
  font-size: 12px;
  color: var(--color-text-muted);
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── 메시지 ── */
.message {
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--color-primary-light);
}

.message.user .message-avatar {
  background: var(--color-user-bubble);
  color: var(--color-user-text);
  font-size: 14px;
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 80%;
}

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

.message .label {
  font-size: 11px;
  color: var(--color-text-muted);
}

.message .bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

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

.message.bot .bubble {
  background: var(--color-bot-bubble);
  color: var(--color-bot-text);
  border-bottom-left-radius: 4px;
}

/* ── 타이핑 인디케이터 ── */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background: var(--color-text-muted);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

/* ── 추천 질문 버튼 ── */
.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestions.hidden {
  display: none;
}

.suggestion-btn {
  padding: 8px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.2s;
}

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

/* ── 액션 버튼 묶음 ── */
.action-buttons {
  display: flex;
  gap: 6px;
}

/* ── 토픽 모달 ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 20px;
  animation: slideUp 0.3s ease;
}

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.modal-header h2 {
  font-size: 16px;
  color: var(--color-text);
  font-weight: 600;
}

.topics-count {
  color: var(--color-text-muted);
  font-weight: normal;
  font-size: 13px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 0.2s;
}

.modal-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.modal-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 16px;
}

.topics-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-y: auto;
}

.topic-chip {
  padding: 6px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  transition: all 0.2s;
}

.topic-chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-light);
}

/* ── 입력 영역 ── */
.input-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  outline: none;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.2s;
}

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

.input-row button {
  padding: 12px 20px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.input-row button:hover:not(:disabled) {
  opacity: 0.9;
}

.input-row button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-reset {
  padding: 6px 12px;
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-reset:hover:not(:disabled) {
  border-color: var(--color-text-muted);
  color: var(--color-text);
}

.btn-reset:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* ── 푸터 ── */
.footer {
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.footer a {
  color: var(--color-primary);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ── 모바일 대응 ── */
@media (max-width: 600px) {
  body { padding: 12px; }
  .chat-box { max-height: 50vh; }

  /* 추천 버튼: 2x2 그리드 */
  .suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .suggestion-btn {
    width: 100%;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    line-height: 1.4;
  }

  /* 액션 버튼: 풀 너비로 균등 분할 */
  .input-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .action-buttons {
    width: 100%;
  }
  .action-buttons .btn-reset {
    flex: 1;
    text-align: center;
  }

  /* 헤더 텍스트 줄바꿈 방지 */
  .header p {
    font-size: 12px;
  }
}
