:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #20211f;
  --muted: #6f726b;
  --line: #d8d1c3;
  --dark: #1e2524;
  --dark-2: #2d3533;
  --accent: #2f7d69;
  --accent-2: #b98734;
  --danger: #b94d38;
  --ok: #2f7d69;
  --warn: #b98734;
  --shadow: 0 14px 40px rgba(40, 37, 31, 0.13);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(30, 37, 36, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30, 37, 36, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
  font-family: "Microsoft YaHei", "DengXian", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: inherit;
}

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

button {
  border: 1px solid var(--dark);
  border-radius: 6px;
  background: var(--dark);
  color: #fffdf8;
  min-height: 34px;
  padding: 0 12px;
  cursor: pointer;
}

button.secondary {
  background: var(--panel);
  color: var(--dark);
}

button.ghost {
  background: transparent;
  color: var(--dark);
  border-color: var(--line);
}

button.warn {
  background: var(--warn);
  border-color: var(--warn);
}

button.danger {
  background: var(--danger);
  border-color: var(--danger);
}

button.icon-button {
  width: 34px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefb;
  min-height: 36px;
  padding: 7px 9px;
  color: var(--ink);
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
}

.inline-input {
  width: 92px;
  min-height: 30px;
  padding: 5px 7px;
}

textarea {
  min-height: 70px;
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 480px) 1fr;
}

.login-panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: clamp(24px, 6vw, 64px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  box-shadow: var(--shadow);
}

.login-art {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(47, 125, 105, 0.18), rgba(185, 135, 52, 0.12)),
    repeating-linear-gradient(90deg, transparent 0 34px, rgba(30, 37, 36, 0.1) 35px 36px),
    #e8e1d3;
}

.login-art::before {
  content: "";
  position: absolute;
  inset: 12%;
  border: 2px solid rgba(30, 37, 36, 0.32);
  transform: skewX(-11deg);
}

.login-art::after {
  content: "BOM  采购  仓库  生产  财务";
  position: absolute;
  left: 10%;
  bottom: 12%;
  max-width: 620px;
  font-family: Cambria, "Microsoft YaHei", serif;
  font-size: clamp(42px, 7vw, 96px);
  font-weight: 700;
  line-height: 0.98;
  color: rgba(30, 37, 36, 0.78);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--dark);
  color: var(--panel);
  border-radius: 8px;
  font-weight: 800;
}

.brand-title {
  font-size: 21px;
  font-weight: 800;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.15;
}

.login-card p {
  color: var(--muted);
  margin: 0 0 22px;
}

.login-card form,
.stack {
  display: grid;
  gap: 14px;
}

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--dark);
  color: #f5efe4;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: auto;
}

.sidebar .brand {
  margin: 0;
}

.sidebar .brand-mark {
  background: #f5efe4;
  color: var(--dark);
}

.nav {
  display: grid;
  gap: 8px;
}

.nav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: #eee6d8;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px 11px;
}

.nav-root {
  font-size: 15px;
  font-weight: 700;
}

.nav-group {
  display: grid;
  gap: 4px;
}

.nav-group-title {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  color: #f8efe2;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  text-align: left;
}

.nav-group-title:hover,
.nav-group-title:focus-visible {
  background: rgba(255, 253, 248, 0.08);
  border-color: rgba(255, 253, 248, 0.16);
  outline: none;
}

.nav-chevron {
  flex: 0 0 auto;
  color: rgba(245, 239, 228, 0.72);
  font-size: 16px;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 0.16s ease;
}

.nav-item-label {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.nav-todo {
  flex: 0 0 auto;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #d14b35;
  color: #fffaf1;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0 0 1px rgba(255, 253, 248, 0.18);
}

.nav-group.open .nav-chevron {
  transform: rotate(90deg);
}

.nav-group.collapsed .nav-sub {
  display: none;
}

.nav-sub {
  display: grid;
  gap: 3px;
}

.nav-sub a {
  padding: 8px 10px 8px 18px;
  color: rgba(245, 239, 228, 0.88);
  font-size: 13px;
  font-weight: 500;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 253, 248, 0.1);
  border-color: rgba(255, 253, 248, 0.18);
}

.user-box {
  margin-top: auto;
  border-top: 1px solid rgba(255, 253, 248, 0.16);
  padding-top: 14px;
  display: grid;
  gap: 10px;
}

.main {
  min-width: 0;
}

.topbar {
  background: rgba(244, 241, 234, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 18px clamp(16px, 3vw, 30px);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
}

.topbar .meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.content {
  padding: clamp(16px, 3vw, 30px);
  display: grid;
  gap: 18px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel,
.metric,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(40, 37, 31, 0.06);
}

.panel {
  padding: 16px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.panel h2,
.panel h3 {
  margin: 0;
}

.panel h2 {
  font-size: 18px;
}

.panel h3 {
  font-size: 15px;
}

.metric {
  padding: 14px;
  min-height: 96px;
  display: grid;
  align-content: space-between;
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
}

.metric .value {
  font-family: Cambria, Georgia, serif;
  font-size: 34px;
  font-weight: 700;
}

.metric .hint {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: hidden;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th,
td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px 11px;
  vertical-align: top;
}

th {
  background: #ede7da;
  color: #383b36;
  font-weight: 700;
  position: sticky;
  top: 0;
}

td.truncate {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

tr:last-child td {
  border-bottom: 0;
}

.table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.plan-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.plan-chip {
  display: inline-grid;
  gap: 1px;
  min-width: 82px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 7px;
  background: #ebe5d8;
  font-size: 11px;
  line-height: 1.25;
}

.plan-chip strong {
  font-size: 11px;
}

.plan-ok {
  background: rgba(47, 125, 105, 0.1);
  border-color: rgba(47, 125, 105, 0.26);
}

.plan-warn {
  background: rgba(185, 135, 52, 0.16);
  border-color: rgba(185, 135, 52, 0.34);
}

.plan-danger {
  background: rgba(185, 77, 56, 0.13);
  border-color: rgba(185, 77, 56, 0.34);
  color: var(--danger);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.filter-panel {
  background: rgba(255, 255, 255, 0.62);
}

.module-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.module-tabs a {
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  background: var(--panel);
  color: var(--dark);
  font-size: 13px;
}

.module-tabs a.active,
.module-tabs a:hover {
  border-color: var(--dark);
  background: var(--dark);
  color: var(--panel);
}

.form-grid .wide {
  grid-column: span 2;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.form-grid.inner {
  margin-top: 10px;
}

.form-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(255, 255, 255, 0.45);
}

.form-section h3 {
  margin: 0;
}

.panel-header.compact {
  margin-bottom: 10px;
}

.detail-table input,
.detail-table select {
  min-width: 120px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(30, 37, 36, 0.38);
}

.modal-card {
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 22px 60px rgba(30, 37, 36, 0.26);
  padding: 16px;
}

.modal-card.wide-modal {
  width: min(1100px, 100%);
}

.permission-group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(255, 255, 255, 0.45);
}

.permission-group h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 12px;
}

.role-template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  color: var(--ink);
  font-size: 13px;
}

.json-preview {
  overflow: auto;
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffefb;
  padding: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #ebe5d8;
  color: var(--dark);
  border: 1px solid var(--line);
  font-size: 12px;
  white-space: nowrap;
}

.badge.ok {
  background: rgba(47, 125, 105, 0.12);
  border-color: rgba(47, 125, 105, 0.35);
  color: var(--ok);
}

.badge.warn {
  background: rgba(185, 135, 52, 0.14);
  border-color: rgba(185, 135, 52, 0.36);
  color: #7b5519;
}

.badge.danger {
  background: rgba(185, 77, 56, 0.12);
  border-color: rgba(185, 77, 56, 0.35);
  color: var(--danger);
}

.muted {
  color: var(--muted);
}

.empty,
.loading,
.error {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.64);
}

.error {
  color: var(--danger);
  border-color: rgba(185, 77, 56, 0.36);
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.tab {
  border-color: var(--line);
  color: var(--dark);
  background: var(--panel);
}

.tab.active {
  background: var(--dark);
  color: var(--panel);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 14px;
  align-items: start;
}

.kvs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.kv {
  padding: 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-height: 72px;
}

.kv:nth-child(3n) {
  border-right: 0;
}

.kv .key {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.kv .val {
  font-weight: 700;
}

.progress {
  height: 8px;
  background: #e1dbcf;
  border-radius: 999px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.notice {
  padding: 10px 12px;
  border: 1px solid rgba(185, 135, 52, 0.34);
  background: rgba(185, 135, 52, 0.1);
  color: #6b4a16;
  border-radius: var(--radius);
}

.notice.danger {
  border-color: rgba(185, 77, 56, 0.32);
  background: rgba(185, 77, 56, 0.08);
  color: #793222;
}

@media (max-width: 1040px) {
  .grid.cols-4,
  .grid.cols-3,
  .grid.cols-2,
  .split,
  .form-grid,
  .kvs {
    grid-template-columns: 1fr;
  }

  .form-grid .wide,
  .form-grid .full {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .login-screen,
  .shell {
    grid-template-columns: 1fr;
  }

  .login-art {
    display: none;
  }

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

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    position: relative;
    align-items: start;
    flex-direction: column;
  }
}
