body {
  background: #f4f7fb;
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

/* ---------- 登录页 ---------- */
#loginPage {
  min-height: 100vh;
  background: linear-gradient(135deg, #0d63e0 0%, #094aaf 100%);
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
/* 装饰性背景图标。码位必须选 FA6 免费版 Solid 里真实存在的，
   否则会渲染成豆腐块 —— f3ed=shield-halved，f6c8=cow */
#loginPage::before {
  content: '\f3ed'; font-family: "Font Awesome 6 Free"; font-weight: 900;
  position: absolute; font-size: 280px; color: rgba(255,255,255,.06);
  top: -30px; left: -50px; z-index: 1;
}
#loginPage::after {
  content: '\f6c8'; font-family: "Font Awesome 6 Free"; font-weight: 900;
  position: absolute; font-size: 220px; color: rgba(255,255,255,.05);
  bottom: -40px; right: -30px; z-index: 1;
}
.login-box {
  width: 100%; max-width: 460px; background: #fff; border-radius: 20px;
  box-shadow: 0 12px 40px rgba(0,0,0,.15); padding: 50px 40px;
  position: relative; z-index: 2;
}
.login-box .logo-area { text-align: center; margin-bottom: 30px; }
.login-box .logo-area h4 { font-size: 22px; font-weight: 700; color: #0d47a1; margin-bottom: 8px; }
.login-box .logo-area p { color: #666; font-size: 14px; margin: 0; }
.login-box .icon-group {
  display: flex; justify-content: center; gap: 20px;
  margin-bottom: 25px; color: #0d6efd; font-size: 24px;
}
.login-box .form-label { font-weight: 500; color: #333; }
.login-box .form-control { border-radius: 10px; padding: 12px 15px; border: 1px solid #ced4da; }
.btn-login {
  background: linear-gradient(90deg, #0d63e0, #094aaf); color: #fff;
  border-radius: 10px; padding: 12px; font-weight: 600; margin-top: 10px; border: none;
}
.btn-login:hover { background: #0946a2; color: #fff; }
.btn-login:disabled { opacity: .6; }

/* ---------- 主体 ---------- */
.app-header {
  background: linear-gradient(90deg, #0d63e0, #094aaf);
  color: #fff; padding: 16px 28px;
}
.app-header h4 { margin: 0; font-size: 20px; font-weight: 600; }
.user-info { font-size: 14px; }

.stat-box {
  background: #fff; border-radius: 14px; padding: 18px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05); text-align: center;
  transition: transform .2s, box-shadow .2s;
}
.stat-box:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0,0,0,.08); }
.stat-box p { font-size: 13px; }
.stat-box h4 { margin: 0; font-weight: 700; }

.card { border: none; border-radius: 16px; box-shadow: 0 2px 12px rgba(0,0,0,.05); }
.card-header { background: transparent; border: none; font-weight: 600; color: #0d47a1; padding: 0 0 8px; }
.nav-pills .nav-link { cursor: pointer; color: #444; border-radius: 10px; }
.nav-pills .nav-link.active { background: #0d63e0; color: #fff; }

.form-control, .form-select { border-radius: 10px; border: 1px solid #dee2e6; }
.table thead th { font-size: 13px; color: #555; white-space: nowrap; }
.table td { font-size: 13px; vertical-align: middle; }
.row-warning { background: #fff8e1 !important; }
.row-danger  { background: #ffebee !important; }
.row-void    { opacity: .55; text-decoration: line-through; }

/* ---------- 消息条 ---------- */
#msgBox {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 9999; min-width: 320px; max-width: 80vw; display: none;
  padding: 12px 20px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.15);
  font-size: 14px; text-align: center;
}

/* ---------- 牧户搜索下拉 ---------- */
.combo-box { position: relative; }
.combo-box .arrow-icon {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: #666; pointer-events: none;
}
.dropdown-list {
  display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 1000;
  background: #fff; border: 1px solid #dee2e6; border-radius: 10px; margin-top: 4px;
  max-height: 280px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,.12);
}
.dropdown-list .dropdown-item {
  padding: 9px 14px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid #f2f2f2; white-space: normal;
}
.dropdown-list .dropdown-item:last-child { border-bottom: none; }
.dropdown-list .dropdown-item:hover { background: #eef4ff; }
.dropdown-list .empty { padding: 14px; color: #888; font-size: 13px; text-align: center; }

/* ---------- 开票面板 ---------- */
.invoice-panel .invoice-card-body { padding: 8px 4px 4px; }
.invoice-label { font-size: 13px; font-weight: 500; color: #444; margin-bottom: 5px; display: block; }
.form-group-icon { position: relative; }
.form-group-icon .input-icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #0d6efd;
}
.form-group-icon .form-control, .form-group-icon .form-select { padding-left: 38px; }

.chart-card canvas { min-height: 300px; max-height: 340px; }

/* 按角色显隐。登录后 body 会被打上 as-admin / as-hall / as-company。
   body 的类必须用 as- 前缀，不能和元素级的 .role-hall / .role-company 同名，
   否则 body 自己会命中下面的隐藏规则，整页变空白。
   用 revert 而不是 block —— 让 li 回到 list-item、td 回到 table-cell，
   否则表格和导航的布局会错乱。 */
.admin-only, .role-hall, .role-company { display: none !important; }
body.as-admin   .admin-only,
body.as-hall    .role-hall,
body.as-company .role-company { display: revert !important; }
.pager { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; }

/* ==================== 耳标录入 ==================== */
.earmark-box {
  border: 1px solid #dee2e6; border-radius: 12px; padding: 12px; background: #fbfcfe;
}
.earmark-counter {
  float: right; font-weight: 600; color: #0d6efd;
  background: #eaf1ff; border-radius: 20px; padding: 1px 12px; font-size: 12px;
}
.earmark-counter.done { color: #0f5132; background: #d1e7dd; }
.earmark-counter.over { color: #842029; background: #f8d7da; }

.earmark-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 8px; }
.earmark-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #cfe0ff; color: #0d47a1;
  border-radius: 20px; padding: 5px 6px 5px 12px;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.earmark-chip.dup { border-color: #f5c2c7; background: #fff5f5; color: #842029; }
.earmark-chip .rm {
  border: none; background: #eef2f7; color: #667;
  width: 20px; height: 20px; border-radius: 50%; line-height: 1;
  font-size: 13px; cursor: pointer; padding: 0;
}
.earmark-chip .rm:hover { background: #dc3545; color: #fff; }

.btn-scan { white-space: nowrap; }
#scanRegion { background: #000; min-height: 240px; }
#scanRegion video { width: 100% !important; display: block; }
.scan-recent { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.scan-recent span {
  font-size: 12px; background: #d1e7dd; color: #0f5132;
  border-radius: 12px; padding: 2px 9px; font-variant-numeric: tabular-nums;
}

/* ==================== 底部导航（仅手机）==================== */
#bottomNav { display: none; }

/* ==================== 手机适配 ==================== */
@media (max-width: 768px) {

  /* --- 顶部与整体间距 --- */
  .app-header { padding: 12px 14px; }
  .app-header h4 { font-size: 15px; }
  .app-header .user-info { font-size: 12px; gap: 4px !important; }
  .app-header .user-info .btn { padding: 3px 8px; font-size: 12px; }
  .container-fluid { padding: 12px !important; }

  /* 给底部导航让位，含 iPhone 安全区 */
  body.logged-in #mainPage { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }

  .stat-box { padding: 12px 8px; border-radius: 12px; }
  .stat-box p { font-size: 11px; margin-bottom: 2px !important; }
  .stat-box h4 { font-size: 18px; }

  /* 顶部胶囊导航在手机上收起，改用底部导航 */
  #navTabs { display: none !important; }

  /* 登录后才显示底部导航，登录页上不该出现 */
  body.logged-in #bottomNav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    background: #fff; border-top: 1px solid #e6e9ee;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  }
  #bottomNav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: 8px 2px 6px; color: #8a94a6; font-size: 11px;
    text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  #bottomNav a i { font-size: 17px; }
  #bottomNav a.active { color: #0d63e0; }
  /* 管理入口对非管理员隐藏，规则同 .admin-only，但要保持 flex 布局 */
  body.as-admin #bottomNav a.admin-only { display: flex !important; }

  /* --- 表格转卡片 ---
     每行变成一张卡，单元格左侧用 data-label 显示表头。
     没有 data-label 的单元格（比如操作按钮列）单独占一行。 */
  .table-responsive { padding: 8px !important; }
  .card-mobile thead { display: none; }
  .card-mobile, .card-mobile tbody, .card-mobile tr, .card-mobile td { display: block; width: 100%; }
  .card-mobile tr {
    border: 1px solid #e6e9ee; border-radius: 12px;
    margin-bottom: 10px; padding: 10px 12px; background: #fff;
  }
  .card-mobile tr.row-warning { background: #fff8e1 !important; }
  .card-mobile tr.row-danger  { background: #ffebee !important; }
  .card-mobile td {
    border: none !important; padding: 4px 0 !important;
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    font-size: 13px;
  }
  .card-mobile td::before {
    content: attr(data-label); color: #8a94a6; font-size: 12px;
    flex-shrink: 0; font-weight: 500;
  }
  /* 第一列（姓名/发票号）当卡片标题 */
  .card-mobile td.cell-title {
    font-size: 15px; font-weight: 600; color: #0d47a1;
    border-bottom: 1px dashed #e6e9ee !important;
    padding-bottom: 8px !important; margin-bottom: 4px;
  }
  .card-mobile td.cell-title::before { content: none; }
  .card-mobile td.cell-actions { justify-content: flex-end; padding-top: 8px !important; }
  .card-mobile td.cell-actions::before { content: none; }
  .card-mobile td.cell-wide { flex-direction: column; align-items: flex-start; gap: 2px; }
  .card-mobile td.cell-wide::before { font-size: 11px; }

  /* --- 表单 --- */
  .invoice-label { font-size: 12px; }
  .form-control, .form-select { font-size: 16px; }  /* 16px 以下 iOS 会自动放大页面 */
  .modal-dialog { margin: 8px; }
  .modal-body { padding: 16px !important; }

  /* --- 卡片头部按钮组换行 --- */
  .card-header { flex-wrap: wrap; gap: 8px; }
  .card-header .btn { font-size: 12px; }

  /* 图表在手机上竖排 */
  .chart-card canvas { min-height: 260px; }

  /* 提示条避开顶部 */
  #msgBox { min-width: 0; width: calc(100vw - 24px); top: 12px; }
}

/* 极窄屏（小屏手机） */
@media (max-width: 380px) {
  .stat-box h4 { font-size: 16px; }
  #bottomNav a { font-size: 10px; }
  .earmark-chip { font-size: 12px; }
}
