/* ===== 水多多 SaaS · 真机窄屏适配 + 统一三态组件 =====
   用法：三端在 </head> 前引入 <link rel="stylesheet" href="assets/mobile.css">
   职责：仅做 375px 真机适配与加载/空/失败三态样式，不改任何 JS 逻辑与业务布局。
   桌面端(>480px)保留 390px 手机外壳；窄屏真机铺满视口、留安全区、保证底部操作可点。 */

/* ---------- 1. 375px 真机适配 ---------- */
@media (max-width: 480px) {
  html, body {
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
    background: var(--bg, #f1f5f9) !important;
    width: 100% !important;
    overflow-x: hidden;
  }
  body { min-height: 100vh; min-height: 100dvh; }
  .phone {
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  /* 状态栏 / 底部栏留足安全区，避免刘海与 Home 指示条遮挡 */
  .statusbar { padding-top: env(safe-area-inset-top, 0) !important; }
  .tabbar { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0)) !important; }
  /* Toast 上移到安全区之上 */
  #toast, .toast, .toast-bar {
    bottom: calc(88px + env(safe-area-inset-bottom, 0)) !important;
    max-width: calc(100% - 32px) !important;
  }
  /* 关键操作按钮加大触控热区（下单/接单/取件/送达） */
  .btn, .btn.orange, .dc-primary { min-height: 44px; }
  /* 表单项在窄屏不挤压 */
  .form-grid { grid-template-columns: 1fr !important; }
}

/* ---------- 2. 统一三态组件（新增类，不覆盖页面原有 .empty） ---------- */
/* 加载态：骨架屏 */
.ui-loading { padding: 4px 0; }
.ui-skel {
  background: linear-gradient(90deg, #eef1f6 25%, #e2e8f0 37%, #eef1f6 63%);
  background-size: 400% 100%;
  animation: ui-shimmer 1.3s ease-in-out infinite;
  border-radius: 10px;
}
.ui-skel-line { height: 14px; margin-bottom: 10px; }
.ui-skel-line.short { width: 55%; }
.ui-skel-card { height: 92px; margin-bottom: 12px; }
@keyframes ui-shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* 空态 / 失败态通用容器 */
.ui-state {
  text-align: center;
  padding: 44px 20px;
  color: #64748b;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 160px;
}
.ui-state .ui-ico { font-size: 44px; line-height: 1; margin-bottom: 14px; opacity: .85; }
.ui-state .ui-title { font-size: 15px; font-weight: 600; color: #334155; margin-bottom: 6px; }
.ui-state .ui-desc { font-size: 12.5px; line-height: 1.6; color: #94a3b8; max-width: 240px; }
.ui-state .ui-btn {
  margin-top: 16px;
  border: 1px solid var(--blue, #0891B2);
  color: var(--blue, #0891B2);
  background: #fff;
  border-radius: 10px;
  padding: 9px 22px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.ui-state .ui-btn:active { opacity: .7; }
.ui-state.error .ui-ico { filter: grayscale(.2); }

/* ---------- 2b. 通用二次确认弹窗（商家批量上下架 / 骑手接单等） ---------- */
.ui-confirm-mask {
  position: fixed; inset: 0; z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(15, 23, 42, .5);
}
.ui-confirm-box {
  width: 100%; max-width: 340px; background: #fff; border-radius: 16px;
  padding: 22px 20px 18px; box-shadow: 0 12px 40px rgba(0, 0, 0, .2);
}
.ui-confirm-title { font-size: 16px; font-weight: 700; color: #1e293b; margin-bottom: 10px; }
.ui-confirm-msg { font-size: 14px; line-height: 1.6; color: #475569; margin-bottom: 20px; }
.ui-confirm-actions { display: flex; gap: 10px; }
.ui-confirm-actions .btn { flex: 1; min-height: 44px; margin: 0; }

/* ---------- 3. 图片/头像加载失败占位（全局兜底） ---------- */
img { max-width: 100%; }
.ui-img-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  background: #eef1f6; color: #94a3b8; font-size: 12px;
  border-radius: 8px; min-width: 32px; min-height: 32px; padding: 4px;
}

/* ---------- 4. 骑手端：操作热区 / 安全区 / 异常上报入口 ---------- */
@media (max-width: 480px) {
  /* 底部操作栏图标按钮热区≥44px，且不被 Home 指示条遮挡 */
  .deal-action { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0)) !important; }
  .deal-action .icon-action,
  .deal-action .dc-chat,
  .deal-action .dc-call { min-width: 44px; min-height: 44px; justify-content: center; }
  .deal-action .main-deal,
  .deal-action .dc-primary,
  .deal-action .dc-outline { min-height: 48px; }
  /* 卡片内主操作按钮热区≥44px */
  .dc-card .dc-primary, .dc-card .dc-outline { min-height: 44px; }
  /* 操作栏吸底：滚动时长驻可见，避免送达按钮被挤出视口 */
  .view:has(.deal-action) .pad { padding-bottom: 8px; }
}
/* 异常上报入口高亮（显眼位置） */
.icon-action.report-entry { color: #ef4444; }
.icon-action.report-entry svg { stroke: #ef4444; }
/* 异常上报处理后的状态条 */
.ui-report-status {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin: 10px 0;
  background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; border-radius: 10px;
  font-size: 13px; font-weight: 600;
}
.ui-report-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; flex: none; animation: pulse 1.4s infinite; }

/* ---------- 5. 商家端订单详情抽屉 ---------- */
.drawer-mask {
  position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.55);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }
.drawer-panel {
  width: 100%; max-width: 480px; max-height: 88vh; max-height: 88dvh;
  background: #fff; border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.22,.61,.36,1);
  box-shadow: 0 -8px 30px rgba(15,23,42,.18); overflow: hidden;
}
.drawer-mask.show .drawer-panel { transform: translateY(0); }
.drawer-head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px; border-bottom: 1px solid #eef1f6;
}
.drawer-head h3 { font-size: 16px; font-weight: 700; color: #1e293b; }
.drawer-close { font-size: 18px; color: #94a3b8; cursor: pointer; padding: 4px 8px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 20px; }
.drawer-foot {
  flex: none; padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid #eef1f6; background: #fff;
}
.drawer-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.drawer-sec { padding: 11px 0; border-bottom: 1px dashed #eef1f6; }
.drawer-k { font-size: 12px; color: #94a3b8; margin-bottom: 4px; }
.drawer-v { font-size: 14px; color: #334155; line-height: 1.5; }
.drawer-v.price { color: #ef4444; font-weight: 700; font-size: 16px; }
.drawer-timeline { margin: 8px 0 4px; }
.dt-item { position: relative; display: flex; gap: 12px; padding-bottom: 18px; }
.dt-item:last-child { padding-bottom: 0; }
.dt-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: #cbd5e1; margin-top: 2px; z-index: 1; }
.dt-item.done .dt-dot { background: #0891B2; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.dt-line { position: absolute; left: 5px; top: 16px; bottom: 0; width: 2px; background: #e2e8f0; }
.dt-item.done .dt-line { background: #93c5fd; }
.dt-label { font-size: 13.5px; font-weight: 600; color: #334155; }
.dt-item:not(.done) .dt-label { color: #94a3b8; }
.dt-time { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.dt-item.done .dt-time { color: #64748b; }
.drawer-foot .btn { min-height: 44px; }
.drawer-foot .btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- 6. 真机尺寸回归：375x667 / 390x844 / 横屏 844x390 ---------- */
/* 竖屏窄机（375/390）：外壳完全铺满，内容区可滚动，底部栏不遮挡 */
@media (max-width: 480px) and (orientation: portrait) {
  html, body { overflow-x: hidden !important; }
  .phone { height: 100vh !important; height: 100dvh !important; }
  /* 内容区独立滚动，为底部 tabbar / 操作栏留出空间，避免按钮被挤出 */
  .phone > .view, .view.active { min-height: 0; }
  .tabbar, .deal-action { position: sticky; bottom: 0; z-index: 30; background: #fff; }
  .pad { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0)); }
}
/* 横屏（844x390 等）：高度受限，禁用固定外壳高度，内容纵向滚动，禁止横向滚动 */
@media (orientation: landscape) and (max-height: 520px) {
  html, body {
    padding: 0 !important; margin: 0 !important;
    width: 100% !important; overflow-x: hidden !important;
  }
  .phone {
    width: 100% !important; max-width: 100% !important;
    height: auto !important; min-height: 100vh !important; min-height: 100dvh !important;
    border-radius: 0 !important; box-shadow: none !important;
  }
  /* 横屏矮屏：状态栏压缩，顶部导航与底部栏不吸底占位过高的空间 */
  .statusbar { display: none !important; }
  .nav { padding-top: 6px !important; padding-bottom: 6px !important; }
  /* 操作栏改为常态流内（不 position:fixed），随内容滚动，保证任何高度都能点到 */
  .deal-action, .tabbar { position: static !important; padding-bottom: 8px !important; }
  .deal-action .main-deal, .deal-action .dc-primary, .deal-action .dc-outline { min-height: 44px; }
  .icon-action, .dc-chat, .dc-call { min-width: 44px; min-height: 44px; }
  /* 抽屉在横屏矮屏占满高度且内部滚动 */
  .drawer-panel { max-height: 96vh !important; max-height: 96dvh !important; }
  .drawer-body { overflow-y: auto; }
}

/* ---------- 7. 图片懒加载与可访问性辅助 ---------- */
/* 列表图片统一懒加载（loading=lazy 由 JS/HTML 设置，此处保证不抖动） */
img[loading="lazy"] { content-visibility: auto; }
/* 键盘聚焦可见：Tab 可完成核心操作 */
button:focus-visible, [role="button"]:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, .chip:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--blue, #0891B2); outline-offset: 2px;
}
/* 演示支付标注 */
.demo-pay-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; margin: 0 auto 12px;
  background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; border-radius: 16px;
  font-size: 12px; font-weight: 700;
}
.demo-pay-result {
  padding: 10px 14px; margin: 12px 0; background: #fef3c7; color: #92400e;
  border: 1px solid #fde68a; border-radius: 10px; font-size: 12.5px; line-height: 1.5; text-align: center;
}
/* 列表到底说明 */
.ui-end { text-align: center; color: #b6c0cd; font-size: 12px; padding: 16px 0 8px; }

/* ---------- 8. 第四轮：用户端地址/消息/评价/优惠券 ---------- */
/* 消息中心：分类筛选 + 未读角标 + 按 msgType 分组 */
.msg-filters {
  flex: none; display: flex; gap: 8px; padding: 10px 14px; overflow-x: auto;
  background: #fff; border-bottom: 1px solid var(--line, #e2e8f0); white-space: nowrap;
  scrollbar-width: none;
}
.msg-filters::-webkit-scrollbar { display: none; }
.msg-chip {
  flex: none; border: 1px solid var(--line, #e2e8f0); background: #f8fafc; color: #64748b;
  border-radius: 18px; padding: 7px 14px; font-size: 12.5px; cursor: pointer;
}
.msg-chip.on { border-color: var(--blue, #0891B2); color: var(--blue, #0891B2); background: #dbeafe; font-weight: 700; }
.msg-badge {
  display: inline-block; min-width: 18px; height: 18px; line-height: 18px; text-align: center;
  padding: 0 5px; margin-right: 3px; border-radius: 9px; background: #ef4444; color: #fff;
  font-size: 11px; font-weight: 700; vertical-align: 1px;
}
.msg-group-title {
  display: flex; justify-content: space-between; align-items: center; padding: 6px 2px 2px;
  color: #64748b; font-size: 12.5px; font-weight: 600;
}
.msg-card { cursor: pointer; transition: opacity .2s ease, border-color .2s ease; }
.msg-card.unread { border-left: 3px solid var(--blue, #0891B2); }
.msg-card:not(.unread) { opacity: .78; }
.msg-content {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.msg-card.expanded .msg-content { display: block; overflow: visible; }
.msg-card:active { background: #f8fafc; }

/* 优惠券：状态分组 + 已使用/已过期置灰 */
.coupon-group { margin-bottom: 16px; }
.coupon-group-title {
  display: flex; justify-content: space-between; align-items: center;
  margin: 4px 2px 10px; color: #334155; font-size: 14px; font-weight: 700;
}
.coupon-group-title span { color: #94a3b8; font-size: 12px; font-weight: 500; }
.coupon-card.disabled { opacity: .55; filter: grayscale(1); }
.coupon-card.disabled .price { color: #94a3b8; }

/* 订单列表/详情：已评价分数与内容 */
.order-review {
  display: flex; align-items: flex-start; gap: 8px; margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--line, #e2e8f0); line-height: 1.5;
}
.order-review .muted { flex: 1; word-break: break-all; }

/* 评价弹窗（底部抽屉式，位于手机外壳内，不影响页面栈） */
.rate-modal {
  position: absolute; inset: 0; z-index: 60; display: none;
  align-items: flex-end; justify-content: center;
}
.rate-modal.show { display: flex; }
.rate-mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .55); }
.rate-panel {
  position: relative; width: 100%; max-width: 480px; max-height: 90%; max-height: 90dvh;
  display: flex; flex-direction: column; background: #fff; border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(15, 23, 42, .18); overflow: hidden;
}
.rate-head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px; border-bottom: 1px solid #eef1f6;
}
.rate-head h3 { font-size: 16px; font-weight: 700; color: #1e293b; }
.rate-close { color: #94a3b8; font-size: 22px; line-height: 1; cursor: pointer; padding: 0 6px; }
.rate-body { flex: 1; overflow-y: auto; padding: 14px 20px; text-align: center; }
.rate-body #rate-order-info { text-align: left; line-height: 1.5; }
.rate-body .stars { margin: 12px 0 6px; }
.review-chips { text-align: left; margin: 14px 0; }
.rate-body textarea { width: 100%; border: 1px solid var(--line, #e2e8f0); border-radius: 10px; padding: 12px; font-size: 14px; font-family: inherit; background: #f8fafc; resize: vertical; }
.rate-body textarea:disabled { background: #f1f5f9; color: #64748b; }
.rate-detail { margin-top: 12px; padding: 12px; border-radius: 10px; background: #fffbeb; text-align: left; line-height: 1.6; }
.rate-score { color: #d97706; font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.rate-foot {
  flex: none; display: flex; gap: 10px; padding: 12px 20px calc(14px + env(safe-area-inset-bottom, 0));
  border-top: 1px solid #eef1f6; background: #fff;
}
.rate-foot .btn { min-height: 44px; }
.rate-foot .btn[hidden] { display: none; }

@media (orientation: landscape) and (max-height: 520px) {
  /* 横屏矮屏下 .phone 高度随内容增长，弹窗改为相对视口固定，底部按钮不被挤出屏幕 */
  .rate-modal { position: fixed !important; }
  .rate-panel { max-height: 96vh !important; max-height: 96dvh !important; }
  .rate-panel .rate-body { padding-top: 8px; padding-bottom: 8px; }
  .rate-panel .stars { margin: 4px 0; }
  .msg-filters { padding: 6px 12px; }
  .msg-chip { padding: 5px 10px; }
}

/* 地址表单就地校验：错误字段高亮 + 行内错误说明，不清空已填内容 */
.input-error { border-color: #ef4444 !important; background: #fff5f5 !important; }
.field-error {
  display: flex; gap: 8px; align-items: flex-start; margin: 4px 0 12px;
  padding: 10px 12px; border-radius: 10px; background: #fef2f2;
  color: #b91c1c; font-size: 12px; line-height: 1.7;
}
.field-error > span { flex: none; font-size: 14px; line-height: 1.4; }
.field-error > div > div { margin: 0; }

/* ---------- 骑手端断网提示条 ---------- */
.net-banner {
  position: sticky; top: 0; left: 0; right: 0; z-index: 9000;
  display: none; padding: 9px 14px; text-align: center;
  font-size: 12.5px; font-weight: 600; color: #fff; background: #dc2626;
}
.net-banner.show { display: block; }

/* ---------- 触控目标 ≥40px：主从操作与筛选 chip ---------- */
.btn, .small-btn, .ui-btn, .chip, .tab, .filter-chip, .pf, .seg,
.menu-item, .list-item, .addr-act, .grab, .hc-grab,
.product-actions .small-btn, .stock-control button {
  min-height: 40px;
}
.chip, .filter-chip, .pf, .seg { min-width: 40px; }

/* ---------- 尊重系统「减少动态效果」设置 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .stat-bump, .bump, [class*=bump] { animation: none !important; }
}

/* 订单号/取件码点击复制 */
.copy-field {
  color: var(--blue, #0891B2);
  cursor: pointer;
  border-bottom: 1px dashed currentColor;
  padding: 2px 4px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.copy-field:active { opacity: .65; }

/* 骑手端待取/配送排序栏 */
.doing-sort-bar { align-items: center; gap: 8px; }
.doing-sort-bar .sort-label { font-size: 12px; color: var(--sub, #64748b); flex: none; }
.doing-sort-bar .filter-chip { min-height: 40px; }

/* 列表页通用搜索框（订单 / 历史订单 / 商品等） */
.area-search {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line, #e2e8f0);
  border-radius: 13px; padding: 10px 14px;
}
.area-search input {
  flex: 1; min-width: 0; border: none; outline: none;
  background: transparent; font-size: 14px; color: inherit;
  font-family: inherit;
}
.area-search input::placeholder { color: var(--sub, #94a3b8); }
