:root {
  --blue-900: #0a2540;
  --blue-800: #10345c;
  --blue-700: #1657a0;
  --blue-600: #1e6fd8;
  --blue-500: #2b82f6;
  --blue-400: #60a5fa;
  --blue-100: #e8f1fe;
  --blue-50: #f4f8ff;
  --ink: #0f1b2d;
  --gray-600: #556074;
  --gray-400: #8a94a6;
  --gray-200: #e2e8f0;
  --gray-100: #f1f5fa;
  --white: #fff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --shadow: 0 4px 20px rgba(16, 52, 92, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--blue-50);
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.login-body {
  min-height: 100vh;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--blue-900), var(--blue-700));
}
.login-card {
  background: #fff; padding: 40px; border-radius: 14px;
  width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-card .logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 22px; font-weight: 700; color: var(--blue-700); margin-bottom: 6px;
}
.login-card .logo-mark {
  width: 36px; height: 36px; border-radius: 8px; color: #fff; font-weight: 800;
  background: linear-gradient(135deg, var(--blue-600), var(--blue-500));
  display: grid; place-items: center;
}
.login-card .sub { color: var(--gray-400); font-size: 13px; margin-bottom: 24px; }
.login-card label { display: block; font-size: 13px; color: var(--gray-600); margin: 12px 0 6px; font-weight: 600; }
.login-card input {
  width: 100%; padding: 11px 12px; border: 1px solid var(--gray-200); border-radius: 8px;
  font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px var(--blue-100); }
.login-card .err {
  background: #fee2e2; color: var(--err); padding: 8px 12px;
  border-radius: 6px; font-size: 13px; margin-bottom: 12px;
}
.btn {
  padding: 11px 18px; border: none; border-radius: 8px; font-weight: 600; font-size: 14px;
  transition: .2s; display: inline-block;
}
.btn-primary { background: var(--blue-600); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--blue-700); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-ghost { background: #fff; color: var(--blue-700); border: 1px solid var(--gray-200); }
.btn-ghost:hover { border-color: var(--blue-500); }
.btn-danger { background: var(--err); color: #fff; }

/* ---------- Admin layout ---------- */
.admin-layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: var(--blue-900); color: #cbd8ee; padding: 22px 0;
  flex-shrink: 0; position: relative;
}
.sidebar .brand {
  padding: 0 22px 22px; border-bottom: 1px solid rgba(255,255,255,.1);
  color: #fff; font-weight: 700; font-size: 17px;
  display: flex; align-items: center; gap: 10px;
}
.sidebar .brand .m {
  width: 32px; height: 32px; border-radius: 7px;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-400));
  display: grid; place-items: center; color: #fff; font-weight: 800;
}
.sidebar nav { padding-top: 12px; }
.sidebar nav a {
  display: block; padding: 11px 22px; font-size: 14px; color: #b7c8e0;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar nav a.active { background: rgba(46,130,246,.15); color: #fff; border-left-color: var(--blue-500); }
.sidebar .foot {
  position: absolute; bottom: 20px; font-size: 12px; padding: 0 22px; color: #7c8ca6;
}

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  background: #fff; height: 60px; border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; padding: 0 28px; gap: 16px;
}
.topbar h1 { font-size: 18px; font-weight: 700; color: var(--blue-900); }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topbar .user {
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; color: var(--gray-600);
}
.topbar .logout { color: var(--blue-600); font-size: 13px; }
.topbar .logout:hover { text-decoration: underline; }
.logout-btn { border: 0; background: none; padding: 0; font-family: inherit; }
.logout-form { margin: 0; }

.content { padding: 28px; }

.audit-filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }
.audit-filters .form-field { margin: 0; min-width: 180px; }
.audit-filters .btn-primary { width: auto; }
.audit-time { white-space: nowrap; }
.audit-table { min-width: 1100px; }
.audit-details { display: block; max-width: 360px; overflow-wrap: anywhere; white-space: normal; }
.audit-pagination { display: flex; gap: 12px; align-items: center; justify-content: flex-end; margin-top: 14px; }
.empty-cell { color: var(--gray-400); text-align: center; padding: 28px; }

/* ---------- Cards / stats ---------- */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px;
}
.stat {
  background: #fff; border-radius: 12px; padding: 20px; box-shadow: var(--shadow);
}
.stat .label { font-size: 13px; color: var(--gray-400); }
.stat .value { font-size: 28px; font-weight: 700; color: var(--blue-900); margin-top: 4px; }
.stat .sub { color: var(--gray-400); font-size: 12px; margin-top: 4px; }
.stat.accent .value { color: var(--blue-600); }

.panel {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow);
  padding: 22px; margin-bottom: 20px;
}
.panel h2 {
  font-size: 16px; color: var(--blue-900); margin-bottom: 14px;
  padding-bottom: 12px; border-bottom: 1px solid var(--gray-100);
}

/* ---------- Table ---------- */
.tbl {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.tbl th, .tbl td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--gray-100); }
.tbl th { font-weight: 600; color: var(--gray-600); background: var(--gray-100); font-size: 13px; }
.tbl tbody tr:hover { background: var(--blue-50); }
.tbl a { color: var(--blue-600); font-weight: 500; }
.tbl a:hover { text-decoration: underline; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.badge.new { background: #dbeafe; color: #1e40af; }
.badge.quoted { background: #fef3c7; color: #92400e; }
.badge.paid { background: #dcfce7; color: #166534; }
.badge.producing { background: #e0e7ff; color: #3730a3; }
.badge.shipped { background: #cffafe; color: #155e75; }
.badge.done { background: #d1fae5; color: #065f46; }
.badge.cancelled { background: #fee2e2; color: var(--err); }
.badge.contacted { background: #fef3c7; color: #92400e; }
.badge.closed { background: #e2e8f0; color: #475569; }

/* ---------- Filters ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters a {
  padding: 6px 14px; border-radius: 20px; font-size: 13px;
  background: #fff; border: 1px solid var(--gray-200); color: var(--gray-600);
}
.filters a.active { background: var(--blue-600); color: #fff; border-color: var(--blue-600); }

/* ---------- Order detail ---------- */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 14px; }
.kv .k { color: var(--gray-400); }
.kv .v { color: var(--ink); }

.item-card {
  border: 1px solid var(--gray-200); border-radius: 10px; padding: 16px;
  margin-bottom: 12px; background: #fff;
}
.item-card .head { display: flex; justify-content: space-between; align-items: baseline; }
.item-card .name { font-weight: 700; color: var(--blue-900); }
.item-card .cno { color: var(--gray-400); font-size: 13px; }
.item-card .price { font-size: 18px; font-weight: 700; color: var(--blue-600); }
.item-meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; font-size: 13px; }
.item-meta .k { color: var(--gray-400); font-size: 12px; }

.status-form { display: flex; gap: 8px; align-items: center; }
.status-form select {
  padding: 8px 12px; border: 1px solid var(--gray-200); border-radius: 6px; font-size: 13px;
}

/* ---------- Materials ---------- */
.mat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.mat-card {
  background: #fff; border-radius: 10px; padding: 16px; box-shadow: var(--shadow);
  border-left: 4px solid var(--blue-500);
}
.mat-card h4 { color: var(--blue-900); font-size: 15px; margin-bottom: 8px; }
.mat-card .proc { color: var(--blue-600); font-size: 12px; font-weight: 600; }
.mat-card .rows { margin-top: 10px; font-size: 13px; color: var(--gray-600); }
.mat-card .rows div { display: flex; justify-content: space-between; padding: 3px 0; }

/* ---------- Forms (notice edit) ---------- */
.form-row { display: flex; gap: 16px; }
.form-row .form-field { flex: 1; }
.form-field { margin-bottom: 16px; }
.form-field label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; }
.form-field input,
.form-field textarea,
.form-field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gray-200);
  border-radius: 8px; font-size: 14px; font-family: inherit; color: var(--ink);
}
.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none; border-color: var(--blue-500); box-shadow: 0 0 0 3px var(--blue-100);
}
.form-field textarea { resize: vertical; line-height: 1.6; }

.switch-line { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--gray-600); }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: var(--gray-200);
  border-radius: 24px; transition: .2s;
}
.slider:before {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .2s;
}
.switch input:checked + .slider { background: var(--blue-500); }
.switch input:checked + .slider:before { transform: translateX(18px); }

code {
  background: var(--gray-100); padding: 2px 7px; border-radius: 4px;
  font-family: "Consolas", "Menlo", monospace; font-size: 13px; color: var(--blue-700);
}

/* ---------- Dashboard category bars ---------- */
.cat-bars { display: flex; flex-direction: column; gap: 12px; }
.cat-bar-row { display: grid; grid-template-columns: 140px 1fr 120px; align-items: center; gap: 12px; }
.cat-bar-label { font-size: 14px; color: var(--ink); font-weight: 600; }
.cat-bar-label .cat-bar-count { color: var(--gray-400); font-weight: 400; font-size: 12px; margin-left: 6px; }
.cat-bar-track { background: var(--gray-100); border-radius: 20px; height: 18px; overflow: hidden; }
.cat-bar-fill { width: 0; height: 100%; background: linear-gradient(90deg, var(--blue-500), var(--blue-400)); border-radius: 20px; min-width: 2px; transition: width .4s; }
.cat-bar-val { text-align: right; font-weight: 700; color: var(--blue-700); font-size: 14px; }

.filter-form { display:flex; gap:10px; flex-wrap:wrap; align-items:end; margin-bottom:16px; }
.filter-search { margin:0; flex:1; min-width:220px; }
.table-scroll { overflow-x:auto; }
.muted { color:var(--gray-400); font-size:12px; }
.empty-state { color:var(--gray-400); text-align:center; padding:30px 0; }
.back-link { margin-bottom:14px; }
.pre-wrap { white-space:pre-wrap; }
.btn-inline { width:auto; margin-top:16px; }
.inline-form { display: inline; }
.nowrap { white-space: nowrap; }
.text-muted { color: var(--gray-400); }
.text-small-muted { color: var(--gray-400); font-size: 12px; }
.intro-text { color: var(--gray-600); font-size: 14px; margin-bottom: 16px; }
.flash {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 16px;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-error { background: #fee2e2; color: var(--err); }
.login-card .login-success { background: #dcfce7; color: #166534; }
.login-submit { margin-top: 20px; }
.section-toolbar { display: flex; align-items: center; margin-bottom: 14px; gap: 12px; }
.section-toolbar-spacious { margin-bottom: 16px; }
.section-toolbar .intro-text { margin-bottom: 0; }
.section-toolbar .section-title { margin: 0; border: 0; padding: 0; }
.section-toolbar .toolbar-action { width: auto; margin-left: auto; flex: 0 0 auto; }
.admin-grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.catalog-action-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.panel-width-640 { max-width: 640px; }
.panel-width-720 { max-width: 720px; }
.panel-width-760 { max-width: 760px; }
.panel-width-820 { max-width: 820px; }
.form-row-wrap { flex-wrap: wrap; }
.form-row .form-field-flex { flex: 1 1 220px; }
.form-row .form-field-sort { flex: 0 0 120px; max-width: 120px; }
.form-row .form-field-sort-wide { flex: 0 0 140px; max-width: 140px; }
.label-note { color: var(--gray-400); }
.readonly-field { background: var(--gray-100); }
.form-actions { margin-top: 20px; }
.form-action-cancel { margin-left: 8px; }
.settings-actions { margin-top: 16px; }
.help-text { color: var(--gray-400); font-size: 12px; margin-top: 12px; max-width: 720px; }
.switch-spaced { margin-bottom: 10px; }
.filter-field { margin: 0; }
.item-price-group { text-align: right; }
.item-unit-price { color: var(--gray-400); font-size: 12px; }
.item-detail {
  margin-top: 10px; padding: 8px 12px; border-radius: 6px; color: var(--gray-600);
}
.item-spec { background: #eef4ff; font-size: 12px; }
.item-note { background: var(--blue-50); font-size: 13px; }
.order-total { color: var(--blue-600); font-weight: 700; font-size: 18px; }

.account-grid {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
  gap: 20px; align-items: start;
}
.account-grid > .panel { overflow-x: auto; }
.account-access-form { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.account-access-form select { width: auto; min-width: 104px; padding: 7px 9px; }
.account-active { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.account-actions { min-width: 0; }

/* manufacturing execution: work orders, tasks, status history */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  background: var(--gray-100); color: var(--gray-600);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.tbl-kv th {
  width: 160px; text-align: left; color: var(--gray-600);
  font-weight: 600; vertical-align: top;
}
.inline-form {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.inline-form select { width: auto; min-width: 104px; padding: 6px 8px; }
.input-narrow { width: 88px; }
.pager { display: flex; gap: 8px; margin-top: 12px; }
.notice { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.notice-ok { background: #dcfce7; color: #166534; }
.notice-err { background: #fee2e2; color: var(--err); }

@media (max-width: 900px) {
  .sidebar { width: 190px; }
  .detail-grid { grid-template-columns: 1fr; }
  .item-meta { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 18px; }
  .account-grid { grid-template-columns: 1fr; }
  .admin-grid-two { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .admin-layout { display: block; }
  .sidebar { width: 100%; padding: 12px 0 0; }
  .sidebar .brand { padding: 0 14px 10px; }
  .sidebar nav {
    display: flex; gap: 4px; padding: 8px 10px 0; overflow-x: auto;
    scrollbar-width: thin;
  }
  .sidebar nav a {
    flex: 0 0 auto; padding: 8px 10px; border-left: 0;
    border-bottom: 3px solid transparent;
  }
  .sidebar nav a.active { border-left-color: transparent; border-bottom-color: var(--blue-500); }
  .sidebar .foot { display: none; }
  .topbar { min-height: 54px; height: auto; padding: 8px 14px; }
  .topbar h1 { flex: 1; }
  .topbar .right { gap: 8px; }
  .topbar .user { display: none; }
  .content { padding: 14px; }
  .panel { padding: 14px; }
  .audit-filters .form-field { flex: 1 1 140px; min-width: 0; }
  .section-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .section-toolbar .toolbar-action { margin-left: 0; }
  .form-row { flex-wrap: wrap; }
  .form-row .form-field { flex: 1 1 180px; }

  .catalog-table,
  .catalog-table tbody {
    display: block;
    width: 100%;
  }
  .catalog-table thead { display: none; }
  .catalog-table tbody {
    display: grid;
    gap: 12px;
  }
  .catalog-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    overflow: hidden;
  }
  .catalog-table tbody tr:hover { background: #fff; }
  .catalog-table td {
    display: grid;
    grid-template-columns: minmax(68px, 0.8fr) minmax(0, 1.2fr);
    gap: 8px;
    align-items: start;
    min-width: 0;
    padding: 9px 10px;
    overflow-wrap: anywhere;
  }
  .catalog-table td::before {
    content: attr(data-label);
    color: var(--gray-400);
    font-size: 12px;
    font-weight: 600;
  }
  .catalog-table td:nth-child(odd) { border-right: 1px solid var(--gray-100); }
  .catalog-table td.catalog-actions {
    grid-column: 1 / -1;
    grid-template-columns: minmax(68px, 0.4fr) minmax(0, 1.6fr);
    border-right: 0;
  }
  .catalog-table .catalog-action-group { min-width: 0; }
  .catalog-table .btn { white-space: nowrap; }
  .catalog-table-materials td:nth-child(6) { color: var(--gray-600); }
}

/* ---------- 在线报价格式白名单选择 ---------- */
.format-groups { display: grid; gap: 12px; }
.format-group {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 12px 14px;
  background: #fafbfc;
}
.format-group-title {
  font-size: 13px; font-weight: 700; color: var(--gray-600);
  margin-bottom: 10px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.format-badge {
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
}
.format-badge-ok { color: #0f7b3f; background: #e6f6ec; }
.format-badge-off { color: #8a4a00; background: #fff3e0; }
.format-item {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 16px 6px 0; font-size: 13px; font-weight: 500;
  color: var(--gray-600); cursor: pointer;
}
.format-item input { width: auto; margin: 0; }
.format-item-disabled { opacity: .55; cursor: not-allowed; }
