/* Foothills Invoice Bridge -- app stylesheet.
   Palette is Discovery Solutions' own: #0A4994 blue and #A7A9AC grey, the two
   colours in static/img/ds-logo.svg. Every class the templates use is defined
   here; adding a new one means adding it here too, since there is no build
   step and no CSS framework.

   Layout, after the 2026-11 rebuild (modelled on the Walker AR Packager):
   status tiles across the top of a work screen, a list on the left and the
   selected record on the right, and a freshness line saying how current the
   OpenInvoice check is -- "not sent" is only true if that check is recent. */

:root {
  --brand-primary: #0c4a96;
  --brand-primary-hover: #093a78;
  --brand-primary-dark: #1e2530;
  --brand-primary-light: #e5eeff;
  --brand-secondary: #a7a9ac;
  --brand-secondary-dark: #6b6f76;
  --brand-black: #16181d;
  --brand-offwhite: #f4f5f7;

  --surface: #ffffff;
  --surface-sunken: #f8f9fb;
  --hairline: #e6e8ec;
  --hairline-strong: #d6d9df;
  --text: #16181d;
  --text-muted: #636871;

  --ok-bg: #e9f7ef;      --ok-fg: #0f5c2e;   --ok-line: #a8ddba;
  --warn-bg: #fff7e6;    --warn-fg: #7a4b00; --warn-line: #f0c36d;
  --err-bg: #fdecee;     --err-fg: #86232c;  --err-line: #f0aab0;
  --info-bg: #eef4fd;    --info-fg: #0c3d7a; --info-line: #b9d0f2;

  --r-sm: 6px;  --r-md: 9px;  --r-lg: 12px;  --r-pill: 999px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;

  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-2: 0 1px 3px rgba(16, 24, 40, .07), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-3: 0 8px 28px rgba(16, 24, 40, .10);
  --ring: 0 0 0 3px rgba(12, 74, 150, .22);

  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
  --ease: 150ms cubic-bezier(.2, .6, .3, 1);
}

* { box-sizing: border-box; }
/* The pages toggle panes with the hidden attribute; a display rule on the
   same element would otherwise win and keep it on screen. */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  background: var(--brand-offwhite);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Numbers in tables should line up in columns. */
table, .bar-value, .amount, .tile-value { font-variant-numeric: tabular-nums; }
.amount { text-align: right; white-space: nowrap; }

a { color: var(--brand-primary); }

/* ---------------------------------------------------------------- header */

header {
  background: linear-gradient(180deg, #232b38 0%, var(--brand-primary-dark) 100%);
  color: #fff;
  padding: var(--sp-2) var(--sp-5);
  box-shadow: var(--shadow-2);
}
.header-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }

.brand { display: inline-flex; align-items: center; gap: var(--sp-3); text-decoration: none; color: inherit; }
/* White chip: the logo's wordmark is Discovery blue and would disappear on
   the dark header. */
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border-radius: var(--r-md);
  padding: 5px 9px; box-shadow: var(--shadow-1);
}
.brand-mark img { display: block; height: 28px; width: auto; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-size: 1.02rem; font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.74rem; color: rgba(229, 238, 255, .62); letter-spacing: .02em; }
.brand:hover .brand-title { text-decoration: underline; text-underline-offset: 2px; }

nav { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; }
nav a {
  color: rgba(229, 238, 255, .85); text-decoration: none;
  padding: 7px 12px; border-radius: var(--r-sm);
  font-size: 0.92rem; font-weight: 550; transition: background var(--ease), color var(--ease);
}
nav a:hover { background: rgba(255, 255, 255, .10); color: #fff; }
/* The page you are on. */
nav a.is-current { background: rgba(255, 255, 255, .16); color: #fff; }
.nav-gap { width: var(--sp-3); }
.who {
  color: rgba(229, 238, 255, .70); margin-left: var(--sp-2); padding-left: var(--sp-3);
  border-left: 1px solid rgba(255, 255, 255, .16); font-size: 0.86rem;
}
nav a.signout { font-weight: 400; font-size: 0.86rem; }
/* The Feedback button looks like a nav link (templates/_feedback.html). */
nav button.nav-feedback {
  background: none; border: 1px solid rgba(255, 255, 255, .28); box-shadow: none;
  color: rgba(229, 238, 255, .9); padding: 5px 11px; font-size: 0.86rem; font-weight: 550;
}
nav button.nav-feedback:hover { background: rgba(255, 255, 255, .10); color: #fff; box-shadow: none; }

.feedback-box {
  position: fixed; right: var(--sp-4); top: 72px; z-index: 40;
  width: min(380px, calc(100vw - 2 * var(--sp-4))); margin: 0;
  box-shadow: var(--shadow-3);
}
.feedback-box h2 { margin: 0 0 var(--sp-2); font-size: 1.05rem; }
.feedback-box textarea { width: 100%; box-sizing: border-box; min-height: 96px; font: inherit; }
.feedback-box .hint { margin: var(--sp-2) 0 0; }
.feedback-box .feedback-bad { color: var(--err-fg); }
.feedback-shotrow { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: var(--sp-2); }
.feedback-shot { position: relative; margin-top: var(--sp-2); border: 1px solid var(--hairline); border-radius: var(--r-sm); }
.feedback-shot img { display: block; width: 100%; max-height: 180px; object-fit: contain; background: var(--surface-sunken); }
.feedback-shot button { position: absolute; top: var(--sp-1); right: var(--sp-1); }
.feedback-error { margin: var(--sp-2) 0 0; color: var(--err-fg); font-size: 0.875rem; }
.feedback-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-3); }
.feedback-actions .secondary { margin-left: 0; }
.feedback-box.feedback-drop { outline: 2px dashed var(--brand-primary); outline-offset: -4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Admin > Feedback */
.feedback-list { list-style: none; margin: 0; padding: 0; }
.feedback-item { border-top: 1px solid var(--hairline); padding: var(--sp-3) 0; display: grid;
  grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-3); }
.feedback-item:first-child { border-top: 0; }
.feedback-item .meta { color: var(--text-muted); font-size: 0.86rem; margin: 0 0 var(--sp-1); }
.feedback-item .note { white-space: pre-wrap; margin: 0 0 var(--sp-2); }
.feedback-item img { display: block; max-width: 320px; max-height: 200px; border: 1px solid var(--hairline); border-radius: var(--r-sm); }
.feedback-item form { margin: 0; }

.badge { display: inline-block; border-radius: var(--r-pill); font-size: 0.7rem;
  font-weight: 600; letter-spacing: .04em; text-transform: uppercase; padding: 3px 9px; }
.badge-demo { background: #b45309; color: #fff; }
/* Config error, not a mode: OI_CLIENT_DUNS != OI_SUPPLIER_DUNS. Deliberately
   the loudest thing on the page -- the API reports this as empty results. */
.badge-misconfig { background: #b91c1c; color: #fff; font-weight: 700; }

/* Environment badges. PROD is the loud one on purpose: the mistake that costs
   something is acting in production while believing you are in UAT, so the
   real environment is the one that has to be impossible to miss. UAT is muted
   and outlined -- present, informative, not shouting all day. */
.badge-env-prod {
  background: #b91c1c; color: #fff;
  box-shadow: 0 0 0 2px rgba(185, 28, 28, .35);
}
.badge-env-uat {
  background: rgba(255, 255, 255, .10); color: rgba(229, 238, 255, .85);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .28);
}
/* DEMO is deliberately unmissable too, for the opposite reason to PROD: nobody
   should ever mistake synthetic sales data for a real customer's numbers. */
.badge-env-demo {
  background: #7c3aed; color: #fff;
  box-shadow: 0 0 0 2px rgba(124, 58, 237, .35);
}

/* Which OpenInvoice account we are connected to. Admin information, so it
   sits small under the header rather than in the clerk's way. */
.oi-status {
  margin-top: var(--sp-2); padding-top: var(--sp-1);
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: 0.74rem; color: rgba(229, 238, 255, .55);
}
.oi-status strong { color: var(--brand-primary-light); font-weight: 600; }

/* ------------------------------------------------------------ structure */

main { max-width: 1320px; margin: var(--sp-5) auto; padding: 0 var(--sp-5); }

section, .card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: var(--sp-5); margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-1);
}
.card-tight { padding: var(--sp-4); }

h1 { margin: 0; font-size: 1.45rem; font-weight: 680; letter-spacing: -0.02em; }
h2 { margin: 0 0 var(--sp-3); font-size: 1.15rem; font-weight: 650; letter-spacing: -0.015em; }
h3 { margin: var(--sp-5) 0 var(--sp-2); font-size: 1rem; font-weight: 640; letter-spacing: -0.01em; }
.card > h2:first-child, section > h2:first-child, .card > h3:first-child { margin-top: 0; }
.hint { color: var(--text-muted); font-size: 0.875rem; }
.narrow { max-width: 480px; }
.nowrap { white-space: nowrap; }
.muted { color: var(--text-muted); }

/* Page title row: title and one line of context on the left, actions right. */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.page-head p { margin: 4px 0 0; color: var(--text-muted); font-size: 0.92rem; }
.page-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.back-link { display: inline-block; margin-bottom: var(--sp-2); font-size: 0.88rem; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* ------------------------------------------------------- freshness line */
/* "OpenInvoice last checked 3 h ago". Red when the check is too old to trust,
   because then "not sent" may be wrong and an invoice could go twice. */

.fresh {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4);
  padding: var(--sp-2) var(--sp-4); margin-bottom: var(--sp-4);
  background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-md);
  font-size: 0.86rem; color: var(--text-muted);
}
.fresh strong { color: var(--text); font-weight: 600; }
.fresh-item { display: inline-flex; align-items: center; gap: 6px; }
.fresh-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok-line); flex: none; }
.fresh-item.is-stale .fresh-dot { background: #d92d3a; }
.fresh-item.is-stale strong { color: var(--err-fg); }
.fresh.is-stale { background: var(--err-bg); border-color: var(--err-line); color: var(--err-fg); }
.fresh a { font-weight: 550; }
.fresh form { display: inline; margin: 0; }
.fresh .linkish { font-size: 0.86rem; }

/* ---------------------------------------------------------------- tiles */
/* Status counts. Each is a button that filters the list below it. */

.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--sp-3); margin-bottom: var(--sp-4);
}
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: left; background: var(--surface); color: var(--text);
  border: 1px solid var(--hairline); border-radius: var(--r-lg);
  padding: var(--sp-3) var(--sp-4); box-shadow: var(--shadow-1);
  font: inherit; cursor: pointer; text-decoration: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.tile:hover { border-color: var(--brand-secondary); box-shadow: var(--shadow-2); background: var(--surface); }
.tile:active { transform: none; }
.tile.is-active { border-color: var(--brand-primary); box-shadow: 0 0 0 1px var(--brand-primary), var(--shadow-2); }
.tile-label { font-size: 0.7rem; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted); }
.tile-value { font-size: 1.75rem; font-weight: 650; line-height: 1.15; letter-spacing: -0.02em; }
.tile-sub { font-size: 0.8rem; color: var(--text-muted); }
.tile-warn .tile-value { color: #b45309; }
.tile-bad .tile-value { color: #b91c1c; }
.tile-good .tile-value { color: var(--ok-fg); }
/* A tile that is information, not a filter (e.g. "Last checked"). */
.tile-static { cursor: default; }
.tile-static:hover { border-color: var(--hairline); box-shadow: var(--shadow-1); }

/* ------------------------------------------------- list beside detail */

.workspace {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px;
  gap: var(--sp-4); align-items: start;
}
.list-pane { padding: var(--sp-4); margin: 0; min-width: 0; overflow-x: auto; }
.detail-pane {
  position: sticky; top: var(--sp-4); margin: 0;
  max-height: calc(100vh - 2 * var(--sp-4)); overflow: auto;
}
.detail-pane h2 { margin-bottom: var(--sp-1); }
.detail-pane .detail-sub { margin: 0 0 var(--sp-4); color: var(--text-muted); font-size: 0.9rem; }

.list-tools { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-3); }
.list-tools input[type=search], .list-tools input[type=text] { flex: 1 1 220px; min-width: 0; }
.list-tools select, .list-tools input[type=date] { min-width: 0; }
.list-tools label.hint { display: inline-flex; align-items: center; gap: 6px; }
.list-count { font-size: 0.85rem; color: var(--text-muted); margin: 0 0 var(--sp-2); }

.list-table { margin-top: 0; }
.list-table tbody tr { cursor: pointer; }
.list-table tbody tr.is-selected { background: var(--brand-primary-light); box-shadow: inset 3px 0 0 var(--brand-primary); }
.list-table td.check, .list-table th.check { width: 34px; padding-right: 0; }
.list-table .sub { display: block; font-size: 0.8rem; color: var(--text-muted); }
.list-empty { padding: var(--sp-5); text-align: center; color: var(--text-muted); }

/* Bulk action bar, shown when rows are ticked. */
.bulk-bar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3);
  background: var(--info-bg); border: 1px solid var(--info-line); border-radius: var(--r-md);
  font-size: 0.88rem; color: var(--info-fg);
}
.bulk-bar form { margin: 0; }

/* Numbered "Start here" steps. */
ol.steps { list-style: none; counter-reset: step; margin: var(--sp-3) 0 0; padding: 0; }
ol.steps li {
  counter-increment: step; position: relative; padding: 0 0 var(--sp-3) 38px;
  font-size: 0.92rem;
}
ol.steps li::before {
  content: counter(step); position: absolute; left: 0; top: -1px;
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-primary-light); color: var(--brand-primary);
  font-weight: 700; font-size: 0.82rem;
}
ol.steps li strong { display: block; }
ol.steps li span { color: var(--text-muted); font-size: 0.86rem; }

/* Facts about one record (label above value). */
dl.facts { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3) var(--sp-4); margin: 0 0 var(--sp-4); }
dl.facts div { min-width: 0; }
dl.facts dt { font-size: 0.7rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); }
dl.facts dd { margin: 2px 0 0; font-size: 0.95rem; overflow-wrap: anywhere; }
dl.facts .wide { grid-column: 1 / -1; }
.facts-4 { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }

.detail-actions { display: flex; flex-direction: column; gap: var(--sp-2); }
.detail-actions .btn, .detail-actions button { text-align: center; margin-left: 0; }

/* ----------------------------------------------------- step bar (prepare) */

.stepper { display: flex; gap: 0; margin: 0 0 var(--sp-4); padding: 0; list-style: none; }
.stepper li {
  flex: 1; display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3); font-size: 0.86rem; color: var(--text-muted);
  border-bottom: 3px solid var(--hairline);
}
.stepper li .n {
  width: 22px; height: 22px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--hairline); color: var(--text-muted); font-weight: 700; font-size: 0.76rem;
}
.stepper li.is-done { color: var(--ok-fg); border-bottom-color: var(--ok-line); }
.stepper li.is-done .n { background: var(--ok-line); color: var(--ok-fg); }
.stepper li.is-current { color: var(--text); font-weight: 600; border-bottom-color: var(--brand-primary); }
.stepper li.is-current .n { background: var(--brand-primary); color: #fff; }

/* One large "where this stands" box at the top of a record. */
.status-banner {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-4); border-radius: var(--r-lg); margin-bottom: var(--sp-4);
  border: 1px solid var(--hairline); background: var(--surface-sunken);
}
.status-banner .icon {
  flex: none; width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1rem; color: #fff; background: var(--brand-secondary-dark);
}
.status-banner .title { font-weight: 650; font-size: 1.05rem; margin: 2px 0 2px; }
.status-banner p { margin: 0; font-size: 0.9rem; }
.status-ok   { background: var(--ok-bg);   border-color: var(--ok-line);   color: var(--ok-fg); }
.status-ok .icon { background: #1f8a4c; }
.status-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-fg); }
.status-warn .icon { background: #c27803; }
.status-err  { background: var(--err-bg);  border-color: var(--err-line);  color: var(--err-fg); }
.status-err .icon { background: #c0313c; }
.status-info { background: var(--info-bg); border-color: var(--info-line); color: var(--info-fg); }
.status-info .icon { background: var(--brand-primary); }

/* Two-column record page: the work on the left, a summary on the right. */
.record { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--sp-4); align-items: start; }
.record-side { position: sticky; top: var(--sp-4); }
.record-main > .card:last-child, .record-side > .card:last-child { margin-bottom: 0; }
.form-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; margin-top: var(--sp-4); }
.form-actions .btn.secondary { margin-left: 0; }

/* Collapsed technical detail (DUNS numbers, raw payloads). */
details.tech { margin-top: var(--sp-4); border-top: 1px solid var(--hairline); padding-top: var(--sp-3); }
details.tech > summary { color: var(--text-muted); font-weight: 550; font-size: 0.88rem; }

/* --------------------------------------------------- collapsible panels */
/* Used on the admin mapping page so setup/import forms are collapsed by
   default -- they pushed everything useful below the fold. Panels open
   themselves when they hold something that needs attention (see the "open"
   expressions in admin_mapping_edit.html). */

details.panel {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); margin-bottom: var(--sp-3);
  box-shadow: var(--shadow-1); overflow: hidden;
}
details.panel > summary {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-4) var(--sp-5); cursor: pointer;
  list-style: none; user-select: none;
  transition: background var(--ease);
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary:hover { background: var(--surface-sunken); }
details.panel > summary:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-lg); }
/* Chevron, rotated when open. */
details.panel > summary::before {
  content: ""; flex: none; width: 8px; height: 8px;
  border-right: 2px solid var(--brand-secondary-dark);
  border-bottom: 2px solid var(--brand-secondary-dark);
  transform: rotate(-45deg); transition: transform var(--ease);
}
details.panel[open] > summary::before { transform: rotate(45deg); }
details.panel[open] > summary { border-bottom: 1px solid var(--hairline); }
.panel-title { font-weight: 640; font-size: 1rem; letter-spacing: -0.01em; }
.panel-note { color: var(--text-muted); font-size: 0.8rem; }
.panel-body { padding: var(--sp-5); }
.panel-body > *:first-child { margin-top: 0; }

/* Plain details (used for "Add a new customer" etc.) */
details:not(.panel) { margin-top: var(--sp-4); }
details:not(.panel) > summary { cursor: pointer; color: var(--brand-primary); font-weight: 550; }

/* ------------------------------------------------------------- messages */

.flash-container { max-width: 1320px; margin: var(--sp-3) auto 0; padding: 0 var(--sp-5); }
.flash {
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); margin-bottom: var(--sp-2);
  font-size: 0.9rem; border: 1px solid transparent; border-left-width: 4px;
  box-shadow: var(--shadow-1); background: var(--surface);
}
.flash-success { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-line); }
.flash-warning { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-line); }
.flash-error   { background: var(--err-bg);  color: var(--err-fg);  border-color: var(--err-line); }

.box {
  background: var(--surface-sunken); border: 1px solid var(--hairline);
  border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4); font-size: 0.9rem;
}
.box-warn { background: var(--warn-bg); border-color: var(--warn-line); }
.box-ok   { background: var(--ok-bg);   border-color: var(--ok-line); }
.box-info { background: var(--info-bg); border-color: var(--info-line); }
.box > *:last-child { margin-bottom: 0; }

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

table { width: 100%; border-collapse: collapse; margin-top: var(--sp-3); }
th, td { text-align: left; padding: 9px var(--sp-3); border-bottom: 1px solid var(--hairline); font-size: 0.9rem; vertical-align: top; }
thead th {
  font-size: 0.7rem; font-weight: 650; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); background: var(--surface-sunken);
  border-bottom: 1px solid var(--hairline-strong); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
th.amount { text-align: right; }
tbody tr { transition: background var(--ease); }
tbody tr:hover { background: var(--surface-sunken); }
table.kv td:first-child { color: var(--text-muted); width: 220px; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--brand-primary); }
th.sortable::after { content: " \2195"; opacity: .35; }

/* --------------------------------------------------------- form controls */

button, .btn {
  display: inline-block; background: var(--brand-primary); color: #fff;
  border: 1px solid transparent; padding: 8px 14px; border-radius: var(--r-md);
  cursor: pointer; font-size: 0.9rem; font-weight: 550; font-family: inherit;
  text-decoration: none; box-shadow: var(--shadow-1); line-height: 1.4;
  transition: background var(--ease), box-shadow var(--ease), transform var(--ease);
}
button:hover, .btn:hover { background: var(--brand-primary-hover); box-shadow: var(--shadow-2); }
button:active, .btn:active { transform: translateY(1px); box-shadow: var(--shadow-1); }
button:focus-visible, .btn:focus-visible, .tile:focus-visible { outline: none; box-shadow: var(--ring); }
button.secondary, .btn.secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--hairline-strong); box-shadow: var(--shadow-1);
}
button.secondary:hover, .btn.secondary:hover { background: var(--surface-sunken); border-color: var(--brand-secondary); }
.btn.secondary { margin-left: var(--sp-2); }
.btn-lg { padding: 11px 18px; font-size: 0.98rem; font-weight: 600; }
.btn-sm { padding: 4px 10px; font-size: 0.82rem; }
/* A button that reads as a link (e.g. "Sync now" in the freshness line). */
button.linkish {
  background: none; border: none; box-shadow: none; padding: 0;
  color: var(--brand-primary); font-weight: 550; text-decoration: underline; text-underline-offset: 2px;
}
button.linkish:hover { background: none; box-shadow: none; color: var(--brand-primary-hover); }
button:disabled { background: #d9dbdf; color: #8c9098; cursor: not-allowed; box-shadow: none; }
button:disabled:hover { background: #d9dbdf; transform: none; }

select, input[type=text], input[type=search], input[type=date], input[type=file], input[type=password], input[type=number] {
  padding: 8px 10px; border: 1px solid var(--hairline-strong); border-radius: var(--r-md);
  min-width: 260px; font-size: 0.9rem; font-family: inherit; background: var(--surface);
  color: var(--text); transition: border-color var(--ease), box-shadow var(--ease);
}
select:focus, input:focus { outline: none; border-color: var(--brand-primary); box-shadow: var(--ring); }
input[type=file] { padding: 6px 8px; }
.field-full { width: 100%; min-width: 0 !important; }

.step { margin-bottom: var(--sp-4); }
.step label, label.field-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.86rem; }
.step .hint { margin: 4px 0 0; }
.checkbox-line { display: flex; gap: var(--sp-2); align-items: flex-start; margin-bottom: var(--sp-1); font-size: 0.9rem; }
.checkbox-line input { margin-top: 4px; }

/* Older pages' filter row. */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-1); }
.toolbar form { margin: 0; }
.toolbar select, .toolbar input[type=date] { min-width: 0; padding: 7px 9px; }
.toolbar input[type=text] { min-width: 0; width: 220px; }
.toolbar label.hint { display: flex; align-items: center; gap: 6px; }

/* ------------------------------------------------------------ tags, code */

.tag {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 0.74rem; font-weight: 600; letter-spacing: .01em; white-space: nowrap;
  background: var(--surface-sunken); color: var(--text-muted); border: 1px solid var(--hairline-strong);
}
.tag-warning { background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-line); }
.tag-ok { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid var(--ok-line); }
.tag-bad { background: var(--err-bg); color: var(--err-fg); border: 1px solid var(--err-line); }
.tag-info { background: var(--info-bg); color: var(--info-fg); border: 1px solid var(--info-line); }

code {
  background: var(--surface-sunken); border: 1px solid var(--hairline);
  padding: 1px 5px; border-radius: var(--r-sm); font-size: 0.86em;
  font-family: var(--mono);
}
pre {
  background: #10131a; color: #d9dadb; padding: var(--sp-4); border-radius: var(--r-md);
  overflow: auto; font-size: 0.8rem; box-shadow: var(--shadow-1); max-height: 480px;
  font-family: var(--mono);
}

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

.mapping-table { table-layout: fixed; width: 100%; }
.mapping-table td { border-bottom: 1px solid var(--hairline); padding: 6px var(--sp-2); overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.mapping-table th:nth-child(1), .mapping-table td:nth-child(1) { width: 22%; }
.mapping-table th:nth-child(2), .mapping-table td:nth-child(2) { width: 18%; }
.mapping-table th:nth-child(3), .mapping-table td:nth-child(3) { width: 11%; }
.mapping-table th:nth-child(4), .mapping-table td:nth-child(4) { width: 29%; }
.mapping-table th:nth-child(5), .mapping-table td:nth-child(5) { width: 10%; }
.mapping-table th:nth-child(6), .mapping-table td:nth-child(6) { width: 10%; }
.mapping-table select, .mapping-table input[type=text] { width: 100%; min-width: 0; }

/* item-mapping-table has a different column mix (Discovery item / Uses /
   Match / OpenInvoice item / Confidence) than the header/line tables. */
.item-mapping-table th:nth-child(1), .item-mapping-table td:nth-child(1) { width: 30%; }
.item-mapping-table th:nth-child(2), .item-mapping-table td:nth-child(2) { width: 8%; }
.item-mapping-table th:nth-child(3), .item-mapping-table td:nth-child(3) { width: 10%; }
.item-mapping-table th:nth-child(4), .item-mapping-table td:nth-child(4) { width: 42%; }
.item-mapping-table th:nth-child(5), .item-mapping-table td:nth-child(5) { width: 10%; }

/* Overview of the four scopes on the customer's mapping page. */
.scope-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: var(--sp-3); }
.scope-card {
  border: 1px solid var(--hairline); border-radius: var(--r-lg); padding: var(--sp-4);
  background: var(--surface); display: flex; flex-direction: column; gap: var(--sp-2);
}
.scope-card h3 { margin: 0; }
.scope-card .scope-links { margin-top: auto; display: flex; gap: var(--sp-3); align-items: center; font-size: 0.88rem; }
.scope-card .scope-links .btn { margin-left: 0; }

/* Paging links on the item mapping scope pages. */
.pager { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; font-size: 0.88rem; }
.pager a, .pager strong { padding: 3px 9px; border-radius: var(--r-sm); text-decoration: none; }
.pager a { border: 1px solid var(--hairline-strong); }
.pager a:hover { background: var(--surface-sunken); }
.pager strong { background: var(--brand-primary); color: #fff; }

/* ------------------------------------------------ progress (warming, sync) */

.bar-track { background: #eaeef3; border-radius: var(--r-sm); height: 20px; display: flex; overflow: hidden; }
.bar-fill {
  height: 20px; min-width: 3px; border: none; padding: 0;
  background: linear-gradient(90deg, var(--brand-primary) 0%, #1a63bd 100%);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.warming-bar-track { margin-top: var(--sp-5); height: 24px; }
.warming-bar-fill { transition: width 400ms cubic-bezier(.2,.6,.3,1); height: 24px; }
.warming-step { margin-top: var(--sp-3); font-size: 0.92rem; font-weight: 600; }
.warming-fun { margin-top: var(--sp-1); font-size: 0.85rem; color: var(--text-muted); font-style: italic; min-height: 1.2em; }

/* Centred single-card pages: sign in, access denied, warming, sync. */
.center-page { max-width: 520px; margin: 7vh auto 0; }
.center-page.wide { max-width: 640px; }
.signin-card { padding: var(--sp-6); }
.signin-card h1 { margin-bottom: var(--sp-2); }
.signin-card .lead { color: var(--text-muted); margin: 0 0 var(--sp-5); }
.signin-card .btn-ms {
  display: flex; align-items: center; justify-content: center; gap: var(--sp-3);
  width: 100%; padding: 12px 16px; font-size: 1rem; font-weight: 600; margin-left: 0;
}
.ms-logo { display: inline-grid; grid-template-columns: 9px 9px; gap: 2px; }
.ms-logo i { width: 9px; height: 9px; display: block; }
.ms-logo i:nth-child(1) { background: #f25022; } .ms-logo i:nth-child(2) { background: #7fba00; }
.ms-logo i:nth-child(3) { background: #00a4ef; } .ms-logo i:nth-child(4) { background: #ffb900; }
.or-rule { display: flex; align-items: center; gap: var(--sp-3); margin: var(--sp-5) 0; color: var(--text-muted); font-size: 0.82rem; }
.or-rule::before, .or-rule::after { content: ""; flex: 1; border-top: 1px solid var(--hairline); }
.signin-card input[type=text], .signin-card input[type=password] { width: 100%; min-width: 0; }
.signin-card button[type=submit] { width: 100%; padding: 10px 14px; }

.build-footer {
  max-width: 1320px; margin: var(--sp-2) auto var(--sp-5); padding: 0 var(--sp-5);
  font-size: 0.75rem; color: var(--brand-secondary); text-align: right;
}

/* ------------------------------------------------------------ responsive */
/* Desktop is the design target (billing happens at a desk). Narrow screens
   stack the panes so the pages stay readable, nothing more. */

@media (max-width: 1100px) {
  .workspace, .record { grid-template-columns: minmax(0, 1fr); }
  .detail-pane, .record-side { position: static; max-height: none; }
}
@media (max-width: 720px) {
  header { padding: var(--sp-2) var(--sp-4); }
  main, .flash-container { padding: 0 var(--sp-3); }
  section, .card, .panel-body, details.panel > summary { padding: var(--sp-4); }
  select, input[type=text], input[type=search] { min-width: 0; width: 100%; }
  dl.facts, .facts-4 { grid-template-columns: 1fr 1fr !important; }
  .stepper li { font-size: 0.76rem; padding: var(--sp-2) 4px; }
}

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