@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Bold.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: block;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("/static/fonts/JetBrainsMono-Italic.woff2") format("woff2");
  font-style: italic;
  font-weight: 400;
  font-display: block;
}

:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #d7dee8;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #165dff;
  --accent-soft: #e8efff;
  --warning: #b45309;
  --ok: #047857;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "JetBrains Mono", Inter, "PingFang SC", "Microsoft YaHei", monospace, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }
.login-screen {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-language {
  position: absolute;
  top: 20px;
  right: 20px;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}
.login-brand {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-bottom: 22px;
  text-align: center;
}
.app-logo {
  display: block;
  object-fit: contain;
}
.login-logo {
  width: min(260px, 100%);
  max-height: 112px;
}
.login-card h1 { margin: 0; }
.login-card label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}
.login-card input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font: inherit;
}
.login-card button { width: 100%; margin-top: 4px; }

.app { min-height: 100vh; padding: 20px; }
.shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
}
.sidebar {
  min-height: calc(100vh - 40px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  padding: 2px 8px 12px;
  text-align: center;
}
.sidebar-logo {
  width: min(144px, 100%);
  max-height: 62px;
}
.brand-title {
  position: relative;
  display: inline-block;
  padding-right: 20px;
}
.brand h1 { font-size: 18px; margin: 0; }
.brand-title span {
  position: absolute;
  right: 0;
  bottom: -3px;
  font-size: 10px;
  color: var(--muted);
}
.menu {
  display: grid;
  gap: 10px;
}
.menu-group {
  display: grid;
  gap: 6px;
}
.menu-subgroup {
  display: grid;
  gap: 6px;
}
.menu-submenu {
  display: grid;
  gap: 6px;
}
.menu-submenu[hidden] {
  display: none;
}
.menu-group-title {
  background: #f8fafc;
  font-size: 13px;
  color: var(--text);
  font-weight: 700;
}
.menu-group-title:hover {
  border-color: #c9d3e2;
}
.menu-item {
  width: 100%;
  text-align: left;
}
.menu-toggle {
  position: relative;
  padding-right: 28px;
}
.menu-toggle::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-65%) rotate(45deg);
  transition: transform 0.15s ease;
}
.menu-toggle[aria-expanded="true"]::after {
  transform: translateY(-35%) rotate(225deg);
}
.menu-item.child {
  padding-left: 24px;
}
.menu-item.grandchild {
  padding-left: 40px;
}
.menu-item:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}
.menu-item.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.user-box {
  margin-top: auto;
  border-top: 1px solid #eef2f7;
  padding-top: 12px;
  display: grid;
  gap: 8px;
  font-size: 13px;
}
.content { min-width: 0; }
.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}
.eyebrow { font-size: 12px; color: var(--muted); letter-spacing: 0; }
h1 { margin: 4px 0 0; font-size: 22px; }
.tabs { display: flex; gap: 8px; }
.language-switch {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.language-toggle {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  background: var(--panel);
}
.language-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.language-icon {
  width: 24px;
  height: 18px;
  position: relative;
  display: block;
  font-weight: 800;
  line-height: 1;
}
.language-zh,
.language-en {
  position: absolute;
  display: block;
  letter-spacing: 0;
}
.language-zh {
  left: 0;
  top: 0;
  font-size: 15px;
}
.language-en {
  right: 0;
  bottom: 0;
  font-size: 13px;
}
.tab, button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 14px;
  cursor: pointer;
}
.tab.active, .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.ghost { background: transparent; }

.upload-strip {
  min-height: auto;
  margin-bottom: 12px;
  padding: 8px;
}
.upload-strip .panel-head { margin-bottom: 0; }
.panel-head.upload-title {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  justify-content: stretch;
}
.upload-strip h2 {
  display: flex;
  align-items: center;
  padding-left: 4px;
  font-size: 14px;
}
.upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 8px;
  align-items: stretch;
  width: 100%;
  min-width: 0;
}
.upload-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  min-height: 76px;
  padding: 10px 12px;
  border: 1px solid #eef2f7;
  border-radius: 8px;
  background: #fbfdff;
}
.cloud-fetch {
  margin-top: 8px;
}
.cloud-fetch input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.workspace {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 16px;
  align-items: start;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}
.workspace.loadings-workspace { grid-template-columns: minmax(0, 1fr); }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-height: 70vh;
  min-width: 0;
}
.panel.upload-strip { min-height: auto; }
.loadings-workspace .panel { min-height: auto; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.panel h2 { margin: 0; font-size: 16px; }
.dropzone {
  position: relative;
  border: 1px dashed #a8b4c5;
  border-radius: 8px;
  width: 100%;
  height: 100%;
  min-height: 76px;
  padding: 16px;
  display: grid;
  place-items: center;
  text-align: center;
  background: #fafcff;
}
.dropzone p { margin: 0; font-size: 13px; color: var(--muted); }
.dropzone.dragover { background: var(--accent-soft); border-color: var(--accent); }
.dropzone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.actions { display: flex; gap: 10px; margin-top: 12px; }
.upload-strip .actions { margin-top: 0; }
.upload-strip .actions { flex-wrap: wrap; }
.hint { margin-top: 12px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.upload-strip .hint { margin-top: 6px; line-height: 1.3; min-height: 18px; }
.stats-panel { min-height: calc(100vh - 124px); }
.chart-placeholder {
  min-height: 420px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfdff;
}
.users-panel { min-height: calc(100vh - 124px); }
.cache-panel { min-height: calc(100vh - 124px); }
.cache-summary {
  border: 1px solid #dbe7ff;
  background: #f7fbff;
  color: var(--muted);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.cache-table {
  min-width: 1120px;
}
.delivery-panel {
  min-height: calc(100vh - 124px);
  padding: 0;
  overflow: hidden;
}
.delivery-frame {
  width: 100%;
  height: calc(100vh - 124px);
  display: block;
  border: 0;
  background: white;
}
.backfill-panel {
  min-height: calc(100vh - 124px);
}
.link-panel {
  min-height: calc(100vh - 124px);
}
.backfill-query,
.link-query {
  display: grid;
  grid-template-columns: minmax(220px, 360px) max-content max-content;
  gap: 10px;
  align-items: center;
}
.link-preview-form {
  grid-template-columns: minmax(220px, 360px) max-content;
}
.backfill-query input,
.link-query input,
.backfill-controls select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
  color: var(--text);
  font: inherit;
}
.backfill-summary,
.link-summary,
.link-file-meta {
  border: 1px solid #dbe7ff;
  background: #f7fbff;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 12px;
  display: grid;
  gap: 8px;
  font-size: 13px;
}
.link-summary,
.link-file-meta {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.link-summary div,
.link-file-meta div {
  display: grid;
  gap: 4px;
  min-width: 0;
}
.link-summary span,
.link-file-meta span {
  color: var(--muted);
  font-size: 12px;
}
.link-summary strong,
.link-file-meta strong {
  overflow-wrap: anywhere;
}
.link-preview {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}
.backfill-swb-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.backfill-swb-counts span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: white;
}
.backfill-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.backfill-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.backfill-workspace {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}
.backfill-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  border: 1px solid #eef2f7;
  border-radius: 8px;
  padding: 10px;
  background: #fbfdff;
}
.backfill-controls label {
  display: grid;
  gap: 6px;
  min-width: 190px;
  font-size: 12px;
  color: var(--muted);
}
.backfill-table-area {
  display: grid;
  gap: 8px;
}
.backfill-table .filtered-row td {
  background: #ecfdf5;
}
.user-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}
.user-form input,
.user-form select,
.users-table input,
.users-table select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
  color: var(--text);
  font: inherit;
}
.users-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
}
.users-table {
  width: 100%;
  min-width: 960px;
}
.users-table th,
.users-table td {
  white-space: nowrap;
}
.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.row-actions button {
  padding: 7px 9px;
}
.danger {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fff7f7;
}
.query-view {
  display: grid;
  gap: 14px;
  align-content: start;
}
.query-input-panel,
.query-result-panel {
  display: grid;
  gap: 14px;
}
.query-input-panel {
  position: sticky;
  top: 20px;
  z-index: 5;
  min-height: auto;
  padding: 10px 12px;
  gap: 8px;
  box-shadow: 0 10px 22px rgba(31, 41, 55, 0.08);
}
.query-input-panel .panel-head {
  margin-bottom: 2px;
}
.query-input-panel h2 {
  font-size: 14px;
}
.query-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 8px 10px;
  align-items: end;
}
.query-form label {
  display: grid;
  gap: 3px;
  min-width: 0;
  font-size: 11px;
  color: var(--muted);
}
.query-form input,
.query-form select {
  width: 100%;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
  background: white;
  color: var(--text);
  font: inherit;
  font-size: 12px;
}
.query-actions {
  display: flex;
  gap: 6px;
}
.query-actions button {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}
.query-result-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.query-table {
  table-layout: fixed;
}
.query-table th,
.query-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.query-table th {
  position: relative;
  user-select: none;
}
.query-table th span:first-child {
  display: block;
  overflow: hidden;
  padding-right: 8px;
  text-overflow: ellipsis;
}
.query-table td[data-col-key="goods_name_cn"] {
  white-space: normal;
}
.column-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
}
.column-resizer::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  border-left: 1px solid transparent;
}
.query-table th:hover .column-resizer::after,
.is-resizing-column .column-resizer::after {
  border-left-color: var(--accent);
}
.is-resizing-column {
  cursor: col-resize;
  user-select: none;
}

.preview-area {
  min-height: 120vh;
  overflow: auto;
  max-width: 100%;
}
.loadings-workspace .preview-area { min-height: 0; }
.preview-area img {
  max-width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.pdf-frame {
  width: 100%;
  height: 130vh;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}
.placeholder {
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 24px;
}

.field-list { display: grid; gap: 10px; }
.field-row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px;
  align-items: start;
  border-bottom: 1px solid #eef2f7;
  padding-bottom: 10px;
}
.field-row label { font-size: 13px; color: var(--muted); padding-top: 9px; }
.field-row input, .field-row textarea, .field-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
  color: var(--text);
  font: inherit;
}
.field-row input { height: 36px; }
.field-row textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.field-row.multiline textarea { min-height: 112px; }
.cargo-section {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.cargo-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.cargo-table-wrap { max-height: 68vh; }
.cargo-table th,
.cargo-table td {
  min-width: 150px;
}
.cargo-table th {
  position: static;
  z-index: auto;
}
.cargo-table th:nth-child(2),
.cargo-table td:nth-child(2) {
  min-width: 320px;
}
.cargo-table input,
.cargo-table textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 12px;
}
.cargo-table input { height: 34px; }
.cargo-table textarea {
  min-height: 72px;
  line-height: 1.35;
  resize: vertical;
}
.cargo-empty { padding: 16px; }
.confidence {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.recognition-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.recognition-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
}
.warning-list {
  border: 1px solid #f1c27d;
  background: #fff8ed;
  color: var(--warning);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 12px;
  font-size: 12px;
  line-height: 1.5;
}
.sheet-select-panel {
  display: grid;
  grid-template-columns: minmax(220px, 360px) max-content;
  gap: 12px;
  align-items: end;
}
.sheet-select-panel label {
  display: grid;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.sheet-select-panel select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: white;
  color: var(--text);
  font: inherit;
}

.mapping-grid {
  display: grid;
  gap: 8px;
}
.select-all-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 10px;
  font-size: 13px;
  font-weight: 700;
}
.mapping-row {
  display: grid;
  grid-template-columns: 28px 72px minmax(180px, 1.1fr) minmax(180px, 1fr) 92px;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid #eef2f7;
  padding-bottom: 8px;
}
.column-check {
  display: grid;
  place-items: center;
}
.mapping-row > .muted:nth-child(2) {
  font-weight: 700;
  color: var(--text);
}
.mapping-row input, .mapping-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}
.override-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 8px 12px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #eef2f7;
}
.section-title {
  grid-column: 1 / -1;
  font-size: 13px;
  font-weight: 700;
}
.override-row {
  display: grid;
  grid-template-columns: 18px 120px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.override-row input[type="text"],
.override-row input:not([type]) {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}
.muted { color: var(--muted); font-size: 12px; }
.ok { color: var(--ok); }
.warn { color: var(--warning); }
.table-wrap {
  overflow: auto;
  max-width: 100%;
  max-height: 52vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 13px; table-layout: fixed; }
th, td {
  border-bottom: 1px solid #edf1f6;
  border-right: 1px solid #edf1f6;
  padding: 8px 10px;
  vertical-align: top;
}
td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td.duplicate-cell { background: #ffe4ec; }
th { background: #f9fbff; position: sticky; top: 0; z-index: 1; }
.loading-preview .col-letter {
  top: 0;
  padding: 5px 8px;
  text-align: center;
  color: var(--text);
  background: #eef4ff;
}
.loading-preview .header-cell {
  top: 29px;
  line-height: 1.25;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: var(--muted);
}
.page-version {
  position: fixed;
  right: 10px;
  bottom: 6px;
  z-index: 1000;
  color: #9ca3af;
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

@media (max-width: 1200px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
  .user-form { grid-template-columns: 1fr; }
  .sheet-select-panel { grid-template-columns: 1fr; }
  .upload-title { grid-template-columns: 1fr; }
  .upload-row { grid-template-columns: 1fr; }
  .upload-strip h2 { padding-left: 0; }
  .workspace { grid-template-columns: 1fr; }
  .backfill-query, .link-query { grid-template-columns: 1fr; }
  .panel { min-height: auto; }
}
