/* ============================================
   「纸上」设计变量
   改配色只改这一层，其他文件不用动
   ============================================ */

:root {
  /* 纸 */
  --paper:        #F5F0E6;   /* 页面底：米色纸 */
  --note:         #FFFEFB;   /* 序的便签：无边框，靠阴影浮起 */
  --note-user:    #EAE3D5;   /* 你的气泡（官端吸色后替换这一行） */
  --line:         #E3DCCD;   /* 分隔线 / 边框 */

  /* 字 */
  --ink:          #3D3A35;   /* 正文：暖炭 */
  --ink-soft:     #A8A194;   /* 时间戳、占位符、次要信息 */

  /* 点缀（留着，暂时不用） */
  --accent:       #C9B8E4;   /* 淡紫，将来给焦点态/发送反馈 */

  /* 形状 */
  --r-bubble:     18px;
  --r-input:      22px;
  --r-panel:      16px;
  --tilt:         0deg;      /* 便签歪度：0=摆正（当前）。想手帐一点就调 0.5~1.2deg */

  /* 字号 */
  --fs-msg:       15px;
  --fs-title:     16px;
  --fs-meta:      11px;

  /* 阴影：很轻，像纸贴在纸上 */
  --shadow-note:  0 1px 4px rgba(90, 80, 60, 0.10), 0 0 0 0.5px rgba(90, 80, 60, 0.04);
  --shadow-panel: 0 2px 14px rgba(90, 80, 60, 0.10);
}

/* 深色：墨紫纸 · 回国后调，色号先记住 */
:root[data-theme="dark"] {
  --paper:        #4A4356;
  --note:         #565064;
  --note-user:    #C9B8E4;
  --line:         #625B70;
  --ink:          #F0EDF5;
  --ink-soft:     #9B93AC;
  --accent:       #C9B8E4;
  --shadow-note:  0 1px 3px rgba(0, 0, 0, 0.18);
  --shadow-panel: 0 2px 14px rgba(0, 0, 0, 0.28);
}
/* ============================================
   骨架 · header · 输入区
   ============================================ */

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
  height: 100dvh;              /* 手机浏览器地址栏收缩时不会跳 */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; height: 100dvh; }

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

/* ---------- header ---------- */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

#menu-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}

header h1 {
  flex: 1;
  text-align: center;
  font-family: Georgia, "Songti SC", serif;
  font-size: var(--fs-title);
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header .right-slot {
  min-width: 32px;            /* 和左边菜单键对称，标题才真居中 */
  display: flex;
  justify-content: flex-end;
}

header .icon-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13.5px;
  cursor: pointer;
  padding: 4px 5px;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}
header .icon-btn:hover { color: var(--ink); }

/* 线条图标：细线，跟着文字颜色走，深色模式自动跟着变 */
header .icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* 月亮 / 太阳：按当前主题只露一个 */
#theme-btn .i-sun { display: none; }
:root[data-theme="dark"] #theme-btn .i-moon { display: none; }
:root[data-theme="dark"] #theme-btn .i-sun  { display: block; }

/* ---------- 输入区 ---------- */

footer {
  position: relative;          /* 螃蟹要趴在这上面 */
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px 18px;
  border-top: 1px solid var(--line);
}

/* ＋ 按钮这版不上线：没有功能挂着的按钮不放。
   等图片上传做好了，样式写回这里。 */

#input {
  flex: 1;
  min-height: 42px;
  max-height: 140px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-input);
  background: var(--note);
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-msg);
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}
#input::placeholder {
  color: var(--ink-soft);
  font-family: Georgia, "Songti SC", serif;   /* 跟标题同一套衬线 */
  font-style: italic;
  letter-spacing: 0.03em;
}
/* 聚焦时只是线变深一点。淡紫在米纸上太跳，留给深色模式用 */
#input:focus { border-color: var(--ink-soft); }
:root[data-theme="dark"] #input:focus { border-color: var(--accent); }

/* 发送键：只有一朵花，没有框 */
#send-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  transition: transform 0.15s;
}
#send-btn img { width: 30px; height: 30px; display: block; }
#send-btn:active { transform: scale(0.88) rotate(-8deg); }
#send-btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- 螃蟹 · 趴在输入框上沿 ---------- */

#crab {
  position: absolute;
  right: 76px;
  top: -14px;
  width: 34px;
  height: auto;
  image-rendering: pixelated;   /* 像素图不要被糊掉 */
  pointer-events: none;
  z-index: 2;
  /* 2026 七夕打开的。不想要就把下面这行注释掉。 */
  animation: crab-idle 2.4s ease-in-out infinite;
}

@keyframes crab-idle {
  0%, 100% { transform: translateY(0) }
  50%      { transform: translateY(-3px) }
}
/* ============================================
   消息气泡 · 无边框，只靠阴影浮在纸上
   ============================================ */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* 每条消息的外层（气泡 + 可能的时间戳） */
.msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  margin-bottom: 14px;
}
.msg-wrap.user      { align-self: flex-end;   align-items: flex-end; }
.msg-wrap.assistant { align-self: flex-start; align-items: flex-start; }

/* 时间戳：只在序的消息上方，小灰字 */
.msg-time {
  font-size: var(--fs-meta);
  color: var(--ink-soft);
  margin: 0 0 5px 4px;
  letter-spacing: 0.02em;
}
.msg-wrap.user .msg-time { display: none; }   /* 你的不显示 */

/* 气泡本体 */
.msg {
  padding: 11px 15px;
  border-radius: var(--r-bubble);
  font-size: var(--fs-msg);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-note);
}

/* 序：白便签，微微歪 */
.msg.assistant {
  position: relative;                /* 水印要贴在右下角 */
  background: var(--note);
  color: var(--ink);
  border-bottom-left-radius: 6px;
  transform: rotate(var(--tilt));
}

/* 便签右下角一朵极淡的雏菊。不凑近看不见——本来就不是给人看的。
   想更明显：把 opacity 调到 0.14。不想要：把整块删掉。 */
.msg.assistant::after {
  content: "";
  position: absolute;
  right: 8px;
  bottom: 7px;
  width: 24px;
  height: 24px;
  background: url("/icons/daisy.png") center / contain no-repeat;
  opacity: 0.16;
  pointer-events: none;
}
/* 深色底上白花更跳，所以反而要压低 */
:root[data-theme="dark"] .msg.assistant::after { opacity: 0.10; }

/* 你：暖米气泡，往另一边歪 */
.msg.user {
  background: var(--note-user);
  color: var(--ink);
  border-bottom-right-radius: 6px;
  transform: rotate(calc(var(--tilt) * -1));
}

/* 模型名小标签：挂在序的气泡里，跟时间戳一个量级，不抢正文 */
.model-tag {
  margin-top: 6px;
  font-size: var(--fs-meta);
  line-height: 1.4;
  color: var(--ink-soft);
  letter-spacing: 0.02em;
}

/* 歪一点点就好，长消息不要歪（会显得散） */
.msg-wrap.long .msg { transform: none; }

/* 正在输入 / 等待回复时的呼吸点 */
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
}
.typing span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: breathe 1.3s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s }
.typing span:nth-child(3) { animation-delay: 0.36s }

@keyframes breathe {
  0%, 100% { opacity: 0.25; transform: translateY(0) }
  50%      { opacity: 0.9;  transform: translateY(-2px) }
}
/* ============================================
   侧栏 · 对话列表 · 设定面板
   ============================================ */

#sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  transition: transform 0.26s ease;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  font-family: Georgia, "Songti SC", serif;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.sidebar-head button {
  border: none;
  background: var(--note);
  color: var(--ink-soft);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  box-shadow: var(--shadow-note);
}
.sidebar-head button:hover { color: var(--ink); }

#conv-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px;
}

/* 每个对话 = 一张小便签 */
.conv-item {
  display: flex;
  align-items: center;
  background: transparent;
  border-radius: 12px;
  padding: 9px 11px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: background 0.15s;
}
.conv-item:hover { background: var(--note); }

.conv-item.active {
  background: var(--note);
  box-shadow: var(--shadow-note);
}

.conv-info { flex: 1; min-width: 0; }

.conv-title {
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-meta {
  font-size: var(--fs-meta);
  color: var(--ink-soft);
  margin-top: 3px;
}

.conv-actions { display: flex; gap: 1px; opacity: 0; transition: opacity 0.15s; }
.conv-item:hover .conv-actions,
.conv-item.active .conv-actions { opacity: 1; }

.conv-actions button {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 6px;
  font-size: 12px;
}
.conv-actions button:hover { color: var(--ink); background: var(--paper); }

.sidebar-foot { padding: 12px; border-top: 1px solid var(--line); }

.sidebar-foot button {
  width: 100%;
  border: none;
  background: var(--note);
  color: var(--ink);
  border-radius: 10px;
  padding: 9px;
  cursor: pointer;
  font-size: 12.5px;
  box-shadow: var(--shadow-note);
}

#backdrop { display: none; }

/* ---------- 设定面板（system prompt / 纸条） ----------
   选择器按现有 index.html / app.js 来：遮罩是 #settings-overlay，
   开关是 .show（不是 .open），卡片是 #settings-panel。JS 一行没动。 */

#settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  place-items: center;
  background: rgba(60, 52, 40, 0.22);
  padding: 20px;
}
#settings-overlay.show { display: grid; }

#settings-panel {
  width: min(560px, 100%);
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--note);
  border-radius: var(--r-panel);
  box-shadow: var(--shadow-panel);
  padding: 20px;
}

.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: Georgia, "Songti SC", serif;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--ink);
  margin-bottom: 12px;
}

.settings-head button {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
}
.settings-head button:hover { color: var(--ink); }

#system-input {
  flex: 1;
  min-height: 240px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.65;
  resize: none;
  outline: none;
}
#system-input:focus { border-color: var(--ink-soft); }
:root[data-theme="dark"] #system-input:focus { border-color: var(--accent); }

.settings-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.settings-hint {
  font-size: var(--fs-meta);
  color: var(--ink-soft);
  line-height: 1.5;
}
.settings-foot .settings-hint { flex: 1; }

.settings-foot button {
  border: none;
  border-radius: 9px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  background: var(--accent);
  color: #3D3A35;
}

/* 备份 / 恢复 */
.settings-backup {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.backup-actions { display: flex; gap: 8px; }

.backup-actions button {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--ink);
  padding: 8px;
  cursor: pointer;
  font-size: 12.5px;
}
.backup-actions button:hover { background: var(--note); }

/* ---------- 手机 ---------- */

@media (max-width: 760px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 30;
    width: 258px;
    transform: translateX(-100%);
    box-shadow: 2px 0 20px rgba(60, 52, 40, 0.12);
  }
  #sidebar.open { transform: translateX(0); }

  #backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(60, 52, 40, 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.26s;
  }
  #backdrop.show { opacity: 1; pointer-events: auto; }

  #settings-overlay { padding: 12px; }
  .msg-wrap { max-width: 88%; }
  .conv-actions { opacity: 1; }
  footer { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}
