/**
 * 三通自适应：手机 (≤639) / 平板 (640–1023) / 桌面 (≥1024)
 * 叠在 index.css 之后加载。
 */

/* ---------- 手机 + 平板：主栏纵向堆叠，功能栏（输入区 + 底栏）全宽贴底 ---------- */
@media (max-width: 1023px) {
  .app-body {
    flex-direction: column;
    min-height: 0;
  }

  .main-chat,
  .sidebar,
  .aside-right {
    width: 100% !important;
    max-width: none !important;
    min-width: 0;
    flex: 1 1 auto;
    min-height: 0;
  }

  body.theme-warm-space .app-body.imm-mobile-view-chat .main-chat,
  body.theme-warm-space .app-body.imm-mobile-view-left .sidebar,
  body.theme-warm-space .app-body.imm-mobile-view-right .aside-right {
    display: flex !important;
    flex: 1 1 auto;
    width: 100% !important;
  }

  .chat-surface {
    width: 100%;
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .chat-peer-header,
  .chat-toolbar,
  .composer.candy-composer {
    width: 100%;
    box-sizing: border-box;
  }

  .composer-advanced {
    width: 100%;
  }

  .composer-main-row {
    width: 100%;
  }

  body.theme-warm-space .imm-mobile-tabbar {
    order: 999;
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    min-height: 52px;
    height: calc(52px + env(safe-area-inset-bottom, 0px));
    padding: 0 max(8px, env(safe-area-inset-left, 0px)) env(safe-area-inset-bottom, 0px)
      max(8px, env(safe-area-inset-right, 0px));
    box-sizing: border-box;
  }

  body.theme-warm-space .imm-mobile-tabbar button {
    min-height: 48px;
    font-size: 13px;
  }
}

/* ---------- 平板：单栏 + 底栏，输入区横向排列 ---------- */
@media (min-width: 640px) and (max-width: 1023px) {
  :root {
    --header-h: 54px;
  }

  body.theme-warm-space .app-header--immersive {
    grid-template-columns: minmax(120px, 0.9fr) minmax(180px, 1.6fr) auto;
    gap: 10px;
    padding: 0 12px 0 14px;
  }

  body.theme-warm-space .imm-header-search input {
    padding: 8px 12px 8px 34px;
    font-size: 12px;
  }

  body.theme-warm-space .imm-lang {
    display: none;
  }

  .char-item {
    min-width: 168px;
  }

  .chat-peer-header {
    flex-wrap: nowrap;
    padding: 10px 16px;
    gap: 12px;
  }

  .chat-peer-nurture-strip {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .chat-toolbar {
    padding: 8px 16px;
  }

  .composer {
    padding: 12px 16px 14px;
  }

  .msg-scroll {
    padding: 14px 18px 12px;
  }

  /* 平板功能栏：礼物 + 输入 + 重启 + 发送 同一行（窄屏再换行） */
  .candy-composer .composer-main-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
  }

  .candy-composer .composer-actions,
  body.theme-candy .candy-composer-actions {
    flex-direction: row;
    flex: 0 0 auto;
    order: 1;
  }

  .candy-composer .composer-inner {
    flex: 1 1 240px;
    min-width: 180px;
    order: 2;
  }

  .candy-composer .btn-reset-chat {
    flex: 0 0 auto;
    order: 3;
    min-width: 108px;
    height: 44px;
    width: auto;
  }

  .candy-composer .btn-send {
    order: 4;
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
  }

  .composer-scene-row {
    flex-wrap: wrap;
  }

  .gift-dialog {
    max-width: min(560px, 94vw);
  }

  .gift-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* ---------- 手机：紧凑布局，输入区网格 ---------- */
@media (max-width: 639px) {
  :root {
    --header-h: 50px;
  }

  body.theme-warm-space .app-header--immersive {
    grid-template-columns: 1fr auto;
    gap: 6px;
    padding: 0 8px 0 10px;
  }

  body.theme-warm-space .imm-header-identity,
  body.theme-warm-space .imm-header-search {
    display: none;
  }

  body.theme-warm-space .imm-header-actions {
    gap: 4px;
    width: 100%;
    justify-content: flex-end;
  }

  body.theme-warm-space .imm-lang {
    display: none;
  }

  body.theme-warm-space .imm-user-pill {
    max-width: 72px;
    font-size: 10px;
    padding: 3px 8px;
  }

  body.theme-warm-space .imm-ico-btn {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  .chat-peer-header {
    flex-wrap: wrap;
    align-items: flex-start;
    padding: 10px 12px;
    gap: 8px;
  }

  .chat-peer-left {
    flex: 1 1 calc(100% - 52px);
    min-width: 0;
  }

  .chat-peer-actions {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .chat-peer-nurture-strip {
    flex: 1 1 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 6px 8px;
    padding: 0;
  }

  .chat-peer-lv-badge {
    font-size: 12px;
  }

  .chat-peer-pack-row {
    justify-content: flex-start;
  }

  .chat-peer-title {
    max-width: 100%;
    font-size: 15px;
  }

  .chat-peer-sub {
    max-width: 100%;
    font-size: 11px;
  }

  .chat-toolbar {
    padding: 8px 10px;
  }

  .scene-char-wrap {
    margin-left: -2px;
    margin-right: -2px;
  }

  .char-list {
    gap: 6px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .char-item {
    min-width: 132px;
    max-width: 46vw;
    padding: 8px;
    gap: 8px;
    scroll-snap-align: start;
  }

  .char-avatar,
  .char-avatar-fallback {
    width: 36px;
    height: 36px;
  }

  .char-name {
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .char-role {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .msg-scroll {
    padding: 12px 12px 10px;
  }

  .msg-row {
    max-width: 100%;
    margin-bottom: 14px;
  }

  .msg-bubble {
    font-size: 14px;
    padding: 10px 12px;
  }

  .composer {
    padding: 10px 10px 12px;
  }

  .composer-advanced > summary {
    font-size: 10px;
  }

  .composer-scene-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .candy-composer .composer-main-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 8px;
    align-items: stretch;
  }

  .candy-composer .composer-actions,
  body.theme-candy .candy-composer-actions {
    grid-column: 1;
    grid-row: 1;
    flex-direction: row;
    align-self: end;
    padding-bottom: 0;
  }

  .candy-composer .composer-inner {
    grid-column: 2 / 4;
    grid-row: 1;
  }

  .candy-composer .btn-reset-chat {
    grid-column: 1 / 3;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    height: 40px;
    font-size: 11px;
  }

  .candy-composer .btn-send {
    grid-column: 3;
    grid-row: 2;
    align-self: stretch;
    width: 44px;
    height: 40px;
  }

  .composer textarea {
    min-height: 40px;
    max-height: 120px;
    padding: 10px 12px;
    font-size: 14px;
  }

  .btn-composer-ico {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  body.theme-warm-space .app-body.imm-mobile-view-left .sidebar,
  body.theme-warm-space .app-body.imm-mobile-view-right .aside-right {
    width: 100% !important;
    max-width: none !important;
  }

  .gift-dialog {
    width: 96vw;
    max-width: none;
    margin: auto 2vw;
  }

  .gift-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: min(58vh, 480px);
  }

  .gift-dialog-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .gift-tab {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .checkin-calendar {
    gap: 4px;
  }
}

/* ---------- 桌面：三栏工作台，隐藏移动底栏 ---------- */
@media (min-width: 1024px) {
  body.theme-warm-space .imm-mobile-tabbar {
    display: none !important;
  }

  body.theme-warm-space .app-body.imm-mobile-view-chat .sidebar,
  body.theme-warm-space .app-body.imm-mobile-view-chat .aside-right {
    display: flex !important;
  }

  body.theme-warm-space .app-body.imm-mobile-view-left .main-chat,
  body.theme-warm-space .app-body.imm-mobile-view-right .main-chat,
  body.theme-warm-space .app-body.imm-mobile-view-left .aside-right,
  body.theme-warm-space .app-body.imm-mobile-view-right .sidebar {
    display: flex !important;
  }

  .main-chat {
    min-width: 0;
  }

  .chat-surface {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  .composer-main-row {
    flex-wrap: nowrap;
  }

  .msg-row {
    max-width: min(720px, 72%);
  }
}

/* 横屏手机：略增消息区高度 */
@media (max-width: 639px) and (orientation: landscape) {
  .msg-scroll {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .composer textarea {
    max-height: 72px;
  }
}
