:root {
  --bg: #fff8ef;
  --card: #fffdf9;
  --ink: #3d2c24;
  --sub: #8f7a6d;
  --line: #3d2c24;
  --primary: #ff8a4c;
  --primary-deep: #f06b2f;
  --primary-soft: #ffe6d4;
  --mint: #7bcf9b;
  --mint-soft: #e5f7ec;
  --pink: #f7a8bc;
  --pink-soft: #fde8ee;
  --yellow: #ffd166;
  --yellow-soft: #fff4cc;
  --danger: #e85d5d;
  --radius: 22px;
  --shadow: 7px 7px 0 rgba(61, 44, 36, 0.13);
  --shadow-soft: 0 16px 40px rgba(61, 44, 36, 0.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.halftone {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: radial-gradient(rgba(61, 44, 36, 0.09) 1px, transparent 1px);
  background-size: 18px 18px;
  mask-image: linear-gradient(180deg, rgba(0,0,0,.65), rgba(0,0,0,.18));
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.22em;
  color: var(--primary-deep);
}

/* ---------- 登录 ---------- */
.login-view {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    radial-gradient(circle at 12% 16%, rgba(255, 209, 102, 0.35), transparent 26%),
    radial-gradient(circle at 88% 82%, rgba(123, 207, 155, 0.28), transparent 30%);
}
.login-card {
  width: min(430px, 100%);
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 32px;
  padding: 34px 34px 26px;
  box-shadow: 12px 12px 0 rgba(61, 44, 36, 0.16);
  position: relative;
}
.login-card::after {
  content: "";
  position: absolute;
  right: -18px;
  top: 70px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: var(--yellow);
  z-index: -1;
}
.login-mascot {
  width: 92px;
  height: 92px;
  border-radius: 28px;
  background: var(--mint-soft);
  border: 2.5px solid var(--line);
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  transform: rotate(-3deg);
}
.login-mascot svg { width: 78px; height: 78px; }
.login-card h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.login-sub { margin: 8px 0 24px; color: var(--sub); font-size: 13px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 12px; font-weight: 800; }
.login-card input {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 13px 15px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fffaf3;
  outline: none;
  font-size: 14px;
  transition: box-shadow .18s, transform .18s;
}
.login-card input:focus { box-shadow: 4px 4px 0 rgba(255, 138, 76, .35); }
.login-msg { min-height: 18px; margin: 12px 0 0; font-size: 12px; color: var(--danger); font-weight: 700; }
.login-foot { margin: 16px 0 0; color: var(--sub); font-size: 10.5px; line-height: 1.6; }

/* ---------- 布局 ---------- */
.app-view {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px 18px;
  background: #fffaf2;
  border-right: 2.5px solid var(--line);
}
.side-brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 24px; }
.side-logo {
  width: 50px; height: 50px; border-radius: 16px;
  background: var(--mint-soft);
  border: 2px solid var(--line);
  display: grid; place-items: center;
  transform: rotate(-4deg);
}
.side-logo svg { width: 42px; height: 42px; }
.side-brand strong { display: block; font-size: 15px; font-weight: 900; letter-spacing: .03em; }
.side-brand span { display: block; margin-top: 2px; color: var(--sub); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
#nav { display: flex; flex-direction: column; gap: 7px; }
#nav button {
  display: flex; align-items: center; justify-content: space-between;
  border: 2px solid transparent;
  background: transparent;
  border-radius: 14px;
  padding: 12px 13px;
  font-size: 13px;
  font-weight: 800;
  color: var(--sub);
  text-align: left;
  transition: .18s;
}
#nav button em { font-style: normal; font-size: 9px; letter-spacing: .08em; opacity: .55; }
#nav button:hover { background: #fff2e5; color: var(--ink); }
#nav button.active {
  background: var(--primary-soft);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: 4px 4px 0 rgba(61, 44, 36, .12);
}
.side-foot {
  margin-top: auto;
  display: flex; align-items: center; gap: 7px;
  padding: 14px 8px 4px;
  border-top: 2px dashed rgba(61, 44, 36, .18);
  color: var(--sub); font-size: 10px;
}
.side-foot small { margin-left: auto; opacity: .7; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); border: 1.5px solid var(--line); }

.main { padding: 26px 30px 46px; min-width: 0; }
.page { display: none; }
.page.active { display: block; animation: pageIn .22s ease-out; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.topbar h2 { margin: 0; font-size: 28px; font-weight: 900; letter-spacing: -.02em; }
.top-actions { display: flex; gap: 9px; }

/* ---------- 通用组件 ---------- */
.btn {
  border: 2px solid var(--line);
  border-radius: 13px;
  padding: 9px 14px;
  background: var(--card);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 3px 3px 0 rgba(61, 44, 36, .14);
  transition: transform .12s, box-shadow .12s, background .12s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 rgba(61, 44, 36, .16); }
.btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 rgba(61, 44, 36, .14); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-deep); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: #fffaf2; }
.btn.small { padding: 6px 10px; font-size: 11px; }
.btn.block { width: 100%; padding: 13px; font-size: 14px; }

.panel {
  background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.panel-head h3 { margin: 0; font-size: 16px; font-weight: 900; }
.panel-head p { margin: 4px 0 0; color: var(--sub); font-size: 11px; }
.panel-subhead { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 10px; }
.panel-subhead h4 { margin: 0; font-size: 13px; font-weight: 900; }
.pill { display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--mint-soft); font-size: 10px; font-weight: 800; }
.note-panel { background: var(--yellow-soft); }
.note-panel h3 { margin: 0 0 8px; font-size: 14px; font-weight: 900; }
.note-panel p { margin: 0; font-size: 12px; line-height: 1.8; color: #6a5548; }
code { background: rgba(61,44,36,.08); padding: 1px 5px; border-radius: 5px; font-size: 11px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.stat-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 7px; background: var(--primary); border-bottom: 2px solid var(--line); }
.stat-card:nth-child(2)::before { background: var(--mint); }
.stat-card:nth-child(3)::before { background: var(--pink); }
.stat-card:nth-child(4)::before { background: var(--yellow); }
.stat-card .label { color: var(--sub); font-size: 10.5px; font-weight: 800; letter-spacing: .04em; }
.stat-card .value { margin-top: 8px; font-size: 28px; font-weight: 900; letter-spacing: -.03em; }
.stat-card .hint { margin-top: 3px; font-size: 10px; color: var(--sub); }

.chart { width: 100%; min-height: 190px; }
.chart svg { width: 100%; height: 190px; overflow: visible; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--sub); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 3px; margin-left: 8px; border: 1px solid var(--line); }
.dot.orange { background: var(--primary); }
.dot.green { background: var(--mint); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12px; }
th { text-align: left; padding: 9px 10px; color: var(--sub); font-size: 10.5px; font-weight: 900; letter-spacing: .04em; border-bottom: 2px solid rgba(61,44,36,.15); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px dashed rgba(61,44,36,.13); vertical-align: middle; }
tbody tr:hover { background: #fff6eb; }
.empty-row td { text-align: center; color: var(--sub); padding: 28px 10px; }
.row-link { cursor: pointer; font-weight: 800; }
.badge { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; border: 1.5px solid var(--line); font-size: 9.5px; font-weight: 800; white-space: nowrap; }
.badge.green { background: var(--mint-soft); }
.badge.orange { background: var(--primary-soft); }
.badge.pink { background: var(--pink-soft); }
.badge.gray { background: #f3ece5; color: var(--sub); }
.badge.red { background: #fde3e3; color: #b43d3d; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; letter-spacing: .03em; }

.search-row, .inline-form { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.search-row input { width: 220px; }
input, textarea, select {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fffaf3;
  padding: 9px 11px;
  font-size: 12px;
  outline: none;
}
input:focus, textarea:focus, select:focus { box-shadow: 4px 4px 0 rgba(255, 138, 76, .30); }
textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 11px; font-weight: 800; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid .switch-line { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 2px solid var(--line); border-radius: 12px; background: #fffaf3; }
.switch-line input { width: 18px; height: 18px; box-shadow: none; accent-color: var(--primary); }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.form-msg { font-size: 11px; font-weight: 700; color: var(--sub); }
.form-msg.ok { color: #2f8f5b; }
.form-msg.err { color: var(--danger); }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; font-size: 11px; color: var(--sub); }

.plans-editor { display: flex; flex-direction: column; gap: 10px; }
.plan-row { display: grid; grid-template-columns: 1.1fr .8fr .8fr .8fr .8fr 1.4fr auto; gap: 8px; align-items: end; padding: 11px; border: 2px dashed rgba(61,44,36,.22); border-radius: 14px; background: #fffaf3; }
.plan-row label { display: flex; flex-direction: column; gap: 4px; font-size: 9.5px; font-weight: 800; color: var(--sub); }
.plan-row input { padding: 7px 9px; font-size: 11px; }
.plan-row .remove { align-self: center; }

.code-output { display: flex; flex-wrap: wrap; gap: 7px; margin: 14px 0; }
.code-chip { padding: 7px 10px; border: 2px solid var(--line); border-radius: 10px; background: var(--yellow-soft); font-family: ui-monospace, Consolas, monospace; font-size: 11px; font-weight: 800; cursor: pointer; }

/* ---------- 弹窗 / Toast ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(61, 44, 36, .35);
  display: grid; place-items: center;
  padding: 24px;
  backdrop-filter: blur(2px);
}
.modal {
  width: min(680px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 24px;
  box-shadow: 12px 12px 0 rgba(61,44,36,.2);
  padding: 22px;
}
.modal h3 { margin: 0 0 4px; font-size: 18px; font-weight: 900; }
.modal .modal-sub { color: var(--sub); font-size: 11px; margin: 0 0 16px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 16px; font-size: 12px; }
.detail-grid .k { color: var(--sub); font-size: 10px; }
.detail-grid .v { font-weight: 800; }
.timeline { margin-top: 16px; max-height: 220px; overflow: auto; border-top: 2px dashed rgba(61,44,36,.15); padding-top: 10px; }
.timeline-item { display: flex; gap: 9px; padding: 7px 0; font-size: 11px; border-bottom: 1px dashed rgba(61,44,36,.1); }
.timeline-item time { color: var(--sub); white-space: nowrap; font-size: 10px; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: #fff8ef;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 11px 18px;
  font-size: 12px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: .22s;
  z-index: 40;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 响应式 ---------- */
@media (max-width: 1000px) {
  .app-view { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 2.5px solid var(--line); padding: 16px; }
  .side-brand { padding-bottom: 12px; }
  #nav { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  #nav button { flex: 0 0 auto; gap: 12px; padding: 9px 12px; }
  .side-foot { display: none; }
  .main { padding: 20px 16px 40px; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .plan-row { grid-template-columns: 1fr 1fr; }
  .panel-head { flex-direction: column; }
  .search-row input { width: 100%; }
}
@media (max-width: 520px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: flex-end; }
  .stat-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}
