/* 金潮客服后台 · 手机端适配层
   只在窄屏（<=820px）生效，桌面端不受影响。
   依赖结构：n-layout-sider(240) + n-layout > header + content > .conversation-page
   语法保持保守（无 flex gap 依赖、无 inset/100dvh 硬依赖），兼容老浏览器。 */

/* ---------- 基础：桌面隐藏注入的按钮 ---------- */
#kf-menu-btn,
#kf-back-btn,
#kf-contact-btn,
#kf-drawer-backdrop {
  display: none;
}

@media (max-width: 820px) {
  html,
  body {
    overflow-x: hidden;
  }

  /* ---------- 1) 左侧菜单：固定侧栏 -> 抽屉 ---------- */
  aside.n-layout-sider {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px !important;
    max-width: 84vw !important;
    z-index: 1301;
    background: #fff;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 2px 0 14px rgba(0, 0, 0, 0.14);
  }
  body.kf-drawer-open aside.n-layout-sider {
    transform: translateX(0);
  }
  body.kf-drawer-open {
    overflow: hidden;
  }
  .n-layout-toggle-button,
  .n-layout-sider__border {
    display: none !important;
  }

  #kf-drawer-backdrop {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1300;
    background: rgba(0, 0, 0, 0.42);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
  }
  body.kf-drawer-open #kf-drawer-backdrop {
    opacity: 1;
    visibility: visible;
  }

  /* ---------- 2) 顶栏 ---------- */
  .n-layout-header {
    padding-left: 4px !important;
    padding-right: 8px !important;
  }
  .n-layout-header .n-breadcrumb {
    font-size: 15px;
  }

  #kf-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    margin-right: 4px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #333639;
    cursor: pointer;
  }
  #kf-menu-btn:active {
    background: #f0f0f0;
  }

  /* ---------- 3) 内容区留白 ---------- */
  .n-layout-content {
    padding: 8px !important;
  }

  /* ---------- 4) 会话页：列表 / 聊天 两屏切换 ---------- */
  .conversation-page {
    position: relative !important;
    height: calc(100vh - 4.4rem) !important;
  }

  /* 会话列表占满整屏 */
  .conversation-page > *:nth-child(1) {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    border-right: 0 !important;
  }

  /* 聊天区：默认在右侧屏幕外，选中会话后滑入 */
  .conversation-page > *:nth-child(2) {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100% !important;
    max-width: 100% !important;
    background: #fff;
    z-index: 2;
    transform: translateX(103%);
    transition: transform 0.2s ease;
  }
  .conversation-page.has-selection:not(.m-back) > *:nth-child(2) {
    transform: translateX(0);
  }

  /* 会话列表里的筛选行：窄屏可横向滑动 */
  .conversation-page > *:nth-child(1) .n-radio-group {
    display: flex;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 消息区留白收窄一点，气泡更宽 */
  .conversation-page .p-4.space-y-3 {
    padding: 10px !important;
  }

  /* 聊天区顶部：返回键 */
  .conversation-page > *:nth-child(2) > .h-12 {
    height: auto !important;
    min-height: 48px;
    padding: 5px 6px !important;
    flex-wrap: wrap !important;
  }
  .conversation-page > *:nth-child(2) > .h-12 > * {
    min-width: 0;
    overflow: hidden;
  }
  .conversation-page > *:nth-child(2) > .h-12 > *:last-child {
    margin-top: 2px;
  }
  .conversation-page > *:nth-child(2) > .h-12 span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    vertical-align: middle;
  }
  .conversation-page > *:nth-child(2) > .h-12 .n-tag {
    max-width: 46vw;
    overflow: hidden;
  }
  .conversation-page > *:nth-child(2) > .h-12 .n-tag .n-tag__content {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #kf-back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    margin-right: 4px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #333639;
    cursor: pointer;
  }
  #kf-back-btn:active {
    background: #f0f0f0;
  }

  /* 聊天区顶部：访客信息按钮 */
  #kf-contact-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    min-width: 34px;
    margin-right: 4px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #333639;
    cursor: pointer;
  }
  #kf-contact-btn:active {
    background: #f0f0f0;
  }

  /* ---------- 5) 访客信息：底部抽屉 ---------- */
  .conversation-page > .conversation-contact-panel {
    position: absolute;
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 68vh;
    z-index: 4;
    background: #fff;
    border-left: 0 !important;
    border-top: 1px solid #efeff5;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.16);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(112%);
    transition: transform 0.24s ease;
  }
  .conversation-page.m-contact > .conversation-contact-panel {
    display: block !important;
    transform: translateY(0);
  }

  /* ---------- 6) 触摸目标 ---------- */
  .n-button {
    min-height: 36px;
  }
  .n-button--tiny-type {
    min-height: 30px;
    padding-left: 8px;
    padding-right: 8px;
  }
  .n-button--small-type {
    min-height: 32px;
  }
  .n-radio-button {
    min-height: 34px;
    line-height: 34px;
  }
  input.n-input__input-el,
  textarea.n-input__textarea-el {
    font-size: 16px !important;
  }

  /* ---------- 7) 表格 / 弹窗 ---------- */
  .n-data-table-base-table-body,
  .n-scrollbar-container,
  .n-layout-content {
    -webkit-overflow-scrolling: touch;
  }
  /* 表格里的行内操作按钮（编辑/删除等）：窄屏也要点得到 */
  .n-data-table .n-button--small-type,
  .n-data-table .n-button--tiny-type {
    min-width: 40px;
    min-height: 32px;
    padding-left: 6px;
    padding-right: 6px;
  }
  .n-pagination .n-pagination-item {
    min-width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .n-card__content {
    padding: 12px !important;
  }
  .n-modal {
    width: calc(100vw - 20px) !important;
    max-width: 520px !important;
  }
  .n-modal .n-card__content {
    max-height: 66vh;
    overflow-y: auto;
  }
}
