:root {
  --bg-deep: #0d0b14;
  --bg-panel: #161224;
  --bg-elev: #1f1933;
  --bg-bubble-user: linear-gradient(135deg, #c95b7d 0%, #e07a5f 100%);
  --bg-bubble-ai: #1c172e;
  --border: rgba(255, 224, 200, 0.12);
  --text-main: #f8f1eb;
  --text-dim: #b4a7bd;
  --accent: #f4a261;
  --accent-pink: #e76f91;
  --online: #4ade80;
  --radius: 18px;
}

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

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

/* Login Screen */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #2a1b3d 0%, #0d0b14 68%);
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: rgba(22, 18, 36, 0.92);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(18px);
}

.login-photo-wrap {
  width: 112px;
  height: 112px;
  margin: 0 auto 14px;
  border-radius: 50%;
  padding: 3px;
  background: linear-gradient(135deg, var(--accent), var(--accent-pink));
}

.login-couple-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.login-card h1 {
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  color: #fff;
  margin-bottom: 6px;
}

.login-sub {
  font-size: 13.5px;
  color: var(--text-dim);
  margin-bottom: 20px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-password {
  width: 100%;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-size: 15px;
  outline: none;
}

#login-password:focus { border-color: var(--accent); }

#login-btn, .primary-btn {
  padding: 13px 18px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #e76f91 0%, #f4a261 100%);
  color: #160d1c;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

#login-btn:active, .primary-btn:active { transform: scale(0.98); }

.login-error {
  margin-top: 10px;
  color: #ff7b89;
  font-size: 13px;
  min-height: 18px;
}

.login-hint {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* App Shell */
.app-shell {
  display: flex;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 285px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 40;
  transition: transform 0.22s ease;
}

.sidebar-top {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 14px;
}

.brand-avatar, .header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent-pink);
  flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: 15px; }
.brand-status { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.dot-online { width: 8px; height: 8px; border-radius: 50%; background: var(--online); display: inline-block; }

.new-chat-btn {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px dashed rgba(244, 162, 97, 0.5);
  background: rgba(244, 162, 97, 0.08);
  color: var(--accent);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
}

.sidebar-section-label {
  padding: 12px 16px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 13.5px;
  transition: background 0.15s;
}

.conv-item:hover, .conv-item.active {
  background: var(--bg-elev);
  color: var(--text-main);
}

.conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conv-del {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  opacity: 0.65;
}
.conv-del:hover { color: #ff7b89; opacity: 1; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-action-btn {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
}
.side-action-btn:hover { background: var(--bg-elev); border-color: var(--border); }
.side-action-btn.danger { color: #ff9aa5; }

/* Chat Main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: radial-gradient(circle at 80% 0%, rgba(231, 111, 145, 0.08), transparent 45%), var(--bg-deep);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(22, 18, 36, 0.88);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-subtitle { font-size: 11.5px; color: var(--text-dim); }

.mode-switch {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  flex-shrink: 0;
}

.mode-pill {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.mode-pill.active {
  background: linear-gradient(135deg, #e76f91 0%, #f4a261 100%);
  color: #160d1c;
}

/* Messages Area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 24px;
  scroll-behavior: smooth;
}

.welcome-box {
  max-width: 560px;
  margin: 26px auto;
  text-align: center;
  padding: 10px;
}

.welcome-avatar {
  width: 92px;
  height: 92px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
  margin-bottom: 14px;
  box-shadow: 0 10px 30px rgba(231, 111, 145, 0.25);
}

.welcome-box h2 {
  font-family: 'Playfair Display', serif;
  font-size: 24px;
  margin-bottom: 8px;
}

.welcome-box p {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 20px;
}

.quick-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
}

.chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 9px 13px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.chip:hover { border-color: var(--accent); transform: translateY(-1px); }

.messages-list {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1.5px solid var(--accent-pink);
}

.msg-bubble {
  max-width: 82%;
  padding: 12px 15px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.62;
  word-wrap: break-word;
}

.msg-row.user .msg-bubble {
  background: var(--bg-bubble-user);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.msg-row.assistant .msg-bubble {
  background: var(--bg-bubble-ai);
  border: 1px solid var(--border);
  color: var(--text-main);
  border-bottom-left-radius: 5px;
}

.msg-meta {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 6px;
  opacity: 0.8;
}

.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 20px; margin: 6px 0; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: Consolas, monospace;
  font-size: 13px;
}

.code-block-wrap {
  position: relative;
  margin: 10px 0;
  background: #0b0912;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.code-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11px;
  color: var(--text-dim);
}

.copy-code-btn {
  background: rgba(244, 162, 97, 0.16);
  border: none;
  color: var(--accent);
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
}

.code-block-wrap pre {
  padding: 10px 12px;
  overflow-x: auto;
  font-family: Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  color: #f3e8ff;
}

/* Typing indicator */
.typing-dots span {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 2px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Composer */
.composer-wrap {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  background: rgba(13, 11, 20, 0.94);
  border-top: 1px solid var(--border);
}

.composer {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 10px 8px 14px;
}

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

#msg-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  max-height: 130px;
  outline: none;
  padding: 4px 0;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #e76f91 0%, #f4a261 100%);
  color: #160d1c;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 4, 10, 0.72);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
}

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

.modal-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 14px; line-height: 1.5; }

.memory-form, .settings-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.setting-group { display: flex; flex-direction: column; gap: 6px; }
.setting-group label { font-size: 13px; font-weight: 600; color: var(--text-main); }

select, input[type="text"], input[type="password"], .memory-form textarea {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

select option { background: #1c172e; color: #fff; }

.hint-text { font-size: 12px; color: var(--accent); }
.settings-msg { font-size: 13px; color: var(--online); min-height: 18px; }

.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.ghost-btn {
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.memory-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.memory-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.5;
}

.memory-tag {
  display: inline-block;
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(244, 162, 97, 0.16);
  color: var(--accent);
  margin-bottom: 4px;
}

.mobile-only { display: none; }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 35;
}

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; margin-left: auto; }
  .msg-bubble { max-width: 88%; }
}
