/* Agent Home v2（F1）。无构建链、无外链（CSP 'self'）。
   布局：桌面 左=它的人生（四区纵列）· 右=对话；≤760px 左区折叠为抽屉。 */

:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --ink: #23211d;
  --muted: #8a857c;
  --line: #e6e2da;
  --accent: #3d6b5e;
  --accent-ink: #ffffff;
  --warn: #a2582d;
  --ok: #3d6b5e;
  --danger: #a03b3b;
  --chip-off: #b9b3a8;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(35, 33, 29, .06), 0 6px 18px rgba(35, 33, 29, .05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); font-size: 13px; }
a { color: var(--accent); }

button {
  font: inherit; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); border-radius: 10px; padding: 7px 14px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
.small-btn { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.icon-btn { padding: 4px 9px; font-size: 16px; }

input, textarea, select {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(61,107,94,.25); }

/* ── 登录 / 创建引导 ── */
.view { min-height: 100vh; }
.auth-card {
  max-width: 460px; margin: 8vh auto; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 34px 34px 26px; display: flex; flex-direction: column; gap: 12px;
}
.auth-card.onboard { max-width: 560px; margin: 4vh auto; max-height: 92vh; overflow: auto; }
.auth-hero { font-size: 44px; text-align: center; }
.auth-card h1 { font-size: 20px; margin: 4px 0 0; }
.auth-card h1.gap-top { margin-top: 26px; }
.auth-card input { width: 100%; }
.auth-legal { margin: 2px 0 10px; color: var(--muted); font-size: 12px; line-height: 1.55; }
.auth-legal a { color: var(--accent); }
.notice { font-size: 13px; color: var(--muted); }
#code-row { display: flex; gap: 10px; }
.terms { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; font-size: 13px; }
.terms label { display: block; margin-top: 8px; }

.avatar-category { font-size: 13px; color: var(--muted); margin: 10px 0 6px; }
#avatar-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-opt {
  width: 52px; height: 52px; font-size: 24px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.avatar-opt.sel { border-color: var(--accent); outline: 2px solid rgba(61,107,94,.35); }

#skills-list { display: flex; flex-direction: column; gap: 6px; }
.skill-item { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.skill-item input { margin-top: 4px; }

/* ── Home 布局 ── */
.home-layout {
  display: grid; grid-template-columns: 430px 1fr; height: 100vh;
}

/* 左：它的人生 */
.life {
  overflow-y: auto; padding: 18px 16px 28px; display: flex; flex-direction: column;
  gap: 14px; background: linear-gradient(180deg, #f2f1ec 0%, var(--bg) 220px);
  border-right: 1px solid var(--line);
}
.zone { background: var(--card); border: 1px solid var(--line);
        border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.zone-title { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
.zone-sub-title { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.badge {
  background: var(--accent); color: #fff; font-size: 12px; border-radius: 999px;
  min-width: 20px; height: 20px; display: inline-flex; align-items: center;
  justify-content: center; padding: 0 6px;
}
.life-foot { text-align: center; padding-top: 4px; }

/* 身份区 */
.id-head { display: flex; gap: 14px; align-items: center; }
.portrait {
  width: 92px; height: 92px; border-radius: 16px; padding: 0; overflow: hidden;
  background: #eceae4; border: 1px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center;
}
.portrait-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.portrait-emoji { font-size: 44px; }
.id-name-col { min-width: 0; }
.id-name { font-size: 19px; font-weight: 600; }
.id-status { margin-top: 4px; }
/* WORLD-ENTRY-CLICK-01：世界状态段=可点入口（触控易点，语义 a href） */
.id-status a.world-entry, #chat-agent-status a.world-entry {
  color: var(--accent); text-decoration: underline; cursor: pointer;
}
.id-counts { margin-top: 12px; }
.id-mem { margin-top: 12px; }
.id-mem summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }
.mem-list { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.mem-row { border-left: 3px solid var(--line); padding-left: 10px; }
.mem-text { font-size: 13.5px; }

/* 使命区 */
.mission-list, .watch-list { display: flex; flex-direction: column; gap: 10px; }
.mission-card, .watch-card, .inbox-card, .cap-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 7px; background: #fdfcfb;
}
.mission-card.paused, .watch-card.paused, .muted-card { opacity: .72; }
.mission-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.mission-title { font-weight: 600; font-size: 14.5px; }
.chip-status {
  font-size: 12px; border-radius: 999px; padding: 2px 9px; white-space: nowrap;
  background: #eee9df; color: var(--muted);
}
.chip-status.ok { background: #e3ede8; color: var(--ok); }
.chip-status.warn { background: #f4e8dc; color: var(--warn); }
.chip-status.off { background: #eee9df; color: var(--chip-off); }
.budget-bar { display: flex; height: 6px; border-radius: 4px; overflow: hidden;
              background: #eceae4; min-width: 120px; }
.budget-bar .seg.spent { background: var(--accent); }
.budget-bar .seg.reserved { background: #9db8ae; }
.budget-bar .seg.free { background: #d9d5cb; }
.next-action {
  display: flex; gap: 8px; align-items: center; justify-content: flex-start;
  background: #f4f6f2; border-radius: 9px; padding: 8px 10px; font-size: 13.5px;
  flex-wrap: wrap;
}
/* 提醒文字独占一整行；动作按钮在下一行横向并排靠左，文字与按钮都不竖排
   （桌面左栏只有 ~350px，与手机同一套规则，避免汉字被挤成竖排） */
.next-action > span { flex: 1 1 100%; min-width: 0; overflow-wrap: anywhere; }
.next-action > button { flex: 0 0 auto; white-space: nowrap; }
.mission-ops, .inbox-ops { display: flex; gap: 8px; flex-wrap: wrap; }

/* UX39-SIMPLE-CARD-01：目标级管理操作折叠进原生 details，默认不抢眼 */
.mission-more { margin-top: 8px; }
.mission-more > summary {
  cursor: pointer; font-size: 13px; color: var(--muted);
  padding: 6px 2px; min-height: 32px; list-style: none;
}
.mission-more > summary::-webkit-details-marker { display: none; }
.mission-more > summary::before { content: "▸ "; }
.mission-more[open] > summary::before { content: "▾ "; }
.mission-more .mission-ops { margin-top: 6px; }
.watch-add { margin-top: 4px; }
.watch-add summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }
.watch-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.watch-form input { width: 130px; padding: 6px 9px; font-size: 13.5px; }

/* 能力区 */
.cap-limits { background: #f7f4ee; border-radius: 9px; padding: 8px 10px; }
.lim-title { font-size: 12.5px; color: var(--warn); }
.lim-item { font-size: 13px; }
.learn-fold, .skill-fold { margin-top: 10px; }
.learn-fold summary, .skill-fold summary {
  cursor: pointer; font-size: 13.5px; color: var(--muted);
}
.learn-fold > div, .skill-fold > div { margin-top: 8px; }
.learn-group { margin-bottom: 8px; }
.learn-item { padding-left: 8px; border-left: 2px solid var(--line); margin: 3px 0; }
.model-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

/* 收件箱 */
.inbox-kind { font-size: 12.5px; color: var(--muted); }
.inbox-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.inbox-card.collab { border-left: 3px solid var(--accent); }

/* 右：对话 */
.chat-side { display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-bottom: 1px solid var(--line); background: var(--card);
}
.chat-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-title #chat-agent-name { font-weight: 600; }
.chat-title .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages { flex: 1; overflow-y: auto; padding: 20px 8%; display: flex;
            flex-direction: column; gap: 12px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 14.5px;
       white-space: pre-wrap; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink);
          border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--card);
             border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--muted);
              font-size: 12.5px; text-align: center; max-width: 90%; }
.fb-row { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.fb-btn { padding: 2px 8px; font-size: 13px; border-radius: 7px; }
.card-chip {
  align-self: flex-start; background: #f4f6f2; border: 1px dashed var(--line);
  border-radius: 10px; padding: 8px 12px; font-size: 12.5px; max-width: 78%;
}
.chip-title { font-weight: 600; margin-bottom: 3px; }
/* TASK-PUB-01：需求草稿确认卡（聊天流内一次点击发布） */
.msg.system.need-card {
  align-self: flex-start; text-align: left; max-width: 78%;
  background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 10px;
  padding: 10px 14px; font-size: 13.5px; color: inherit;
}
.need-title { font-weight: 600; font-size: 14.5px; margin-bottom: 6px; }
.need-row { margin: 2px 0; word-break: break-word; }
.need-row.ok { color: var(--ok); font-weight: 600; }
.need-ops { margin-top: 10px; align-items: center; }
.chat-input-row {
  display: flex; gap: 10px; padding: 12px 8% 16px; border-top: 1px solid var(--line);
  background: var(--card);
}
.chat-input-row textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 44px; border-radius: 12px;
}
.chat-input-row button { align-self: flex-end; height: 44px; }

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(35,33,29,.35); z-index: 39;
}

/* ── 移动端（375px 可用；左区=抽屉） ── */
@media (max-width: 760px) {
  .home-layout { grid-template-columns: 1fr; }
  .life {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(88vw, 400px);
    z-index: 40; transform: translateX(-102%); transition: transform .22s ease;
    border-right: 1px solid var(--line); box-shadow: var(--shadow);
  }
  .life.open { transform: translateX(0); }
  .messages { padding: 16px 4%; }
  .chat-input-row { padding: 10px 4% 12px; }
  .msg { max-width: 88%; }
  .auth-card { margin: 4vh 14px; padding: 24px 20px; }

  /* MOBILE-UX-LANG-01（6548624832 A）：信息架构/空间分配修复——
     外层不滚，只有 #messages 是正文滚动面；flex 子项必须 min-height:0
     才不会把 composer 推出可视区（此前双层滚动的根因）。 */
  .home-layout { height: 100dvh; overflow: hidden; }
  .chat-side { min-height: 0; }
  .messages { min-height: 0; flex: 1 1 auto; }
  .chat-input-row { flex-shrink: 0; }
  .chat-head { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  .chat-title { min-width: 0; flex: 1 1 auto; }
  .chat-title > span:first-child { display: block; white-space: nowrap;
                                   overflow: hidden; text-overflow: ellipsis; }
  /* 状态行（含世界入口）独占一行，不被右侧按钮覆盖 */
  .chat-title { flex-basis: 100%; }
  .chat-title > span:first-child { display: block; white-space: nowrap;
                                   overflow: hidden; text-overflow: ellipsis; }
  #chat-input { min-height: 40px; max-height: 96px; }
  /* 首用提示折为一行：标题 + 展开/收起 + 知道了；展开才显示步骤与说明 */
  #first-use-guide { margin: 8px 10px 0; padding: 8px 10px; }
  #first-use-guide .fug-steps,
  #first-use-guide .fug-note { display: none; }
  #first-use-guide.fug-expanded .fug-steps { display: flex; }
  #first-use-guide.fug-expanded .fug-note { display: block; }
  /* 常驻导航收为「功能」单入口：默认不占两行，展开经头部按钮 */

  /* #39 视觉收口：小屏 .next-action 换行——提醒文字独占一行，
     批准/已阅两按钮落到下一行横向并排，按钮文字不竖排（桌面规则不动） */
  /* 布局规则已上移到基础样式，小屏只补触摸目标尺寸 */
  .next-action > button { min-width: 44px; min-height: 40px; }
  /* 「更多操作」保持整行可点、不挤压目标卡 */
  .mission-more { margin-top: 6px; }
  .mission-more > summary { min-height: 40px; padding: 8px 2px; }
  .mission-more .mission-ops > button { flex: 0 0 auto; white-space: nowrap;
                                        min-width: 44px; min-height: 40px; }
}

/* ── F2：目标草稿卡就地编辑表单 · 自建技能版本徽标 ── */
.inbox-card.goal-draft { border-left: 3px solid var(--accent); }
/* B-01：目标页「有 N 个目标草稿待批准」提示（链接收件箱） */
.mission-drafts-hint {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  background: #eef4e9; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; margin: 0 0 10px; font-size: 13.5px;
}
.draft-form {
  display: flex; flex-direction: column; gap: 8px;
  background: #f4f6f2; border-radius: 9px; padding: 10px; margin-top: 2px;
}
.draft-form input { width: 100%; padding: 6px 9px; font-size: 13.5px; }
.uskill-row {
  padding-left: 8px; border-left: 2px solid var(--line); margin: 6px 0;
}
.uskill-top {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
}
.uskill-name {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0; flex: 1;
}
.ver-chip {
  font-size: 11px; line-height: 1.4; border-radius: 999px; padding: 1px 7px;
  background: #eee9df; color: var(--muted); white-space: nowrap; flex: none;
}

/* TTS 点读按钮：agent 消息右侧小图标，播放中变暂停符 */
.msg-row { display: flex; align-items: flex-start; gap: 6px; }
.msg-row .msg-body { flex: 1 1 auto; min-width: 0; }
.tts-btn { flex: 0 0 auto; border: none; background: transparent; cursor: pointer;
           font-size: 13px; opacity: 0.45; padding: 2px 4px; border-radius: 6px; }
.tts-btn:hover { opacity: 1; background: rgba(0,0,0,0.05); }


/* ── T4-RL01：最近对话切换器 + mission 只读横幅 ────────────────────────── */
#btn-convs { flex: 0 0 auto; }
#conv-switcher {
  position: fixed; top: 52px; right: 120px; z-index: 40; width: 340px;
  max-height: 60vh; overflow: auto; background: var(--bg, #fff);
  border: 1px solid var(--line, #d8d8d8); border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0,0,0,.14);
}
#conv-switcher .conv-item {
  display: block; width: 100%; text-align: left; padding: 9px 12px;
  border: none; border-bottom: 1px solid #eee; background: none;
  cursor: pointer; font-size: 13px;
}
#conv-switcher .conv-item:hover { background: #f1f5f1; }
#conv-switcher .conv-item.conv-current { background: #eef4ee; }
#conv-switcher .conv-item .muted { color: var(--muted, #777); font-size: 12px; }
#mission-banner {
  border: 1px solid #d9e2d9; border-radius: 8px; padding: 6px 10px;
  margin: 8px 12px 0; font-size: 13px; background: #f3f7f3; color: #2b3a2b;
}
#mission-banner .mb-title { font-weight: 600; margin-bottom: 2px; }
#mission-banner.hidden, #conv-switcher.hidden { display: none; }

/* ── PB01（A2A-PRODUCT-BATCH-01）W-1：首页导航 + 首次使用引导 ──────────────────
   CSP 事实：script-src 'self' 且 style-src 'self'，均无 'unsafe-inline' ⇒
   内联 onclick 与内联 style 属性都会被浏览器拒绝。新代码一律走本文件（样式）
   与 addEventListener（行为），不使用内联属性。 */
.home-nav {
  display: flex; flex-wrap: wrap; gap: 12px; padding: 4px 12px; font-size: 13px;
}
#btn-nav-toggle { display: none; }   /* MOBILE-UX-LANG-01：桌面不渲染「功能」钮 */
.home-nav a { color: inherit; text-decoration: none; }
.home-nav a:hover { color: var(--accent); }

#first-use-guide {
  margin: 10px 12px 0; padding: 10px 12px; border: 1px solid #d9e2d9;
  border-radius: 10px; background: #f3f7f3; color: #2b3a2b;
}
#first-use-guide.hidden { display: none; }
.fug-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fug-title { font-weight: 600; font-size: 13.5px; }
.fug-steps { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; padding: 0;
             list-style: none; }
/* Z-T3（owner 7051777073 第 3 项）：首屏引导=一个主操作（说第一句话）；
   次级两步收进展开态（fug-toggle），不堆说明。 */
.fug-steps li.fug-more { display: none; }
#first-use-guide.fug-expanded .fug-steps li.fug-more { display: list-item; }
.fug-step { font-size: 13px; text-align: left; }
.fug-step.primary { background: rgba(61,107,94,.9); color: #fff;
                    border-color: rgba(61,107,94,.9); }
.fug-note { margin-top: 6px; }
/* 引导落点提示：仅瞬态高亮，不触发任何请求、不写入任何数据 */
.fug-flash { outline: 2px solid rgba(61,107,94,.55); outline-offset: 2px;
             border-radius: 10px; }

/* MOBILE-INPUT-01（6544334747 P0-M）：移动可视高度——100dvh 跟随
   Android 地址栏/键盘与 iOS safe-area 的动态视口；输入行固定在
   可视区内，聊天消息区独立滚动。不触碰桌面 1440 布局。 */
@supports (height: 100dvh) {
  .home-layout, .chat-side { height: 100dvh; }
}
@media (max-width: 900px) {
  .chat-input-row {
    position: sticky; bottom: 0;
    background: var(--card, #fff);
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}

/* MOBILE-PWA-01（6543753387 M）：安装引导横幅 */
.pwa-install-banner {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 999;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: #0d3b66; color: #fff; padding: 10px 12px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.pwa-install-banner .primary { margin-left: auto; }
.pwa-install-banner.hidden { display: none; }

/* MOBILE-UX-LANG-01：常驻导航收为「功能」单入口——必须置于基础 .home-nav
   规则之后（同特异性后者胜，早段块会被 298 行的 display:flex 覆盖） */
@media (max-width: 760px) {
  #btn-nav-toggle { display: inline-block; }
  .home-nav { display: none; flex-wrap: wrap; gap: 10px; padding: 8px 12px;
              border-bottom: 1px solid var(--line); font-size: 13px; }
  .home-nav.nav-open { display: flex; }
}

/* ── COMM-S2 商业待办卡（issue #35 切片2）────────────────────────────── */
.comm-chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 2px 0 8px; }
.comm-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; border: 1px solid rgba(127,127,127,.35);
  color: inherit; text-decoration: none; }
.comm-chip.mine { background: rgba(192,57,43,.08); border-color: rgba(192,57,43,.4);
  color: #c0392b; font-weight: 600; }
.comm-chip.peer { opacity: .75; }
.comm-row { display: flex; align-items: center; gap: 8px; padding: 7px 2px;
  border-bottom: 1px dashed rgba(127,127,127,.25); color: inherit;
  text-decoration: none; font-size: 13px; }
.comm-row:last-of-type { border-bottom: 0; }
.comm-row .n { margin-left: auto; font-weight: 600; }
.comm-row.dim { opacity: .5; }
.comm-card { cursor: default; }
.comm-brief { margin-top: 3px; font-size: 13px; }
.comm-todos { margin-top: 4px; display: flex; flex-direction: column; gap: 2px; }
.comm-todo { font-size: 12px; }
.comm-todo.peer { opacity: .6; }
.comm-sub { font-size: 11px; opacity: .75; margin-top: 6px; }
.comm-sub a { color: inherit; }
