:root {
  --ink: #0f172a;
  --muted: #64748b;
  --paper: #f1f5f9;
  --panel: #ffffff;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-active: #1e3a8a;
  --accent-2: #0f766e;
  --ok: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 20px rgba(15, 23, 42, 0.05);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --display: "Plus Jakarta Sans", system-ui, sans-serif;
  --text: 0.875rem;
  --text-sm: 0.8125rem;
  --text-xs: 0.75rem;
  --h1: 1.45rem;
  --h2: 1rem;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  font-size: var(--text);
  line-height: 1.35;
  color: var(--ink);
  background:
    radial-gradient(1000px 480px at 8% -8%, rgba(29, 78, 216, 0.08) 0%, transparent 55%),
    radial-gradient(900px 420px at 100% 0%, rgba(15, 118, 110, 0.07) 0%, transparent 50%),
    linear-gradient(180deg, #f8fafc 0%, var(--paper) 45%, #eef2f7 100%);
}

code, .mono { font-family: var(--mono); font-size: 0.92em; }

.shell { max-width: 1600px; margin: 0 auto; padding: 16px 18px 40px; }

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px 24px;
  flex-wrap: wrap;
  margin: 0 0 20px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.top-main {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1 1 auto;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  padding-right: 4px;
}
.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.brand strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.25;
}
.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 3px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid transparent;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.nav-link .nav-icon {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  opacity: 0.85;
}
.nav-link:hover { color: var(--ink); background: rgba(255, 255, 255, 0.8); }
.nav-link:hover .nav-icon { opacity: 1; }
.nav-link.active {
  color: var(--accent);
  background: #fff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}
.nav-link.active .nav-icon { opacity: 1; }
.metric-link { text-decoration: none; color: inherit; display: block; }
.metric-link article { height: 100%; transition: border-color 0.15s ease; }
.metric-link:hover article { border-color: #cbd5e1; }
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px 14px;
  margin-top: 10px;
}
.pager-size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
}
.pager-size-select {
  min-width: 4.5rem;
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
}
.pager-range { margin-right: auto; }
.pager-nav {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.role-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.role-badge.role-admin {
  background: #dbeafe;
  color: #1d4ed8;
}
.role-badge.role-readonly {
  background: #e2e8f0;
  color: #475569;
}
.who .role-badge { margin-left: 8px; }
.user-password-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.user-password-form input[type="password"] {
  min-width: 160px;
  max-width: 220px;
  font-size: var(--text-xs);
  padding: 5px 8px;
}
.user-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}
.user-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}
tr.is-disabled-user td { opacity: 0.65; }
.user-create { align-items: end; }
.btn.disabled { opacity: 0.45; pointer-events: none; }
.mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #2563eb 0%, var(--accent) 100%);
  color: #f8fafc;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  box-shadow: 0 2px 8px rgba(29, 78, 216, 0.28);
  flex: 0 0 auto;
}
.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: 0 0 auto;
  margin-left: auto;
}
.who {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
}
.top-signout {
  padding: 7px 12px;
  font-size: 0.8125rem;
  background: #fff;
}
.top-signout:hover {
  border-color: #cbd5e1;
  background: var(--paper);
}

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: 7px; padding: 6px 11px;
  font: 600 var(--text-sm) var(--sans); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn:hover { border-color: #cbd5e1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #f8fafc; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; }

.login-wrap { min-height: 70vh; display: grid; place-items: center; }
.login-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.login-card { width: min(400px, 100%); padding: 22px; }
.login-card h1, .dash h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: var(--h1);
  letter-spacing: -0.03em;
  margin: 0 0 4px;
}
.panel h2 {
  font-family: var(--display);
  font-weight: 700;
  font-size: var(--h2);
  letter-spacing: -0.02em;
  margin: 0;
}
.lede { color: var(--muted); margin: 0 0 12px; line-height: 1.4; font-size: var(--text-sm); }
.stack { display: grid; gap: 10px; }
label { display: grid; gap: 4px; font-weight: 600; font-size: var(--text-sm); }
input, select {
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px;
  font: 500 var(--text) var(--sans); background: #fff;
}
select { cursor: pointer; }
.filters {
  display: block;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(248, 250, 252, 0.9);
}
/* Legacy filter forms (History, Users) keep the old grid. */
.filters:not(:has(.filters-bar)) {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.4fr auto;
  gap: 8px;
  align-items: end;
}
.filters-bar {
  display: flex;
  flex-wrap: nowrap;
  align-items: end;
  gap: 10px 12px;
  width: 100%;
}
.filters-search {
  flex: 0 1 520px;
  min-width: 320px;
  max-width: 600px;
  display: grid;
  gap: 4px;
}
.filters-controls {
  flex: 1 1 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: end;
  gap: 8px;
  padding-left: 12px;
  margin-left: 2px;
  border-left: 1px solid var(--line);
  min-width: 0;
}
.filters-select {
  display: grid;
  gap: 4px;
  min-width: 140px;
  flex: 0 1 180px;
}
.filters-select select {
  width: 100%;
  max-width: 220px;
}
.search-field {
  display: flex;
  align-items: stretch;
  gap: 0;
  width: 100%;
}
.search-field input {
  flex: 1;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  min-width: 0;
}
.search-submit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 38px;
  min-width: 38px;
  padding: 7px 8px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 0;
  background: var(--accent);
  border-color: var(--accent);
  color: #f8fafc;
}
.search-submit:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}
.search-icon { display: block; }
.multi-filter {
  display: grid;
  gap: 4px;
  min-width: 120px;
  flex: 0 1 160px;
}
.multi-filter-label {
  font-weight: 600;
  font-size: var(--text-sm);
}
.multi-filter-menu {
  position: relative;
}
.multi-filter-menu > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 26px 7px 9px;
  background: #fff;
  font: 500 var(--text) var(--sans);
  min-width: 120px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  user-select: none;
}
.multi-filter-menu > summary::-webkit-details-marker { display: none; }
.multi-filter-menu > summary::after {
  content: "";
  position: absolute;
  right: 10px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-60%) rotate(45deg);
}
.multi-filter-menu[open] > summary {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.12);
}
.multi-filter-options {
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 260px;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
  display: grid;
  gap: 2px;
}
.multi-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: var(--text-sm);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.multi-filter-option:hover { background: rgba(15, 23, 42, 0.04); }
.multi-filter-option input { margin: 0; }
.filters-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  padding-bottom: 1px;
}
.filter-btn {
  min-width: 72px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
  user-select: none;
}
.filter-btn-apply {
  background: var(--accent);
  border-color: var(--accent);
  color: #f8fafc;
}
.filter-btn-apply:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 6px 16px rgba(29, 78, 216, 0.22);
  transform: translateY(-1px);
}
.filter-btn-apply:active {
  background: var(--accent-active);
  border-color: var(--accent-active);
  box-shadow: none;
  transform: translateY(1px);
}
.filter-btn-clear:hover {
  background: rgba(15, 23, 42, 0.04);
  border-color: #cbd5e1;
  color: var(--ink);
  transform: translateY(-1px);
}
.filter-btn-clear:active {
  background: rgba(15, 23, 42, 0.08);
  border-color: #94a3b8;
  transform: translateY(1px);
  box-shadow: none;
}
.filter-btn.is-disabled,
.filter-btn:disabled {
  opacity: 0.55;
  pointer-events: none;
  transform: none;
  box-shadow: none;
}
.filters.is-loading {
  pointer-events: none;
  opacity: 0.85;
}
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(248, 250, 252, 0.9);
}
.bulk-select-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
}
.check-cell {
  width: 2.25rem;
  text-align: center;
  vertical-align: middle;
}
.check-cell input[type="checkbox"],
.bulk-select-all input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
#bulk-push-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
.listing {
  position: relative;
  min-height: 80px;
}
.listing-loading {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(248, 250, 252, 0.88);
  color: var(--muted);
  font-weight: 600;
  font-size: var(--text-sm);
  border-radius: 10px;
}
.listing.is-loading .listing-loading {
  display: flex;
}
.listing.is-loading .table-wrap,
.listing.is-loading .pager {
  opacity: 0.35;
  pointer-events: none;
  filter: blur(0.4px);
}
.listing-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: listing-spin 0.7s linear infinite;
}
@keyframes listing-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .filter-btn { transition: none; }
  .filter-btn-apply:hover,
  .filter-btn-clear:hover,
  .filter-btn-apply:active,
  .filter-btn-clear:active { transform: none; }
  .listing-spinner { animation: none; border-top-color: var(--line); }
}
.flash.error {
  background: #fdeceb; color: var(--bad); border-radius: 8px; padding: 7px 10px;
}
.flash.ok {
  background: #e8f6ee; color: var(--ok); border-radius: 8px; padding: 7px 10px;
  margin: 0 0 10px;
}
.flash-summary {
  display: grid;
  gap: 2px;
}
.flash-summary strong {
  display: block;
  font-size: var(--text);
}
.flash-summary span {
  display: block;
  line-height: 1.35;
  font-size: var(--text-sm);
}

.app-dialog {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.app-dialog.is-open,
.app-dialog:not([hidden]) {
  display: flex;
}
.app-dialog[hidden] { display: none !important; }
.app-dialog-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
}
.app-dialog-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  padding: 20px 20px 16px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 22px 50px rgba(15, 23, 42, 0.28);
  animation: app-dialog-in 0.16s ease;
}
@keyframes app-dialog-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.app-dialog-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.app-dialog-message {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: 1.45;
  white-space: pre-wrap;
}
.app-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.app-dialog.is-danger .app-dialog-actions .btn.primary {
  background: var(--bad);
  border-color: var(--bad);
}
.app-dialog.is-danger .app-dialog-actions .btn.primary:hover {
  background: #991b1b;
  border-color: #991b1b;
}
body.has-dialog { overflow: hidden; }

.page-busy {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
  padding: 16px;
  text-align: center;
}
.page-busy[hidden]:not(.is-visible) { display: none !important; }
body.is-busy .page-busy,
.page-busy.is-visible {
  display: flex !important;
}
body.is-busy {
  cursor: progress;
  overflow: hidden;
}
.page-busy-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  min-width: min(320px, 92vw);
  max-width: 360px;
  padding: 22px 24px;
  border-radius: 14px;
  background: #0f172a;
  border: 1px solid rgba(248, 250, 252, 0.12);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.45);
}
.page-busy strong {
  color: #f8fafc;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}
.page-busy .muted {
  color: rgba(248, 250, 252, 0.78);
  max-width: 280px;
  font-size: var(--text-sm);
  line-height: 1.4;
}
.page-busy .listing-spinner {
  border-color: rgba(248, 250, 252, 0.28);
  border-top-color: #93c5fd;
  width: 32px;
  height: 32px;
}

.hero-band {
  display: flex; justify-content: space-between; gap: 14px; align-items: flex-start;
  margin-bottom: 14px;
}
.hero-aside {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  justify-content: flex-end;
}
.hero-pulls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  min-width: 200px;
}
.hero-pulls-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink);
}
.hero-pulls-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.last-sync {
  margin: 6px 0 0;
  font-size: var(--text-sm);
  line-height: 1.35;
}
.last-sync strong {
  color: var(--ink);
  font-weight: 600;
}
.agent {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; min-width: 220px; box-shadow: var(--shadow);
}
.agent strong { display: block; font-size: var(--text); }
.agent small { color: var(--muted); display: block; max-width: 240px; line-height: 1.3; font-size: var(--text-xs); }
.agent .dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--warn); flex: 0 0 auto;
}
.agent.ok .dot { background: var(--ok); }
.agent.bad .dot { background: var(--bad); }

.metrics {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 12px;
}
.metrics article {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow);
}
.metrics span { color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.metrics strong { display: block; font-size: 1.35rem; margin: 4px 0 2px; letter-spacing: -0.03em; }
.metrics strong.tiny { font-size: var(--text-sm); font-family: var(--mono); font-weight: 500; word-break: break-all; }
.metrics small { color: var(--muted); font-size: var(--text-xs); }

.panel { padding: 12px 14px; margin-bottom: 12px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.panel-head .muted { font-size: var(--text-sm); }
.panel-head-3 {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: 12px;
}
.panel-head-3 h2 { justify-self: start; margin: 0; }
.panel-head-3 .last-sync-inline,
.panel-head-3 .panel-head-center {
  justify-self: center;
  text-align: center;
  margin: 0;
  font-size: var(--text-sm);
  white-space: nowrap;
}
.panel-head-3 .panel-head-center {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.panel-head-3 > .muted:last-child {
  justify-self: end;
  text-align: right;
}
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); text-align: center; }
tr.mismatch td.num { color: #9a3412; font-weight: 600; }
.inline-form { display: inline; margin: 0; }
.actions-cell { width: 1%; white-space: nowrap; }
.btn.tiny { padding: 2px 7px; font-size: var(--text-xs); }
.pill {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: #e2e8f0; font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
}
.pill.ok { background: #e8f6ee; color: var(--ok); }
.pill.bad { background: #fce8e8; color: var(--bad); }
.pill.warn { background: #fff7ed; color: #9a6b12; }
.pill.sync-fresh { background: #e8f6ee; color: var(--ok); }
.pill.sync-warm { background: #fff7ed; color: #9a6b12; }
.pill.sync-stale { background: #fce8e8; color: var(--bad); }

.dash-chart-wrap { display: grid; gap: 8px; }
.dash-chart { width: 100%; max-width: 100%; height: auto; display: block; }
.dash-bar.orders { fill: #2563eb; }
.dash-bar.inventory { fill: #0f6b5c; }
.dash-bar.customers { fill: #c45c26; }
.dash-grid { stroke: var(--line); stroke-width: 1; }
.dash-axis { fill: var(--muted); font-size: 9px; font-family: var(--mono); }
.dash-legend {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: var(--text-xs); color: var(--muted);
}
.dash-legend .swatch {
  display: inline-block; width: 9px; height: 9px; border-radius: 2px;
  margin-right: 5px; vertical-align: middle;
}
.dash-legend .swatch.orders { background: #2563eb; }
.dash-legend .swatch.inventory { background: #0f6b5c; }
.dash-legend .swatch.customers { background: #c45c26; }
.dash-table-note { margin: -2px 0 8px; }
.sync-status-table td { vertical-align: top; }
.runs-mini-table td { vertical-align: top; }
.runs-mini-table td:last-child { max-width: 420px; }
.pill.status-matched { background: #e8f6ee; color: var(--ok); }
.pill.status-linked { background: #e4eef8; color: #1d4f7a; }
.pill.status-unlinked { background: #f3e8e8; color: #7a3d3d; }
.pill.status-sage_only { background: #eef2f7; color: #3d5a73; }
.pill.status-shopify_only { background: #f7efe6; color: #8a5a22; }
.pill.status-ful-fulfilled { background: #e8f6ee; color: var(--ok); }
.pill.status-ful-partial { background: #fff7ed; color: #c2410c; }
.pill.status-ful-progress { background: #dbeafe; color: #1d4ed8; }
.pill.status-ful-hold { background: #fef3c7; color: #b45309; }
.pill.status-ful-scheduled { background: #eef2ff; color: #4338ca; }
.pill.status-ful-restocked { background: #f1f5f9; color: #475569; }
.pill.status-ful-unfulfilled { background: #f1f5f9; color: #64748b; }
.pill.pill-today {
  background: #dbeafe;
  color: #1d4ed8;
  vertical-align: middle;
}
.order-shopify-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.order-row-today td {
  background: rgba(219, 234, 254, 0.22);
}

.stats-today { margin-bottom: 14px; }
.stats-table th { white-space: nowrap; }
.stats-day {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.stats-highlights {
  margin: 0;
  padding-left: 16px;
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: 1.35;
  max-width: 360px;
}
.stats-highlights li { margin: 2px 0; }
.stats-row-today td { background: rgba(219, 234, 254, 0.22); }
.stats-footnote {
  margin: 12px 2px 0;
  font-size: var(--text-xs);
  line-height: 1.4;
}

.customer-link-form {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  margin: 0;
  min-width: 200px;
}
.sage-link-input {
  flex: 1 1 140px;
  min-width: 120px;
  max-width: 240px;
  padding: 3px 7px;
  font-size: var(--text-sm);
}
.link-cell { min-width: 210px; }
.subline { font-size: var(--text-xs); margin-top: 1px; }
.dt { line-height: 1.2; }
.dt .subline { white-space: nowrap; }

.order-pair {
  display: flex;
  align-items: stretch;
  gap: 0;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  overflow: hidden;
}
.order-pair-side {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 8px;
}
.order-pair-label {
  display: block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}
.order-pair-join {
  position: relative;
  flex: 0 0 18px;
  background: linear-gradient(180deg, transparent 0%, var(--line) 35%, var(--line) 65%, transparent 100%);
  background-size: 2px 100%;
  background-repeat: no-repeat;
  background-position: center;
}
.order-pair-join::before {
  content: "↔";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 0.65rem;
  color: var(--muted);
  line-height: 1;
}
.order-pair.is-linked {
  border-color: #b7d7c4;
  background: #f3faf6;
}
.order-pair.is-linked .order-pair-join::before {
  border-color: #b7d7c4;
  color: var(--ok);
  content: "✓";
  font-size: 0.7rem;
  font-weight: 700;
}
.order-pair.is-linked.from-sage {
  border-color: #c5d3e0;
  background: #f5f8fb;
}
.order-pair.is-linked.from-sage .order-pair-join::before {
  border-color: #c5d3e0;
  color: #3d5a73;
}
.order-pair.is-unlinked .order-pair-side:first-child {
  opacity: 0.72;
}

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text); }
th, td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; }
th.sort-th { padding: 0; }
a.sort-link {
  display: block;
  padding: 6px;
  color: inherit;
  text-decoration: none;
  border-radius: 6px;
}
a.sort-link:hover {
  color: var(--ink);
  background: rgba(15, 23, 42, 0.04);
}
th.sort-th.is-active a.sort-link {
  color: var(--ink);
  font-weight: 700;
}

.activity { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 360px; overflow: auto; font-size: var(--text-sm); }
.activity li { border-left: 2px solid var(--line); padding: 2px 0 2px 10px; }
.activity li.ok { border-color: var(--ok); }
.activity li.error { border-color: var(--bad); }
.activity li.info { border-color: #5b7c99; }

.inventory-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.inventory-hero-actions form { margin: 0; }

.flash.info {
  background: #e8f0fe;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0 0 12px;
}
.history-filters { grid-template-columns: 1fr 1.4fr auto; }
.run-list { display: grid; gap: 10px; margin-top: 4px; }
.run-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}
.run-card.is-running {
  border-color: #93c5fd;
  box-shadow: 0 0 0 1px rgba(29, 78, 216, 0.08);
  background: linear-gradient(180deg, #f8fbff 0%, #fff 70%);
}
.run-card.is-paused {
  border-color: #fbbf24;
  background: linear-gradient(180deg, #fffbeb 0%, #fff 70%);
}
.run-progress-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.run-pct {
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.run-eta {
  margin-left: auto;
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.run-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.run-controls .run-cancel { color: var(--bad); border-color: #fecaca; }
.run-controls .run-cancel:hover { background: #fef2f2; }
.run-card-top {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.run-title {
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.run-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: var(--text-sm);
}
.run-meta > div { display: grid; gap: 2px; min-width: 72px; }
.run-meta strong { font-family: var(--mono); font-size: var(--text-sm); }
.run-message { margin: 10px 0 0; font-size: var(--text-sm); line-height: 1.4; }
.run-progress { margin-top: 10px; }
.run-progress-bar {
  height: 8px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
  margin-bottom: 4px;
}
.run-progress-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #2563eb, #1d4ed8);
  border-radius: inherit;
  transition: width 0.3s ease;
}
.run-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.run-stat {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px 7px;
  border-radius: 6px;
  background: #f1f5f9;
  color: var(--ink);
}
.run-stat em {
  font-style: normal;
  color: var(--muted);
  margin-right: 4px;
  font-weight: 600;
}
.run-error {
  margin: 8px 0 0;
  color: var(--bad);
  font-size: var(--text-sm);
}
.pill.status-run-running { background: #dbeafe; color: #1d4ed8; }
.pill.status-run-paused { background: #fef3c7; color: #b45309; }
.pill.status-run-ok { background: #e8f6ee; color: var(--ok); }
.pill.status-run-error { background: #fce8e8; color: var(--bad); }
.pill.status-run-cancelled { background: #f1f5f9; color: #475569; }
.pill.status-run-interrupted { background: #fff7ed; color: var(--warn); }
.tiny { font-size: var(--text-xs); }

/* Settings */
.settings-status {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  min-width: 220px;
}
.settings-status-count {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding-right: 14px;
  border-right: 1px solid var(--line);
}
.settings-status-count strong {
  font-size: 1.6rem;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent);
}
.settings-status-count span {
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
  margin-top: 2px;
}
.settings-status-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: var(--text-sm);
}
.settings-panel { overflow: hidden; }
.settings-warn {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  font-size: var(--text-sm);
  line-height: 1.4;
}
.settings-warn strong { display: block; margin-bottom: 2px; }
.switch {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 0 0 12px;
  cursor: pointer;
  user-select: none;
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch-ui {
  position: relative;
  width: 42px;
  height: 24px;
  flex: 0 0 auto;
  margin-top: 2px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.18s ease;
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.18s ease;
}
.switch input:checked + .switch-ui { background: var(--accent); }
.switch input:checked + .switch-ui::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-ui {
  outline: 2px solid rgba(29, 78, 216, 0.35);
  outline-offset: 2px;
}
.switch-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.switch-copy strong {
  font-size: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.switch-copy small {
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 500;
  line-height: 1.35;
}
.master-switch {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
}
.nested-switch {
  padding: 10px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #fff;
}
.sched-jobs {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}
.sched-job {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.sched-job.is-on {
  border-color: #bfdbfe;
  box-shadow: 0 0 0 1px rgba(29, 78, 216, 0.06);
}
.sched-job.is-off { opacity: 0.72; }
.sched-job-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.sched-job-top .switch { margin: 0; flex: 1; }
.sched-pill {
  flex: 0 0 auto;
  margin-top: 2px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sched-pill.on { background: #dbeafe; color: #1d4ed8; }
.sched-pill.off { background: #e2e8f0; color: #64748b; }
.sched-job-controls {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(160px, 1fr);
  gap: 10px 14px;
  align-items: end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.sched-freq, .sched-cron {
  display: grid;
  gap: 4px;
  font-weight: 600;
  font-size: var(--text-sm);
}
.sched-cron.is-hidden { display: none; }
.cron-input { font-family: var(--mono); font-size: var(--text-sm); }
.sched-human {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
}
.settings-active {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.settings-active li {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
}
.settings-bar {
  position: sticky;
  bottom: 12px;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 4px 0 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(8px);
}
.settings-bar .btn.primary { min-width: 140px; padding: 9px 16px; }
.settings-write .master-switch input:checked + .switch-ui { background: var(--warn); }

@media (max-width: 960px) {
  .metrics, .grid-2 { grid-template-columns: 1fr 1fr; }
  .hero-band { flex-direction: column; }
  .filters:not(:has(.filters-bar)) { grid-template-columns: 1fr 1fr; }
  .filters-bar { flex-wrap: wrap; }
  .filters-controls {
    flex-wrap: wrap;
    padding-left: 0;
    border-left: 0;
    width: 100%;
  }
  .sched-job-controls { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .metrics, .grid-2 { grid-template-columns: 1fr; }
  .top { flex-direction: column; align-items: flex-start; }
  .filters:not(:has(.filters-bar)) { grid-template-columns: 1fr; }
  .filters-search { max-width: none; flex: 1 1 100%; }
  .settings-status { width: 100%; }
  .settings-bar { position: static; }
}
