/* /admin, Métricas tab (js/metrics.js). Builds on styles.css tokens; light/dark follow the system.
   Widths and the tooltip position come from CSS custom properties set via CSSOM (CSP-safe). */

.mx {
  --mx-c1: #C2410C; --mx-c2: #0F766E; --mx-c3: #1D4ED8; --mx-c4: #7C3AED; --mx-c5: #15803D; --mx-c6: #BE185D;
  --mx-grid: rgba(15, 27, 45, 0.08);
  --mx-sk: rgba(15, 27, 45, 0.07);
  display: grid; gap: 14px; min-width: 0;
}
@media (prefers-color-scheme: dark) {
  .mx {
    --mx-c1: #F28C28; --mx-c2: #2DD4BF; --mx-c3: #60A5FA; --mx-c4: #A78BFA; --mx-c5: #4ADE80; --mx-c6: #F472B6;
    --mx-grid: rgba(148, 163, 184, 0.14);
    --mx-sk: rgba(148, 163, 184, 0.12);
  }
}
.mx h2 { margin: 0; }
.mx .mx-lead { margin: -8px 0 0; }
[data-c="1"] { --mx-c: var(--mx-c1); }
[data-c="2"] { --mx-c: var(--mx-c2); }
[data-c="3"] { --mx-c: var(--mx-c3); }
[data-c="4"] { --mx-c: var(--mx-c4); }
[data-c="5"] { --mx-c: var(--mx-c5); }
[data-c="6"] { --mx-c: var(--mx-c6); }

/* ---------- filter bar ---------- */
.mx-filters { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.mx-range { display: flex; flex-wrap: wrap; align-items: end; gap: 8px 12px; }
.mx-range > .mx-label { flex-basis: 100%; }
.mx-label { font-weight: 600; font-size: 0.82rem; color: var(--muted); }
.mx-presets { display: flex; flex-wrap: wrap; gap: 6px; }
.mx-preset {
  min-height: 40px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: 600 0.88rem/1.1 var(--font-body); cursor: pointer;
}
.mx-preset:hover { border-color: var(--text); }
.mx-preset[aria-pressed="true"] { background: var(--navy); color: var(--on-navy); border-color: var(--navy); box-shadow: inset 0 -3px 0 var(--orange); }
.mx-custom { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.mx-custom[hidden] { display: none; }
.mx-custom .mx-field { width: 170px; }
.mx-selects { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; align-items: end; }
.mx-field { display: grid; gap: 4px; min-width: 0; }
.mx-field .mx-select, .mx-field .mx-date { min-height: 40px; padding: 8px 10px; font-size: 0.92rem; }
.mx-field select:disabled { opacity: 0.55; }
.mx-sep { display: none; }
.mx-field-btn { align-self: end; }
.mx-reset { width: 100%; }
.mx-reset:disabled { opacity: 0.45; cursor: not-allowed; }
@media (min-width: 640px) {
  .mx-selects { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1000px) {
  .mx-selects { grid-template-columns: repeat(2, minmax(96px, 0.6fr)) 1px repeat(3, minmax(0, 1.35fr)) auto; }
  .mx-sep { display: block; align-self: stretch; background: var(--border); margin: 6px 0; }
  .mx-reset { width: auto; }
}

/* ---------- notices, meta, errors ---------- */
.mx-status:empty { display: none; }
.mx-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; margin: 0; color: var(--muted); font-size: 0.86rem; }
.mx-fresh { font-variant-numeric: tabular-nums; }
.mx-notice { margin: 0; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--orange); background: var(--orange-soft); color: var(--text); font-weight: 500; font-size: 0.92rem; }
.mx-notice-quiet { border-color: var(--border); background: var(--surface-2); }
.mx-error { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 14px; border: 1px solid var(--no); border-radius: 10px; }
.mx-error .panel-msg { margin: 0; }
.mx-body { display: grid; gap: 16px; min-width: 0; }
.mx-body.mx-stale > :not(.mx-error) { opacity: 0.55; transition: opacity 0.2s; }

/* ---------- cards ---------- */
.mx-card { min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.mx-card-title { margin: 0 0 10px; font-size: 1rem; }
.mx-section { margin: 8px 0 -4px; font-size: 1.1rem; }
.mx-note { margin: 6px 0 0; color: var(--muted); font-size: 0.84rem; }
.mx-empty, .mx-unavail { margin: 0; color: var(--muted); font-size: 0.9rem; }
.mx-unavail { padding: 10px 12px; border: 1px dashed var(--border); border-radius: 10px; }
.mx-two, .mx-grid { display: grid; gap: 16px; min-width: 0; }
@media (min-width: 900px) {
  .mx-two { grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); }
  .mx-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- KPIs ---------- */
.mx-kpis { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .mx-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .mx-kpis { grid-template-columns: repeat(7, minmax(0, 1fr)); } }
.mx-kpi { display: grid; align-content: start; gap: 4px; min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.mx-kpi-label { margin: 0; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.mx-kpi-value { margin: 0; font: 700 clamp(1.4rem, 5vw, 1.75rem)/1.1 var(--font-head); letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mx-kpi[data-off] .mx-kpi-value { color: var(--muted); }
.mx-kpi-sub { margin: 0; font-size: 0.76rem; color: var(--muted); overflow-wrap: anywhere; }
.mx-spark { display: block; width: 100%; height: 28px; }
.mx-spark-line { fill: none; stroke: var(--orange); stroke-width: 1.75; }
.mx-spark-area { fill: var(--orange-soft); stroke: none; }
.mx-spark-empty { border-bottom: 1px dashed var(--border); height: 14px; margin-bottom: 14px; }
.mx-rate { display: block; height: 8px; margin: 10px 0; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.mx-rate-fill { display: block; height: 100%; width: var(--mx-w, 0%); background: var(--yes); border-radius: inherit; }

/* ---------- funnel ---------- */
.mx-funnel { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 12px; counter-reset: mxstep; }
.mx-step { display: grid; gap: 4px; }
.mx-step-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mx-step-name { font-weight: 600; font-size: 0.92rem; }
.mx-step-name::before { counter-increment: mxstep; content: counter(mxstep) ". "; color: var(--muted); font-weight: 500; }
.mx-step-count { font: 700 1.05rem/1 var(--font-head); font-variant-numeric: tabular-nums; }
.mx-step-track { height: 14px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.mx-step-fill { display: block; height: 100%; width: var(--mx-w, 0%); min-width: 2px; border-radius: inherit; background: linear-gradient(90deg, var(--orange), var(--orange-hover)); }
.mx-step-rates { margin: 0; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- time series ---------- */
.mx-toggles { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.mx-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: transparent; color: var(--muted); font: 500 0.84rem/1.1 var(--font-body); cursor: pointer;
}
.mx-toggle[aria-pressed="true"] { color: var(--text); border-color: var(--mx-c); background: var(--surface-2); }
.mx-toggle[aria-pressed="false"] .mx-swatch { background: transparent; border: 2px solid var(--mx-c); }
.mx-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--mx-c, var(--orange)); flex: none; }
.mx-plot-wrap { position: relative; }
.mx-plot { min-height: 200px; border-radius: 8px; touch-action: pan-y; }
.mx-plot:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.mx-chart { display: block; max-width: 100%; }
.mx-grid-line { stroke: var(--mx-grid); stroke-width: 1; }
.mx-axis { fill: var(--muted); font: 500 11px var(--font-body); }
.mx-line { fill: none; stroke: var(--mx-c); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.mx-dot { fill: var(--surface); stroke: var(--mx-c); stroke-width: 2; }
.mx-guide { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.mx-tip {
  position: absolute; top: 4px; left: var(--mx-x, 0px); transform: translateX(10px); z-index: 2; pointer-events: none;
  min-width: 150px; max-width: 220px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); box-shadow: var(--shadow); font-size: 0.8rem;
}
.mx-tip.mx-tip-left { transform: translateX(calc(-100% - 10px)); }
.mx-tip[hidden] { display: none; }
.mx-tip-date { margin: 0 0 4px; font-weight: 600; }
.mx-tip-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.mx-tip-list li { display: flex; align-items: center; gap: 6px; }
.mx-tip-list strong { margin-left: auto; font-variant-numeric: tabular-nums; }
.mx-trend-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-top: 6px; }
.mx-trend-foot .mx-note { margin: 0; }

/* ---------- tables ---------- */
.mx-table-wrap { max-width: 100%; overflow-x: auto; margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; }
.mx-table-wrap[hidden] { display: none; }
.mx-table-wrap:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.mx-card > .mx-table-wrap:first-of-type { margin-top: 0; }
.mx-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.mx-table th, .mx-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.mx-table thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
.mx-table tbody tr:last-child > * { border-bottom: 0; }
.mx-table tbody th { font-weight: 500; }
.mx-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mx-table .mx-num { text-align: right; }
.mx-sort { display: inline-flex; align-items: center; gap: 4px; min-height: 32px; padding: 0 4px; border: 0; background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }
.mx-sort:hover { color: var(--text); }
.mx-sort-ico { font-size: 0.7rem; }
.mx-ch-title { display: block; overflow-wrap: anywhere; min-width: 140px; }
.mx-ch-meta { display: block; color: var(--muted); font-size: 0.76rem; }

.mx-scroll { position: relative; min-width: 0; }
.mx-scroll[data-overflow="1"]::after {
  content: ""; position: absolute; top: 11px; right: 1px; bottom: calc(0.78rem * 1.5 + 7px); width: 36px; pointer-events: none;
  border-radius: 0 10px 10px 0; background: linear-gradient(90deg, transparent, var(--surface));
}
.mx-scroll-hint { margin: 6px 0 0; font-size: 0.78rem; line-height: 1.5; color: var(--muted); text-align: right; }
.mx-scroll-hint[hidden] { display: none; }
.mx-na-legend { margin: -6px 0 0; }
.mx-unfiltered { font-style: italic; }

/* ---------- bar lists and splits ---------- */
.mx-bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.mx-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; font-size: 0.88rem; }
.mx-bar-label { overflow-wrap: anywhere; min-width: 0; }
.mx-path { font-size: 0.82rem; }
.mx-bar-val { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.mx-bar-sub { display: block; font-weight: 400; color: var(--muted); font-size: 0.75rem; }
.mx-bar-track { grid-column: 1 / -1; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.mx-bar-fill { display: block; height: 100%; width: var(--mx-w, 0%); background: var(--mx-c2); border-radius: inherit; }
.mx-split { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--surface-2); margin-bottom: 10px; }
.mx-split-seg { display: block; height: 100%; width: var(--mx-w, 0%); background: var(--mx-c); }
.mx-split-seg[data-c="2"] { background: var(--mx-c2); }
.mx-split-seg[data-c="1"] { background: var(--mx-c1); }
.mx-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 0.9rem; }
.mx-legend li { display: flex; align-items: center; gap: 8px; }
.mx-legend-name { flex: 1; min-width: 0; }
.mx-legend li[data-c="2"] .mx-swatch { background: var(--mx-c2); }
.mx-legend strong { font-variant-numeric: tabular-nums; }
.mx-legend-pct { min-width: 4.5em; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- skeleton ---------- */
.mx-sk { position: relative; overflow: hidden; }
.mx-sk-line, .mx-sk-big { display: block; border-radius: 6px; background: var(--mx-sk); }
.mx-sk-line { height: 10px; width: 70%; }
.mx-sk-big { height: 26px; width: 50%; margin: 6px 0; }
.mx-sk-block { min-height: 220px; background: var(--surface); }
.mx-sk::after {
  content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--mx-sk), transparent); animation: mx-shimmer 1.4s infinite;
}
@keyframes mx-shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
  .mx-sk::after { animation: none; }
  .mx-body.mx-stale > * { transition: none; }
}

@media (max-width: 479px) {
  .mx-filters { padding: 12px; }
  .mx-card { padding: 14px 12px; }
  .mx-custom .mx-field { width: calc(50% - 6px); }
  .mx-preset { padding: 6px 10px; }
}
@media (max-width: 419px) {
  .mx-selects { grid-template-columns: minmax(0, 1fr); }
}
