/**
 * 前端公共样式 - 用户端
 * 多头借贷账单分析系统
 *
 * 提供:
 *  1. 底部 Tab Bar(移动端)
 *  2. 抽屉菜单(汉堡)
 *  3. 触摸目标优化(>=44x44)
 *  4. 防止 iOS 自动缩放(input font-size>=16)
 *  5. 链接行为
 *
 * 用法:HTML <head> 内引用
 *   <link rel="stylesheet" href="common-mobile.css">
 *   <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,viewport-fit=cover">
 */

/* ── 移动端 Tab Bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--card-bg);
  box-shadow: 0 -1px 12px rgba(0, 0, 0, 0.06);
  display: none;
  z-index: 99;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--border-subtle);
}
.tab-bar.show { display: flex; }
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-muted);
  transition: color 0.15s;
  min-height: 50px;
  -webkit-tap-highlight-color: transparent;
}
.tab-item.active { color: var(--brand); }
.tab-item:active { background: var(--fill-hover); }
.tab-item .icon { font-size: 22px; line-height: 1; }
.tab-item .label { font-size: 10px; font-weight: 500; }

/* ── 汉堡菜单按钮 ── */
.mobile-menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 18px;
  align-items: center;
  justify-content: center;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}
.mobile-menu-btn:active { transform: scale(0.92); }

/* ── 抽屉 ── */
.mobile-drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 199;
  display: none;
  animation: drawerFadeIn 0.2s ease;
}
.mobile-drawer-mask.show { display: block; }
@keyframes drawerFadeIn { from { opacity: 0; } to { opacity: 1; } }

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--card-bg);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  padding: 16px 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.mobile-drawer.show { transform: translateX(0); }
.mobile-drawer a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.mobile-drawer a:hover,
.mobile-drawer a:active { background: var(--primary-bg); }
.mobile-drawer a.active {
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-bg);
}
.mobile-drawer a .icon { font-size: 20px; width: 24px; text-align: center; }
.mobile-drawer .logout-link {
  color: var(--danger);
  margin-top: auto;
  border-top: 2px solid var(--border);
}
.mobile-drawer .logout-link:hover,
.mobile-drawer .logout-link:active { background: #fee2e2; }

/* ── 触摸目标(>=44x44) ── */
button, .btn, a.button {
  min-height: 36px;
}
input[type="checkbox"], input[type="radio"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* ── iOS 防止自动缩放(input 16px+) ── */
input, select, textarea {
  font-size: 16px;
}

/* ── 链接行为 ── */
a { -webkit-tap-highlight-color: transparent; }
a[target="_blank"]::after {
  content: " ↗";
  font-size: 0.85em;
  opacity: 0.6;
  margin-left: 2px;
}
a[href^="tel:"]::after,
a[href^="mailto:"]::after { content: ""; }

/* ── 响应式断点 ── */
@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: initial; }
  .mobile-menu-btn { display: inline-flex; }
  .tab-bar { display: flex; }

  /* 通用移动端适配:限制内容最大宽度、隐藏桌面 nav、调整 header */
  body {
    max-width: 100% !important;
    font-size: 14px;
  }
  body.has-tab-bar { padding-bottom: calc(70px + env(safe-area-inset-bottom)) !important; }

  /* Header:压缩高度、横向布局保持,但隐藏桌面横向 nav */
  .header {
    padding: 0 12px !important;
    height: 50px !important;
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .header .nav,
  .header .desktop-nav,
  .header nav[role="navigation"]:not(.tab-bar) {
    display: none !important;
  }
  .header-left { gap: 8px !important; }
  .header .logo { font-size: 15px !important; }
  .header .title { font-size: 16px !important; }

  /* 容器:减少内边距 */
  .container, .main-wrap, .main, .content {
    padding: 12px !important;
    margin: 0 !important;
    max-width: 100% !important;
  }

  /* 卡片:减少内边距 */
  .card, .panel, .box {
    padding: 14px !important;
    margin: 8px 0 !important;
    border-radius: var(--radius-md) !important;
  }

  /* 标题:缩小字号 */
  h1, .h1 { font-size: 20px !important; }
  h2, .h2 { font-size: 17px !important; }
  h3, .h3 { font-size: 15px !important; }

  /* 表格:横向滚动 + 小字号 */
  table {
    font-size: 13px !important;
  }
  .table-wrap, .table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* 按钮:全宽主操作 */
  .btn-primary, .btn-submit, button[type="submit"], .primary-btn {
    min-height: 44px;
    font-size: 15px;
  }

  /* 模态/弹窗:全屏化 */
  .modal, .modal-mask > div, .modal-content {
    max-width: 100vw !important;
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    height: 100dvh !important;
    border-radius: 0 !important;
  }

  /* 描述文字 */
  .desc, .description, .meta {
    font-size: 12px !important;
  }

  /* 单行省略 */
  .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (min-width: 769px) {
  .mobile-only { display: none !important; }
}

/* ── 通用工具 ── */
.text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── 滚动条优化 ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

/* ── 安全区适配 ── */
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
.safe-top { padding-top: env(safe-area-inset-top); }
