:root {
  --forest: #16302B;
  --forest-light: #204039;
  --forest-lighter: #2A4F47;
  --teal: #2F6F5E;
  --teal-hover: #285F51;
  --amber: #E0A542;
  --amber-hover: #C9903A;
  --bg: #F6F7F5;
  --surface: #FFFFFF;
  --border: #E3E6E1;
  --text: #1C2420;
  --text-muted: #6B7770;
  --text-inverse: #F6F7F5;
  --crisis: #B65C4A;
  --crisis-bg: #FBEEEA;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(22, 48, 43, 0.06);
  --shadow-lg: 0 12px 40px rgba(22, 48, 43, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .brand-word {
  font-family: 'Fraunces', Georgia, serif;
}

a { color: inherit; }

::selection { background: var(--amber); color: var(--forest); }

button { font-family: inherit; cursor: pointer; }

input:focus-visible, button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  display: inline-block;
  animation: pulse-beat 1.6s ease-in-out infinite;
}

@keyframes pulse-beat {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.6); opacity: 0.5; }
}

@media (prefers-reduced-motion: reduce) {
  .pulse-dot { animation: none; }
}

/* ==================================================================
   AUTH PAGES (login / signup)
   ================================================================== */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.auth-brand {
  background: var(--forest);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 48px;
  position: relative;
  overflow: hidden;
}

.auth-brand::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% 85%, rgba(224, 165, 66, 0.16), transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(47, 111, 94, 0.35), transparent 50%);
  pointer-events: none;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
  position: relative;
  z-index: 1;
}

.auth-logo i { color: var(--amber); font-size: 22px; }

.auth-brand-body {
  position: relative;
  z-index: 1;
  max-width: 420px;
}

.auth-brand-body h1 {
  font-size: 40px;
  line-height: 1.15;
  font-weight: 500;
  margin: 0 0 16px;
}

.auth-brand-body p {
  color: rgba(246, 247, 245, 0.72);
  font-size: 15px;
  line-height: 1.6;
}

.auth-brand-foot {
  position: relative;
  z-index: 1;
  color: rgba(246, 247, 245, 0.55);
  font-size: 13px;
}

.auth-form-side {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-card h2 {
  font-size: 28px;
  font-weight: 500;
  margin: 0 0 6px;
}

.auth-card .sub {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 32px;
}

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--forest);
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease;
}

.field input:focus { border-color: var(--teal); }

.btn-primary {
  width: 100%;
  padding: 13px 14px;
  border: none;
  border-radius: 9px;
  background: var(--teal);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: background 0.15s ease;
}

.btn-primary:hover { background: var(--teal-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-switch {
  text-align: center;
  margin-top: 22px;
  font-size: 14px;
  color: var(--text-muted);
}

.auth-switch a { color: var(--teal); font-weight: 600; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }

.form-error {
  background: var(--crisis-bg);
  color: var(--crisis);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 18px;
  display: none;
}

.form-error.show { display: block; }

.form-success {
  background: #EAF3F0;
  color: var(--teal);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 18px;
  display: none;
  text-align: center;
}

.form-success.show { display: block; }

@media (max-width: 860px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
}

/* ==================================================================
   CHAT APP
   ================================================================== */

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--forest);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head { padding: 20px 16px 16px; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 18px;
}

.sidebar-logo i { color: var(--amber); font-size: 18px; }

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(246, 247, 245, 0.16);
  border-radius: 9px;
  background: rgba(246, 247, 245, 0.04);
  color: var(--text-inverse);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease;
}

.new-chat-btn:hover { background: rgba(246, 247, 245, 0.1); }

.sidebar-history {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px;
}

.history-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(246, 247, 245, 0.4);
  padding: 16px 8px 6px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: rgba(246, 247, 245, 0.85);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  position: relative;
}

.history-item:hover { background: rgba(246, 247, 245, 0.08); }
.history-item.active { background: var(--forest-lighter); color: #fff; }

.history-item .del-btn {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(246, 247, 245, 0.55);
  font-size: 12px;
  padding: 2px;
}

.history-item:hover .del-btn { display: inline-block; }
.history-item .del-btn:hover { color: var(--amber); }

.history-empty {
  color: rgba(246, 247, 245, 0.4);
  font-size: 13px;
  padding: 10px;
  line-height: 1.5;
}

.sidebar-foot {
  border-top: 1px solid rgba(246, 247, 245, 0.1);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--amber);
  color: var(--forest);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(246, 247, 245, 0.6);
  font-size: 15px;
  padding: 6px;
  border-radius: 6px;
}

.logout-btn:hover { color: var(--amber); background: rgba(246, 247, 245, 0.08); }

.main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-left { display: flex; align-items: center; }

.topbar-title { font-size: 15px; font-weight: 600; color: var(--forest); }

.topbar-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.messages { flex: 1; overflow-y: auto; padding: 28px 0 12px; }

.messages-inner { max-width: 720px; margin: 0 auto; padding: 0 24px; }

.welcome { text-align: center; padding: 60px 24px; color: var(--text-muted); }

.welcome i { font-size: 34px; color: var(--teal); margin-bottom: 14px; }

.welcome h2 { color: var(--forest); font-size: 24px; font-weight: 500; margin: 0 0 8px; }

.welcome p { font-size: 14px; max-width: 380px; margin: 0 auto; line-height: 1.6; }

.suggestions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 22px;
  flex-wrap: wrap;
}

.suggestion-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 9px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--forest);
}

.suggestion-chip:hover { border-color: var(--teal); background: #F0F5F3; }

.msg-row { display: flex; gap: 12px; margin-bottom: 22px; align-items: flex-start; }

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

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.msg-row.bot .msg-avatar { background: var(--forest); color: var(--amber); }
.msg-row.user .msg-avatar { background: var(--amber); color: var(--forest); font-weight: 700; }

.bubble { max-width: 78%; padding: 12px 16px; border-radius: var(--radius); font-size: 14.5px; line-height: 1.6; }

.msg-row.bot .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-top-left-radius: 4px;
}

.msg-row.user .bubble {
  background: var(--teal);
  color: #fff;
  border-top-right-radius: 4px;
}

.bubble.crisis {
  background: var(--crisis-bg);
  border: 1px solid rgba(182, 92, 74, 0.3);
  color: var(--crisis);
}

.typing-row .bubble { display: flex; align-items: center; gap: 6px; padding: 14px 16px; }

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

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 16px 24px 20px; }

.composer-inner { max-width: 720px; margin: 0 auto; }

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 18px;
  background: var(--bg);
  transition: border-color 0.15s ease;
}

.composer-box:focus-within { border-color: var(--teal); }

.composer-box textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--text);
  padding: 8px 0;
  max-height: 160px;
  line-height: 1.5;
}

.composer-box textarea:focus { outline: none; }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.send-btn:hover { background: var(--teal-hover); }
.send-btn:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }

.composer-note { text-align: center; font-size: 11.5px; color: var(--text-muted); margin-top: 10px; }

.menu-toggle { display: none; border: none; background: none; font-size: 18px; color: var(--forest); padding: 6px; margin-right: 6px; }

@media (max-width: 780px) {
  .app { grid-template-columns: 0 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex !important; }
}
