:root {
  --canvas: #f4f6f8;
  --paper: #f4f6f8;
  --card: #ffffff;
  --ink: #17252a;
  --muted: #65717a;
  --line: #dce4e2;
  --nav: #101318;
  --cyan: #00a6a6;
  --orange: #e8783e;
  --green: #24845f;
  --blue: #356fa3;
  --shadow: 0 8px 22px rgba(17, 42, 45, .06);
}
* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); font-family: "Microsoft YaHei UI", "Noto Sans SC", sans-serif; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select { font: inherit; }
button, select, input { border-radius: 0; }
button { cursor: pointer; }
.app-frame { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.side-nav { position: sticky; top: 0; height: 100vh; padding: 1.5rem 1.2rem; background: var(--nav); color: #eaf5f2; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: .75rem; color: inherit; text-decoration: none; padding-bottom: 1.4rem; border-bottom: 1px solid rgba(255,255,255,.14); }
.brand-mark { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--cyan); color: var(--cyan); font: 900 .9rem/1 Consolas, monospace; }
.brand strong, .brand small { display: block; }
.brand small { margin-top: .18rem; color: #9fb5b5; font-size: .72rem; }
.side-nav nav { display: grid; gap: .5rem; margin-top: 1.4rem; }
.side-nav nav > a, .side-nav nav section > a, .disabled-link { display: block; padding: .72rem .75rem; color: #c7d5d3; text-decoration: none; border-left: 3px solid transparent; font-size: .88rem; }
.side-nav nav section { margin: .35rem 0; padding: .45rem 0 .55rem; border-top: 1px solid rgba(255,255,255,.09); border-bottom: 1px solid rgba(255,255,255,.09); }
.side-nav nav section > p { margin: .25rem .75rem .4rem; color: #7f9a9a; font-size: .7rem; letter-spacing: .14em; text-transform: uppercase; }
.side-nav nav a:hover { color: #fff; background: rgba(255,255,255,.055); }
.side-nav nav a.active { color: #fff; background: rgba(55,184,177,.14); border-left-color: var(--cyan); font-weight: 800; }
.disabled-link { color: #6f8584; cursor: not-allowed; }
.side-note { margin-top: auto; color: #7f9a9a; font: 700 .72rem/1.7 Consolas, monospace; letter-spacing: .08em; }
main { min-width: 0; padding: 1.15rem clamp(1rem, 3vw, 3rem) 3rem; }
.management-page-head { margin: 0 0 .85rem; padding: .95rem 1.05rem; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.eyebrow, .section-kicker { margin: 0; color: #176963; font: 800 .72rem/1.3 Consolas, monospace; letter-spacing: .16em; }
h1 { margin: .16rem 0 .24rem; font-size: 1.56rem; line-height: 1.12; letter-spacing: 0; }
.management-page-head > p:last-child { max-width: 820px; margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.55; }
.acceptance-order { margin: .85rem 0 0; padding: .9rem 1rem; border: 1px solid var(--line); border-left: 3px solid var(--cyan); background: var(--card); display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .85fr); gap: .85rem 1rem; align-items: end; }
.acceptance-order h2 { margin: .25rem 0 .4rem; font-size: 1.35rem; }
.acceptance-order p { margin: 0; color: var(--muted); font-size: .82rem; line-height: 1.65; }
.acceptance-order-action { display: grid; grid-template-columns: minmax(220px, 1fr) auto; gap: .65rem; align-items: end; }
.acceptance-order-action label { display: grid; gap: .38rem; color: #48565e; font-size: .76rem; font-weight: 800; }
.acceptance-order-action button { min-height: 42px; border: 1px solid var(--nav); background: var(--nav); color: #fff; padding: .65rem 1rem; font-weight: 850; white-space: nowrap; }
.acceptance-order-action button:hover { border-color: var(--cyan); background: var(--cyan); color: #092825; }
.acceptance-order-action button:disabled { cursor: wait; border-color: #87918e; background: #87918e; color: #eef2ef; }
.acceptance-order-status { grid-column: 1 / -1; padding-top: .75rem; border-top: 1px solid #d9e1dd; font-weight: 750; }
.acceptance-order-status[data-state="loading"] { color: var(--blue); }
.acceptance-order-status[data-state="success"] { color: var(--green); }
.acceptance-order-status[data-state="error"] { color: #a33f2a; }
.filters { margin: 1.5rem 0; display: grid; grid-template-columns: repeat(3, minmax(150px, .7fr)) minmax(220px, 1.2fr) auto; gap: .75rem; align-items: end; }
.filters label, .field-drawer label { display: grid; gap: .38rem; color: #48565e; font-size: .76rem; font-weight: 800; }
select, input { width: 100%; min-height: 42px; border: 1px solid #9eaaa7; background: var(--card); color: var(--ink); padding: .65rem .7rem; outline: none; }
select:focus, input:focus, button:focus-visible, tr.field-row:focus-visible { outline: 3px solid rgba(55,184,177,.32); outline-offset: 1px; border-color: #17726d; }
.reset-button { min-height: 42px; border: 1px solid var(--ink); background: transparent; color: var(--ink); padding: .65rem 1rem; font-weight: 800; }
.reset-button:hover { background: var(--ink); color: #fff; }
.ledger { background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.ledger-head { padding: 1.2rem 1.3rem .75rem; display: flex; justify-content: space-between; gap: 1rem; align-items: end; }
.ledger-head h2 { margin: .2rem 0 0; font-size: 1.45rem; }
.ledger-head > p { margin: 0; color: var(--muted); font-size: .82rem; }
.group-hint { margin: 0; padding: 0 1.3rem 1rem; color: var(--muted); font-size: .82rem; }
.page-state { padding: 2rem 1.3rem; border-top: 1px solid var(--line); color: var(--muted); }
.table-shell { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 1080px; }
th { padding: .78rem 1rem; background: #edf4f3; color: #435159; text-align: left; font-size: .74rem; letter-spacing: .04em; }
th:nth-child(1) { width: 17%; }
th:nth-child(2) { width: 9%; }
th:nth-child(3) { width: 14%; }
th:nth-child(4) { width: 27%; }
th:nth-child(5) { width: 21%; }
th:nth-child(6) { width: 12%; }
td { padding: .88rem 1rem; border-top: 1px solid #e1e6e3; vertical-align: middle; font-size: .86rem; }
.group-row td { padding: 0; background: #eef3f0; border-top: 1px solid #bfcac5; }
.group-toggle { width: 100%; display: flex; justify-content: space-between; align-items: center; border: 0; background: transparent; color: var(--ink); padding: .7rem 1rem; font-weight: 900; text-align: left; }
.group-toggle span:last-child { color: var(--muted); font: 700 .75rem Consolas, monospace; }
.field-row { cursor: pointer; background: var(--card); }
.field-row:hover { background: #f2f7f4; box-shadow: inset 4px 0 var(--cyan); }
.field-row td { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cell-truncate, .current-value-preview { display: block; width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.current-value-preview { color: #31444c; }
button.current-value-preview { border: 0; border-bottom: 1px dashed #17726d; background: transparent; padding: 0 0 .08rem; color: #0d6f69; text-align: left; font-weight: 750; }
button.current-value-preview:hover { color: #084c48; border-bottom-style: solid; }
.field-name { font-weight: 850; }
.level-chip, .source-chip, .status-chip { display: inline-flex; align-items: center; min-height: 25px; padding: .2rem .5rem; border: 1px solid currentColor; font-size: .72rem; font-weight: 800; white-space: nowrap; }
.level-chip { color: #53636c; border-color: #a8b4b1; }
.source-chip[data-type="API_DIRECT"] { color: #0d6f69; }
.source-chip[data-type="SYSTEM_DERIVED"] { color: #7d4a1f; }
.source-chip[data-type="TECHNICAL_FIXED"] { color: #4d5f7c; }
.source-chip[data-type="CUSTOM_CONFIG"] { color: #77517f; }
.status-chip[data-status="PENDING_CONFIRMATION"] { color: #a34c1f; background: #fff2e9; }
.status-chip[data-status="CONFIRMED"] { color: var(--green); background: #eaf7f0; }
.status-chip[data-status="LOCKED"] { color: var(--blue); background: #ebf3fa; }
.page-foot { margin-top: 1.2rem; padding: 1rem 1.2rem; border-left: 4px solid var(--orange); background: rgba(255,255,255,.55); display: grid; gap: .35rem; color: var(--muted); font-size: .84rem; }
.page-foot strong { color: var(--ink); }
.field-drawer { width: min(560px, 100vw); height: 100vh; max-height: 100vh; margin: 0 0 0 auto; border: 0; border-left: 1px solid var(--line); padding: 0; background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.field-drawer::backdrop { background: rgba(10, 23, 28, .48); }
.field-drawer[open] { animation: drawer-in .18s ease-out; }
@keyframes drawer-in { from { transform: translateX(28px); opacity: .6; } to { transform: translateX(0); opacity: 1; } }
.field-drawer form { min-height: 100%; padding: 1.4rem; display: flex; flex-direction: column; gap: 1.15rem; }
.drawer-head { display: flex; justify-content: space-between; gap: 1rem; align-items: start; padding-bottom: 1rem; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: .3rem 0 0; font-size: 1.7rem; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); background: transparent; color: var(--ink); font-size: 1.5rem; }
.read-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
input[readonly], input:disabled, select:disabled { background: #edf0ed; color: #67736f; cursor: not-allowed; }
.field-drawer small { color: var(--muted); font-weight: 400; line-height: 1.55; }
.rule-field { display: grid; gap: .4rem; }
.rule-field > span { color: #48565e; font-size: .76rem; font-weight: 800; }
.rule-field p, .drawer-note { margin: 0; padding: .85rem; background: #edf3f0; color: #405058; line-height: 1.75; font-size: .84rem; white-space: normal; }
.current-value-panel { display: grid; gap: .4rem; }
.current-value-panel > span { color: #48565e; font-size: .76rem; font-weight: 800; }
.current-value-panel > p { margin: 0; padding: .85rem; border-left: 3px solid var(--cyan); background: #edf3f0; color: #263b43; line-height: 1.65; overflow-wrap: anywhere; }
.drawer-current-items { display: grid; gap: .55rem; max-height: 38vh; overflow-y: auto; padding-right: .15rem; }
.drawer-current-items article { padding: .75rem .85rem; border: 1px solid #d5ddda; background: #f7f9f6; display: grid; gap: .3rem; }
.drawer-current-items article strong { color: #176963; font-size: .8rem; }
.drawer-current-items article span { color: var(--muted); font: 700 .72rem/1.5 Consolas, "Microsoft YaHei UI", sans-serif; overflow-wrap: anywhere; }
.drawer-current-items article p { margin: 0; color: var(--ink); font-size: .84rem; line-height: 1.55; overflow-wrap: anywhere; }
.drawer-note:empty, .drawer-error:empty { display: none; }
.drawer-error { padding: .75rem; border: 1px solid #c35b45; color: #973a28; background: #fff0ec; font-size: .82rem; }
.drawer-actions { margin-top: auto; display: flex; justify-content: flex-end; gap: .6rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.drawer-actions button { border: 1px solid var(--ink); background: var(--ink); color: #fff; padding: .72rem 1rem; font-weight: 850; }
.drawer-actions button.secondary { background: transparent; color: var(--ink); }
.drawer-actions button:hover { background: var(--cyan); border-color: var(--cyan); color: #092825; }
[hidden] { display: none !important; }
@media (max-width: 900px) {
  .app-frame { grid-template-columns: 1fr; }
  .side-nav { position: static; height: auto; padding: 1rem; }
  .side-nav nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-nav nav section { grid-column: 1 / -1; }
  .side-note { display: none; }
  .acceptance-order { grid-template-columns: 1fr; }
  .acceptance-order-status { grid-column: auto; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reset-button { align-self: end; }
}
@media (max-width: 620px) {
  main { padding: 1rem; }
  .acceptance-order { padding: 1rem; }
  .acceptance-order-action { grid-template-columns: 1fr; }
  .filters, .read-grid { grid-template-columns: 1fr; }
  .search-label { grid-column: auto; }
  .field-drawer { width: 100vw; }
}
@media (prefers-reduced-motion: reduce) {
  .field-drawer[open] { animation: none; }
}

/* Custom field creation */
.ledger-actions { display: flex; align-items: center; justify-content: flex-end; gap: .9rem; flex-wrap: wrap; }
.ledger-actions p { margin: 0; }
.ledger-actions button { min-height: 40px; border: 1px solid var(--nav); background: var(--nav); color: #fff; padding: .6rem .85rem; font-weight: 850; white-space: nowrap; }
.ledger-actions button:hover { border-color: var(--cyan); background: var(--cyan); color: #092825; }
.source-chip[data-type="FORMULA_CALCULATION"] { color: #a34c1f; background: #fff2e9; }
.cell-truncate { display: block; max-width: 26rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td, th { max-width: 30rem; }
.current-value-preview { display: block; max-width: 18rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.current-value-preview { width: 100%; border: 0; padding: 0; background: transparent; color: #176963; text-align: left; text-decoration: underline; }
textarea { width: 100%; resize: vertical; min-height: 96px; border: 1px solid #9eaaa7; border-radius: 0; background: var(--card); color: var(--ink); padding: .7rem; font: inherit; line-height: 1.6; outline: none; }
textarea:focus { outline: 3px solid rgba(55,184,177,.32); outline-offset: 1px; border-color: #17726d; }
.api-picker-field { display: grid; gap: .55rem; }
.api-picker-field > span { color: #48565e; font-size: .76rem; font-weight: 800; }
.api-option-list { display: grid; gap: .5rem; max-height: 42vh; overflow-y: auto; padding: .15rem; border: 1px solid #d2dad7; background: #f2f5f2; }
.api-option-card { width: 100%; min-width: 0; padding: .72rem .78rem; border: 1px solid #c7d1cd; background: var(--card); color: var(--ink); display: grid; gap: .3rem; text-align: left; }
.api-option-card:hover:not(:disabled), .api-option-card[data-selected="true"] { border-color: #17726d; box-shadow: inset 4px 0 0 var(--cyan); }
.api-option-card:disabled { cursor: not-allowed; opacity: .58; background: #e9edeb; }
.api-option-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; min-width: 0; }
.api-option-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.api-option-path { color: #176963; font: 800 .76rem/1.45 Consolas, monospace; }
.api-option-current { color: #34464e; font-size: .78rem; }
.api-option-meta { color: var(--muted); font-size: .68rem; letter-spacing: .03em; }
.api-option-empty { margin: 0; padding: 1rem; color: var(--muted); text-align: center; }
.api-option-list[data-readonly="true"] .api-option-card { pointer-events: none; }
.drawer-current-item { padding: .75rem .85rem; border: 1px solid #d5ddda; background: #f7f9f6; display: grid; gap: .3rem; }
.drawer-current-item strong { color: #176963; font-size: .8rem; }
.drawer-current-item span { color: var(--muted); font: 700 .72rem/1.5 Consolas, "Microsoft YaHei UI", sans-serif; overflow-wrap: anywhere; }
.creation-drawer { width: min(680px, 100vw); }
.step-rail { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); }
.step-rail li { padding: .7rem .45rem; color: var(--muted); background: #edf0ed; text-align: center; font-size: .74rem; font-weight: 800; }
.step-rail li + li { border-left: 1px solid var(--line); }
.step-rail li[data-active="true"] { color: #0b4f4b; background: #dff4ef; box-shadow: inset 0 -3px 0 var(--cyan); }
.create-step { display: grid; gap: 1rem; }
.source-choice { margin: 0; padding: 0; border: 0; display: grid; gap: .55rem; }
.source-choice legend { margin-bottom: .55rem; color: #48565e; font-size: .76rem; font-weight: 800; }
.source-choice label { grid-template-columns: auto 1fr; align-items: start; gap: .7rem; padding: .75rem; border: 1px solid var(--line); background: #f7f9f6; cursor: pointer; }
.source-choice input { width: 18px; min-height: 18px; margin: .15rem 0 0; accent-color: #17726d; }
.source-choice span { display: grid; gap: .2rem; }
.source-choice strong { color: var(--ink); }
.source-choice small { color: var(--muted); font-weight: 400; }
.source-choice label:has(input:checked) { border-color: #17726d; box-shadow: inset 4px 0 0 var(--cyan); }
.source-choice label:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.source-panel { display: grid; gap: .8rem; padding: .9rem; border: 1px solid #c7d1cd; border-left: 4px solid var(--cyan); background: #f5f8f5; }
.source-summary { margin: 0; padding: .75rem; background: #e8efec; color: #405058; font-size: .82rem; line-height: 1.65; }
.review-card { display: grid; border: 1px solid var(--line); background: #f7f9f6; }
.review-card > div { min-width: 0; display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: .8rem; padding: .72rem .8rem; }
.review-card > div + div { border-top: 1px solid #dde3e0; }
.review-card span { color: var(--muted); font-size: .76rem; font-weight: 800; }
.review-card strong { min-width: 0; color: var(--ink); font-size: .82rem; }

@media (max-width: 900px) {
  .ledger-actions { justify-content: flex-start; }
  .cell-truncate { max-width: 18rem; }
}
@media (max-width: 620px) {
  .ledger-actions { align-items: stretch; flex-direction: column; }
  .ledger-actions button { width: 100%; }
  .step-rail li { font-size: .66rem; }
  .review-card > div { grid-template-columns: 1fr; gap: .25rem; }
  .api-option-list { max-height: 34vh; }
}

.formula-editor { display: grid; gap: .75rem; }
.formula-panel { display: grid; gap: .75rem; padding: .75rem; border: 1px solid #d2dad7; background: #f7f9f6; }
.formula-row { display: flex; gap: .75rem; align-items: end; flex-wrap: wrap; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.multi-term-list { display: grid; gap: .55rem; }
.formula-term-row { display: grid; grid-template-columns: minmax(7rem, .7fr) minmax(11rem, 1fr) minmax(16rem, 2fr) auto; gap: .55rem; align-items: end; }
.formula-term-row select { min-width: 0; }
.formula-term-row .formula-term-kind-select { min-width: 10rem; }
.formula-term-row .formula-term-identity-select { min-width: 14rem; }
.formula-term-actions { display: flex; gap: .4rem; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.mini-button { min-height: 34px; padding: .45rem .7rem; font-size: .78rem; }
.formula-term-row .remove-term { border-color: #c88c7a; color: #8b3c27; }
@media (max-width: 620px) {
  .two-columns { grid-template-columns: 1fr; }
  .formula-term-row { grid-template-columns: 1fr; }
}
