:root {
  color-scheme: light;
  --bg: #f7f3ed;
  --surface: #ffffff;
  --surface-muted: #f4ece2;
  --line: #dccdb8;
  --line-soft: #eadfce;
  --line-strong: #bda98c;
  --text: #172126;
  --muted: #5c6c74;
  --nav: #394D58;
  --nav-muted: #d8dfe2;
  --nav-hover: #465f6b;
  --nav-active: #506976;
  --brand-warm: #E3BD8D;
  --on-brand: #172126;
  --accent: #015697;
  --accent-hover: #004678;
  --focus-ring: #015697;
  --focus-halo: rgba(1, 86, 151, .18);
  --danger: #a61d2d;
  --warning: #875000;
  --success-bg: #e6f4ef;
  --danger-bg: #fbeaec;
  --warning-bg: #fff1d2;
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.sidebar button:focus-visible { outline-color: var(--brand-warm); }

.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg, #f7f3ed 0%, #ead9c3 100%); }
.login-panel { width: min(400px, 100%); padding: 30px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 12px 35px rgba(57, 77, 88, .16); transition: width .16s ease; }
.login-panel.mfa-active { width: min(700px, 100%); }
.mfa-setup { display: grid; grid-template-columns: 184px minmax(0, 1fr); gap: 16px; margin-bottom: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface-muted); }
.mfa-setup-head { grid-column: 1 / -1; }
.mfa-setup-head strong { display: block; margin-bottom: 4px; }
.mfa-setup-head p, .mfa-manual-title, .mfa-clock-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.mfa-qr { display: block; width: 184px; height: 184px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
.mfa-setup-detail { min-width: 0; }
.mfa-meta { display: grid; gap: 5px; margin: 0 0 10px; }
.mfa-meta div { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 8px; }
.mfa-meta dt { color: var(--muted); font-size: 12px; }
.mfa-meta dd { min-width: 0; margin: 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 600; }
.mfa-manual-title { margin-bottom: 5px; }
.mfa-secret-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; gap: 6px; }
.mfa-secret-row code { min-width: 0; padding: 8px; overflow-wrap: anywhere; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; font-size: 13px; line-height: 1.35; user-select: all; }
.mfa-copy { min-height: 0; padding: 6px 10px; font-size: 12px; }
.mfa-steps { margin: 10px 0 8px; padding-left: 20px; color: var(--nav); font-size: 12px; line-height: 1.55; }
.mfa-clock-hint { padding: 7px 8px; color: var(--warning); background: var(--warning-bg); border-radius: 4px; }
.brand-block, .sidebar-brand { display: flex; align-items: center; gap: 12px; }
.brand-block { margin-bottom: 28px; }
.brand-block strong, .sidebar-brand strong { display: block; font-size: 18px; }
.brand-block span:not(.brand-mark), .sidebar-brand span:not(.brand-mark) { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; flex: 0 0 36px; border-radius: 5px; color: var(--on-brand); background: var(--brand-warm); box-shadow: 0 0 0 1px rgba(57, 77, 88, .18); font-size: 19px; font-weight: 700; }

label { display: grid; gap: 6px; margin-bottom: 16px; color: var(--nav); font-size: 13px; font-weight: 600; }
input, select, textarea { width: 100%; min-height: 38px; padding: 8px 10px; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 4px; outline: none; }
textarea { resize: vertical; min-height: 100px; font-family: Consolas, monospace; font-size: 12px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-halo); }
input:disabled, select:disabled { color: #6d7980; background: #eee8df; }

.primary, .secondary, .quiet { min-height: 36px; padding: 7px 14px; border-radius: 4px; border: 1px solid transparent; font-weight: 600; }
.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.secondary { color: var(--nav); background: var(--surface); border-color: var(--line-strong); }
.secondary:hover { background: var(--surface-muted); }
.quiet { padding-inline: 0; color: #f2e7d8; background: transparent; }
.full { width: 100%; }
.form-error { min-height: 18px; margin: -4px 0 12px; color: var(--danger); font-size: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px 14px; color: #fff; background: var(--nav); }
.sidebar-brand { padding: 0 8px 20px; border-bottom: 1px solid #59707b; }
.sidebar-brand span:not(.brand-mark) { color: var(--nav-muted); }
.sidebar nav { display: grid; gap: 4px; margin-top: 18px; }
.nav-item { min-height: 40px; padding: 9px 12px; text-align: left; color: #eef1f2; background: transparent; border: 1px solid transparent; border-radius: 4px; }
.nav-item:hover { color: #fff; background: var(--nav-hover); }
.nav-item.active { color: #fff; background: var(--nav-active); border-color: #70838c; box-shadow: inset 3px 0 0 var(--brand-warm); }
.sidebar-foot { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid #59707b; }
.sidebar-foot span { display: block; overflow: hidden; color: var(--nav-muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }

.workspace { min-width: 0; padding: 0 28px 40px; }
.topbar { min-height: 82px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: 21px; line-height: 1.2; }
h2 { margin-bottom: 4px; font-size: 16px; }
.topbar p, .split-heading p { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.view { display: none; padding-top: 22px; }
.view.active { display: block; }
.section-toolbar, .split-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; }
.summary-strip { display: flex; flex-wrap: wrap; gap: 18px; color: var(--muted); }
.summary-strip strong { color: var(--text); }
.split-heading.second { margin-top: 30px; }

.table-frame { width: 100%; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; }
table { width: 100%; min-width: 850px; border-collapse: collapse; }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: var(--nav); background: var(--surface-muted); font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fcf8f2; }
th.actions, td.actions { text-align: right; }
td.actions { min-width: 190px; }
.table-action { padding: 5px 8px; color: var(--accent); background: transparent; border: 0; font-weight: 600; }
.table-action.danger { color: var(--danger); }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 4px; font-size: 12px; font-weight: 600; }
.badge.ok { color: #176a4c; background: var(--success-bg); }
.badge.off { color: var(--danger); background: var(--danger-bg); }
.badge.warn { color: var(--warning); background: var(--warning-bg); }
.muted { color: var(--muted); }
.clamp-note { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.empty { margin: 0; padding: 42px; color: var(--muted); text-align: center; }
.metric-band { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); margin-bottom: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; }
.metric-item { min-height: 88px; padding: 16px; border-right: 1px solid var(--line); }
.metric-item:last-child { border-right: 0; }
.metric-item span { display: block; color: var(--muted); font-size: 12px; }
.metric-item strong { display: block; margin-top: 7px; font-size: 22px; }
.definition-table { display: grid; grid-template-columns: 190px minmax(0, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; }
.definition-table span, .definition-table strong { padding: 11px 13px; border-bottom: 1px solid var(--line-soft); }
.definition-table span { color: var(--muted); background: var(--surface-muted); }
.definition-table strong { font-weight: 600; }
.definition-table span:nth-last-child(-n+2), .definition-table strong:nth-last-child(-n+2) { border-bottom: 0; }

dialog { width: min(780px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; overflow: auto; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 20px 50px rgba(57, 77, 88, .28); }
dialog::backdrop { background: rgba(57, 77, 88, .52); }
dialog form { padding: 22px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.dialog-head p { margin-bottom: 0; color: var(--muted); font-size: 12px; }
.icon-close { width: 32px; height: 32px; flex: 0 0 32px; padding: 0; color: var(--nav); background: transparent; border: 0; font-size: 24px; line-height: 1; }
.form-grid { display: grid; gap: 0 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.toggle-row { display: flex; align-items: center; gap: 9px; min-height: 36px; }
.toggle-row input { width: 17px; min-height: 17px; margin: 0; }
.editor-section { margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
.editor-section h3 { margin: 0 0 10px; font-size: 14px; }
.section-note { margin: -5px 0 12px; color: var(--muted); font-size: 12px; }
#user-notes { min-height: 70px; font-family: inherit; font-size: 13px; }
.route-assignment-grid { display: grid; gap: 7px; }
.route-assignment-row { display: grid; grid-template-columns: 145px minmax(140px, .9fr) minmax(170px, 1.2fr) 64px; align-items: center; gap: 8px; }
.route-assignment-row select, .route-assignment-row input { min-height: 34px; margin: 0; }
.compact-check { display: flex; align-items: center; gap: 5px; margin: 0; font-size: 12px; }
.compact-check input { width: 16px; min-height: 16px; margin: 0; }
.inline-editor { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-bottom: 14px; }
.option-list { display: grid; gap: 1px; border: 1px solid var(--line); border-radius: 4px; }
.option-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; padding: 8px 11px; border-bottom: 1px solid var(--line); }
.option-row:last-child { border-bottom: 0; }
.option-row strong, .option-row span { display: block; }
.option-row span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.permission-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; margin-bottom: 4px; }
.permission-option { display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: start; gap: 10px; min-height: 58px; margin: 0; padding: 10px 0; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.permission-option input { width: 18px; min-height: 18px; margin: 2px 0 0; }
.permission-option strong, .permission-option small { display: block; }
.permission-option strong { color: var(--text); font-size: 13px; }
.permission-option small { margin-top: 3px; color: var(--muted); font-size: 12px; font-weight: 400; line-height: 1.35; }
#user-equity-cap-values { transition: opacity .15s ease; }
#user-equity-cap-values[aria-disabled="true"] { opacity: .58; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--line); }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: min(420px, calc(100vw - 44px)); padding: 11px 14px; color: #fff; background: var(--nav); border-radius: 4px; box-shadow: 0 8px 24px rgba(57, 77, 88, .24); opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .16s ease, transform .16s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; width: 100%; height: auto; padding: 12px 14px; }
  .sidebar-brand { padding-bottom: 10px; }
  .sidebar nav { grid-template-columns: repeat(2, 1fr); margin-top: 10px; }
  .nav-item { text-align: center; }
  .sidebar-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 8px; }
  .workspace { padding: 0 14px 28px; }
  .topbar { min-height: 70px; }
  .form-grid.two { grid-template-columns: 1fr; }
  .permission-grid { grid-template-columns: 1fr; }
  .route-assignment-row { grid-template-columns: 1fr; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .metric-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-item { border-bottom: 1px solid var(--line); }
  .definition-table { grid-template-columns: 140px minmax(0, 1fr); }
}

@media (max-width: 540px) {
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-toolbar, .split-heading { align-items: stretch; flex-direction: column; }
  .topbar { align-items: flex-start; padding: 14px 0; }
  .login-panel { padding: 22px; }
  .mfa-setup { grid-template-columns: 1fr; }
  .mfa-qr { justify-self: center; }
}
