:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --text: #1a201c;
  --muted: #5f6b63;
  --line: #dfe4df;
  --primary: #176747;
  --primary-soft: #e8f3ed;
  --accent: #b85c38;
  --warn: #a46416;
  --danger: #9c3b3b;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(23 35 28 / .06), 0 12px 32px rgb(23 35 28 / .05);
  --font: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 32px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 17px; letter-spacing: -.01em; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; gap: 3px; padding: 8px; }
.logo span { display: block; height: 3px; border-radius: 2px; background: white; }
.logo span:nth-child(2) { width: 70%; opacity: .75; }
.logo span:nth-child(3) { width: 45%; opacity: .55; }
.top-actions { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.live-dot { width: 8px; height: 8px; border-radius: 99px; background: #35a36e; box-shadow: 0 0 0 4px #e6f5ee; }
.shell { max-width: 1240px; margin: 0 auto; padding: 24px 28px 64px; }
.tabs { display: flex; gap: 6px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.tab { border: 0; background: transparent; color: var(--muted); padding: 10px 14px; border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.panel { display: none; }
.panel.active { display: block; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 20px; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 8px; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 14px; }
p { margin: 0; color: var(--muted); }
.filters, .resolve-form, .admin-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 9px 11px; color: var(--text); min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
button.primary { border: 0; background: var(--primary); color: #fff; border-radius: 9px; padding: 10px 16px; min-height: 40px; }
button.primary:hover { background: #11563a; }
button.primary:disabled { opacity: .5; cursor: default; }
button.ghost { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 9px; padding: 9px 13px; min-height: 40px; }
button.ghost:hover { border-color: var(--primary); color: var(--primary); }
button.small { padding: 6px 10px; min-height: 32px; font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 25px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 860px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; background: #fbfcfa; }
tbody tr:hover { background: #fafcf9; cursor: pointer; }
.badge { display: inline-block; border-radius: 999px; padding: 3px 9px; font-size: 12px; background: var(--primary-soft); color: var(--primary); }
.badge.warn { background: #fbf1e2; color: var(--warn); }
.badge.danger { background: #faeaea; color: var(--danger); }
.badge.gray { background: #f0f2f0; color: var(--muted); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.detail { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.detail h2 { margin-bottom: 8px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.detail pre { white-space: pre-wrap; word-break: break-word; background: #f5f7f4; border-radius: 9px; padding: 12px; font-size: 12px; }
.feedback-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.feedback-form textarea { grid-column: 1 / -1; min-height: 76px; }
.resolve-form input { min-width: 180px; }
#resolveResult { margin-top: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.collect-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.card label input, .card label select { display: block; width: 100%; margin-top: 4px; }
.card .primary { width: 100%; }
.hint { margin-top: 10px; font-size: 13px; }
pre { font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; }
#collectOutput { min-height: 100px; max-height: 320px; overflow: auto; background: #f5f7f4; border-radius: 9px; padding: 12px; }
.run-item, .source-item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.run-item:last-child, .source-item:last-child { border-bottom: 0; }
.source-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.source-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.source-item b { font-variant-numeric: tabular-nums; color: var(--primary); }
.toast { position: fixed; right: 24px; bottom: 24px; background: var(--text); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 20; }
@media (max-width: 800px) {
  .topbar { padding: 0 16px; }
  .shell { padding: 18px 14px 48px; }
  .section-head { display: block; }
  .filters, .resolve-form, .admin-bar { align-items: stretch; }
  .collect-grid { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
}

/* ---- wide screen layout + side detail ---- */
.shell { max-width: 1720px; padding: 24px 40px 64px; }
.topbar { padding: 0 40px; }
.table-wrap { box-shadow: var(--shadow); }
table { min-width: 760px; }
.facts-layout { display: grid; grid-template-columns: minmax(0, 1fr) 470px; gap: 20px; align-items: start; }
.detail-col { position: sticky; top: 88px; max-height: calc(100vh - 112px); overflow: auto; padding-right: 2px; }
.detail-col .detail { margin-top: 0; }
.detail-empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px 22px; color: var(--muted); display: grid; gap: 6px; }
.detail-empty b { color: var(--text); font-size: 16px; }
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-close { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 8px; width: 32px; height: 32px; line-height: 1; font-size: 18px; flex: 0 0 auto; }
.detail-close:hover { color: var(--text); border-color: var(--primary); }
tr.active { background: var(--primary-soft) !important; }
@media (max-width: 1280px) {
  .facts-layout { grid-template-columns: minmax(0, 1fr) 420px; }
}
@media (max-width: 1100px) {
  .shell { padding: 18px 16px 48px; }
  .topbar { padding: 0 16px; }
  .facts-layout { grid-template-columns: 1fr; }
  .detail-col { position: static; max-height: none; }
}
/* ---- right drawer detail ---- */
.drawer {
  position: fixed; right: 0; top: 0; height: 100vh; width: min(580px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -24px 0 70px rgb(23 35 28 / .18);
  transform: translateX(102%); transition: transform .28s cubic-bezier(.22,.8,.24,1);
  z-index: 40; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); background: #fbfcfa; flex: 0 0 auto; }
.drawer-bar strong { display: block; font-size: 16px; }
.drawer-bar small { display: block; color: var(--muted); font-size: 12px; }
.drawer-body { flex: 1 1 auto; overflow: auto; padding: 20px; margin: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent; }
.drawer-body .detail-grid { grid-template-columns: 1fr; }
.drawer-backdrop { position: fixed; inset: 0; background: rgb(18 28 22 / .32); z-index: 39; backdrop-filter: blur(2px); }
body.drawer-open { overflow: hidden; }
@media (max-width: 640px) { .drawer { width: 100vw; } }
/* ---- floating feedback + modal ---- */
[hidden] { display: none !important; }
.feedback-fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 45;
  border: 0; border-radius: 999px; padding: 12px 18px; min-height: 44px;
  background: var(--primary); color: #fff; box-shadow: 0 10px 30px rgb(23 103 71 / .28);
}
.feedback-fab:hover { background: #11563a; }
body.drawer-open .feedback-fab { right: calc(min(580px, 100vw) + 20px); }
.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgb(18 28 22 / .42); backdrop-filter: blur(3px); }
.modal { position: relative; width: min(640px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: 0 30px 90px rgb(15 25 20 / .28); padding: 22px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.modal-head h2 { margin: 0 0 4px; }
.modal-head p { font-size: 13px; }
.feedback-form label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.feedback-form input, .feedback-form select, .feedback-form textarea { width: 100%; }
.feedback-form textarea { min-height: 92px; resize: vertical; }
.span2 { grid-column: 1 / -1; }
.inline { display: grid; grid-template-columns: 1fr 100px; gap: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
@media (max-width: 900px) { body.drawer-open .feedback-fab { display: none; } .modal-wrap { padding: 12px; } }
body.modal-open { overflow: hidden; }
.detail-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.detail-actions .hint { margin: 0; }
/* ---- fluid full-width shell ---- */
.shell { max-width: none; width: 100%; padding: 20px clamp(16px, 2.4vw, 48px) 64px; }
.topbar { padding: 0 clamp(16px, 2.4vw, 48px); }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---- admin gating ---- */
body:not(.admin) .admin-only { display: none !important; }
body.admin .admin-only { display: inline-block !important; }
#adminLogout { display: none; }
body.admin #adminLogout { display: inline-block; }
.admin-status { color: var(--muted); font-size: 13px; }
body.admin .admin-status { color: var(--primary); }
/* ---- model-level rows ---- */
.price-chip { display: inline-flex; margin: 0 6px 4px 0; padding: 2px 7px; border-radius: 6px; background: #f2f6f3; color: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; }
.summary-cell { max-width: 520px; }
.line-list { display: grid; gap: 10px; margin-top: 14px; }
.line-item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fcfdfb; }
.line-main { display: grid; grid-template-columns: minmax(0, 1.4fr) auto auto minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.line-item details { margin-top: 8px; }
.line-item summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.line-item pre { margin: 8px 0 0; max-height: 240px; overflow: auto; }
@media (max-width: 1280px) { .line-main { grid-template-columns: 1fr auto auto; } .line-main > :nth-child(4) { display: none; } }
.scope-row td { background: #f2f6f3; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--text); }
.scope-row td span { color: var(--muted); margin-right: 8px; font-size: 12px; }
.scope-row td small { color: var(--muted); margin-left: 10px; font-size: 12px; }
/* ---- topbar navigation (admin only) ---- */
.topbar { gap: 24px; }
.topnav { display: none; align-items: center; gap: 2px; margin-left: 8px; margin-right: auto; overflow-x: auto; }
body.admin .topnav { display: flex; }
.topnav .tab { white-space: nowrap; padding: 8px 10px; border-bottom-width: 2px; }
.topnav .tab.active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }
@media (max-width: 900px) { .topnav { margin-left: 0; } }
/* operational metrics are admin-only */
body:not(.admin) #stats { display: none; }
/* ---- full filter bar ---- */
.filter-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; align-items: end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.filter-field { display: grid; gap: 5px; font-size: 12px; color: var(--muted); }
.filter-field input, .filter-field select { width: 100%; min-height: 36px; padding: 7px 10px; }
.search-field { grid-column: span 2; }
.filter-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: end; grid-column: span 2; }
.filter-actions button { min-height: 36px; }
.result-meta { color: var(--muted); font-size: 13px; margin: 0 2px 10px; }
@media (max-width: 900px) { .search-field, .filter-actions { grid-column: span 1; } }
/* ---- loading feedback ---- */
.is-loading { opacity: .8; cursor: wait; }
.spinner { display: inline-block; width: 13px; height: 13px; margin-right: 6px; vertical-align: -2px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.loading-state { display: flex; align-items: center; gap: 6px; padding: 28px 8px; color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }
/* ---- facts page: title row + toolbar row ---- */
.page-head { margin-bottom: 18px; }
.page-head h1 { margin-bottom: 6px; }
.filter-bar { grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.search-field { grid-column: span 4; }
.filter-bar .filter-field { grid-column: span 2; }
.filter-bar .filter-actions { grid-column: span 4; justify-content: flex-end; }
@media (max-width: 1200px) {
  .filter-bar { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .search-field { grid-column: span 3; }
  .filter-bar .filter-actions { grid-column: span 3; }
}
@media (max-width: 720px) {
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-field { grid-column: span 2; }
  .filter-bar .filter-actions { grid-column: span 2; }
}
/* price overview grows into the removed column and wraps cleanly */
.summary-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; max-width: none; }
.summary-cell .price-chip { margin: 0; }
.summary-cell { display: table-cell; }
.price-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
/* title hint: no subtitle row */
.page-head { margin-bottom: 16px; }
.title-line { display: flex; align-items: center; gap: 9px; }
.help-dot { position: relative; width: 20px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--muted); font: 600 12px/1 Georgia, serif; cursor: help; }
.help-dot:hover, .help-dot:focus-visible { color: var(--accent); border-color: var(--accent); outline: none; }
.help-dot::after { content: attr(data-tip); position: absolute; left: 0; top: calc(100% + 8px); z-index: 60; width: min(380px, calc(100vw - 40px)); padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); font: 12px/1.6 var(--font); text-align: left; box-shadow: var(--shadow); opacity: 0; visibility: hidden; transform: translateY(-3px); transition: opacity .12s ease, transform .12s ease; pointer-events: none; }
.help-dot:hover::after, .help-dot:focus-visible::after { opacity: 1; visibility: visible; transform: translateY(0); }
/* brand hint moved into top-left title area */
.brand-copy { display: flex; flex-direction: column; gap: 2px; }
.brand-line { display: flex; align-items: center; gap: 8px; }
.brand-line .help-dot { width: 17px; height: 17px; font-size: 10px; }
.brand-line .help-dot::after { top: calc(100% + 10px); }
/* ---- pagination ---- */
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.pager[hidden] { display: none; }
.page-info { margin-right: auto; }
.page-size { display: flex; align-items: center; gap: 6px; }
.page-size select { min-height: 30px; padding: 4px 8px; }
.pager button { min-height: 30px; padding: 4px 10px; }
/* ---- feedback fact picker ---- */
.fb-record { display: grid; gap: 6px; }
.fb-record > label { font-size: 13px; color: var(--muted); }
.fb-picker { position: relative; }
.fb-picker input { width: 100%; }
.fb-results { position: absolute; z-index: 70; left: 0; right: 0; top: calc(100% + 5px); max-height: 280px; overflow: auto; padding: 4px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); box-shadow: var(--shadow); }
.fb-result { display: flex; align-items: center; justify-content: space-between; gap: 14px; width: 100%; padding: 8px 9px; border: 0; border-radius: 6px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.fb-result:hover, .fb-result:focus-visible { background: var(--surface-2, #f4f6f3); outline: none; }
.fb-result span { display: grid; gap: 2px; min-width: 0; }
.fb-result strong, .fb-result small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-result small { color: var(--muted); font-size: 12px; }
.fb-result b { flex: none; font-size: 13px; font-weight: 600; }
.fb-empty { padding: 10px; color: var(--muted); font-size: 12px; }
.fb-selected { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2, #f4f6f3); }
.fb-selected div { display: grid; gap: 2px; min-width: 0; }
.fb-selected small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* keep model search/filter visible while scrolling long lists */
@media (min-width: 900px) {
  .filter-bar {
    position: sticky;
    top: 0;
    z-index: 30;
  }
}
/* compact, readable update time */
.update-cell { white-space: nowrap; color: var(--muted); font-size: 13px; }
.update-cell time { font-variant-numeric: tabular-nums; }
/* structured conditions */
.cond-note { display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 999px; background: #f1f3ef; color: var(--muted); font-size: 11px; }
.cond-block { display: grid; gap: 7px; padding: 10px 0 2px; }
.cond-head { color: var(--muted); font-size: 12px; font-weight: 600; }
.cond-list { display: grid; gap: 3px; margin: 0; padding-left: 18px; color: var(--text); font-size: 12px; }
.cond-empty { color: var(--muted); font-size: 12px; }
.cond-meta { color: var(--muted); font-size: 12px; }
.cond-links { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; }
.cond-links a { color: var(--primary); text-decoration: none; }
.cond-links a:hover { text-decoration: underline; }
.src-link { font-weight: 600; }
.page-size input { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; }
/* searchable filter comboboxes */
.combo { position: relative; width: 100%; }
.combo-native { display: none; }
.combo-input { width: 100%; }
.combo-menu { position: absolute; z-index: 80; left: 0; right: 0; top: calc(100% + 4px); max-height: 280px; overflow: auto; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.combo-option { display: block; width: 100%; padding: 7px 9px; border: 0; border-radius: 5px; background: transparent; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.combo-option:hover, .combo-option:focus-visible { background: var(--surface-2, #f4f6f3); outline: none; }
.combo-empty { padding: 8px 9px; color: var(--muted); font-size: 12px; }
.combo::after { content: "⌄"; position: absolute; right: 10px; top: 50%; transform: translateY(-55%); color: var(--muted); font-size: 12px; pointer-events: none; }
.combo .combo-input { padding-right: 28px; }