* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #F9FAFB;
  --white: #fff;
  --gray-100: #F3F4F6;
  --gray-400: #9CA3AF;
  --gray-600: #6B7280;
  --gray-800: #1F2937;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

body {
  font-family: -apple-system, 'Pretendard', 'Apple SD Gothic Neo', sans-serif;
  background: var(--bg);
  color: var(--gray-800);
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
}

/* ====== 랜딩 ====== */
.landing {
  max-width: 480px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}

.landing-header {
  text-align: center;
  margin-bottom: 2rem;
}

.logo {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.landing h1 {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
}

.subtitle {
  color: var(--gray-600);
  font-size: 0.95rem;
}

/* 카드 그리드 */
.persona-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 1.5rem;
}

.persona-card {
  background: var(--white);
  border-radius: 16px;
  padding: 1.2rem 1rem;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  color: inherit;
  display: block;
  box-shadow: var(--shadow);
}

.persona-card:active {
  transform: scale(0.96);
  box-shadow: none;
}

.persona-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

/* 마지막 홀수 카드 전체 너비 */
.persona-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.color-bar {
  height: 4px;
  border-radius: 2px;
  margin-bottom: 0.8rem;
}

.card-icon {
  font-size: 1.8rem;
  margin-bottom: 0.4rem;
}

.card-name {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.2rem;
}

.card-role {
  font-size: 0.8rem;
  color: var(--gray-600);
  margin-bottom: 0.5rem;
}

.card-desc {
  font-size: 0.78rem;
  color: var(--gray-400);
  line-height: 1.4;
}

/* 스켈레톤 로딩 */
.loading-cards {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.skeleton-card {
  height: 140px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 16px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.no-login {
  text-align: center;
  color: var(--gray-400);
  font-size: 0.85rem;
}

/* 로그아웃 버튼 */
.logout-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(107, 114, 128, 0.1);
  color: var(--gray-600);
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.logout-btn:active {
  background: rgba(107, 114, 128, 0.2);
}

/* ====== 채팅 ====== */
.chat-body {
  background: var(--gray-100);
}

.chat-layout {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  height: 100dvh;
  position: relative;
}

.chat-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  background: var(--white);
  min-width: 0; /* flex child overflow fix */
}

/* 사이드바 */
.sidebar {
  width: 280px;
  background: #fff;
  border-left: 1px solid var(--gray-100);
  display: flex;
  flex-direction: column;
  height: 100%;
  position: absolute;
  right: 0;
  top: 0;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 100;
  box-shadow: -4px 0 16px rgba(0,0,0,0.1);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--gray-100);
}

.sidebar-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: 4px 8px;
  line-height: 1;
  transition: color 0.15s;
}

.sidebar-close:hover { color: var(--gray-600); }
.sidebar-close:active { color: var(--gray-800); }

.new-chat-btn {
  margin: 12px 16px;
  padding: 12px;
  background: var(--bg);
  border: 1.5px solid var(--gray-100);
  border-radius: 12px;
  color: var(--gray-800);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s;
}

.new-chat-btn:hover {
  background: var(--gray-100);
  border-color: var(--gray-400);
}

.new-chat-btn:active {
  background: var(--gray-200);
}

.new-chat-icon {
  font-size: 1.2rem;
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
}

.conversation-item {
  padding: 12px;
  margin: 4px 0;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1.5px solid transparent;
  position: relative;
}

.conv-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  line-height: 1;
}

.conversation-item:hover .conv-delete {
  opacity: 1;
}

.conversation-item:hover {
  background: var(--gray-100);
}

.conversation-item.active {
  background: var(--gray-100);
  border-color: var(--gray-200);
}

.conv-persona {
  font-size: 12px;
  color: #888;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 2px;
}
.conv-persona-icon { margin-right: 2px; }
.conv-persona-name { font-weight: 500; }

.conversation-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta {
  font-size: 0.75rem;
  color: var(--gray-400);
}

.conversation-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--gray-400);
  font-size: 0.85rem;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  gap: 12px;
  flex-shrink: 0;
  min-height: 56px;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-toggle {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 8px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}

.sidebar-toggle:hover { background: rgba(255,255,255,0.3); }
.sidebar-toggle:active { background: rgba(255,255,255,0.4); }

.back {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 10px;
  line-height: 1;
  transition: background 0.15s;
}

.back:active { background: rgba(255,255,255,0.3); }

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

/* 내보내기 버튼 */
.export-wrapper {
  position: relative;
}

.export-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  padding: 6px 10px;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.export-btn:active { background: rgba(255,255,255,0.3); }
.export-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.export-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  min-width: 120px;
  z-index: 100;
  overflow: hidden;
}

.export-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 14px;
  text-align: left;
  font-size: 0.85rem;
  color: var(--gray-800);
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.export-option:hover {
  background: var(--gray-100);
}

.export-option:active {
  background: var(--gray-200);
}

.export-option:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 포맷 토글 */
.format-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.format-toggle input[type="checkbox"] {
  display: none;
}

.toggle-track {
  width: 44px;
  height: 24px;
  background: rgba(255,255,255,0.3);
  border-radius: 12px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-thumb {
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.format-toggle input:checked + .toggle-track {
  background: rgba(34,197,94,0.9);
}

.format-toggle input:checked + .toggle-track .toggle-thumb {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 0.75rem;
  color: #fff;
  white-space: nowrap;
}

/* 채팅 메시지 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 85%;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 0.95rem;
  word-break: break-word;
}

.message.assistant {
  background: var(--gray-100);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

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

/* 마크다운 스타일 */
.message strong { font-weight: 700; }
.message table {
  border-collapse: collapse;
  font-size: 0.85rem;
  margin: 8px 0;
  width: 100%;
}
.message th, .message td {
  border: 1px solid #ddd;
  padding: 6px 8px;
  text-align: left;
}
.message th { background: #f5f5f5; font-weight: 600; }

/* 타이핑 인디케이터 */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--gray-100);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--gray-400);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

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

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

/* 입력 영역 */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--gray-100);
  background: var(--white);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1.5px solid #E5E7EB;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color 0.15s;
  line-height: 1.5;
}

#chat-input:focus { border-color: #4F46E5; }

#send-btn {
  background: #4F46E5;
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  min-height: 42px;
}

#send-btn:active { transform: scale(0.96); }
#send-btn:disabled { background: #9CA3AF; cursor: not-allowed; transform: none; }

/* 에러 메시지 */
.message.error {
  background: #FEF2F2;
  color: #991B1B;
  align-self: flex-start;
}

/* 데스크탑 */
@media (min-width: 640px) {
  .landing { padding: 3rem 1.5rem; }
  .landing h1 { font-size: 2.2rem; }
  .persona-grid { gap: 16px; }
}

/* 사이드바 모바일 */
@media (min-width: 768px) {
  .sidebar {
    position: relative;
    transform: none;
    border-left: none;
    box-shadow: none;
  }
  .sidebar.open { transform: none; }
  .sidebar.collapsed { display: none; }
  .sidebar-close { display: none; }
}
