/* ─── v2.6.2 全尺寸屏幕自适应优化 ─────────────────────────────────────────────
   目标：兼容小尺寸笔记本、高 DPI 缩放、普通台式机和大屏，避免整体放大、三栏挤压、模块消失。 */
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  font-size: clamp(12px, 0.82vw, 14px);
}
#app, .app-layout {
  width: 100%;
  max-width: 100vw;
}
.main-content {
  min-width: 0;
  width: 100%;
}
.page {
  padding: clamp(14px, 1.8vw, 28px) clamp(14px, 2vw, 32px);
}
.page-header {
  margin-bottom: clamp(14px, 1.6vw, 24px);
  padding: clamp(14px, 1.3vw, 18px) clamp(14px, 1.5vw, 20px);
  border-radius: 14px;
}
.page-title {
  font-size: clamp(18px, 1.45vw, 22px);
  flex-wrap: wrap;
}
.page-desc {
  font-size: clamp(12px, 0.9vw, 13px);
}
.card, .modal-box, .chat-panel, .result-content {
  min-width: 0;
}
.card-header,
.chat-header {
  gap: 10px;
  flex-wrap: wrap;
}
.card-body {
  padding: clamp(14px, 1.35vw, 20px);
}

/* 主工作区采用可降级网格：大中屏两栏（聊天已改悬浮窗），小屏单栏。 */
.module-layout {
  grid-template-columns: minmax(300px, 0.95fr) minmax(360px, 1.6fr) !important;
  gap: clamp(14px, 1.4vw, 22px) !important;
}
.module-layout-2col {
  grid-template-columns: minmax(300px, 0.95fr) minmax(360px, 1.45fr) !important;
  gap: clamp(14px, 1.4vw, 22px) !important;
}
.settings-grid,
.system-status-grid,
.manual-upload-grid,
.params-grid {
  min-width: 0;
}
.upload-zone {
  padding: clamp(18px, 2.4vw, 32px) clamp(12px, 1.6vw, 20px);
}
.result-image-preview {
  min-width: 0;
  flex-wrap: wrap;
}
.result-image-thumb {
  width: clamp(74px, 7vw, 96px) !important;
  height: clamp(58px, 5.4vw, 72px) !important;
}
.result-image-info,
.file-name,
.history-item-info,
.push-item-info,
.kb-item-name {
  min-width: 0;
}
.chat-panel {
  max-height: min(70vh, 760px);
}
.chat-messages {
  max-height: min(48vh, 520px);
}
.modal-box {
  width: min(680px, calc(100vw - 28px)) !important;
  max-height: min(84vh, 760px) !important;
}
.toast {
  max-width: min(360px, calc(100vw - 24px)) !important;
}
.user-table-wrap,
.history-list,
.push-list,
.queue-list,
.result-content {
  overflow-x: auto;
}
.setting-input,
.form-input,
select,
textarea,
button {
  max-width: 100%;
}

@media (max-width: 1500px) {
  .module-layout {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr) !important;
  }
  .module-layout-2col {
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr) !important;
  }
}

@media (max-width: 1180px) {
  :root { --sidebar-width: 76px; }
  .sidebar {
    width: var(--sidebar-width) !important;
  }
  .sidebar-header {
    padding: 16px 10px 12px !important;
  }
  .sidebar-brand {
    justify-content: center;
  }
  .sidebar-brand-text,
  .sidebar-section-label,
  .nav-item span:not(.nav-icon),
  .user-name,
  .user-role,
  .status-text,
  .btn-logout {
    display: none !important;
  }
  .nav-item {
    justify-content: center;
    padding: 11px 8px !important;
  }
  .nav-item.active::before {
    height: 70%;
  }
  .sidebar-footer {
    padding: 12px 8px !important;
  }
  .user-info {
    justify-content: center;
  }
  .status-bar {
    justify-content: center;
    padding: 8px !important;
  }
  .module-layout,
  .module-layout-2col,
  [style*="grid-template-columns:360px 1fr"],
  [style*="grid-template-columns: 360px 1fr"] {
    grid-template-columns: 1fr !important;
  }
  .module-layout > .card:nth-child(3),
  .module-layout > * {
    grid-column: auto !important;
  }
  .settings-grid,
  .system-status-grid,
  .manual-upload-grid,
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 900px) {
  #app {
    height: 100vh;
    overflow: hidden;
  }
  .app-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100% !important;
    height: auto;
    max-height: 92px;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid rgba(6,182,212,.12);
  }
  .sidebar::before { height: 2px; }
  /* 顶栏模式下侧栏收放不适用：隐藏抽屉把手，并强制侧栏可见（覆盖收起态） */
  .sidebar-handle { display: none; }
  body.sidebar-collapsed .sidebar {
    width: 100% !important; min-width: 0 !important;
    border-bottom: 1px solid rgba(6,182,212,.12) !important;
  }
  .sidebar-header,
  .sidebar-footer {
    display: none !important;
  }
  .sidebar-section {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px !important;
    flex-shrink: 0;
  }
  .nav-item {
    min-width: 56px;
    margin-bottom: 0 !important;
  }
  .main-content {
    height: calc(100vh - 70px);
  }
  .page {
    padding: 12px;
  }
  .page-header {
    padding: 12px;
  }
  .card-header {
    padding: 12px 14px;
  }
  .result-style-toolbar {
    width: 100%;
    justify-content: flex-start;
  }
  .result-style-toolbar select {
    max-width: none;
    flex: 1;
  }
  .chat-panel {
    max-height: none;
  }
  .chat-messages {
    max-height: 280px;
  }
}

@media (max-width: 640px) {
  body { font-size: 12px; }
  .login-left { display: none; }
  .login-right {
    width: 100% !important;
    padding: 32px 20px !important;
  }
  .page-title {
    font-size: 17px;
  }
  .module-title-icon {
    width: 24px;
    height: 24px;
  }
  .card-body {
    padding: 12px;
  }
  .file-preview,
  .result-image-preview,
  .history-item,
  .push-item,
  .queue-item {
    align-items: flex-start;
  }
  .result-image-switcher {
    width: 100%;
  }
  #img-lightbox img {
    max-width: 96vw;
    max-height: 82vh;
  }
  #img-lightbox .lb-close {
    top: 12px;
    right: 12px;
  }
}


/* ─── v2.6.2 阶段4：小屏可用性细节修复 ─────────────────────────────────────
   修正 901-1180px 图标侧栏文字竖排、窄屏按钮挤压、表格/弹窗底部按钮不换行等问题。 */
@media (min-width: 901px) and (max-width: 1180px) {
  .nav-item {
    font-size: 0 !important;
    gap: 0 !important;
  }
  .nav-item .nav-icon {
    font-size: 18px !important;
    margin: 0 !important;
  }
}

@media (max-width: 1180px) {
  .card-header .btn,
  .modal-footer .btn,
  .history-item-actions .btn,
  .queue-item-actions .btn,
  .push-item-actions .btn {
    white-space: nowrap;
  }
  .modal-footer {
    flex-wrap: wrap;
  }
  .modal-footer .btn {
    min-width: 112px;
  }
  .result-style-toolbar,
  [style*="padding:0 20px 20px;display:grid"],
  [style*="padding:0 20px 20px; display:grid"],
  [style*="display:grid;grid-template-columns:1fr 1fr;gap:10px"],
  [style*="display:grid; grid-template-columns:1fr 1fr; gap:10px"] {
    min-width: 0 !important;
  }
}

@media (max-width: 900px) {
  .sidebar .nav-item {
    font-size: 13px !important;
    gap: 6px !important;
    white-space: nowrap;
  }
  .sidebar .nav-icon {
    font-size: 15px !important;
  }
  .history-table,
  .user-table {
    min-width: 680px;
  }
  .modal-body {
    padding: 16px !important;
  }
  .modal-footer {
    justify-content: stretch !important;
  }
  .modal-footer .btn {
    flex: 1 1 140px;
  }
}

@media (max-width: 640px) {
  .card-header,
  .page-header,
  .result-style-toolbar,
  .queue-item-actions,
  .history-item-actions {
    align-items: flex-start;
  }
  .card-header .btn,
  .result-style-toolbar > *,
  .setting-item .btn {
    flex: 1 1 auto;
  }
  .btn-full,
  .btn-login {
    min-height: 40px;
  }
  .toast {
    right: 12px !important;
    left: 12px !important;
    width: auto !important;
  }
}
