:root {
  --ink: #182536;
  --ink-soft: #536174;
  --muted: #7b8798;
  --paper: #ffffff;
  --canvas: #f4f6f8;
  --line: #d9e0e8;
  --line-strong: #c6d0dc;
  --navy: #193a5b;
  --indigo: #315e96;
  --indigo-pale: #edf3fb;
  --success: #22765f;
  --success-pale: #eaf6f1;
  --warning: #996a22;
  --warning-pale: #fff6df;
  --danger: #a23942;
  --danger-pale: #fff0f1;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(25, 45, 68, .06);
  --mono: "Cascadia Code", "Consolas", monospace;
  --sans: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.55; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }

.topbar { height: 76px; padding: 0 5vw; display: flex; align-items: center; justify-content: space-between; background: var(--paper); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 12px; min-height: 44px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--navy); color: var(--navy); font-family: var(--mono); font-size: 12px; font-weight: 700; letter-spacing: -.06em; }
.brand-kicker, .section-label, .eyebrow { display: block; font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .12em; color: var(--muted); }
.brand-name { display: block; margin-top: 1px; font-size: 15px; font-weight: 650; letter-spacing: .02em; }
.brand-version { margin-left: 8px; color: var(--muted); font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .03em; white-space: nowrap; }
.topnav { display: flex; align-items: center; gap: 14px; }
.external-link { min-height: 40px; display: inline-flex; align-items: center; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink-soft); background: var(--paper); font-size: 13px; transition: color 180ms ease, border-color 180ms ease, background 180ms ease; }
.external-link:hover { color: var(--navy); border-color: var(--line-strong); background: #f7f9fb; }
.ai-placeholder { min-height: 40px; padding: 0 13px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: #fafbfc; font-size: 13px; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--line-strong); vertical-align: 1px; }

.page-shell { width: min(1180px, 90vw); margin: 0 auto; padding: 28px 0 80px; }
.intro { display: block; margin-bottom: 30px; }
h1, h2, p { margin: 0; }
h1 { max-width: none; margin-top: 0; color: var(--ink); font-size: clamp(30px, 4vw, 46px); line-height: 1.12; letter-spacing: -.045em; font-weight: 720; white-space: nowrap; }
.intro-copy { max-width: none; margin-top: 12px; color: var(--ink-soft); font-size: 16px; }

.workflow-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, .8fr); gap: 18px; align-items: stretch; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.upload-panel, .status-panel, .results-panel { padding: 26px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.section-label { color: var(--indigo); }
h2 { margin-top: 3px; font-size: 22px; letter-spacing: -.025em; }
.panel-meta { color: var(--muted); font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.dropzone { min-height: 214px; margin-top: 24px; padding: 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px dashed var(--line-strong); border-radius: 8px; color: var(--ink-soft); background: #fbfcfd; text-align: center; transition: border-color 180ms ease, background 180ms ease; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.dragover { border-color: var(--indigo); background: var(--indigo-pale); outline: none; }
.upload-icon { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 12px; color: var(--indigo); background: var(--indigo-pale); border-radius: 50%; }
.upload-icon svg { width: 21px; height: 21px; }
.dropzone strong { color: var(--ink); font-size: 17px; }
.dropzone span { margin-top: 5px; font-size: 13px; }
.dropzone u { color: var(--indigo); text-underline-offset: 3px; }
.file-list { min-height: 36px; margin-top: 15px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.empty-list { color: var(--muted); font-size: 13px; }
.file-chip { display: inline-flex; align-items: center; gap: 9px; max-width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fbfcfd; font-size: 13px; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { width: 24px; height: 24px; padding: 0; border: 0; color: var(--muted); background: transparent; border-radius: 4px; }
.file-chip button:hover { color: var(--danger); background: var(--danger-pale); }
.upload-actions { display: flex; gap: 10px; margin-top: 18px; }
.button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 17px; border: 1px solid transparent; border-radius: 7px; font-weight: 650; font-size: 14px; transition: background 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease; }
.button:focus-visible, .ai-placeholder:focus-visible, .external-link:focus-visible, .file-chip button:focus-visible { outline: 3px solid rgba(49, 94, 150, .25); outline-offset: 2px; }
.button-primary { color: #fff; background: var(--navy); box-shadow: 0 3px 0 #0f2943; }
.button-primary:not(:disabled) .button-icon { color: #fff; }
.button-primary:not(:disabled) .button-icon img { filter: brightness(0) invert(1); }
.button-primary:disabled .button-icon img, .button-secondary:disabled .button-icon img { filter: grayscale(1); opacity: .55; }
.button-secondary:not(:disabled) .button-icon img { filter: brightness(0) saturate(100%) invert(20%) sepia(19%) saturate(1160%) hue-rotate(169deg) brightness(87%) contrast(91%); }
.formula-cell span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.button-primary:hover:not(:disabled) { background: #244d73; }
.button-primary:disabled, .button-secondary:disabled { color: #9aa5b3; background: #e8edf2; border-color: #e8edf2; box-shadow: none; }
.button-secondary { color: var(--navy); background: var(--indigo-pale); border-color: #c7d8ec; }
.button-secondary:hover:not(:disabled) { background: #dce9f6; border-color: #afc7e2; }
.button-quiet { color: var(--ink-soft); background: transparent; border-color: var(--line); }
.button-quiet:hover:not(:disabled) { color: var(--ink); background: #f7f9fb; border-color: var(--line-strong); }
.button-icon { width: 18px; height: 18px; display: inline-grid; place-items: center; flex: 0 0 18px; }
.button-icon img { display: block; width: 18px; height: 18px; object-fit: contain; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin-top: 25px; }
.summary-item { min-height: 91px; padding: 15px; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--line); border-radius: 7px; background: #fbfcfd; }
.summary-item.wide { grid-column: span 2; min-height: 116px; background: var(--indigo-pale); border-color: #d6e2f0; }
.summary-item span, .summary-item small { color: var(--muted); font-size: 12px; }
.summary-item strong { color: var(--navy); font-family: var(--mono); font-size: 27px; line-height: 1; }
.summary-item small { margin-top: -3px; }
.status-note { display: flex; gap: 9px; margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); color: var(--ink-soft); font-size: 13px; }
.note-mark { flex: 0 0 auto; width: 19px; height: 19px; display: grid; place-items: center; color: var(--indigo); border: 1px solid #b9cde4; border-radius: 50%; font-family: var(--mono); font-size: 11px; }
.pill { padding: 5px 9px; border-radius: 999px; font-family: var(--mono); font-size: 11px; font-weight: 700; }
.pill-idle { color: var(--muted); background: #eef1f4; }
.pill-ready { color: var(--indigo); background: var(--indigo-pale); }
.pill-success { color: var(--success); background: var(--success-pale); }
.pill-warning { color: var(--warning); background: var(--warning-pale); }

.results-panel { margin-top: 18px; }
.results-heading { align-items: center; }
.results-actions { display: flex; gap: 10px; flex: 0 0 auto; }
.results-empty { min-height: 198px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.empty-rule { width: 42px; height: 1px; margin-bottom: 17px; background: var(--line-strong); }
.results-empty p { color: var(--ink-soft); font-size: 15px; font-weight: 650; }
.results-empty span { margin-top: 6px; font-size: 13px; }
.results-table-wrap { margin-top: 23px; overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; }
.results-table { width: 100%; min-width: 760px; border-collapse: collapse; text-align: left; font-size: 13px; }
.results-table th { padding: 12px 13px; color: var(--muted); background: #f6f8fa; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.results-table td { padding: 13px; border-top: 1px solid var(--line); vertical-align: bottom; }
.results-table tr:hover td { background: #fbfcfe; }
.results-table .num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.order-cell strong, .fabric-cell strong { display: block; color: var(--ink); }
.order-cell span, .fabric-cell span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.meter-cell { color: var(--navy); font-size: 18px; font-weight: 750; }
.additions { color: var(--warning); font-size: 12px; line-height: 1.45; }
.alert-box { margin-top: 15px; padding: 12px 14px; border: 1px solid #f0d999; border-radius: 7px; color: var(--warning); background: var(--warning-pale); font-size: 13px; }
.error-box { margin-top: 15px; padding: 12px 14px; border: 1px solid #efc4c8; border-radius: 7px; color: var(--danger); background: var(--danger-pale); font-size: 13px; }

.rules-section { display: grid; grid-template-columns: .6fr 1.4fr; gap: 50px; padding: 46px 4px 0; }
.rules-section h2 { font-size: 25px; }
.rule-list { border-top: 1px solid var(--line-strong); }
.rule-row { min-height: 62px; display: grid; grid-template-columns: 42px 150px 1fr; gap: 16px; align-items: center; border-bottom: 1px solid var(--line); font-size: 13px; }
.rule-index { color: var(--indigo); font-family: var(--mono); font-size: 11px; font-weight: 700; }
.rule-row strong { font-size: 14px; }
.rule-row span:last-child { color: var(--ink-soft); }
.muted { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 10; max-width: min(500px, 88vw); padding: 12px 16px; color: #fff; background: var(--ink); border-radius: 7px; box-shadow: var(--shadow); opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.history-page { padding-top: 42px; }
.history-panel { padding: 26px; }
.history-toolbar { margin-top: 20px; }
.history-search { display: block; max-width: 460px; }
.history-search input { width: 100%; min-height: 42px; padding: 0 13px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: #fbfcfd; outline: none; }
.history-search input:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(49, 94, 150, .12); background: var(--paper); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.history-content { margin-top: 23px; }
.history-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 7px; }
.history-table { width: 100%; min-width: 860px; border-collapse: collapse; text-align: left; font-size: 13px; }
.history-table th { padding: 12px 13px; color: var(--muted); background: #f6f8fa; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.history-table td { padding: 14px 13px; border-top: 1px solid var(--line); vertical-align: top; }
.history-table tr:hover td { background: #fbfcfe; }
.history-empty { min-height: 220px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; color: var(--muted); text-align: center; }
.history-empty strong { color: var(--ink-soft); font-size: 15px; }
.history-error strong { color: var(--danger); }

@media (max-width: 780px) {
  .topbar { height: auto; min-height: 70px; padding: 12px 5vw; align-items: flex-start; gap: 14px; }
  .topnav { gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
  .external-link { min-height: 38px; padding: 0 9px; font-size: 12px; }
  .ai-placeholder { font-size: 12px; }
  .page-shell { width: min(92vw, 640px); padding-top: 28px; }
  .intro { margin-bottom: 26px; }
  h1 { font-size: clamp(30px, 9vw, 46px); white-space: normal; }
  .workflow-grid, .rules-section { grid-template-columns: 1fr; gap: 15px; }
  .rules-section { padding-top: 34px; gap: 25px; }
  .rule-row { grid-template-columns: 34px 1fr; gap: 10px; padding: 12px 0; }
  .rule-row span:last-child { grid-column: 2; }
  .upload-panel, .status-panel, .results-panel { padding: 20px; }
  .history-panel { padding: 20px; }
  .results-heading { align-items: flex-start; flex-direction: column; }
  .results-actions { width: 100%; flex-direction: column; }
  .results-heading .button { width: 100%; }
}

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