:root {
  --bg: #E9EEE6;
  --bg-soft: #F3F6F1;
  --card: #FBFCF9;
  --ink: #28352E;
  --muted: #6F7D73;
  --line: #D6E0D4;
  --primary: #4F7A63;
  --primary-dark: #3F6652;
  --primary-soft: #DDE9DE;
  --user: #4F7A63;
  --assistant: #FBFCF9;
  --sidebar-bg: #F0F4EE;
  --error: #A24B3E;
  --ok: #4F7A63;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(40, 53, 46, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(circle at 15% 0%, #F3F8F1 0%, transparent 45%),
    radial-gradient(circle at 85% 100%, #E9F1E8 0%, transparent 40%),
    var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.view { min-height: 100dvh; }

/* Cat avatar */

.cat-avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #F3F6F1;
  border: 1px solid #D6E0D4;
  overflow: hidden;
}
.cat-avatar svg { width: 100%; height: 100%; display: block; }
.cat-avatar.large { width: 54px; height: 54px; flex-basis: 54px; }

/* Login */

.login-view, .consent-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card { width: min(440px, 100%); padding: 30px 28px 26px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 8px; }
.login-card h1 { margin: 0 0 8px; font-size: 25px; line-height: 1.3; text-align: center; }
.login-card .muted { margin: 0 0 6px; text-align: center; font-size: 14px; }
.login-card label { display: block; margin: 16px 0 6px; font-size: 14px; color: var(--muted); }

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #FBFCF9;
  padding: 12px 14px;
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(79, 122, 99, 0.16);
}
button {
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 600;
}
button:hover { background: var(--primary-dark); }
button:disabled { background: #C9D6C9; cursor: not-allowed; }
.login-card button { width: 100%; margin-top: 20px; }
.muted { color: var(--muted); }
.tiny { font-size: 13px; }
.error { color: var(--error); min-height: 22px; margin: 10px 0 0; font-size: 14px; }
.link-button {
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  font-weight: 500;
  font-size: 14px;
}
.link-button:hover { color: var(--ink); background: transparent; }

/* Consent */

.consent-card {
  width: min(760px, 100%);
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  padding: 26px 26px 22px;
}
.consent-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.consent-head h1 { margin: 0; font-size: 23px; }
.consent-body {
  overflow-y: auto;
  padding-right: 6px;
  font-size: 15px;
  line-height: 1.8;
}
.consent-body p { margin: 0 0 10px; }
.consent-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 16px 0 14px;
  font-size: 15px;
  cursor: pointer;
}
.consent-check input { width: 18px; height: 18px; accent-color: var(--primary); margin-top: 3px; }
#consent-agree { width: 100%; }
#consent-decline { width: 100%; margin-top: 6px; }

/* App shell */

.app-view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 820px;
  margin: 0 auto;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 249, 0.90);
  backdrop-filter: blur(8px);
}
.brand { font-weight: 700; }
.chat-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-right { display: inline-flex; align-items: center; gap: 12px; margin-left: auto; }

/* Initial-password reminder */
.password-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 16px;
  background: #FFF8E8;
  border-bottom: 1px solid #EADFC4;
  color: #6B5636;
  font-size: 13px;
  line-height: 1.5;
}
.password-hint-text { min-width: 0; }
.password-hint-actions { display: inline-flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.password-hint .link-button { color: #7A623E; padding: 4px 6px; white-space: nowrap; }
.password-hint .link-button:hover { color: #3F6652; }

/* Chat shell with sidebar */

.chat-shell {
  display: flex;
  flex-direction: row;
  max-width: none;
  height: 100dvh;
  background: transparent;
}
.sidebar {
  width: 280px;
  flex: 0 0 280px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--line);
  padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
  height: 100dvh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  padding: 0 4px 12px;
}
.new-chat-btn {
  width: 100%;
  background: #FBFCF9;
  color: var(--primary-dark);
  border: 1px solid var(--primary);
  padding: 11px 14px;
  font-size: 15px;
}
.new-chat-btn:hover { background: var(--primary-soft); }
.new-chat-btn .plus { font-size: 16px; margin-right: 2px; }
.sidebar-label { font-size: 12px; color: var(--muted); margin: 18px 6px 8px; }
.session-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.session-empty { color: var(--muted); font-size: 13px; padding: 10px 12px; }
.session-item {
  text-align: left;
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 500;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.session-item:hover { background: #E7EEE4; }
.session-item.active { background: var(--primary-soft); color: var(--primary-dark); }
.session-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); flex: 0 0 6px; }
.session-item.ended .dot { background: #c7b5a7; }
.session-item .s-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .s-time { font-size: 11px; color: var(--muted); font-weight: 400; flex: 0 0 auto; }
.sidebar-foot {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-actions { display: inline-flex; align-items: center; gap: 2px; }
.sidebar-backdrop { display: none; }

.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg-soft);
}
.icon-btn {
  display: none;
  background: transparent;
  padding: 6px 10px;
  margin-left: -6px;
}
.hamburger, .hamburger::before, .hamburger::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 2px;
}
.hamburger { position: relative; }
.hamburger::before, .hamburger::after { content: ""; position: absolute; left: 0; }
.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

/* Welcome */

.welcome {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 32px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.welcome-card { width: min(720px, 100%); padding: 24px 24px 20px; }
.welcome-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 18px; }
.welcome-heading { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.welcome-step { font-size: 12px; line-height: 1.4; color: var(--muted); font-weight: 400; }
.opening { white-space: pre-wrap; font-size: 16px; }
.welcome-card button { width: 100%; margin: 20px 0 10px; }
#welcome-back {
  width: auto;
  display: block;
  margin: 0 auto 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

/* Messages */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
}
.msg-row { display: flex; align-items: flex-end; gap: 8px; width: 100%; scroll-margin-top: 12px; }
.msg-row.assistant { justify-content: flex-start; }
.msg-row.user { justify-content: flex-end; }
.msg-row .cat-avatar { margin-bottom: 2px; }
.bubble {
  max-width: min(680px, 82%);
  padding: 12px 15px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 16px;
  border: 1px solid transparent;
}
.bubble.assistant {
  background: var(--assistant);
  border-color: var(--line);
  border-top-left-radius: 6px;
}
.bubble.user {
  background: var(--user);
  color: #fff;
  border-top-right-radius: 6px;
}
.bubble.typing { color: var(--muted); }
.bubble.thinking {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  min-height: 45px;
}
.thinking-dots { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--primary);
  display: block;
  animation: thinking-pulse 1.15s infinite ease-in-out;
}
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }
.thinking-text { font-size: 14px; }
@keyframes thinking-pulse {
  0%, 75%, 100% { opacity: 0.25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-2px); }
}
.quick {
  display: flex;
  gap: 10px;
  padding: 0 16px 8px;
  flex-wrap: wrap;
}
.quick button {
  background: #FBFCF9;
  color: var(--primary-dark);
  border: 1px solid var(--primary);
  padding: 8px 14px;
  font-size: 15px;
}
.quick button:hover { background: var(--primary-soft); }
.scene-hint {
  margin: 0;
  padding: 0 18px 6px;
  color: var(--muted);
  font-size: 13px;
}

/* Rating sliders */

.rating-card {
  margin: 0 16px 10px;
  padding: 14px 16px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #F6F1E7;
  box-shadow: var(--shadow);
}
.rating-title { font-weight: 700; margin-bottom: 8px; font-size: 15px; }
.rating-row {
  display: grid;
  grid-template-columns: 86px 1fr 36px;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 14px;
}
.rating-row input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  padding: 0;
  border: 0;
  background: transparent;
}
.rating-row output {
  text-align: center;
  font-weight: 700;
  color: var(--primary-dark);
  background: var(--primary-soft);
  border-radius: 8px;
  padding: 2px 0;
}
.rating-actions { display: flex; gap: 8px; margin-top: 8px; }
.rating-actions button:first-child { flex: 1; }

/* End banner */

.end-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 16px 10px;
  padding: 12px 14px;
  border: 1px solid #C9DDC6;
  background: #EDF5EA;
  border-radius: 12px;
  font-size: 15px;
}
.end-banner.safety { border-color: #f3c6a5; background: #fff6ee; }

/* Composer */

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  background: #fff;
  line-height: 1.5;
}
.composer textarea:disabled {
  background: var(--bg-soft);
  color: var(--muted);
}
.composer button { min-width: 76px; }
.status {
  min-height: 20px;
  margin: 0;
  padding: 0 18px 8px;
  color: var(--muted);
  font-size: 14px;
}
.status.error-text { color: var(--error); }

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 53, 46, 0.38);
  padding: 24px;
}
.modal-card {
  width: min(440px, 100%);
  background: #FBFCF9;
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 18px 50px rgba(40, 53, 46, 0.22);
}
.modal-card h3 { margin: 0 0 14px; font-size: 18px; }
.password-reminder-card {
  border-top: 5px solid #E2B45A;
  text-align: center;
  padding: 24px 22px 20px;
}
.password-reminder-icon { font-size: 42px; line-height: 1; margin-bottom: 8px; }
.password-reminder-card h3 { font-size: 21px; margin-bottom: 10px; }
.password-reminder-card p { margin: 0 0 8px; font-size: 15px; line-height: 1.65; }
.password-reminder-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.password-reminder-actions button { flex: 1; }
.password-reminder-actions .link-button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 12px 16px;
}
.modal-card input { margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* Mobile: sidebar becomes a drawer */

@media (max-width: 720px) {
  .icon-btn { display: inline-block; }
  .sidebar {
    position: fixed;
    z-index: 40;
    top: 0;
    left: 0;
    width: min(82vw, 300px);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 30px rgba(59, 47, 42, 0.14);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(40, 53, 46, 0.35);
  }
  .bubble { max-width: 90%; }
  .topbar { padding: 12px 14px; }
  .messages { padding: 16px 12px 10px; }
  .password-hint { align-items: flex-start; padding: 8px 12px; font-size: 12px; }
  .password-hint-actions { flex-direction: column; align-items: flex-end; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .session-item { padding: 12px; }
  .consent-card { padding: 20px 18px; }
}
