/* Mobile workspace additions stay absent from the desktop layout. */
.mobile-workspace-nav,
.mobile-invite-button,
.mobile-composer-more,
.mobile-composer-tools {
  display: none;
}
.chat-header-mode-label { display: none; }
.mobile-account-return { display: none; }

@media (max-width: 768px) {
  #chat-container .chart-result {
    box-sizing: border-box;
    padding: 20px;
  }

  #chat-container .chart-result > [id^="echarts-"]:not([data-chart-layout="multi"]),
  #chat-container .chart-result > [id^="echarts_"]:not([data-chart-layout="multi"]),
  #chat-container .chart-result .qa-chat-chart {
    height: clamp(340px, 90vw, 400px) !important;
    min-height: 340px !important;
  }
  html {
    --mobile-nav-height: 56px;
    /* Keep a small home-indicator cushion without leaving a large blank strip. */
    --mobile-safe-bottom: max(4px, calc(env(safe-area-inset-bottom, 0px) - 10px));
    --mobile-nav-space: calc(var(--mobile-nav-height) + var(--mobile-safe-bottom));
  }

  html body,
  html.wx-miniprogram body {
    position: fixed;
    top: var(--mobile-workspace-offset-top, 0px);
    left: 0;
    width: 100%;
    height: var(--mobile-workspace-height, 100dvh);
    overflow: hidden;
  }

  /* The mini-program's fixed body uses layout-viewport coordinates. Follow
     the visible viewport when iOS pans it to reveal the focused editor. */
  html.wx-miniprogram body {
    top: var(--mobile-workspace-offset-top, 0px);
    bottom: auto;
  }

  body > .flex.flex-col.h-screen { height: 100%; min-height: 0; }

  html .content-wrapper,
  html.wx-miniprogram .content-wrapper {
    box-sizing: border-box;
    width: 100%;
    height: 100% !important;
    min-height: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: var(--mobile-nav-space) !important;
    background: #fff !important;
  }

  .chat-area,
  .right-panel-container,
  .main-content {
    min-height: 0;
    min-width: 0;
  }

  .right-panel-container { flex: 1 1 0%; }
  /* Bottom navigation replaces the desktop workspace tab strip on phones. */
  html #right-panel > .panel-header { display: none !important; }

  /* Child pages keep a local way back even without desktop tabs. */
  .cached-panel-frame.account-child-page, .mobile-detail-page { flex-direction: column; min-height:0; }
  .mobile-detail-page:not([hidden]) { display:flex; }
  .account-child-page > .mobile-account-return,
  .mobile-detail-page > .mobile-account-return {
    display: inline-flex;
    flex: 0 0 auto;
    align-self: flex-start;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    margin: 0 8px;
    padding: 8px;
    border: 0;
    background: transparent;
    color: #475569;
    font-size: 14px;
    cursor: pointer;
  }
  .account-child-page > .mobile-account-return:focus-visible,
  .mobile-detail-page > .mobile-account-return:focus-visible { outline: 2px solid #2563eb; }
  .account-child-page > iframe, .mobile-detail-page > iframe { flex: 1 1 0%; height: 0; min-height: 0; }
  .mobile-detail-page > .receipt-report-body { flex:1; min-height:0; overflow:auto; }

  /* Collaboration is the mobile receipt entry; mascots are decorative. */
  html [data-receipts-desktop-only] { cursor: default; pointer-events: none !important; }
  html [data-receipts-desktop-only] .receipt-mascot-orbit::after,
  html [data-receipts-desktop-only] .welcome-agent-name,
  html [data-receipts-desktop-only] .chat-header-agent-name,
  html [data-receipts-desktop-only] .receipt-entry-hint { display: none !important; }

  /* The picker is a top-level mobile destination. */
  #bot-workspace:has([data-bot-picker]:not([hidden])) [data-bot-back],
  #bot-workspace:has([data-bot-picker]:not([hidden])) [data-bot-data] {
    display: none !important;
  }

  #welcome-page,
  #chat-container { min-height: 0; }

  html .chat-header {
    flex: 0 0 56px;
    height: 56px;
    min-height: 56px;
    padding-right: max(12px, env(safe-area-inset-right, 0px));
    padding-left: max(12px, env(safe-area-inset-left, 0px));
  }

  /* Keep the AUTU image and text fully opaque in every mobile state. */
  html .chat-header .chat-header-brand { opacity: 1; }

  /* In an active conversation the question title is redundant. Keep the
     header white and use the compact AUTU block to show the current
     mobile mode under the mark. The welcome state keeps its original title. */
  html body.has-active-chat .chat-header {
    background: #fff !important;
    border-bottom-color: transparent !important;
  }
  html body.has-active-chat .chat-header-title {
    position: absolute;
    top: 0;
    left: 50%;
    display: flex;
    width: auto;
    height: 56px;
    max-width: 150px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 0;
    transform: translateX(-50%);
  }
  html body.has-active-chat .chat-header-brand {
    position: static;
    display: flex;
    width: max-content;
    transform: none;
    pointer-events: none;
  }
  html body.has-active-chat .chat-header-character { width: 30px; height: 30px; }
  html body.has-active-chat .chat-header-agent-name {
    margin-top: -2px;
    padding: 0 7px 1px;
    font-size: 11px;
    line-height: 1.1;
    box-shadow: none;
  }
  html body.has-active-chat .chat-header-mode-label {
    display: block;
    max-width: 100px;
    overflow: hidden;
    color: #6b7280;
    font-size: 10px;
    line-height: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  html body.has-active-chat #current-chat-title { display: none; }

  .chat-header-title { max-width: calc(100% - 150px); }
  .chat-header .mobile-account { margin: 0; }
  .chat-header .mobile-account-toggle { display: none !important; }

  #mobile-bot-button {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    margin-left: auto;
    padding: 4px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    color: #1f2937;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
  }

  #mobile-bot-button svg { width: 36px; height: 36px; }

  html #system-pages-bar,
  html #daily-task-drawer,
  html #xunkuai-disclaimer,
  html.voice-input-mode #xunkuai-disclaimer,
  html.wx-miniprogram #xunkuai-disclaimer,
  html .composer-row > .models-container,
  html #composer-workspace-switch {
    display: none !important;
  }

  html .main-content > .bg-white {
    flex: 0 0 auto;
    padding: 0 !important;
    background: #fff !important;
  }

  html .main-content .input-container {
    width: calc(100% - 24px) !important;
    max-width: none;
    margin: 4px 12px 3px !important;
  }

  html .main-content .composer-row {
    display: flex;
    align-items: center;
    min-height: 56px;
    padding: 4px 48px !important;
    border: 1px solid #e8eaee;
    border-radius: 26px;
    background: #fff;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.03);
  }

  html .main-content .composer-row:focus-within {
    border-color: #cbd5e1;
    box-shadow: 0 0 0 2px rgba(148, 163, 184, 0.07);
  }

  #message-input {
    min-width: 0;
    width: 100%;
    min-height: 46px;
    max-height: min(144px, 30dvh);
    padding: 10px 0 !important;
    border-radius: 0;
    font-size: 16px !important;
    line-height: 26px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #message-input[data-placeholder]:is(:empty, [data-empty="true"])::before {
    top: 10px;
    right: 0;
    left: 0;
    color: #969ca6;
    font-size: 16px;
    line-height: 26px;
  }

  #message-input:not(.workflow-agent-locked)[contenteditable="true"]:is(:empty, [data-empty="true"])::before {
    content: "发消息或按住说话";
  }

  #message-input[data-mobile-placeholder]:not(.workflow-agent-locked)[contenteditable="true"]:is(:empty, [data-empty="true"])::before {
    content: attr(data-mobile-placeholder);
  }

  html #voice-input-btn,
  html.wx-miniprogram.mini-keyboard-mode #voice-input-btn {
    position: absolute !important;
    right: auto !important;
    bottom: 6px !important;
    left: 4px !important;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #000000 !important;
    font-size: 21px;
    line-height: 44px;
    text-align: center;
  }

  #mobile-composer-more {
    position: absolute;
    right: 5px;
    bottom: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #242930;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
  }

  #mobile-composer-more svg { width: 26px; height: 26px; }
  .input-container .send-button-container { display: block; right: 7px; bottom: 8px; }
  .input-container.mobile-has-draft .send-button { opacity: 1; }
  .input-container .send-button { width: 36px; height: 36px; }

  #mobile-composer-tools:not([hidden]) {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 70;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: min(300px, 100%);
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.12);
  }

  #mobile-composer-tools[hidden] { display: none !important; }
  #mobile-composer-tools > button {
    display: inline-flex;
    flex: 1 1 110px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px;
    border: 0;
    border-radius: 12px;
    background: #f5f6f8;
    color: #374151;
    font-size: 14px;
    cursor: pointer;
  }

  #file-list:not(:empty) {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 88px;
    margin-bottom: 8px;
    overflow: auto;
  }

  #mobile-workspace-nav {
    position: fixed;
    right: 0;
    bottom: var(--mobile-keyboard-inset, 0px);
    left: 0;
    z-index: 80;
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    height: var(--mobile-nav-space);
    border-top: 0;
    background: #fff;
  }

  #mobile-workspace-nav > button {
    display: flex;
    min-width: 0;
    min-height: 48px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3px 0 5px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #90969e;
    font-size: 11px;
    font-weight: 500;
    line-height: 18px;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  #mobile-workspace-nav > button svg {
    display: block;
    width: 25px;
    height: 25px;
    flex: 0 0 25px;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  #mobile-workspace-nav > button[aria-current="page"] { color: #000000; }
  #mobile-workspace-nav > button[aria-current="page"] svg { stroke-width: 2.2; }
  #mobile-workspace-nav > button:active,
  #mobile-composer-more:active { background: #eceff3; }
  #mobile-bot-button:active svg { opacity: .7; }
  #mobile-workspace-nav > button:focus-visible,
  #mobile-composer-more:focus-visible,
  #mobile-bot-button:focus-visible,
  #mobile-composer-tools > button:focus-visible { outline: 2px solid #2563eb; outline-offset: -2px; }

  #mobile-account-menu {
    position: fixed;
    top: auto;
    right: max(12px, env(safe-area-inset-right, 0px));
    bottom: calc(var(--mobile-nav-space) + var(--mobile-keyboard-inset, 0px) + 8px);
    width: min(300px, calc(100vw - 24px));
    max-height: calc(var(--mobile-workspace-height, 100dvh) - var(--mobile-nav-space) - 80px);
    overflow-y: auto;
    border-radius: 18px;
    -webkit-overflow-scrolling: touch;
  }

  /* Only the editable field opens the software keyboard. Focusing a mode
     button must not hide the menu and move that button during a touch tap. */
  body:has(.bot-chat-is-recording) #mobile-workspace-nav { display:none !important; }
  body:has(.bot-chat-is-recording) .content-wrapper { padding-bottom:0 !important; }
  html.mobile-keyboard-open #mobile-workspace-nav,
  body:has(#message-input:focus) #mobile-workspace-nav {
    display: none !important;
  }
  html.mobile-keyboard-open .content-wrapper,
  body:has(#message-input:focus) .content-wrapper {
    padding-bottom: 0 !important;
  }
  html.mobile-keyboard-open .main-content > .bg-white,
  body:has(#message-input:focus) .main-content > .bg-white {
    border-top: 0 !important;
  }

  .mobile-account-menu > button { min-height: 44px; border-radius: 10px; }
  .left-panel { bottom: 0; }
  .scroll-to-bottom { bottom: calc(var(--mobile-nav-space) + var(--mobile-keyboard-inset, 0px) + 88px); }

  /* Idle speech input shares the capsule. The existing recording overlay remains untouched. */
  html.voice-input-mode .main-content .composer-row {
    height: 56px !important;
    min-height: 56px !important;
    padding: 0 !important;
  }

  html.voice-input-mode #mobile-composer-more,
  html.voice-input-mode #mobile-composer-tools,
  html.voice-input-mode .input-container .send-button-container { display: none !important; }

  html.voice-input-mode:not(.voice-recording):not(.voice-cancel-preview) #voice-hold-area {
    position: absolute;
    inset: 0 !important;
    padding: 0 4px;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
  }

  html.voice-input-mode:not(.voice-recording):not(.voice-cancel-preview) #voice-hold-btn {
    position: absolute;
    inset: 0;
    z-index: 1;
    flex: none;
    width: 100% !important;
    height: 54px !important;
    min-height: 54px;
    margin: 0;
    padding: 0 48px;
    border-radius: 28px;
    background: transparent !important;
    font-size: 16px;
    justify-content: center;
    text-align: center;
  }

  html.voice-input-mode:not(.voice-recording):not(.voice-cancel-preview) #keyboard-mode-btn {
    order: -1;
    position: relative;
    z-index: 2;
    width: 44px !important;
    height: 44px !important;
    flex: 0 0 44px;
    border-radius: 50% !important;
    color: #000000 !important;
  }

  @media (max-height: 500px) {
    html { --mobile-nav-height: 56px; }
    #mobile-workspace-nav > button { min-height: 44px; gap: 0; padding: 0; }
    #mobile-workspace-nav > button svg { width: 22px; height: 22px; flex-basis: 22px; }
    html .main-content .input-container { margin-top: 5px !important; margin-bottom: 5px !important; }
  }
}
