/* ============================================================
   鸡场鸡舍笼位管理系统 - H5 样式（移动端优先）
   ============================================================ */
:root {
  --green: #0a9d58;
  --green-dk: #077a44;
  --green-lt: #e6f5ee;
  --bg: #f4f6f8;
  --card: #ffffff;
  --line: #e8ecef;
  --txt: #232a32;
  --txt2: #7a8794;
  --red: #e5484d;
  --orange: #f08c1a;
  --blue: #2d7ff9;
  --purple: #8b5cf6;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(20, 40, 60, .06);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg); color: var(--txt); font-size: 15px; line-height: 1.5;
  padding-bottom: 62px; /* tabbar */
}
a { color: var(--green); text-decoration: none; }
img { max-width: 100%; }
.tabbar svg, .quick .ic svg {
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(135deg, var(--green) 0%, #0b8a50 100%);
  color: #fff; box-shadow: var(--shadow);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.topbar-title { font-size: 17px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.user-chip { opacity: .95; }
.link-logout { color: #fff; opacity: .8; }

/* ---------- 主体 ---------- */
.app { max-width: 760px; margin: 0 auto; padding: 14px 14px 30px; }
.muted { color: var(--txt2); font-size: 13px; }
.right { text-align: right; }
.mb10 { margin-bottom: 10px; } .mb14 { margin-bottom: 14px; }
.flex { display: flex; align-items: center; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 12px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }

/* 统计卡 */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.stat {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 8px; text-align: center;
}
.stat .num { font-size: 22px; font-weight: 700; color: var(--green); line-height: 1.2; }
.stat .num.warn { color: var(--orange); } .stat .num.bad { color: var(--red); } .stat .num.info { color: var(--blue); }
.stat .lbl { font-size: 12px; color: var(--txt2); margin-top: 2px; }

/* 趋势图（纯 CSS 柱状） */
.trend { display: flex; align-items: flex-end; gap: 8px; height: 110px; padding-top: 8px; }
.trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.trend .bar { width: 60%; max-width: 34px; background: linear-gradient(180deg, #17b26a, var(--green)); border-radius: 6px 6px 2px 2px; min-height: 2px; transition: height .4s; }
.trend .v { font-size: 10px; color: var(--txt2); margin-bottom: 2px; }
.trend .d { font-size: 10px; color: var(--txt2); margin-top: 4px; }

/* 快捷入口 */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.quick a { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 4px; text-align: center; color: var(--txt); }
.quick .ic { width: 40px; height: 40px; margin: 0 auto 6px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #fff; }
.quick .ic svg { width: 20px; height: 20px; }
.ic.g { background: linear-gradient(135deg, #17b26a, var(--green)); }
.ic.b { background: linear-gradient(135deg, #4d9df8, var(--blue)); }
.ic.o { background: linear-gradient(135deg, #ffb04d, var(--orange)); }
.ic.p { background: linear-gradient(135deg, #a78bfa, var(--purple)); }
.quick .t { font-size: 12px; }

/* ---------- 列表项 ---------- */
.item {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 14px; margin-bottom: 10px;
}
.item .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.item .name { font-weight: 600; font-size: 15px; word-break: break-all; }
.item .sub { color: var(--txt2); font-size: 12.5px; margin-top: 4px; }
.item .acts { display: flex; gap: 8px; margin-top: 10px; }

/* 徽标/状态点 */
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; line-height: 1.6; white-space: nowrap;
}
.chip.ok    { background: var(--green-lt); color: var(--green-dk); }
.chip.warn  { background: #fdf1e2; color: #c97a10; }
.chip.bad   { background: #fdebec; color: var(--red); }
.chip.info  { background: #e8f1fe; color: #1f6fe0; }
.chip.mute  { background: #eef1f4; color: #5b6875; }
.chip.plain { background: #f2f4f6; color: var(--txt2); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  border: none; border-radius: 10px; cursor: pointer; font-size: 14px;
  padding: 10px 18px; background: var(--green); color: #fff; font-family: inherit;
  transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn.block { width: 100%; }
.btn.plain { background: #fff; color: var(--green); border: 1px solid var(--green); }
.btn.gray  { background: #eef1f4; color: var(--txt); }
.btn.red   { background: var(--red); }
.btn.sm    { padding: 5px 12px; font-size: 12.5px; border-radius: 8px; }
.btn.sm.plain { border: 1px solid #d6dce2; color: var(--txt2); background: #fff; }
.btn.light { background: rgba(255,255,255,.18); color: #fff; }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--txt2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--txt); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--green); }
.field textarea { min-height: 70px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--txt2); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* 筛选条 */
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters select, .filters input {
  flex: 1; min-width: 90px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; background: #fff; font-family: inherit; color: var(--txt);
}

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
  background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 6px; color: var(--txt2); font-size: 10.5px;
}
.tabbar a.on { color: var(--green); }
.tabbar svg { width: 21px; height: 21px; }

/* ---------- 弹层 ---------- */
.mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 80;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  background: #fff; border-radius: 16px 16px 0 0;
  max-height: 86vh; overflow-y: auto;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  animation: up .22s ease;
}
@keyframes up { from { transform: translateY(30%); opacity: .4; } to { transform: none; opacity: 1; } }
@media (min-width: 500px) { .sheet { left: 50%; right: auto; width: 460px; margin-left: -230px; border-radius: 16px; bottom: 40px; } }
.sheet h3 { font-size: 16px; margin-bottom: 14px; text-align: center; }
.sheet .sheet-acts { display: flex; gap: 10px; margin-top: 16px; }
.sheet .sheet-acts .btn { flex: 1; }

/* 类型选择 chips */
.type-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.type-pick button {
  padding: 8px 2px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  font-size: 13px; color: var(--txt); font-family: inherit; cursor: pointer;
}
.type-pick button.on { border-color: var(--green); background: var(--green-lt); color: var(--green-dk); font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 42%; left: 50%; transform: translateX(-50%);
  background: rgba(20,25,30,.86); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; z-index: 100; max-width: 80vw; text-align: center; word-break: break-all;
}
.toast.err { background: rgba(200,40,45,.92); }

/* ---------- 空状态 / 加载 ---------- */
.empty { text-align: center; color: var(--txt2); padding: 40px 0; font-size: 14px; }
.empty .e { font-size: 40px; margin-bottom: 8px; opacity: .4; }
.loading { text-align: center; color: var(--txt2); padding: 14px; font-size: 13px; }

/* ---------- 登录页 ---------- */
.login-wrap { max-width: 400px; margin: 60px auto 0; padding: 0 18px; }
.login-logo { text-align: center; margin-bottom: 26px; }
.login-logo .ico {
  width: 74px; height: 74px; margin: 0 auto 12px; border-radius: 22px;
  background: linear-gradient(135deg, #17b26a, var(--green));
  display: flex; align-items: center; justify-content: center; font-size: 38px; color: #fff;
  box-shadow: 0 6px 18px rgba(10,157,88,.35);
}
.login-logo h1 { font-size: 20px; }
.login-logo p { color: var(--txt2); font-size: 13px; margin-top: 4px; }

/* ---------- AI 诊断 ---------- */
.ai-photo-box {
  border: 1.5px dashed #c7d2cc; border-radius: 14px; background: #f9fbfa;
  min-height: 150px; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 8px; color: var(--txt2); cursor: pointer; overflow: hidden;
}
.ai-photo-box img { width: 100%; display: block; }
.conf-bar { height: 8px; border-radius: 999px; background: #eef1f4; overflow: hidden; }
.conf-bar i { display: block; height: 100%; background: linear-gradient(90deg, #ffb04d, var(--orange)); border-radius: 999px; }
.advice-list { list-style: none; }
.advice-list li { padding: 7px 0 7px 20px; position: relative; border-bottom: 1px dashed #eef1f4; font-size: 14px; }
.advice-list li:last-child { border-bottom: none; }
.advice-list li::before {
  content: ""; position: absolute; left: 4px; top: 14px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--green);
}
.demo-tip { background: #fff8e6; border: 1px solid #f5e3b3; color: #9a7a20; border-radius: 10px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 10px; }

/* ---------- 日志时间线 ---------- */
.timeline { position: relative; padding-left: 18px; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: #e8ecef; border-radius: 2px; }
.tl-item { position: relative; padding: 8px 0 14px; }
.tl-item::before {
  content: ""; position: absolute; left: -17px; top: 14px; width: 10px; height: 10px;
  border-radius: 50%; background: #fff; border: 2.5px solid var(--green);
}
.tl-item .tl-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tl-item .tl-date { color: var(--txt2); font-size: 12px; }
.tl-item .tl-body { font-size: 14px; margin-top: 4px; word-break: break-all; }
.tl-item .tl-imgs { display: flex; gap: 6px; margin-top: 6px; }
.tl-item .tl-imgs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }

/* ---------- 二维码标签与打印 ---------- */
#printArea { display: none; }
@media print {
  body { background: #fff; padding: 0; }
  .topbar, .tabbar, .app, .toast, .mask, .sheet { display: none !important; }
  #printArea { display: block !important; }
  @page { margin: 6mm; }
}
.qr-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.qr-check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 46vh; overflow-y: auto; }
.qr-check { display: flex; align-items: center; gap: 6px; background: #f7f9fa; border-radius: 8px; padding: 6px 8px; font-size: 12.5px; }
.label-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.label {
  border: 1px solid #333; border-radius: 6px; padding: 5px 7px; text-align: center;
  break-inside: avoid; page-break-inside: avoid; background: #fff; display: flex; flex-direction: column; align-items: center;
}
.label .l-farm { font-size: 11px; font-weight: 600; }
.label .l-code { font-size: 12px; font-weight: 700; letter-spacing: .3px; }
.label .l-pos { font-size: 10px; color: #444; }
.label img { display: block; }
.label.lv1 { width: 37mm; height: 58mm; } .label.lv1 img { width: 30mm; height: 30mm; }
.label.lv2 { width: 46mm; height: 67mm; } .label.lv2 img { width: 38mm; height: 38mm; }
.label.lv3 { width: 56mm; height: 87mm; } .label.lv3 img { width: 48mm; height: 48mm; }

/* ---------- 设置页 tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button {
  flex: 1; padding: 9px 0; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; font-size: 14px; color: var(--txt2); font-family: inherit; cursor: pointer;
}
.tabs button.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.user-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.user-table th, .user-table td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: left; word-break: break-all; }
.user-table th { color: var(--txt2); font-weight: 500; }

/* 桌面适配 */
@media (min-width: 760px) {
  body { font-size: 15px; }
  .app { padding: 20px 20px 40px; }
}

/* ============================================================
   v2：巡舍模式 / 大按钮 / 数字键盘 / 场切换
   ============================================================ */

/* 顶栏场切换 */
.farm-switch { position: relative; }
.farm-name-btn { display: flex; align-items: center; gap: 3px; color: #fff; font-size: 13px; background: rgba(255,255,255,.16); border-radius: 8px; padding: 4px 9px; border: none; }
.farm-menu {
  position: absolute; right: 0; top: 34px; z-index: 95; min-width: 150px;
  background: #fff; border-radius: 10px; box-shadow: 0 4px 20px rgba(0,0,0,.18); overflow: hidden;
}
.farm-menu-item { display: block; padding: 10px 14px; color: var(--txt); font-size: 14px; border-bottom: 1px solid var(--line); }
.farm-menu-item:last-child { border-bottom: none; }
.farm-menu-item.on { color: var(--green); font-weight: 600; }
.farm-menu-item::after { content: " ✓"; color: var(--green); float: right; }
.farm-menu-item:not(.on)::after { content: ""; }

/* 大按钮（巡舍操作，≥56px 高） */
.big-btn {
  flex: 1; min-width: 0; border: none; border-radius: 12px; cursor: pointer;
  padding: 9px 2px; font-size: 13px; font-family: inherit; color: #fff; line-height: 1.25;
  display: flex; flex-direction: column; align-items: center; gap: 1px; justify-content: center;
}
.big-btn .bi { font-size: 20px; line-height: 1.2; }
.big-btn:active { transform: scale(.94); }
.big-btn.egg   { background: linear-gradient(135deg, #ffb04d, var(--orange)); }
.big-btn.dead  { background: linear-gradient(135deg, #f77, var(--red)); }
.big-btn.bad   { background: linear-gradient(135deg, #b088f8, var(--purple)); }
.big-btn.ok    { background: linear-gradient(135deg, #2ec97e, var(--green)); }
.big-btn.plain { background: #eef1f4; color: var(--txt2); }
.big-btn.blue  { background: linear-gradient(135deg, #4d9df8, var(--blue)); }
.big-btn-row { display: flex; gap: 8px; margin-top: 10px; }

/* 数字键盘 */
.kpad-display {
  text-align: center; font-size: 40px; font-weight: 700; color: var(--green);
  background: #f4f9f6; border-radius: 12px; padding: 10px 0; margin-bottom: 12px; min-height: 68px;
  letter-spacing: 2px; word-break: break-all;
}
.kpad-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpad-key {
  height: 64px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 24px; font-weight: 600; color: var(--txt); font-family: inherit; cursor: pointer;
}
.kpad-key:active { background: var(--green-lt); border-color: var(--green); }
.kpad-key.gray { font-size: 15px; background: #f2f4f6; }

/* 巡舍：列分组 */
.house-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.house-chips button {
  flex-shrink: 0; padding: 9px 18px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--txt); font-size: 14px; font-family: inherit;
}
.house-chips button.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }

.col-sec { margin-bottom: 14px; }
.col-head {
  display: flex; align-items: center; justify-content: space-between;
  background: #eaf4ef; border-radius: 10px 10px 0 0; padding: 8px 12px;
  border-bottom: 1px dashed #cfe4d8;
}
.col-head .t { font-weight: 700; font-size: 14.5px; color: var(--green-dk); }
.col-head .egg-all { border: none; background: var(--orange); color: #fff; border-radius: 8px; padding: 6px 12px; font-size: 12.5px; font-family: inherit; }
.patrol-cage {
  background: #fff; border-bottom: 1px solid var(--line); padding: 10px 12px;
}
.patrol-cage:last-child { border-radius: 0 0 10px 10px; }
.col-sec .patrol-cage:first-of-type { border-top: none; }
.pc-top { display: flex; align-items: center; gap: 8px; }
.pc-code { font-weight: 700; font-size: 15px; }
.pc-badges { display: flex; gap: 5px; flex-wrap: wrap; }
.pc-note { font-size: 12px; color: var(--txt2); margin-top: 2px; }
.patrol-done { border-left: 3px solid var(--green); background: #fbfffc; }
.col-sec-wrap { background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }

/* 同步条 */
.sync-bar {
  position: sticky; top: 50px; z-index: 40; margin-bottom: 10px;
  background: #fff8e6; border: 1px solid #f5e3b3; border-radius: 10px;
  padding: 8px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px;
}
.sync-bar.hot { background: #e8f1fe; border-color: #bcd6fb; }
.sync-bar .n { font-weight: 700; }

/* 撤销条 */
.undo-toast {
  position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); z-index: 99;
  background: rgba(20,25,30,.9); color: #fff; border-radius: 999px; padding: 8px 8px 8px 16px;
  display: flex; align-items: center; gap: 10px; font-size: 13.5px; white-space: nowrap;
}
.undo-toast button { border: none; background: var(--orange); color: #fff; border-radius: 999px; padding: 5px 14px; font-size: 13px; font-family: inherit; }

/* 报表 SVG */
.chart-box { width: 100%; overflow-x: auto; }
.chart-box svg { min-width: 100%; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--txt2); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }

.ratio-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ratio-table th, .ratio-table td { padding: 9px 6px; border-bottom: 1px solid var(--line); text-align: center; }
.ratio-table th { color: var(--txt2); font-weight: 500; }
.ratio-table .hl { color: var(--green); font-weight: 700; }

/* 免疫计划 */
.vp-due { border-left: 3px solid var(--red); }
.vp-soon { border-left: 3px solid var(--orange); }
.vp-done { opacity: .65; }
