/* ============================================================
   雅创智园智慧种植物联网管理平台 V4.0 —— 移动端 APP 样式
   深色科技风沿用 V3 视觉语言，信息架构改为"水链优先"
   ============================================================ */
:root {
  --bg: #08111f;
  --bg-2: #0b1728;
  --panel: #0f1e33;
  --panel-2: #14263f;
  --line: rgba(0, 212, 255, 0.16);
  --line-soft: rgba(139, 163, 199, 0.14);
  --cyan: #00d4ff;
  --cyan-dim: rgba(0, 212, 255, 0.12);
  --green: #4ade80;
  --amber: #fbbf24;
  --red: #f87171;
  --purple: #a78bfa;
  --text: #e6f4ff;
  --dim: #8ba3c7;
  --dim-2: #5f7799;
  --radius: 14px;
  --nav-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 关键：hidden 属性必须优先于组件的 display:flex/grid，否则弹层会默认显示 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  max-width: 100%; overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  background-image:
    radial-gradient(900px 420px at 12% -8%, rgba(0, 212, 255, 0.16), transparent 62%),
    radial-gradient(700px 380px at 92% 4%, rgba(74, 222, 128, 0.10), transparent 60%);
  background-attachment: fixed;
}

.app { min-height: 100vh; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 8px); }

/* ---------------- 顶部栏 ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 10px) 14px 10px;
  background: linear-gradient(180deg, rgba(8, 17, 31, 0.96), rgba(8, 17, 31, 0.78));
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.topbar-right { flex: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center;
  font-weight: 700; font-size: 17px; color: #04121f;
  background: linear-gradient(135deg, var(--cyan), var(--green));
  box-shadow: 0 4px 14px rgba(0, 212, 255, 0.28);
}
.brand-title { font-size: 15.5px; font-weight: 700; letter-spacing: 0.5px; }
.brand-sub { font-size: 10.5px; color: var(--dim); letter-spacing: 0.3px; }
.topbar-right { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  position: relative; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent;
  color: var(--text); font-size: 16px; cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.06); }
.icon-btn .badge {
  position: absolute; top: 2px; right: 0;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--red); color: #2a0505;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
#refreshIco.spin { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 提示条 ---------------- */
.notice-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 8px 12px 0; padding: 8px 11px;
  border-radius: 10px; font-size: 11.5px;
  background: rgba(251, 191, 36, 0.10);
  border: 1px solid rgba(251, 191, 36, 0.32);
  color: #fde68a;
}
.notice-bar.demo { background: rgba(167, 139, 250, 0.10); border-color: rgba(167, 139, 250, 0.32); color: #ddd6fe; }
.notice-bar.hos { background: rgba(76, 141, 255, 0.10); border-color: rgba(76, 141, 255, 0.32); color: #c7dbff; }
.dot-hos { width: 7px; height: 7px; border-radius: 50%; flex: none; background: #4c8dff; }
.hos-text { flex: 1; line-height: 1.5; }
.notice-x {
  flex: none; width: 20px; height: 20px; padding: 0;
  border: none; border-radius: 6px; cursor: pointer;
  background: rgba(255, 255, 255, 0.09); color: inherit;
  font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.dot-warn, .dot-demo { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot-warn { background: var(--amber); }
.dot-demo { background: var(--purple); }

/* ---------------- 视图与通用卡片 ---------------- */
.view { padding: 10px 12px 4px; animation: fadeup 0.26s ease; }
@keyframes fadeup { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: linear-gradient(160deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 12px 13px;
  margin-bottom: 10px;
}
.card.hl { border-color: var(--line); box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.card-title { font-size: 13.5px; font-weight: 600; letter-spacing: 0.3px; }
.card-sub { font-size: 10.5px; color: var(--dim-2); }
.card-link { font-size: 11.5px; color: var(--cyan); text-decoration: none; }
.card-link:active { opacity: 0.6; }

.section-label {
  display: flex; align-items: center; gap: 7px;
  margin: 14px 2px 8px; font-size: 12px; color: var(--dim);
  letter-spacing: 0.6px;
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }

/* ---------------- 告警条 ---------------- */
.alert-strip {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 12px; margin-bottom: 10px;
  border-radius: 12px; font-size: 12.5px; cursor: pointer;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca;
}
.alert-strip.warn { background: rgba(251, 191, 36, 0.10); border-color: rgba(251, 191, 36, 0.36); color: #fde68a; }
.alert-strip .as-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-strip .as-go { font-size: 11px; opacity: 0.8; }

/* ---------------- 水链 ---------------- */
.chain-scroll {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 2px 2px 8px; margin: 0 -2px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.chain-scroll::-webkit-scrollbar { height: 0; }
.chain-node {
  flex: 0 0 auto; width: 128px; scroll-snap-align: start;
  background: linear-gradient(165deg, var(--panel-2), #0c1a2c);
  border: 1px solid var(--line-soft);
  border-radius: 12px; padding: 10px 10px 9px;
  position: relative; cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.chain-node:active { transform: scale(0.97); }
.chain-node.ok { border-color: rgba(74, 222, 128, 0.34); }
.chain-node.alert { border-color: rgba(248, 113, 113, 0.55); box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.18), 0 6px 16px rgba(248, 113, 113, 0.12); }
.chain-node.offline { opacity: 0.62; border-style: dashed; }
.cn-top { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.cn-seq {
  width: 17px; height: 17px; border-radius: 5px; flex: none;
  background: var(--cyan-dim); color: var(--cyan);
  font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
.cn-name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cn-zone { font-size: 9.5px; color: var(--dim-2); margin-bottom: 6px; }
.cn-metrics { display: flex; flex-direction: column; gap: 3px; }
.cn-metric { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.cn-metric .k { font-size: 9.5px; color: var(--dim-2); white-space: nowrap; }
.cn-metric .v { font-size: 12px; font-weight: 700; color: var(--cyan); font-variant-numeric: tabular-nums; }
.cn-foot { display: flex; align-items: center; gap: 5px; margin-top: 7px; font-size: 9.5px; color: var(--dim-2); }
.cn-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
.chain-node.alert .cn-dot { background: var(--red); }
.chain-node.offline .cn-dot { background: var(--dim-2); }
.chain-arrow { display: flex; align-items: center; color: var(--dim-2); font-size: 12px; flex: none; }

.chain-hint { font-size: 10.5px; color: var(--dim-2); text-align: center; margin: 2px 0 4px; }

/* ---------------- KPI ---------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 12px; padding: 10px 11px;
}
.kpi-label { font-size: 10.5px; color: var(--dim); margin-bottom: 3px; }
.kpi-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.3px; }
.kpi-value small { font-size: 10.5px; font-weight: 400; color: var(--dim); margin-left: 3px; }
.kpi.c-cyan .kpi-value { color: var(--cyan); }
.kpi.c-green .kpi-value { color: var(--green); }
.kpi.c-amber .kpi-value { color: var(--amber); }
.kpi.c-text .kpi-value { color: var(--text); }

/* ---------------- 列表 ---------------- */
.list { display: flex; flex-direction: column; gap: 7px; }
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 11px; border-radius: 11px;
  background: var(--panel); border: 1px solid var(--line-soft);
}
.row:active { background: var(--panel-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.row-sub { font-size: 10.5px; color: var(--dim-2); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-value { font-size: 14px; font-weight: 700; color: var(--cyan); font-variant-numeric: tabular-nums; text-align: right; }
.row-value small { display: block; font-size: 9.5px; color: var(--dim-2); font-weight: 400; }
.row-arrow { color: var(--dim-2); font-size: 13px; }

.pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 7px; border-radius: 999px; font-size: 9.5px; font-weight: 600;
  border: 1px solid transparent; white-space: nowrap;
}
.pill.on { background: rgba(74, 222, 128, 0.14); color: var(--green); border-color: rgba(74, 222, 128, 0.34); }
.pill.off { background: rgba(139, 163, 199, 0.12); color: var(--dim); border-color: rgba(139, 163, 199, 0.24); }
.pill.warn { background: rgba(251, 191, 36, 0.14); color: var(--amber); border-color: rgba(251, 191, 36, 0.34); }
.pill.danger { background: rgba(248, 113, 113, 0.14); color: var(--red); border-color: rgba(248, 113, 113, 0.36); }
.pill.info { background: rgba(0, 212, 255, 0.12); color: var(--cyan); border-color: rgba(0, 212, 255, 0.3); }

/* ---------------- 按钮 ---------------- */
.btn {
  appearance: none; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2); color: var(--text);
  padding: 9px 14px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(135deg, var(--cyan), #22b8d8); color: #04121f; border-color: transparent; }
.btn.ghost { background: transparent; color: var(--dim); border-color: var(--line-soft); }
.btn.danger { background: rgba(248, 113, 113, 0.16); color: #fecaca; border-color: rgba(248, 113, 113, 0.42); }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 11px; font-size: 11.5px; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

/* ---------------- 表单 ---------------- */
.field { margin-bottom: 11px; }
.field label { display: block; font-size: 11px; color: var(--dim); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 11px;
  background: #0a1828; border: 1px solid var(--line-soft); border-radius: 10px;
  color: var(--text); font-size: 13px; font-family: inherit; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--cyan); }
.field .hint { font-size: 10px; color: var(--dim-2); margin-top: 4px; }
.field-row { display: flex; gap: 8px; }
.field-row .field { flex: 1; }

/* ---------------- 图表 ---------------- */
.chart-box { width: 100%; height: 132px; }
.chart-box svg { width: 100%; height: 100%; display: block; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; font-size: 10px; color: var(--dim-2); }
.chart-legend i { display: inline-block; width: 8px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.chart-empty { height: 132px; display: grid; place-items: center; color: var(--dim-2); font-size: 11.5px; }

/* ---------------- 底部导航 ---------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: stretch;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(9, 20, 35, 0.94);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line-soft);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--dim-2);
  font-size: 10px; letter-spacing: 0.4px;
  transition: color 0.15s ease;
}
.tab-ico { font-size: 17px; line-height: 1; filter: grayscale(0.6); opacity: 0.8; }
.tab.active { color: var(--cyan); }
.tab.active .tab-ico { filter: none; opacity: 1; transform: translateY(-1px); }

/* ---------------- 悬浮球 ---------------- */
.fab {
  position: fixed; right: 16px; z-index: 41;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 50px; height: 50px; border-radius: 50%;
  border: none; cursor: pointer;
  background: linear-gradient(140deg, var(--cyan), var(--green));
  color: #04121f; font-weight: 800; font-size: 13px;
  box-shadow: 0 8px 22px rgba(0, 212, 255, 0.34);
}
.fab:active { transform: scale(0.94); }

/* ---------------- 弹层 ---------------- */
.mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(3, 9, 18, 0.66);
  backdrop-filter: blur(2px);
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg-2);
  border-radius: 18px 18px 0 0;
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  animation: slideup 0.24s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes slideup { from { transform: translateY(28px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--line-soft); margin: 7px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px 6px; }
.sheet-title { font-size: 14px; font-weight: 700; }
.sheet-body { padding: 4px 14px 10px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 8px 14px 14px; border-top: 1px solid var(--line-soft); }

.dialog { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 22px; background: rgba(3, 9, 18, 0.7); }
.dialog-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; animation: fadeup 0.2s ease; }
.dialog-title { font-size: 14.5px; font-weight: 700; margin-bottom: 8px; }
.dialog-body { font-size: 12.5px; color: var(--dim); line-height: 1.7; }
.dialog-actions { display: flex; gap: 8px; margin-top: 15px; }
.dialog-actions .btn { flex: 1; }

/* ---------------- Toast ---------------- */
.toast-wrap {
  position: fixed; left: 0; right: 0; z-index: 70;
  bottom: calc(var(--nav-h) + var(--safe-b) + 76px);
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  pointer-events: none;
}
.toast {
  max-width: 88%; padding: 9px 14px; border-radius: 10px;
  background: rgba(20, 38, 63, 0.97);
  border: 1px solid var(--line);
  font-size: 12px; color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: fadeup 0.2s ease;
}
.toast.err { border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }
.toast.ok { border-color: rgba(74, 222, 128, 0.5); color: #bbf7d0; }

/* ---------------- 聊天 ---------------- */
.chat {
  position: fixed; inset: 0; z-index: 55;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.chat-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-t) + 12px) 14px 10px;
  border-bottom: 1px solid var(--line-soft);
}
.chat-title { font-size: 15px; font-weight: 700; }
.chat-sub { font-size: 10.5px; color: var(--dim-2); }
.chat-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; }
.msg.me { justify-content: flex-end; }
.bubble {
  max-width: 84%; padding: 10px 12px; border-radius: 12px;
  font-size: 13px; line-height: 1.65; white-space: pre-wrap; word-break: break-word;
}
.msg.bot .bubble { background: var(--panel); border: 1px solid var(--line-soft); border-bottom-left-radius: 4px; }
.msg.me .bubble { background: linear-gradient(135deg, var(--cyan), #22b8d8); color: #04121f; border-bottom-right-radius: 4px; }
.msg.typing .bubble { color: var(--dim); }
.chat-quick { display: flex; gap: 7px; overflow-x: auto; padding: 0 14px 8px; }
.chat-quick::-webkit-scrollbar { height: 0; }
.chip {
  flex: none; padding: 6px 11px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line-soft);
  color: var(--dim); font-size: 11.5px; font-family: inherit; cursor: pointer;
}
.chat-input {
  display: flex; gap: 8px; padding: 8px 14px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line-soft); background: var(--bg-2);
}
.chat-input input {
  flex: 1; padding: 11px 13px; border-radius: 11px;
  background: #0a1828; border: 1px solid var(--line-soft);
  color: var(--text); font-size: 13px; outline: none; font-family: inherit;
}

/* ---------------- 骨架屏 ---------------- */
.skeleton-wrap { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.sk {
  height: 74px; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--panel) 20%, var(--panel-2) 40%, var(--panel) 60%);
  background-size: 220% 100%;
  animation: shimmer 1.3s infinite linear;
}
.sk-lg { height: 118px; }
.sk-row { display: flex; gap: 10px; }
.sk-row .sk { flex: 1; height: 78px; }
@keyframes shimmer { from { background-position: 140% 0; } to { background-position: -40% 0; } }

/* ---------------- 状态与工具 ---------------- */
.empty { text-align: center; padding: 26px 10px; color: var(--dim-2); font-size: 12px; }
.empty .ico { display: block; font-size: 26px; margin-bottom: 7px; opacity: 0.6; }
.muted { color: var(--dim-2); }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, Consolas, monospace; }
.hr { height: 1px; background: var(--line-soft); margin: 10px 0; }
.tag-quality { font-size: 9px; padding: 0 4px; border-radius: 4px; background: rgba(251, 191, 36, 0.16); color: var(--amber); margin-left: 4px; }
.lvl-info { color: var(--cyan); }
.lvl-warning { color: var(--amber); }
.lvl-critical { color: var(--red); }
.mini-note { font-size: 10.5px; color: var(--dim-2); line-height: 1.65; margin-top: 8px; }

@media (min-width: 720px) {
  .app { max-width: 520px; margin: 0 auto; box-shadow: 0 0 60px rgba(0, 0, 0, 0.5); }
  .tabbar { max-width: 520px; margin: 0 auto; }
  .fab { right: calc(50% - 260px + 16px); }
}
