/* Notion 设计语言（见 DESIGN.md）：暖纸画布 + 近黑 Inter + 单一 Notion 蓝。 */
:root {
  color-scheme: light;
  --canvas: #f6f5f4;
  --surface: #ffffff;
  --ink: rgba(0, 0, 0, .95);
  --ink-secondary: #31302e;
  --ink-muted: #615d59;
  --ink-faint: #a39e98;
  --hairline: #e6e6e6;
  --hairline-strong: #d9d9d8;
  --primary: #0075de;
  --primary-active: #005bab;
  --primary-soft: #e8f4fd;
  --on-primary: #ffffff;
  --accent-green: #1aae39;
  --green-deep: #14832c;
  --green-soft: #eaf6ec;
  --accent-orange: #dd5b00;
  --orange-soft: #fdf0e7;
  --danger: #e03e3e;
  --danger-soft: #fdeeee;
  --radius-xs: 4px;
  --radius-sm: 5px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-soft: rgba(0, 0, 0, .01) 0 .175px 1.041px,
    rgba(0, 0, 0, .02) 0 .8px 2.925px,
    rgba(0, 0, 0, .027) 0 2.025px 7.847px,
    rgba(0, 0, 0, .04) 0 4px 18px;
  --shadow-card: var(--shadow-soft);
  --shadow-hover: rgba(0, 0, 0, .02) 0 1px 3.6px,
    rgba(0, 0, 0, .03) 0 4px 10px,
    rgba(0, 0, 0, .04) 0 8px 24px;
  --z-header: 40;
  --z-toast: 70;
  font-family: Inter, -apple-system, "Segoe UI", "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-feature-settings: "lnum";
  font-synthesis: none;
}
* { box-sizing: border-box; }

html { background: var(--canvas); scroll-behavior: smooth; }

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  line-height: 1.5;
}

button, input, select { font: inherit; }
button, a, input, select { touch-action: manipulation; }
button, a, select { cursor: pointer; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(0, 117, 222, .4);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: var(--on-primary);
  background: var(--ink);
  border-radius: var(--radius-md);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

/* 顶栏：Notion 白底导航 + 发丝线。 */
.app-header {
  position: sticky;
  z-index: var(--z-header);
  top: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--hairline);
  backdrop-filter: blur(14px);
}

.header-inner {
  width: min(100%, 1440px);
  min-height: 76px;
  margin: 0 auto;
  padding: 12px clamp(16px, 3vw, 36px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-block,
.header-actions,
.header-navigation,
.header-nav-link,
.live-badge,
.field-label,
.filter-helper,
.loading-heading,
.refresh-button,
.status-action,
.inline-status { display: flex; align-items: center; }

.brand-block { gap: 12px; min-width: 0; }
.header-actions { justify-content: flex-end; gap: 10px; }
.header-navigation { gap: 8px; }

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid #d3e9f9;
  border-radius: var(--radius-md);
}

.brand-mark svg { width: 27px; height: 27px; }

.eyebrow,
.section-kicker {
  margin: 0 0 1px;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .125px;
  text-transform: uppercase;
}

.brand-block .eyebrow { color: var(--primary); }
.brand-block h1 { margin: 0; font-size: clamp(18px, 2.5vw, 22px); font-weight: 700; line-height: 1.2; letter-spacing: -.125px; }

.header-nav-link {
  min-height: 44px;
  padding: 8px 12px;
  justify-content: center;
  gap: 6px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 180ms ease, border-color 180ms ease;
}

.header-nav-link svg { width: 19px; height: 19px; flex: 0 0 auto; }
.header-nav-link:hover { background: var(--canvas); border-color: var(--hairline-strong); }
.header-nav-link:active { background: #eeedec; }

.live-badge {
  min-height: 36px;
  padding: 7px 12px;
  gap: 8px;
  color: var(--ink-secondary);
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(0, 117, 222, .12);
}

.page-shell { width: min(100%, 1440px); margin: 0 auto; padding: clamp(18px, 3vw, 36px); }

.filter-panel {
  padding: clamp(18px, 3vw, 28px);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0; font-size: clamp(20px, 3vw, 26px); font-weight: 700; line-height: 1.25; letter-spacing: -.625px; }

.order-count {
  padding: 4px 10px;
  color: var(--primary);
  background: var(--surface);
  border: 1px solid #d3e9f9;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.filter-grid {
  margin-top: 20px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.field-control { min-width: 0; }
.field-label { margin-bottom: 8px; gap: 7px; color: var(--ink-secondary); font-size: 14px; font-weight: 600; }
.field-label svg, .filter-helper svg { width: 19px; height: 19px; flex: 0 0 auto; color: var(--primary); }

.select-wrap,
.input-wrap { position: relative; display: block; }

.select-wrap select,
.input-wrap input,
.status-select {
  width: 100%;
  min-height: 50px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #dcdcdc;
  border-radius: var(--radius-xs);
  font-size: 16px;
  font-weight: 500;
}

.select-wrap select { padding-right: 44px; appearance: none; }
.select-wrap select:disabled,
.input-wrap input:disabled { color: var(--ink-faint); background: var(--canvas); cursor: wait; }
.select-wrap > svg { position: absolute; top: 50%; right: 14px; width: 20px; height: 20px; color: var(--ink-muted); pointer-events: none; transform: translateY(-50%); }
.input-wrap input::placeholder { color: var(--ink-faint); font-weight: 400; }

.filter-helper { margin: 14px 0 0; gap: 8px; color: var(--ink-muted); font-size: 14px; }
.results-section { margin-top: 32px; }
.results-heading { margin-bottom: 16px; }

.refresh-button,
.empty-action,
.status-confirm {
  min-height: 44px;
  border-radius: var(--radius-md);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

.refresh-button {
  padding: 8px 12px;
  justify-content: center;
  gap: 7px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
}

.refresh-button svg { width: 19px; height: 19px; }
.refresh-button:hover:not(:disabled) { background: var(--canvas); border-color: var(--hairline-strong); }

.refresh-button:disabled,
.status-confirm:disabled {
  color: var(--ink-faint);
  background: var(--canvas);
  border-color: var(--hairline);
  cursor: not-allowed;
}

.loading-state,
.empty-state {
  padding: clamp(24px, 5vw, 48px);
  color: var(--ink-muted);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}

.loading-heading { justify-content: center; gap: 12px; text-align: left; }
.loading-heading strong, .loading-heading span { display: block; }
.loading-heading strong { color: var(--ink); }
.loading-heading span { margin-top: 2px; font-size: 14px; }

.loading-spinner {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 3px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .85s linear infinite;
}

.skeleton-list { margin-top: 28px; display: grid; gap: 10px; }
.skeleton-list div {
  height: 52px;
  background: linear-gradient(90deg, #efeeed 25%, #e6e5e4 37%, #efeeed 63%);
  background-size: 220% 100%;
  border-radius: var(--radius-md);
  animation: skeleton-sweep 1.3s linear infinite;
}

.empty-state { text-align: center; }
.empty-illustration { width: 64px; height: 64px; margin: 0 auto 12px; color: var(--ink-faint); }
.empty-state h3 { margin: 0; color: var(--ink); font-size: 20px; font-weight: 700; }
.empty-state p { max-width: 560px; margin: 7px auto 0; }
.empty-action { margin-top: 18px; padding: 8px 14px; color: var(--primary); background: var(--surface); border: 1px solid #d3e9f9; }
.empty-action:hover { background: var(--primary-soft); }

.mps-table-wrap { overflow: hidden; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-lg); box-shadow: none; }
.mps-table-wrap table { width: 100%; border-collapse: collapse; table-layout: auto; }
.mps-table-wrap th { padding: 12px 10px; color: var(--ink-muted); background: var(--canvas); border-bottom: 1px solid var(--hairline); font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap; }
.mps-table-wrap td { padding: 12px 10px; color: var(--ink-secondary); border-bottom: 1px solid var(--hairline); font-size: 14px; vertical-align: middle; }
.mps-table-wrap tbody tr:last-child td { border-bottom: 0; }
.mps-table-wrap tbody tr:hover { background: #fbfbfa; }
.mps-table-wrap .number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.mps-table-wrap td.number-cell { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 700; }

.table-order,
.table-style,
.identifier-value { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 700; overflow-wrap: anywhere; }
.table-style,
.style-value { color: var(--primary); }

/* 车缝状态徽章：贴纸色板语义——绿=完结、蓝=生产中、红=停止、橙=异常。 */
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status--not-started { color: var(--ink-secondary); background: var(--canvas); border-color: var(--hairline); }
.status--in-progress { color: var(--primary-active); background: var(--primary-soft); border-color: #d3e9f9; }
.status--complete { color: var(--green-deep); background: var(--green-soft); border-color: #cdebd3; }
.status--stopped { color: var(--danger); background: var(--danger-soft); border-color: #f5d4d4; }
.status--unexpected { color: var(--accent-orange); background: var(--orange-soft); border-color: #f3ddc9; }
.status--empty { min-width: 28px; padding: 0; background: transparent; border-color: transparent; }

.status-action { flex-wrap: wrap; gap: 8px; min-width: 250px; }
.status-select { min-height: 44px; flex: 1 1 120px; padding: 8px 34px 8px 10px; border-radius: var(--radius-xs); font-size: 14px; font-weight: 500; appearance: auto; }
.status-select:disabled { color: var(--ink-faint); background: var(--canvas); cursor: wait; }
.status-confirm { padding: 8px 12px; color: var(--on-primary); background: var(--primary); border: 1px solid var(--primary); }
.status-confirm:hover:not(:disabled) { background: var(--primary-active); border-color: var(--primary-active); }
.status-confirm:active:not(:disabled) { background: var(--primary-active); }
.row-feedback { width: 100%; margin: 0; color: var(--danger); font-size: 12px; font-weight: 500; }
.row-feedback[data-type="success"] { color: var(--green-deep); }

.mps-card-list { display: grid; grid-template-columns: 1fr; gap: 14px; }
.mps-card { overflow: hidden; background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius-lg); box-shadow: none; }
.mps-card-head { padding: 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--hairline); }
.mps-card-date { margin: 0; color: var(--ink); font-size: 17px; font-weight: 700; }
.mps-card-date-label { display: block; margin-top: 2px; color: var(--ink-muted); font-size: 13px; }
.group-badge { padding: 4px 9px; color: var(--primary); background: var(--primary-soft); border: 1px solid #d3e9f9; border-radius: 999px; font-size: 12px; font-weight: 600; }

.mps-identifiers { padding: 15px 16px 0; display: grid; gap: 10px; }
.identifier-label { display: block; color: var(--ink-muted); font-size: 12px; font-weight: 500; }
.identifier-value { display: block; margin-top: 2px; color: var(--ink); font-size: 16px; line-height: 1.35; }

.mps-metrics { margin: 15px 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.mps-metrics > div { min-width: 0; padding: 11px; background: var(--canvas); border: 1px solid var(--hairline); border-radius: var(--radius-md); }
.mps-metrics dt { color: var(--ink-muted); font-size: 12px; font-weight: 500; }
.mps-metrics dd { min-height: 28px; margin: 3px 0 0; color: var(--ink); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mps-metrics .metric-status dd { display: flex; align-items: center; font-family: inherit; font-size: 14px; }

.mps-card-action { margin: 0 16px 16px; padding-top: 14px; border-top: 1px solid var(--hairline); }
.mps-card-action h4 { margin: 0 0 9px; color: var(--ink-secondary); font-size: 14px; font-weight: 600; }
.mps-card-action .status-action { min-width: 0; }

.mps-batch-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px; margin-bottom: 14px; border: 1px solid var(--hairline); border-radius: var(--radius-md); background: var(--surface); }
.mps-select-label { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-size: 14px; }
.mps-select-label input { width: 20px; height: 20px; flex: 0 0 20px; accent-color: var(--primary); }
.mps-batch-target { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-left: auto; font-size: 14px; }
.mps-batch-feedback { padding: 12px 14px; background: var(--primary-soft); border-radius: var(--radius-md); overflow-wrap: anywhere; }
.mps-other-status { margin-top: 8px; }
.mps-other-status summary { min-height: 36px; padding: 8px 0; color: var(--ink-secondary); cursor: pointer; font-size: 13px; }
.quick-start { min-height: 44px; }
.mps-card .quick-start { width: 100%; }
.mps-card-head > div { min-width: 0; flex: 1; }
.mps-card-head .group-badge { flex-shrink: 0; }
.mps-identifiers { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mps-identifiers > div { min-width: 0; }
.identifier-value { overflow-wrap: anywhere; }
@media (max-width: 430px) {
  .mps-batch-target { margin-left: 0; width: 100%; }
  #mpsBatchSubmit { width: 100%; }
  .mps-card-head { gap: 8px; padding: 12px; }
  .mps-card-date { font-size: 15px; }
  .mps-card-date-label { font-size: 12px; }
  .group-badge { padding: 4px 6px; }
}

.toast {
  position: fixed;
  z-index: var(--z-toast);
  right: clamp(16px, 3vw, 36px);
  bottom: clamp(16px, 3vw, 30px);
  max-width: min(440px, calc(100vw - 32px));
  padding: 13px 15px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-hover);
  font-size: 14px;
  font-weight: 500;
}

.toast svg { width: 20px; height: 20px; flex: 0 0 auto; color: var(--accent-green); }
.toast[data-type="error"] svg { color: var(--danger); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes skeleton-sweep { to { background-position: -120% 0; } }

@media (min-width: 640px) and (max-width: 899px) {
  .mps-card-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .mps-card-list { display: none !important; }
  .mps-table-wrap:not([hidden]) { display: block; }
}

@media (max-width: 899px) {
  .mps-table-wrap { display: none !important; }
  .mps-card-list:not([hidden]) { display: grid; }
}

@media (max-width: 960px) {
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .header-inner {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "brand badge" "nav nav";
    gap: 8px 12px;
  }
  .brand-block { grid-area: brand; }
  .header-actions { display: contents; }
  .header-navigation { grid-area: nav; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .header-nav-link { min-width: 0; padding: 8px; }
  .live-badge { grid-area: badge; padding: 6px 9px; font-size: 11px; }
  .status-dot { display: none; }
  .brand-mark { width: 40px; height: 40px; }
  .page-shell { padding: 16px; }
  .filter-panel { padding: 17px; border-radius: var(--radius-lg); }
  .section-heading { align-items: flex-start; }
  .filter-grid { grid-template-columns: 1fr; gap: 13px; }
  .results-section { margin-top: 28px; }
  .skeleton-list div:nth-child(n+3) { display: none; }
}

@media (max-width: 430px) {
  .eyebrow { font-size: 10px; letter-spacing: .09em; }
  .header-nav-link { padding-inline: 6px; font-size: 12px; }
  .header-nav-link svg { width: 17px; height: 17px; }
  .section-heading h2 { font-size: 20px; }
  .order-count { font-size: 12px; }
  .mps-card-head { padding: 15px; }
  .mps-identifiers { padding: 14px 15px 0; }
  .mps-metrics { margin: 14px 15px; }
  .mps-card-action { margin: 0 15px 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
