/* EMMCB — reusable components
   Depth comes from surface contrast and hairlines, not shadow. */

/* ---- Panel ----------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.panel__head {
  display: flex;
  align-items: flex-start;
  gap: var(--s4);
  padding: var(--s5) var(--s6) var(--s4);
  border-bottom: 1px solid var(--line-faint);
  flex: none;
}
.panel__titles { min-width: 0; flex: 1 1 auto; }
.panel__title {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-snug);
}
.panel__sub {
  margin-top: 4px;
  font-size: var(--fs-xs);
  color: var(--ink-3);
  line-height: var(--lh-snug);
  max-width: var(--measure);
}
.panel__tools { flex: none; display: flex; align-items: center; gap: var(--s2); }
.panel__body { padding: var(--s6); min-width: 0; flex: 1 1 auto; }
.panel__body--flush { padding: 0; }
.panel__body--tight { padding: var(--s3) var(--s5) var(--s4); }
.panel__foot {
  flex: none;
  padding: var(--s4) var(--s6);
  border-top: 1px solid var(--line-faint);
  background: transparent;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: var(--fs-xs);
  color: var(--ink-2);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
}

/* ---- Buttons --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  height: 30px;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:active { background: var(--surface-3); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.btn svg { width: 14px; height: 14px; flex: none; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink-invert);
  font-weight: 600;
}
.btn--primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn--primary:active { background: var(--accent-ink); }

.btn--ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn--ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }

.btn--sm { height: 24px; padding: 0 var(--s2); font-size: var(--fs-tiny); }
.btn--icon { width: 30px; padding: 0; }
.btn--sm.btn--icon { width: 24px; }

/* ---- Segmented control ---------------------------------------------- */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 0 var(--s3);
  height: 28px;
  font-size: var(--fs-tiny);
  font-weight: 500;
  color: var(--ink-2);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button:hover { background: var(--surface-2); color: var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--ink-invert); font-weight: 600; }

/* ---- Select / input -------------------------------------------------- */
.field { display: inline-flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > label { font-size: var(--fs-micro); font-weight: 500; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); }

.select, .input {
  height: 30px;
  padding: 0 var(--s3);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--fs-xs);
  color: var(--ink);
  min-width: 0;
  transition: border-color var(--dur-fast) var(--ease);
}
.select:hover, .input:hover { border-color: var(--ink-3); }
.select:focus, .input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
textarea.input { height: auto; padding: var(--s2) var(--s3); line-height: var(--lh-snug); resize: vertical; }

.switch { display: inline-flex; align-items: center; gap: var(--s3); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch__track {
  width: 34px; height: 19px; flex: none;
  border-radius: 10px;
  background: var(--line-strong);
  position: relative;
  transition: background var(--dur) var(--ease);
}
.switch__track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--surface);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(15px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--accent-wash); }

/* ---- Badges / pills -------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 19px; padding: 0 7px;
  border-radius: 3px;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge[data-tone="pos"]  { background: var(--pos-wash);  color: var(--pos); }
.badge[data-tone="neg"]  { background: var(--neg-wash);  color: var(--neg); }
.badge[data-tone="warn"] { background: var(--warn-wash); color: var(--warn); }
.badge[data-tone="accent"] { background: var(--accent-wash); color: var(--accent-ink); }
.badge[data-tone="plain"] { background: transparent; color: var(--ink-3); border: 1px solid var(--line); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot[data-tone="pos"] { background: var(--pos); }
.dot[data-tone="neg"] { background: var(--neg); }
.dot[data-tone="warn"] { background: var(--warn); }
.dot[data-tone="accent"] { background: var(--accent); }

.delta { font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta[data-dir="up"]   { color: var(--pos); }
.delta[data-dir="down"] { color: var(--neg); }
.delta[data-dir="flat"] { color: var(--ink-3); }
/* Direction is not the same as goodness — a rising stockout count is bad. */
.delta[data-sense="bad"]  { color: var(--neg); }
.delta[data-sense="good"] { color: var(--pos); }

/* ---- KPI -------------------------------------------------------------- *
   Headline metrics are set editorially, not as cards. A grid of bordered
   boxes reads as a row of tiles and flattens the hierarchy — every metric
   shouting equally at the same weight. Here the strip sits directly on the
   page, separated by air rather than rules, and the number carries it.
   Instructions §6 and §10. */
.kpirow {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(224px, 1fr));
  gap: var(--s6) var(--s8);
  padding: var(--s2) 0 var(--s6);
  border-bottom: 1px solid var(--line);
}
.kpi {
  padding: 0;
  border: 0;
  background: none;
  min-width: 0;
  display: flex; flex-direction: column; gap: 6px;
  text-align: left;
  position: relative;
}
/* No hover fill. A tint on a borderless block reads as a rendering fault;
   the affordance is the value colouring and the action beneath it. */
.kpi:hover .kpi__value { color: var(--accent-ink); }
.kpi[aria-pressed="true"] { padding-left: var(--s3); }
.kpi[aria-pressed="true"]::before {
  content: ""; position: absolute; inset: 2px auto 2px 0; width: 2px;
  background: var(--accent); border-radius: 1px;
}
.kpi__label {
  font-size: var(--fs-micro); font-weight: 500;
  letter-spacing: var(--tracking-label); text-transform: uppercase;
  color: var(--ink-3);
  display: flex; align-items: center; gap: var(--s2);
}
.kpi__value {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
  line-height: 1.04;
  transition: color var(--dur-fast) var(--ease);
}
.kpi__value small { font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.kpi__meta { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.kpi__period { font-size: var(--fs-xs); color: var(--ink-3); }
.kpi__spark { margin-top: 4px; height: 22px; opacity: 0.7; transition: opacity var(--dur-fast) var(--ease); }
.kpi:hover .kpi__spark { opacity: 1; }
.kpi__why {
  font-size: var(--fs-xs);
  color: var(--ink-2);
  line-height: var(--lh-snug);
  margin-top: 3px;
  max-width: 36ch;
}

/* ---- Signal → Explanation → Action ----------------------------------- */
.insight {
  display: grid;
  grid-template-columns: 3px 1fr;
  gap: var(--s4);
  padding: var(--s4) var(--s5) var(--s4) 0;
  border-bottom: 1px solid var(--line);
}
.insight:last-child { border-bottom: 0; }
.insight__rail { background: var(--line-strong); border-radius: 0 2px 2px 0; }
.insight[data-sev="critical"] .insight__rail { background: var(--sev-critical); }
.insight[data-sev="high"]     .insight__rail { background: var(--sev-high); }
.insight[data-sev="medium"]   .insight__rail { background: var(--sev-medium); }
.insight[data-sev="low"]      .insight__rail { background: var(--sev-low); }
.insight[data-sev="ok"]       .insight__rail { background: var(--sev-ok); }
.insight__main { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.insight__signal {
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: -0.005em;
  display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap;
}
.insight__why { font-size: var(--fs-xs); color: var(--ink-2); line-height: var(--lh-snug); }
.insight__why b { color: var(--ink); font-weight: 600; }
.insight__foot {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  margin-top: 3px;
}
.insight__action {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--accent-ink);
  background: none; border: 0; padding: 0;
  display: inline-flex; align-items: center; gap: 4px;
}
.insight__action:hover { text-decoration: underline; text-underline-offset: 2px; }
.insight__source {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--ink-3);
  letter-spacing: -0.01em;
}

/* ---- Table ----------------------------------------------------------- */
.tablewrap { overflow: auto; min-width: 0; }
table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-xs);
}
/* The header is a line of labels, not a filled band. A grey bar across the
   top of every table is a great deal of ink for information the reader
   already has from the column beneath it. */
table.data th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  padding: var(--s3) var(--s4) var(--s2);
  text-align: left;
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: var(--tracking-label);
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
  user-select: none;
}
table.data th[data-sortable] { cursor: pointer; }
table.data th[data-sortable]:hover { color: var(--ink); }
table.data th .sortmark { opacity: 0; margin-left: 4px; font-size: 9px; }
table.data th[aria-sort] .sortmark { opacity: 1; color: var(--accent); }
table.data td {
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line-faint);
  color: var(--ink);
  vertical-align: middle;
  white-space: nowrap;
}
table.data td.wrap { white-space: normal; min-width: 220px; line-height: var(--lh-snug); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr { transition: background var(--dur-fast) var(--ease); }
table.data tbody tr:hover { background: var(--surface-inset); }
table.data tbody tr[data-selected="true"] { background: var(--accent-wash); }
table.data tbody tr.is-expandable { cursor: pointer; }
table.data .cell-sub { display: block; font-size: var(--fs-micro); color: var(--ink-3); }
table.data tfoot td {
  background: transparent;
  border-top: 1px solid var(--line-strong);
  border-bottom: 0;
  font-weight: 600;
}
.table-detail td {
  background: var(--surface-inset);
  padding: var(--s4) var(--s4) var(--s5);
  white-space: normal;
}

/* Inline bar inside a table cell — comparison without another chart */
.cellbar { display: flex; align-items: center; gap: var(--s2); justify-content: flex-end; }
.cellbar__track { width: 62px; height: 5px; background: var(--surface-3); border-radius: 3px; overflow: hidden; flex: none; }
.cellbar__fill { height: 100%; background: var(--accent); border-radius: 3px; }
.cellbar__fill[data-tone="neg"] { background: var(--neg); }
.cellbar__fill[data-tone="warn"] { background: var(--warn); }
.cellbar__fill[data-tone="pos"] { background: var(--pos); }
.cellbar__fill[data-tone="mute"] { background: var(--ink-3); }

/* ---- Alerts / activity ---------------------------------------------- */
.feed { display: flex; flex-direction: column; }
.feed__item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--s3);
  align-items: baseline;
  padding: var(--s3) var(--s5);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-xs);
}
.feed__item:last-child { border-bottom: 0; }
.feed__item:hover { background: var(--surface-2); }
.feed__time { font-family: var(--font-mono); font-size: var(--fs-micro); color: var(--ink-3); white-space: nowrap; }
.feed__text { min-width: 0; line-height: var(--lh-snug); color: var(--ink-2); }
.feed__text b { color: var(--ink); font-weight: 600; }
.feed__tag { justify-self: end; }

/* ---- Definition list (compact stats) --------------------------------- */
.deflist { display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s4); align-items: baseline; }
.deflist dt { font-size: var(--fs-xs); color: var(--ink-2); }
.deflist dd { margin: 0; font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.deflist dd.mono { font-weight: 500; }

/* ---- Meter ----------------------------------------------------------- */
.meter { display: flex; flex-direction: column; gap: 5px; }
.meter__head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); }
.meter__name { font-size: var(--fs-xs); color: var(--ink-2); }
.meter__val { font-size: var(--fs-xs); font-weight: 600; font-variant-numeric: tabular-nums; }
.meter__track { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; position: relative; }
.meter__fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width var(--dur-slow) var(--ease); }
.meter__fill[data-tone="pos"] { background: var(--pos); }
.meter__fill[data-tone="warn"] { background: var(--warn); }
.meter__fill[data-tone="neg"] { background: var(--neg); }
.meter__target { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--ink); }

/* ---- Legend ---------------------------------------------------------- */
.legend { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; font-size: var(--fs-tiny); color: var(--ink-2); }
.legend__key { display: inline-flex; align-items: center; gap: 6px; }
.legend__swatch { width: 9px; height: 9px; border-radius: 2px; background: var(--series-1); flex: none; }
.legend__swatch[data-shape="line"] { height: 2px; width: 14px; border-radius: 1px; }
.legend__swatch[data-shape="dash"] {
  height: 0; width: 14px; border-radius: 0;
  border-top: 2px dashed var(--series-3); background: none;
}

/* ---- Empty state ----------------------------------------------------- */
.empty {
  padding: var(--s8) var(--s5);
  text-align: center;
  color: var(--ink-3);
  font-size: var(--fs-xs);
}
.empty b { display: block; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 600; margin-bottom: 4px; }

/* ---- Toast ----------------------------------------------------------- */
.toasts {
  position: fixed; right: var(--s6); bottom: var(--s6); z-index: 60;
  display: flex; flex-direction: column; gap: var(--s2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  min-width: 260px; max-width: 380px;
  background: var(--ink);
  color: var(--ink-invert);
  border-radius: var(--radius);
  padding: var(--s3) var(--s4);
  font-size: var(--fs-xs);
  line-height: var(--lh-snug);
  box-shadow: var(--shadow-pop);
  display: flex; align-items: flex-start; gap: var(--s3);
  animation: toast-in var(--dur) var(--ease);
}
.toast b { font-weight: 600; }
.toast[data-tone="neg"] { background: var(--neg); }
.toast[data-tone="pos"] { background: var(--pos); }
.toast[data-tone="warn"] { background: var(--warn); }
.toast__dismiss { margin-left: auto; background: none; border: 0; color: inherit; opacity: 0.7; font-size: var(--fs-sm); line-height: 1; padding: 0 2px; }
.toast__dismiss:hover { opacity: 1; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---- Drawer ---------------------------------------------------------- */
.drawer-scrim {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(17, 17, 17, 0.28);
  animation: fade-in var(--dur) var(--ease);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 51;
  width: min(520px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
  animation: drawer-in var(--dur-slow) var(--ease);
}
.drawer__head {
  flex: none;
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: var(--s4);
}
.drawer__body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--s5); }
.drawer__foot { flex: none; padding: var(--s3) var(--s5); border-top: 1px solid var(--line); background: var(--surface-2); display: flex; gap: var(--s2); justify-content: flex-end; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes drawer-in { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- Tooltip (shared by every chart) --------------------------------- */
.charttip {
  position: fixed; z-index: 70;
  pointer-events: none;
  background: var(--ink);
  color: var(--ink-invert);
  border-radius: var(--radius-sm);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-tiny);
  line-height: 1.45;
  box-shadow: var(--shadow-pop);
  max-width: 280px;
}
.charttip b { font-weight: 600; }
.charttip .k { color: rgba(255, 255, 255, 0.62); }
.charttip .v { font-variant-numeric: tabular-nums; }
.charttip hr { border: 0; border-top: 1px solid rgba(255, 255, 255, 0.18); margin: 5px 0; }
