/* Mobile application shell. Loaded after upstream styles so the phone UI stays stable. */
@media (max-width: 720px) {
  :root {
    --mobile-bg: #f6f7f9;
    --mobile-card: #ffffff;
    --mobile-line: #e5e7eb;
    --mobile-text: #172033;
    --mobile-muted: #7b8494;
    --mobile-accent: #1677ff;
    --mobile-radius: 14px;
    --mobile-viewport-top: 0px;
    --mobile-viewport-left: 0px;
    --mobile-viewport-width: 100vw;
    --mobile-viewport-height: 100dvh;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  html,
  body {
    width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 100%;
    max-height: none;
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--mobile-bg);
  }

  body,
  button,
  input,
  textarea,
  select {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  }

  body {
    position: relative;
  }

  button,
  a,
  input,
  textarea,
  select {
    touch-action: manipulation;
  }

  .shell,
  .main,
  .transcript-panel,
  .log,
  .message,
  .bubble,
  .composer,
  .composer-main-row,
  .composer-input-wrap {
    min-width: 0;
    max-width: 100%;
  }

  .shell {
    position: absolute;
    top: var(--mobile-viewport-top);
    left: var(--mobile-viewport-left);
    display: block;
    width: var(--mobile-viewport-width);
    height: var(--mobile-viewport-height, 100dvh);
    min-height: 0;
    overflow: hidden;
  }

  .main {
    display: grid;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: 100%;
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 0;
    overflow: hidden;
    background: var(--mobile-bg);
  }

  .detail-header {
    position: relative;
    top: auto;
    z-index: 40;
    min-height: 54px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    border: 0;
    border-bottom: 1px solid var(--mobile-line);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: none;
    backdrop-filter: blur(16px);
  }

  .detail-header h2 {
    color: var(--mobile-text);
    font-size: 16px;
    font-weight: 700;
  }

  .detail-actions {
    flex: 0 0 auto;
    gap: 4px;
  }

  .detail-actions > #toggle-navigator-button,
  .detail-actions > #open-settings-button,
  .detail-actions > #resume-session-button:not(.hidden) {
    width: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: transparent;
  }

  .detail-actions > #resume-session-button:not(.hidden) {
    width: auto;
    max-width: 104px;
    padding: 0 10px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .unified-session-panel {
    min-height: 34px;
    padding: 5px 10px;
    border: 0;
    border-bottom: 1px solid #edf0f4;
    background: #fff;
  }

  #runtime-chip-row {
    gap: 5px;
  }

  #runtime-chip-row .runtime-chip {
    min-height: 24px;
    padding: 4px 8px;
    background: #f0f3f7;
    color: #566074;
    font-size: 10px;
  }

  .transcript-panel {
    display: grid;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
    background: var(--mobile-bg);
  }

  .log {
    display: flex;
    min-height: 0;
    max-height: none;
    gap: 12px;
    padding: 12px 10px 18px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    background: var(--mobile-bg);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .log:empty::before {
    content: "选择会话后即可开始";
    align-self: center;
    margin: auto;
    color: #a0a7b3;
    font-size: 14px;
  }

  .log::-webkit-scrollbar {
    display: none;
  }

  .message {
    width: auto;
    max-width: 88%;
  }

  .message.user {
    align-self: flex-end;
  }

  .message.agent,
  .message:has(.message-file-list),
  .message.thinking {
    width: 100%;
    max-width: 100%;
  }

  .message-meta {
    margin: 0 4px 4px;
    color: #a0a7b3;
    font-size: 9px;
    letter-spacing: 0.02em;
  }

  .message-toolbar {
    display: none;
  }

  .bubble {
    max-width: 100%;
    padding: 10px 12px;
    overflow-wrap: anywhere;
    border: 1px solid #e8ebf0;
    border-radius: 15px;
    background: var(--mobile-card);
    color: var(--mobile-text);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.035);
    font-size: 15px;
    line-height: 1.55;
  }

  .message.user .bubble {
    border: 0;
    border-radius: 15px 15px 4px 15px;
    background: var(--mobile-accent);
    color: #fff;
    box-shadow: none;
  }

  .message.agent .bubble,
  .message:not(.user) .bubble {
    border-radius: 15px 15px 15px 4px;
    background: #fff;
    color: var(--mobile-text);
  }

  .bubble img,
  .bubble video,
  .bubble canvas,
  .markdown-table-wrap,
  .markdown-code-card {
    max-width: 100%;
  }

  .bubble pre,
  .bubble code,
  .markdown-table-wrap {
    overflow-x: auto;
  }

  .message-file-card,
  .message-file-card.image {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 10px;
    min-height: 92px;
    padding: 7px;
    border: 1px solid #e5e9ef;
    border-radius: 13px;
    background: #fff;
    box-shadow: none;
  }

  button.message-file-preview-button,
  .message-file-preview {
    width: 84px;
    height: 76px;
    max-height: 76px;
    border-radius: 9px;
    object-fit: cover;
  }

  .message-file-name {
    display: -webkit-box;
    overflow: hidden;
    color: var(--mobile-text);
    font-size: 13px;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .message-file-path,
  .message-file-meta {
    display: none;
  }

  .message-file-actions {
    gap: 6px;
    flex-wrap: nowrap;
  }

  .message-file-actions .secondary-button {
    min-width: 54px;
    min-height: 32px;
    padding: 5px 10px;
    border: 1px solid #dde2ea;
    border-radius: 9px;
    background: #f7f8fa;
    color: #344054;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
  }

  .message-file-card.image .message-file-actions a:first-of-type {
    display: none;
  }

  .message.thinking > .message-meta {
    display: none;
  }

  .thinking-card,
  html[data-theme="minimal-light"] .thinking-card {
    border: 1px solid #e0e6e4;
    border-radius: 12px;
    background: #f9fbfa;
    box-shadow: none;
  }

  .thinking-summary,
  .thinking-card[open] .thinking-summary {
    min-height: 42px;
    align-content: center;
    gap: 0;
    padding: 8px 11px;
  }

  .thinking-title::after {
    content: "思考过程";
    font-size: 12px;
  }

  .thinking-preview,
  .thinking-note {
    display: none;
  }

  .thinking-card[open] .thinking-content {
    max-height: 46dvh;
    padding: 0 46px 10px 10px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .composer {
    position: relative;
    right: auto;
    bottom: auto;
    left: auto;
    z-index: 50;
    display: grid;
    width: 100%;
    min-width: 0;
    min-height: 66px;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: end;
    gap: 7px;
    padding: 8px 9px max(8px, env(safe-area-inset-bottom));
    border: 0;
    border-top: 1px solid var(--mobile-line);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 -3px 14px rgba(15, 23, 42, 0.05);
  }

  html.mobile-keyboard-open .detail-header {
    min-height: 46px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  html.mobile-keyboard-open .unified-session-panel {
    display: none;
  }

  html.mobile-keyboard-open .log {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  html.mobile-input-focused .composer {
    box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08);
  }

  .composer-attachment-grid {
    display: flex;
    min-width: 0;
    grid-column: 1;
    align-items: center;
  }

  .composer-attachment-grid .attachment-icon-button {
    width: 42px;
    min-width: 42px;
    height: 48px;
    min-height: 48px;
    padding: 0;
    border: 1px solid #dde2ea;
    border-radius: 14px;
    background: #fff;
    color: #344054;
    box-shadow: none;
  }

  .composer-main-row {
    display: grid;
    width: 100%;
    min-width: 0;
    grid-column: 2;
    grid-template-columns: minmax(0, 1fr) 62px;
    align-items: end;
    gap: 7px;
  }

  .composer-input-wrap {
    width: 100%;
    min-width: 0;
  }

  .composer-input-wrap textarea,
  .composer-main-row textarea,
  #input-text {
    display: block;
    width: 100%;
    min-width: 0;
    height: 48px !important;
    min-height: 48px !important;
    max-height: 112px;
    padding: 12px 13px;
    border: 1px solid #dfe3ea;
    border-radius: 14px;
    background: #f7f8fa;
    color: var(--mobile-text);
    font-size: 16px !important;
    line-height: 22px;
    resize: none;
    box-shadow: none;
  }

  .composer-input-wrap textarea::placeholder,
  #input-text::placeholder {
    color: #9aa2af;
    opacity: 1;
  }

  .composer-action-stack {
    display: flex;
    min-width: 0;
    gap: 0;
  }

  .composer-action-stack button,
  #codex-send-button {
    width: 62px;
    min-width: 62px;
    height: 48px;
    min-height: 48px;
    padding: 0 8px;
    overflow: hidden;
    border: 0;
    border-radius: 14px;
    background: var(--mobile-accent);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-shadow: none;
  }

  #codex-interrupt-button:not(.hidden) {
    width: 62px;
    min-width: 62px;
  }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 220;
    width: min(88vw, 342px);
    height: 100%;
    max-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: 0 18px 18px 0;
    background: #fff;
  }

  .conversation-card {
    min-width: 0;
    padding: 10px;
    border-radius: 12px;
  }

  .conversation-card * {
    min-width: 0;
  }

  .conversation-card-title,
  .conversation-card-path {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .settings-modal,
  .modal-card {
    max-width: calc(100vw - 16px);
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 16px);
  }
}
