:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #18212b;
  --muted: #667085;
  --line: #dfe5ea;
  --line-strong: #c8d1d8;
  --accent: #12645a;
  --accent-soft: #e7f3f0;
  --warning: #a15c11;
  --danger: #b42318;
  --ok: #087443;
  --shadow: 0 12px 32px rgba(22, 34, 45, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

body.is-locked {
  display: block;
}

body.is-locked .sidebar,
body.is-locked main {
  display: none;
}

.login-screen {
  display: none;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 20%, #e7f3f0, transparent 28%), var(--bg);
}

body.is-locked .login-screen {
  display: grid;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 2px 0 0;
  font-size: 24px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.session-box {
  display: grid;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 6px 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.session-box span {
  color: #b9ccc8;
  font-size: 13px;
}

.session-box label {
  display: grid;
  gap: 5px;
  color: #b9ccc8;
  font-size: 12px;
}

.session-box select {
  width: 100%;
  min-height: 34px;
}

.session-box button {
  color: #d9e6e2;
  background: transparent;
  border-color: rgba(255, 255, 255, 0.16);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  color: #fff;
  background: #10231f;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 6px 10px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  background: #f0c66c;
  color: #10231f;
  font-weight: 800;
  overflow: hidden;
  flex: 0 0 auto;
}

.brand-mark.logo-uploaded {
  background: transparent;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: #b9ccc8;
}

nav {
  display: grid;
  gap: 6px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: var(--line-strong);
}

.nav {
  min-height: 42px;
  border: 0;
  color: #d9e6e2;
  background: transparent;
  text-align: left;
}

.nav.active {
  color: #fff;
  background: #1d4038;
}

main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow,
.panel p {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(112px, 1fr));
  gap: 10px;
}

.metric-strip span {
  min-height: 72px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric-strip small {
  display: block;
  color: var(--muted);
}

.metric-strip b {
  display: block;
  margin-top: 6px;
  font-size: 21px;
}

.notice {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid #f0d9a8;
  border-radius: 8px;
  color: #714500;
  background: #fff8e6;
}

.view { display: none; }
.view.active { display: block; }

.workbench {
  display: grid;
  gap: 16px;
}

.bot-layout,
.two-col {
  grid-template-columns: minmax(340px, 0.82fr) minmax(460px, 1.18fr);
}

.panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-title p {
  margin-top: 5px;
  font-size: 13px;
}

.badge,
.pill,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.badge,
.pill {
  color: var(--accent);
  background: var(--accent-soft);
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
}

textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.form-grid label { font-size: 12px; gap: 3px; }
.form-grid input { min-height: 30px; font-size: 12px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check input {
  width: 18px;
}

.primary {
  width: 100%;
  min-height: 42px;
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 14px;
}

.quick-actions button {
  padding: 0 8px;
  font-size: 13px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.inline-actions button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.chat-log,
.stack,
.timeline,
.log-list {
  display: grid;
  gap: 10px;
}

.chat-log {
  min-height: 360px;
  align-content: start;
}

.empty {
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
}

.bubble,
.row-card,
.role-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.bubble {
  padding: 13px;
}

.bubble strong {
  display: block;
  margin-bottom: 5px;
}

.bubble hr {
  margin: 12px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.role-card {
  padding: 15px;
}

.role-card h3 {
  margin-bottom: 12px;
}

.role-metrics {
  display: grid;
  gap: 9px;
}

.role-metrics p {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
}

.role-metrics strong {
  font-size: 18px;
}

.row-card {
  display: grid;
  gap: 7px;
  padding: 13px;
}

.row-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row-card p {
  font-size: 13px;
}

.link-button {
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  font: inherit;
  font-weight: 800;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.36);
}

.detail-panel {
  width: min(720px, 100%);
  max-height: 86vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
}

.detail-panel header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-panel h2 {
  margin: 4px 0 0;
  font-size: 22px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  padding: 18px;
  background: var(--line);
}

.detail-grid p {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 12px;
  background: var(--surface);
}

.detail-grid span,
.detail-note {
  color: var(--muted);
  font-size: 13px;
}

.detail-note {
  padding: 0 18px 18px;
}

.detail-subsection {
  display: grid;
  gap: 10px;
  padding: 0 18px 18px;
}

.detail-subsection h3 {
  margin: 0;
  font-size: 15px;
}

.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 18px 18px;
}

.save-status {
  min-height: 20px;
  color: var(--accent);
  font-weight: 700;
}

.logo-uploader {
  display: grid;
  gap: 12px;
}

.logo-preview-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-preview {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f0c66c;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.logo-placeholder {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 8px;
  background: #f0c66c;
  color: #10231f;
  font-weight: 800;
 font-size: 14px;
}

.section-label {
  margin: 4px 0 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.admin-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(135deg, #f7fbff, #f7faf8);
  margin-bottom: 6px;
}

.admin-hero h2 {
  font-size: 17px;
}

.admin-hero p {
  margin: 0;
  color: var(--muted);
}

.admin-health {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
}

.ok-dot,
.warn-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.ok-dot {
  background: var(--ok);
}

.warn-dot {
  background: var(--warning);
}

.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}

.admin-stat-grid .mini-card {
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-stat-grid .mini-card.clickable {
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
}
.admin-stat-grid .mini-card.clickable:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transform: translateY(-1px);
  border-color: var(--accent);
}
.admin-stat-grid .mini-card.clickable:active {
  transform: translateY(0);
}

.admin-stat-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.admin-stat-grid b {
  display: block;
  margin-top: 4px;
  color: var(--ink);
  font-size: 18px;
}

.admin-section {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.admin-console {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
}

.admin-menu {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.admin-menu button {
  justify-content: flex-start;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-weight: 700;
}

.admin-menu button.active,
.admin-menu button:hover {
  background: #eef4ff;
  color: #2454a6;
}

.admin-content {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.admin-section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.admin-section-title h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.admin-section-title p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.admin-table th,
.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.admin-table th {
  color: var(--muted);
  background: #f6f8fb;
  font-size: 13px;
}

.admin-row {
  display: grid;
  grid-template-columns: 1.3fr 0.8fr 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.admin-row:last-child {
  border-bottom: 0;
}

.admin-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.role-bind-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.model-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.role-bind-card,
.model-card {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.role-bind-card header,
.model-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.role-bind-card label { font-size: 12px; gap: 3px; }
.role-bind-card input, .role-bind-card textarea { min-height: 28px; font-size: 12px; }
.role-bind-card textarea { min-height: 40px; }
.role-bind-card .role-chip { font-size: 11px; padding: 2px 6px; }

.button-row,
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.filter-row input {
  min-width: 180px;
  flex: 1;
}

.role-chip {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: #2454a6;
  font-size: 12px;
  font-weight: 700;
}

.callback-box {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px dashed #b7c5d8;
  border-radius: 10px;
  background: #f8fbff;
}

.callback-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.callback-box code {
  overflow-wrap: anywhere;
  color: #16427b;
}

.compact-stack {
  gap: 8px;
}

@media (max-width: 900px) {
  .admin-hero,
  .admin-section-title {
    display: grid;
  }

  .admin-stat-grid,
  .module-grid,
  .role-bind-grid,
  .model-grid,
  .admin-console,
  .admin-row {
    grid-template-columns: 1fr;
  }
}

.status-draft,
.status-pending {
  color: var(--warning);
  background: #fff3df;
}

.status-confirmed,
.status-completed,
.status-qualified {
  color: var(--ok);
  background: #e8f6ef;
}

.status-defective {
  color: var(--danger);
  background: #fff0ee;
}

.log-list {
  max-height: 520px;
  overflow: auto;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .topbar,
  .bot-layout,
  .two-col {
    display: grid;
    grid-template-columns: 1fr;
  }

  .metric-strip,
  .quick-actions,
  .detail-grid,
  .detail-actions,
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Rule Engine Panel ===== */
.rule-engine-layout {
  display: grid;
  gap: 16px;
}

.rules-ai-chat {
  max-height: 320px;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.rules-ai-placeholder {
  color: var(--muted);
  font-size: 13px;
}

.rules-ai-placeholder ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.rules-ai-placeholder li {
  margin-bottom: 4px;
}

.rules-ai-msg {
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.rules-ai-msg.user {
  background: #e7f3f0;
  border-color: #cde3de;
}

.rules-ai-msg.ai {
  background: #f0f4ff;
  border-color: #d8e2f5;
}

.rules-ai-msg.error {
  background: #fff0ee;
  border-color: #fcd5d0;
}

.rules-ai-msg b {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
}

.rules-ai-msg p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
}

.rules-ai-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.rules-ai-input-row textarea {
  flex: 1;
  min-height: 44px;
}

.rules-ai-input-row button {
  width: auto;
  min-width: 80px;
  min-height: 44px;
}

/* ===== Log Items ===== */
.log-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}
.log-item .role-chip {
  flex: 0 0 auto;
  margin-top: 1px;
  min-width: 44px;
  text-align: center;
}
.log-item p {
  flex: 1;
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
}
.log-item .log-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

/* ===== Section Labels ===== */
.section-label {
  margin: 16px 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

/* ===== Inline Actions ===== */
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.inline-actions button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

/* ===== Master Data Table ===== */
.master-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.master-tab {
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 6px 6px 0 0;
  background: var(--surface-soft);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.master-tab.active {
  background: var(--surface);
  border-bottom-color: var(--surface);
  font-weight: 700;
  color: var(--accent);
}
.master-tab .badge {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
}
.master-tab:hover { background: var(--surface); }
.master-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.master-toolbar input { flex: 1; min-width: 180px; }
.master-table-wrap {
  max-height: 480px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.master-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.master-table th {
  background: var(--surface-soft);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.master-table th.th-actions { width: 80px; text-align: center; }
.master-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.master-table tr:hover td { background: var(--accent-soft); }
.master-table td.empty { text-align: center; color: var(--muted); padding: 40px 16px; font-style: italic; }
.td-actions { text-align: center; white-space: nowrap; }
.master-add-form, .master-import-area {
  margin-top: 12px;
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
}
.master-add-form h4, .master-import-area h4 { margin: 0 0 10px; }
.master-add-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 10px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border-radius: 10px;
  padding: 24px;
  max-width: 640px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
}
.modal-box h4 { margin: 0 0 14px; }
.modal-box .master-add-grid { max-height: 50vh; overflow-y: auto; }

/* ===== System Admin ===== */
.sysadmin-grid { display: grid; gap: 16px; }
.form-narrow { max-width: 400px; }

/* ===== List Row (Sales / Purchase view) ===== */
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row-main {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}
.list-row-main b { font-size: 13px; }
.list-row-meta {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.list-row .badge {
  flex: 0 0 auto;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.warn { background: #fff3e0; color: #b76a00; }
.badge.error { background: #fee8e6; color: var(--danger); }
.badge-orange { background: #fff3e0; color: #b76a00; }
.badge-blue { background: #e3f0ff; color: #1a6bb0; }
.badge-green { background: #e3f5ec; color: #087443; }
.badge-red { background: #fee8e6; color: var(--danger); }

/* ===== Backup / Restore ===== */
.backup-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.backup-buttons button {
  font-size: 13px;
  min-height: 34px;
  min-width: 120px;
}
.compare-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.compare-col {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}
.compare-col b { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.compare-val { display: block; font-size: 13px; font-weight: 700; }
.compare-diff { display: block; font-size: 11px; margin-top: 2px; }
.compare-diff.up { color: var(--ok); }
.compare-diff.down { color: var(--danger); }

.dash-scroll { overflow: hidden; }
.dash-scroll-inner {
  max-height: 280px;
  overflow-y: auto;
  margin: 0 -14px;
  padding: 0 14px;
}

/* ===== Accordion (采购看板) ===== */
.purchase-accordion {
  display: grid;
  gap: 4px;
}
.accordion-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.accordion-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  font-weight: 700;
  background: var(--surface-soft);
  transition: background 0.1s;
}
.accordion-header:hover { background: #eef2f5; }
.accordion-header.open { background: var(--accent-soft); color: var(--accent); }
.accordion-arrow {
  margin-left: auto;
  font-size: 10px;
  color: var(--muted);
}
.accordion-body { display: none; }
.accordion-inner {
  max-height: 300px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}
.accordion-inner .list-row:last-child { border-bottom: 0; }

.toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.toolbar input { flex: 1; min-width: 200px; font-size: 14px; padding: 6px 10px; }
.toolbar select.order-sort { width: auto; min-width: 90px; min-height: 30px; font-size: 12px; }
.toolbar button { min-width: 90px; min-height: 32px; font-size: 12px; }
.search-go-btn { min-width: 50px !important; min-height: 30px !important; font-size: 13px; font-weight: 700; }

/* ===== Item Table (in order detail) ===== */
.item-table {
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
}
.item-table-header {
  display: grid;
  grid-template-columns: 1fr 50px 50px 70px 70px;
  gap: 4px;
  padding: 4px 8px;
  background: var(--surface-soft);
  font-weight: 700;
  color: var(--muted);
  font-size: 11px;
  border-bottom: 1px solid var(--line-strong);
}
.item-table-header span:not(:first-child) { text-align: right; }
.item-row {
  display: grid;
  grid-template-columns: 1fr 50px 50px 70px 70px;
  gap: 4px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
}
.item-row:last-child { border-bottom: 0; }
.item-model { font-weight: 600; font-size: 12px; }
.item-qty, .item-shipped, .item-price, .item-total { text-align: right; color: var(--muted); font-size: 12px; }
.item-shipped.done { color: var(--ok); font-weight: 700; }
.item-total { font-weight: 700; color: var(--ink); }

.results-scroll { overflow: hidden; }
.results-inner {
  max-height: 400px;
  overflow-y: auto;
  margin: 0 -14px;
  padding: 0 14px;
}
.clickable-row { cursor: pointer; transition: background 0.1s; }
.clickable-row:hover { background: var(--accent-soft); }

.order-detail { max-width: 520px; }
.order-detail h4 { font-size: 15px; }
.order-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px 12px;
  font-size: 13px;
}
.detail-field { padding: 3px 0; }
.detail-field b { color: var(--muted); font-weight: 600; display: inline-block; min-width: 50px; margin-right: 6px; }
.stage-track {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 12px;
  padding: 10px;
  background: var(--surface-soft);
  border-radius: 8px;
  font-size: 12px;
  flex-wrap: wrap;
}
.stage-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--line);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}
.stage-dot.done { background: var(--ok); }
.stage-line {
  width: 16px;
  height: 2px;
  background: var(--line);
}

.form-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.form-card textarea { resize: vertical; min-height: 40px; }

.form-prod-info {
  display: flex;
  gap: 16px;
  padding: 8px 12px;
  background: var(--accent-soft);
  border-radius: 6px;
  font-size: 13px;
  flex-wrap: wrap;
}
.form-prod-info span { color: var(--muted); }
.form-prod-info b { color: var(--ink); font-weight: 700; }
.form-total { font-size: 18px; font-weight: 700; color: var(--accent); display: block; padding-top: 4px; }

/* ===== Reconcile ===== */
.reconcile-items {
  display: grid;
  gap: 2px;
  margin-top: 6px;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px;
}
.reconcile-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.reconcile-row:hover { background: var(--accent-soft); }
.reconcile-row input[type=checkbox] { width: 16px; height: 16px; }
.reconcile-row .list-row-main { flex: 1; }
.reconcile-row .list-row-meta { font-weight: 700; }
.reconcile-row .list-row-meta.negative { color: var(--danger); }
.reconcile-row .list-row-meta.positive { color: var(--ok); }

.back-btn {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
}
.back-btn:hover { background: var(--accent-soft); }

.backup-list {
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 12px;
  max-height: 150px;
  overflow-y: auto;
}
.backup-list b { display: block; margin-bottom: 4px; }
.backup-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 0;
}
.restore-btn {
  font-size: 11px;
  min-height: 24px;
  padding: 0 8px;
}

/* ===== WeChat Config Tabs ===== */
.wecom-tabs { display: grid; gap: 0; }
.wecom-tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.wecom-tab {
  padding: 8px 16px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: -1px;
}
.wecom-tab.active {
  border-color: var(--line);
  background: #fff;
  color: var(--accent);
}
.wecom-tab:hover { color: var(--ink); }
.wecom-tab-content { min-height: 0; }

/* ===== Master Detail Grid ===== */
.master-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 4px 12px;
  font-size: 12px;
}
.master-detail-grid span { display: flex; gap: 4px; }
.master-detail-grid b { color: var(--muted); font-weight: 600; min-width: 60px; }
.master-expand-btn { font-size: 12px; padding: 2px 6px; min-height: 0; }

/* ===== Log list compact ===== */
.log-list { display: grid; gap: 4px; width: 100%; }
.log-list .log-item {
  padding: 5px 8px;
}
.log-list .log-item .log-time { font-size: 10px; }

/* ===== Compact view tweaks ===== */
main { padding: 14px; }
.admin-section-title { margin-bottom: 0; }
.admin-section-title h3 { font-size: 14px; }
.admin-section-title p { font-size: 12px; }

/* Missing CSS classes from app.js modules */
.order-search { width:100%; padding:8px 12px; border:1px solid var(--line); border-radius:6px; font-size:14px; }
.order-create-btn { padding:6px 16px; background:var(--accent); color:#fff; border:none; border-radius:6px; cursor:pointer; font-size:13px; }
.btn-sm { padding:4px 12px; font-size:12px; border:1px solid var(--line); border-radius:4px; cursor:pointer; background:#fff; }
.btn-cancel { padding:6px 16px; background:var(--surface); color:var(--ink); border:1px solid var(--line); border-radius:6px; cursor:pointer; font-size:13px; }
.btn-inbound-confirm, .btn-confirm-outbound { padding:4px 10px; font-size:12px; background:var(--ok); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.btn-inbound-defective { padding:4px 10px; font-size:12px; background:var(--danger); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.toolbar { display:flex; gap:8px; align-items:center; margin-bottom:12px; }
.dash-scroll { margin-bottom:12px; }
.dash-scroll-inner { max-height:300px; overflow-y:auto; }
.timeline-item { padding:8px 0; border-bottom:1px solid var(--line); }
.reconcile-check { width:18px; height:18px; }
.reconcile-confirm-btn, .reconcile-open-btn { padding:3px 8px; font-size:11px; background:var(--accent); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.reconcile-del-btn { padding:3px 8px; font-size:11px; background:var(--danger); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.master-add-btn, .master-edit-btn { padding:4px 10px; font-size:12px; background:var(--accent); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.master-del-btn { padding:4px 10px; font-size:12px; background:var(--danger); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.master-import-btn { padding:6px 14px; background:var(--surface); border:1px solid var(--line); border-radius:6px; cursor:pointer; }
.master-export-btn { padding:6px 14px; background:var(--surface); border:1px solid var(--line); border-radius:6px; cursor:pointer; }
.bind-ids { width:100%; padding:6px; border:1px solid var(--line); border-radius:4px; font-size:13px; min-height:60px; }
.bind-name { width:100%; padding:6px; border:1px solid var(--line); border-radius:4px; font-size:13px; }
.model-provider, .model-name, .model-key, .model-url { width:100%; padding:6px; border:1px solid var(--line); border-radius:4px; font-size:13px; box-sizing:border-box; }
.model-enabled { width:18px; height:18px; }
.edit-field { width:100%; padding:6px; border:1px solid var(--line); border-radius:4px; font-size:13px; box-sizing:border-box; }
.close-order-btn { padding:4px 10px; font-size:12px; background:var(--warning); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.master-search { width:100%; padding:6px 10px; border:1px solid var(--line); border-radius:4px; font-size:13px; }
.form-prod-select, .form-qty-input { padding:6px; border:1px solid var(--line); border-radius:4px; font-size:13px; }
.inbound-qty, .outbound-qty { width:60px; padding:4px; border:1px solid var(--line); border-radius:4px; text-align:center; }
.rule-value-input { width:100%; padding:6px; border:1px solid var(--line); border-radius:4px; }
.rule-value-text { font-size:13px; color:var(--muted); }
.rule-save-btn { padding:3px 8px; background:var(--ok); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.rule-cancel-btn { padding:3px 8px; background:var(--surface); border:1px solid var(--line); border-radius:4px; cursor:pointer; }
.rule-edit-btn { padding:2px 6px; font-size:11px; background:transparent; border:1px solid var(--line); border-radius:3px; cursor:pointer; }
.ret-complete-btn { padding:3px 8px; background:var(--ok); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.ret-del-btn { padding:3px 8px; background:var(--danger); color:#fff; border:none; border-radius:4px; cursor:pointer; }
.reconcile-contact { font-size:12px; color:var(--muted); }
.reconcile-date { font-size:11px; color:var(--muted); }
.master-detail-row { display:flex; gap:6px; align-items:center; margin:4px 0; }
.master-add-input { flex:1; padding:6px; border:1px solid var(--line); border-radius:4px; }

/* Master data table - hidden rows */
[hidden] { display: none !important; }
.master-expand-btn { cursor: pointer; padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px; background: #fff; font-size: 11px; }

.wecom-login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0;
  color: var(--muted);
  font-size: 12px;
}
.wecom-login-divider::before,
.wecom-login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.wecom-login-btn {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 13px;
  color: #333;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
}
.wecom-login-btn:hover {
  border-color: #07c160;
  color: #07c160;
  background: #f0faf4;
}

/* ===== 移动端优化（企微内置浏览器）===== */
@media (max-width: 768px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 8px; }
  .sidebar .brand { font-size: 14px; padding: 6px; }
  nav { grid-template-columns: repeat(2, 1fr); gap: 3px; }
  nav button { font-size: 11px; padding: 6px 4px; min-height: 36px; }
  .topbar { padding: 6px 10px; }
  main { padding: 8px; }
  
  .admin-hero { padding: 8px 10px; }
  .admin-hero h2 { font-size: 15px; }
  .admin-section { padding: 8px; gap: 6px; }
  .admin-section-title h3 { font-size: 13px; }
  
  .admin-stat-grid { grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .mini-card { padding: 6px; font-size: 11px; }
  .mini-card b { font-size: 16px; }
  
  /* 表单优化 */
  .form-card { padding: 10px; }
  .form-grid { grid-template-columns: 1fr; gap: 6px; }
  .form-grid label { font-size: 12px; }
  .form-grid input, .form-grid select, .form-grid textarea { font-size: 14px; padding: 8px; }
  .form-prod-info { font-size: 11px; gap: 4px; flex-wrap: wrap; }
  .form-prod-info span { padding: 2px 6px; }
  
  .button-row { flex-direction: column; gap: 4px; }
  .button-row button { width: 100%; min-height: 40px; font-size: 14px; }
  
  /* 表格 */
  .admin-row { grid-template-columns: 1fr; gap: 2px; padding: 6px; }
  .admin-row b { font-size: 13px; }
  .admin-row span { font-size: 11px; }
  .admin-row button { min-height: 34px; }
  
  /* 日志 */
  .log-list { max-height: 240px; }
  .log-item { font-size: 11px; padding: 4px 6px; }
  
  /* 企业微信配置 */
  .wecom-tab-bar { overflow-x: auto; white-space: nowrap; }
  .wecom-tab { font-size: 11px; padding: 6px 10px; }
  .role-bind-grid { grid-template-columns: 1fr; }
  
  /* 邮件 */
  #adminContent > div[style*="height:calc(100vh - 140px)"] { flex-direction: column; height: auto !important; }
  #adminContent > div[style*="height:calc(100vh - 140px)"] > div:first-child { width: 100% !important; min-width: unset !important; max-height: 50vh; }
  #emailFolderTree { max-height: 20vh !important; }
  .email-actions { flex-wrap: wrap; }
  #emailActions button { font-size: 10px; padding: 3px 8px; }
  
  /* 销售订单详情 */
  .order-detail { max-width: 100%; }
  .order-detail .order-summary { flex-direction: column; gap: 4px; }
  .order-detail .order-summary span { font-size: 12px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { min-width: 120px; font-size: 13px; }
  .toolbar button { min-width: 60px; min-height: 30px; font-size: 11px; }
  .search-go-btn { min-width: 40px !important; }
  
  /* 新建订单页面 */
  [data-view="sales-new"] .form-prod-info { display: grid; grid-template-columns: repeat(2, 1fr); }
  
  /* 规则引擎 */
  .rules-grid { grid-template-columns: 1fr; }
  .rules-ai-chat { max-height: 200px; }
  
  /* 系统设置 */
  .sysadmin-grid { grid-template-columns: 1fr; }
  .master-tabs { overflow-x: auto; }
  .master-tab { font-size: 11px; padding: 6px 10px; }
  .master-toolbar { flex-direction: column; }
  position: sticky;
  top: 0;
  z-index: 10;
  .master-table { font-size: 11px; }
  .master-table th, .master-table td { padding: 4px 6px; }
  
  /* 看板数字 */
  .ceo-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .ceo-card { padding: 8px; }
  .ceo-card .num { font-size: 18px; }
  
  /* AI对话窗口 */
  .brain-chat { max-height: 200px; }
  .brain-msg { font-size: 12px; padding: 6px 8px; }
  
  /* 模态框 */
  div[style*="position:fixed"][style*="z-index:9999"] > div { width: 92% !important; max-width: 92% !important; padding: 16px !important; }
  
  /* 底部用户区域 */
  .bot-layout { grid-template-columns: 1fr; }
  #sessionRole { font-size: 11px; }
}
