/* ============================================================
   Cipher 密链 v3 · 沉浸式页面层（Immersive UI）
   规则：主 Tab 保留底栏；任何「点开的页面」全屏覆盖，
   隐藏全局侧栏 / 顶栏 / 底栏，自带返回头与完整内容。
   ============================================================ */

/* ---------- 1. 沉浸式状态：隐藏全局 chrome ---------- */
html[data-immersive="1"] .rail,
html[data-immersive="1"] .topbar,
html[data-immersive="1"] .mobile-tabs,
html[data-immersive="1"] .v2-fab-fixed,
html[data-immersive="1"] .subpage-bar { display: none !important; }
html[data-immersive="1"] .workspace { width: 100%; }
html[data-immersive="1"] .view-root { overflow: auto; }
html[data-immersive="1"] .view { overflow: visible; padding: 0 24px 64px; }
html[data-immersive="1"] .view-root > .view { max-width: 1120px; width: 100%; margin: 0 auto; }
html[data-immersive="1"] .view-head { margin-top: 22px; }
html[data-immersive="1"] .chat-layout { border: 0; border-radius: 0; background: transparent; }
html[data-immersive="1"] .conv-panel { border-right: 0; background: transparent; }
html[data-immersive="1"] .chat-pane { background: var(--surface); border-radius: 16px; border: 1px solid var(--border); overflow: hidden; }
html[data-immersive="1"] .chat-head { background: var(--surface); }
html[data-immersive="1"] .composer { border-top: 1px solid var(--border); }

/* 二级页自有头部（sticky） */
.im-head {
  position: sticky; top: 0; z-index: 30;
  margin: 0 -24px; padding: 9px 24px;
  min-height: 60px; display: flex; align-items: center; gap: 14px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.im-head-back {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.im-head-back:hover { color: var(--brand); border-color: var(--brand); }
.im-head-title { min-width: 0; flex: 1; display: flex; flex-direction: column; line-height: 1.4; }
.im-head-title strong { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.im-head-title small { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.im-head-acts { display: flex; gap: 8px; align-items: center; flex: none; }
.im-head-btn {
  height: 34px; padding: 0 13px; border-radius: 9px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  display: inline-flex; align-items: center; gap: 6px;
}
.im-head-btn.primary { background: var(--brand); color: #fff; border-color: transparent; }
.im-head-btn:hover { border-color: var(--brand); color: var(--brand); }
.im-head-btn.primary:hover { color: #fff; filter: brightness(1.06); }
.im-crumb { font-size: 11px; color: var(--text-3); display: flex; align-items: center; gap: 5px; }

/* ---------- 2. 全屏自绘页面层 ---------- */
#imm-layer {
  position: absolute; inset: 0; z-index: 150; display: none;
  flex-direction: column; background: var(--page);
  animation: im-in .22s ease both;
}
#imm-layer.on { display: flex; }
html[data-page="1"] .mobile-tabs,
html[data-page="1"] .v2-fab-fixed { display: none !important; }
@keyframes im-in { from { opacity: 0; transform: translateX(22px); } to { opacity: 1; transform: none; } }
@keyframes im-scan { 0% { top: 8%; } 50% { top: 88%; } 100% { top: 8%; } }
@keyframes im-pulse { 0%,100% { opacity: .45; } 50% { opacity: 1; } }

.im-phead {
  flex: none; display: flex; align-items: center; gap: 13px;
  min-height: 62px; padding: 9px 22px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.im-phead .im-head-title strong { font-size: 16px; }
.im-pbody { flex: 1; overflow: auto; padding: 22px 24px 72px; }
.im-pbody > * { max-width: 1000px; margin-left: auto; margin-right: auto; }
.im-pfoot {
  flex: none; padding: 12px 22px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: center; justify-content: flex-end;
}
.im-pfoot > * { max-width: 1000px; }

/* ---------- 3. 通用组件 ---------- */
.im-ic { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.im-ic.sm { width: 15px; height: 15px; }
.im-ic.lg { width: 24px; height: 24px; }

.im-sec { margin-bottom: 18px; }
.im-sec-h { display: flex; align-items: center; gap: 8px; margin: 0 0 9px; padding: 0 3px; }
.im-sec-h h3 { font-size: 12px; font-weight: 700; letter-spacing: .6px; color: var(--text-3); text-transform: uppercase; }
.im-sec-h .im-count { font-size: 10px; font-weight: 600; color: var(--text-3); background: var(--surface-2); border-radius: 99px; padding: 2px 8px; }
.im-sec-h .im-link { margin-left: auto; font-size: 11.5px; color: var(--brand); font-weight: 600; }

.im-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 15px; box-shadow: var(--shadow); overflow: hidden;
}
.im-card.pad { padding: 18px; }
.im-card + .im-card { margin-top: 12px; }

.im-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 15px; text-align: left; color: var(--text);
  border-bottom: 1px solid var(--border); background: transparent;
  min-height: 52px;
}
.im-row:last-child { border-bottom: 0; }
.im-row:hover { background: var(--surface-2); }
.im-row-ic {
  width: 32px; height: 32px; border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand);
}
.im-row-ic.tone-ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.im-row-ic.tone-warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.im-row-ic.tone-up { background: color-mix(in srgb, var(--up) 13%, transparent); color: var(--up); }
.im-row-ic.tone-plain { background: var(--surface-2); color: var(--text-2); }
.im-row-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.im-row-txt strong { font-size: 13.5px; font-weight: 600; }
.im-row-txt small { font-size: 11px; color: var(--text-3); line-height: 1.55; }
.im-row-val { font-size: 12px; color: var(--text-3); flex: none; max-width: 46%; text-align: right; }
.im-row-arrow { color: var(--text-3); flex: none; }
.im-row.danger .im-row-txt strong { color: var(--up); }

.im-sw {
  width: 40px; height: 23px; border-radius: 99px; flex: none; position: relative;
  background: var(--surface-3); border: 1px solid var(--border); transition: .18s;
}
.im-sw i { position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.18); transition: .18s; }
.im-sw.on { background: var(--brand); border-color: var(--brand); }
.im-sw.on i { left: 19px; }

.im-grid { display: grid; gap: 10px; }
.im-grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.im-grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.im-grid.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.im-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px 12px; text-align: left; display: flex; flex-direction: column; gap: 8px;
  color: var(--text); min-height: 92px; transition: .16s;
}
.im-tile:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow); }
.im-tile .im-tile-ic { width: 34px; height: 34px; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand); }
.im-tile strong { font-size: 13px; font-weight: 650; }
.im-tile small { font-size: 10.5px; color: var(--text-3); line-height: 1.5; }
.im-tile .im-tag { align-self: flex-start; }

.im-tag { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); }
.im-tag.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.im-tag.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.im-tag.up { background: color-mix(in srgb, var(--up) 13%, transparent); color: var(--up); }
.im-tag.plain { background: var(--surface-2); color: var(--text-3); }

.im-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.im-stat { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; padding: 13px 14px; }
.im-stat b { display: block; font-size: 20px; font-weight: 700; line-height: 1.2; }
.im-stat span { font-size: 11px; color: var(--text-3); }
.im-stat.accent b { color: var(--brand); }

.im-chips { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.im-chip { height: 30px; padding: 0 13px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.im-chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.im-chip:hover { border-color: var(--brand); }

.im-search { display: flex; align-items: center; gap: 9px; height: 42px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); padding: 0 13px; margin-bottom: 14px; color: var(--text-3); }
.im-search input { flex: 1; min-width: 0; font-size: 13px; color: var(--text); background: transparent; border: 0; outline: none; }
.im-search kbd { font-size: 10px; color: var(--text-3); border: 1px solid var(--border); border-radius: 5px; padding: 2px 6px; }

.im-hero { display: flex; align-items: center; gap: 16px; padding: 18px; border-radius: 16px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; margin-bottom: 16px; }
.im-hero .im-avatar { border: 2px solid rgba(255,255,255,.5); }
.im-hero-txt { flex: 1; min-width: 0; }
.im-hero-txt strong { display: block; font-size: 17px; font-weight: 700; }
.im-hero-txt small { display: block; font-size: 11.5px; opacity: .85; margin-top: 4px; line-height: 1.6; }
.im-hero .im-tag { background: rgba(255,255,255,.18); color: #fff; }

.im-avatar { width: 44px; height: 44px; border-radius: 14px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 16px; font-weight: 700; flex: none; background: linear-gradient(135deg, #6D5CF6, #5145E5); }
.im-avatar.c1 { background: linear-gradient(135deg, #F0A05A, #DE7B4B); }
.im-avatar.c2 { background: linear-gradient(135deg, #4FB6A8, #159B8C); }
.im-avatar.c3 { background: linear-gradient(135deg, #E4738E, #C64C75); }
.im-avatar.c4 { background: linear-gradient(135deg, #6C8CE0, #425EC4); }
.im-avatar.c5 { background: linear-gradient(135deg, #9B7CE8, #7551D6); }
.im-avatar.sm { width: 34px; height: 34px; border-radius: 11px; font-size: 12px; }

.im-empty { padding: 38px 20px; text-align: center; color: var(--text-3); }
.im-empty .im-ic { width: 34px; height: 34px; margin-bottom: 10px; opacity: .55; }
.im-empty strong { display: block; font-size: 14px; color: var(--text-2); margin-bottom: 6px; }
.im-empty small { font-size: 11.5px; line-height: 1.7; }

.im-note { display: flex; gap: 10px; padding: 13px 15px; border-radius: 12px; background: var(--surface-2); color: var(--text-2); font-size: 11.5px; line-height: 1.8; margin-bottom: 16px; }
.im-note .im-ic { margin-top: 2px; color: var(--brand); }
.im-note.warn { background: color-mix(in srgb, var(--warn) 11%, transparent); }
.im-note.warn .im-ic { color: var(--warn); }

.im-bubble { max-width: 76%; padding: 10px 13px; border-radius: 14px 14px 14px 4px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; line-height: 1.7; }
.im-bubble.me { margin-left: auto; border-radius: 14px 14px 4px 14px; background: var(--brand); color: #fff; border-color: transparent; }
.im-bubble small { display: block; font-size: 10px; opacity: .7; margin-top: 5px; }
.im-bubble.reply { border-left: 3px solid var(--brand); background: var(--surface-2); font-size: 11.5px; color: var(--text-2); margin-bottom: 8px; }

.im-input, .im-textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface); color: var(--text); padding: 10px 12px; font-size: 13px; outline: none;
}
.im-input:focus, .im-textarea:focus { border-color: var(--brand); }
.im-textarea { min-height: 88px; resize: vertical; line-height: 1.7; }
.im-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-2); margin: 0 0 6px; }
.im-field { margin-bottom: 14px; }
.im-btn { height: 38px; padding: 0 17px; border-radius: 10px; background: var(--brand); color: #fff; font-size: 13px; font-weight: 650; display: inline-flex; align-items: center; gap: 7px; }
.im-btn.ghost { background: var(--surface); color: var(--text-2); border: 1px solid var(--border); }
.im-btn.danger { background: color-mix(in srgb, var(--up) 12%, transparent); color: var(--up); border: 1px solid color-mix(in srgb, var(--up) 30%, transparent); }
.im-btn:hover { filter: brightness(1.05); }
.im-btn:disabled { opacity: .5; cursor: not-allowed; }

.im-bar { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 9px; }
.im-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand), var(--brand-2)); }

.im-kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.im-kv > div { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.im-kv > div span { color: var(--text-3); flex: none; }
.im-kv > div b { font-weight: 600; text-align: right; word-break: break-all; }

/* 二级页「全部功能」补充区 */
.im-extra { margin-top: 26px; padding-top: 8px; }
.im-extra-h { display: flex; align-items: baseline; gap: 10px; margin: 20px 0 12px; }
.im-extra-h h2 { font-size: 16px; font-weight: 700; }
.im-extra-h span { font-size: 11.5px; color: var(--text-3); }

/* 主 Tab 注入条 */
.im-chatbar { display: flex; align-items: center; gap: 8px; padding: 12px 14px 4px; }
.im-chatbar .im-conn { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--ok); font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; }
.im-chatbar .im-conn i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); animation: im-pulse 2s infinite; }
.im-chatbar button { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); color: var(--text-2); }
.im-chatbar button:hover { color: var(--brand); }
.im-folder-chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 14px 10px; scrollbar-width: none; }
.im-folder-chips::-webkit-scrollbar { display: none; }
.im-folder-chips button { white-space: nowrap; height: 27px; padding: 0 11px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.im-folder-chips button.active { background: var(--brand); color: #fff; }
.im-launch { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 4px 0 20px; }
.im-launch.compact { gap: 6px; margin: 0 0 10px; }
.im-launch.compact button { flex-direction: row; justify-content: center; gap: 5px; padding: 8px 4px; font-size: 11px; border-radius: 10px; white-space: nowrap; }
@media (max-width: 767px) { .im-launch.compact button { font-size: 10px; gap: 4px; padding: 8px 2px; } }
.im-launch.compact .im-launch-ic { width: 22px; height: 22px; border-radius: 7px; }
.im-launch.compact .im-launch-ic .im-ic { width: 14px; height: 14px; }
.im-launch button { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; padding: 13px 10px; display: flex; flex-direction: column; align-items: center; gap: 7px; color: var(--text); font-size: 12px; font-weight: 600; }
.im-launch button:hover { border-color: var(--brand); color: var(--brand); }
.im-launch .im-launch-ic { width: 36px; height: 36px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); display: flex; align-items: center; justify-content: center; }
.im-more-tools { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.im-more-tools button { height: 28px; padding: 0 10px; border-radius: 8px; font-size: 11px; color: var(--text-2); background: var(--surface-2); display: inline-flex; align-items: center; gap: 5px; }
.im-more-tools button:hover { color: var(--brand); }

/* 扫码取景框 / 拨号盘 / 二维码 */
.im-camera { position: relative; height: 260px; border-radius: 16px; background: radial-gradient(circle at 50% 40%, #2C3550, #10141F); overflow: hidden; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.im-camera-frame { width: 168px; height: 168px; border: 1px solid rgba(255,255,255,.35); border-radius: 14px; position: relative; }
.im-camera-frame::before, .im-camera-frame::after { content: ""; position: absolute; width: 22px; height: 22px; border: 3px solid var(--brand-2); }
.im-camera-frame::before { top: -3px; left: -3px; border-right: 0; border-bottom: 0; border-radius: 12px 0 0 0; }
.im-camera-frame::after { bottom: -3px; right: -3px; border-left: 0; border-top: 0; border-radius: 0 0 12px 0; }
.im-camera-line { position: absolute; left: 8%; right: 8%; height: 2px; background: linear-gradient(90deg, transparent, #9B8DFF, transparent); box-shadow: 0 0 12px #9B8DFF; animation: im-scan 2.6s linear infinite; }
.im-qr-grid { display: grid; grid-template-columns: repeat(21, 1fr); gap: 1px; width: 210px; height: 210px; padding: 10px; background: #fff; border-radius: 12px; margin: 0 auto; }
.im-qr-grid i { background: #fff; }
.im-qr-grid i.on { background: #161B22; }
.im-dial { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 280px; margin: 0 auto; }
.im-dial button { height: 56px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); font-size: 20px; font-weight: 600; color: var(--text); }
.im-dial button small { display: block; font-size: 9px; color: var(--text-3); letter-spacing: 1px; font-weight: 500; }
.im-dial button:hover { border-color: var(--brand); color: var(--brand); }

.im-moment { display: flex; gap: 12px; padding: 15px; border-bottom: 1px solid var(--border); }
.im-moment:last-child { border-bottom: 0; }
.im-moment-body { flex: 1; min-width: 0; }
.im-moment-body strong { font-size: 13px; }
.im-moment-body p { font-size: 13px; line-height: 1.75; margin-top: 5px; }
.im-moment-body time { display: block; font-size: 10.5px; color: var(--text-3); margin-top: 7px; }
.im-moment-acts { display: flex; gap: 14px; margin-top: 9px; }
.im-moment-acts button { font-size: 11px; color: var(--text-3); display: inline-flex; align-items: center; gap: 5px; }
.im-moment-acts button.liked { color: var(--up); }
.im-photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 9px; }
.im-photo-grid span { height: 76px; border-radius: 8px; background: linear-gradient(135deg, var(--brand-soft), var(--surface-3)); display: flex; align-items: center; justify-content: center; color: var(--brand); font-size: 10px; }

.im-media-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.im-media-grid span { aspect-ratio: 1; border-radius: 9px; background: linear-gradient(135deg, var(--brand-soft), var(--surface-3)); display: flex; align-items: center; justify-content: center; color: var(--brand); }

/* ---------- 3.5 主 Tab 头部：去掉「全局工具条」观感，改为页面专属标题 ---------- */
html:not([data-immersive="1"]) .topbar {
  border-bottom: 0; background: transparent; box-shadow: none;
  min-height: 68px;
}
html:not([data-immersive="1"]) .top-title { font-size: 19px; font-weight: 700; letter-spacing: -.3px; }
html:not([data-immersive="1"]) .global-search { border: 1px solid var(--border); background: var(--surface); }
html:not([data-immersive="1"]) .view-head h1 { font-size: 23px; }
html[data-fs="s"] body { font-size: 12px; }
html[data-fs="l"] body { font-size: 16px; }
html[data-fs="xl"] body { font-size: 18px; }
html[data-fs="s"] .im-pbody, html[data-fs="l"] .im-pbody, html[data-fs="xl"] .im-pbody { font-size: inherit; }

/* ---------- 4. 响应式 ---------- */
@media (max-width: 767px) {
  html[data-immersive="1"] .view { padding: 0 14px 48px; }
  .im-head, .im-phead { margin: 0 -14px; padding: 8px 14px; }
  .im-pbody { padding: 16px 14px 64px; }
  .im-head-acts .im-head-btn span { display: none; }
  .im-grid.g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .im-grid.g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .im-launch { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
  .im-launch button { padding: 10px 4px; font-size: 10px; }
  .im-launch .im-launch-ic { width: 32px; height: 32px; }
  .im-kv { grid-template-columns: 1fr; }
  .im-media-grid { grid-template-columns: repeat(3, 1fr); }
}
