/* 写字 · 浅色生产软件风格（飞书/Lark 风） */

/* ---------- Design tokens ---------- */
:root {
  /* 兼容旧 token 名 */
  --bg: #f5f6f7;
  --card: #ffffff;
  --ink: #1f2329;
  --muted: #646a73;
  --line: #dee0e3;
  --accent: #3370ff;
  --accent-ink: #ffffff;
  --danger: #f54a45;

  /* 扩展 token */
  --ink-secondary: #51565d;
  --line-strong: #c9cdd2;
  --accent-hover: #2b5fd9;
  --accent-active: #2452b8;
  --accent-bg: #f0f4ff;
  --accent-line: #bacefd;
  --danger-bg: #fef1f1;
  --field-bg: #ffffff;
  --hover-bg: rgba(31, 35, 41, 0.05);

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;

  --shadow-card: 0 1px 2px rgba(31, 35, 41, 0.04);
  --shadow-pop: 0 4px 12px rgba(31, 35, 41, 0.08);
  --focus-ring: 0 0 0 2px rgba(51, 112, 255, 0.18);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans CJK SC", "Helvetica Neue", Arial, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  font-size: 15px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) 56px;
}

/* ---------- 顶栏 ---------- */
.topbar {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  min-width: 0;
}

.brand {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.5px;
  color: var(--ink);
  white-space: nowrap;
}

.ai-badge,
.user-badge {
  font-size: 12px;
  line-height: 20px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40vw;
}
.ai-badge { margin-right: auto; }
.ai-badge.ok {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: var(--accent-line);
}

/* ---------- Tabs ---------- */
.tabs {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  gap: var(--space-1);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.tab {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  padding: 10px 0 9px;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 500;
}
.tab:focus-visible {
  outline: none;
  box-shadow: inset var(--focus-ring);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.panel { display: none; }
.panel.active {
  display: block;
  animation: panel-in 0.22s ease-out both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  margin-top: var(--space-4);
  animation: card-in 0.24s ease-out both;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}
.card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-pop);
  transform: translateY(-1px);
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.5px;
  margin-bottom: var(--space-2);
}

.prompt-text {
  font-size: 15px;
  color: var(--ink);
}

/* ---------- 表单控件 ---------- */
textarea,
input[type="text"],
input[type="password"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font: inherit;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--field-bg);
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

textarea::placeholder,
input::placeholder { color: #8f959e; }

textarea:hover,
input[type="text"]:hover,
input[type="password"]:hover { border-color: var(--muted); }

textarea:focus,
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

textarea:disabled,
input:disabled {
  background: var(--bg);
  color: var(--muted);
  cursor: not-allowed;
}

/* ---------- 按钮 ---------- */
button {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 20px;
  min-height: 38px;
  line-height: 1.45;
  white-space: nowrap;
  transition: background-color 0.15s ease, box-shadow 0.15s ease,
    color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}
button:hover { background: var(--accent-hover); }
button:active { background: var(--accent-active); transform: translateY(1px); }
button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
button:disabled {
  background: #bacefd;
  color: var(--accent-ink);
  cursor: not-allowed;
  opacity: 1;
}

.link-btn {
  background: none;
  color: var(--accent);
  font-weight: 400;
  padding: 4px 8px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.link-btn:hover { background: var(--accent-bg); color: var(--accent-hover); }
.link-btn:active { background: var(--accent-bg); color: var(--accent-active); }
.link-btn:disabled {
  background: none;
  color: var(--line-strong);
}
.link-btn.center { display: block; margin: var(--space-4) auto 0; }

/* ---------- 布局工具 ---------- */
.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
  min-width: 0;
}
.row .muted { margin-right: auto; }
.row input { flex: 1; min-width: 0; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: var(--space-3);
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.pre-wrap { white-space: pre-wrap; word-break: break-word; }

/* ---------- 微动效 / 加载态 ---------- */
.shimmer-line {
  display: block;
  height: 12px;
  max-width: 100%;
  margin: 7px 0;
  border-radius: 99px;
  background: linear-gradient(90deg, #f0f2f5 0%, #e6ebf5 42%, #f0f2f5 76%);
  background-size: 180% 100%;
  animation: shimmer 1.15s ease-in-out infinite;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}
.typing-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.38;
  animation: typing-dot 1s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.14s; }
.typing-dots i:nth-child(3) { animation-delay: 0.28s; }

@keyframes shimmer {
  from { background-position: 120% 0; }
  to { background-position: -120% 0; }
}
@keyframes typing-dot {
  0%, 70%, 100% { transform: translateY(0); opacity: 0.35; }
  35% { transform: translateY(-3px); opacity: 0.9; }
}

/* ---------- AI 回应 ---------- */
.ai-question {
  margin-top: var(--space-2);
  padding: 8px 12px;
  background: var(--accent-bg);
  border-left: 2px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--ink-secondary);
  font-size: 14px;
}

/* ---------- 标签 / Chip ---------- */
.tags {
  margin-top: var(--space-3);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag {
  font-size: 12px;
  line-height: 20px;
  color: var(--ink-secondary);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 8px;
}
.tag.mood {
  color: var(--accent);
  background: var(--accent-bg);
  border-color: var(--accent-line);
}

/* ---------- 历史日记 ---------- */
.entry { position: relative; }

.entry-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 0;
}
.entry-day {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
}
.entry-del {
  margin-left: auto;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}
.entry-del:hover {
  background: var(--danger-bg);
  color: var(--danger);
}
.entry-del:active { background: var(--danger-bg); color: var(--danger); }

.entry-content {
  margin-top: var(--space-2);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  color: var(--ink);
}

.entry-ai {
  margin-top: var(--space-3);
  padding: 12px;
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--ink-secondary);
  animation: card-in 0.22s ease-out both;
}
.entry-ai-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.entry-ai-body,
.entry-ai-question {
  white-space: pre-wrap;
  word-break: break-word;
}
.entry-ai-question {
  margin-top: 8px;
  padding-left: 10px;
  border-left: 2px solid var(--accent-line);
  color: var(--ink-secondary);
}

/* ---------- 周回顾 ---------- */
.weekly-item {
  margin-top: var(--space-3);
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbfcff;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.weekly-item:hover { border-color: var(--accent-line); background: #f8faff; }
.weekly-item h3 {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

/* ---------- AI 回复线程 ---------- */
.ai-thread {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px dashed var(--line);
}
.thread-msgs {
  display: grid;
  gap: 8px;
}
.thread-msg {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msg-in 0.18s ease-out both;
}
.thread-msg.user {
  justify-self: end;
  color: #1d4ed8;
  background: var(--accent-bg);
  border: 1px solid var(--accent-line);
  border-bottom-right-radius: 4px;
}
.thread-msg.ai {
  justify-self: start;
  color: var(--ink-secondary);
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.thread-msg.thread-error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #f8c9c7;
}
.thread-note {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.thread-toggle {
  margin-top: 8px;
}
.thread-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  margin-top: 8px;
}
.thread-compose textarea {
  min-height: 64px;
  resize: none;
  font-size: 14px;
}
.thread-send {
  min-width: 72px;
  padding-left: 14px;
  padding-right: 14px;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(4px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- 问过去 ---------- */
.source-item {
  font-size: 13px;
  color: var(--muted);
  margin-top: var(--space-2);
  padding-left: 10px;
  border-left: 2px solid var(--line);
  word-break: break-word;
}

/* ---------- 登录 / 注册页 ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-4);
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 36px 28px 28px;
  text-align: center;
}

.login-card .brand {
  font-size: 22px;
  display: block;
}
.login-card p {
  margin-top: var(--space-2);
  font-size: 13px;
}
.login-card input {
  margin-top: var(--space-3);
  text-align: left;
}
.login-card button[type="submit"] {
  width: 100%;
  margin-top: var(--space-5);
  padding: 9px;
  font-size: 15px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: var(--space-5);
  margin-bottom: var(--space-2);
  padding: 3px;
  background: #eff0f1;
  border: none;
  border-radius: var(--radius-md);
}
.mode-btn {
  background: transparent;
  color: var(--muted);
  font-weight: 400;
  padding: 6px 0;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.mode-btn:hover { background: var(--hover-bg); color: var(--ink); }
.mode-btn.active {
  background: var(--card);
  color: var(--ink);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(31, 35, 41, 0.1);
}
.mode-btn.active:hover { background: var(--card); }

#login-tip {
  text-align: left;
  line-height: 1.6;
  margin-top: var(--space-3);
  color: var(--muted);
}

/* ---------- 移动端 ---------- */
@media (max-width: 480px) {
  body { font-size: 15px; }
  main { padding: var(--space-3) var(--space-3) 48px; }
  .topbar { padding: var(--space-3); }
  .tabs { padding: 0 var(--space-3); }
  .card { padding: var(--space-3); margin-top: var(--space-3); }
  .login-card { padding: 28px 20px 24px; }
  .ai-badge, .user-badge { max-width: 32vw; }
  textarea { resize: none; }
  .row > button, #save-btn, #ask-btn { min-height: 40px; }
  .thread-compose { grid-template-columns: 1fr; }
  .thread-send { min-height: 40px; }
  .thread-msg { max-width: 96%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
