:root {
  --bg: #e9f0eb;
  --paper: #f5f8f5;
  --card: #ffffff;
  --ink: #18261e;
  --muted: #6c7d72;
  --line: #e1eae3;
  --green: #176b46;
  --green-2: #2f9e66;
  --green-soft: #e5f4ec;
  --amber: #b97712;
  --amber-soft: #fff5e2;
  --red: #b93b2e;
  --red-soft: #fdecea;
  --blue: #2f65a5;
  --blue-soft: #eaf2fb;
  --radius: 18px;
  --shadow: 0 10px 24px rgba(28, 70, 48, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 15% 0%, #d7eadf 0%, transparent 60%),
    radial-gradient(700px 400px at 90% 100%, #dce9f4 0%, transparent 55%),
    #e8efea;
  color: var(--ink);
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }

.phone {
  width: min(430px, 100%);
  height: 100vh;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 30px 90px rgba(19, 53, 37, .18);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
@media (min-width: 700px) {
  .phone { height: calc(100vh - 48px); min-height: calc(100vh - 48px); margin: 24px auto; border-radius: 30px; }
}

.app-top {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 14px;
  background: linear-gradient(135deg, #0f4f35, #1f7a4d 58%, #35a06b);
  color: #fff;
  position: sticky; top: 0; z-index: 10;
}
.back {
  width: 34px; height: 34px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.1); color: #fff; border-radius: 10px;
  cursor: pointer; font-size: 18px; line-height: 1;
}
.back.hidden { visibility: hidden; }
.titles { min-width: 0; flex: 1; }
.titles h1 { margin: 0; font-size: 17px; letter-spacing: .3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.titles p { margin: 4px 0 0; font-size: 10.5px; color: #c6e4d3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 11px; background: #e8f8ee; color: #14563f;
  display: grid; place-items: center; font-weight: 800; font-size: 13px; overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.profile-card { background: linear-gradient(140deg, #ffffff, #f1faf5); border: 1px solid var(--line); border-radius: 20px; padding: 18px; text-align: center; margin-bottom: 12px; }
.profile-card h2 { margin: 9px 0 4px; font-size: 18px; }
.profile-card p { margin: 0 0 8px; color: var(--muted); font-size: 10.5px; }
.avatar-edit { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.avatar-edit .user-avatar { width: 76px; height: 76px; font-size: 28px; border: 3px solid #fff; box-shadow: 0 6px 18px rgba(30, 70, 50, .14); border-radius: 22px; }
.avatar-edit span { color: var(--green); font-size: 10.5px; font-weight: 700; }
.profile-card .kind-badge { margin-top: 3px; }
.ws-dot { width: 7px; height: 7px; border-radius: 50%; background: #91a79a; flex: none; box-shadow: 0 0 0 3px rgba(255,255,255,.13); }
.ws-dot.on { background: #6fe3a1; }
.ws-dot.off { background: #e7b36b; }

.app-view { flex: 1; overflow-y: auto; padding: 14px 14px 16px; }
.loading { padding: 80px 10px; text-align: center; color: var(--muted); font-size: 12px; }

.hero {
  background: linear-gradient(135deg, #ffffff, #f1faf5);
  border: 1px solid #dbe9df; border-radius: 20px; padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.hero .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hero h2 { margin: 0; font-size: 18px; }
.hero .weather { text-align: right; color: var(--muted); font-size: 11px; line-height: 1.7; }
.hero .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.hero .stats div { background: #f7fbf8; border: 1px solid #e3efe7; border-radius: 12px; padding: 9px 10px; }
.hero .stats span { display: block; color: var(--muted); font-size: 10px; }
.hero .stats b { display: block; font-size: 18px; margin-top: 3px; color: var(--green); }

.section-head { display: flex; justify-content: space-between; align-items: center; margin: 18px 2px 10px; }
.section-head h3 { margin: 0; font-size: 14px; }
.section-head a, .section-head button { color: var(--green); font-size: 11.5px; background: none; border: 0; padding: 0; cursor: pointer; }
.section-actions { display: flex; align-items: center; gap: 12px; }
.section-actions button { font-weight: 700; }
.detail-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -2px 2px 10px; }
.detail-actions .btn { flex: 0 0 auto; }
.bind-results { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; max-height: 42vh; overflow: auto; }
.bind-result { display: flex; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 13px; padding: 9px 10px; background: #fbfdfc; }
.bind-info { flex: 1; min-width: 0; }
.bind-info b { display: block; font-size: 12.5px; }
.bind-info small { display: block; color: var(--muted); font-size: 9px; margin-top: 3px; }

.alarm-banner {
  display: flex; gap: 10px; align-items: center; background: var(--amber-soft);
  border: 1px solid #f2dfb7; border-radius: 14px; padding: 11px 13px; margin-bottom: 14px;
}
.alarm-banner .icon { width: 28px; height: 28px; border-radius: 9px; background: #f7d58c; color: #6b4304; display: grid; place-items: center; font-weight: 800; flex: none; }
.alarm-banner b { font-size: 12px; display: block; }
.alarm-banner small { color: #7d5a17; font-size: 10.5px; display: block; margin-top: 3px; }
.alarm-banner.critical { background: var(--red-soft); border-color: #f2c5c0; }
.alarm-banner.critical .icon { background: #f0b1a9; color: #6d1a12; }

.device-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 13px 14px; margin-bottom: 10px; box-shadow: 0 6px 18px rgba(30,70,50,.05);
}
.device-card .top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.device-card .top b { font-size: 14px; }
.device-card .top small { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
.device-card .meta { display: flex; gap: 14px; margin-top: 12px; }
.device-card .meta div { font-size: 10.5px; color: var(--muted); }
.device-card .meta b { display: block; color: var(--ink); font-size: 13px; margin-top: 2px; }
.status { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; padding: 4px 8px; border-radius: 999px; background: var(--green-soft); color: var(--green); font-weight: 700; }
.status::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status.offline { background: var(--red-soft); color: var(--red); }

.device-hero {
  border-radius: 22px; padding: 18px; color: #fff; margin-bottom: 12px;
  background: linear-gradient(140deg, #0e4a33, #1d754b 60%, #35a06b);
  box-shadow: 0 16px 34px rgba(18, 80, 50, .22);
}
.device-hero .row { display: flex; justify-content: space-between; align-items: flex-start; }
.device-hero h2 { margin: 0 0 5px; font-size: 20px; }
.device-hero p { margin: 0; color: #c8e5d5; font-size: 10.5px; }
.device-hero .big { font-size: 26px; font-weight: 800; text-align: right; }
.device-hero .big small { display: block; font-size: 9.5px; color: #b7ddc8; font-weight: 400; margin-top: 3px; }
.device-hero .chips { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 13px; }
.device-hero .chip { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.14); border-radius: 999px; padding: 5px 9px; font-size: 9.5px; color: #d9f1e4; }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 12px; }
.metric-card { background: var(--card); border: 1px solid var(--line); border-radius: 15px; padding: 12px 13px; }
.metric-card span { color: var(--muted); font-size: 10.5px; }
.metric-card b { display: block; font-size: 20px; margin-top: 5px; }
.metric-card small { display: block; color: var(--muted); font-size: 9.5px; margin-top: 3px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px; margin-bottom: 12px; box-shadow: 0 6px 18px rgba(30,70,50,.04); }
.panel .panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.panel .panel-head h3 { margin: 0; font-size: 13.5px; }
.panel .panel-head span { color: var(--muted); font-size: 10px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 10px 12px; border-radius: 11px; font-size: 12px; cursor: pointer;
}
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.danger { background: #fff8f7; color: var(--red); border-color: #f0c9c4; }
.btn.small { padding: 7px 9px; font-size: 10.5px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.control-row { display: flex; gap: 8px; }
.control-row .btn { flex: 1; }

.valve-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.valve {
  border: 1px solid var(--line); background: #fbfdfc; border-radius: 12px;
  padding: 10px 4px; text-align: center; cursor: pointer; color: var(--ink);
}
.valve b { display: block; font-size: 12px; }
.valve span { display: block; font-size: 9px; color: var(--muted); margin-top: 3px; }
.valve.on { background: var(--green); color: #fff; border-color: var(--green); }
.valve.on span { color: #d6efdf; }

.plan-item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px dashed #e7efe9; }
.plan-item:last-child { border-bottom: 0; }
.plan-badge { width: 34px; height: 34px; border-radius: 10px; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-weight: 800; flex: none; }
.plan-item .info { flex: 1; min-width: 0; }
.plan-item b { font-size: 12px; }
.plan-item small { display: block; color: var(--muted); font-size: 9.5px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plan-item .actions { display: flex; gap: 5px; }

.alert-item { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px dashed #e7efe9; }
.alert-item:last-child { border-bottom: 0; }
.alert-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); margin-top: 5px; flex: none; }
.alert-dot.critical { background: var(--red); }
.alert-item b { display: block; font-size: 12px; }
.alert-item small { display: block; color: var(--muted); font-size: 10px; margin-top: 4px; line-height: 1.5; }

.empty { padding: 22px 8px; text-align: center; color: var(--muted); font-size: 11px; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "Cascadia Code", monospace; }

.bottom-nav {
  flex: none; z-index: 12;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 3px; color: #8c9c92; font-size: 9.5px; padding: 5px 0; border-radius: 10px; }
.bottom-nav a span { font-size: 17px; line-height: 1; }
.bottom-nav a.active { color: var(--green); font-weight: 700; background: var(--green-soft); }

.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translate(-50%, 12px);
  background: #183c2b; color: #fff; padding: 10px 15px; border-radius: 10px;
  font-size: 11px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f2c22; }

.modal-mask { position: fixed; inset: 0; background: rgba(16, 42, 28, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal {
  width: min(430px, 100%); background: #fff; border-radius: 22px 22px 0 0;
  max-height: 90vh; overflow: auto; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  animation: slideup .18s ease-out;
}
@keyframes slideup { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal h3 { margin: 0 0 14px; font-size: 16px; }
.field { margin-bottom: 11px; }
.field label { display: block; color: var(--muted); font-size: 10.5px; margin-bottom: 5px; }
.input, .select {
  width: 100%; border: 1px solid var(--line); background: #fbfdfc; border-radius: 10px;
  padding: 10px 11px; font: inherit; font-size: 12px; color: var(--ink); outline: none;
}
.input:focus, .select:focus { border-color: var(--green-2); background: #fff; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.week-row { display: flex; gap: 5px; flex-wrap: wrap; }
.week { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 10.5px; background: #fff; }
.week input { margin-right: 3px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }
.hint { color: var(--muted); font-size: 9.5px; line-height: 1.6; margin-top: 8px; }
.bytes { color: var(--green); font-family: Consolas, monospace; }

.type-chips { display: flex; gap: 7px; overflow-x: auto; padding: 2px 1px 10px; scrollbar-width: none; }
.type-chips::-webkit-scrollbar { display: none; }
.type-chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 7px 10px; font-size: 10.5px; cursor: pointer;
}
.type-chip b { min-width: 16px; height: 16px; border-radius: 999px; background: #eef4f0; color: #47705a; display: inline-grid; place-items: center; font-size: 9px; }
.type-chip.active { border-color: #b9dcc9; background: var(--green-soft); color: var(--green); font-weight: 700; }
.type-chip.active b { background: var(--green); color: #fff; }
.device-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.device-title > div { min-width: 0; }
.device-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kind-icon { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: #eaf7ef; font-size: 17px; }
.kind-icon.small { width: 24px; height: 24px; border-radius: 8px; font-size: 13px; }
.kind-badge { display: inline-block; background: #eef4f0; color: #47705a; border-radius: 999px; padding: 3px 6px; font-size: 8.5px; white-space: nowrap; }
.device-side { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.device-card .meta.type-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.device-card .meta.type-metrics b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-foot { margin-top: 9px; padding-top: 8px; border-top: 1px dashed #e4eee7; color: var(--muted); font-size: 9px; }
.type-section { margin-top: 15px; }
.type-section-head { display: flex; align-items: center; gap: 7px; margin: 0 2px 8px; }
.type-section-head b { font-size: 12.5px; }
.type-section-head small { color: var(--muted); font-size: 9.5px; }
.search { width: 100%; margin: 2px 0 9px; box-sizing: border-box; }
.device-kind-line { color: #c8e5d5; font-size: 11px; margin-bottom: 5px; }
.device-hero.fertigation { background: linear-gradient(140deg, #0d3c4a, #176d78 60%, #2b9ba3); }
.tank-block { background: #f6fbf8; border: 1px solid #e2efe7; border-radius: 14px; padding: 11px 12px; }
.tank-label { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 10.5px; }
.tank-label b { color: var(--green); font-size: 17px; }
.water-bar { height: 10px; border-radius: 999px; background: #dcefe3; margin-top: 9px; overflow: hidden; }
.water-bar i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #4fb27d, #1f8f5e); }
.tank-scale { display: flex; justify-content: space-between; color: #91a89a; font-size: 8.5px; margin-top: 5px; }

.login-mask {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center;
  padding: 20px;
  background:
    radial-gradient(600px 400px at 20% 0%, rgba(47,158,102,.35), transparent 60%),
    linear-gradient(150deg, #0d3326, #14563f 60%, #1f7a4d);
}
.login-card {
  width: min(350px, 92vw); background: #fff; border-radius: 22px;
  padding: 24px 20px; box-shadow: 0 30px 80px rgba(0,0,0,.3);
}
.login-card h2 { margin: 0 0 6px; font-size: 20px; }
.login-card p { margin: 0 0 16px; color: var(--muted); font-size: 10.5px; line-height: 1.6; }
.login-card .field { margin-bottom: 10px; }
.login-error { color: var(--red); font-size: 10.5px; min-height: 16px; margin: 4px 0; }
.login-demo { background: var(--green-soft); border: 1px solid #cfe8d9; border-radius: 10px; padding: 9px 10px; color: #246348; font-size: 9.5px; line-height: 1.7; margin-top: 10px; }
.login-card .btn { width: 100%; margin-top: 4px; }

@media (max-width: 380px) {
  .app-view { padding-left: 10px; padding-right: 10px; }
  .metric-card b { font-size: 18px; }
}
