/* 拟人助理 Web App — Liquid Glass 液态毛玻璃响应式样式系统 (v1.0.0) */
/* 断点 SSOT: Compact <600px | Medium 600~839px | Expanded >=840px | Wide >=1200px */
:root {
  --bg-deep: #0b0a10;
  --bg-ambient: radial-gradient(circle at 18% 12%, rgba(124, 92, 255, 0.22), transparent 48%),
    radial-gradient(circle at 82% 85%, rgba(45, 212, 191, 0.14), transparent 52%),
    linear-gradient(160deg, #0b0a10 0%, #13111c 55%, #0d0c14 100%);
  --glass-surface: rgba(24, 21, 36, 0.72);
  --glass-elevated: rgba(34, 30, 52, 0.84);
  --glass-border: rgba(198, 185, 255, 0.22);
  --glass-border-strong: rgba(198, 185, 255, 0.44);
  --text-primary: #f8f7ff;
  --text-secondary: #c4bedd;
  --text-muted: #8e87ab;
  --accent-primary: #c6b9ff;
  --accent-strong: #9f85ff;
  --accent-ink: #141122;
  --teal-glow: #5eead4;
  --amber-warn: #fbbf24;
  --danger-rose: #fb7185;
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-glass: 0 18px 42px rgba(4, 3, 10, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

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

html,
body {
  width: 100%;
  min-height: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg-deep);
  background-image: var(--bg-ambient);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    system-ui, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* 触控热区与键盘焦点可访问性基线 (Rule 21 WCAG 2.2 POUR) */
button,
.btn,
.icon-btn,
.nav-item,
.chip-btn,
select,
input[type="text"],
input[type="url"],
input[type="password"] {
  min-height: 44px;
  font-family: inherit;
  font-size: 0.92rem;
}

button,
.btn,
.icon-btn,
.nav-item,
.chip-btn {
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.16s ease, background-color 0.18s ease, border-color 0.18s ease,
    box-shadow 0.18s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--teal-glow);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.liquid-glass {
  background: var(--glass-surface);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-glass);
}

/* Qt6 Offscreen 隐藏节点 */
#canvas_gl {
  position: fixed;
  top: -9999px;
  left: -9999px;
  width: 180px;
  height: 180px;
  opacity: 0.001;
  pointer-events: none;
}

#screen {
  position: fixed;
  bottom: -9999px;
  right: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  pointer-events: none;
}

/* 主应用布局骨架 */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  padding-bottom: 84px;
}

/* 顶部全局状态栏 */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--glass-border);
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, #c6b9ff 0%, #6ee7b7 100%);
  color: #131022;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
}

.brand-text-wrap {
  min-width: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.version-pill {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(198, 185, 255, 0.16);
  color: var(--accent-primary);
  border: 1px solid rgba(198, 185, 255, 0.32);
  font-weight: 600;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 58vw;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(94, 234, 212, 0.12);
  border: 1px solid rgba(94, 234, 212, 0.35);
  color: var(--teal-glow);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal-glow);
  box-shadow: 0 0 8px var(--teal-glow);
}

.status-chip.warn {
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(251, 191, 36, 0.4);
  color: var(--amber-warn);
}

.status-chip.warn .status-dot {
  background: var(--amber-warn);
  box-shadow: 0 0 8px var(--amber-warn);
}

.pill-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 11px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
}

.pill-btn:hover {
  background: rgba(198, 185, 255, 0.18);
  border-color: var(--glass-border-strong);
}

.btn-primary {
  background: linear-gradient(135deg, #c6b9ff 0%, #a590ff 100%);
  color: var(--accent-ink);
  font-weight: 700;
  border: none;
  padding: 0 16px;
  border-radius: var(--radius-md);
  box-shadow: 0 6px 20px rgba(165, 144, 255, 0.32);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(165, 144, 255, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  padding: 0 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
}

.btn-secondary:hover {
  background: rgba(198, 185, 255, 0.16);
}

.btn-danger {
  background: rgba(251, 113, 133, 0.18);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: #fecdd3;
  padding: 0 14px;
  border-radius: var(--radius-md);
  font-weight: 600;
}

/* 主视图内容区 */
.main-content {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 12px 28px;
}

.view-panel {
  display: none;
  animation: fadeIn 0.22s ease;
}

.view-panel.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 首页英雄横幅与操作栏 */
.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
  border-radius: var(--radius-lg);
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 3px;
}

.section-desc {
  font-size: 0.83rem;
  color: var(--text-secondary);
}

/* 8 大无水印数字人角色卡片网格 */
.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 285px), 1fr));
  gap: 14px;
}

.character-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-radius: var(--radius-lg);
  padding: 14px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.character-card:hover {
  transform: translateY(-2px);
  border-color: var(--glass-border-strong);
}

.character-card.selected {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1px var(--accent-primary), var(--shadow-glass);
}

.card-top-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.avatar-thumb-wrap {
  position: relative;
  width: 68px;
  height: 84px;
  border-radius: 14px;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(15, 13, 24, 0.9);
  border: 1px solid rgba(198, 185, 255, 0.3);
}

.avatar-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(11, 10, 16, 0.85);
  color: var(--teal-glow);
  border: 1px solid rgba(94, 234, 212, 0.35);
}

.card-meta {
  min-width: 0;
  flex: 1;
}

.card-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.card-name {
  font-size: 1.04rem;
  font-weight: 700;
}

.card-en-name {
  font-size: 0.74rem;
  color: var(--accent-primary);
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(198, 185, 255, 0.14);
}

.card-role {
  font-size: 0.8rem;
  color: var(--teal-glow);
  font-weight: 600;
  margin-top: 2px;
}

.card-tagline {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 12px;
}

.tag-chip {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.tag-chip.engine-fish {
  background: rgba(198, 185, 255, 0.15);
  color: var(--accent-primary);
  border-color: rgba(198, 185, 255, 0.32);
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.card-actions .btn-call-full {
  grid-column: 1 / -1;
}

.card-sub-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.mini-action-btn {
  min-height: 44px;
  padding: 4px 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.74rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
}

.mini-action-btn:hover {
  background: rgba(198, 185, 255, 0.16);
  color: var(--text-primary);
  border-color: var(--glass-border-strong);
}

/* 底部/侧边响应式导航栏 */
.bottom-nav {
  position: fixed;
  bottom: 10px;
  left: 10px;
  right: 10px;
  z-index: 35;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border-radius: 20px;
}

.nav-item {
  min-height: 48px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.74rem;
  color: var(--text-secondary);
  padding: 4px;
}

.nav-item.active {
  background: rgba(198, 185, 255, 0.2);
  color: var(--accent-primary);
  border-color: rgba(198, 185, 255, 0.38);
  font-weight: 700;
}

/* P08 全屏沉浸式实时视频通话室 (无 iframe 单页直驱架构) */
.live-call-stage {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: radial-gradient(circle at 50% 28%, #221d38 0%, #0b0a10 75%);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.live-call-stage.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* MatesX v2 无水印 WebGL2 画布：居中人物特写渲染 */
.avatar-stage-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

#canvas_video {
  width: 100%;
  height: 100%;
  max-width: 680px;
  object-fit: cover;
  object-position: center top;
}

/* 顶部通话 HUD 胶囊 */
.call-top-hud {
  position: relative;
  z-index: 15;
  margin: 12px 12px 0;
  padding: 10px 14px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.call-persona-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.call-avatar-mini {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--accent-primary);
}

.call-name-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.call-char-name {
  font-weight: 700;
  font-size: 0.98rem;
}

.call-timer-badge {
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(94, 234, 212, 0.16);
  color: var(--teal-glow);
  border: 1px solid rgba(94, 234, 212, 0.35);
}

.call-state-text {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.call-hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.engine-telemetry-pill {
  font-size: 0.72rem;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(198, 185, 255, 0.16);
  border: 1px solid rgba(198, 185, 255, 0.35);
  color: var(--accent-primary);
}

/* 中下部实时双语/情感字幕悬浮舱 + 声波能量条 */
.call-lower-stack {
  position: relative;
  z-index: 15;
  margin: auto 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 720px;
  width: calc(100% - 24px);
  align-self: center;
}

.call-subtitle-box {
  padding: 12px 16px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.subtitle-speaker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.subtitle-speaker-tag {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--accent-primary);
  text-transform: uppercase;
}

.waveform-bars {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 16px;
}

.wave-bar {
  width: 3px;
  height: 5px;
  border-radius: 99px;
  background: var(--teal-glow);
  transition: height 0.08s ease;
}

.subtitle-live-text {
  font-size: 0.96rem;
  color: var(--text-primary);
  line-height: 1.48;
  word-break: break-word;
}

/* P09 键盘与 6 大快捷互动悬浮舱 */
.call-interactive-sheet {
  padding: 12px;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quick-action-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-chip {
  min-height: 44px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(198, 185, 255, 0.14);
  border: 1px solid rgba(198, 185, 255, 0.3);
  color: var(--text-primary);
  font-size: 0.78rem;
  font-weight: 600;
}

.quick-chip:hover {
  background: rgba(198, 185, 255, 0.28);
}

.call-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.call-text-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--glass-border);
  background: rgba(11, 10, 16, 0.65);
  color: var(--text-primary);
}

/* 通话底部主控船坞 */
.call-bottom-dock {
  padding: 10px;
  border-radius: 22px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.dock-btn {
  min-height: 48px;
  border-radius: 14px;
  padding: 6px 6px;
  font-size: 0.76rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-align: center;
}

.dock-btn.active {
  background: rgba(94, 234, 212, 0.18);
  border-color: rgba(94, 234, 212, 0.45);
  color: var(--teal-glow);
}

.dock-btn.interrupt {
  background: rgba(251, 191, 36, 0.18);
  border-color: rgba(251, 191, 36, 0.45);
  color: var(--amber-warn);
}

.dock-btn.hangup {
  background: rgba(244, 63, 94, 0.26);
  border-color: rgba(251, 113, 133, 0.55);
  color: #ffe4e6;
}

/* 通用模态抽屉 (P03 助理编辑 / P05 音色克隆 / P06 知识库 / P07 长期记忆 / P11 通话详情) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(6, 5, 12, 0.72);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-drawer {
  width: 100%;
  max-width: 640px;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: hidden;
  border-radius: var(--radius-xl);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 10px;
  flex-shrink: 0;
}

.modal-title {
  font-size: 1.08rem;
  font-weight: 700;
}

/* 表单与字段校验样式 (Rule 21 边填边校验) */
.form-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-drawer > .form-grid,
.modal-drawer > .list-stack {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.modal-drawer > div:last-child {
  flex-shrink: 0;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.field-input,
.field-select,
.field-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
  background: rgba(11, 10, 16, 0.65);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.field-textarea {
  min-height: 84px;
  resize: vertical;
}

.field-error {
  font-size: 0.76rem;
  color: var(--danger-rose);
  display: none;
}

.field-group.invalid .field-input,
.field-group.invalid .field-textarea {
  border-color: var(--danger-rose);
}

.field-group.invalid .field-error {
  display: block;
}

/* 列表卡片 (知识库、长期记忆、通话记录、设置面板) */
.list-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-card {
  padding: 14px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.list-card-body {
  flex: 1;
  min-width: 180px;
}

.list-card-title {
  font-weight: 700;
  font-size: 0.96rem;
  margin-bottom: 4px;
}

.list-card-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  word-break: break-word;
}

/* 撤销 Snackbar 与全局 Toast */
.toast-container {
  position: fixed;
  top: 70px;
  right: 14px;
  left: 14px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  max-width: 520px;
  width: 100%;
  padding: 10px 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
}

/* 宽屏桌面端 (>=840px) 自适应增强 */
@media (min-width: 840px) {
  .app-shell {
    padding-left: 96px;
    padding-bottom: 24px;
  }

  .bottom-nav {
    top: 84px;
    bottom: auto;
    left: 14px;
    right: auto;
    width: 72px;
    grid-template-columns: 1fr;
    padding: 10px 6px;
  }
}

/* 超窄屏 (<=360px, 含 320px iPhone SE) 防溢出保障 */
@media (max-width: 360px) {
  .top-header {
    padding: 8px 10px;
  }
  .brand-subtitle {
    display: none;
  }
  .card-sub-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .call-bottom-dock {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* 减弱动态效果无障碍偏好支持 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
