/* ========== 设计变量 ========== */
:root {
  --primary: #e8490f;
  --primary-light: #ff6b35;
  --blue: #4a7dff;
  --blue-dark: #3366e8;
  --green: #07c160;
  --text-main: #1a1a1a;
  --text-sub: #666;
  --text-hint: #999;
  --bg-page: #f5f7fa;
  --bg-card: #fff;
  --border: #f0f0f0;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 25px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========== 移动端优先：全屏布局 ========== */
.app-viewport {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--vh, 1vh) * 100);
  background: var(--bg-page);
  overflow: hidden;
}

.app-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--bg-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ========== 桌面端：居中手机预览 ========== */
@media (min-width: 769px) {
  .app-viewport {
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
  .app-container {
    width: 390px;
    height: 844px;
    max-height: 95vh;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  }
}

/* ========== 页面内容区 ========== */
.app-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.app-content::-webkit-scrollbar { width: 0; display: none; }

/* ========== 页面（SPA 路由） ========== */
.page {
  display: none;
  min-height: 100%;
  animation: fadeSlideIn 0.3s var(--ease);
}

.page.active { display: block; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== 底部导航栏 ========== */
.tab-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 58px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 16px;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  color: var(--text-hint);
  font-size: 11px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tab-item .tab-icon {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: transform 0.2s var(--ease);
}

.tab-item.active { color: var(--primary); }
.tab-item.active .tab-icon { transform: scale(1.1); }
.tab-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  border-radius: 2px;
  background: var(--primary);
}

/* ========== 通用组件 ========== */
.section-title {
  font-size: 17px;
  font-weight: 600;
  padding: 16px;
  color: var(--text-main);
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  margin: 0 12px 12px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  border: none;
  cursor: pointer;
  transition: all 0.25s var(--ease);
  box-shadow: 0 4px 12px rgba(232, 73, 15, 0.3);
}

.btn-primary:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.btn-blue {
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  box-shadow: 0 4px 12px rgba(74, 125, 255, 0.3);
}

/* ========== 顶部导航栏 ========== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-main);
  background: var(--bg-card);
  flex-shrink: 0;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.top-bar .back-btn {
  position: absolute;
  left: 14px;
  cursor: pointer;
  font-size: 20px;
  color: #333;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.top-bar .back-btn:active { background: var(--border); }

/* ========== 全面浏览器适配 ========== */

/* --- iOS 11.0~11.2 Safe Area 兼容（constant + env） --- */
@supports (padding-bottom: constant(safe-area-inset-bottom)) {
  .tab-bar {
    padding-bottom: constant(safe-area-inset-bottom);
  }
}

/* --- 通用 WebKit 触摸优化 --- */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

input, textarea, select, button {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  outline: none;
}

input[type="radio"],
input[type="checkbox"] {
  -webkit-appearance: auto;
  -moz-appearance: auto;
  appearance: auto;
}

input:focus, textarea:focus, select:focus {
  outline: none;
}

/* --- 平滑滚动（兼容旧版 iOS） --- */
.app-content,
.page-sub,
.contract-list-body,
.invite-records,
.rc-case-list {
  -webkit-overflow-scrolling: touch;
}

/* --- backdrop-filter 兼容 + fallback --- */
.login-modal-overlay {
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

@supports not ((-webkit-backdrop-filter: blur(4px)) or (backdrop-filter: blur(4px))) {
  .login-modal-overlay {
    background: rgba(0, 0, 0, 0.7);
  }
}

/* --- 横屏适配 --- */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 768px) {
  .tab-bar {
    height: 46px;
  }
  .tab-item {
    padding: 4px 12px;
  }
  .top-bar {
    height: 40px;
    font-size: 15px;
  }
}

/* --- 超小屏适配（<320px，如 iPhone SE 1代） --- */
@media (max-width: 320px) {
  :root {
    --radius-md: 10px;
    --radius-lg: 14px;
  }
  .tab-item { font-size: 10px; padding: 4px 10px; }
  .tab-item .tab-icon { width: 22px; height: 22px; font-size: 17px; }
  .btn-primary { font-size: 14px; padding: 12px; }
  .top-bar { height: 44px; font-size: 15px; }
  .card { margin: 0 8px 10px; padding: 12px; }
}

/* --- 平板适配（如 iPad mini / iPad） --- */
@media (min-width: 421px) and (max-width: 768px) {
  .form-card { max-width: 540px; margin-left: auto; margin-right: auto; }
  .card { max-width: 540px; margin-left: auto; margin-right: auto; }
}

/* --- 键盘弹起时处理视口偏移 --- */
@media (max-height: 450px) and (orientation: portrait) {
  .tab-bar { display: none !important; }
  .app-content { padding-bottom: 0; }
}

/* --- 微信 X5 内核 / 安卓 WebView 兼容 --- */
.page {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* 防止 input zoom（iOS Safari 字体 <16px 会触发缩放） */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
  input[type="text"],
  input[type="tel"],
  input[type="number"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px;
  }
}

/* --- 刘海屏顶部适配 --- */
@supports (padding-top: env(safe-area-inset-top)) {
  .contract-navbar,
  .top-bar,
  .inv-top-bar {
    padding-top: env(safe-area-inset-top);
  }
}

@supports (padding-top: constant(safe-area-inset-top)) {
  .contract-navbar,
  .top-bar,
  .inv-top-bar {
    padding-top: constant(safe-area-inset-top);
  }
}

/* --- 暗色模式基础适配（跟随系统） --- */
@media (prefers-color-scheme: dark) {
  /* 预留暗色模式入口，当前不激活以保持一致性 */
}

/* --- 动画降级（减弱动画偏好） --- */
@media (prefers-reduced-motion: reduce) {
  .page { animation: none; }
  * { transition-duration: 0.01ms !important; }
}
