/* ==========================================================================
   蜜雪AI哨兵 · 响应式重排
   断点：≥1440 完全照设计稿 → 1024–1439 收窄 → 768–1023 抽屉化 → <768 手机
   配色、圆角、字重、语义色在所有断点保持不变，只压字号与间距。
   ========================================================================== */

/* ==========================================================================
   ≤1439：设计稿 1440 之下的等比压缩
   ========================================================================== */

@media (max-width: 1439px) {
  .sidebar { width: 216px; padding: 18px 14px; }
  .content { padding: 22px 22px 26px; }
  .ai-card { padding: 10px 11px; }
}

/* 760–1439 之间：AI 矩阵与统计栅格维持比例，仅靠 fr 收缩 */

@media (max-width: 1180px) {
  .ai-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .advice-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* 在线状态：5 列降为 4 列（每个 chip 变窄，名字还有省略号兜底） */
  .online-chips { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ==========================================================================
   ≤1023：侧边栏折叠为顶栏 + 抽屉，多栏一律单列
   ========================================================================== */

@media (max-width: 1023px) {
  .app { display: block; }

  /* ---- 顶栏 ---- */
  .topbar {
    display: flex; align-items: center; gap: 10px;
    position: sticky; top: 0; z-index: 80;
    height: 56px; padding: 0 12px;
    background: var(--c-white);
    border-bottom: 1px solid var(--c-line);
  }
  .topbar__btn {
    width: 38px; height: 38px; flex: none;
    border-radius: 9px; display: grid; place-items: center;
    color: var(--c-t1);
  }
  .topbar__btn:hover { background: var(--c-bg-page); }
  .topbar__btn.btn--patrol { background: var(--c-brand); color: var(--c-white); }
  .topbar__title { flex: 1; text-align: center; font-size: var(--fs-15); font-weight: var(--fw-semibold); }

  /* ---- 侧边栏抽屉 ---- */
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 95;
    width: 264px; height: 100dvh; padding: 20px 16px;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 0 1px var(--c-line);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .sidebar__spacer { min-height: 32px; }

  .content { padding: 18px 18px 24px; }
  .view { gap: 16px; }
  .col { gap: 14px; }

  /* ---- 栅格：全部单列 ---- */
  .cols--dash,
  .cols--settings,
  .cols--pair,
  .cols--error { grid-template-columns: minmax(0, 1fr); }

  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* ---- 报告目录：窄屏改单行横滑（横向条本身已是通用形态，见 app.css） ---- */
  .toc { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .toc__item { flex: none; }

  /* ---- 页头换行 ---- */
  .page-header { flex-wrap: wrap; }
  .page-header__actions { margin-left: auto; }
}

/* ==========================================================================
   ≤767：手机
   ========================================================================== */

@media (max-width: 767px) {
  .content { padding: 14px 14px 22px; }
  .view { gap: 14px; }

  /* 巡检弹窗的 AI 进度：两列在手机上太挤，退回一列 */
  .patrol-ais { grid-template-columns: minmax(0, 1fr); }
  .patrol-ai__name { width: 100px; }

  /* ---- 字号与内边距降级（配色与圆角不动） ---- */
  .page-title { font-size: 21px; line-height: 31px; }
  .page-header--stacked .page-title { font-size: 20px; line-height: 28.5px; }
  .page-sub { font-size: var(--fs-11); }
  .banner { padding: 10px 12px; border-radius: 10px; font-size: var(--fs-115); }
  .banner__tail { display: none; }

  .card { padding: 14px; border-radius: 12px; gap: 11px; }
  .card__head--pad { padding: 14px 14px 10px; }
  .card__title--lg { font-size: var(--fs-135); line-height: 24px; }

  .stat-card { padding: 13px; border-radius: 12px; gap: 7px; }
  .stat-card__value { font-size: var(--fs-22); line-height: 33px; }
  .stat-card__row { height: 28px; }

  /* ---- 栅格 ---- */
  .stat-row { gap: 12px; }
  .summary-strip { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .summary-strip__cell { padding: 10px 12px; }
  .summary-strip__value { font-size: var(--fs-20); line-height: 26.5px; }

  .ai-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  /* 在线状态：窄屏 2 列，标签挪到上方不再占左侧定宽 */
  .online-group { flex-direction: column; align-items: stretch; gap: 8px; }
  .online-group__label { width: auto; height: auto; }
  .online-chips { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tier { padding: 10px 14px 14px; }
  .metric-band { gap: 10px; }
  .advice-row { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .est-row { gap: 10px; }
  .est-cell { padding: 10px; }
  .form__row { grid-template-columns: minmax(0, 1fr); }

  /* ---- 九字段：竖排信息行 ---- */
  .field-grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .field-cell { flex-direction: row; align-items: baseline; justify-content: space-between; gap: 12px; min-height: 0; padding: 10px 12px; }
  .field-cell__k { flex: none; }
  .field-cell__v { text-align: right; }

  /* ---- 表格转卡片式列表 ---- */
  .table-wrap { overflow-x: visible; }
  .table, .table tbody, .table tr, .table td { display: block; width: auto; }
  .table thead { display: none; }
  .table th, .table td { width: auto !important; padding-left: 0; padding-right: 0; }
  .table tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--c-line-light);
    background: none !important;
  }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
    padding: 3px 0; border: 0; text-align: right;
  }
  .table td::before {
    content: attr(data-label);
    flex: none; font-size: var(--fs-115); font-weight: var(--fw-regular); color: var(--c-t5);
  }
  .table td:first-child { font-weight: var(--fw-semibold); }
  .table--compare td:first-child { font-weight: var(--fw-medium); }
  .table-foot-link { height: 40px; }

  /* ---- 纠偏时间线改竖排 ---- */
  .timeline { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .timeline__step { flex-direction: row; align-items: center; gap: 10px; padding: 0; }
  .timeline__step::before { display: none; }
  .timeline__name, .timeline__time { text-align: left; }
  .timeline__name { flex: 1; }
  .curve svg { height: 92px; }

  /* ---- 卡片头在窄屏允许换行 ---- */
  .card__head { flex-wrap: wrap; gap: 6px 10px; }

  .report-meta { padding: 13px 14px; border-radius: 12px; }
  .report-meta__row { gap: 8px; }
  .track-list__item, .rel-row { padding: 12px 14px; }
  .archive { padding: 0 14px 14px; }
  .cite, .cited { padding: 9px 10px; }
  .quote { padding: 10px 12px; }
  .quote--danger .quote__text { font-size: var(--fs-13); }

  .btn { padding: 0 14px; }
  .btn--block { height: 36px; }

  /* ---- 弹窗改全宽底部抽屉 ---- */
  .modal { align-items: flex-end; padding: 0; }
  .modal__panel {
    width: 100%; max-width: 100%;
    max-height: 92dvh; overflow-y: auto;
    border-radius: var(--r-modal) var(--r-modal) 0 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  }
  .modal__foot { flex-direction: column-reverse; align-items: stretch; gap: 10px; }
  .modal__foot-note { text-align: center; order: 2; }
  .modal__btns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .modal__btns .btn { padding: 0 8px; font-size: var(--fs-12); }
}

/* 超窄机型：AI 卡改为单列，两个数字块并排 */
@media (max-width: 419px) {
  .ai-grid { grid-template-columns: minmax(0, 1fr); }
  .stat-row { grid-template-columns: minmax(0, 1fr); }
  .metric-band { grid-template-columns: minmax(0, 1fr); }
  .est-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .btn-row { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   打印：输出报告时去掉外壳与交互装饰
   ========================================================================== */

@media print {
  .sidebar, .topbar, .scrim, .modal, .toast, .page-header__actions, .toc { display: none !important; }
  .app { display: block; }
  .content { max-width: none; padding: 0; }
  .view { gap: 12px; }
  .card, .stat-card, .report-meta { break-inside: avoid; }
}
