:root {
  --ink: #18211d;
  --muted: #68736d;
  --line: #d9dfda;
  --paper: #f7f8f6;
  --white: #fff;
  --green: #173f46;
  --green-soft: #e8f0ef;
  --gold: #a37b2c;
  --gold-soft: #f7f1e4;
  --red: #8b3d35;
  --blue: #336d85;
  --shadow: 0 18px 60px rgba(28, 42, 35, .16);
}

* { box-sizing: border-box; }
html { color: var(--ink); background: var(--paper); font-family: "PingFang SC", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
body { min-width: 320px; margin: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.config-header { position: fixed; z-index: 20; inset: 0 0 auto; height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 24px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.config-brand { display: flex; align-items: center; gap: 11px; }
.config-brand > span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 4px; color: #fff; background: var(--green); font-family: Georgia, serif; font-size: 13px; font-weight: 800; }
.config-brand strong { font-family: "Songti SC", serif; font-size: 18px; }
.config-brand small { padding-left: 10px; border-left: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.config-header-actions { display: flex; align-items: center; gap: 18px; color: var(--muted); font-size: 11px; }
.config-header-actions a { min-height: 34px; display: flex; align-items: center; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; color: var(--green); background: #fff; font-weight: 750; }

.config-shell { min-height: 100vh; padding-top: 64px; }
.config-nav { position: fixed; z-index: 10; inset: 64px auto 0 0; width: 238px; display: flex; flex-direction: column; padding: 26px 14px 18px; border-right: 1px solid var(--line); background: #f2f5f2; }
.config-nav > p { margin: 0 10px 14px; color: var(--muted); font-size: 10px; font-weight: 850; }
.config-nav > button { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border: 0; border-radius: 4px; color: #50605a; background: transparent; font-size: 12px; font-weight: 750; text-align: left; }
.config-nav > button span { width: 23px; height: 23px; display: grid; place-items: center; border: 1px solid #cbd5cf; border-radius: 3px; font-family: "Songti SC", serif; font-size: 11px; }
.config-nav > button:hover { background: #e8eeea; }
.config-nav > button.is-active { color: #fff; background: var(--green); }
.config-nav > button.is-active span { border-color: rgba(255,255,255,.4); }
.config-nav-foot { display: grid; gap: 7px; margin-top: auto; padding: 18px 10px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.config-nav-foot b { color: var(--red); }

.config-main { margin-left: 238px; }
.config-view { width: min(1320px, 100%); min-height: calc(100vh - 64px); padding: 42px clamp(28px, 4vw, 62px) 70px; }
.page-title { min-height: 106px; display: flex; align-items: flex-start; justify-content: space-between; gap: 30px; padding-bottom: 24px; border-bottom: 2px solid var(--ink); }
.page-title span, .section-head span { color: var(--gold); font-size: 10px; font-weight: 900; }
.page-title h1 { margin: 7px 0 8px; font-family: "Songti SC", serif; font-size: clamp(28px, 3vw, 40px); line-height: 1.15; }
.page-title p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.title-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }
.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0 15px; border: 1px solid transparent; border-radius: 4px; font-size: 11px; font-weight: 800; }
.button.primary { color: #fff; background: var(--green); }
.button.secondary { border-color: var(--line); color: var(--green); background: #fff; }
.text-button { padding: 5px 0; border: 0; color: var(--blue); background: transparent; font-size: 11px; font-weight: 800; }

.status-ledger { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.status-ledger article { min-height: 126px; padding: 25px 22px; border-right: 1px solid var(--line); }
.status-ledger article:first-child { padding-left: 0; }
.status-ledger article:last-child { border-right: 0; }
.status-ledger span { display: block; color: var(--muted); font-size: 10px; }
.status-ledger strong { display: block; margin: 14px 0 5px; font-family: "Songti SC", serif; font-size: 28px; }
.status-ledger small { color: var(--muted); font-size: 10px; }
.status-ledger .is-ok { color: var(--green); }
.status-ledger .is-warn { color: var(--red); }

.route-board, .rule-summary { padding: 34px 0; border-bottom: 1px solid var(--line); }
.section-head { display: flex; justify-content: space-between; gap: 20px; }
.section-head h2 { margin: 5px 0 0; font-family: "Songti SC", serif; font-size: 21px; }
.route-track { display: grid; grid-template-columns: minmax(160px, .8fr) 60px minmax(210px, 1fr) 60px minmax(180px, .8fr); align-items: stretch; margin-top: 24px; }
.route-node { min-height: 94px; display: grid; align-content: center; gap: 7px; padding: 17px; border: 1px solid var(--line); background: #fff; }
.route-node.is-primary { border-top: 3px solid var(--green); }
.route-node.is-fallback { border-top: 3px solid var(--gold); }
.route-node span { color: var(--muted); font-size: 9px; }
.route-node strong { font-size: 13px; }
.route-node small { color: var(--muted); font-size: 10px; }
.route-arrow { display: grid; place-items: center; color: var(--gold); font-size: 21px; }
.route-empty { grid-column: 1 / -1; padding: 28px; border: 1px dashed #bdc8c1; color: var(--muted); text-align: center; }

.rule-flow { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 24px; }
.rule-flow article { position: relative; min-height: 102px; padding: 17px 24px 17px 17px; border: 1px solid var(--line); border-right: 0; background: #fff; }
.rule-flow article:last-child { border-right: 1px solid var(--line); }
.rule-flow article:not(:last-child)::after { content: ""; position: absolute; z-index: 2; top: 43px; right: -6px; width: 10px; height: 10px; border-top: 1px solid var(--gold); border-right: 1px solid var(--gold); background: #fff; transform: rotate(45deg); }
.rule-flow span { color: var(--gold); font-size: 9px; font-weight: 850; }
.rule-flow strong { display: block; margin: 8px 0 5px; font-size: 12px; }
.rule-flow small { color: var(--muted); font-size: 10px; line-height: 1.55; }
.safety-lines { display: flex; flex-wrap: wrap; gap: 10px 20px; margin-top: 18px; }
.safety-lines span { color: var(--red); font-size: 10px; }
.safety-lines span::before { content: "锁"; margin-right: 6px; font-weight: 900; }

.data-table-wrap { overflow: auto; border-bottom: 1px solid var(--line); }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.data-table th { height: 52px; color: var(--muted); font-size: 10px; text-align: left; }
.data-table td { min-height: 62px; padding: 15px 12px 15px 0; border-top: 1px solid var(--line); font-size: 11px; vertical-align: middle; }
.data-table td strong { display: block; color: var(--ink); font-size: 12px; }
.data-table td small { display: block; max-width: 280px; margin-top: 4px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; }
.data-table .empty-cell { padding: 48px 0; color: var(--muted); text-align: center; }
.badge { display: inline-flex; min-height: 24px; align-items: center; padding: 0 7px; border-radius: 3px; color: var(--green); background: var(--green-soft); font-size: 9px; font-weight: 800; }
.badge.gold { color: #795711; background: var(--gold-soft); }
.badge.red { color: var(--red); background: #f6e9e7; }
.row-actions { display: flex; justify-content: flex-end; gap: 9px; }
.data-table .check-row { position: relative; display: inline-flex; cursor: pointer; }
.data-table .check-row input { position: absolute; opacity: 0; pointer-events: none; }

.route-explainer { display: flex; flex-wrap: wrap; gap: 10px 24px; padding: 17px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.route-explainer strong { color: var(--green); }
.event-toolbar { height: 58px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.event-toolbar label { display: flex; align-items: center; gap: 9px; }
.event-toolbar input { width: 220px; min-height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }

.policy-sheet { display: grid; grid-template-columns: 1fr 1fr; gap: 0 36px; }
.policy-band { min-width: 0; display: grid; align-content: start; grid-template-columns: 1fr 1fr; gap: 18px; margin: 0; padding: 28px 0; border: 0; border-bottom: 1px solid var(--line); }
.policy-band legend { grid-column: 1 / -1; padding: 0 0 16px; color: var(--green); font-family: "Songti SC", serif; font-size: 18px; font-weight: 800; }
.policy-band label { display: grid; gap: 7px; color: var(--muted); font-size: 10px; }
.policy-band input[type="number"], .policy-band select { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: #fff; }
.policy-band small { line-height: 1.45; }
.policy-band:first-child, .safety-band { grid-column: 1 / -1; }
.switch-row { grid-column: span 1; min-height: 58px; grid-template-columns: 1fr auto !important; align-items: center; padding: 9px 0; }
.switch-row > span { display: grid; gap: 4px; }
.switch-row b { color: var(--ink); font-size: 11px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row i, .event-switch { position: relative; width: 40px; height: 22px; border-radius: 12px; background: #c9d0cc; transition: .18s; }
.switch-row i::after, .event-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .18s; }
.switch-row input:checked + i, input:checked + .event-switch { background: var(--green); }
.switch-row input:checked + i::after, input:checked + .event-switch::after { transform: translateX(18px); }
.switch-row.compact { min-height: 40px; }
.inline-inputs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.inline-inputs em { color: var(--muted); font-style: normal; }
.safety-band { grid-template-columns: 1fr; }
.safety-band > div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); }
.safety-band p { min-height: 74px; margin: 0; padding: 16px; color: var(--red); background: var(--white); font-size: 10px; line-height: 1.6; }

.access-state { min-height: 100vh; display: grid; place-content: center; justify-items: center; padding: 30px; text-align: center; }
.access-state > span { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 5px; color: #fff; background: var(--green); font-family: Georgia, serif; }
.access-state h1 { margin: 24px 0 8px; font-family: "Songti SC", serif; font-size: 28px; }
.access-state p { margin: 0 0 24px; color: var(--muted); font-size: 12px; }
.admin-login-form { width: min(360px, calc(100vw - 40px)); display: grid; gap: 14px; padding: 22px; border: 1px solid var(--line); background: #fff; text-align: left; }
.admin-login-form label { display: grid; gap: 7px; color: var(--muted); font-size: 10px; }
.admin-login-form input { width: 100%; min-height: 42px; padding: 0 11px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: #fff; }
.admin-login-form .button { width: 100%; margin-top: 2px; }
.admin-login-form small { min-height: 16px; color: var(--red); font-size: 10px; text-align: center; }
.back-to-workbench { margin-top: 18px; color: var(--blue); font-size: 11px; font-weight: 750; }

dialog { width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto; border: 0; border-radius: 6px; background: #fff; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(17, 29, 23, .55); }
.dialog-form > header { display: flex; align-items: flex-start; justify-content: space-between; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.dialog-form header span { color: var(--gold); font-size: 9px; font-weight: 850; }
.dialog-form h2 { margin: 5px 0 0; font-family: "Songti SC", serif; font-size: 21px; }
.dialog-form header button { width: 32px; height: 32px; border: 0; border-radius: 4px; color: var(--muted); background: transparent; font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 24px; }
.form-grid label { display: grid; gap: 7px; color: var(--muted); font-size: 10px; }
.form-grid input, .form-grid select { width: 100%; min-height: 40px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: #fff; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid .check-row { display: flex; align-items: center; gap: 9px; color: var(--ink); }
.form-grid .check-row input { width: 17px; min-height: 17px; }
.dialog-form footer { display: flex; justify-content: flex-end; gap: 9px; padding: 17px 24px; border-top: 1px solid var(--line); }
.dialog-message { min-height: 18px; margin: 0; padding: 0 24px 12px; color: var(--red); font-size: 10px; }
.toast { position: fixed; z-index: 80; right: 22px; bottom: 22px; max-width: min(360px, calc(100vw - 44px)); padding: 12px 16px; border-radius: 4px; color: #fff; background: var(--green); box-shadow: var(--shadow); font-size: 11px; transform: translateY(30px); opacity: 0; pointer-events: none; transition: .2s; }
.toast.is-visible { transform: translateY(0); opacity: 1; }
.toast.is-error { background: var(--red); }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }

@media (max-width: 900px) {
  .config-header { height: 58px; padding: 0 14px; }
  .config-brand strong { font-size: 15px; }
  .config-brand small, .config-header-actions > span { display: none; }
  .config-shell { padding-top: 58px; }
  .config-nav { position: sticky; z-index: 8; top: 58px; width: 100%; height: 54px; display: flex; flex-direction: row; gap: 5px; padding: 7px 10px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .config-nav > p, .config-nav-foot { display: none; }
  .config-nav > button { width: auto; min-width: max-content; min-height: 38px; padding: 0 11px; }
  .config-nav > button span { display: none; }
  .config-main { margin-left: 0; }
  .config-view { min-height: auto; padding: 28px 20px 60px; }
  .status-ledger { grid-template-columns: 1fr 1fr; }
  .status-ledger article:nth-child(2) { border-right: 0; }
  .status-ledger article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .route-track { grid-template-columns: 1fr; gap: 8px; }
  .route-arrow { height: 22px; transform: rotate(90deg); }
  .rule-flow { grid-template-columns: 1fr 1fr; }
  .rule-flow article { border-right: 1px solid var(--line); }
  .rule-flow article::after { display: none; }
  .policy-sheet { grid-template-columns: 1fr; }
  .policy-band, .policy-band:first-child, .safety-band { grid-column: 1; }
  .safety-band > div { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .config-header-actions a { padding: 0 9px; }
  .page-title { min-height: 0; display: grid; gap: 18px; }
  .page-title h1 { font-size: 29px; }
  .page-title > .button { justify-self: start; }
  .title-actions { justify-content: flex-start; }
  .status-ledger { grid-template-columns: 1fr; }
  .status-ledger article { min-height: 94px; padding: 19px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .status-ledger article strong { margin: 9px 0 3px; font-size: 24px; }
  .rule-flow { grid-template-columns: 1fr; }
  .policy-band { grid-template-columns: 1fr; }
  .switch-row { grid-column: 1; }
  .form-grid { grid-template-columns: 1fr; padding: 20px; }
  .form-grid .span-2 { grid-column: 1; }
  .event-toolbar { align-items: flex-start; flex-direction: column; justify-content: center; gap: 7px; height: 82px; }
  .event-toolbar input { width: min(260px, 72vw); }
}
