/* =========================================================
   Sunny 的私人 AI 工作台 — 奶油米色简约风
   移动端优先 · 设计系统
   ========================================================= */

:root {
  --bg: #F6F0E6;          /* 奶油米色主背景 */
  --bg-grad: #F3ECDD;
  --surface: #FFFFFF;     /* 卡片 */
  --surface-soft: #FBF7F0;
  --surface-warm: #F2E9D9;
  --primary: #C19A6B;     /* 焦糖驼 */
  --primary-dark: #A9824F;
  --primary-soft: #EBDDC8;
  --text: #4B4136;        /* 暖棕主文字 */
  --text-soft: #6E6353;
  --muted: #A1937E;       /* 次要文字 */
  --line: #ECE3D4;        /* 分隔线 */
  --accent: #E7B98F;      /* 蜜桃高亮 */
  --good: #8AAE7F;        /* 鼠尾草绿 */
  --bad: #D98C7A;         /* 柔红 */
  --info: #8FA9C4;
  --shadow: 0 6px 20px rgba(150, 130, 100, 0.12);
  --shadow-sm: 0 2px 8px rgba(150, 130, 100, 0.10);
  --radius: 18px;
  --radius-sm: 12px;
  --maxw: 480px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-grad);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 15px; }

.app {
  position: relative;
  max-width: var(--maxw);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(150, 130, 100, 0.10);
}

/* ---------------- 顶部栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(180deg, #FBF5EC 0%, #F6F0E6 100%);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0);
}
.topbar-inner {
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { font-size: 20px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .3px; color: var(--text); }
.icon-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: var(--text-soft);
  transition: background .15s;
}
.icon-btn:active { background: var(--primary-soft); }

/* ---------------- 主视图 ---------------- */
.view {
  flex: 1;
  padding: 16px 16px 92px;
  overflow-y: auto;
}

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 15px; margin: 0 0 12px;
  color: var(--text);
}
.card-title .emo { font-size: 18px; }

/* ---------------- 问候 / 仪表盘 ---------------- */
.hero {
  background: linear-gradient(135deg, #F7EEDD 0%, #F1E4CF 100%);
  border-radius: var(--radius);
  padding: 20px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.hero .hi { font-size: 13px; color: var(--text-soft); }
.hero .name { font-size: 22px; font-weight: 800; margin: 4px 0 2px; color: var(--text); }
.hero .date { font-size: 13px; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}
.stat {
  background: rgba(255,255,255,.6);
  border-radius: var(--radius-sm);
  padding: 12px;
}
.stat .v { font-size: 20px; font-weight: 800; color: var(--primary-dark); }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------------- 模块九宫格 ---------------- */
.section-label { font-size: 13px; color: var(--muted); margin: 6px 2px 10px; font-weight: 600; }
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.tile {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  border: 1px solid transparent;
  transition: transform .12s, border-color .12s;
}
.tile:active { transform: scale(.96); border-color: var(--primary-soft); }
.tile .ic { font-size: 26px; }
.tile .tx { font-size: 12.5px; color: var(--text-soft); }

/* ---------------- 列表项 ---------------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.item .main { flex: 1; min-width: 0; }
.item .ttl { font-weight: 600; color: var(--text); word-break: break-word; }
.item .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; word-break: break-word; white-space: pre-wrap; }
.item .meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.item.done .ttl { text-decoration: line-through; color: var(--muted); }

.chk {
  width: 22px; height: 22px; flex: 0 0 22px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: transparent;
  display: grid; place-items: center;
  color: #fff; font-size: 13px; margin-top: 1px;
}
.chk.on { background: var(--primary); }

.del {
  border: none; background: transparent; color: var(--muted);
  font-size: 16px; width: 30px; height: 30px; border-radius: 8px;
}
.del:active { background: #F6E6E0; color: var(--bad); }

.tag {
  display: inline-block; font-size: 11px; padding: 1px 8px;
  border-radius: 999px; background: var(--primary-soft); color: var(--primary-dark);
  margin-right: 6px;
}
.tag.green { background: #E3EEDD; color: #5C7A4E; }
.tag.red { background: #F6E2DC; color: #B25B47; }
.tag.blue { background: #E2EAF1; color: #4E6E8A; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 13px; }

/* ---------------- 按钮 ---------------- */
.btn {
  border: none; border-radius: 999px;
  padding: 11px 18px; font-size: 14px; font-weight: 700;
  background: var(--primary); color: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform .12s, background .15s;
}
.btn:active { transform: scale(.97); background: var(--primary-dark); }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-warm); color: var(--primary-dark); }
.btn.sm { padding: 8px 14px; font-size: 13px; }

.fab {
  position: fixed;
  right: max(16px, calc(50% - var(--maxw)/2 + 16px));
  bottom: 84px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff; font-size: 24px;
  border: none;
  box-shadow: 0 8px 22px rgba(161,130,79,.4);
  z-index: 15;
  display: grid; place-items: center;
}
.fab:active { transform: scale(.93); }

/* ---------------- 底部导航 ---------------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--maxw);
  background: rgba(251,247,240,.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 18;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab {
  flex: 1;
  border: none; background: transparent;
  padding: 8px 0 9px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); font-size: 11px;
}
.tab .ti { font-size: 20px; }
.tab.active { color: var(--primary-dark); font-weight: 700; }

/* ---------------- 弹窗 ---------------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(75,65,54,.4);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: var(--maxw);
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0));
  box-shadow: 0 -8px 30px rgba(75,65,54,.2);
  animation: slideUp .22s ease;
  max-height: 88vh; overflow-y: auto;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; font-size: 17px; color: var(--text); }
.modal-body { display: flex; flex-direction: column; gap: 12px; }

.field label { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 6px; font-weight: 600; }
.field input, .field textarea, .field select {
  width: 100%;
  border: 1.5px solid var(--line);
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--primary); }
.field textarea { resize: vertical; min-height: 84px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label {
  border: 1.5px solid var(--line);
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 7px 13px; font-size: 13px; color: var(--text-soft);
  margin: 0;
}
.seg input { display: none; }
.seg input:checked + span { color: var(--primary-dark); font-weight: 700; }
.seg label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }

/* ---------------- AI 聊天 ---------------- */
.chat { display: flex; flex-direction: column; gap: 12px; padding-bottom: 4px; }
.bubble {
  max-width: 82%; padding: 11px 14px; border-radius: 16px; font-size: 14px;
  word-break: break-word; white-space: pre-wrap;
}
.bubble.me { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.bubble.ai { align-self: flex-start; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-input {
  position: fixed; bottom: 64px; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--maxw);
  background: rgba(251,247,240,.97);
  border-top: 1px solid var(--line);
  display: flex; gap: 8px; padding: 10px 12px;
  z-index: 19;
}
.chat-input textarea {
  flex: 1; border: 1.5px solid var(--line); background: #fff;
  border-radius: 999px; padding: 10px 14px; resize: none; max-height: 90px; outline: none;
}
.chat-input textarea:focus { border-color: var(--primary); }
.chat-wrap { padding-bottom: 132px; }

/* ---------------- 设置 ---------------- */
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row .k { font-size: 14px; color: var(--text); }
.row .v { font-size: 13px; color: var(--muted); }

/* ---------------- 轻提示 ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: rgba(75,65,54,.92); color: #fff; padding: 10px 18px;
  border-radius: 999px; font-size: 13px; z-index: 60;
  box-shadow: var(--shadow);
  animation: pop .2s ease;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translateX(-50%); } }

/* 区间小标题 */
.subhead { font-size: 13px; color: var(--muted); margin: 16px 2px 8px; font-weight: 600; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1.5px solid var(--line); background: var(--surface-soft);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; color: var(--text-soft);
}
.pill.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; }

/* ---------------- 天气卡片 ---------------- */
.wx-tip {
  margin-top: 10px; background: var(--surface-soft);
  padding: 10px 12px; border-radius: 12px;
  font-size: 13px; color: var(--text-soft); line-height: 1.5;
}

/* ---------------- 记账图表 ---------------- */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.bar-label { width: 42px; flex: 0 0 42px; color: var(--text-soft); }
.bar-track { flex: 1; height: 14px; background: var(--surface-warm); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%); border-radius: 999px; transition: width .4s ease; }
.bar-val { width: 66px; flex: 0 0 66px; text-align: right; color: var(--muted); }

.spark { display: flex; align-items: flex-end; justify-content: space-between; gap: 4px; height: 78px; padding: 0 2px; }
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.spark-bars { display: flex; align-items: flex-end; gap: 3px; height: 60px; }
.sb { width: 7px; border-radius: 3px 3px 0 0; }
.sb.in { background: var(--good); }
.sb.out { background: var(--bad); }
.spark-x { font-size: 9.5px; color: var(--muted); }
.spark-legend { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.spark-legend .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.spark-legend .dot.in { background: var(--good); }
.spark-legend .dot.out { background: var(--bad); }
