:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #206bc4;
  --accent-weak: #e8f1ff;
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

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

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

button.ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

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

input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 34px;
  padding: 6px 8px;
  background: #fff;
  color: var(--text);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

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

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.error { color: var(--danger); min-height: 20px; }

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

.sidebar {
  background: #152238;
  color: #fff;
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.brand {
  display: grid;
  gap: 6px;
}

.brand span {
  color: #b7c3d7;
  font-size: 13px;
}

.sidebar nav {
  display: grid;
  align-content: start;
  gap: 8px;
}

.nav {
  width: 100%;
  background: transparent;
  color: #e8edf7;
  border-color: transparent;
  text-align: left;
}

.nav.active {
  background: #274260;
  border-color: #45627f;
}

.content {
  min-width: 0;
  overflow: auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  background: rgba(245, 247, 250, 0.96);
  border-bottom: 1px solid var(--line);
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

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

.top-actions, .toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.view {
  padding: 18px;
}

.toolbar {
  margin-bottom: 12px;
}

.toolbar input {
  width: min(460px, 100%);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.floating {
  position: absolute;
  z-index: 4;
  right: 22px;
  top: 110px;
  width: 340px;
  max-height: 520px;
  overflow: auto;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

.grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; }

.check {
  display: inline-flex;
  align-items: center;
  color: var(--text);
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  height: calc(100vh - 180px);
}

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

th, td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
  max-width: 360px;
}

th:first-child,
td:first-child {
  border-left: 1px solid var(--line);
}

th {
  background: #eef2f7;
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  white-space: nowrap;
}

td {
  background: #fff;
}

tr:hover td {
  background: #f9fbff;
}

#productsTable th:last-child,
#productsTable td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  min-width: 86px;
  text-align: center;
  box-shadow: -8px 0 10px -10px rgba(15, 23, 42, 0.35);
}

#productsTable th:last-child {
  z-index: 3;
}

#productsTable td:last-child {
  background: #fff;
}

#productsTable tr:hover td:last-child {
  background: #f9fbff;
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-weak);
  color: #194b88;
  border-radius: 999px;
  padding: 3px 8px;
  margin: 2px;
  font-size: 12px;
}

.chooser-actions {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.column-search {
  width: 100%;
  min-width: 0;
}

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

.chooser-buttons button {
  min-width: 0;
  white-space: normal;
}

.column-search-result {
  min-height: 18px;
  font-size: 12px;
}

.column-group {
  margin-bottom: 12px;
}

.required-export-label { display: inline-block; margin-left: 6px; color: #286447; font-size: 11px; }
.export-identity-note { font-size: 12px; line-height: 1.6; }

.filter-bar {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.filter-heading, .filter-controls, .active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.filter-heading { justify-content: space-between; }
.filter-heading strong { font-size: 13px; }
.filter-heading-title { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.filter-match-label { font-size: 12px; }
#filterMatch { min-height: 30px; padding: 4px 8px; color: var(--text); }
#exportRangeInfo, .filter-help, .filter-and { font-size: 12px; color: var(--muted); }
#filterField { flex: 1 1 230px; min-width: 0; max-width: 380px; }
#filterOp { flex: 0 1 145px; }
#filterValue { flex: 1 1 230px; min-width: 160px; }
.active-filters .chip { max-width: 100%; white-space: normal; overflow-wrap: anywhere; text-align: left; }
#filterError:empty { display: none; }

.pager {
  display: none;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.result {
  background: #101828;
  color: #ecfdf3;
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
  max-height: 260px;
}

dialog {
  width: min(1080px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.46);
}

.account-actions { display: grid; gap: 8px; }
#passwordDialog { width: min(440px, calc(100vw - 32px)); }
.password-form { display: grid; gap: 12px; padding: 20px; }
.password-form p { margin: 0; font-size: 13px; }

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
  font-size: 20px;
}

#productDetail {
  padding: 18px;
  overflow: auto;
  max-height: calc(100vh - 180px);
}

#exceptionDetail {
  padding: 18px;
  display: grid;
  gap: 14px;
  min-width: min(760px, calc(100vw - 72px));
}

.dialog-actions {
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  text-align: right;
}

.detail-group {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.detail-group h3 {
  margin: 0;
  padding: 10px 12px;
  background: #eef2f7;
  font-size: 15px;
}

.field-row {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.exception-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.exception-summary div {
  display: grid;
  gap: 4px;
}

.exception-summary strong {
  color: var(--muted);
  font-size: 12px;
}

.exception-editor textarea {
  min-height: 150px;
  width: 100%;
}

.legacy-tools {
  display: flex;
  justify-content: flex-end;
  padding: 0 0 8px;
}

.legacy-tools a {
  color: #1d5ca5;
  font-size: 14px;
}

.legacy-tools:not(.hidden) + .legacy-frame {
  height: calc(100vh - 126px);
}

.legacy-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 96px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.field-row textarea {
  min-height: 70px;
}

.thumb {
  max-width: 96px;
  max-height: 72px;
  object-fit: contain;
  background: #f2f4f7;
  border: 1px solid var(--line);
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; grid-template-rows: auto auto auto; }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.four { grid-template-columns: 1fr; }
}

