:root {
  color-scheme: light;
  --ink: #10233f;
  --muted: #64748b;
  --line: #dce4ee;
  --paper: #ffffff;
  --canvas: #f3f6fa;
  --nav: #0b1f38;
  --blue: #1769e0;
  --blue-soft: #e9f2ff;
  --green: #138a61;
  --amber: #c77b15;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); color: var(--ink); }
button { font: inherit; }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 38px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); box-shadow: 0 24px 60px rgba(16,35,63,.12); }
.login-mark { margin-bottom: 24px; color: #fff; }
.login-card h1 { margin-bottom: 12px; }
.login-note { color: var(--muted); }
.login-error { margin: 18px 0; padding: 11px 13px; border-radius: 8px; background: #fff0f0; color: #b42318; font-weight: 700; }
.login-form { display: grid; gap: 17px; margin-top: 24px; }
.login-form label { display: grid; gap: 7px; font-size: .86rem; font-weight: 800; }
.login-form input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; font: inherit; color: var(--ink); background: #fff; }
.login-form input:focus { outline: 3px solid rgba(23,105,224,.14); border-color: var(--blue); }
.login-form .primary { margin-top: 5px; }
.mli-control-block { margin-top: 28px; padding-top: 26px; border-top: 1px solid var(--line); }
.mli-master-row { margin: 18px 0; padding: 16px 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.mli-master-row strong, .mli-master-row small { display: block; }
.mli-master-row small { margin-top: 4px; color: var(--muted); }
.switch { position: relative; display: inline-flex; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { width: 48px; height: 27px; border-radius: 999px; background: #b8c3d1; cursor: pointer; transition: .18s ease; position: relative; }
.switch span::after { content: ""; position: absolute; width: 21px; height: 21px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(16,35,63,.25); transition: .18s ease; }
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { transform: translateX(21px); }
.switch input:disabled + span { opacity: .55; cursor: wait; }
.switch.compact span { width: 40px; height: 23px; }
.switch.compact span::after { width: 17px; height: 17px; }
.switch.compact input:checked + span::after { transform: translateX(17px); }
.notice.safe { border-left-color: var(--green); background: #edf9f4; color: #17664d; }
.mli-sku-table { min-width: 1900px; }
.mli-sku-table th small { color: var(--muted); font-weight: 600; white-space: nowrap; }
.mli-quantity-input { width: 68px; margin-top: 6px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; }
.mli-actions { min-width: 150px; }
.mli-actions button { display: block; width: 100%; margin: 4px 0; }
.shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 18px 20px; background: var(--nav); color: #fff; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 28px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: var(--blue); font-weight: 800; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; letter-spacing: .01em; }
.brand small { margin-top: 2px; color: #9fb0c7; font-size: .78rem; }
nav { display: grid; gap: 5px; }
.nav-item { width: 100%; border: 0; border-radius: 9px; background: transparent; color: #b8c5d6; display: flex; justify-content: space-between; align-items: center; padding: 12px 13px; cursor: pointer; text-align: left; }
.nav-item:hover { background: #122e50; color: #fff; }
.nav-item.active { background: var(--blue); color: #fff; box-shadow: 0 10px 24px rgba(23,105,224,.22); }
.nav-item small { font-size: .72rem; opacity: .7; }
.sidebar-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255,255,255,.12); color: #aebbd0; font-size: .78rem; display: flex; gap: 8px; align-items: center; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #2dd4a3; box-shadow: 0 0 0 4px rgba(45,212,163,.12); }
main { min-width: 0; padding: 34px 38px 48px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 26px; }
.eyebrow { margin: 0 0 6px; color: var(--blue); text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; font-weight: 800; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.75rem, 3vw, 2.4rem); letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 1.15rem; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.time { color: var(--muted); font-size: .82rem; }
.secondary { border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); padding: 9px 15px; cursor: pointer; font-weight: 700; }
.top-actions a.secondary { text-decoration: none; font-size: .85rem; }
.secondary:hover { border-color: var(--blue); color: var(--blue); }
.primary { border: 1px solid var(--blue); border-radius: 8px; background: var(--blue); color: #fff; padding: 10px 16px; cursor: pointer; font-weight: 800; }
.primary:hover { background: #0f5dcc; }
.primary:disabled, .secondary:disabled { opacity: .58; cursor: wait; }
.view { display: none; }
.view.active { display: block; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.metric, .panel, .empty-panel { border: 1px solid var(--line); background: var(--paper); border-radius: 13px; }
.metric { padding: 19px 20px; min-height: 116px; }
.metric-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.metric h2 { font-size: .95rem; }
.metric-state { margin: 20px 0 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -.03em; }
.metric small { display: block; margin-top: 5px; color: var(--muted); }
.connection-dot { width: 10px; height: 10px; border-radius: 50%; background: #b8c3d1; }
.connection-dot.ready { background: var(--green); box-shadow: 0 0 0 4px rgba(19,138,97,.12); }
.grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr); gap: 16px; }
.panel { padding: 22px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 20px; }
.pill { border-radius: 999px; background: #edf1f6; color: #4b5d73; padding: 5px 10px; font-size: .74rem; font-weight: 700; }
.pill.accent { background: var(--blue-soft); color: var(--blue); }
.warehouse-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.warehouse { border: 1px solid var(--line); border-radius: 9px; padding: 13px; }
.warehouse strong, .warehouse small { display: block; }
.warehouse strong { font-size: .94rem; }
.warehouse small { color: var(--muted); margin-top: 4px; font-size: .76rem; }
.steps { margin: 0; padding: 0; list-style: none; display: grid; gap: 16px; }
.steps li { display: grid; grid-template-columns: 30px 1fr; gap: 11px; align-items: center; color: var(--muted); }
.steps li > span { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 50%; display: grid; place-items: center; font-size: .75rem; font-weight: 800; }
.steps strong, .steps small { display: block; }
.steps strong { color: var(--ink); font-size: .88rem; }
.steps small { margin-top: 2px; font-size: .76rem; }
.steps .done > span { background: var(--green); border-color: var(--green); color: white; }
.steps .current > span { background: var(--blue); border-color: var(--blue); color: white; }
.cache-panel { margin-top: 16px; }
.cache-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.cache-item { padding: 15px; border-right: 1px solid var(--line); }
.cache-item:last-child { border-right: 0; }
.cache-item strong, .cache-item small { display: block; }
.cache-item strong { font-size: .86rem; }
.cache-item small { margin-top: 6px; color: var(--muted); font-size: .74rem; }
.skeleton { background: linear-gradient(100deg, #fff 20%, #f0f4f8 40%, #fff 60%); background-size: 200% 100%; animation: shine 1.2s infinite; }
@keyframes shine { to { background-position-x: -200%; } }
.empty-panel { min-height: 440px; display: grid; place-content: center; text-align: center; padding: 32px; }
.empty-index { color: var(--blue); font-weight: 800; letter-spacing: .12em; }
.empty-panel h2 { margin: 12px 0 8px; font-size: 1.6rem; }
.empty-panel p { max-width: 460px; margin-bottom: 0; color: var(--muted); }
.routing-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.routing-controls { display: flex; align-items: center; gap: 12px; }
.routing-controls label { color: var(--muted); font-size: .86rem; }
.routing-controls input { width: 64px; margin: 0 4px; border: 1px solid var(--line); border-radius: 7px; padding: 9px; font: inherit; color: var(--ink); }
.notice { margin: 18px 0 0; border-left: 3px solid var(--blue); background: var(--blue-soft); color: #33567f; padding: 10px 12px; font-size: .82rem; }
.routing-summary { display: flex; flex-wrap: wrap; gap: 22px; padding: 16px 2px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.inventory-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.inventory-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-top: 18px; color: #42536a; font-size: .86rem; font-weight: 700; }
.inventory-filters label { display: inline-flex; align-items: center; gap: 7px; }
.inventory-filters input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--blue); }
.search-field input { width: min(280px, 54vw); border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; font: inherit; color: var(--ink); }
.inventory-summary { display: flex; flex-wrap: wrap; gap: 22px; padding: 16px 2px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.inventory-table { min-width: 1380px; }
.inventory-table th[data-sort], .replenishment-table th[data-replenishment-sort] { cursor: pointer; user-select: none; }
.inventory-table th[data-sort]::after, .replenishment-table th[data-replenishment-sort]::after { content: " ⇅"; color: #9aa9bb; }
.inventory-table th.sorted[data-direction="asc"]::after, .replenishment-table th.sorted[data-direction="asc"]::after { content: " ↑"; color: var(--blue); }
.inventory-table th.sorted[data-direction="desc"]::after, .replenishment-table th.sorted[data-direction="desc"]::after { content: " ↓"; color: var(--blue); }
.inventory-table td small { display: block; margin-top: 3px; color: var(--muted); }
.number-cell { text-align: right; font-variant-numeric: tabular-nums; }
.old-stock { color: #b44d38; font-weight: 800; background: #fff5f2; }
.target-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.target-strip span { border-radius: 999px; background: #edf3fb; color: #395875; padding: 6px 10px; font-size: .76rem; font-weight: 800; }
.needs-stock td { background: #fff7f5; }
.needs-stock .ship-cell { color: #b42318; font-weight: 900; }
.credential-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 16px; }
.credential-item { display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 9px; padding: 13px; }
.credential-item strong, .credential-item small { display: block; }
.credential-item strong { font-size: .84rem; }
.credential-item small { color: var(--muted); margin-top: 3px; font-size: .74rem; }
.credential-item.pending { background: #fffaf1; }
.mli-table { min-width: 1050px; }
.matched { color: var(--green); font-weight: 800; }
.unmatched { color: var(--amber); font-weight: 800; }
.rule-form { display: flex; align-items: end; flex-wrap: wrap; gap: 14px; margin: 18px 0; }
.rule-form label { display: grid; gap: 6px; color: #42536a; font-size: .82rem; font-weight: 800; }
.rule-form input, .rule-form select { min-width: 190px; border: 1px solid var(--line); border-radius: 7px; background: white; color: var(--ink); padding: 10px 11px; font: inherit; }
.form-status { color: var(--muted); font-size: .82rem; min-height: 1.2em; }
.rule-table { min-width: 760px; }
.table-action { border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--blue); padding: 6px 10px; cursor: pointer; font-weight: 700; margin-right: 7px; }
.table-action.danger { color: #b42318; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; min-width: 950px; }
th, td { border-bottom: 1px solid var(--line); padding: 12px 13px; text-align: left; vertical-align: top; font-size: .82rem; }
th { background: #f5f8fc; color: #42536a; white-space: nowrap; }
td { color: #253a56; }
tbody tr:last-child td { border-bottom: 0; }
.table-empty { text-align: center; padding: 46px; color: var(--muted); }
.order-status { color: var(--amber); font-weight: 700; white-space: nowrap; }
.distribution-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.distribution-actions { display: flex; flex-wrap: wrap; gap: 9px; justify-content: flex-end; }
.distribution-controls { display: grid; grid-template-columns: auto minmax(210px, 1fr) auto auto; gap: 16px; align-items: end; margin-top: 18px; }
.distribution-controls > label, .distribution-controls fieldset { color: #42536a; font-size: .82rem; font-weight: 800; }
.distribution-controls > label { display: grid; gap: 6px; }
.distribution-controls input[type="number"], .distribution-controls input[type="search"] { border: 1px solid var(--line); border-radius: 7px; padding: 9px 10px; font: inherit; color: var(--ink); }
.distribution-controls input[type="number"] { width: 112px; }
.distribution-controls fieldset { margin: 0; padding: 7px 11px 9px; border: 1px solid var(--line); border-radius: 8px; display: flex; gap: 12px; }
.distribution-controls legend { padding: 0 5px; color: var(--muted); font-size: .72rem; }
.distribution-controls fieldset label, .warehouse-pick label { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.distribution-controls input[type="checkbox"], .distribution-controls input[type="radio"], .warehouse-pick input[type="checkbox"] { accent-color: var(--blue); }
.warehouse-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 15px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px; color: #42536a; font-size: .8rem; }
.warehouse-pick > strong { margin-right: 2px; color: var(--ink); }
.warehouse-pick .cutoff-time { margin-left: auto; }
.warehouse-pick .cutoff-time + .cutoff-time { margin-left: 0; }
.warehouse-pick input[type="time"] { width: 104px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 7px; color: var(--ink); font: inherit; }
.performance-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.performance-card { border: 1px solid var(--line); border-left: 4px solid var(--amber); border-radius: 9px; padding: 13px 15px; }
.performance-card.passed { border-left-color: var(--green); background: #f5fcf9; }
.performance-card.failed { background: #fffaf4; }
.performance-card > div { display: flex; justify-content: space-between; gap: 12px; }
.performance-card span { color: var(--amber); font-size: .76rem; font-weight: 800; }
.performance-card.passed span { color: var(--green); }
.performance-card p { margin: 8px 0 4px; color: #253a56; font-size: .85rem; font-weight: 800; }
.performance-card small { color: var(--muted); font-size: .74rem; }
.performance-delta { margin-left: 10px; font-weight: 800; }
.performance-delta.positive { color: var(--green); }
.performance-delta.negative { color: #b42318; }
.distribution-table { min-width: 1420px; }
.distribution-table th[data-distribution-sort] { cursor: pointer; user-select: none; }
.distribution-table th[data-distribution-sort]::after { content: " ⇅"; color: #9aa9bb; }
.distribution-table th.sorted[data-direction="asc"]::after { content: " ↑"; color: var(--blue); }
.distribution-table th.sorted[data-direction="desc"]::after { content: " ↓"; color: var(--blue); }
.distribution-table td small { display: block; margin-top: 3px; color: var(--amber); }

@media (max-width: 980px) {
  .shell { grid-template-columns: 84px minmax(0, 1fr); }
  .sidebar { padding-inline: 12px; }
  .brand { justify-content: center; padding-inline: 0; }
  .brand div, .nav-item span, .nav-item small, .sidebar-foot span:last-child { display: none; }
  .nav-item { justify-content: center; min-height: 43px; }
  .nav-item::before { content: attr(data-view); width: 2ch; overflow: hidden; text-transform: uppercase; font-size: .75rem; font-weight: 800; }
  main { padding: 28px 24px 40px; }
  .grid { grid-template-columns: 1fr; }
  .distribution-controls { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
  .shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
  .brand { justify-content: flex-start; padding: 0 0 12px; }
  .brand div { display: block; }
  nav { display: flex; overflow-x: auto; padding-bottom: 3px; }
  .nav-item { min-width: max-content; padding: 10px 12px; }
  .nav-item::before { display: none; }
  .nav-item span { display: block; }
  .sidebar-foot { display: none; }
  main { padding: 22px 16px 34px; }
  .topbar { align-items: flex-start; }
  .time { display: none; }
  .metrics { grid-template-columns: 1fr; }
  .warehouse-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cache-list { grid-template-columns: 1fr 1fr; }
  .cache-item:nth-child(2) { border-right: 0; }
  .cache-item { border-bottom: 1px solid var(--line); }
  .routing-toolbar { align-items: flex-start; flex-direction: column; }
  .routing-controls { width: 100%; justify-content: space-between; }
  .inventory-toolbar { align-items: flex-start; }
  .credential-grid { grid-template-columns: 1fr; }
  .distribution-heading { align-items: flex-start; flex-direction: column; }
  .distribution-actions { justify-content: flex-start; }
  .distribution-controls, .performance-grid { grid-template-columns: 1fr; }
  .warehouse-pick .cutoff-time { margin-left: 0; }
}
