:root {
  --ink: #172033;
  --muted: #738096;
  --line: #e5e8ef;
  --surface: #ffffff;
  --canvas: #f5f6f9;
  --navy: #171b38;
  --violet: #6b5ce7;
  --violet-soft: #efedff;
  --green: #179f6f;
  --green-soft: #e7f8f1;
  --amber: #c47a13;
  --amber-soft: #fff4df;
  --red: #d34b55;
  --red-soft: #ffedef;
  --blue: #3478c6;
  --blue-soft: #eaf3ff;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 0; background: var(--canvas); }
button, input, select { font: inherit; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 20px; color: #fff; background: linear-gradient(180deg, #1c2147 0%, #12162e 100%); display: grid; grid-template-columns: 42px 1fr; grid-template-rows: auto 1fr auto; gap: 0 12px; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: linear-gradient(135deg, #8d7cff, #5d51c9); font: 700 23px/1 Georgia, serif; }
.brand-name { margin: 2px 0 0; font: 700 18px/1.1 Georgia, serif; letter-spacing: .02em; }
.brand-subtitle { margin: 4px 0 0; color: #aeb7d5; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; }
.sidebar nav { grid-column: 1 / -1; margin-top: 46px; display: flex; flex-direction: column; gap: 8px; }
.nav-item { min-height: 44px; padding: 0 13px; display: flex; align-items: center; gap: 11px; border-radius: 11px; color: #c8cee3; text-decoration: none; font-size: 13px; }
.nav-item span { font-size: 18px; }
.nav-item em { margin-left: auto; color: #747c9a; font-size: 10px; font-style: normal; }
.nav-item.active { color: #fff; background: rgba(125, 111, 235, .23); box-shadow: inset 3px 0 0 #8c7df1; }
.nav-item.disabled { opacity: .62; }
.sidebar-note { grid-column: 1 / -1; display: flex; gap: 10px; align-items: flex-start; padding: 15px; border: 1px solid rgba(255,255,255,.1); border-radius: 12px; background: rgba(255,255,255,.04); color: #aeb7d5; font-size: 11px; line-height: 1.5; }
.sidebar-note strong { color: #fff; font-size: 12px; }
.live-dot { flex: 0 0 auto; width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: #4ed39a; box-shadow: 0 0 0 4px rgba(78,211,154,.12); }
main { min-width: 0; padding: 0 34px 42px; }
.topbar { min-height: 104px; display: flex; align-items: center; justify-content: space-between; }
.eyebrow { margin: 0 0 6px; color: var(--violet); font-size: 10px; font-weight: 800; letter-spacing: .15em; text-transform: uppercase; }
h1 { margin: 0; font: 700 28px/1.15 Georgia, serif; }
h2 { margin: 0; font: 700 22px/1.2 Georgia, serif; }
h3 { margin: 0 0 14px; font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.demo-badge { padding: 8px 12px; border: 1px solid #e0dcff; border-radius: 999px; background: var(--violet-soft); color: #584abd; font-size: 11px; font-weight: 700; }
.demo-badge.live-data { border-color: #bdebd9; background: var(--green-soft); color: #117756; }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--muted); cursor: pointer; }
.avatar { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: #e1ddff; color: #4d41ad; font-size: 12px; font-weight: 800; }
.context-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--line); }
.context-strip div { padding: 14px 17px; background: var(--surface); }
.context-strip span, .filters label > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.context-strip strong { display: block; font-size: 12px; overflow-wrap: anywhere; }
.context-strip small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.kpi-grid { margin: 18px 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi-card { position: relative; overflow: hidden; min-height: 118px; padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 4px 18px rgba(40, 47, 74, .04); }
.kpi-card::after { content: ""; position: absolute; right: -20px; top: -20px; width: 68px; height: 68px; border-radius: 50%; background: currentColor; opacity: .08; }
.kpi-card > span { color: var(--muted); font-size: 11px; font-weight: 700; }
.kpi-card strong { display: block; margin: 11px 0 5px; color: var(--ink); font: 700 25px/1 Georgia, serif; }
.kpi-card small { color: var(--muted); font-size: 10px; }
.kpi-card.violet { color: var(--violet); border-top: 3px solid var(--violet); }
.kpi-card.green { color: var(--green); border-top: 3px solid var(--green); }
.kpi-card.red { color: var(--red); border-top: 3px solid var(--red); }
.kpi-card.amber { color: var(--amber); border-top: 3px solid var(--amber); }
.kpi-card.blue { color: var(--blue); border-top: 3px solid var(--blue); }
.workspace-card { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 28px rgba(35, 44, 76, .05); }
.workspace-heading { padding: 22px 24px 17px; display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.workspace-heading .muted { max-width: 720px; margin: 7px 0 0; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; }
.secondary-button { padding: 9px 14px; border: 1px solid #d8dce7; border-radius: 10px; background: #fff; color: #4e5870; cursor: pointer; font-size: 11px; font-weight: 700; white-space: nowrap; }
.secondary-button.active { border-color: var(--violet); background: var(--violet-soft); color: #5548bb; }
.filters { padding: 15px 24px; display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: #fafbfc; }
.filters select, .filters input { width: 100%; height: 38px; padding: 0 11px; border: 1px solid #d9dde7; border-radius: 9px; outline: none; background: #fff; color: var(--ink); font-size: 12px; }
.filters select:focus, .filters input:focus { border-color: #9388eb; box-shadow: 0 0 0 3px rgba(107,92,231,.1); }
.table-wrap { position: relative; overflow-x: auto; }
table { width: 100%; min-width: 1180px; border-collapse: collapse; font-size: 11px; }
th { padding: 12px 10px; color: #707a90; background: #fbfbfd; border-bottom: 1px solid var(--line); text-align: left; font-size: 9px; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
th:first-child, td:first-child { padding-left: 24px; }
th:last-child, td:last-child { padding-right: 18px; }
td { padding: 14px 10px; border-bottom: 1px solid #edf0f4; vertical-align: middle; white-space: nowrap; }
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #faf9ff; }
tbody tr:last-child td { border-bottom: 0; }
.row-blocked { background: #fffafb; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.metric { color: #303b57; font-size: 13px; font-weight: 750; }
.product-cell { min-width: 170px; }
.product-cell strong { display: block; margin-bottom: 4px; font-size: 12px; }
.product-cell span, .dq-caption { color: var(--muted); font-size: 9px; }
.positive { color: var(--amber); }
.negative { color: var(--green); }
.flow-mark { display: block; margin-top: 3px; color: var(--amber); font-size: 8px; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 999px; font-size: 9px; font-weight: 800; }
.status-badge i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.status-shortage { color: #b6303b; background: var(--red-soft); }
.status-excess { color: #9c620f; background: var(--amber-soft); }
.status-within_norm { color: #13805b; background: var(--green-soft); }
.status-no_norm { color: #5b667a; background: #edf0f4; }
.status-data_quality { color: #2f6fae; background: var(--blue-soft); }
.status-no_consumption { color: #5b667a; background: #eef0f5; }
.status-aggregate { color: #5b667a; background: #eef0f5; }
.dq-caption { display: block; margin-top: 4px; }
.row-action { width: 28px; height: 28px; border: 0; border-radius: 8px; background: var(--violet-soft); color: var(--violet); cursor: pointer; }
.empty-state { padding: 46px; text-align: center; color: var(--muted); }
.load-state { padding: 28px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--muted); text-align: center; font-size: 12px; }
.load-error { border-color: #f1c7cb; background: var(--red-soft); color: #a52f3a; }
.stale-warning { margin-bottom: 14px; border-color: #f0d6a8; background: var(--amber-soft); color: #8b5b15; }
.method-note { margin-top: 16px; padding: 17px 20px; display: flex; gap: 13px; border: 1px solid #dfe4ee; border-radius: 13px; background: #fafbfe; }
.method-note p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.method-icon { width: 24px; height: 24px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: var(--blue-soft); color: var(--blue); font-weight: 800; }
code { padding: 2px 5px; border-radius: 4px; background: #eef0f5; font-size: .95em; }
dialog { width: min(900px, calc(100vw - 48px)); max-height: calc(100vh - 48px); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 28px 90px rgba(12,16,40,.25); }
dialog::backdrop { background: rgba(20,24,48,.5); backdrop-filter: blur(3px); }
.dialog-shell { min-width: 0; }
.dialog-shell > header { position: sticky; top: 0; z-index: 2; padding: 22px 24px 18px; display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 1px solid var(--line); background: #fff; }
#detail-content { padding: 4px 24px 26px; }
.detail-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.detail-section:last-child { border-bottom: 0; }
.kpi-card.gray { color: #5b667a; border-top: 3px solid #9aa3b5; }
.formula-box { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 14px; align-items: center; padding: 18px; border-radius: 13px; background: #f7f6ff; }
.formula-box div { display: flex; flex-direction: column; gap: 5px; }
.formula-box span, .flow-card span { color: var(--muted); font-size: 10px; }
.formula-box strong { font-size: 17px; }
.formula-box small { color: #8a91a2; font-size: 9px; }
.formula-box b { color: #8f86cc; }
.flow-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.flow-card { padding: 12px; border: 1px solid #dcd8ff; border-radius: 10px; background: #faf9ff; }
.flow-card strong { display: block; margin-top: 6px; font-size: 13px; }
.flow-card.muted-flow { border-color: var(--line); background: #fafbfc; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; }
.detail-list { margin: 0; }
.detail-list div { padding: 8px 0; display: flex; justify-content: space-between; gap: 18px; border-bottom: 1px dashed #e6e8ed; }
.detail-list dt { color: var(--muted); font-size: 10px; }
.detail-list dd { margin: 0; text-align: right; font-size: 10px; font-weight: 650; }
.dq-list { display: grid; gap: 8px; }
.dq-item { padding: 12px; display: grid; grid-template-columns: 78px 1fr; gap: 12px; border-radius: 10px; background: #f8f9fb; }
.dq-item > span { font-size: 9px; font-weight: 800; text-transform: uppercase; }
.dq-item strong { font-size: 10px; }
.dq-item p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.severity-error > span { color: var(--red); }
.severity-warning > span { color: var(--amber); }
.severity-info > span { color: var(--blue); }
.empty-copy { color: var(--muted); font-size: 11px; }
.access-shell { width: min(430px, calc(100vw - 48px)); padding: 28px; }
.access-shell .muted { margin: 10px 0 20px; }
.access-shell label > span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.access-shell input { width: 100%; height: 42px; padding: 0 12px; border: 1px solid #d9dde7; border-radius: 9px; }
.primary-button { width: 100%; margin-top: 18px; padding: 11px 16px; border: 0; border-radius: 10px; background: var(--violet); color: #fff; font-weight: 750; cursor: pointer; }
.access-error { margin: 10px 0 0; color: var(--red); font-size: 11px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1280px) {
  .app-shell { grid-template-columns: 190px 1fr; }
  .sidebar { padding-inline: 16px; }
  main { padding-inline: 24px; }
  .kpi-grid { gap: 8px; }
  .kpi-card { padding: 14px; }
}

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 76px minmax(0, 1fr); }
  .sidebar { padding: 22px 12px; grid-template-columns: 1fr; justify-items: center; }
  .sidebar-copy { display: none; }
  .sidebar nav { width: 100%; }
  .nav-item { justify-content: center; padding: 0; font-size: 0; }
  .nav-item span { font-size: 18px; }
  .nav-item em { display: none; }
  .sidebar-note { padding: 11px; justify-content: center; }
  .sidebar-note div { display: none; }
  main { padding-inline: 18px; }
  .context-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  .topbar { min-height: 88px; }
  .topbar-actions .icon-button, .topbar-actions .avatar { display: none; }
  h1 { font-size: 23px; }
  .demo-badge { font-size: 9px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .workspace-heading { flex-direction: column; }
  .filters { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .flow-grid { grid-template-columns: repeat(2, 1fr); }
  .formula-box { grid-template-columns: 1fr; }
  .formula-box b { display: none; }
  .two-columns { grid-template-columns: 1fr; }
}

/* ---- pilot hardening additions ---- */
.demo-badge.stale-data { border-color: #f0d6a8; background: var(--amber-soft); color: #8b5b15; }
.null-value { color: #9aa3b5; }
.store-cell { color: #4e5870; font-size: 11px; }
.norm-cell { color: #4b5a78; }
.norm-banner { margin: 14px 0 0; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; border: 1px solid #e0dcff; border-radius: 12px; background: var(--violet-soft); }
.norm-banner p { flex: 1 1 320px; margin: 0; color: #4b4590; font-size: 11px; line-height: 1.5; }
.norm-badge { display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 999px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.norm-badge.pilot { background: #6b5ce7; color: #fff; }
.norm-badge.monitor { border: 1px solid #6b5ce7; background: #fff; color: #5548bb; }
.workspace-heading.compact { padding-bottom: 8px; }
.store-overview { margin: 0 0 16px; }
.overview-table { min-width: 0; }
.result-count { margin: 0; padding: 10px 24px; color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line); }
.dq-chip { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 9px; font-weight: 800; white-space: nowrap; }
.dq-blocked { color: #a52f3a; background: var(--red-soft); }
.dq-attention { color: #8b5b15; background: var(--amber-soft); }
.dq-ok { color: #13805b; background: var(--green-soft); }
.badge-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.status-reason { margin: 12px 0 0; font-size: 12px; line-height: 1.5; }
.kpi-steps { margin: 0 0 10px; padding-left: 20px; font-size: 12px; line-height: 1.7; }
.dq-group { margin-bottom: 14px; }
.dq-group h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.dq-group-blocked h4 { color: var(--red); }
.dq-group-attention h4 { color: var(--amber); }
.dq-group-info h4 { color: var(--blue); }
.dq-item { grid-template-columns: 1fr; }
.dq-item strong { font-size: 12px; }
.dq-item p { font-size: 11px; line-height: 1.5; }
.dq-item .dq-action { color: #4e5870; }
.dq-item code { display: inline-block; margin-top: 6px; color: #5b667a; font-size: 9px; }
.severity-error { border-left: 3px solid var(--red); }
.severity-warning { border-left: 3px solid var(--amber); }
.severity-info { border-left: 3px solid var(--blue); }
.technical summary { cursor: pointer; color: var(--muted); font-size: 11px; font-weight: 700; }
.technical .detail-list { margin-top: 10px; }
.formula-line code { font-size: 12px; }
#help-content { padding: 4px 24px 26px; }
#help-content ul { margin: 8px 0 0; padding-left: 20px; font-size: 12px; line-height: 1.7; }
#help-content p { margin: 6px 0; font-size: 12px; line-height: 1.6; }
th[data-tip] { cursor: help; text-decoration: underline dotted #b9bfce; text-underline-offset: 3px; }
.load-error p { margin: 8px 0 0; }

@media (max-width: 1050px) {
  .context-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .context-strip { grid-template-columns: 1fr; }
  .filters { grid-template-columns: 1fr; }
  .result-count { padding-inline: 16px; }
}

/* compact operational table */
#turnover-table th { white-space: normal; line-height: 1.25; vertical-align: bottom; padding: 10px 6px; }
#turnover-table td { padding: 11px 6px; }
#turnover-table .product-cell { min-width: 150px; max-width: 210px; white-space: normal; }
#turnover-table .store-cell { max-width: 96px; white-space: normal; line-height: 1.3; }
#turnover-table .status-badge { white-space: nowrap; }
#turnover-table th:first-child, #turnover-table td:first-child { padding-left: 18px; }

/* small screens: header actions wrap instead of widening the page */
.topbar { flex-wrap: wrap; gap: 10px 16px; padding-block: 14px; }
.topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
.overview-table th, .overview-table td { padding: 10px 8px; }

.show-more-row { padding: 14px 24px; text-align: center; }
.show-more-row[hidden], #show-more[hidden] { display: none; }

/* keyboard focus, skip link, quick views, untrusted-text containment */
:focus-visible { outline: 3px solid #6b5ce7; outline-offset: 2px; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 20; padding: 10px 14px; border-radius: 8px; background: #172033; color: #fff; font-size: 12px; text-decoration: none; }
.skip-link:focus { top: 12px; }
.quick-views { padding: 12px 24px 0; display: flex; flex-wrap: wrap; gap: 8px; }
.quick-chip { padding: 7px 12px; border: 1px solid #d8dce7; border-radius: 999px; background: #fff; color: #4e5870; font-size: 11px; font-weight: 700; cursor: pointer; }
.quick-chip b { margin-left: 4px; color: var(--violet); }
.quick-chip.active { border-color: var(--violet); background: var(--violet-soft); color: #4b3fb0; }
.norm-legend { margin: 0; padding: 10px 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); background: #faf9ff; color: #4b4590; font-size: 11px; }
.product-cell strong, .product-cell span, .store-cell, .context-strip strong, .dq-item strong, .detail-list dd, #detail-title, #detail-subtitle { overflow-wrap: anywhere; word-break: break-word; unicode-bidi: isolate; }
.product-cell { max-width: 210px; }
dialog { max-width: calc(100vw - 24px); }
#detail-content { overflow-wrap: anywhere; }
