:root {
  --bg: #0b0e14;
  --bg-2: #0f141d;
  --panel: rgba(22, 27, 36, 0.72);
  --panel-solid: #161b24;
  --panel-2: #1c2230;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --txt: #e9eef6;
  --muted: #8a96a8;
  --teal: #2ee6a6;
  --teal-soft: rgba(46, 230, 166, 0.14);
  --amber: #ffb347;
  --amber-soft: rgba(255, 179, 71, 0.14);
  --red: #ff5d6c;
  --red-soft: rgba(255, 93, 108, 0.14);
  --blue: #5aa9ff;
  --blue-soft: rgba(90, 169, 255, 0.14);
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1100px 540px at 78% -12%, rgba(46, 230, 166, 0.10), transparent 60%),
    radial-gradient(900px 480px at 8% 8%, rgba(90, 169, 255, 0.08), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  background-attachment: fixed;
  color: var(--txt);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(600px 320px at 50% 120%, rgba(46, 230, 166, 0.06), transparent 70%);
}

.app { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; padding: 28px 22px 56px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-bottom: 20px; margin-bottom: 22px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  font-size: 24px; background: linear-gradient(145deg, var(--teal), #1aa37a);
  box-shadow: 0 10px 26px -10px rgba(46, 230, 166, 0.7);
  animation: spin 9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.brand h1 { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: .4px; }
.brand .sub { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

.status { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 12.5px; }

.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.conn.live { color: var(--teal); }
.conn.live i { background: var(--teal); box-shadow: 0 0 0 0 var(--teal); animation: pulse 1.8s infinite; }
.conn.off { color: var(--red); }
.conn.off i { background: var(--red); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(46, 230, 166, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(46, 230, 166, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 230, 166, 0); }
}

.btn {
  background: var(--panel-2); color: var(--txt); border: 1px solid var(--line-strong);
  padding: 9px 18px; border-radius: 11px; cursor: pointer; font-size: 13px; transition: .16s;
}
.btn:hover { border-color: var(--teal); color: var(--teal); transform: translateY(-1px); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; backdrop-filter: blur(10px); box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--blue);
}
.stat.warn::before { background: var(--amber); }
.stat.ok::before { background: var(--teal); }
.stat.bad::before { background: var(--red); }
.stat .num { font-size: 30px; font-weight: 700; line-height: 1; letter-spacing: .5px; }
.stat.warn .num { color: var(--amber); }
.stat.ok .num { color: var(--teal); }
.stat.bad .num { color: var(--red); }
.stat .lbl { margin-top: 6px; font-size: 12.5px; color: var(--muted); }

/* ---------- Banners ---------- */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-radius: 12px; padding: 11px 16px; font-size: 13px; margin-bottom: 18px;
  flex-wrap: wrap;
}
.banner.demo {
  background: var(--amber-soft); border: 1px solid rgba(255, 179, 71, 0.3);
  color: var(--amber);
}
.banner.demo b { color: #ffd089; }
.banner.error {
  background: var(--red-soft); border: 1px solid rgba(255, 93, 108, 0.35);
  color: var(--red);
}
.banner.error b { color: #ffb3bc; }
.mini {
  background: var(--panel-2); color: var(--txt); border: 1px solid var(--line-strong);
  padding: 6px 12px; border-radius: 9px; cursor: pointer; font-size: 12px; transition: .15s;
}
.mini:hover { border-color: var(--teal); color: var(--teal); }
.mini.ghost { background: transparent; }

/* ---------- Grid & Cards ---------- */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; align-items: start; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; backdrop-filter: blur(10px); box-shadow: var(--shadow);
  animation: rise .4s ease both;
}
.card:nth-child(2) { animation-delay: .05s; }
.card:nth-child(3) { animation-delay: .1s; }
.card:nth-child(4) { animation-delay: .15s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.card-head h2 { font-size: 15.5px; font-weight: 650; margin: 0; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--amber-soft); color: var(--amber); font-size: 12px; padding: 2px 10px; border-radius: 999px; font-weight: 700; }

/* ---------- 配方表内嵌 3×3 形状 ---------- */
.minigrid {
  display: grid; grid-template-columns: repeat(3, 18px); grid-template-rows: repeat(3, 18px);
  gap: 2px; margin-top: 8px;
}
.minigrid .cell {
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px;
  font-size: 8.5px; line-height: 1; color: var(--txt); text-align: center;
  padding: 1px; overflow: hidden; word-break: break-all;
}
.minigrid .cell.empty { background: transparent; border-style: dashed; border-color: var(--line); }
.badge.bad { background: var(--red-soft); color: var(--red); }
.actions { display: flex; gap: 7px; flex-wrap: wrap; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 9px; }
.list.scroll { max-height: 340px; overflow-y: auto; padding-right: 4px; }
.list.scroll::-webkit-scrollbar { width: 8px; }
.list.scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 11px; padding: 11px 14px; transition: .15s;
}
.row:hover { border-color: var(--line-strong); transform: translateX(2px); }
.row .name { font-weight: 550; }
.row .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.have { color: var(--teal); font-weight: 600; }
.lack { color: var(--red); font-weight: 700; }
.need { color: var(--txt); }
.empty { color: var(--muted); font-size: 13px; padding: 10px 4px; text-align: center; }

/* 报错行 */
.row.err { border-color: rgba(255, 93, 108, 0.3); background: var(--red-soft); }
.row.err .name { color: var(--red); }
.row.err .type { background: var(--panel-solid); color: var(--red); font-size: 11.5px; padding: 2px 9px; border-radius: 999px; font-weight: 600; border: 1px solid rgba(255, 93, 108, 0.4); }

/* 库存进度条 */
.bar { height: 6px; border-radius: 6px; background: var(--line); overflow: hidden; min-width: 60px; flex: 1; max-width: 140px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--teal), var(--blue)); border-radius: 6px; }
.stk { display: flex; align-items: center; gap: 10px; flex: 1; }
.stk .nm { min-width: 96px; }

/* ---------- Recipe table ---------- */
.legend { display: flex; gap: 12px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.lg.ok { color: var(--teal); } .lg.warn { color: var(--amber); } .lg.mute { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 550; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px; }
td .out { color: var(--teal); font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 9px; font-size: 12px; }
.station { color: var(--blue); font-size: 12.5px; }
.st { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 650; white-space: nowrap; }
.st.ok { background: var(--teal-soft); color: var(--teal); }
.st.warn { background: var(--amber-soft); color: var(--amber); }
.st.mute { background: var(--line); color: var(--muted); }

/* ---------- Search ---------- */
.search {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line-strong);
  color: var(--txt); border-radius: 10px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; outline: none;
}
.search:focus { border-color: var(--teal); }

/* ---------- Footer ---------- */
.foot { text-align: center; margin-top: 30px; font-size: 12px; color: var(--muted); }
.foot code { background: var(--panel-2); padding: 2px 7px; border-radius: 6px; color: var(--teal); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-solid); border: 1px solid var(--line-strong); color: var(--txt);
  padding: 11px 20px; border-radius: 12px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: .25s; box-shadow: var(--shadow); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 860px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: span 1; }
}
