/* explainable.css — framework-free explainable-recommendation component.
   Token-only styling → auto light/dark via the panel's :root / [data-theme="light"].
   No CDN, no lib. Pairs with explainable.js (window.Explain). */

/* ── token shim: map the component's token names onto content-panel's :root vars.
   Scoped to the component roots (.exr / .exp-root) so it never leaks to hub
   sections that use bare --text / --surface-2 / --border-strong with fallbacks. */
.exr, .exp-root {
  --text: var(--text-primary);
  --text-dim: var(--text-secondary);
  --surface-hover: var(--sidebar-hover);
  --surface-2: rgba(255, 255, 255, 0.05);
  --card: var(--rail-bg);
  --border-strong: rgba(255, 255, 255, 0.18);
  --radius-sm: var(--r-sm);
  --red: var(--error);
  --yellow: var(--warning);
  --blue: var(--info);
  --green: var(--success);
}
[data-theme="light"] .exr,
[data-theme="light"] .exp-root {
  --surface-2: rgba(0, 0, 0, 0.04);
  --border-strong: rgba(0, 0, 0, 0.15);
}

/* ── compact list row (Explain.row) ─────────────────────────── */
.exr {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s ease;
}
.exr:first-child { border-top: 0; }
.exr:hover, .exr:focus-visible { background: var(--surface-hover); outline: none; }
.exr:focus-visible { box-shadow: inset 2px 0 0 var(--accent); }
.exr-dot {
  flex: 0 0 auto;
  width: 8px; height: 8px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--text-dim);
}
.exr[data-urgency="critical"] .exr-dot { background: var(--red); }
.exr[data-urgency="high"]     .exr-dot { background: var(--yellow); }
.exr[data-urgency="medium"]   .exr-dot { background: var(--blue); }
.exr[data-urgency="low"]      .exr-dot { background: var(--text-dim); }
.exr-main { flex: 1 1 auto; min-width: 0; }
.exr-title {
  font-weight: 600;
  color: var(--text);
  font-size: 0.95em;
  line-height: 1.3;
}
.exr-sub {
  margin-top: 2px;
  font-size: 0.82em;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.exr-tag { color: var(--text-tertiary); }
.exr-aside { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.exr-key {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78em;
  color: var(--text);
  white-space: nowrap;
}
.exr-key b { font-weight: 700; }
.exr-key span { color: var(--text-dim); font-weight: 500; }
.exr-why {
  font-size: 0.78em;
  color: var(--accent);
  border-bottom: 1px dashed var(--accent);
  line-height: 1;
  padding-bottom: 1px;
}
.exr-acts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

/* ── slide-in drawer (Explain.openPanel) ────────────────────── */
.exp-root {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
}
.exp-root.open { display: block; }
.exp-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.18s ease;
}
.exp-root.open .exp-backdrop { opacity: 1; }
.exp-drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 94vw);
  background: var(--card);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-overflow-scrolling: touch;
}
.exp-root.open .exp-drawer { transform: translateX(0); }
.exp-x {
  position: sticky;
  top: 0;
  float: right;
  margin: 10px 12px 0 0;
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.exp-x:hover { color: var(--text); border-color: var(--border-strong); }
.exp-body { padding: 18px 20px 28px; }

.exp-head { margin: 0 30px 4px 0; }
.exp-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.exp-badge {
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
}
.exp-badge[data-urgency="critical"] { color: var(--red); border-color: var(--red); background: rgba(255,77,77,0.10); }
.exp-badge[data-urgency="high"]     { color: var(--yellow); border-color: var(--yellow); background: rgba(255,184,0,0.10); }
.exp-badge[data-urgency="medium"]   { color: var(--blue); border-color: var(--blue); background: rgba(0,209,193,0.10); }
.exp-badge[data-urgency="low"]      { color: var(--text-dim); }
.exp-conf { font-size: 0.72em; color: var(--text-dim); }
.exp-title { font-size: 1.15em; font-weight: 700; color: var(--text); line-height: 1.3; }
.exp-ctx { margin-top: 4px; font-size: 0.8em; color: var(--text-dim); }
.exp-ctx b { color: var(--text); font-weight: 600; }

.exp-sec { margin-top: 18px; }
.exp-h {
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.exp-h::before {
  content: "";
  width: 3px; height: 12px;
  border-radius: 2px;
  background: var(--accent);
}
.exp-sec[data-kind="not"] .exp-h::before { background: var(--red); }
.exp-sec[data-kind="working"] .exp-h::before { background: var(--green); }
.exp-sec[data-kind="action"] .exp-h::before { background: var(--blue); }
.exp-sec[data-kind="impact"] .exp-h::before { background: var(--yellow); }
.exp-p { font-size: 0.9em; line-height: 1.5; color: var(--text); }
.exp-p.muted { color: var(--text-dim); font-style: italic; }
.exp-action {
  font-size: 0.95em;
  font-weight: 600;
  color: var(--text);
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--blue);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

/* evidence / metrics table */
.exp-metrics { width: 100%; border-collapse: collapse; font-size: 0.85em; }
.exp-metrics td { padding: 5px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.exp-metrics tr:last-child td { border-bottom: 0; }
.exp-metrics td.k { color: var(--text-dim); white-space: nowrap; }
.exp-metrics td.v { color: var(--text); font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.exp-trace {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78em;
  color: var(--text-dim);
  line-height: 1.5;
  word-break: break-word;
}
.exp-trace code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  font-size: 0.95em;
}

.exp-actions {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (prefers-reduced-motion: reduce) {
  .exp-backdrop, .exp-drawer { transition: none; }
}
