:root {
  color-scheme: light;
  --bg: #f3f1eb;
  --surface: #ffffff;
  --surface-soft: #eef4ef;
  --surface-blue: #eaf5ff;
  --surface-blue-soft: #f5fbff;
  --surface-blue-deep: #d7ebfb;
  --surface-warm: #fff6df;
  --surface-danger: #fbe7e7;
  --border: #d6d3ca;
  --blue-border: #bfd8ea;
  --text: #1d2620;
  --muted: #5a655d;
  --primary: #177245;
  --primary-strong: #0f5c36;
  --accent: #0f766e;
  --warn: #b7791f;
  --danger: #b42318;
  --shadow: 0 10px 28px rgba(38, 45, 39, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(23, 114, 69, 0.18);
  outline-offset: 1px;
  border-color: var(--primary);
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 13px;
}

.app-shell {
  width: min(1480px, calc(100% - 24px));
  margin: 0 auto;
  padding: 20px 0 36px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(23, 114, 69, 0.08), rgba(15, 118, 110, 0.08)), var(--surface);
  box-shadow: var(--shadow);
}

.topbar-copy {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

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

.lead {
  margin: 10px 0 0;
  max-width: 760px;
  color: var(--muted);
}

.stock-legend {
  margin: 8px 0 0;
  max-width: 880px;
  color: #2f5f7a;
  font-size: 13px;
}

.topbar-side {
  display: grid;
  gap: 10px;
  justify-items: end;
  min-width: 150px;
}

.page-stack {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.band,
.result-pane,
.detail-pane {
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.band {
  background: var(--surface);
  padding: 18px;
}

.result-pane {
  background: linear-gradient(180deg, rgba(132, 186, 226, 0.18), rgba(132, 186, 226, 0.04) 140px), #f8fcff;
}

.detail-pane {
  background: linear-gradient(180deg, rgba(183, 121, 31, 0.08), rgba(183, 121, 31, 0.02) 120px), #fffdf7;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 14px;
}

.section-head h2,
.section-head h3 {
  margin: 0;
  font-size: 20px;
}

.section-note {
  color: var(--muted);
  font-size: 13px;
}

.sticky-head {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 18px 18px 12px;
  border-bottom: 1px solid rgba(214, 211, 202, 0.8);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
}

.result-pane .sticky-head {
  background: rgba(245, 251, 255, 0.96);
  border-bottom-color: rgba(191, 216, 234, 0.9);
}

.detail-pane .sticky-head {
  background: rgba(255, 253, 247, 0.95);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.summary-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
}

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

.summary-value {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 700;
}

.summary-hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.expander summary {
  cursor: pointer;
  font-weight: 700;
}

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

.form-grid.three,
.sync-grid,
.search-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.checkbox-block {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #faf8f3;
}

.checkbox-block span {
  color: var(--muted);
  font-size: 13px;
}

.checkbox-block label,
.checkbox-inline {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text);
}

.checkbox-block input[type="checkbox"],
.checkbox-inline input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.checkbox-block.compact {
  grid-template-columns: 1fr;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.align-end {
  align-items: end;
}

.primary-button,
.ghost-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 600;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.ghost-button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.ghost-button:hover {
  background: #f6f6f1;
}

.inline-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.result-pane,
.detail-pane {
  min-width: 0;
  overflow: hidden;
}

.result-list {
  display: grid;
  gap: 16px;
  padding: 14px 18px 18px;
  background: transparent;
}

.result-card {
  display: grid;
  gap: 14px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--blue-border);
  border-radius: 6px;
  background: #ffffff;
  text-align: left;
  box-shadow: 0 6px 18px rgba(94, 133, 168, 0.08);
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.result-card:nth-child(odd):not(.erp-only) {
  background: linear-gradient(180deg, #f5fbff, #edf7ff);
}

.result-card:nth-child(even):not(.erp-only) {
  background: #ffffff;
}

.result-card:hover {
  transform: translateY(-1px);
  border-color: #7eb0d2;
  box-shadow: 0 10px 24px rgba(94, 133, 168, 0.14);
}

.result-card.active {
  border-color: #5895c2;
  background: linear-gradient(180deg, #ffffff, #f3faff);
  box-shadow: 0 0 0 2px rgba(88, 149, 194, 0.18), 0 12px 28px rgba(94, 133, 168, 0.16);
}

.result-card.erp-only {
  background: linear-gradient(180deg, #ffffff, #eef7ff);
}

.result-card.safety-warning {
  border-color: rgba(183, 121, 31, 0.45);
  box-shadow: 0 0 0 1px rgba(183, 121, 31, 0.12), 0 8px 20px rgba(183, 121, 31, 0.1);
}

.result-card.stagnant-warning {
  border-color: rgba(183, 121, 31, 0.52);
  background: linear-gradient(180deg, #fffaf0, #fff3d9);
  box-shadow: 0 0 0 1px rgba(183, 121, 31, 0.16), 0 8px 20px rgba(183, 121, 31, 0.12);
}

.result-card.stagnant-warning:hover {
  border-color: rgba(183, 121, 31, 0.72);
  box-shadow: 0 12px 28px rgba(183, 121, 31, 0.16);
}

.result-card.stagnant-warning.active {
  border-color: rgba(183, 121, 31, 0.82);
  background: linear-gradient(180deg, #fffdf5, #fff2d1);
  box-shadow: 0 0 0 2px rgba(183, 121, 31, 0.2), 0 12px 28px rgba(183, 121, 31, 0.16);
}

.result-card.safety-warning.active {
  border-color: rgba(183, 121, 31, 0.78);
  box-shadow: 0 0 0 2px rgba(183, 121, 31, 0.2), 0 12px 28px rgba(183, 121, 31, 0.14);
}

.result-card:nth-child(odd):not(.erp-only) .metric-box,
.result-card:nth-child(odd):not(.erp-only) .detail-meta {
  border-color: #cfe1ef;
  background: linear-gradient(180deg, #ffffff, #f3f9ff);
}

.result-card:nth-child(odd):not(.erp-only) .metric-label,
.result-card:nth-child(odd):not(.erp-only) .detail-meta .label {
  color: #54738d;
}

.card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.card-title-wrap {
  min-width: 0;
}

.card-title-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
}

.card-title {
  margin: 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.card-title-name {
  color: var(--accent);
}

.card-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
}

.pill.good {
  background: rgba(23, 114, 69, 0.12);
  color: var(--primary-strong);
}

.pill.warn {
  background: rgba(183, 121, 31, 0.14);
  color: #8a5b15;
}

.pill.danger {
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
}

.pill.neutral {
  background: #f0efea;
  color: var(--muted);
  border-color: rgba(214, 211, 202, 0.8);
}

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

.result-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.result-card-grid__full {
  grid-column: 1 / -1;
}

.metric-box {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}

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

.metric-value {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.metric-box.rich-value .metric-value {
  margin-top: 6px;
}

.actual-stock-block {
  display: grid;
  gap: 6px;
}

.stacked-metric-block {
  display: grid;
  gap: 8px;
}

.actual-stock-total {
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.stacked-metric-value {
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.actual-stock-lines {
  display: grid;
  gap: 4px;
}

.actual-stock-line {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.metric-detail-list {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.metric-detail-line {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: normal;
}

.metric-detail-item {
  display: grid;
  gap: 5px;
  padding: 8px 10px;
  border: 1px solid rgba(197, 215, 232, 0.9);
  border-radius: 6px;
  background: #ffffff;
}

.metric-detail-item.simple {
  gap: 0;
}

.metric-detail-item.overdue {
  border-color: rgba(226, 118, 86, 0.38);
  background: rgba(255, 243, 239, 0.9);
}

.metric-detail-item.overdue .metric-detail-dates {
  color: #a63b12;
}

.metric-detail-main {
  display: block;
  font-weight: 700;
  line-height: 1.35;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
}

.metric-detail-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.metric-detail-dates {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f1f7fb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.metric-detail-qty {
  color: var(--accent);
  font-weight: 700;
  min-width: 0;
}

.subsection {
  padding: 0 18px 18px;
}

.detail-pane {
  position: sticky;
  top: 16px;
}

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

.detail-panel.empty {
  color: var(--muted);
  padding-top: 12px;
}

.detail-title-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.detail-title-wrap {
  min-width: 0;
}

.detail-title {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.detail-title-line {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: baseline;
}

.detail-title-name {
  color: var(--accent);
}

.detail-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.detail-block {
  display: grid;
  gap: 12px;
}

.detail-block h3 {
  margin: 0;
  font-size: 16px;
}

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.result-meta-grid .detail-meta.warehouse-wide {
  grid-column: span 3;
}

.result-meta-grid .detail-meta.status-narrow {
  grid-column: span 1;
}

.detail-meta {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafaf7;
}

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

.detail-meta .value {
  margin-top: 4px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.detail-meta.rich-value .value,
.metric-box.rich-value .metric-value {
  min-width: 0;
  overflow-wrap: break-word;
  word-break: normal;
}

.expected-block {
  display: grid;
  gap: 8px;
}

.expected-block.compact {
  gap: 6px;
}

.expected-block.attention {
  padding: 8px 10px;
  border: 1px solid rgba(180, 35, 24, 0.26);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(255, 239, 234, 0.96), rgba(255, 247, 244, 0.98));
}

.expected-block.attention .expected-value {
  color: #a63b12;
}

.expected-value {
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.detail-meta.rich-value .expected-value {
  font-size: 16px;
}

.detail-meta.rich-value .date-pair,
.metric-box.rich-value .date-pair {
  margin-top: 0;
}

.date-pair {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.date-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.date-chip.purchase {
  background: rgba(15, 118, 110, 0.12);
  border-color: rgba(15, 118, 110, 0.18);
  color: var(--accent);
}

.date-chip.delivery {
  background: rgba(183, 121, 31, 0.12);
  border-color: rgba(183, 121, 31, 0.18);
  color: #8a5b15;
}

.date-alert-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  color: #c81e1e;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.date-empty {
  color: var(--muted);
  font-size: 13px;
}

.line-list {
  display: grid;
  gap: 10px;
}

.line-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafaf7;
}

.line-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.line-card-title {
  margin: 0;
  font-size: 15px;
}

.line-card-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.line-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.line-meta {
  min-width: 0;
}

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

.line-meta .value {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.empty-note {
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: #faf8f3;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
  font-weight: 700;
  text-align: center;
}

.status-chip[data-status="connected"] {
  background: rgba(23, 114, 69, 0.12);
  color: var(--primary-strong);
}

.status-chip[data-status="disconnected"] {
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
}

.status-chip[data-status="degraded"] {
  background: rgba(183, 121, 31, 0.14);
  color: #8a5b15;
}

.notice {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-warm);
  color: #6b4b12;
}

.notice.danger {
  background: var(--surface-danger);
  color: var(--danger);
}

.muted-text {
  color: var(--muted);
  font-size: 13px;
}

.mono {
  font-family: Consolas, "SFMono-Regular", Monaco, monospace;
}

@media (max-width: 1120px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .detail-pane {
    position: static;
  }
}

@media (max-width: 900px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-side {
    justify-items: start;
    min-width: 0;
  }

  .form-grid.three,
  .sync-grid,
  .search-grid,
  .result-card-grid,
  .metric-grid,
  .detail-meta-grid,
  .line-meta-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .result-meta-grid .detail-meta.warehouse-wide,
  .result-meta-grid .detail-meta.status-narrow {
    grid-column: span 2;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 16px, 1480px);
    padding-top: 14px;
  }

  .topbar,
  .band {
    padding: 14px;
  }

  .sticky-head {
    padding: 14px 14px 10px;
  }

  .result-list,
  .subsection,
  .detail-panel {
    padding-left: 14px;
    padding-right: 14px;
    padding-bottom: 14px;
  }

  .form-grid.three,
  .sync-grid,
  .search-grid,
  .result-card-grid,
  .metric-grid,
  .detail-meta-grid,
  .line-meta-grid {
    grid-template-columns: 1fr;
  }

  .result-meta-grid {
    grid-template-columns: 1fr;
  }

  .result-meta-grid .detail-meta.warehouse-wide,
  .result-meta-grid .detail-meta.status-narrow {
    grid-column: span 1;
  }

  .topbar h1 {
    font-size: 25px;
  }

  .summary-value {
    font-size: 21px;
  }
}
