/* 竖版工作台收口
 * 只处理移动端的空间、触控和安全区，不改变桌面端信息架构。
 */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body,
.app-shell,
.body-wrap,
.main,
.page {
  min-width: 0;
}

.app-shell {
  min-height: 100dvh;
  overflow-x: clip;
}

.body-wrap {
  width: 100%;
  min-height: calc(100dvh - var(--topbar-h));
}

.main,
.page {
  width: 100%;
  max-width: 100%;
}

img,
svg,
canvas,
iframe,
pre {
  max-width: 100%;
}

@media (max-width: 760px) {
  :root {
    --topbar-h: 56px;
  }

  .topbar {
    height: calc(var(--topbar-h) + env(safe-area-inset-top));
    min-height: calc(var(--topbar-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 8px 0;
  }

  .topbar-left {
    flex: 1 1 auto;
    min-width: 0;
  }

  .topbar-right {
    flex: 0 0 auto;
    min-width: 0;
    gap: 2px;
  }

  .sidebar-toggle,
  .topbar-item,
  .global-search-btn,
  .account-btn {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    justify-content: center;
  }

  .brand {
    min-width: 0;
    max-width: calc(100vw - 150px);
    padding: 0 4px;
  }

  .brand-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
  }

  .brand-tag,
  .topnav,
  #ai-chip,
  #offline-toggle,
  .search-shortcut,
  #account-name,
  .account-btn > svg {
    display: none !important;
  }

  .main {
    padding: 16px 12px calc(96px + env(safe-area-inset-bottom));
  }

  .page-head {
    width: 100%;
    gap: 10px;
    margin-bottom: 16px;
  }

  .page-head > div {
    width: 100%;
  }

  .page-head > div:last-child {
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }

  .page-title {
    font-size: clamp(22px, 7vw, 28px);
    line-height: 1.22;
    overflow-wrap: anywhere;
  }

  .page-sub {
    overflow-wrap: anywhere;
  }

  .card,
  .col-panel,
  .q-card,
  .wrong-card,
  .knowledge-card,
  .corpus-card,
  .queue-card,
  .guide-step,
  .paper-col,
  .paper-panel {
    max-width: 100%;
  }

  .workspace-hero {
    min-height: 0;
    padding: 28px 20px 24px;
    border-radius: 22px;
  }

  .workspace-hero h1 {
    max-width: 100%;
    font-size: clamp(30px, 9vw, 38px);
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .workspace-hero p {
    max-width: 100%;
    line-height: 1.7;
  }

  .workspace-actions {
    width: 100%;
    gap: 8px;
  }

  .workspace-actions .btn {
    min-height: 44px;
    width: 100%;
  }

  .workspace-status {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: -10px 8px 18px;
    gap: 6px;
  }

  .workspace-status > span {
    min-width: 0;
    min-height: 36px;
    justify-content: center;
    padding: 5px 8px;
    text-align: center;
    line-height: 1.35;
  }

  .workspace-status > span:last-child {
    grid-column: 1 / -1;
  }

  .workspace-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 24px;
  }

  .metric-card {
    min-width: 0;
  }

  .capability-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .capability-card {
    min-height: 0;
    padding: 18px;
  }

  .capability-card p {
    min-height: 0;
    max-width: 100%;
  }

  .evidence-flow {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 16px;
  }

  .evidence-flow > i {
    justify-self: center;
    transform: rotate(90deg);
  }

  .research-layout {
    grid-template-columns: 1fr;
  }

  .module-toolkit {
    padding: 14px;
  }

  .module-toolkit-head {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .module-productivity {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .module-productivity button {
    width: 100%;
    min-width: 0;
    min-height: 42px;
    justify-content: center;
    padding: 0 6px;
    font-size: 10.5px;
  }

  .module-shortcuts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
  }

  .module-shortcuts button {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 0 9px;
    white-space: normal;
    line-height: 1.35;
  }

  .module-shortcuts button span {
    flex: 0 0 28px;
  }

  .today-plan-head,
  .card-heading {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .today-plan-form {
    align-items: stretch;
  }

  .today-plan-form .input {
    min-width: 0;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    min-height: calc(70px + env(safe-area-inset-bottom));
    padding: 6px 6px env(safe-area-inset-bottom);
    background: rgba(249, 249, 249, .92);
    border-top: 1px solid rgba(60, 60, 67, .13);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
  }

  .mobile-nav-item {
    min-width: 0;
    min-height: 54px;
    padding: 4px 2px;
    font-size: 10px;
  }

  .toast-wrap {
    bottom: calc(86px + env(safe-area-inset-bottom));
  }

  .panel-jump {
    bottom: calc(88px + env(safe-area-inset-bottom));
  }

  .dialog-mask {
    align-items: flex-end;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .dialog {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top));
    overflow-y: auto;
    border-radius: 20px 20px 0 0;
  }

  .dialog-actions {
    position: sticky;
    bottom: -1px;
    padding-top: 10px;
    background: inherit;
  }

  .ai-workspace-dialog,
  .source-dialog,
  .announcement-center,
  .announcement-editor {
    max-height: calc(100dvh - 16px - env(safe-area-inset-top));
  }

  .ai-task-options {
    grid-template-columns: 1fr;
  }

  .source-platforms,
  .announcement-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .source-platforms > button {
    min-height: 112px;
    padding: 11px;
  }

  .announcement-admin-item,
  .announcement-reader-head,
  .announcement-reader-foot {
    align-items: stretch;
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .announcement-admin-actions {
    flex-wrap: wrap;
  }

  .announcement-admin-actions .btn {
    flex: 1 1 120px;
  }
}

@media (max-width: 400px) {
  .main {
    padding-left: 10px;
    padding-right: 10px;
  }

  .workspace-hero {
    padding-left: 17px;
    padding-right: 17px;
  }

  .workspace-status {
    margin-left: 4px;
    margin-right: 4px;
  }

  .module-productivity,
  .module-shortcuts {
    grid-template-columns: 1fr;
  }

  .module-productivity button,
  .module-shortcuts button {
    justify-content: flex-start;
  }

  .source-platforms,
  .announcement-stats {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
