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

:root {
  --bg: #f0ede8;
  --surface: #ffffff;
  --surface2: #f5f3ef;
  --border: #e0dbd4;
  --text: #1a1814;
  --text2: #6b6560;
  --text3: #9e9890;
  --accent: #2d5a3d;
  --accent2: #4a8c5c;
  --accent-light: #e8f2eb;
  --user-bg: #2d5a3d;
  --user-text: #ffffff;
  --ai-bg: #ffffff;
  --ai-border: #e0dbd4;
  --input-bg: #ffffff;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 14px;
}

body.dark {
  --bg: #0f1210;
  --surface: #171c19;
  --surface2: #1e2520;
  --border: #2a3330;
  --text: #e8ede9;
  --text2: #8a9e8f;
  --text3: #556a5a;
  --accent: #4a8c5c;
  --accent2: #6bb07a;
  --accent-light: #1a2e20;
  --user-bg: #2d5a3d;
  --user-text: #ffffff;
  --ai-bg: #1e2520;
  --ai-border: #2a3330;
  --input-bg: #1e2520;
  --shadow: 0 2px 12px rgba(0,0,0,0.35);
}

body {
  font-family: 'Sora', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background 0.3s, color 0.3s;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  z-index: 10;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 15px; color: #fff;
}
.logo-name { font-weight: 600; font-size: 15px; color: var(--text); }
.logo-sub { font-size: 11px; color: var(--text2); }

.header-right { display: flex; gap: 8px; }
.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s;
  color: var(--text);
  line-height: 1;
}
.icon-btn:hover { background: var(--accent-light); }

/* MESSAGES */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* WELCOME */
.welcome {
  text-align: center;
  padding: 32px 16px 16px;
  color: var(--text2);
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.welcome-icon { font-size: 44px; margin-bottom: 14px; }
.welcome h1 { font-size: 21px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.welcome p { font-size: 14px; line-height: 1.65; margin-bottom: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: 'Sora', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}
.chip:hover { background: var(--accent-light); border-color: var(--accent2); color: var(--accent); }

/* MSG */
.msg { display: flex; gap: 10px; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.msg.user { flex-direction: row-reverse; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0; margin-top: 2px;
  user-select: none;
}
.avatar.ai { background: var(--accent); color: #fff; }
.avatar.user { background: var(--surface2); border: 1px solid var(--border); color: var(--text2); }

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}
.bubble.ai { background: var(--ai-bg); border: 1px solid var(--ai-border); border-radius: 4px 14px 14px 14px; color: var(--text); }
.bubble.user { background: var(--user-bg); color: var(--user-text); border-radius: 14px 4px 14px 14px; }
.bubble.error { background: #fff0f0; border-color: #ffc5c5; color: #c0392b; }
body.dark .bubble.error { background: #2a1515; border-color: #5a2020; color: #f08080; }

.bubble p { margin-bottom: 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { padding-left: 18px; margin: 6px 0; }
.bubble li { margin-bottom: 3px; }
.bubble code { font-family: 'JetBrains Mono', monospace; font-size: 12px; background: var(--surface2); padding: 2px 6px; border-radius: 4px; }
.bubble pre { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; margin: 8px 0; }
.bubble pre code { background: none; padding: 0; }
.bubble strong { font-weight: 600; }

/* TYPING */
.typing { display: flex; gap: 5px; align-items: center; padding: 4px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text3); animation: bounce 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* INPUT */
#input-area {
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.input-wrap {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s;
  box-shadow: var(--shadow);
}
.input-wrap:focus-within { border-color: var(--accent2); }
#input {
  flex: 1; border: none; background: transparent;
  font-family: 'Sora', sans-serif; font-size: 14px; color: var(--text);
  resize: none; outline: none; max-height: 120px; line-height: 1.5;
}
#input::placeholder { color: var(--text3); }
#send {
  background: var(--accent); border: none; border-radius: 10px;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s; flex-shrink: 0;
}
#send:hover:not(:disabled) { background: var(--accent2); transform: scale(1.05); }
#send:disabled { background: var(--border); cursor: not-allowed; transform: none; }
.disclaimer { text-align: center; font-size: 11px; color: var(--text3); margin-top: 8px; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px 28px;
  text-align: center;
  max-width: 280px; width: 90%;
}
.modal-box p { font-size: 15px; margin-bottom: 20px; color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions button {
  padding: 8px 24px; border-radius: 8px; font-family: 'Sora', sans-serif;
  font-size: 14px; cursor: pointer; border: 1px solid var(--border);
  transition: all 0.2s;
}
#confirmYes { background: #c0392b; color: #fff; border-color: #c0392b; }
#confirmYes:hover { background: #e74c3c; }
#confirmNo { background: var(--surface2); color: var(--text); }
#confirmNo:hover { background: var(--accent-light); }

@media (max-width: 480px) {
  #messages { padding: 14px 12px 0; }
  #input-area { padding: 10px 12px 14px; }
  .bubble { max-width: 88%; font-size: 13.5px; }
  .welcome { padding: 20px 8px 12px; }
}
