/* ---------- theme ----------
   Every colour is a token. Light is the default; dark is chosen by
   data-theme="dark" on <html>, which a tiny script in the page head sets from
   the saved choice (or the system setting) before anything is drawn. */

:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef1f5;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef4ff;
  --accent-strong: #1e40af;
  --on-accent: #ffffff;

  --ok: #067647;
  --ok-bg: #ecfdf3;
  --bad: #b42318;
  --bad-bg: #fef3f2;
  --warn: #b54708;
  --warn-bg: #fffaeb;

  --hover: #f5f7fa;
  --held-bg: #fffaeb;
  --held-hover: #fef0c7;

  --sidebar: #ffffff;
  --sidebar-line: #eaecf0;
  --sidebar-text: #344054;
  --sidebar-muted: #98a2b3;
  --sidebar-hover: #f2f4f7;

  --toast: #101828;
  --overlay: rgba(16, 24, 40, .45);
  --focus: 0 0 0 3px rgba(37, 99, 235, .25);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 16px 40px -8px rgba(16, 24, 40, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-bg: rgba(255, 255, 255, .82);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f17;
  --surface: #111725;
  --surface-2: #151c2b;
  --surface-3: #1c2536;
  --line: #222c3f;
  --line-strong: #33405a;
  --text: #e7ebf3;
  --text-2: #c3cad8;
  --muted: #8d98ad;

  --accent: #5b8cff;
  --accent-hover: #7ba3ff;
  --accent-soft: rgba(91, 140, 255, .14);
  --accent-strong: #a9c2ff;
  --on-accent: #ffffff;

  --ok: #4ade80;
  --ok-bg: rgba(74, 222, 128, .12);
  --bad: #f87171;
  --bad-bg: rgba(248, 113, 113, .13);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, .13);

  --hover: #172033;
  --held-bg: rgba(251, 191, 36, .06);
  --held-hover: rgba(251, 191, 36, .11);

  --sidebar: #0d121c;
  --sidebar-line: #1b2333;
  --sidebar-text: #c3cad8;
  --sidebar-muted: #627089;
  --sidebar-hover: rgba(255, 255, 255, .05);

  --toast: #26324a;
  --overlay: rgba(0, 0, 0, .6);
  --focus: 0 0 0 3px rgba(91, 140, 255, .35);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 4px 14px -2px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 44px -8px rgba(0, 0, 0, .6);
  --topbar-bg: rgba(17, 23, 37, .82);
}
/* The primary button keeps white text readable on the lighter dark-mode blue. */
:root[data-theme="dark"] button.primary { background: #3b6cf6; border-color: #3b6cf6; }
:root[data-theme="dark"] button.primary:hover { background: #4d7bff; border-color: #4d7bff; }

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* One visible focus ring for keyboard users, everywhere. */
:focus-visible { outline: none; box-shadow: var(--focus); }
a { color: var(--accent); text-underline-offset: 2px; }

/* an element with [hidden] must stay hidden even when a rule gives it a display */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14.5px/1.5 "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
/* Switching theme fades the colours rather than flashing. */
body, .sidebar, .topbar, .card, .tile, .panel, button, input, select {
  transition-property: background-color, border-color, color, box-shadow, transform;
  transition-duration: .15s;
}

/* The theme button shows the moon in light mode and the sun in dark mode. */
:root[data-theme="dark"] [data-when="light"],
:root:not([data-theme="dark"]) [data-when="dark"] { display: none; }
[data-when] { display: inline-grid; place-items: center; }

svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex: none;
  background: var(--sidebar);
  color: var(--sidebar-text);
  border-right: 1px solid var(--sidebar-line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 16px 18px;
  color: var(--text);
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #3b82f6, #6d28d9);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .02em;
  flex: none;
  box-shadow: 0 4px 10px -3px rgba(59, 130, 246, .55);
}
/* Image variant used when the sidebar carries the brand image: the gradient
   and shadow drop so the logo stands on its own, scaled to the same box. */
img.brand-mark.brand-logo {
  background: #000;
  object-fit: contain;
  padding: 2px;
  box-shadow: 0 4px 10px -3px rgba(0, 0, 0, .35);
}
.brand strong { font-size: 14.5px; letter-spacing: -.01em; }
.brand .sub { color: var(--sidebar-muted); }

#nav { flex: 1; overflow-y: auto; padding: 6px 12px 20px; }

.nav-group {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--sidebar-muted);
  padding: 16px 10px 6px;
  font-weight: 600;
}

#nav button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--sidebar-text);
  padding: 8px 10px;
  margin: 1px 0;
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  position: relative;
}
#nav button:hover { background: var(--sidebar-hover); color: var(--text); }
#nav button.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
#nav button.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.count {
  font-size: 11px;
  font-weight: 600;
  min-width: 20px;
  text-align: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
}
#nav button.active .count { background: var(--accent); color: var(--on-accent); }
.count.warn { background: var(--warn-bg); color: var(--warn); }
.count.bad { background: var(--bad-bg); color: var(--bad); }

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--sidebar-line);
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
}
.user-card:hover { background: var(--sidebar-hover); }
.user-meta { flex: 1; min-width: 0; line-height: 1.25; }
.user-meta strong {
  display: block;
  font-size: 13.5px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-meta .sub { color: var(--sidebar-muted); }
.avatar {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }

.link-button {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.link-button:hover { color: var(--text); text-decoration: underline; }
.link-button.inline { color: var(--accent); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 22px;
  min-height: 60px;
  background: var(--topbar-bg);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: -.015em; font-weight: 650; }
.topbar-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.topbar-user { display: flex; align-items: center; gap: 6px; padding-left: 6px; border-left: 1px solid var(--line); }

.icon-button { display: none; padding: 7px; line-height: 0; }
.icon-only {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 10px;
  color: var(--text-2);
}

/* The user chip and its menu. */
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px 8px 3px 3px;
  border-radius: 999px;
  height: 36px;
}
.user-chip .chip-name { font-weight: 600; font-size: 13.5px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { min-width: 260px; padding: 8px; }
.user-menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.user-menu-head strong { display: block; font-size: 14px; }
.menu-label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 4px 8px 6px; }
.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  margin: 0 4px 8px;
  border-radius: 10px;
  background: var(--surface-3);
}
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: none;
  background: transparent;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  box-shadow: none;
}
.segmented button svg.icon { width: 15px; height: 15px; }
.segmented button:hover { background: transparent; color: var(--text); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
:root[data-theme="dark"] .segmented button.on { background: #2b3651; }
.menu-item.danger { color: var(--bad); }
.menu-item.with-icon { display: flex; align-items: center; gap: 9px; }

main { padding: 22px; max-width: 1560px; width: 100%; }

/* Messages from actions ("Job finished", "Download started") float at the
   bottom instead of pushing the page down, and fade out on their own. */
.status-line {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 80;
  transform: translate(-50%, 12px);
  max-width: min(560px, calc(100vw - 24px));
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--toast);
  color: #fff !important;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
}
.status-line.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.status-line.bad { background: #b42318; }

/* While a page is loading the old one dims, so a click visibly did something. */
#panel { transition: opacity .15s; }
#panel.is-loading { opacity: .55; pointer-events: none; }

/* The menu's backdrop on narrow screens; tapping it closes the menu. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: var(--overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s;
}
.backdrop.show { opacity: 1; pointer-events: auto; }
.lead { margin: 0 0 16px; color: var(--muted); max-width: 70ch; }

/* ---------- cards, tiles ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* Even columns, so two rows of tiles line up instead of stretching unevenly. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.tile:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); background: var(--surface); }
.tile:active { transform: none; }
.tile.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-md); background: var(--surface); }
.tile.active::after {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--accent);
}
/* The Orders tiles use .n/.l/.hint and the Report's use .tile-n/.tile-label/.tile-hint. */
.tile .n, .tile .tile-n { font-size: 26px; font-weight: 700; line-height: 1.15; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .l, .tile .tile-label { font-weight: 600; font-size: 13px; margin-top: 2px; color: var(--text-2); }
.tile .hint, .tile .tile-hint { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.tile.bad .n, .tile.bad .tile-n { color: var(--bad); }
.tile.ok .n, .tile.ok .tile-n { color: var(--ok); }
.tile.warn .n, .tile.warn .tile-n { color: var(--warn); }
/* Report summary tiles are figures, not buttons. */
.card .tiles { margin: 16px 0; }
.card .tiles .tile { cursor: default; }
.card .tiles .tile:hover { transform: none; border-color: var(--line); box-shadow: var(--shadow-sm); }

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: var(--surface-2);
  white-space: nowrap;
}
thead tr:first-child th:first-child { border-top-left-radius: var(--radius-sm); }
thead tr:first-child th:last-child { border-top-right-radius: var(--radius-sm); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--hover); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.scroll-x { overflow-x: auto; margin: -18px; padding: 18px; }
.scroll-x table { width: max-content; min-width: 100%; }
/* Thin, themed scrollbars inside the console. */
.scroll-x, #nav, .card table { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }

th.group-start, td.group-start { border-left: 2px solid var(--line); }
th.center { text-align: center; }
table.orders thead th { vertical-align: bottom; }
th.sub-head {
  font-size: 11px;
  font-weight: 500;
  padding-top: 0;
  text-transform: none;
  letter-spacing: 0;
}

.col-order {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
th.col-order { background: var(--surface-2); }
thead .col-order { z-index: 3; }
tbody tr:hover .col-order { background: var(--hover); }
.link-space { display: inline-block; width: 21px; }

tr.held > td { background: var(--held-bg); }
tr.held:hover > td { background: var(--held-hover); }
tr.held > td:first-child { box-shadow: inset 3px 0 0 var(--warn); }

tr.detail > td { background: var(--surface-2); padding: 12px 14px; }
.send-detail { padding: 9px 0; border-bottom: 1px solid var(--line); }
.send-detail:last-child { border-bottom: none; }
.send-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.send-detail pre {
  margin: 7px 0 0;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
}

/* ---------- small pieces ---------- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-3);
  color: var(--text-2);
}
/* A small dot makes the colour readable at a glance, and without colour too. */
.tag.sent::before, .tag.ok::before, .tag.failed::before, .tag.bad::before,
.tag.skipped::before, .tag.pending::before, .tag.warn::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.tag.sent, .tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.failed, .tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.skipped, .tag.pending, .tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.none { background: var(--surface-3); color: var(--muted); }

.ref { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.sub { font-size: 11.5px; line-height: 1.35; margin-top: 2px; }
.muted { color: var(--muted); }

.resp { font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.resp.ok { color: var(--ok); }
.resp.bad { color: var(--bad); font-weight: 500; white-space: normal; }
.resp-body {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tags-cell { max-width: 190px; }
.chip {
  font: inherit;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 1px 8px;
  margin: 0 3px 3px 0;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--text-2);
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

button {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button:hover { background: var(--hover); border-color: var(--line-strong); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }
button:disabled:hover { background: var(--surface); }
.sidebar button, .sidebar button:hover, .sidebar button:active { box-shadow: none; transform: none; }
button.link {
  border: none;
  background: none;
  box-shadow: none;
  padding: 2px 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}
button.link:hover { color: var(--accent); background: none; }
button.ghost { border-color: transparent; background: transparent; box-shadow: none; }
button.ghost:hover { background: var(--hover); }

select, input, textarea {
  font: inherit;
  color: var(--text);
  padding: 7px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .85; }
select:hover, input:hover, textarea:hover { border-color: var(--muted); }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); cursor: pointer; }

.error { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: var(--radius-sm); }
.empty { padding: 44px 20px; text-align: center; color: var(--muted); }

/* ---------- panels, policy, settings ---------- */

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  background: var(--surface);
}
.panel p { margin: 0 0 10px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 14.5px; }
.section-title { font-size: 14.5px; margin: 24px 0 10px; }

.step { display: flex; gap: 13px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: none; }
.step-n {
  width: 26px;
  height: 26px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
}

.field { display: block; margin-bottom: 14px; font-size: 13px; }
.field > span:first-child { display: block; font-weight: 600; margin-bottom: 5px; color: var(--text-2); }
.field input[type="text"], .field input[type="number"], .field select { width: 100%; }
.with-unit { display: flex; align-items: center; gap: 8px; }
.with-unit input { width: 110px; }
.with-unit em { font-style: normal; color: var(--muted); font-size: 13px; }

.switch { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; font-size: 13px; }
.switch input { margin-top: 3px; flex: none; width: 16px; height: 16px; }

.save-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 13px 0 2px;
  background: linear-gradient(to top, var(--surface) 70%, transparent);
}

/* ---------- files ---------- */

.file-list { display: grid; gap: 8px; }
.file-list.wide { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.file-button {
  display: block;
  text-align: left;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.file-button:hover { border-color: var(--accent); background: var(--accent-soft); }
.file-label { font-weight: 600; display: block; }
.file-button.ok .file-label { color: var(--ok); }
.file-button.bad .file-label { color: var(--bad); }

/* ---------- menu, pager ---------- */

.menu { position: relative; }
.menu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 40;
  min-width: 300px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  max-width: calc(100vw - 24px);
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu-head {
  padding: 7px 11px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  box-shadow: none;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 13px;
}
.menu-item:hover { background: var(--hover); }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 14px;
  margin-top: 4px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.pager-buttons { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager button { padding: 5px 11px; font-size: 13px; }
.pager select { padding: 4px 7px; font-size: 13px; margin-left: 5px; }
.pager label { display: flex; align-items: center; }

/* ---------- login ---------- */

.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
  background:
    radial-gradient(1100px 600px at 10% -10%, rgba(59, 130, 246, .16), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(109, 40, 217, .14), transparent 60%),
    var(--bg);
}
.login-wrap { width: min(390px, 100%); }
.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; }
.login-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #3b82f6, #6d28d9);
  color: #fff;
  font-weight: 700;
  flex: none;
  box-shadow: 0 8px 18px -6px rgba(59, 130, 246, .6);
}
img.login-mark.login-logo {
  background: #000;
  object-fit: contain;
  padding: 3px;
  box-shadow: 0 8px 18px -6px rgba(0, 0, 0, .55);
}
.login-brand h1 { font-size: 20px; margin: 0; letter-spacing: -.015em; }
.login-brand p { margin: 2px 0 0; font-size: 13px; }
.login { padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); }
.login label { display: block; margin-bottom: 15px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.login input { width: 100%; margin-top: 6px; height: 42px; font-weight: 400; }
.login button.primary { width: 100%; height: 42px; font-weight: 600; margin-top: 4px; }
.login-foot { font-size: 12px; margin: 14px 0 0; text-align: center; }
.login-theme { position: fixed; top: 16px; right: 16px; }

.pw-field { position: relative; display: block; }
.pw-field input { padding-right: 62px; }
.pw-toggle {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  margin-top: 3px;
  padding: 4px 9px;
  font-size: 12px;
  border: none;
  background: none;
  box-shadow: none;
  color: var(--accent);
  font-weight: 600;
}
.pw-toggle:hover { background: var(--accent-soft); }

.notice { padding: 10px 12px; border-radius: var(--radius-sm); margin-bottom: 15px; font-size: 13px; }
.notice.error { background: var(--bad-bg); color: var(--bad); }
.notice.warn  { background: var(--warn-bg); color: var(--warn); }
.notice.ok    { background: var(--ok-bg); color: var(--ok); }

/* The exact bytes sent to a partner, and their reply. Wrapped rather than
   scrolled sideways, because an address or a line item is what you came to
   read and a horizontal scrollbar hides it. */
pre.payload {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin: 6px 0 18px;
  font-size: 12.5px;
  line-height: 1.5;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
table.kv { width: auto; margin-bottom: 18px; }
table.kv th { text-align: left; padding-right: 18px; white-space: nowrap; font-weight: 600; background: none; }
.panel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 16px; }

/* The report builder: a row of filters that wraps on a phone rather than
   scrolling sideways, because every one of them has to be reachable. */
.report-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 2px;
}
.report-controls label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.report-controls input,
.report-controls select { font-size: 13px; padding: 6px 10px; height: 36px; }
.report-controls button { height: 36px; padding-top: 0; padding-bottom: 0; }
.report-controls .menu { position: relative; }
/* The Download button on the Report page sits on the left of its row, so the
   default right-aligned drop would run off-screen to the left and clip the
   layout names. Anchor it to the button's own left edge instead. */
.report-controls .menu-items { left: 0; right: auto; }
/* A date and its optional time sit side by side, so every filter is one row
   tall and the buttons line up with the fields. */
.report-controls label:has(input[type="time"]) {
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 6px;
}
.report-controls label:has(input[type="time"]) > input { grid-row: 2; }
.report-controls input[type="time"] { width: 108px; }
.report-controls input[type="search"] { min-width: 230px; }

/* The filter card at the top of a list reads as a quiet band, not a box in a box. */
.card > .panel:first-child {
  background: var(--surface-2);
  border-color: var(--line);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.card > .panel + .panel { margin-bottom: 16px; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
}
.toolbar label { display: inline-flex; align-items: center; gap: 6px; }

/* The Wukusy import sits with the Orders filters and should read as a button,
   not as the browser's default "Choose file" control. */
.file-pick {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 14px;
  border: 1px dashed var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-2);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.file-pick:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- sidebar icons, and the collapsed (icons only) sidebar ---------- */

.brand-text { flex: 1; min-width: 0; }
.collapse-toggle { width: 30px; height: 30px; border-radius: 8px; color: var(--sidebar-muted); }
.collapse-toggle:hover { color: var(--text); }
.collapse-toggle svg.icon { width: 17px; height: 17px; }

#nav button { justify-content: flex-start; gap: 11px; }
#nav button svg.icon { width: 18px; height: 18px; color: var(--sidebar-muted); transition: color .12s; }
#nav button:hover svg.icon { color: var(--text-2); }
#nav button.active svg.icon { color: var(--accent); }
#nav .nav-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#nav .count:empty, #nav .count[hidden] { display: none; }

@media (min-width: 901px) {
  .sidebar { transition: width .2s ease; }
  .nav-collapsed .sidebar { width: 72px; }
  .nav-collapsed .brand { flex-direction: column; gap: 10px; padding: 14px 0 10px; }
  .nav-collapsed .brand-text { display: none; }
  .nav-collapsed .collapse-toggle svg.icon { transform: scaleX(-1); }
  .nav-collapsed #nav { padding: 4px 12px 20px; }
  .nav-collapsed .nav-group { font-size: 0; padding: 10px 0 8px; }
  .nav-collapsed .nav-group::after { content: ""; display: block; height: 1px; margin: 0 6px; background: var(--sidebar-line); }
  .nav-collapsed #nav button { justify-content: center; padding: 10px 0; }
  .nav-collapsed #nav button.active::before { left: -12px; }
  .nav-collapsed .nav-label { display: none; }
  /* The count becomes a small badge on the icon's corner. */
  .nav-collapsed #nav .count {
    position: absolute;
    top: 3px;
    right: 6px;
    min-width: 16px;
    padding: 0 4px;
    font-size: 9.5px;
    line-height: 15px;
    box-shadow: 0 0 0 2px var(--sidebar);
  }
  .nav-collapsed .sidebar-foot { padding: 12px 8px; }
  .nav-collapsed .user-card { flex-direction: column; gap: 6px; padding: 6px 0; }
  .nav-collapsed .user-meta { display: none; }
}
/* On a phone the menu is a drawer, always full width. */
@media (max-width: 900px) { .collapse-toggle { display: none; } }

/* ---------- narrow screens ---------- */

@media (max-width: 1200px) { .hide-md { display: none; } }

@media (max-width: 900px) {
  .icon-button { display: inline-grid; place-items: center; width: 38px; height: 38px; }
  .sidebar {
    position: fixed;
    left: 0;
    width: min(280px, 86vw);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    height: 100dvh;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  #nav button { padding: 11px 12px; font-size: 15px; }
  main { padding: 16px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .topbar h1 { flex: 1; }
  .topbar-user .chip-name { display: none; }
  .user-chip { padding-right: 3px; }
}

@media (max-width: 720px) {
  body { font-size: 14px; }
  /* 16px stops iPhones zooming the page whenever a field is tapped. */
  input, select, textarea { font-size: 16px; }
  th, td { padding: 9px 10px; }
  .hide-sm, .hide-md { display: none; }

  /* Top bar: menu, title, theme and account on one line; the tools on a
     second line that scrolls sideways rather than stacking into rows. */
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .topbar h1 { font-size: 16.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .topbar-user { border-left: none; padding-left: 0; }
  .topbar-tools {
    order: 5;
    flex: 1 1 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -14px;
    padding: 0 14px 2px;
  }
  .topbar-tools::-webkit-scrollbar { display: none; }
  .topbar-tools > * { flex: none; }
  .topbar-tools select, .topbar-tools input { height: 38px; padding: 4px 9px; }
  .topbar-tools #tag-filter { width: 130px; }
  .topbar-tools button { height: 38px; padding: 0 12px; }
  /* Menus escape the scrolling strip so they are not clipped. */
  .topbar-tools .menu, .topbar-user .menu { position: static; }
  .topbar .menu-items { left: 12px; right: 12px; top: auto; min-width: 0; margin-top: 8px; }

  /* Tiles: one swipeable strip instead of two screens of cards. */
  .tiles {
    display: flex;
    gap: 9px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 14px;
    margin: 0 -16px 16px;
    padding: 2px 16px 8px;
    scrollbar-width: none;
  }
  .tiles::-webkit-scrollbar { display: none; }
  .tile { flex: 0 0 136px; padding: 11px 12px; scroll-snap-align: start; }
  .tile:hover { transform: none; }
  .tile .n, .tile .tile-n { font-size: 22px; }
  .tile .hint, .tile .tile-hint { display: none; }
  .card .tiles { margin: 12px -12px; padding: 2px 12px 6px; }

  main { padding: 12px 16px 84px; }
  .card { padding: 12px; border-radius: 11px; }
  .scroll-x { margin: -12px; padding: 12px; }

  /* Filters: two to a row, full width, buttons share the last row. */
  .card > .panel:first-child { padding: 11px; }
  .report-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .report-controls > * { min-width: 0; }
  .report-controls input, .report-controls select { width: 100%; height: 42px; font-size: 16px; }
  .report-controls button, .report-controls .file-pick { height: 42px; width: 100%; justify-content: center; }
  .report-controls label:has(input[type="time"]) { grid-column: span 2; grid-template-columns: 1fr 116px; }
  .report-controls input[type="time"] { width: 100%; }
  .report-controls label:has(input[type="search"]) { grid-column: span 2; }
  .report-controls input[type="search"] { min-width: 0; }
  .report-controls > strong, .report-controls > span.muted { grid-column: span 2; }
  .report-controls .menu { display: block; }
  .report-controls .menu-items { left: 0; right: auto; min-width: 260px; }

  /* Tables that are not already in a scroller get one, instead of being cut off. */
  .card table:not(.scroll-x table) { display: block; overflow-x: auto; }
  td { word-break: normal; }
  td .muted, td code { overflow-wrap: anywhere; }

  .pager { justify-content: center; text-align: center; }
  .pager > .muted:first-child { flex: 1 1 100%; }
  .pager button { padding: 8px 12px; }
  .pager-buttons { justify-content: center; }

  .panel-grid { grid-template-columns: 1fr; }
  .panel { padding: 14px; }
  .save-bar { margin: 18px -12px -12px; padding: 12px; background: var(--surface); border-top: 1px solid var(--line); }
  .save-bar button { flex: 1; height: 44px; }

  .status-line { bottom: 16px; }
}

@media (max-width: 380px) {
  .report-controls { grid-template-columns: 1fr; }
  .report-controls label:has(input[type="time"]),
  .report-controls label:has(input[type="search"]),
  .report-controls > strong, .report-controls > span.muted { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
