:root {
  --bg: #0c1118;
  --bg-elev: #121922;
  --panel: #161e28;
  --panel-2: #1c2633;
  --line: #2a3544;
  --line-soft: #232d3b;
  --text: #e9eef4;
  --muted: #8a97a8;
  --accent: #2f9e90;
  --accent-dim: rgba(47, 158, 144, 0.14);
  --warn: #c9a227;
  --danger: #d4676a;
  --ok: #5fad7a;
  --radius: 12px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
/* 作者样式里的 display:grid/flex 会盖掉 UA 的 [hidden]，必须用 !important */
[hidden] { display: none !important; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-optical-sizing: auto;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.err { color: var(--danger); font-size: 0.9rem; }
.ok { color: var(--ok); }

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 0.5rem 0.9rem;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.btn:hover { border-color: #3f4f63; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #04120f;
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.muted {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 500;
}
.btn.muted:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: #3f4f63;
  color: var(--text);
}
.btn.danger {
  background: transparent;
  border-color: rgba(212, 103, 106, 0.55);
  color: var(--danger);
}
.btn.ghost { background: transparent; width: 100%; }
.btn.block { width: 100%; }
.btn.sm { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

/* —— Login —— */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 480px at 8% -8%, #16352f 0%, transparent 55%),
    radial-gradient(700px 420px at 92% 8%, #2d2818 0%, transparent 50%),
    linear-gradient(180deg, #0e141c 0%, var(--bg) 100%);
}
.login-shell {
  width: min(920px, 96vw);
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1.5rem;
  align-items: stretch;
}
.login-hero {
  padding: 2rem 1.25rem 1.5rem 0.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-hero .brand {
  margin: 0 0 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 600;
}
.login-hero h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 4vw, 2.6rem);
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.login-hero .lede {
  margin: 0 0 1.5rem;
  color: var(--muted);
  max-width: 34ch;
  line-height: 1.55;
}
.login-points {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.55rem;
}
.login-points li {
  position: relative;
  padding-left: 1.1rem;
  color: #b7c3d0;
  font-size: 0.92rem;
  line-height: 1.45;
}
.login-points li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.5rem 1.4rem 1.35rem;
  display: grid;
  gap: 0.7rem;
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 0.15rem 0 0; font-size: 1.25rem; }
.login-card label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.login-card input,
.form-row input,
.form-row select,
.form-row textarea,
.search-bar input {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.65rem 0.75rem;
  color: var(--text);
  outline: none;
}
.login-card input:focus,
.form-row input:focus,
.form-row select:focus,
.search-bar input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-row label.check,
label.check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-direction: row;
  cursor: pointer;
  user-select: none;
  color: var(--muted);
  font-size: 0.82rem;
}
.form-row label.check input[type="checkbox"],
label.check input[type="checkbox"] {
  width: 19px;
  height: 19px;
  min-width: 19px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  box-shadow: none;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.form-row label.check input[type="checkbox"]:focus,
label.check input[type="checkbox"]:focus {
  box-shadow: none;
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.transport-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  width: fit-content;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--bg-elev);
}
.transport-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.transport-chip.secure {
  color: var(--ok);
  border-color: rgba(95, 173, 122, 0.35);
  background: rgba(95, 173, 122, 0.08);
}
.transport-chip.secure::before { background: var(--ok); }
.transport-chip.insecure {
  color: var(--warn);
  border-color: rgba(201, 162, 39, 0.4);
  background: rgba(201, 162, 39, 0.1);
}
.transport-chip.insecure::before { background: var(--warn); }
.transport-chip.compact {
  width: 100%;
  justify-content: center;
  margin-bottom: 0.55rem;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

/* —— Shell —— */
.main-view {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.side {
  background: linear-gradient(180deg, #121922 0%, #0f151d 100%);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 1rem 0.7rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side-brand {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.55rem 0.65rem 1.2rem;
}
.side-brand .mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #04120f;
  font-weight: 700;
}
.side-brand strong { display: block; font-size: 0.95rem; }
.side-brand em {
  display: block;
  font-style: normal;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 500;
}
.nav { display: grid; gap: 0.15rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 0.62rem 0.75rem;
  border-radius: 9px;
}
.nav-item .ico {
  width: 1.35rem;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.72rem;
  opacity: 0.75;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}
.side-foot {
  margin-top: auto;
  padding: 0.85rem 0.55rem 0.35rem;
  border-top: 1px solid var(--line-soft);
}
.me {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
  line-height: 1.45;
  word-break: break-all;
}
.me b { color: var(--text); font-weight: 600; }

.content {
  padding: 1.35rem 1.6rem 2.4rem;
  background:
    radial-gradient(800px 280px at 100% 0%, rgba(47, 158, 144, 0.06), transparent 60%),
    var(--bg);
}
.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.15rem;
}
.top h2 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.page-desc { margin: 0.35rem 0 0; font-size: 0.9rem; max-width: 52ch; }
.top-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.1rem;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
}
.stat .label { color: var(--muted); font-size: 0.78rem; }
.stat .value {
  font-size: 1.35rem;
  font-weight: 650;
  margin-top: 0.3rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1rem;
}
.panel:last-child { margin-bottom: 0; }
.panel-h {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.015);
}
.panel-h strong { font-weight: 600; }
.panel-h > label.check,
.panel-h > .btn { margin-left: auto; }
.panel-body { padding: 1rem; }

.stack { display: grid; gap: 1rem; }
.grid-2 {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
  align-items: stretch;
  margin-bottom: 1rem;
}
.grid-2 > .panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  margin-bottom: 0;
}
.grid-2 > .panel .panel-body,
.grid-2 > .panel .stats,
.grid-2 > .panel .kv,
.grid-2 > .panel .rule-summary {
  flex: 1;
}
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.32rem 0.8rem;
  font-size: 0.84rem;
}
.tab.active {
  background: var(--panel-2);
  color: var(--text);
  border-color: #405064;
}

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td {
  padding: 0.7rem 0.95rem;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
td.mono, .mono { font-family: var(--mono); font-size: 0.8rem; }
td.amt-pos, .amt-pos { color: #3dce7a !important; font-weight: 600; }
td.amt-neg, .amt-neg { color: #e85d62 !important; font-weight: 600; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
.actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  font-size: 0.74rem;
  border: 1px solid var(--line);
  color: var(--muted);
  text-transform: lowercase;
}
.badge.pending, .badge.approved { color: var(--warn); border-color: rgba(201, 162, 39, 0.45); }
.badge.paid, .badge.confirmed, .badge.active { color: var(--ok); border-color: rgba(95, 173, 122, 0.4); }
.badge.rejected, .badge.disabled, .badge.void { color: var(--danger); border-color: rgba(212, 103, 106, 0.4); }

.tree {
  padding: 0.85rem 1rem 1.2rem;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.75;
  overflow: auto;
}
.tree .node { white-space: pre; }
.tree .role { color: var(--accent); }

.tree-tools {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  margin-left: auto;
}
.tree-tools input {
  width: 11rem;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
  color: var(--text);
  outline: none;
}
.tree-tools input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.tree-wrap {
  max-height: min(52vh, 28rem);
  overflow: auto;
  padding: 0.55rem 0.75rem 0.9rem;
}
.acct-tree,
.acct-children {
  list-style: none;
  margin: 0;
  padding: 0;
}
.acct-children {
  margin-left: 0.85rem;
  padding-left: 0.55rem;
  border-left: 1px solid var(--line-soft);
}
.acct-node { margin: 0.1rem 0; }
.acct-node.is-faded > .acct-row { opacity: 0.38; }
.acct-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.55rem;
  padding: 0.28rem 0.4rem;
  border-radius: 8px;
  font-size: 0.86rem;
}
.acct-row:hover { background: rgba(255, 255, 255, 0.03); }
.acct-toggle {
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1;
  flex-shrink: 0;
}
.acct-toggle.spacer {
  display: inline-block;
  border: none;
  background: transparent;
  visibility: hidden;
}
.acct-toggle:hover { border-color: var(--accent); color: var(--text); }
.acct-name { font-weight: 600; color: var(--text); }
.acct-dn, .acct-inv { font-size: 0.78rem; }
.acct-count {
  margin-left: auto;
  font-size: 0.72rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--line-soft);
}
.acct-tree .role { color: var(--accent); font-weight: 500; }

.form-row {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  align-items: end;
}
.form-row label {
  display: grid;
  gap: 0.28rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.form-row input,
.form-row select,
.form-row textarea { min-width: 148px; }
.form-row textarea { min-width: 220px; min-height: 72px; }

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}
.skeleton {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--panel-2), #243040, var(--panel-2));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
  margin: 0.55rem 0;
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

#dlg {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  width: min(760px, 94vw);
  max-height: 85vh;
}
#dlg::backdrop { background: rgba(4, 8, 12, 0.62); }
#dlg form { margin: 0; display: flex; flex-direction: column; max-height: 85vh; }
#dlg h3 { margin: 0; padding: 1rem 1.15rem 0.45rem; }
.dlg-body { padding: 0.45rem 1.15rem 1rem; overflow: auto; }
#dlg menu {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin: 0;
  padding: 0.8rem 1.15rem 1rem;
  border-top: 1px solid var(--line-soft);
}
.kv {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 0.4rem 0.8rem;
  font-size: 0.9rem;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

.rule-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0.75rem;
  align-content: stretch;
  align-items: stretch;
  min-height: 0;
}
.grid-2 > .panel .rule-summary {
  /* 随卡片拉高，三列底框接近整块可用高度 */
  min-height: 11rem;
}
.rule-summary-item {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  padding: 0.7rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  min-height: 100%;
  height: 100%;
  box-sizing: border-box;
}
.rule-summary-title {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text);
  margin-bottom: 0.15rem;
  flex-shrink: 0;
}
.rule-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.rule-summary-row .mono {
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
}

.rule-scenarios {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
  padding: 0;
  align-items: stretch;
}
.panel-body > .rule-scenarios { padding: 0; }
.rule-scenarios-intro {
  grid-column: 1 / -1;
  margin: 0 0 0.1rem;
  line-height: 1.4;
}
.rule-scenario {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  min-width: 0;
  height: 100%;
  box-sizing: border-box;
}
.rule-scenario-h {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.rule-scenario-h strong { font-weight: 600; font-size: 0.9rem; }
.rule-scenario .rule-tier-hint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.35;
  min-height: 2.1em;
  flex-shrink: 0;
}
.rule-scenario .rule-amt {
  flex-shrink: 0;
}
.rule-amt {
  display: grid;
  gap: 0.2rem;
  padding: 0.2rem 0;
}
.rule-amt-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
  min-width: 0;
}
.rule-amt-value { font-weight: 600; color: var(--text); font-size: 0.92rem; }
.rule-tier-input {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0;
  width: 100%;
}
.rule-tier-input input {
  width: 100%;
  min-width: 0;
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  color: var(--text);
  outline: none;
}
.rule-tier-input input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.rule-tiers {
  display: grid;
  gap: 0.7rem;
  padding: 0.85rem 1rem 1rem;
}
.panel-body > .rule-tiers { padding: 0; }
.rule-tier {
  display: grid;
  gap: 0.28rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}
.rule-tier-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}
.rule-tier-head strong { font-weight: 600; }
.rule-tier-title {
  font-weight: 600;
  color: var(--text);
  font-size: 0.92rem;
}
.rule-tier-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}
.rule-tier.editable {
  cursor: default;
}

/* toast */
#toast-root {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  display: grid;
  gap: 0.45rem;
  width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  animation: toast-in 0.2s ease-out;
}
.toast.err { border-color: rgba(212, 103, 106, 0.45); }
.toast.ok { border-color: rgba(95, 173, 122, 0.45); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line-soft);
}
.pager .btn {
  padding: 0.4rem 0.85rem;
  min-width: 4.5rem;
}
.pager select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.4rem 0.65rem;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.pager select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.pager-size {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
  margin-left: 0.15rem;
}
.pager-total {
  margin-left: auto;
  font-size: 0.85rem;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-hero { padding: 0.5rem 0.25rem 0; }
  .main-view { grid-template-columns: 1fr; }
  .side {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .nav { display: flex; flex-wrap: wrap; flex: 1; }
  .nav-item { width: auto; }
  .rule-scenarios { grid-template-columns: 1fr; }
  .rule-summary { grid-template-columns: 1fr; }
  .side-foot {
    width: 100%;
    margin-top: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
  }
  .me { flex: 1; margin: 0; }
  .btn.ghost { width: auto; }
}
