/* 手机端独立布局：首页 + 全屏扫码 + 底部导航 */
@media (max-width: 640px) {
  :root {
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
    --nav-h: calc(56px + var(--safe-b));
  }

  body {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    background: #eef1f6;
  }

  .desktop-only { display: none !important; }
  .mobile-only { display: block !important; }

  .app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 100%;
    padding: 0;
    padding-bottom: var(--nav-h);
  }

  body.cam-active .app,
  body.mobile-idle .app {
    padding-bottom: 0;
  }

  /* 顶栏 */
  .m-bar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: calc(10px + var(--safe-t)) 16px 10px;
    background: #fff;
    border-bottom: 1px solid #e8edf3;
    position: sticky;
    top: 0;
    z-index: 30;
  }

  body.cam-active .m-bar { display: none !important; }

  .m-bar-brand { display: flex; align-items: center; gap: 10px; }
  .m-logo {
    width: 32px; height: 32px; border-radius: 9px;
    background: linear-gradient(135deg, #0d6efd, #0a58ca);
    color: #fff; font-size: 11px; font-weight: 700;
    display: grid; place-items: center;
  }
  .m-title { font-size: 1.05rem; font-weight: 700; color: #1a2332; }

  .m-status-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: #c5cdd8;
  }
  .m-status-dot.scanning { background: #0d6efd; animation: pulse 1.2s infinite; }
  .m-status-dot.ok { background: #0f9d58; }
  .m-status-dot.warn { background: #f59e0b; }
  @keyframes pulse { 50% { opacity: .4; } }

  /* 首页 */
  .mobile-home {
    flex: 1;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px 32px;
    text-align: center;
  }

  body:not(.mobile-idle) .mobile-home { display: none !important; }

  .mh-visual {
    position: relative;
    width: 120px; height: 120px;
    margin-bottom: 28px;
  }
  .mh-ring {
    position: absolute; inset: 0;
    border: 3px solid #0d6efd;
    border-radius: 28px;
    opacity: .25;
  }
  .mh-ring::after {
    content: '';
    position: absolute;
    inset: 12px;
    border: 2px dashed #0d6efd;
    border-radius: 20px;
    opacity: .5;
  }
  .mh-icon {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #0d6efd;
  }

  .mh-desc {
    font-size: 1rem;
    color: #4a5568;
    line-height: 1.6;
    margin-bottom: 32px;
  }

  .btn-start {
    width: 100%;
    max-width: 320px;
    min-height: 54px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, #0d6efd, #0a58ca);
    color: #fff;
    font-size: 1.1rem;
    font-weight: 700;
    box-shadow: 0 8px 28px rgba(13, 110, 253, .32);
    cursor: pointer;
    margin-bottom: 12px;
  }
  .btn-start:active { transform: scale(.98); }

  .btn-outline {
    width: 100%;
    max-width: 320px;
    min-height: 48px;
    border: 1.5px solid #c5d5f0;
    border-radius: 14px;
    background: #fff;
    color: #0d6efd;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
  }

  .mh-tip {
    margin-top: 24px;
    font-size: .78rem;
    color: #8b95a5;
  }

  /* 工作区：仅预览/相机 */
  .workspace {
    display: none;
    flex: 1;
    flex-direction: column;
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    margin: 0;
    overflow: hidden;
  }

  body:not(.mobile-idle) .workspace { display: flex !important; }

  .layout {
    display: flex !important;
    flex-direction: column;
    flex: 1;
  }

  .side,
  .toolbar,
  .cam-bar,
  .hint,
  .foot { display: none !important; }

  .preview-wrap {
    position: relative;
    flex: 1;
    background: #0f1419;
    border-radius: 0;
    min-height: calc(100dvh - var(--nav-h) - 52px);
    max-height: none;
  }

  .preview-wrap.empty { display: none !important; }

  body.cam-active .preview-wrap {
    position: fixed;
    inset: 0;
    z-index: 40;
    min-height: 100dvh;
    border-radius: 0;
  }

  .dropzone { display: none !important; }

  .mobile-back {
    display: none;
    position: absolute;
    top: calc(10px + var(--safe-t));
    left: 12px;
    z-index: 60;
    width: 40px; height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(0,0,0,.5);
    color: #fff;
    font-size: 1.1rem;
    backdrop-filter: blur(6px);
  }

  body:not(.cam-active):not(.mobile-idle) .mobile-back { display: block; }

  #video.show {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  canvas {
    width: 100%;
    height: 100%;
    max-height: none;
    object-fit: contain;
    touch-action: none;
  }

  .scan-guide::before {
    width: 72vw;
    max-width: 280px;
    border-width: 3px;
    border-radius: 12px;
  }

  .cam-hint {
    bottom: calc(128px + var(--safe-b));
    font-size: .88rem;
    padding: 0 20px;
  }

  .cam-close {
    display: flex !important;
    position: fixed;
    top: calc(12px + var(--safe-t));
    right: 12px;
    z-index: 70;
    width: 44px; height: 44px;
    border: 0; border-radius: 50%;
    background: rgba(0,0,0,.45);
    color: #fff;
    font-size: 1.2rem;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(6px);
  }

  .cam-dock {
    display: flex !important;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 70;
    padding: 14px 20px calc(18px + var(--safe-b));
    align-items: center;
    justify-content: center;
    gap: 28px;
    background: linear-gradient(transparent, rgba(0,0,0,.7));
  }

  .shutter {
    width: 72px; height: 72px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: rgba(255,255,255,.22);
    box-shadow: 0 0 0 4px rgba(255,255,255,.15);
    flex-shrink: 0;
  }
  .shutter:active { transform: scale(.94); }

  .dock-btn {
    min-width: 68px;
    padding: 10px 12px;
    border-radius: 20px;
    border: 0;
    background: rgba(255,255,255,.2);
    color: #fff;
    font-size: .82rem;
    font-weight: 600;
    backdrop-filter: blur(6px);
  }
  .dock-btn.on { background: #0f9d58; }

  /* 底部导航 */
  .mobile-nav {
    display: flex !important;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 90;
    height: var(--nav-h);
    padding-bottom: var(--safe-b);
    background: #fff;
    border-top: 1px solid #e8edf3;
    box-shadow: 0 -2px 16px rgba(0,0,0,.05);
  }

  body.cam-active .mobile-nav,
  body.has-sheet .mobile-nav { display: none !important; }

  .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    background: none;
    color: #8b95a5;
    font-size: .72rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    padding: 6px 0;
  }
  .nav-item.active { color: #0d6efd; }
  .nav-ico { font-size: 1.25rem; line-height: 1; }

  /* 结果面板 */
  .result-sheet {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 100;
    background: #fff;
    border-radius: 20px 20px 0 0;
    padding: 12px 20px calc(20px + var(--safe-b));
    box-shadow: 0 -8px 40px rgba(0,0,0,.2);
    transform: translateY(110%);
    transition: transform .28s ease;
  }
  .result-sheet.show {
    display: block !important;
    transform: translateY(0);
  }

  .sheet-handle {
    width: 40px; height: 4px;
    background: #dde3ec;
    border-radius: 4px;
    margin: 0 auto 14px;
  }
  .sheet-label { font-size: .78rem; color: #6b7a90; margin-bottom: 6px; }
  .sheet-code {
    font-family: "JetBrains Mono", monospace;
    font-size: 1.2rem;
    font-weight: 700;
    word-break: break-all;
    margin-bottom: 14px;
    line-height: 1.4;
  }
  .sheet-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .sheet-actions .btn { min-height: 48px; border-radius: 12px; }
  .sheet-actions .btn-primary { background: #0d6efd; color: #fff; border: 0; }
  .sheet-actions .btn-green { background: #0f9d58; color: #fff; border: 0; }

  body.has-sheet .cam-dock,
  body.has-sheet .cam-hint { display: none !important; }

  body.has-sheet.cam-active .preview-wrap::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 75;
    background: rgba(0,0,0,.4);
    pointer-events: none;
  }

  body.cam-active { overflow: hidden; background: #000; }

  select, .asset-input { font-size: 16px !important; }
}

@media (min-width: 641px) {
  .mobile-only { display: none !important; }
  .m-bar, .mobile-nav, .mobile-home, .mobile-back,
  .cam-close, .cam-dock, .result-sheet { display: none !important; }
}
