:root {
  color-scheme: light;
  --ink-900: #0f172a;
  --ink-800: #1e293b;
  --ink-700: #334155;
  --ink-600: #475569;
  --ink-500: #64748b;
  --ink-300: #cbd5e1;
  --ink-200: #e2e8f0;
  --ink-100: #f1f5f9;
  --surface: #ffffff;
  --canvas: #f8fafc;
  --blue-700: #0369a1;
  --blue-800: #075985;
  --green-700: #047857;
  --amber-700: #b45309;
  --red-700: #b91c1c;
  --shadow-card: 0 12px 32px rgba(15, 23, 42, .07);
  --shadow-sheet: 0 -24px 70px rgba(15, 23, 42, .22);
  --radius-xl: 24px;
  --z-header: 40;
  --z-sheet: 60;
  --z-toast: 70;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); scroll-behavior: smooth; }

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

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

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(2, 132, 199, .42);
  outline-offset: 3px;
}

.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: #fff;
  background: var(--ink-900);
  border-radius: 8px;
  transform: translateY(-160%);
}

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

.app-header {
  position: sticky;
  z-index: var(--z-header);
  top: 0;
  color: #fff;
  background: rgba(15, 23, 42, .96);
  border-bottom: 1px solid rgba(255,255,255,.08);
  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,
.back-link,
.live-badge,
.field-label,
.filter-helper,
.loading-heading,
.refresh-button { display: flex; align-items: center; }

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

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #38bdf8;
  background: rgba(14, 165, 233, .12);
  border: 1px solid rgba(125, 211, 252, .24);
  border-radius: 12px;
}

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

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

.brand-block .eyebrow { color: #7dd3fc; }
.brand-block h1 { margin: 0; font-size: clamp(18px, 2.5vw, 22px); line-height: 1.2; letter-spacing: -.02em; }

.back-link {
  min-height: 44px;
  padding: 8px 12px;
  justify-content: center;
  gap: 6px;
  color: #e0f2fe;
  background: rgba(3, 105, 161, .3);
  border: 1px solid rgba(125, 211, 252, .34);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  transition: background-color 180ms ease, border-color 180ms ease;
}

.back-link svg { width: 19px; height: 19px; }
.back-link:hover { color: #fff; background: rgba(3, 105, 161, .5); border-color: rgba(125, 211, 252, .56); }
.back-link:active { background: rgba(7, 89, 133, .7); }

.live-badge {
  min-height: 36px;
  padding: 7px 12px;
  gap: 8px;
  color: #dbeafe;
  background: rgba(30, 41, 59, .88);
  border: 1px solid rgba(148, 163, 184, .18);
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  background: #38bdf8;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(56, 189, 248, .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(--ink-200);
  border-radius: var(--radius-xl);
  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); line-height: 1.25; letter-spacing: -.02em; }

.record-count {
  padding: 6px 10px;
  color: var(--ink-700);
  background: var(--ink-100);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.field-control { max-width: 520px; margin-top: 20px; display: block; }
.field-label { margin-bottom: 8px; gap: 7px; color: var(--ink-700); font-size: 14px; font-weight: 700; }
.field-label svg, .filter-helper svg { width: 19px; height: 19px; flex: 0 0 auto; color: var(--blue-700); }

.select-wrap { position: relative; display: block; }
.select-wrap select {
  width: 100%;
  min-height: 50px;
  padding: 10px 44px 10px 14px;
  color: var(--ink-900);
  background: var(--surface);
  border: 1px solid var(--ink-300);
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  appearance: none;
  cursor: pointer;
}

.select-wrap select:disabled { color: var(--ink-500); background: var(--ink-100); cursor: wait; }
.select-wrap > svg { position: absolute; top: 50%; right: 14px; width: 20px; height: 20px; color: var(--ink-500); pointer-events: none; transform: translateY(-50%); }

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

.refresh-button {
  min-height: 44px;
  padding: 8px 12px;
  justify-content: center;
  gap: 7px;
  color: var(--blue-800);
  background: #fff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
}

.refresh-button svg { width: 19px; height: 19px; }
.refresh-button:hover { background: #f0f9ff; }

.loading-state,
.empty-state {
  padding: clamp(24px, 5vw, 48px);
  color: var(--ink-600);
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: 18px;
  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-800); }
.loading-heading span { margin-top: 2px; font-size: 14px; }

.loading-spinner {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 3px solid #bae6fd;
  border-top-color: var(--blue-700);
  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, #f1f5f9 25%, #e2e8f0 37%, #f1f5f9 63%);
  background-size: 220% 100%;
  border-radius: 10px;
  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-300); }
.empty-state h3 { margin: 0; color: var(--ink-800); font-size: 20px; }
.empty-state p { max-width: 560px; margin: 7px auto 0; }

.history-card-list { display: grid; grid-template-columns: 1fr; gap: 14px; }
.history-card {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--ink-200);
  border-radius: 18px;
  box-shadow: var(--shadow-card);
}

.history-card-head { padding: 16px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--ink-200); }
.history-date { margin: 0; color: var(--ink-900); font-size: 17px; font-weight: 900; }
.history-time { display: block; margin-top: 2px; color: var(--ink-500); font-size: 13px; }
.history-card-badges { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.group-badge { padding: 5px 9px; color: var(--blue-800); background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 999px; font-size: 13px; font-weight: 800; }
.time-slot-badge { padding: 5px 9px; color: var(--green-700); background: #ecfdf5; border: 1px solid #a7f3d0; border-radius: 999px; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; font-weight: 800; white-space: nowrap; }

.history-identifiers { padding: 15px 16px 0; display: grid; gap: 10px; }
.identifier-label { display: block; color: var(--ink-500); font-size: 12px; font-weight: 700; }
.identifier-value { display: block; margin-top: 2px; color: var(--ink-900); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 16px; line-height: 1.35; overflow-wrap: anywhere; }
.style-value { color: var(--blue-800); font-weight: 800; }

.history-metrics { margin: 15px 16px 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.history-metrics > div { min-width: 0; padding: 11px; background: var(--ink-100); border: 1px solid var(--ink-200); border-radius: 12px; }
.history-metrics dt { color: var(--ink-500); font-size: 12px; font-weight: 700; }
.history-metrics dd { min-height: 28px; margin: 3px 0 0; color: var(--ink-900); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 19px; font-weight: 900; font-variant-numeric: tabular-nums; }
.history-metrics .actual dd { color: var(--green-700); }
.history-metrics .target dd { color: var(--blue-700); }
.history-metrics .difference dd { color: var(--amber-700); }

.history-card-action {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--ink-200);
}

.history-update-button {
  min-width: 72px;
  min-height: 44px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--blue-800);
  background: #f0f9ff;
  border: 1px solid #7dd3fc;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

.history-card-action .history-update-button { width: 100%; }
.history-update-button svg { width: 18px; height: 18px; flex: 0 0 auto; }
.history-update-button:hover { color: #fff; background: var(--blue-700); border-color: var(--blue-700); }
.history-update-button:active { background: var(--blue-800); }
.history-update-button:disabled {
  color: var(--ink-500);
  background: var(--ink-100);
  border-color: var(--ink-200);
  cursor: not-allowed;
}

.history-table-wrap { overflow: hidden; background: var(--surface); border: 1px solid var(--ink-200); border-radius: 16px; box-shadow: var(--shadow-card); }
.history-table-wrap table { width: 100%; border-collapse: collapse; table-layout: auto; }
.history-table-wrap th { padding: 12px 10px; color: var(--ink-600); background: var(--ink-100); border-bottom: 1px solid var(--ink-200); font-size: 12px; font-weight: 800; text-align: left; white-space: nowrap; }
.history-table-wrap td { padding: 13px 10px; color: var(--ink-800); border-bottom: 1px solid var(--ink-200); font-size: 13px; vertical-align: middle; }
.history-table-wrap tbody tr:last-child td { border-bottom: 0; }
.history-table-wrap tbody tr:hover { background: #f8fafc; }
.history-table-wrap .number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.history-table-wrap td.number-cell { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 800; }
.history-table-wrap .table-style { width: 1%; white-space: nowrap; }
.history-table-wrap .table-time-slot { white-space: nowrap; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 800; color: var(--green-700); }
.history-table-wrap .report-column { color: var(--green-700); }
.history-table-wrap .action-cell { width: 1%; text-align: center; white-space: nowrap; }
.table-order, .table-style { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 800; overflow-wrap: anywhere; }
.table-style { color: var(--blue-800); }

.sheet-layer {
  position: fixed;
  z-index: var(--z-sheet);
  inset: 0;
  display: grid;
  place-items: end center;
}

.sheet-scrim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  background: rgba(2, 6, 23, .58);
  border: 0;
  backdrop-filter: blur(3px);
  animation: fade-in 180ms ease-out both;
}

.history-update-sheet {
  position: relative;
  width: min(100%, 660px);
  max-height: min(94dvh, 820px);
  padding: 12px clamp(18px, 4vw, 30px) calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  background: #fff;
  border-radius: 26px 26px 0 0;
  box-shadow: var(--shadow-sheet);
  animation: sheet-in 240ms cubic-bezier(.2,.8,.2,1) both;
}

.sheet-handle {
  width: 44px;
  height: 5px;
  margin: 0 auto 15px;
  background: var(--ink-300);
  border-radius: 999px;
}

.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-icon {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--blue-700);
  background: #e0f2fe;
  border-radius: 13px;
}

.sheet-icon svg { width: 25px; height: 25px; }
.sheet-title-block { flex: 1; min-width: 0; }
.sheet-title-block h2 { margin: 0; font-size: 23px; line-height: 1.2; }

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--ink-600);
  background: var(--ink-100);
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.icon-button:hover { background: var(--ink-200); }
.icon-button svg { width: 22px; height: 22px; }

.update-context {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  background: var(--canvas);
  border: 1px solid var(--ink-200);
  border-radius: 14px;
}

.update-context > div { min-width: 0; padding: 10px 13px; }
.update-context > div:nth-child(odd) { border-right: 1px solid var(--ink-200); }
.update-context > div:nth-child(n+3) { border-top: 1px solid var(--ink-200); }
.update-context span { display: block; color: var(--ink-500); font-size: 12px; font-weight: 700; }
.update-context strong {
  display: block;
  margin-top: 2px;
  color: var(--ink-900);
  overflow-wrap: anywhere;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.update-context .context-accent.target { background: #f0f9ff; }
.update-context .context-accent.target strong { color: var(--blue-700); }
.update-context .context-accent.actual { background: #ecfdf5; }
.update-context .context-accent.actual strong { color: var(--green-700); }

.update-quantity-field { margin-top: 20px; }
.update-quantity-field > label { display: block; margin-bottom: 8px; font-weight: 850; }

.quantity-input-wrap {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  overflow: hidden;
  border: 2px solid var(--ink-300);
  border-radius: 14px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.quantity-input-wrap:focus-within {
  border-color: #0284c7;
  box-shadow: 0 0 0 4px rgba(2, 132, 199, .12);
}

.quantity-input-wrap button {
  min-height: 58px;
  display: grid;
  place-items: center;
  color: var(--ink-700);
  background: var(--ink-100);
  border: 0;
  cursor: pointer;
}

.quantity-input-wrap button:hover { background: var(--ink-200); }
.quantity-input-wrap button svg { width: 23px; height: 23px; }
.quantity-input-wrap input {
  width: 100%;
  min-width: 0;
  padding: 0 12px;
  color: var(--ink-900);
  background: #fff;
  border: 0;
  border-right: 1px solid var(--ink-200);
  border-left: 1px solid var(--ink-200);
  outline: 0;
  font-size: 27px;
  font-weight: 850;
  text-align: center;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
}

.quantity-input-wrap input::-webkit-inner-spin-button { appearance: none; }
.update-hint { margin: 8px 0 0; color: var(--ink-500); font-size: 12px; }
.update-comparison {
  min-height: 24px;
  margin: 10px 0 0;
  padding: 8px 10px;
  color: var(--ink-700);
  background: var(--ink-100);
  border-radius: 9px;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.field-error { min-height: 22px; margin: 4px 0 0; color: var(--red-700); font-size: 13px; font-weight: 700; }
.sheet-actions { margin-top: 10px; display: grid; grid-template-columns: minmax(100px, .7fr) minmax(170px, 1.3fr); gap: 10px; }
.secondary-button,
.primary-button { min-height: 54px; padding: 12px 16px; border-radius: 12px; font-weight: 850; cursor: pointer; }
.secondary-button { color: var(--ink-700); background: #fff; border: 1px solid var(--ink-300); }
.secondary-button:hover { background: var(--ink-100); }
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: #fff;
  background: var(--blue-700);
  border: 1px solid var(--blue-700);
}

.primary-button:hover { background: var(--blue-800); border-color: var(--blue-800); }
.primary-button:disabled,
.secondary-button:disabled,
.quantity-input-wrap button:disabled,
.icon-button:disabled { cursor: wait; opacity: .64; }
.button-spinner {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}

.submit-status {
  margin: 10px 0 0;
  padding: 9px 11px;
  color: var(--blue-800);
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 750;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: var(--z-toast);
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  min-height: 50px;
  width: min(calc(100% - 32px), 420px);
  padding: 12px 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: #fff;
  background: var(--ink-900);
  border-radius: 12px;
  box-shadow: 0 16px 44px rgba(15,23,42,.28);
  font-weight: 750;
  text-align: center;
  animation: toast-in 200ms ease-out both;
}

.toast svg { width: 21px; height: 21px; color: #6ee7b7; flex: 0 0 auto; }
.toast[data-type="error"] svg { color: #fca5a5; }

[hidden] { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes skeleton-sweep { to { background-position: -120% 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { opacity: .6; transform: translateY(42px); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

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

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

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

@media (max-width: 700px) {
  .header-inner { min-height: 68px; }
  .brand-mark { width: 40px; height: 40px; }
  .header-actions { gap: 7px; }
  .back-link { min-width: 44px; padding: 8px 10px; }
  .live-badge { padding: 6px 9px; font-size: 11px; }
  .status-dot { display: none; }
  .page-shell { padding: 16px; }
  .filter-panel { padding: 17px; border-radius: 18px; }
  .section-heading { align-items: flex-start; }
  .results-section { margin-top: 28px; }
  .skeleton-list div:nth-child(n+3) { display: none; }
  .history-update-sheet { width: 100%; }
}

@media (max-width: 430px) {
  .back-link span { display: none; }
  .live-badge { max-width: 84px; white-space: normal; line-height: 1.15; text-align: center; }
  .section-heading h2 { font-size: 20px; }
  .record-count { font-size: 12px; }
  .update-context { grid-template-columns: 1fr; }
  .update-context > div:nth-child(odd) { border-right: 0; }
  .update-context > div + div { border-top: 1px solid var(--ink-200); }
  .sheet-actions { grid-template-columns: .78fr 1.22fr; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .history-update-sheet { max-height: 100dvh; border-radius: 18px 18px 0 0; }
  .update-context { margin-top: 12px; }
  .update-quantity-field { margin-top: 14px; }
}

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