/* =========================================================
   mobile.css —— 响应式适配（最后加载，用于覆盖桌面样式）
   断点：手机 ≤767px ｜ 平板 768–1023px ｜ 桌面 ≥1024px
   ========================================================= */

/* ---------- 全局：杜绝横向溢出 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; -webkit-text-size-adjust: 100%; }
img, video, canvas, iframe { max-width: 100%; }

/* =========================================================
   平板 768–1023px
   ========================================================= */
@media (min-width: 768px) and (max-width: 1023px) {
  .sidebar { width: 210px; }
  .content { padding: 20px 18px; }
  .topbar { padding: 0 18px; }
  .global-search { width: 190px; }
  .top-user { display: inline-flex; }

  .agent-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-grid { grid-template-columns: repeat(3, 1fr); }
  .continue-grid { grid-template-columns: repeat(2, 1fr); }
  .usage-stats.home { grid-template-columns: repeat(2, 1fr); }
  .plans { grid-template-columns: repeat(2, 1fr); }

  .profile-shell { grid-template-columns: 1fr 1fr; }
  .profile-card.wide { grid-column: 1 / -1; }

  /* 聊天：隐藏右侧说明栏，历史侧栏走抽屉（见 history.css ≤1023） */
  .chat-guide { display: none; }
  .chat-layout { height: calc(100vh - 110px); }
}

/* =========================================================
   手机 ≤767px
   ========================================================= */
@media (max-width: 767px) {

  /* ---------- 1. 外壳 ---------- */
  .app-shell { height: 100dvh; display: flex; overflow: hidden; }
  .workspace { width: 100%; min-width: 0; max-width: 100%; overflow: hidden; }
  .content {
    padding: 13px 12px calc(20px + env(safe-area-inset-bottom)) !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100%; overflow-x: hidden; overflow-y: auto;
  }
  body.drawer-lock { overflow: hidden; }

  /* ---------- 2. 左侧导航 → 抽屉 ---------- */
  .login-brand { display: none !important; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: clamp(260px, 72vw, 280px);
    transform: translateX(-102%);
    transition: transform .26s cubic-bezier(.4, 0, .2, 1);
    z-index: 60; box-shadow: 0 20px 60px rgba(11, 33, 25, .22);
    background: #f0f3ef; border-right: 1px solid var(--line);
    padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: translateX(0); left: 0; }
  .sidebar.collapsed { width: clamp(260px, 72vw, 280px); }
  .sidebar.collapsed .nav-label,
  .sidebar.collapsed .brand > div:nth-child(2),
  .sidebar.collapsed .sidebar-foot div,
  .sidebar.collapsed .sidebar-foot i { display: block; }

  .nav-mask {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(11, 30, 23, .46);
    opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  .nav-mask.show { opacity: 1; pointer-events: auto; }

  .sidebar .brand { height: 62px; padding: 0 14px; }
  .sidebar .brand b { font-size: 13px; }
  .sidebar .brand small { font-size: 10px; }
  #collapseBtn { font-size: 0; width: 32px; height: 32px; border-radius: 9px; }
  #collapseBtn::before { content: "✕"; font-size: 14px; color: #5b6a63; }

  .sidebar nav { padding: 10px 9px calc(10px + env(safe-area-inset-bottom)); }
  .nav-item { height: 46px; font-size: 14px; }
  .nav-icon { font-size: 16px; }

  /* 二级智能体预览 */
  .nav-chev {
    display: grid; place-items: center; margin-left: auto; flex: none;
    width: 26px; height: 26px; border-radius: 7px; font-style: normal;
    font-size: 15px; color: #7d8b84; background: rgba(0, 0, 0, .04);
    transform: rotate(90deg); transition: transform .2s;
  }
  .nav-item.active .nav-chev { color: #fff; background: rgba(255, 255, 255, .18); }
  .nav-group.open .nav-chev { transform: rotate(-90deg); }
  .nav-group .nav-sub { display: none; }
  .nav-group.open .nav-sub {
    display: block; margin: 2px 0 8px; padding: 6px;
    background: #e9eee9; border-radius: 11px;
  }
  .nav-sub-item {
    width: 100%; display: flex; align-items: center; gap: 9px;
    border: 0; background: transparent; text-align: left;
    height: 40px; padding: 0 8px; border-radius: 8px; color: #4a5a52; font-size: 13px;
  }
  .nav-sub-item i {
    flex: none; width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
    background: #dbe7df; color: #1d5744; font-style: normal; font-weight: 800; font-size: 12px;
    overflow: hidden; text-align: center; line-height: 1;
  }
  /* 兜底：图标位为空时不留空洞，且绝不溢出压到后面的文字 */
  .nav-sub-item i:empty { background: #e6ede8; }
  .nav-sub-item i:empty::after { content: "智"; color: #7d8f86; font-weight: 700; }
  .nav-sub-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-sub-more {
    width: 100%; border: 0; background: transparent; color: var(--green);
    font-size: 11px; text-align: left; padding: 8px; margin-top: 2px;
  }

  /* 会员入口在移动端收起 */
  .plan-mini { display: none !important; }
  .sidebar-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }

  /* ---------- 3. 顶部 Header ---------- */
  .topbar {
    height: 56px; padding: 0 10px; gap: 8px;
    position: sticky; top: 0; z-index: 40;
    background: rgba(255, 255, 255, .95);
  }
  .mobile-menu {
    display: inline-flex !important; align-items: center; justify-content: center;
    width: 38px; height: 38px; flex: none; border: 0; background: transparent;
    color: #1d4b3c; border-radius: 10px; padding: 0;
  }
  .crumb {
    display: block !important; flex: 1; min-width: 0; font-size: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .crumb b { font-size: 15px; font-weight: 700; color: #153f32; }

  .top-actions { display: flex; align-items: center; gap: 5px; flex: none; }
  .global-search {
    display: flex !important; width: 38px; min-width: 38px; height: 38px;
    padding: 0; justify-content: center; border-radius: 10px; transition: .18s;
  }
  .global-search span { font-size: 17px; }
  .global-search input { width: 0; padding: 0; border: 0; background: transparent; font-size: 16px; }
  .global-search kbd { display: none; }
  .global-search:focus-within {
    position: absolute; left: 10px; right: 10px; top: 9px; width: auto;
    padding: 0 12px; background: #fff; z-index: 6; box-shadow: 0 8px 24px rgba(18, 60, 47, .14);
  }
  .global-search:focus-within input { width: 100%; }
  .global-search:focus-within span { margin-right: 8px; }

  #noticeBtn { display: none !important; }
  .admin-link {
    display: inline-flex !important; align-items: center; justify-content: center;
    font-size: 0 !important; width: 38px; height: 38px; padding: 0; border-radius: 10px; flex: none;
  }
  .admin-link::before { content: "⚙"; font-size: 17px; }
  .top-user {
    display: inline-flex; align-items: center; justify-content: center; flex: none;
    width: 34px; height: 34px; padding: 0; border: 0; background: transparent; border-radius: 50%;
  }
  .top-user .avatar { width: 32px; height: 32px; border-radius: 50%; font-size: 13px; }

  /* ---------- 4. 页面标题 & 操作按钮图标化 ---------- */
  .page-head { align-items: center; gap: 10px; margin-bottom: 13px; flex-wrap: nowrap; }
  .page-head > div:first-child { min-width: 0; flex: 1; }
  .page-head h1 { font-size: 19px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page-head p { display: none; }
  .head-actions {
    flex: none; display: flex; gap: 6px; max-width: 56%;
    overflow-x: auto; scrollbar-width: none;
  }
  .head-actions::-webkit-scrollbar { display: none; }
  .head-actions .btn { flex: none; height: 34px; padding: 0 11px; font-size: 12px; border-radius: 10px; }
  .btn.icon-btn { width: 36px; height: 36px; padding: 0; justify-content: center; }
  .btn.icon-btn .lbl { display: none; }

  /* ---------- 5. 首页任务输入：极简 ＋ [输入] ↑ ---------- */
  .hero, .hero.compact {
    background: #fff; color: #14352c; border: 1px solid #e2eae4;
    border-radius: 14px; padding: 8px; min-height: 0;
    box-shadow: 0 2px 12px rgba(20, 60, 47, .05);
  }
  .hero::before, .hero::after { display: none !important; }
  .hero h2, .hero > p, .hero-welcome, .hero .eyebrow { display: none !important; }
  .hero-composer {
    height: auto; margin: 0; padding: 5px 6px; gap: 6px;
    background: #f4f8f5; border: 1px solid #e2ebe5; border-radius: 12px;
  }
  .hero-composer input {
    flex: 1; min-width: 0; height: 40px; font-size: 16px; background: transparent; color: #173f33;
  }
  .hero-composer .composer-tool {
    width: 34px !important; height: 34px !important;
    background: transparent !important; color: #3d6b59 !important; font-size: 18px !important;
  }
  /* 语音按钮：手机上同样保留（2026-09-19 起不再隐藏） */
  #homeVoice { display: inline-flex !important; align-items: center; justify-content: center; }
  .hero-composer .send-btn {
    width: 38px; height: 38px; min-width: 38px; padding: 0; border-radius: 11px;
    display: inline-flex; align-items: center; justify-content: center; background: #123c2f;
  }
  .hero-composer .send-btn .lbl { display: none; }
  .hero-composer .send-btn .ico { display: block; font-size: 18px; line-height: 1; }

  /* ---------- 6. 分区标题 ---------- */
  .section-title { margin: 18px 0 10px; }
  .section-title h3 { font-size: 14px; }
  .section-title button { font-size: 11px; }

  /* ---------- 7. 高频任务：三列极简 ---------- */
  .quick-grid { display: grid !important; grid-template-columns: repeat(3, 1fr) !important; gap: 9px; }
  .quick-card {
    min-height: 0; padding: 12px 5px; border-radius: 14px;
    display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  }
  .quick-card p, .quick-card .task-tag, .quick-card > span:last-child { display: none !important; }
  .quick-card .icon { width: 44px; height: 44px; border-radius: 12px; position: static; font-size: 16px; }
  .quick-card b {
    margin: 0; font-size: 11px; line-height: 1.35; font-weight: 600;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }

  /* ---------- 8. 智能体网格：一个字徽标 + 名称 ---------- */
  .agent-grid { display: grid !important; grid-template-columns: repeat(3, 1fr) !important; gap: 9px; }
  .agent-card {
    padding: 12px 5px; border-radius: 14px; min-height: 0;
    display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  }
  .agent-card:hover { transform: none; box-shadow: none; }
  .agent-card > p,
  .agent-card .agent-tags,
  .agent-card .agent-meta,
  .agent-card .status-dot,
  .agent-card .agent-top small { display: none !important; }
  .agent-card .agent-top {
    display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; margin: 0;
  }
  .agent-card .agent-top > div { width: 100%; min-width: 0; }
  .agent-card .agent-avatar { width: 44px; height: 44px; border-radius: 12px; font-size: 16px; }
  .agent-card .agent-top b {
    font-size: 11px; line-height: 1.35; font-weight: 600;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }
  /* 低饱和轮转配色 */
  .agent-card:nth-child(4n+2) .agent-avatar { background: #eceff7; color: #4b5079; }
  .agent-card:nth-child(4n+3) .agent-avatar { background: #f6eef1; color: #7b4457; }
  .agent-card:nth-child(4n+4) .agent-avatar { background: #f7f1e8; color: #785634; }

  /* ---------- 9. 继续上次任务 / 最近生成 ---------- */
  .continue-grid { grid-template-columns: 1fr; gap: 8px; }
  .continue-item {
    padding: 11px 12px; border-radius: 12px;
    max-width: 100%;
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .ci-badge { width: 34px; height: 34px; flex: none; }
  .ci-go { font-size: 0; flex: none; }
  .ci-go::before { content: "›"; font-size: 18px; }

  .output-row {
    padding: 10px 12px;
    max-width: 100%;
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  .output-list .output-row:nth-child(n+4) { display: none; }
  .or-view { display: none; }

  /* 首页模块区间距收紧 */
  .section-title { margin: 14px 0 8px; }
  .section-title h3 { font-size: 14px; }

  /* ---------- 10. 会员信息：移动端仅在需要提醒时出现 ---------- */
  .membership-card { display: none; }
  .membership-card.urgent {
    display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 13px 14px;
  }
  .membership-card.urgent .membership-data { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
  .membership-card.urgent .btn { width: 100%; }

  /* ---------- 11. 简报 / 使用数据 ---------- */
  .daily { display: none; }
  .daily.standalone { display: block; padding: 14px; border-radius: 14px; }
  .daily-grid { grid-template-columns: 1fr 1fr; }
  .usage-stats.home { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .usage-stats.home .usage-stat { padding: 11px; }
  .usage-stats.home .usage-stat b { font-size: 15px; }

  /* ---------- 12. 部门 Banner 精简 ---------- */
  .dept-banner { padding: 15px 16px; border-radius: 14px; margin-bottom: 14px; }
  .dept-copy h1 { font-size: 18px; margin: 0; }
  .dept-copy p, .dept-audience, .dept-numbers { display: none !important; }

  /* ---------- 13. 聊天页：整屏 ---------- */
  body.view-chat .content { padding: 0; overflow: hidden; }
  body.view-chat .chat-layout,
  body.view-chat .chat-layout.pro {
    display: flex !important; flex-direction: column;
    height: calc(100dvh - 56px) !important; margin: 0; border: 0; border-radius: 0;
    overflow: hidden;
  }
  .chat-head {
    position: sticky; top: 0; z-index: 5; background: #fff;
    padding: 9px 10px; gap: 8px; min-height: 54px;
    flex-shrink: 0;
  }
  .chat-hist-btn { display: inline-flex !important; width: 36px; height: 36px; }
  .chat-identity { flex: 1; min-width: 0; }
  .chat-identity b { font-size: 14px; }
  .chat-identity small {
    font-size: 10px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .chat-new-btn { width: 36px; height: 36px; padding: 0; flex: none; }

  .chat-main { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
  .chat-body {
    padding: 14px 10px 8px;
    overflow-y: auto; overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    flex: 1; min-height: 0;
  }

  /* ===== 消息气泡：防溢出核心 ===== */
  .message {
    max-width: 92% !important;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow: hidden;
    font-size: 13px !important;
    line-height: 1.7 !important;
  }
  .message.user {
    max-width: 82% !important;
    margin-left: auto;
    padding: 10px 13px;
    border-radius: 13px 13px 4px 13px;
  }
  .message.ai {
    max-width: 90% !important;
    gap: 7px;
  }
  .message.ai .bubble {
    padding: 11px 13px;
    border-radius: 4px 13px 13px 13px;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow: hidden;
    max-width: 100%;
    font-size: 13px !important;
    line-height: 1.7 !important;
  }
  .message.ai .agent-avatar {
    flex: none; width: 32px; height: 32px; border-radius: 9px;
    font-size: 13px;
  }
  .message-actions {
    gap: 5px; margin-top: 6px;
  }
  .message-actions button {
    font-size: 9px; padding: 4px 7px;
  }

  /* 追问 chips 横向滚动 */
  .quick-questions, .chat-compose .quick-actions {
    display: flex !important; flex-wrap: nowrap !important;
    overflow-x: auto; gap: 7px; padding-bottom: 5px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
  .quick-questions::-webkit-scrollbar,
  .chat-compose .quick-actions::-webkit-scrollbar { display: none; }
  .quick-questions .qchip,
  .chat-compose .quick-actions button {
    flex: none; white-space: nowrap;
    font-size: 11px !important;
    padding: 6px 11px !important;
    border-radius: 14px !important;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 输入区 88–120px + 安全区 */
  .chat-compose {
    position: sticky; bottom: 0; background: #fff; z-index: 5;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    max-width: 100%;
    overflow: hidden;
  }
  .chat-compose .box {
    min-height: 80px; max-height: 120px; align-items: flex-end; gap: 6px; padding: 7px 8px;
    max-width: 100%;
    overflow: hidden;
  }
  .chat-compose textarea#chatInput {
    min-height: 54px; max-height: 96px; font-size: 15px; line-height: 1.55;
    max-width: 100%;
    overflow-y: auto;
  }
  /* 语音按钮：手机上同样保留（2026-09-19 起不再隐藏）；两个圆按钮收小，给输入框让位 */
  .chat-compose .composer-tool { width: 34px !important; height: 34px !important; font-size: 16px !important; }
  #chatVoice { display: inline-flex !important; align-items: center; justify-content: center; }
  #chatSend { height: 34px; padding: 0 11px; font-size: 12px; border-radius: 10px; flex: none; }
  .compose-tip { display: none; }
  .chat-guide { display: none !important; }

  /* 历史抽屉安全区 */
  .history-aside { padding-top: max(12px, env(safe-area-inset-top)); }

  /* ---------- 14. 个人中心：单列 ---------- */
  .profile-shell { grid-template-columns: 1fr; gap: 12px; }
  .profile-card.wide { grid-column: auto; }
  .profile-hero { flex-direction: column; align-items: flex-start; gap: 11px; padding: 15px; }
  .profile-hero .btn { width: 100%; }
  .profile-row { flex-wrap: wrap; gap: 4px; }
  .pf-input { width: 100%; font-size: 16px; }
  .hp-list, .qe-list { grid-template-columns: 1fr; }
  .usage-stats { grid-template-columns: repeat(2, 1fr) !important; }

  /* ---------- 15. 使用记录 ---------- */
  .rec-toolbar { flex-direction: column; }
  .rec-toolbar input { font-size: 16px; }
  .rec-toolbar .btn { width: 100%; }
  table.records { min-width: 560px; }

  /* ---------- 16. 套餐 ---------- */
  .plans { grid-template-columns: 1fr; }

  /* ---------- 17. 弹窗 / 提示 ---------- */
  .modal {
    width: calc(100vw - 22px); max-width: none;
    max-height: calc(86dvh - env(safe-area-inset-bottom)); overflow: auto; padding: 18px 16px;
  }
  .modal input, .modal select, .modal textarea { font-size: 16px; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions .btn { width: 100%; }
  .toast { left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); text-align: center; }

  /* ---------- 18. 登录页 ---------- */
  .login-panel { padding: calc(20px + env(safe-area-inset-top)) 0 calc(16px + env(safe-area-inset-bottom)); }
  .login-box { width: min(420px, 90%); }
  .login-box h2 { font-size: 21px; }
  .login-box input { font-size: 16px; }
  .orbit-card { display: none !important; }
  .commercial-links { flex-wrap: wrap; gap: 8px; }
}

/* 超窄屏（≤360px）：网格降为两列，避免文字挤成一列 */
@media (max-width: 360px) {
  .agent-grid, .quick-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .head-actions { max-width: 46%; }
}

/* =========================================================
   智能体中心：定制新智能体 / 筛选 / 使用记录 —— 移动端适配
   ========================================================= */
@media (max-width: 767px) {
  /* 定制创建界面：宽弹窗转全屏，左配置 / 右测试 改为上下堆叠 */
  .modal.wide { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .ca-editor { height: 100dvh; max-height: 100dvh; }
  .ca-head { padding: 13px 16px; }
  .ca-head h3 { font-size: 15px; }
  .ca-head-tip { display: none; }
  .ca-body { grid-template-columns: 1fr; overflow: auto; }
  .ca-form { border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
  .ca-field input, .ca-field textarea, .ca-field select { font-size: 16px; }
  .ca-test { min-height: 62dvh; }
  .ca-test-body { padding: 14px; }
  .ca-save { height: 48px; }

  /* 使用记录：工具栏与表格在窄屏不溢出 */
  .panel-usage .us-toolbar { flex-direction: column; }
  .panel-usage .us-toolbar select,
  .panel-usage .us-toolbar input { width: 100%; }
  .panel-usage .us-table { display: block; overflow-x: auto; white-space: nowrap; }

  /* 筛选面板 select 全宽易点 */
  .panel-filter .ff-row select { font-size: 16px; }

  /* 自定义智能体卡片徽标在窄屏不挤压标题 */
  .agent-card.custom { padding-top: 30px; }
  .custom-badge { left: 12px; top: 12px; }
}
