/* ============================================================
   移动端样式表 & 维护指南
   Mobile Stylesheet & Maintenance Guide
   ============================================================

   【维护规则 / Rules】
   1. 本文件只包含 ≤768px 屏幕的适配样式，PC 端样式在 style.css
   2. 按页面分区，新增页面的移动端样式加在对应分区下
   3. 每个分区用醒目的分隔线标注，方便查找
   4. 新增 PC 端功能后，同步在此文件添加移动端调整
   5. 所有样式嵌套在 @media (max-width: 767.98px) 内

   【文件结构 / Structure】
   - 全局通用：布局 + 底部导航 + 触控优化 + 通用组件
   - 登录页 (login.html)
   - 实时看板 (dashboard.html)
   - 节点管理 (nodes.html)
   - 数据查询 (history.html)
   - 告警中心 (alerts.html)
   - 系统设置 (settings.html)
   ============================================================ */

@media (max-width: 767.98px) {

/* ============================================
   1. 全局通用 / Global
   ============================================ */

/* --- 1.1 布局基础 --- */
.app-sidebar {
  transform: translateX(-100%);
}
.app-sidebar.show {
  transform: translateX(0);
}
.sidebar-overlay.show {
  display: block;
}
.app-main {
  margin-left: 0;
  padding-bottom: calc(max(env(safe-area-inset-bottom, 20px), 20px) + 80px);
}
.topbar-left .sidebar-toggle {
  display: block;
}
.app-content {
  padding: 12px;
}
.app-footer {
  padding: 10px 12px;
  margin-bottom: calc(max(env(safe-area-inset-bottom, 20px), 20px) + 80px);
}
.topbar {
  padding: 0 12px;
}
/* 顶部栏手机端只保留标题和汉堡按钮 */
.topbar-right .topbar-stat {
  display: none;
}

/* --- 1.2 浮动圆角药丸导航栏 --- */
.mobile-tab-bar {
  display: flex;
  position: fixed;
  bottom: calc(max(env(safe-area-inset-bottom, 20px), 20px) + 8px);
  left: 12px;
  right: 12px;
  width: auto;
  height: 52px;
  background: #ffffff;
  border-radius: 18px;
  border: none;
  z-index: 1020;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.08);
  padding: 0;
  overflow: hidden;
}
.mobile-tab-bar .tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  text-decoration: none;
  font-size: 10px;
  gap: 1px;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  position: relative;
}
.mobile-tab-bar .tab-item i {
  font-size: 20px;
  transition: color 0.2s;
}
.mobile-tab-bar .tab-item.active {
  color: #0d9488;
  font-weight: 600;
}
.mobile-tab-bar .tab-item.active i {
  color: #0d9488;
}
/* 当前页底部小圆点指示器 */
.mobile-tab-bar .tab-item.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #0d9488;
}


/* --- 1.3 触控优化 --- */
/* 所有按钮和链接最小触控区域 44px */
.btn, .btn-sm, .nav-link, .dropdown-item, .form-check-label,
.page-link, .accordion-button, .form-select, .form-control {
  min-height: 36px;
}
.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}
/* 表格操作按钮 */
.btn-group-sm .btn {
  min-height: 32px;
  padding: 4px 8px;
}
/* 表单控件字号 ≥16px 防止 iOS 缩放 */
@media (max-width: 480px) {
  .form-control, .form-select {
    font-size: 16px !important;
  }
}

/* --- 1.4 模态框手机端全屏 --- */
@media (max-width: 576px) {
  .modal-dialog {
    margin: 0;
    max-width: 100%;
    height: 100%;
  }
  .modal-content {
    border-radius: 0;
    min-height: 100vh;
  }
  .modal-header {
    padding: 14px 16px;
  }
  .modal-body {
    padding: 16px;
  }
  .modal-footer {
    padding: 10px 16px;
  }
}

/* --- 1.5 Toast 位置调整 --- */
/* 仅匹配节点管理页面的 Toast 容器，避免误伤其他 fixed 元素 */
#toast {
  width: 100%;
  max-width: 100%;
}

/* --- 1.6 通用卡片 --- */
.card-body {
  padding: 12px;
}
.card-header {
  padding: 10px 12px;
}

/* --- 1.7 滚动表格 --- */
.table-responsive {
  -webkit-overflow-scrolling: touch;
}
.table th, .table td {
  white-space: nowrap;
  font-size: 12px;
}

/* ============================================
   2. 登录页 / login.html
   ============================================ */

/* 顶部栏 */
.landing-page .topbar {
  padding: 12px 16px;
}
.landing-page .brand-small {
  font-size: 15px;
}
.landing-page .brand-small i {
  font-size: 20px;
}
.landing-page .btn-login-top {
  padding: 6px 14px;
  font-size: 13px;
}

/* 中央区域 */
.landing-page .hero {
  padding: 24px 20px;
}
.landing-page .hero h1 {
  font-size: 26px;
}
.landing-page .hero .hero-tagline {
  font-size: 13px;
  padding: 0 16px;
}
.landing-page .hero .icon-ring {
  width: 100px;
  height: 100px;
  margin-bottom: 24px;
}
.landing-page .hero .icon-ring .core-icon {
  font-size: 40px;
}

/* 6卡片 → 2列 */
.landing-page .feature-section {
  padding: 0 16px 32px;
}
.landing-page .feature-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.landing-page .feature-card {
  padding: 14px;
}
.landing-page .feature-card-title {
  font-size: 13px;
}
.landing-page .feature-card-desc {
  font-size: 11px;
  margin-bottom: 12px;
}

/* iPhone SE 等小屏 → 单列 */
@media (max-width: 380px) {
  .landing-page .feature-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
}

/* 登录弹窗 */
.landing-page .login-overlay {
  padding: 0;
  align-items: flex-end;
}
.landing-page .login-box {
  max-width: 100%;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 32px;
}
.landing-page .login-box h2 {
  font-size: 20px;
}
.landing-page .login-box .subtitle {
  font-size: 13px;
  margin-bottom: 22px;
}

/* 底部备案 */
.landing-page .site-footer {
  padding: 16px 12px;
  font-size: 11px;
}

/* ============================================
   3. 实时看板 / dashboard.html
   ============================================ */

/* --- 3.1 统计卡片 2×2 --- */
.dashboard .row.g-3.mb-4 > [class*="col-"] {
  /* 由 Bootstrap col-6 控制，无需额外修改 */
}

/* --- 3.2 图表工具栏：垂直排列 --- */
/* 历史趋势卡片头部：工具栏各控件垂直堆叠 */
.card-header .d-flex.gap-2.flex-wrap.align-items-center {
  flex-direction: column;
  align-items: stretch !important;
  gap: 8px !important;
}
/* 节点选择下拉、指标切换、时间范围各占一行 */
.card-header .d-flex.gap-2 .dropdown,
.card-header .d-flex.gap-2 > .btn-group {
  width: 100%;
}
.card-header .d-flex.gap-2 .dropdown .dropdown-toggle {
  width: 100%;
  justify-content: space-between;
}
/* 时间范围按钮均分 */
.card-header .btn-group.btn-group-sm[class*="btn-outline-success"] .btn {
  flex: 1;
}
/* 指标切换按钮换行 */
#envMetricsToggle,
#soilMetricsToggle {
  flex-wrap: wrap;
  gap: 3px;
}
#soilMetricsToggle .btn {
  flex: none;
}
/* 下拉菜单不超出屏幕 */
#nodeSelectMenu {
  max-width: 90vw;
  left: 0 !important;
}

/* --- 3.3 节点卡片 --- */
/* col-12 已经全宽，调整内边距 */
.node-card-enhanced .card-body,
#nodeCardsContainer .card-body {
  padding: 12px;
}
/* 土壤分层 col-4 → col-6，两列显示 */
#nodeCardsContainer .col-4 {
  flex: 0 0 50%;
  max-width: 50%;
}
/* 土壤分层内边距缩小 */
#nodeCardsContainer .bg-light.rounded.p-2 {
  padding: 8px 4px !important;
}

/* --- 3.4 图表高度 --- */
#historyChart {
  height: 300px !important;
}

/* --- 3.5 图表工具栏：指标切换按钮换行 --- */


/* ============================================
   4. 节点管理 / nodes.html
   ============================================ */

/* --- 4.1 顶部操作栏垂直排列 --- */
.d-flex.justify-content-between.align-items-center.mb-3.flex-wrap {
  flex-direction: column;
  align-items: flex-start !important;
  gap: 10px;
}
.d-flex.justify-content-between.align-items-center.mb-3.flex-wrap .d-flex.align-items-center.gap-2 {
  flex-wrap: wrap;
  width: 100%;
}
.d-flex.justify-content-between.align-items-center.mb-3.flex-wrap #searchInput {
  flex: 1;
  max-width: none;
}
.d-flex.justify-content-between.align-items-center.mb-3.flex-wrap #typeFilter {
  max-width: 100px;
}
.d-flex.justify-content-between.align-items-center.mb-3.flex-wrap > .btn {
  width: 100%;
}

/* --- 4.2 批量操作栏 --- */
.batch-toolbar {
  padding: 10px 12px;
  font-size: 13px;
}
.batch-toolbar .d-flex {
  flex-wrap: wrap;
  gap: 8px;
}

/* --- 4.3 表格：隐藏非关键列 --- */
/* 在小屏隐藏：位置、采集间隔、掉线阈值列 */
@media (max-width: 576px) {
  .table th:nth-child(4),  /* 位置 */
  .table td:nth-child(4),
  .table th:nth-child(6),  /* 采集间隔 */
  .table td:nth-child(6),
  .table th:nth-child(7),  /* 掉线阈值 */
  .table td:nth-child(7) {
    display: none;
  }
}

/* --- 4.4 模态框表单 --- */
#nodeForm .row.g-2 .col-6 {
  flex: 0 0 100%;
  max-width: 100%;
  margin-bottom: 8px;
}

/* ============================================
   5. 数据查询 / history.html
   ============================================ */

/* --- 5.1 过滤器垂直排列 --- */
.row.g-2.align-items-end {
  flex-direction: column;
  align-items: flex-start !important;
}
.row.g-2.align-items-end .col-auto {
  width: 100%;
  margin-bottom: 8px;
}
.row.g-2.align-items-end .col-auto.ms-auto {
  margin-left: 0 !important;
  display: flex;
  gap: 8px;
}
.row.g-2.align-items-end .col-auto select,
.row.g-2.align-items-end .col-auto .btn {
  width: 100%;
}

/* --- 5.2 分页按钮间距 --- */
.pagination-sm .page-link {
  padding: 4px 8px;
  font-size: 12px;
}

/* --- 5.3 底部总数+分页分行 --- */
.d-flex.justify-content-between.align-items-center.mt-3 {
  flex-direction: column;
  gap: 8px;
  text-align: center;
}

/* ============================================
   6. 告警中心 / alerts.html
   ============================================ */

/* --- 6.1 统计卡片 + 操作按钮 --- */
/* 告警页面的计数卡片后的操作区：手机端占满宽 */
.row.g-3.mb-3 .d-flex.align-items-end.justify-content-end.gap-2 {
  justify-content: flex-start !important;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* --- 6.2 时间线条目 --- */
.timeline-item {
  padding-left: 28px;
  padding-bottom: 12px;
}
.timeline-item .card {
  padding: 10px 12px !important;
}
.timeline-item .card .d-flex {
  flex-direction: column;
  gap: 6px;
}

/* ============================================
   7. 系统设置 / settings.html
   ============================================ */

/* --- 7.1 手风琴项目 --- */
.settings-accordion .accordion-button {
  padding: 12px 14px;
  font-size: 13px;
}
.settings-accordion .accordion-body {
  padding: 12px;
}

/* --- 7.2 输入组 --- */
.settings-accordion .input-group {
  flex-wrap: wrap;
}
.settings-accordion .input-group .form-control {
  min-width: 0;
}
.settings-accordion .input-group .btn {
  flex-shrink: 0;
}

/* --- 7.3 密码强度条 --- */
#sRequirements {
  font-size: 12px;
}
#sRequirements .mt-1 {
  font-size: 11px;
}

/* ============================================
   8. 图表全局 / ECharts Mobile
   ============================================ */
/* 图例在手机端放底部已由脚本控制，这里只做尺寸兜底 */
#historyChart {
  min-height: 280px;
}

} /* END @media (max-width: 767.98px) */

/* ============================================
   平板竖屏补充 (768px - 1024px)
   ============================================ */
@media (min-width: 768px) and (max-width: 1024px) {
  /* 登录页卡片 3→2 列 */
  .landing-page .feature-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  /* 侧边栏收窄 */
  :root {
    --sidebar-width: 200px;
  }
  .sidebar-brand h5 {
    font-size: 13px;
  }
}
