/* ==================== Mobile Responsive Styles ==================== */

/* 移动端适配 - 针对平板和小屏设备 */
@media screen and (max-width: 768px) {
  /* 侧边栏响应式 */
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    height: 100vh;
    height: 100dvh; /* 修复移动端浏览器工具栏遮挡问题 */
    z-index: 999;
    transition: left 0.3s ease;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
  }

  .sidebar.show {
    left: 0;
  }

  /* 主聊天区域需要正确处理视口高度 */
  .chat-root {
    height: 100vh;
    height: 100dvh;
  }

  /* 主聊天区域占满屏幕 */
  .main {
    width: 100%;
  }

  /* 移动端上传组件适配 */
  .file-upload-progress {
    right: 16px;
    left: 16px;
    width: auto;
    bottom: 70px;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease, visibility 0s linear 0s;
  }

  .file-upload-progress.hidden {
    transform: translateY(120%);
    opacity: 0;
  }

  .file-upload-menu {
    right: 16px;
    bottom: 60px;
  }

  /* 添加汉堡菜单按钮 */
  .chat-header {
    position: relative;
  }

  .sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    margin: 0 4px 0 -8px;
    padding: 0;
    border: 0;
    color: inherit;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
  }
  .sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
  }
  .sidebar-toggle:focus-visible {
    outline: 2px solid #d1c1f2;
    outline-offset: -2px;
  }

  /* 窗口按钮在移动端隐藏 */
  .window-buttons {
    display: none;
  }

  /* 消息区域优化 */
  .messages {
    padding: 12px 0;
  }

  .message {
    padding: 8px 12px;
  }

  .message .avatar {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  /* 输入区域优化 */
  .input-area {
    padding: 12px;
  }

  .input-box {
    padding: 10px 12px;
  }

  /* 输入按钮优化为触摸友好 */
  .input-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  /* Match the original 16px Aa and its baseline without resizing the 20px SVG. */
  .composer-text-icon path {
    transform-origin: center;
    transform: translateY(-.6px) scale(calc(16 / 18));
  }

  /* 名称选择器优化 */
  .name-chooser-content {
    padding: 36px 24px;
  }
}

/* 触摸设备优化；小屏按钮在后面的断点中通过伪元素扩大点击区域。 */
@media (hover: none) and (pointer: coarse) {
  /* 增加点击区域 */
  .input-btn,
  .file-download,
  .channel,
  .voice-user {
    min-height: 44px;
  }

  /* 移除悬停效果，使用点击效果 */
  .input-btn:active {
    background: #3d3750;
    transform: scale(0.95);
  }

  .message:active {
    background: rgba(4, 4, 5, 0.1);
  }

  .name-submit:active {
    transform: scale(0.98);
  }
}

/* 移动端适配 - 针对小屏手机 */
@media screen and (max-width: 480px) {
  /* 减小字体大小 */
  .message-user {
    font-size: 14px;
  }

  .input {
    font-size: 14px;
  }

  /* 消息头部优化 */
  .message-header {
    gap: 6px;
  }

  .message-time {
    font-size: 11px;
  }

  /* 减小头像大小 */
  .message .avatar {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }

  /* 贴纸大小调整 */
  :root {
    --sticker-size: 80px;
  }

  .sticker-inline {
    height: 48px;
  }

  /* 文件附件优化 */
  .message-file {
    max-width: 100%;
  }

  .file-icon {
    width: 40px;
    height: 40px;
    font-size: 20px;
  }

  .file-name {
    font-size: 13px;
  }

  .file-size {
    font-size: 11px;
  }

  /* 输入按钮进一步优化 -- 更加紧凑且视觉上更舒适 */
  .input-area {
    padding: 8px; /* 极简的外部填充 */
    background: #50476a; /* 确保背景色不透明，遮挡底部可能的内容 */
    padding-bottom: max(8px, env(safe-area-inset-bottom)); /* 适配 iPhone X+ 底部安全区域 */
  }

  .input-box {
    padding: 6px 10px; /* 更加紧凑的内部填充 */
    gap: 8px;
    min-height: 44px; /* 保证最小触控高度 */
  }

  .input-btn {
    width: 32px; /* 较小的视觉尺寸 */
    height: 32px;
    min-height: 32px; /* 覆盖全局触摸优化 */
    font-size: 16px;
    padding: 0; /* 移除可能的内边距 */
    position: relative;
  }

  /* 增加实际点击热区但不增加视觉尺寸 */
  .input-btn::after {
    content: '';
    position: absolute;
    top: -6px; right: -6px; bottom: -6px; left: -6px;
  }

  /* 提及列表优化 */
  .mention-list {
    width: calc(100vw - 48px);
    max-width: 280px;
  }

  /* 侧边栏内容优化 */
  .voice-user-info .avatar {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .section-label {
    font-size: 11px;
  }

  /* 名称选择器进一步优化 */
  .name-chooser-content {
    padding: 24px 20px;
  }

  .name-chooser-content h2 {
    font-size: 20px;
  }

  .subtitle {
    font-size: 13px;
    margin-bottom: 24px;
  }

  .name-input {
    padding: 14px 16px;
    font-size: 15px;
  }

  .name-submit {
    padding: 14px;
    font-size: 15px;
  }

  .logo-area svg {
    width: 48px;
    height: 48px;
  }
}

/* 横屏模式优化 */
@media screen and (max-width: 768px) and (orientation: landscape) {
  .chat-root {
    height: 100vh;
    height: 100dvh;
  }

  /* 减小头部高度 */
  .chat-header,
  .server-header {
    height: 40px;
  }

  /* 减小输入区域 */
  .input-area {
    padding: 8px 12px;
  }

  .input-box {
    padding: 8px 12px;
  }
}

/* Nako 思考图标样式 */
.nako-thinking-icon {
  display: inline-block;
  margin-left: 6px;
  font-size: 14px;
  cursor: help;
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.2s;
  vertical-align: middle;
}

.nako-thinking-icon:hover {
  opacity: 0.9;
  transform: scale(1.15);
}

/* 移动端隐藏思考图标 */
@media screen and (max-width: 768px) {
  .nako-thinking-icon {
    display: none;
  }
}

/* Platform-independent interaction safeguards, including Android and Windows. */
.messages { min-height: 0; overscroll-behavior-y: contain; }
:is(.input-btn, .sidebar-toggle, .tools-menu, .settings-close) { touch-action: manipulation; transition: background 150ms, opacity 150ms; }
:is(.input-btn, .sidebar-toggle, .tools-menu, .settings-close):active { opacity: .65; transform: none; }
.input-btn:focus-visible, .input-box:has(.input:focus-visible) { outline: 2px solid rgb(var(--nc-accent)); outline-offset: 2px; }
@media (max-width: 768px), (pointer: coarse) {
  .input-btn { width: 44px; height: 44px; min-height: 44px; padding: 0; flex-shrink: 0; }
  .input-btn::after { content: none; }
  .input-box > .sekai-composer__actions { flex-shrink: 0; align-self: center; gap: 0; margin-top: 0; }
  .input { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .input-btn, .sidebar-toggle, .tools-menu, .settings-close { transition: none; }
}
