/* ================================================
   DataBoard 手机端 v2 - 组件库 (Components)
   --------------------------------------------
   依赖：tokens.css（在 base.html 中先于本文件引入）
   包含：导航、卡片、按钮、表单、徽章、Tab Bar、安全区
   ================================================ */

/* ============== Reset ============== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  /* 禁止横向滚动 */
  -webkit-tap-highlight-color: transparent;
  /* 去除点击高亮 */
  -webkit-touch-callout: none;
  /* 禁止长按弹出菜单 */
}

/* ============== 隐藏所有滚动条（手机端主流设计）============== */
/* Firefox */
html {
  scrollbar-width: none;
}

/* IE/Edge */
html,
body {
  -ms-overflow-style: none;
}

/* Chrome/Safari/Webkit 全部 */
html::-webkit-scrollbar,
body::-webkit-scrollbar,
*::-webkit-scrollbar {
  display: none;
  width: 0 !important;
  height: 0 !important;
  -webkit-appearance: none;
}

/* iOS 弹性滚动（必须加，否则滚动不流畅） */
.phone-page,
.phone-content {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ============== 页面容器 ============== */
.phone-page {
  max-width: 414px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-secondary);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.06);
  /* ✨ 容器内滚动条样式（细而柔和） */
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.phone-page::-webkit-scrollbar {
  width: 4px;
}

.phone-page::-webkit-scrollbar-track {
  background: transparent;
}

.phone-page::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 2px;
}

.phone-page::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* ============== 顶部导航（对齐 Web nav-v315：白底渐变 + 品牌橙底边框 + 深色字 + 品牌橙激活） ============== */
.phone-top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  max-width: 414px;
  margin: 0 auto;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  background: linear-gradient(180deg, #ffffff 0%, #fff7f3 100%);
  border-bottom: 1px solid rgba(239, 106, 76, .28);
  box-shadow: 0 1px 3px rgba(24, 28, 45, .05);
  z-index: 1000;
}

.phone-top-nav__item {
  flex: 1 0 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0 8px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  transition: color 150ms ease, background-color 150ms ease;
}

.phone-top-nav__item:hover {
  color: var(--primary-5);
  background-color: rgba(239, 106, 76, .12);
}

.phone-top-nav__item--active {
  color: var(--primary-5);
  font-weight: var(--font-weight-semibold);
}

.phone-top-nav__item--active::after {
  content: '';
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 4px;
  height: 2px;
  background-color: var(--primary-5);
  border-radius: var(--radius-full);
}

.phone-top-nav__item:active {
  background-color: rgba(239, 106, 76, .22);
}

/* ============== 主内容 ============== */
.phone-content {
  flex: 1;
  padding: var(--space-3);
  padding-top: calc(var(--nav-height) + var(--space-3));
  /* 底部栏已删除：仅留基础间距 + iPhone 安全区 */
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
}

/* ============== 卡片 ============== */
.phone-card {
  /* 与页面背景融合，减少视觉割裂 */
  background-color: var(--bg-secondary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-3);
  overflow: hidden;
  animation: phoneFadeIn 250ms ease;
}

@keyframes phoneFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.phone-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-secondary);
}

.phone-card__title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.phone-card__subtitle {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
}

.phone-card__body {
  padding: var(--space-4);
}

.phone-card__body--compact {
  padding: 12px;
}

/* ============== 数据网格 ============== */
.phone-data-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.phone-data-item {
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-2);
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.phone-data-item__label {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.phone-data-item__value {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  line-height: 1.2;
}

.phone-data-item__unit {
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-normal);
  color: var(--text-tertiary);
  margin-left: 2px;
}

.phone-data-item__change {
  font-size: var(--font-size-xs);
  margin-top: 2px;
}

.phone-data-item__change--up {
  color: var(--color-up);
}

.phone-data-item__change--down {
  color: var(--color-down);
}

/* ============== Segmented Control ============== */
.phone-segment {
  display: flex;
  background: var(--bg-primary);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
}

.phone-segment__item {
  flex: 1;
  padding: var(--space-2) var(--space-1);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  text-align: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 150ms ease;
}

.phone-segment__item--active {
  background: var(--primary-5);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

/* ============== 留白页 ============== */
.phone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
  text-align: center;
}

.phone-empty__icon {
  width: 80px;
  height: 80px;
  background: var(--primary-1);
  color: var(--primary-5);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  margin-bottom: var(--space-4);
}

.phone-empty__title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.phone-empty__desc {
  font-size: var(--font-size-sm);
  color: var(--text-tertiary);
  line-height: 1.6;
}

/* ============== 通用弹窗 (v2.12) ============== */
.phone-dialog {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 180ms ease;
  padding: var(--space-4);
}

.phone-dialog--in {
  opacity: 1;
}

.phone-dialog--leaving {
  opacity: 0;
}

.phone-dialog__card {
  width: 100%;
  max-width: 320px;
  background: var(--bg-primary);
  border-radius: var(--radius-lg, 12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  transform: scale(0.92);
  transition: transform 180ms ease;
  overflow: hidden;
}

.phone-dialog--in .phone-dialog__card {
  transform: scale(1);
}

.phone-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-secondary, #eee);
}

.phone-dialog__title {
  font-size: var(--font-size-md, 15px);
  font-weight: var(--font-weight-semibold, 600);
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  /* 数据表名等长字符串省略 */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.phone-dialog__close {
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--text-tertiary, #999);
  cursor: pointer;
  padding: 0 4px;
  margin-left: var(--space-2);
  transition: color 150ms ease;
}

.phone-dialog__close:hover {
  color: var(--text-primary);
}

.phone-dialog__body {
  padding: var(--space-4);
  font-size: var(--font-size-sm, 13px);
  color: var(--text-secondary);
  line-height: 1.6;
  max-height: 60vh;
  overflow-y: auto;
  word-wrap: break-word;
  white-space: pre-wrap;
}

/* ============== 图表占位 ============== */
.phone-chart {
  width: 100%;
  height: 200px;
  background: linear-gradient(180deg, #fafafa 0%, #f5f5f5 100%);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  color: var(--text-tertiary);
  position: relative;
  overflow: hidden;
}

.phone-chart--lg {
  height: 240px;
}

.phone-chart--sm {
  height: 160px;
}

.phone-chart--empty {
  color: var(--text-disabled);
}

.phone-chart::before {
  content: '';
  position: absolute;
  inset: 0;
  /* v3.x 移除占位符灰色网格背景（之前用 linear-gradient 画 20×20px 网格，Plotly plot_bgcolor 透明导致穿透显示）*/
  background-image: none;
}

.phone-chart__svg {
  position: relative;
  z-index: 1;
}

/* ============== 按钮 ============== */
.phone-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-4);
  background: var(--primary-5);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: all 150ms ease;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(239, 106, 76, 0.3);
}

.phone-btn:active {
  background: var(--primary-6);
  transform: scale(0.98);
}

.phone-btn:disabled {
  background: var(--neutral-5);
  box-shadow: none;
  cursor: not-allowed;
}

.phone-btn--ghost {
  background: transparent;
  color: var(--primary-6);
  border: 1px solid var(--primary-3);
  box-shadow: none;
}

.phone-btn--block {
  width: 100%;
}

/* ============== 表单 ============== */
.phone-input {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  font-family: inherit;
  transition: all 150ms ease;
}

.phone-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

/* ============== 徽章 / 标签 ============== */
.phone-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  background: var(--neutral-3);
  color: var(--text-tertiary);
  font-weight: var(--font-weight-medium);
}

.phone-badge--admin {
  background: rgba(194, 132, 10, 0.15);
  color: var(--color-warning);
}

.phone-badge--success {
  background: rgba(21, 128, 61, 0.1);
  color: var(--color-down);
}

.phone-badge--warning {
  background: rgba(194, 132, 10, 0.15);
  color: var(--color-warning);
}

.phone-badge--danger {
  background: rgba(217, 48, 48, 0.1);
  color: var(--color-up);
}

/* ============== 安全区 ============== */
@supports (padding: max(0px)) {
  .phone-top-nav {
    padding-top: max(0px, env(safe-area-inset-top));
  }
}

/* ============== 响应式 ============== */
@media (max-width: 375px) {
  .phone-data-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (orientation: landscape) {

  .phone-top-nav {
    height: 40px;
  }

  .phone-content {
    padding-top: calc(40px + var(--space-3));
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  }
}

/* ============== 工具类 ============== */
.phone-flex {
  display: flex;
}

.phone-flex--center {
  align-items: center;
  justify-content: center;
}

.phone-flex--between {
  align-items: center;
  justify-content: space-between;
}

.phone-text--up {
  color: var(--color-up);
}

.phone-text--down {
  color: var(--color-down);
}

.phone-text--tertiary {
  color: var(--text-tertiary);
}

.phone-mt-2 {
  margin-top: var(--space-2);
}

.phone-mt-3 {
  margin-top: var(--space-3);
}

.phone-mb-2 {
  margin-bottom: var(--space-2);
}