/* CHIFFRIX — clean, light, enterprise. No decoration; hairlines and whitespace. */

:root {
  --page: #f9f9f7;
  --surface: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;      /* series slot 1 */
  --accent-strong: #256abf;
  --accent-wash: #eaf2fc;
  --series-2: #1baf7a;    /* series slot 2 (aqua) */
  --series-2-strong: #199e70;
  --danger: #d03b3b;
  --danger-strong: #b22222;   /* hover/selected step — darker but still clearly red */
  --good: #006300;
  --radius: 4px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Cross-fade between page loads (Chrome/Edge/Safari; others just ignore it) */
@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ------------------------------------------------------------ top bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 18px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.08em;
  color: var(--ink);
}
.topbar .brand small {
  font-weight: 400;
  color: var(--muted);
  letter-spacing: normal;
  margin-left: 8px;
}
a.brand:hover { text-decoration: none; }
.topbar .user { color: var(--muted); font-size: 13px; text-decoration: none; }
.topbar a.user:hover .user-name { text-decoration: underline; }
.topbar .user-ico { display: none; }
/* The brand pushes everything else right — works whether or not the search
   form is present (it only renders for tenants with the factory module). */
.topbar .brand { margin-right: auto; }
.topbar .nav-search input {
  min-width: 150px;
  width: 150px;
  padding: 5px 10px;
  font-size: 13px;
}
.topbar button.linklike {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  padding: 5px 12px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.topbar button.linklike:hover { border-color: var(--baseline); color: var(--ink); }

/* -------------------------------------------------- shell: areas + pages */
/* Two levels: the sidebar picks an area, the strip picks a page inside it.
 * Both are generated from the NAV registry in common.js — nothing here knows
 * the page names. */
.shell { display: flex; align-items: flex-start; }

.sidebar {
  flex: none;
  width: 190px;
  position: sticky;
  top: 52px;                       /* under the topbar */
  height: calc(100vh - 52px);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}
.sidebar .area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--ink-2);
  font-weight: 500;
  white-space: nowrap;
}
.sidebar .area svg { flex: none; }
.sidebar .area:hover { background: var(--page); text-decoration: none; }
.sidebar .area.active { color: var(--accent-strong); background: var(--accent-wash); }
/* an area with no pages yet — shown, so the shape of the app is legible */
.sidebar .area.empty { color: var(--muted); opacity: 0.45; cursor: default; }
.sidebar .area.empty:hover { background: none; }

.workspace { flex: 1; min-width: 0; }

.subnav {
  display: flex;
  gap: 4px;
  padding: 10px 24px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.subnav::-webkit-scrollbar { display: none; }
.subnav.scroll-right {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
}
.subnav.scroll-left {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px);
  mask-image: linear-gradient(90deg, transparent, #000 36px);
}
.subnav.scroll-left.scroll-right {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 36px), transparent);
}
.subnav a {
  color: var(--ink-2);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
}
.subnav a:hover { background: var(--surface); text-decoration: none; }
.subnav a.active { color: var(--accent-strong); background: var(--accent-wash); }

@media (max-width: 1100px) {
  .topbar { gap: 14px; padding: 0 14px; }
  .topbar .brand small { display: none; }
  .topbar .nav-search input { min-width: 110px; width: 110px; }
  .sidebar { width: 56px; }                    /* icons only */
  .sidebar .area { justify-content: center; padding: 10px 0; }
  .sidebar .area-label { display: none; }
}

/* Phones: the sidebar becomes a bottom bar (thumb reach), the page strip
 * stays at the top and scrolls sideways. */
@media (max-width: 760px) {
  .topbar .user-name { display: none; }
  .topbar .user-ico { display: inline; }
  .topbar .nav-search input { min-width: 90px; width: 90px; }
  .shell { display: block; }
  .sidebar {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: auto;
    flex-direction: row;
    justify-content: space-around;
    gap: 0;
    padding: 4px 2px;
    border-right: none;
    border-top: 1px solid var(--border);
    z-index: 30;
  }
  .sidebar .area {
    flex-direction: column;
    gap: 2px;
    padding: 6px 4px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
  }
  .sidebar .area-label { display: block; }     /* label under the icon */
  .workspace { padding-bottom: 60px; }         /* clear of the bottom bar */
  .subnav { padding: 8px 12px 0; }
}

/* ------------------------------------------------------------- layout */
.content { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: baseline; gap: 16px; margin: 4px 0 20px; }
.page-head h1 { font-size: 20px; font-weight: 650; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filter-row label { color: var(--ink-2); font-size: 13px; }
.filter-row .export-btn {
  margin-left: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
}
.filter-row .export-btn:hover { border-color: var(--baseline); color: var(--ink); text-decoration: none; }

select, input[type="text"], input[type="search"], input[type="password"] {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type="search"] { min-width: 280px; }

.seg {
  display: inline-flex;
  flex: 0 0 auto;               /* never squash a seg to fit the row */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg button {
  font: inherit; font-size: 13px;
  border: none; background: var(--surface); color: var(--ink-2);
  padding: 6px 12px; cursor: pointer;
  white-space: nowrap;
  border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--accent-wash); color: var(--accent-strong); font-weight: 600; }
.seg button:hover:not(.active) { background: var(--page); }
/* a seg that doesn't apply right now (see dashblock setGroupDisabled) —
 * after .active so a disabled group's previous selection greys out too */
.seg button:disabled { background: var(--surface); color: var(--muted); cursor: not-allowed; font-weight: 400; }

/* --------------------------------------------------------------- cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 20px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;              /* toolbar drops below the title before it squeezes it */
}
/* margin-right:auto keeps the title packed against the Back button when the
 * toolbar wraps to its own row (space-between would otherwise split them) */
.card-head h2 { font-size: 14px; font-weight: 650; margin: 0 auto 0 0; color: var(--ink); }
/* step back out of a chart drill-down */
.chart-back {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  padding: 4px 9px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 14px;
  line-height: 1.1;
  cursor: pointer;
}
.chart-back:hover { border-color: var(--baseline); color: var(--ink); background: var(--page); }
.card-head .tools { display: flex; gap: 8px; align-items: center; }
/* The toolbar keeps its natural width and right-aligns, on the title's row or
 * on its own. Its groups can't shrink — DashBlock moves the ones that no
 * longer fit into the "⋯" menu instead (layoutTools). */
.card-head > .tools { flex: 1 0 auto; justify-content: flex-end; }
.card-head .tools > * { flex: 0 0 auto; }
.tool-group { display: flex; align-items: center; }
.tool-group > .tool-group-label { display: none; }   /* shown only inside the menu */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------ KPI row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 20px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 18px;
}
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: var(--baseline); }
.kpi.selected { border-color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-strong); }
.kpi .label { color: var(--ink-2); font-size: 13px; margin-bottom: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; color: var(--ink); }
.kpi .note { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* -------------------------------------------------------------- tables */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th {
  text-align: left;
  font-weight: 600;
  color: var(--ink-2);
  border-bottom: 1px solid var(--grid);
  padding: 8px 10px;
  white-space: nowrap;
}
table.data td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: top;
}
table.data tr:last-child td { border-bottom: none; }
table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--page); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data th.sorted { color: var(--accent-strong); }
table.data .sort-arrow { font-size: 9px; }
table.data .mono { font-variant-numeric: tabular-nums; }
/* the row a map-marker click just scrolled to (see map.js highlightCity) */
table.data tr.row-flash td { animation: row-flash 2.5s ease-out; }
@keyframes row-flash {
  0%, 50% { background: var(--accent-wash); }
  100% { background: transparent; }
}
.table-scroll { overflow-x: auto; }

.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.pager button {
  font: inherit; font-size: 13px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-2); border-radius: var(--radius);
  padding: 5px 12px; cursor: pointer;
}
.pager button:disabled { opacity: 0.4; cursor: default; }
.pager button:hover:not(:disabled) { border-color: var(--baseline); color: var(--ink); }

/* drill-down chip: active period filter set by clicking the chart */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-wash);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 10px;
}
.chip button {
  border: none;
  background: none;
  color: var(--accent-strong);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.chip button:hover { color: var(--ink); }

/* -------------------------------------------------------------- badges */
.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  border: 1px solid var(--border);
  color: var(--ink-2);
  background: var(--page);
}

/* --------------------------------------------------------------- chart */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; }
.chart-tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(11, 11, 11, 0.08);
  padding: 6px 10px;
  font-size: 12.5px;
  z-index: 10;
  display: none;
  white-space: nowrap;
}
.chart-tip .tip-label { color: var(--ink-2); margin-bottom: 2px; }
.chart-tip .tip-value { font-weight: 650; color: var(--ink); font-size: 13px; }
.chart-tip .tip-key {
  display: inline-block;
  width: 10px; height: 2px;
  background: var(--accent);
  vertical-align: middle;
  margin-right: 6px;
}
.chart-tip .tip-name { font-weight: 400; color: var(--ink-2); font-size: 12px; }

.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 12.5px;
  color: var(--ink-2);
  margin: 0 0 8px 52px;
}
.chart-legend .legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .legend-swatch {
  width: 10px; height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* horizontal bar list (top products / clients) */
.hbar-list { display: flex; flex-direction: column; gap: 8px; }
.hbar-row {
  display: grid;
  grid-template-columns: minmax(120px, 220px) 1fr 90px;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
  border-radius: var(--radius);
  cursor: pointer;
}
.hbar-row:hover { background: var(--page); }
.hbar-row .hbar-label {
  font-size: 12.5px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbar-row .hbar-track { height: 14px; position: relative; }
.hbar-row .hbar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  min-width: 2px;
}
.hbar-row .hbar-value {
  font-size: 12.5px;
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- order page */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 24px;
}
.detail-grid .field { padding: 4px 0; }
.detail-grid .field .k { color: var(--muted); font-size: 12px; }
.detail-grid .field .v { color: var(--ink); font-size: 13.5px; margin-top: 1px; }

.spec-row td { background: var(--page); }
.spec-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 4px 0; }
.spec-table td { padding: 3px 10px; border-bottom: 1px solid var(--grid); }
.spec-table td.k { color: var(--ink-2); width: 220px; }
.expand-btn {
  font: inherit; font-size: 12px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-2); border-radius: 3px;
  padding: 2px 8px; cursor: pointer;
}
.expand-btn:hover { border-color: var(--baseline); color: var(--ink); }

/* --------------------------------------------------------------- login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 32px;
  width: 360px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; letter-spacing: 0.06em; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card label { display: block; font-size: 13px; color: var(--ink-2); margin: 14px 0 4px; }
.login-card input { width: 100%; }
.login-card button.primary {
  width: 100%;
  margin-top: 22px;
  font: inherit; font-weight: 600;
  background: var(--accent-strong);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 9px;
  cursor: pointer;
}
.login-card button.primary:hover { background: #1c5cab; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }
.login-hint { color: var(--muted); font-size: 12px; margin-top: 18px; border-top: 1px solid var(--grid); padding-top: 12px; }

/* map page (moved from map.html so the CSP can forbid inline styles) */
.map-card { padding: 8px; }
/* isolate: Leaflet panes use z-index 200-1000; contain them so they
   don't paint over the sticky topbar (z-index 20) when scrolling */
#map { height: 560px; border-radius: 6px; isolation: isolate; }
.map-popup { font-size: 13px; }
.map-popup .p-city { font-weight: 650; margin-bottom: 2px; }
.map-popup .p-row { color: #52514e; }

/* ------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }

/* --------------------------------------------- code tables (TABGEN) */
.tables-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.type-list { padding: 8px; }
.type-list button {
  display: flex;
  width: 100%;
  align-items: baseline;
  gap: 8px;
  padding: 7px 10px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
}
.type-list button:hover { background: var(--page); }
.type-list button.active { background: var(--accent-wash); color: var(--accent-strong); }
.type-list .tname { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 6px; }
.type-list .tname strong { font-weight: 650; }
.type-list .tname small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.type-list button.active .tname small { color: var(--accent-strong); opacity: 0.75; }
.type-list .count { color: var(--muted); font-size: 12px; }
.type-list .new-table { color: var(--accent-strong); font-weight: 600; margin-top: 4px; border-top: 1px solid var(--grid); border-radius: 0 0 var(--radius) var(--radius); }

.btn-sm {
  border: 1px solid var(--grid);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: var(--radius);
  padding: 4px 10px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.btn-sm:hover { border-color: var(--baseline); color: var(--ink); }
.btn-sm.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
  font-weight: 600;
}
.btn-sm.primary:hover { background: #1c5cab; color: #fff; }
table.data td.nw { white-space: nowrap; }
/* editor table: compact single-line rows; .table-wrap scrolls when a table
   with two full 40-char descriptions genuinely can't fit */
.tables-layout table.data th, .tables-layout table.data td { padding: 7px 8px; white-space: nowrap; }
.tables-layout .row-actions button { padding: 3px 8px; font-size: 12px; }
.row-actions { white-space: nowrap; }
.row-actions button { margin-right: 6px; }
.row-actions button:last-child { margin-right: 0; }

table.data td input {
  width: 100%;
  min-width: 60px;
  padding: 4px 6px;
  font: inherit;
  font-size: 13px;
  border: 1px solid var(--baseline);
  border-radius: 3px;
  background: var(--surface);
  color: var(--ink);
}
table.data td input:focus { outline: none; border-color: var(--accent); }
tr.deleted td { color: var(--muted); text-decoration: line-through; }
tr.deleted td.row-actions, tr.deleted td.status-cell { text-decoration: none; }
.badge.conv-yes { color: var(--good); background: #eef6ee; border-color: transparent; text-decoration: none; }
.badge.conv-yes:hover { text-decoration: underline; }
.badge.conv-no { color: var(--muted); }
.badge.edit-modified { color: var(--accent-strong); background: var(--accent-wash); border-color: transparent; }
.badge.edit-added { color: var(--good); background: #eef6ee; border-color: transparent; }
.badge.edit-deleted { color: var(--muted); }
.save-error { color: var(--danger); font-size: 12.5px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 2px 0; }

/* ------------------------------------------------------- small screens */
@media (max-width: 760px) {
  .content { padding: 12px; }
  .page-head { flex-wrap: wrap; gap: 6px 12px; margin-bottom: 14px; }

  /* top bar: brand + actions on the first row, search full-width below.
     (The page nav is the strip under this; the areas are the bottom bar.) */
  .topbar {
    position: static;
    height: auto;
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 8px 10px;
  }
  .topbar .brand { margin-right: auto; }
  .topbar .brand small { display: none; }
  .topbar .user-name { display: none; }
  .topbar .user-ico { display: inline; }
  .topbar .nav-search {
    order: 2;              /* after the buttons: its own row */
    flex: 1 0 100%;
    margin-left: 0;
  }
  .topbar .nav-search input { width: 100%; min-width: 0; }

  /* cards & controls */
  .card { padding: 12px; }
  /* DashBlock's toolbar overflows into the "⋯" menu instead of wrapping; this
   * only catches toolbars it doesn't manage (analytics, pipeline, tables). */
  .card-head .tools { flex-wrap: wrap; row-gap: 6px; }
  .filter-row input[type="search"] { min-width: 0; width: 100%; }
  .filter-row .export-btn { margin-left: 0; }
  .seg button { padding: 6px 9px; }

  /* code tables: stack the type list above the editor */
  .tables-layout { grid-template-columns: 1fr; }

  /* KPI tiles: two per row, slightly tighter */
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
  .kpi { padding: 10px 12px; }
  .kpi .value { font-size: 21px; }

  .grid-2 { gap: 12px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }

  /* ranked bars: shorter label column so the bar keeps room */
  .hbar-row { grid-template-columns: minmax(76px, 120px) 1fr 82px; gap: 8px; }
  .hbar-row .hbar-label, .hbar-row .hbar-value { font-size: 12px; }

  /* tables scroll sideways on phones — keep cells on one line */
  table.data td { white-space: nowrap; }

  .login-card { width: min(360px, calc(100vw - 32px)); padding: 24px; }
  #map { height: 62vh; min-height: 320px; }
  .chart-tip { max-width: calc(100vw - 48px); white-space: normal; }
}

@media (max-width: 420px) {
  .detail-grid { grid-template-columns: 1fr; }
}

/* question title above each configuration-choices group */
.attr-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 10px 0 6px;
}

/* "..." side menu on chart cards — placeholder panel for extended options */
.card-head .tools { position: relative; }
.card-menu-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--ink-2);
  font-size: 16px;
  line-height: 1;
  padding: 5px 9px;
  cursor: pointer;
}
.card-menu-btn:hover { background: var(--page); }
.card-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 240px;
  max-width: min(320px, calc(100vw - 32px));
  background: var(--card, #fff);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  padding: 10px;
  z-index: 50;
}

/* toolbar groups pushed in here by layoutTools: stacked, labelled, and the
 * seg unrolls from a cramped segmented control into wrapping chips */
.card-menu-panel .menu-overflow {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.card-menu-panel .tool-group { display: block; }
.card-menu-panel .tool-group + .tool-group { margin-top: 10px; }
.card-menu-panel .tool-group-label {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.card-menu-panel .tools { display: flex; }
.card-menu-panel .seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
  border: none;
  overflow: visible;
}
.card-menu-panel .seg button {
  flex: 1 1 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
}

/* the comparison picker in the card menu */
.card-menu-panel .menu-select { width: 100%; font-size: 13px; }
.card-menu-panel .menu-select:disabled { color: var(--muted); cursor: not-allowed; }
.card-menu-panel .menu-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------- period picker */
/* One control, every page: presets + a Custom entry with its two dates. */
.period-picker { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.period-picker .period-dates { display: flex; align-items: center; gap: 6px; }
.period-picker .period-arrow { color: var(--muted); }
.period-picker input[type="date"] {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
}

/* KPI change against the comparison period */
.kpi .delta {
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.kpi .delta.up { color: var(--good); }
.kpi .delta.down { color: var(--danger); }
.kpi .delta.flat { color: var(--muted); font-weight: 500; }

/* --------------------------------------------------- production batches */
.btn-new { margin-left: auto; font-size: 13px; padding: 7px 14px; }

.badge.st-pending { color: #8a5a00; background: #faf3e3; border-color: transparent; }
.badge.st-queued { color: #5b4fa8; background: #efedfa; border-color: transparent; }
.badge.st-inprod { color: var(--accent-strong); background: var(--accent-wash); border-color: transparent; }
.badge.st-done { color: var(--good); background: #eef6ee; border-color: transparent; }
.badge.st-issue { color: var(--danger); background: #faecec; border-color: transparent; }

/* one batch, expanded: its lines grouped per order */
.batch-detail { padding: 6px 4px; }
.batch-history {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  margin: 2px 2px 8px;
}
.batch-history .bh-step + .bh-step::before { content: '→ '; }
.batch-detail .bh-at { font-size: 12px; color: var(--muted); margin-left: 6px; }
.batch-detail .bh-reason { font-size: 12px; color: var(--danger); margin: 0 8px 0 6px; }
.batch-detail .btn-sm + .btn-sm { margin-left: 4px; }

/* order page, production view: where each line stands */
.prod-cell .prod-ref { display: flex; align-items: center; gap: 6px; }
.prod-cell .prod-ref + .prod-ref { margin-top: 3px; }
.prod-cell .pr-note { font-size: 12px; color: var(--muted); }
.prod-cell .pr-reason { font-size: 12px; color: var(--danger); }
.batch-detail-order {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 13px;
  font-weight: 650;
  margin: 10px 2px 2px;
}
.batch-detail-order:first-child { margin-top: 2px; }
.batch-detail-order .bd-client { font-weight: 400; color: var(--ink-2); }
.batch-detail-order .bd-due { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: auto; }

/* batch mode: order/line checkboxes + quantity cells */
.batch-check {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-strong);
  vertical-align: middle;
  cursor: pointer;
}
table.data td.qty-cell input {   /* outranks the generic td input rule */
  width: 90px;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  text-align: right;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.qty-cell input:disabled { background: var(--page); color: var(--muted); }
/* why a line can't be added to the batch, shown in the Batch qty cell */
.qty-cell .no-batch { color: var(--muted); font-size: 12px; white-space: nowrap; font-style: italic; }

/* due date + urgency */
.due-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.due-chip .due-days {
  font-size: 11.5px;
  font-weight: 650;
  padding: 1px 7px;
  border-radius: 9px;
  background: var(--page);
  border: 1px solid var(--grid);
  color: var(--muted);
}
.due-chip.urgent .due-days { color: #8a5a00; background: #faf3e3; border-color: transparent; }
.due-chip.overdue .due-days { color: var(--danger-strong); background: #fbeaea; border-color: transparent; }

/* the batch selection bar: sticky at the bottom of any page in the mode */
.batchbar {
  position: sticky;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--baseline);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(11, 11, 11, 0.10);
  padding: 12px 16px;
  margin-top: 14px;
  z-index: 20;
}
.batchbar .batch-info { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 200px; }
/* the contents panel: what's in the batch so far, above the controls row */
.batchbar .batch-panel {
  flex-basis: 100%;
  max-height: 45vh;
  overflow-y: auto;
  border-bottom: 1px solid var(--grid);
  padding-bottom: 10px;
  margin-bottom: 2px;
}
.batch-panel .spec-table td { vertical-align: middle; }
.batch-panel input[type="number"] {
  width: 70px;
  font: inherit;
  font-size: 12.5px;
  text-align: right;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.batch-panel .bp-um { color: var(--muted); font-size: 12px; }
.batch-panel .bp-remove { width: 34px; text-align: right; }
.batch-panel .bp-remove button,
.batch-panel .batch-detail-order .bp-x { padding: 2px 7px; font-size: 11px; color: var(--muted); }
.batch-panel .bp-remove button:hover,
.batch-panel .batch-detail-order .bp-x:hover { color: var(--danger); border-color: var(--danger); }
.batch-panel .batch-detail-order .bp-x { margin-left: auto; }
.batchbar .batch-title { font-weight: 650; font-size: 13.5px; }
.batchbar .batch-empty { color: var(--muted); font-size: 12.5px; }
.batchbar .batch-counts { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.batchbar input[type="text"] { font-size: 13px; width: 210px; }
.batchbar button:disabled { opacity: 0.45; cursor: default; }
.batchbar .save-error { flex-basis: 100%; }
.batchbar .save-error:empty { display: none; }

@media (max-width: 760px) {
  .batchbar { bottom: 64px; }   /* clear of the mobile bottom nav */
}

/* ===== purchasing module (bons de commande) ============================ */

/* Match the base text-input look for the extra field types the module uses. */
input[type="number"], input[type="email"], input[type="tel"],
input[type="date"], textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
}
textarea { resize: vertical; min-height: 38px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  margin: 4px 0 8px;
}
.form-grid label { display: flex; flex-direction: column; gap: 4px; }
.form-grid label > span { color: var(--muted); font-size: 12px; }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }

.form-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.form-actions .save-error:empty { display: none; }

/* import panel */
#import-panel { margin: 4px 0 16px; }
.import-help { color: var(--ink-2); font-size: 13px; margin: 0 0 8px; }
.import-text { width: 100%; min-height: 120px; }
.import-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.import-result { margin-top: 14px; }
.review-note { color: var(--ink-2); font-size: 12.5px; margin-bottom: 8px; }
.review-table input.flagged {
  border-color: var(--danger);
  background: #fdecec;
  color: var(--danger-strong);
}

/* purchase-order editor */
.po-actions { display: flex; align-items: center; gap: 8px; margin: 4px 0 24px; }
.po-actions .save-error:empty { display: none; }
.po-lines { margin-top: 8px; }
.po-line-table input { width: 100%; min-width: 60px; }
.po-line-table td.num input { text-align: right; }
/* per-line CAD/USD choice, riding in the price cell */
.po-line-table td.num { white-space: nowrap; }
.po-line-table select.line-currency {
  width: auto; margin-left: 4px; padding: 6px 4px; font-size: 12px;
}
.po-line-table td.num input[type="number"] { width: calc(100% - 66px); }
.po-total {
  display: flex; justify-content: flex-end; gap: 16px;
  align-items: baseline; margin-top: 10px;
  font-variant-numeric: tabular-nums;
}
.po-total strong { font-size: 15px; }

/* purchase-order status: pill badges, status bar, history journal */
.po-badge {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px; border: 1px solid transparent;
  white-space: nowrap;
}
.po-badge.st-draft     { color: var(--ink-2); background: var(--page); border-color: var(--border); }
.po-badge.st-ordered   { color: var(--accent-strong); background: var(--accent-wash); }
.po-badge.st-partial   { color: #9a6a00; background: #fdf1d8; }
.po-badge.st-received  { color: var(--good); background: #eef6ee; }
.po-badge.st-closed    { color: #fff; background: var(--ink-2); }
.po-badge.st-cancelled { color: var(--danger-strong); background: #fdecec; }

.po-statusbar { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; }
.po-statusbar[hidden] { display: none; }
.po-recv-note { color: var(--ink-2); font-size: 13px; font-variant-numeric: tabular-nums; }

table.data tr.line-received td { background: #f2f8f2; }

.po-history { display: flex; flex-direction: column; gap: 7px; }
.po-history-row { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.po-history-row .ph-at { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 150px; }
.po-history-row .ph-user { color: var(--ink-2); }

/* printable bon de commande: hidden on screen, revealed for print */
.po-sheet { display: none; }
.po-sheet .sheet-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 2px solid var(--ink); padding-bottom: 10px; margin-bottom: 16px;
}
.po-sheet .sheet-co-name { font-size: 18px; font-weight: 700; }
.po-sheet .sheet-title { text-align: right; }
.po-sheet .sheet-doc { font-size: 16px; font-weight: 700; letter-spacing: 0.05em; }
.po-sheet .sheet-no { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.po-sheet .sheet-meta { font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.po-sheet .sheet-blocks { display: flex; gap: 40px; margin-bottom: 18px; }
.po-sheet .sheet-block { font-size: 13px; line-height: 1.5; }
.po-sheet .sheet-block-h {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin-bottom: 4px;
}
.po-sheet .sheet-strong { font-weight: 650; }
.po-sheet .sheet-total {
  display: flex; justify-content: flex-end; gap: 20px; align-items: baseline;
  margin-top: 12px; font-size: 15px; font-variant-numeric: tabular-nums;
}
.po-sheet .sheet-tax {
  text-align: right; margin-top: 2px;
  color: var(--ink-2); font-size: 11px;
}
/* professional-but-sober table: shaded header band, firm rules. The
   print-color-adjust keeps the shading when printing to PDF. */
.po-sheet table.data { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.po-sheet table.data th {
  background: #efeeea; color: var(--ink);
  border-top: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink);
  font-weight: 650;
}
.po-sheet table.data td { border-bottom: 1px solid var(--grid); }
.po-sheet .sheet-notes { margin-top: 20px; font-size: 12.5px; line-height: 1.5; }

@media print {
  /* Zero page margin removes the browser's own header/footer (document title,
     URL, date, page number); the sheet supplies its own margin via padding. */
  @page { margin: 0; }
  .topbar, .sidebar, .subnav, .no-print, .batchbar { display: none !important; }
  .shell, .workspace, main.content {
    display: block !important;
    margin: 0 !important; padding: 0 !important; max-width: none !important;
  }
  body { background: #fff; }
  .po-sheet { display: block; padding: 16mm; }
  .po-sheet table.data th, .po-sheet table.data td { padding: 6px 8px; }
}

/* catalog autocomplete dropdown (custom, not the native datalist) */
.ac-menu {
  position: fixed; z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--baseline); border-radius: var(--radius);
  box-shadow: 0 6px 22px rgba(11, 11, 11, 0.14);
  max-height: 260px; overflow-y: auto; padding: 4px;
  font-size: 13px; min-width: 200px;
}
.ac-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 6px 10px; border-radius: 3px; cursor: pointer; white-space: nowrap;
}
.ac-row.active { background: var(--accent-wash); }
.ac-primary { color: var(--ink); font-weight: 500; }
.ac-secondary { color: var(--muted); font-size: 12px; }
.ac-price {
  margin-left: auto; padding-left: 14px;
  color: var(--ink-2); font-variant-numeric: tabular-nums;
}

/* projects module: needs table + add row + inventory */
td.missing-cell { color: var(--danger-strong); font-weight: 650; }
input.need-qty { width: 80px; text-align: right; }
/* PO refs under the on-order qty of a need */
.oo-pos {
  display: flex; flex-direction: column; align-items: flex-end;
  font-size: 11px; line-height: 1.4;
}
.oo-pos a { white-space: nowrap; }
.oo-pos a.st-draft { color: var(--muted); font-style: italic; }
.need-add { margin-top: 12px; }
.need-add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.need-add-row input[type="text"] { flex: 1; min-width: 160px; }
.need-add-row input.na-sku { flex: 0 1 110px; min-width: 90px; }
.need-add-row input.na-sup { flex: 0 1 160px; min-width: 120px; }
.need-add-row input.na-unit { flex: 0 1 70px; min-width: 60px; }
.need-add-row input[type="number"] { width: 90px; text-align: right; }
.po-project-link { font-size: 13px; }
/* inventory: in-place − [qty] + stepper */
.stock-stepper { display: inline-flex; align-items: center; gap: 4px; }
.stock-stepper input {
  width: 70px; text-align: right; padding: 5px 6px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
/* the native number spinner duplicates the side buttons */
.stock-stepper input::-webkit-inner-spin-button,
.stock-stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.stock-stepper .btn-sm.step {
  padding: 4px 9px; font-size: 14px; line-height: 1; font-weight: 600;
}

/* guided tour: click-blocking layer, spotlight hole, step bubble */
.tour-block { position: fixed; inset: 0; z-index: 9998; }
.tour-spot {
  position: fixed; z-index: 9999; pointer-events: none;
  border-radius: 6px;
  box-shadow: 0 0 0 200vmax rgba(11, 11, 11, 0.45);
  transition: all 0.2s ease;
}
.tour-bubble {
  position: fixed; z-index: 10000;
  width: min(360px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: 0 8px 30px rgba(11, 11, 11, 0.25);
}
.tour-bubble.tour-center {
  top: 50%; left: 50%; transform: translate(-50%, -50%);
}
.tour-bubble h3 { margin: 0 22px 6px 0; font-size: 15px; }
.tour-bubble p { margin: 0 0 12px; color: var(--ink-2); line-height: 1.45; }
.tour-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; cursor: pointer;
  font-size: 18px; line-height: 1; color: var(--muted); padding: 4px;
}
.tour-close:hover { color: var(--ink); }
.tour-foot { display: flex; align-items: center; justify-content: space-between; }
.tour-count { color: var(--muted); font-size: 12px; }
.tour-btns { display: flex; gap: 8px; }

/* company logo beside the brand name in the topbar */
.topbar .brand { display: inline-flex; align-items: center; gap: 8px; }
.topbar .brand-logo {
  height: 32px; width: auto; max-width: 150px;
  object-fit: contain; border-radius: 2px; display: block;
}

/* logo on the printed sheet + the header contact lines */
.po-sheet .sheet-logo { max-height: 70px; max-width: 240px; margin-bottom: 8px; display: block; }
.po-sheet .sheet-co-line { font-size: 12px; color: var(--ink-2); line-height: 1.4; }

/* company-settings page: logo field */
.logo-field { margin: 14px 0 4px; }
.logo-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.logo-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.logo-preview {
  width: 160px; height: 90px; border: 1px dashed var(--baseline);
  border-radius: var(--radius); display: flex; align-items: center;
  justify-content: center; overflow: hidden; background: var(--surface);
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-preview .logo-empty { color: var(--muted); font-size: 12.5px; }
.logo-actions { display: flex; flex-direction: column; gap: 8px; }
.save-ok { color: var(--good); font-size: 12.5px; }
.save-ok:empty { display: none; }

@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  .po-sheet .sheet-blocks { flex-direction: column; gap: 16px; }
}

/* activity: the week chart with the profit stat tile beside it */
.week-row { display: flex; gap: 12px; align-items: center; }
.week-row > :first-child { flex: 1; min-width: 0; }
.week-row .kpi { min-width: 200px; margin: 0 16px 8px 0; }

/* profile page */
.profile-card { max-width: 460px; padding: 16px; margin-bottom: 14px; }
.profile-card h2 { margin: 0 0 10px; font-size: 16px; }
.profile-card form { display: flex; flex-direction: column; gap: 6px; }
.profile-card label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.profile-card input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}
.profile-card button[type="submit"] {
  margin-top: 12px;
  align-self: flex-start;
}
.save-ok { color: var(--ok, #1a7f37); font-size: 12.5px; }
