/* ── 变量 (暗色) ── */
:root {
  --bg: #0f0f0f;
  --bg2: #161625;
  --card: #1a1a2e;
  --accent: #4a9eff;
  --accent-dim: #3a7ecc;
  --text: #e0e0e0;
  --dim: #888;
  --green: #51cf66;
  --red: #ff6b6b;
  --orange: #ffa94d;
  --border: #2a2a3e;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: none;
}

/* ── 变量 (亮色) ── */
[data-theme="light"] {
  --bg: #f5f5f7;
  --bg2: #ffffff;
  --card: #ffffff;
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
  --text: #1a1a2e;
  --dim: #6b7280;
  --green: #16a34a;
  --red: #dc2626;
  --orange: #ea580c;
  --border: #e0e0e8;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}
[data-theme="light"] .reply-card,
[data-theme="light"] .contact-card,
[data-theme="light"] .knowledge-card,
[data-theme="light"] .persona-card,
[data-theme="light"] .stat-box,
[data-theme="light"] .emotion-card,
[data-theme="light"] .modal-box,
[data-theme="light"] .setting-row {
  box-shadow: var(--shadow);
}
[data-theme="light"] .bubble-user {
  background: var(--accent);
}
[data-theme="light"] .bubble-ai {
  background: #f0f0f5;
  border-color: #e0e0e8;
}
[data-theme="light"] .bottom-nav {
  background: #fff;
  box-shadow: 0 -1px 4px rgba(0,0,0,.06);
}
[data-theme="light"] .chat-input-bar {
  background: #fff;
}
[data-theme="light"] #pin-input {
  background: #fff;
}
[data-theme="light"] .chip {
  background: #fff;
}
[data-theme="light"] .input-select,
[data-theme="light"] .input-text,
[data-theme="light"] .input-textarea,
[data-theme="light"] .chat-input {
  background: #fff;
}

/* ── Reset ── */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  font-family: -apple-system, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* ── 页面切换 ── */
.page { display: none; height: 100%; }
.page.active { display: flex; flex-direction: column; }

/* ── 登录页 ── */
#page-login {
  justify-content: center;
  align-items: center;
}
.login-wrap {
  width: 100%;
  max-width: 320px;
  padding: 0 24px;
  text-align: center;
}
.login-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}
.login-sub {
  font-size: 14px;
  color: var(--dim);
  margin-bottom: 32px;
}
#pin-input {
  width: 100%;
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 20px;
  color: var(--text);
  text-align: center;
  letter-spacing: 8px;
  outline: none;
  transition: border-color .2s;
}
#pin-input:focus { border-color: var(--accent); }
.error-text {
  color: var(--red);
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

/* ── 通用按钮 ── */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-full { width: 100%; margin-top: 16px; }
.btn-accent { background: var(--accent); }
.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
}
.btn-red {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
}
.btn-red:active { background: var(--red); color: #fff; }

/* ── 主页布局 ── */
#page-main {
  flex-direction: column;
}
.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 80px;
  -webkit-overflow-scrolling: touch;
}
.tab-content.active { display: block; }

/* ── 底部导航 ── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 6px;
  cursor: pointer;
  transition: color .15s;
  color: var(--dim);
}
.nav-item.active { color: var(--accent); }
.nav-icon {
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}
.nav-label {
  font-size: 10px;
  margin-top: 2px;
}

/* ── 表单组件 ── */
.section-header {
  margin-bottom: 16px;
}
.section-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 6px;
  font-weight: 500;
}
.dim { color: var(--dim); font-weight: 400; }

.input-select, .input-text {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
.input-select { padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.input-select:focus, .input-text:focus { border-color: var(--accent); }
.input-textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}
.input-textarea:focus { border-color: var(--accent); }

/* ── 粘贴快捷 ── */
.textarea-wrap {
  position: relative;
}
.textarea-wrap .input-textarea {
  padding-right: 56px;
}
.btn-paste {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  opacity: .8;
  transition: opacity .15s;
}
.btn-paste:hover { opacity: 1; }
.btn-paste:active { opacity: .6; }
.paste-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  animation: fadeIn .2s;
}
.paste-hint span { flex: 1; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ── Chips ── */
.chips-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  display: inline-block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--dim);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── 结果区 ── */
.result-area {
  margin-top: 20px;
}
.emotion-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
}
.emotion-label {
  color: var(--orange);
  font-weight: 600;
  margin-right: 6px;
}
.emotion-brief { color: var(--dim); }

.reply-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
}
.reply-style {
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 6px;
}
.reply-text {
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.reply-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.btn-copy {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-copy:active { opacity: .7; }

/* ── Loading ── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: var(--dim);
  font-size: 14px;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
}
.toast.show { opacity: 1; }

/* ── 占位Tab ── */
.placeholder-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--dim);
}
.placeholder-tab .icon { font-size: 48px; margin-bottom: 12px; opacity: .3; }
.placeholder-tab p { font-size: 14px; }

/* ── Chat Tab ── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  padding: 0;
  width: 100%;
}
#tab-chat { padding: 0; }
#tab-chat.active { display: flex; flex-direction: column; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  -webkit-overflow-scrolling: touch;
}
.chat-welcome {
  text-align: center;
  padding: 40px 0;
  color: var(--dim);
}
.chat-welcome p:first-child {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 4px;
}
.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  margin-bottom: 8px;
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}
.bubble-user {
  background: var(--accent);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.bubble-ai {
  background: var(--card);
  border: 1px solid var(--border);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}
.bubble-thinking {
  background: var(--card);
  border: 1px solid var(--border);
  margin-right: auto;
  border-bottom-left-radius: 4px;
  color: var(--dim);
  font-style: italic;
}
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
  background: var(--bg2);
  border-top: 1px solid var(--border);
  margin-bottom: 52px;
}
.chat-input {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 80px;
  line-height: 1.4;
}
.chat-input:focus { border-color: var(--accent); }
.btn-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  align-self: flex-end;
}
.btn-send:active { opacity: .7; }
.btn-send:disabled { opacity: .4; }

/* ── Contacts Tab ── */
.contacts-list {
  margin-top: 8px;
}
.contact-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s;
}
.contact-card:active { border-color: var(--accent); }
.contact-name {
  font-size: 15px;
  font-weight: 600;
}
.contact-rel {
  font-size: 12px;
  color: var(--accent);
  margin-left: 6px;
}
.contact-notes {
  font-size: 13px;
  color: var(--dim);
  margin-top: 4px;
}
.contact-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.contact-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--dim);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 20px;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 360px;
}
.modal-box h3 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--text);
}

/* ── 搜索栏 ── */
.search-bar {
  display: flex;
  gap: 8px;
}
.search-bar .input-text {
  flex: 1;
}

/* ── 知识卡片 ── */
.knowledge-list { margin-top: 4px; }
.knowledge-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.knowledge-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.knowledge-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  word-break: break-word;
}
.knowledge-type {
  font-size: 11px;
  color: var(--accent);
  background: rgba(74,158,255,.12);
  border-radius: 10px;
  padding: 2px 8px;
  white-space: nowrap;
}
.knowledge-summary {
  font-size: 13px;
  color: var(--dim);
  margin-top: 6px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.knowledge-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.knowledge-tag {
  font-size: 11px;
  color: var(--accent-dim);
  background: rgba(74,158,255,.08);
  border-radius: 8px;
  padding: 1px 8px;
}
.knowledge-date {
  font-size: 11px;
  color: var(--dim);
  margin-left: auto;
}
.knowledge-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.knowledge-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--dim);
}

/* ── 分页 ── */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
}

/* ── 人格画像 ── */
.persona-list { margin-top: 4px; }
.persona-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.persona-aspect {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}
.persona-content {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}
.persona-bar-wrap {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.persona-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.persona-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s;
}
.persona-confidence {
  font-size: 11px;
  color: var(--dim);
  white-space: nowrap;
}
.persona-empty {
  text-align: center;
  padding: 40px 0;
  color: var(--dim);
}

/* ── Me 统计区 ── */
.me-stats-section {
  margin-top: 20px;
}
.me-stats-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.stat-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.stat-num {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}
.stat-label {
  font-size: 12px;
  color: var(--dim);
  margin-top: 2px;
}
.stats-tags {
  margin-top: 12px;
}
.stats-tags-title {
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 8px;
}

/* ── 桌面端适配 ── */
@media (min-width: 600px) {
  #page-main {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
    position: relative;
  }
  .bottom-nav {
    max-width: 720px;
    left: 50%;
    transform: translateX(-50%);
    border-radius: 16px 16px 0 0;
  }
  .modal-box {
    max-width: 440px;
  }
  .login-wrap {
    max-width: 380px;
  }
  .toast {
    bottom: 100px;
  }
}

/* ── 主题切换 ── */
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.setting-label {
  font-size: 15px;
  color: var(--text);
}
.btn-theme-toggle {
  width: 48px;
  height: 28px;
  border-radius: 14px;
  border: none;
  background: var(--border);
  cursor: pointer;
  position: relative;
  transition: background .25s;
}
.btn-theme-toggle::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform .25s;
}
[data-theme="light"] .btn-theme-toggle {
  background: var(--accent);
}
[data-theme="light"] .btn-theme-toggle::after {
  background: #fff;
  transform: translateX(20px);
}
#theme-icon {
  position: relative;
  z-index: 1;
  font-size: 12px;
  font-weight: 700;
  color: transparent;
}

/* ── 隐藏 ── */
.hidden { display: none !important; }
