:root {
  --primary: #0f766e;
  --primary-600: #0d9488;
  --primary-400: #2dd4bf;
  --primary-bg: #e7f3f1;
  --primary-ink: #0b4f4a;

  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warn: #ea580c;
  --warn-bg: #fff7ed;
  --ok: #059669;
  --ok-bg: #ecfdf5;
  --info: #2563eb;
  --info-bg: #eff6ff;

  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201e;
  --text-2: #5a6663;
  --text-3: #98a29f;
  --border: #e5e9e8;
  --border-2: #d5dbda;

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;

  --shadow-sm: 0 1px 2px rgba(16, 32, 30, .05);
  --shadow: 0 2px 10px rgba(16, 32, 30, .07);
  --shadow-lg: 0 12px 32px rgba(16, 32, 30, .16);

  --appbar-h: 56px;
  --tabbar-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; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
h1, h2, h3, h4, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

/* ---------- shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

#view {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px calc(var(--tabbar-h) + var(--safe-b) + 76px);
}

/* ---------- appbar ---------- */
#appbar {
  flex-shrink: 0;
  padding-top: var(--safe-t);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.bar {
  height: var(--appbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
}

.bar-title { font-size: 17px; font-weight: 600; letter-spacing: -.2px; }
.bar-sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.bar-spacer { flex: 1; }

.home-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-bg);
  color: var(--primary-ink);
  border-radius: 999px;
  padding: 7px 12px 7px 14px;
  font-size: 14px;
  font-weight: 600;
  max-width: 190px;
}
.home-switch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-switch svg { flex-shrink: 0; opacity: .7; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  color: var(--text-2);
}
.icon-btn:active { background: var(--bg); }

/* ---------- tabbar ---------- */
#tabbar {
  flex-shrink: 0;
  display: flex;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
  z-index: 20;
}
.tab {
  flex: 1;
  height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-3);
  font-size: 11px;
  position: relative;
}
.tab.active { color: var(--primary); }
.tab.active svg { stroke: var(--primary); }
.tab-dot {
  position: absolute;
  top: 8px;
  margin-left: 18px;
  min-width: 16px; height: 16px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  display: grid; place-items: center;
  padding: 0 4px;
}

/* ---------- fab ---------- */
#fab {
  position: fixed;
  right: calc(50% - 280px + 16px);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(15, 118, 110, .38);
  z-index: 30;
}
#fab:active { transform: scale(.94); }
@media (max-width: 592px) {
  #fab { right: 16px; }
}

/* ---------- generic ---------- */
.section { margin-bottom: 20px; }
.section-head {
  display: flex; align-items: center; gap: 8px;
  padding: 0 4px 8px;
}
.section-title {
  font-size: 13px; font-weight: 600; color: var(--text-2);
  letter-spacing: .3px;
}
.section-count {
  font-size: 12px; color: var(--text-3);
}
.section-head .bar-spacer { flex: 1; }

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  position: relative;
}
.row + .row::before {
  content: "";
  position: absolute; top: 0; left: 14px; right: 0;
  height: 1px; background: var(--border);
}
.row:active { background: #fafbfb; }
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-size: 15px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-sub {
  font-size: 12px; color: var(--text-3); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-chev { color: var(--text-3); flex-shrink: 0; }

.avatar {
  width: 42px; height: 42px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 20px;
  background: var(--primary-bg);
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--text-3);
}
.empty-ico {
  width: 62px; height: 62px;
  margin: 0 auto 14px;
  border-radius: 20px;
  background: var(--card);
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
  color: var(--primary-400);
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.empty-text { font-size: 13px; line-height: 1.6; }

/* ---------- badges ---------- */
.badge {
  font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-gray { background: #f1f3f3; color: var(--text-2); }

.qty-pill {
  font-size: 12px; font-weight: 600;
  color: var(--text-2);
  background: #f1f3f3;
  border-radius: 7px;
  padding: 3px 7px;
  flex-shrink: 0;
}

/* ---------- stat strip ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 13px;
  box-shadow: var(--shadow-sm);
}
.stat-num { font-size: 22px; font-weight: 600; letter-spacing: -.5px; line-height: 1.2; }
.stat-label { font-size: 11px; color: var(--text-3); margin-top: 3px; }
.stat.danger .stat-num { color: var(--danger); }
.stat.warn .stat-num { color: var(--warn); }
.stat.ok .stat-num { color: var(--ok); }

/* ---------- segmented ---------- */
.seg {
  display: flex;
  background: #ecefee;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  flex: 1;
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  transition: background .15s;
}
.seg button.active {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---------- form ---------- */
.field { margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}
.field-label .opt { color: var(--text-3); font-weight: 400; }
.field-hint { font-size: 12px; color: var(--text-3); margin-top: 5px; line-height: 1.5; }

.input, .select, .textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 15px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, .12);
}
.textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2398a29f' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }

.seg-inline { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  font-size: 13px;
  color: var(--text-2);
  background: var(--card);
}
.chip.active {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary-ink);
  font-weight: 500;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}
.cat-card {
  text-align: left;
  padding: 12px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border-2);
  background: var(--card);
}
.cat-card.active {
  border-color: var(--primary);
  background: var(--primary-bg);
}
.cat-name { font-size: 14px; font-weight: 600; }
.cat-desc { font-size: 11px; color: var(--text-3); margin-top: 2px; line-height: 1.45; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: #eef1f0; color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 22px; }
.btn-row .btn { flex: 1; }

/* ---------- search ---------- */
.searchbar {
  display: flex; align-items: center; gap: 9px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 13px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.searchbar svg { color: var(--text-3); flex-shrink: 0; }
.searchbar input {
  flex: 1; border: none; outline: none; background: none;
  font-size: 15px; min-width: 0;
}
.searchbar input::placeholder { color: var(--text-3); }

/* ---------- tree ---------- */
.tree-node {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 14px;
  position: relative;
  background: var(--card);
}
.tree-node + .tree-node::before {
  content: "";
  position: absolute; top: 0; left: 14px; right: 0;
  height: 1px; background: var(--border);
}
.tree-ico {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--primary-bg); color: var(--primary);
  flex-shrink: 0;
}
.crumb {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text-3);
  margin-bottom: 10px; flex-wrap: wrap;
}
.crumb button { color: var(--primary); font-size: 12px; }
.crumb .sep { color: var(--border-2); }

/* ---------- sheet & modal ---------- */
.sheet-mask {
  position: fixed; inset: 0;
  background: rgba(14, 24, 22, .42);
  z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.sheet {
  width: 100%; max-width: 560px;
  max-height: 88dvh;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  animation: slideUp .24s cubic-bezier(.32, .72, 0, 1);
  overflow: hidden;
}
.sheet-head {
  flex-shrink: 0;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sheet-title { font-size: 16px; font-weight: 600; flex: 1; }
.sheet-body {
  flex: 1; overflow-y: auto;
  padding: 16px 18px;
  -webkit-overflow-scrolling: touch;
}
.sheet-foot {
  flex-shrink: 0;
  padding: 12px 18px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  display: flex; gap: 10px;
  background: var(--card);
}
.sheet-foot .btn { flex: 1; }
.grabber {
  width: 38px; height: 4px; border-radius: 2px;
  background: var(--border-2);
  margin: 8px auto 0;
}

@keyframes fade { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } }

/* ---------- toast ---------- */
#toast-root {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 84px);
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; z-index: 200; pointer-events: none;
}
.toast {
  background: rgba(23, 32, 30, .92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: 84%;
  animation: fade .16s ease;
  backdrop-filter: blur(8px);
}

/* ---------- misc ---------- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.muted { color: var(--text-3); font-size: 13px; }
.center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.nowrap { white-space: nowrap; }

.kv { display: flex; padding: 9px 0; font-size: 14px; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv-k { width: 92px; color: var(--text-3); flex-shrink: 0; }
.kv-v { flex: 1; word-break: break-word; }
