/* Interactive mini ERP (js/erp-demo.js), modelled on the Aupulens ERP shell: module tabs, grouped sidebar, AI panel.
   Built on site.css tokens. Sidebar group labels are wide-tracked to mirror the product UI; that tracking is a
   deliberate deviation from the brand default of 0 for mono text. */
.x-demo { border: 1px solid var(--au-border); background: var(--au-bg-primary); }

.erp { --side: 210px; --ai: 0px; position: relative; display: grid; grid-template-rows: 52px minmax(0, 1fr); height: clamp(560px, 80svh, 720px); font-size: 12px; overflow: hidden; cursor: default; caret-color: var(--au-text-primary); }
/* app chrome: arrow over static text like the product; I-beam only where you can type */
.erp input { cursor: text; }
.erp input[type="search"]::-webkit-search-cancel-button { appearance: none; }
.erp.has-ai { --ai: 300px; }
.erp.is-collapsed { --side: 56px; }
.erp svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.erp__top { display: flex; align-items: center; gap: 16px; min-width: 0; padding: 0 16px; border-bottom: 1px solid var(--au-border); }
.erp__logo { display: block; flex: none; }
.erp__logo img { width: auto; height: 24px; }
html:not(.dark) .erp__logo img { filter: invert(1); }
.erp__icon { display: grid; place-items: center; flex: none; width: 32px; height: 32px; color: var(--au-text-secondary); transition: color .2s, background-color .2s; }
.erp__icon:hover, .erp__icon[aria-pressed="true"] { color: var(--au-text-primary); background: var(--au-bg-secondary); }
.erp__tabs { display: flex; gap: 22px; flex: 1; min-width: 0; height: 100%; overflow-x: auto; scrollbar-width: none; }
.erp__tabs::-webkit-scrollbar { display: none; }
.erp__tabs button { flex: none; height: 100%; border-bottom: 1px solid transparent; font-size: 12px; color: var(--au-text-secondary); transition: color .2s, border-color .2s; }
.erp__tabs button:hover { color: var(--au-text-primary); }
.erp__tabs button[aria-selected="true"] { font-weight: 500; color: var(--au-text-primary); border-bottom-color: var(--au-text-primary); }
.erp__search { display: flex; align-items: center; gap: 8px; flex: none; width: 200px; height: 32px; padding: 0 10px; border: 1px solid var(--au-border); color: var(--au-text-secondary); }
.erp__search:focus-within { border-color: var(--au-text-secondary); }
.erp__search input { width: 100%; min-width: 0; background: none; border: 0; outline: 0; font-size: 12px; color: var(--au-text-primary); }
.erp__org { display: flex; align-items: center; gap: 6px; font-size: 11px; white-space: nowrap; color: var(--au-text-secondary); }
.erp__avatar { display: grid; place-items: center; flex: none; width: 28px; height: 28px; background: var(--au-text-primary); color: var(--au-bg-primary); font-size: 10px; font-weight: 500; }

/* ---------- body: sidebar | main | AI ---------- */
.erp__body { position: relative; display: grid; grid-template-columns: var(--side) minmax(0, 1fr) var(--ai); min-height: 0; transition: grid-template-columns .4s var(--ease); }

.erp__side { min-width: 0; overflow: hidden auto; padding: 4px 12px 24px; border-right: 1px solid var(--au-border); }
.erp__group { display: grid; gap: 2px; padding: 16px 0; border-bottom: 1px solid var(--au-border); }
.erp__group > span { padding: 0 8px 8px; font-size: 9px; font-weight: 500; text-transform: uppercase; letter-spacing: .3em; white-space: nowrap; color: var(--au-text-tertiary); }
.erp__nav { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; text-align: left; font: 400 16px/1.25 var(--au-font-heading); letter-spacing: -0.04em; white-space: nowrap; color: var(--au-text-secondary); transition: color .2s; }
.erp__nav:hover, .erp__nav[aria-current="true"] { color: var(--au-text-primary); }
.erp__nav[aria-current="true"] span { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 6px; }
.is-collapsed .erp__group > span, .is-collapsed .erp__nav span { display: none; }

.erp__main { container-type: inline-size; min-width: 0; overflow: auto; display: grid; align-content: start; gap: 10px; padding: clamp(16px, 2.4vw, 28px); }
.erp__head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.erp__head h3 { font-size: clamp(26px, 3vw, 44px); line-height: 1.05; }
.erp__panel { padding: 18px; background: var(--au-bg-secondary); }

/* ---------- KPIs ---------- */
.erp__kpis { display: grid; gap: 6px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@container (min-width: 640px) { .erp__kpis--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .erp__kpis--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.erp__kpi { position: relative; display: grid; gap: 6px; padding: 14px 16px; overflow: hidden; background: var(--au-bg-secondary); }
.erp__kpi-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--au-text-secondary); }
.erp__kpi b { font: 400 clamp(24px, 2.4vw, 34px)/1.05 var(--au-font-heading); letter-spacing: -0.05em; font-variant-numeric: tabular-nums; }
.erp__kpi small { font-size: 11px; color: var(--au-text-secondary); }
.erp .erp__spark { position: absolute; right: 14px; top: 14px; width: 56px; height: 22px; color: var(--au-text-tertiary); }
.erp__chip { display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border: 1px solid currentColor; font-size: 10px; white-space: nowrap; }
.erp__chip.is-up { color: var(--au-green); border-color: var(--au-green); }
.erp__chip.is-down { color: var(--au-red); border-color: var(--au-red); }
/* light accents are too pale for text on light surfaces: keep the coloured border, use primary text */
html:not(.dark) .erp__chip, html:not(.dark) .erp__note > span { color: var(--au-text-primary); }

/* ---------- buttons ---------- */
.erp__btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 28px; padding: 0 10px; border: 1px solid var(--au-border); font-size: 10px; font-weight: 500; text-transform: uppercase; white-space: nowrap; color: var(--au-text-primary); transition: background-color .2s, border-color .2s, color .2s; }
.erp__btn:hover { border-color: var(--au-text-secondary); }
.erp__btn--solid { background: var(--au-text-primary); border-color: var(--au-text-primary); color: var(--au-bg-primary); }
.erp__btn--solid:hover { background: var(--au-text-secondary); border-color: var(--au-text-secondary); }
.erp .erp__btn svg { width: 12px; height: 12px; }

/* ---------- admin: AI business health ---------- */
.erp__health { display: grid; gap: 16px; }
.erp__health-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--au-border); }
.erp__health-top h4 { font: 400 20px/1.2 var(--au-font-heading); letter-spacing: -0.05em; }
.erp__health-top span { font-size: 10px; color: var(--au-text-tertiary); }
.erp__health > p { max-width: 90ch; font-size: 12px; line-height: 1.7; }
.erp__notes { display: grid; gap: 10px; }
@container (min-width: 560px) { .erp__notes { grid-template-columns: 1fr 1fr; } }
.erp__note { padding: 14px; border: 1px solid; font-size: 12px; }
.erp__note > span { display: block; margin-bottom: 8px; font-size: 10px; font-weight: 500; text-transform: uppercase; }
.erp__note ul { padding-left: 16px; }
.erp__note.is-ok { border-color: var(--au-green); } .erp__note.is-ok > span { color: var(--au-green); }
.erp__note.is-warn { border-color: var(--au-yellow); } .erp__note.is-warn > span { color: var(--au-yellow); }
.erp__outlook span { font-size: 10px; text-transform: uppercase; color: var(--au-text-tertiary); }
.erp__outlook p { margin-top: 6px; font-size: 12px; font-weight: 500; }
.erp__health .erp__btn { justify-self: start; }

/* ---------- sales: kanban ---------- */
.erp__board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(190px, 1fr); gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.erp__col header { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; font-weight: 500; }
.erp__col header span { min-width: 18px; padding: 0 5px; border: 1px solid var(--au-border); text-align: center; font-size: 10px; color: var(--au-text-secondary); }
.erp__col > small { display: block; margin: 2px 0 8px; font-size: 11px; color: var(--au-text-secondary); }
.erp__col-body { display: grid; align-content: start; gap: 6px; min-height: 220px; padding: 6px; border: 1px solid var(--au-border); }
.erp__deal { display: grid; gap: 6px; padding: 12px; background: var(--au-bg-secondary); }
.erp__deal-top { display: flex; justify-content: space-between; gap: 8px; }
.erp__deal-top b { font-size: 11px; font-weight: 500; }
.erp__deal-top span { font-size: 10px; color: var(--au-text-tertiary); }
.erp__deal p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--au-text-secondary); }
.erp__deal strong { font: 400 18px/1.1 var(--au-font-heading); letter-spacing: -0.05em; }
.erp__deal .erp__btn, .erp__deal .status { justify-self: start; margin-top: 4px; }
.erp__empty { padding: 12px; font-size: 11px; color: var(--au-text-tertiary); }
.erp .is-new { animation: panel-in .5s var(--ease); }

/* ---------- finance + inventory tables ---------- */
.erp__recon { display: grid; gap: 10px; }
.erp__recon-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; font-size: 11px; color: var(--au-text-secondary); }
.erp__recon-top b { font-weight: 500; color: var(--au-text-primary); }
.erp__bar { height: 4px; background: var(--au-border); }
.erp__bar i, .erp__meter i { display: block; width: 0; height: 100%; background: var(--au-green); transition: width .7s var(--ease); }
.erp .table th, .erp .table td { padding: 9px 12px; }
.erp__meter { display: inline-block; width: 56px; height: 3px; margin-right: 8px; vertical-align: middle; background: var(--au-border); }
.erp__meter.is-low i { background: var(--au-yellow); }
.erp__meter.is-out i { background: var(--au-red); }

/* ---------- module not in the demo ---------- */
.erp__locked { display: grid; justify-items: start; gap: 12px; padding: 32px; }
.erp .erp__locked > svg { width: 20px; height: 20px; color: var(--au-text-tertiary); }
.erp__locked h4 { font: 400 22px/1.2 var(--au-font-heading); letter-spacing: -0.05em; }
.erp__locked p { max-width: 52ch; color: var(--au-text-secondary); }

/* ---------- AI panel ---------- */
.erp__ai { display: none; grid-template-rows: 44px minmax(0, 1fr) auto auto; min-width: 0; border-left: 1px solid var(--au-border); background: var(--au-bg-primary); }
.has-ai .erp__ai { display: grid; }
.erp__ai-top { display: flex; align-items: center; gap: 8px; padding: 0 8px 0 16px; border-bottom: 1px solid var(--au-border); }
.erp__ai-top b { flex: 1; font-size: 11px; font-weight: 500; text-transform: uppercase; }
.erp__msgs { display: grid; align-content: start; gap: 12px; overflow-y: auto; padding: 14px 16px; }
.erp__msg { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 10px; align-items: start; font-size: 12px; line-height: 1.6; }
.erp__msg i { display: grid; place-items: center; width: 22px; height: 22px; border: 1px solid var(--au-border); font-style: normal; font-size: 10px; color: var(--au-purple); }
.erp .erp__msg i svg { width: 12px; height: 12px; }
.erp__msg.is-me { padding: 10px; border: 1px solid var(--au-border); }
.erp__msg.is-me i { color: var(--au-text-secondary); }
.erp__sugs { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 12px; }
.erp__sug { padding: 6px 8px; border: 1px solid var(--au-border); text-align: left; font-size: 11px; color: var(--au-text-secondary); transition: color .2s, border-color .2s; }
.erp__sug:hover { color: var(--au-text-primary); border-color: var(--au-text-secondary); }
.erp__ask { display: flex; gap: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--au-border); }
.erp__ask input { flex: 1; min-width: 0; height: 32px; padding: 0 10px; background: var(--au-bg-secondary); border: 1px solid var(--au-border); outline: 0; font-size: 12px; }
.erp__ask input:focus { border-color: var(--au-text-secondary); }

.erp__toast { position: absolute; left: 50%; bottom: 16px; z-index: 3; padding: 8px 12px; background: var(--au-text-primary); color: var(--au-bg-primary); font-size: 11px; white-space: nowrap; opacity: 0; transform: translate(-50%, 8px); transition: opacity .3s, transform .3s; pointer-events: none; }
.erp__toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1279px) { .erp__org { display: none; } }
@container (max-width: 639px) { .erp .erp__spark { display: none; } }
