/* ============================================================
   手机浏览器适配层 (≤767px)
   在 main.css / components.css / chat.css 基础上做移动端增强
   保持小程序原有的紧凑触控体验
   ============================================================ */

/* ---------- 安全区与全局 ---------- */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (max-width: 767px) {
  html, body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overscroll-behavior-y: none;
  }

  /* 顶部导航：适配刘海屏 */
  .app-header {
    height: calc(var(--header-height) + var(--safe-top));
    padding-top: var(--safe-top);
  }

  .app-header img {
    width: 34px;
    height: 34px;
  }

  .brand-title {
    font-size: 15px;
  }

  /* 底部 TabBar：加高触摸区 */
  .mobile-tabbar {
    height: calc(var(--tabbar-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
  }

  .tab-item {
    min-height: 46px;
    gap: 3px;
  }

  .tab-icon {
    font-size: 20px;
  }

  .tab-label {
    font-size: 10.5px;
  }

  /* 页面内容不被 TabBar 遮挡 */
  .page-view {
    padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 20px);
  }

  /* 悬浮村长浮窗避开 TabBar */
  .floating-chief-widget {
    bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 14px);
    right: 12px;
  }

  /* AI 村长页时隐藏悬浮浮窗 */
  #app:has(#page-aiChat.active) .floating-chief-widget {
    display: none;
  }

  /* 输入框 16px 避免 iOS 自动放大 */
  .chat-input-field,
  input[type="text"],
  input[type="password"],
  input[type="tel"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px;
  }
}

/* ---------- 首页 Hero 与区块 ---------- */
@media (max-width: 480px) {
  .hero-card {
    padding: 22px 16px 24px;
    border-radius: var(--radius-md);
    min-height: 200px;
  }

  .hero-title {
    font-size: 22px;
    letter-spacing: 3px;
  }

  .hero-desc {
    font-size: 12px;
  }

  .hero-actions .btn {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 12px;
  }

  .section-title {
    font-size: 17px;
    margin: 22px 0 12px 0;
  }

  .quick-nav-icon {
    font-size: 22px;
  }

  .quick-nav-text {
    font-size: 11px;
  }
}

/* ---------- 商品卡片 ---------- */
@media (max-width: 480px) {
  .product-cover {
    height: 125px;
  }

  .product-btn-row .btn {
    padding: 6px 8px;
    font-size: 11px;
  }

  .product-sales {
    display: none;
  }

  .product-price {
    font-size: 16px;
  }
}

/* ---------- 地图页 ---------- */
@media (max-width: 767px) {
  .interactive-map-box {
    height: 300px;
  }

  .marker-bubble {
    font-size: 10px;
    padding: 3px 7px;
  }

  .spot-detail-drawer > div:first-child {
    flex-direction: column;
    gap: 10px;
  }

  .spot-detail-drawer img {
    width: 100% !important;
    height: 120px !important;
  }

  .map-filter-bar {
    padding-bottom: 8px;
  }
}

/* ---------- 模态框：移动端改为底部弹层（与小程序 .popup 一致） ---------- */
@media (max-width: 767px) {
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-box {
    max-width: 100%;
    width: 100%;
    max-height: 88dvh;
    max-height: 88vh;
    border-radius: 18px 18px 0 0;
    animation: mobileSheetUp 0.25s ease-out;
  }

  @keyframes mobileSheetUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* 弹层顶部拖拽手柄（与小程序 .popup-handle 呼应） */
  .modal-box::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--line);
    margin: 10px auto 4px;
  }

  .modal-body {
    padding-bottom: calc(16px + var(--safe-bottom));
  }
}

/* ---------- AI 村长对话页（全屏沉浸式） ---------- */
@media (max-width: 767px) {
  #page-aiChat {
    margin-left: -20px;
    margin-right: -20px;
  }

  .chat-container {
    height: calc(100dvh - var(--header-height) - var(--tabbar-height) - var(--safe-top) - var(--safe-bottom));
    height: calc(100vh - var(--header-height) - var(--tabbar-height));
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
    box-shadow: none;
  }

  .chat-header {
    padding: 10px 14px;
  }

  .chat-chief-avatar {
    width: 36px;
    height: 36px;
  }

  .chat-chief-title {
    font-size: 14px;
  }

  .chat-chief-desc {
    display: none;
  }

  .chat-header-tools .btn {
    padding: 4px 10px;
    font-size: 11px;
  }

  .chat-topics-bar {
    padding: 8px 12px;
  }

  .chat-messages {
    padding: 14px;
    gap: 14px;
    -webkit-overflow-scrolling: touch;
  }

  .msg-row {
    max-width: 92%;
  }

  .msg-bubble {
    font-size: 14px;
  }

  .chat-input-bar {
    padding: 10px 14px;
    padding-bottom: calc(10px + var(--safe-bottom));
  }

  .chat-input-field {
    height: 44px;
  }

  .chat-send-btn {
    width: 44px;
    height: 44px;
  }

  .quick-q-btn {
    padding: 10px 14px;
    font-size: 13px;
  }

  .chat-topic-btn {
    padding: 6px 12px;
  }
}
