/* Customer Health Score · sobre los tokens del Zebra DS (tokens.css). Solo se agregan
   la rampa ink light, los semánticos de estado y la composición de la app. */
:root {
  --ink-50: #F9FAFB; --ink-100: #F5F7FA; --ink-200: #E5E5E5; --ink-300: #CBD5E1;
  --ink-400: #94A3B8; --ink-500: #737373; --ink-700: #262626; --ink: #0A0A0A;
  /* Semánticos del DS (ds-tokens.json › status). Solo como relleno de dato (punto, barra), nunca texto. */
  --ok: #047857; --warn: #D97706; --bad: #B91C1C;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
:root[data-ds-theme="dark"] { --ok: #10B981; --warn: #F59E0B; --bad: #EF4444; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text);
  background: var(--surface-2); -webkit-font-smoothing: antialiased;
  min-height: 100vh; display: flex; flex-direction: column;
}
h1, h2, h3 { font-weight: 600; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 16px; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
.mono, .eyebrow { font-family: var(--mono); }
.eyebrow { font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.muted { color: var(--text-muted); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--accent); transition: box-shadow .18s var(--ease); }

/* ---------- Topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 1320px; margin: 0 auto; padding: 0 24px; height: 60px; display: flex; align-items: center; gap: 28px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; flex-shrink: 0; }
.logo { height: 18px; width: auto; display: block; }
.logo-sm { height: 14px; }
[data-ds-theme="dark"] .logo { filter: invert(1); }
.brand-sep { width: 1px; height: 18px; background: var(--border-strong); }
.tabs { display: flex; gap: 4px; }
.tabs a {
  text-decoration: none; padding: 6px 12px; border-radius: var(--r-control); color: var(--text-muted);
  font-weight: 500; border: 1px solid transparent; transition: color .18s var(--ease), background .18s var(--ease);
}
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.sync-stamp { font-size: 11px; color: var(--text-muted); letter-spacing: .02em; }
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--r-control);
  background: transparent; border: 1px solid var(--border); cursor: pointer; transition: border-color .18s var(--ease);
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn svg, .btn svg, .ico { width: 16px; height: 16px; stroke: currentColor; stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Layout ---------- */
.page { flex: 1; width: 100%; max-width: 1320px; margin: 0 auto; padding: 32px 24px 64px; position: relative; isolation: isolate; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 24px; position: relative; }
.page-head .sub { margin-top: 6px; color: var(--text-muted); }
.hero-motif { position: absolute; inset: -32px -24px auto auto; height: 180px; width: 40%; }
.foot {
  border-top: 1px solid var(--border); background: var(--bg); padding: 18px 24px;
  display: flex; align-items: center; gap: 14px; justify-content: center; color: var(--text-muted); font-size: 12px; flex-wrap: wrap;
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.card-pad { padding: 20px; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

/* ---------- Controles ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-btn); }
.seg button {
  border: 1px solid transparent; background: transparent; padding: 6px 12px; border-radius: var(--r-control);
  cursor: pointer; color: var(--text-muted); font-weight: 500; white-space: nowrap; transition: color .18s var(--ease), background .18s var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.input, .select {
  height: 36px; padding: 0 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-input); min-width: 0; transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.input:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.input-sm { height: 32px; padding: 0 10px; font-size: 13px; }
.input::placeholder { color: var(--text-muted); }
.btn {
  height: 36px; padding: 0 14px; display: inline-flex; align-items: center; gap: 8px; border-radius: var(--r-btn);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500;
  transition: border-color .18s var(--ease), opacity .18s var(--ease);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.btn-primary:hover { opacity: .88; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { border-color: transparent; background: transparent; }

/* ---------- Resumen ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 18px 20px; }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1.1; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.stat-value small { font-size: 14px; font-weight: 500; color: var(--text-muted); margin-left: 2px; }
.stat-note { margin-top: 4px; color: var(--text-muted); font-size: 12px; }
.dist { display: flex; height: 6px; border-radius: 999px; overflow: hidden; margin-top: 12px; background: var(--surface-2); gap: 2px; }
.dist span { display: block; height: 100%; }

/* ---------- Tabla ---------- */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 960px; }
.grid th {
  text-align: left; font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface);
  position: sticky; top: 0;
}
.grid th:first-child { border-top-left-radius: var(--r-card); }
.grid th:last-child { border-top-right-radius: var(--r-card); }
.grid th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.grid th button:focus-visible { box-shadow: 0 0 0 1px var(--accent); border-radius: 4px; }
.grid th .arrow { opacity: .8; }
.grid td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: none; }
.grid tbody tr.clickable { cursor: pointer; transition: background .18s var(--ease); }
.grid tbody tr.clickable:hover { background: var(--surface-2); }
.grid .r { text-align: right; }
.client-name { font-weight: 600; display: block; text-decoration: none; }
.client-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; display: block; }

.kcell { display: grid; gap: 3px; min-width: 130px; }
.kcell-top { display: flex; align-items: center; gap: 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kcell-sub { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.kcell-na { font-size: 12px; color: var(--text-muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--ink-300); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.pct-pill {
  font-family: var(--mono); font-size: 11px; padding: 1px 6px; border-radius: var(--r-chip);
  border: 1px solid var(--border-strong); color: var(--text); font-weight: 500;
}

.score { display: grid; gap: 6px; min-width: 120px; }
.score-num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; line-height: 1; display: flex; align-items: baseline; gap: 6px; }
.score-num small { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.bar { height: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar > span { display: block; height: 100%; background: var(--text); border-radius: 999px; }
.bar.ok > span { background: var(--ok); } .bar.warn > span { background: var(--warn); } .bar.bad > span { background: var(--bad); }
.tag {
  display: inline-flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-muted); border: 1px solid var(--border-strong); padding: 1px 6px; border-radius: var(--r-chip);
  white-space: nowrap; width: fit-content;
}
.tag .ico { width: 12px; height: 12px; }

/* ---------- Detalle ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--text-muted); font-size: 13px; margin-bottom: 14px; }
.back:hover { color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.kpi-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi-rows { display: grid; gap: 6px; font-size: 13px; }
.kpi-rows div { display: flex; justify-content: space-between; gap: 8px; }
.kpi-rows dt { color: var(--text-muted); }
.kpi-rows dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }
.kpi-foot { margin-top: auto; display: grid; gap: 8px; }
.kpi-pts { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }
.kpi-pts b { color: var(--text); font-weight: 600; }
.kpi-note { font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; align-items: flex-start; }
.kpi-note .ico { flex-shrink: 0; margin-top: 2px; width: 14px; height: 14px; }

.funnel { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.funnel > div { padding: 18px 20px; border-right: 1px solid var(--border); }
.funnel > div:last-child { border-right: none; }
.funnel .v { font-size: 22px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.funnel .r { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.chart-card { padding: 20px; }
.chart-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.chart { width: 100%; height: 220px; display: block; }
.chart .bar-in { fill: var(--text); }
.chart .bar-out { fill: var(--ink-300); }
:root[data-ds-theme="dark"] .chart .bar-out { fill: var(--ink-300); }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--text-muted); font-family: var(--mono); font-size: 10px; }
.chart-tip { font-size: 12px; color: var(--text-muted); min-height: 18px; margin-top: 8px; font-variant-numeric: tabular-nums; }

.cfg-list { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; font-size: 13px; }
.cfg-list dt { color: var(--text-muted); }
.cfg-list dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 2px 8px; border: 1px solid var(--border-strong); border-radius: var(--r-chip); background: var(--surface-2); }
.chip b { font-family: var(--mono); font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-right: 6px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Configuración ---------- */
.cfg-table td { vertical-align: middle; }
.cfg-table .input { width: 100%; }
.pct-input { position: relative; width: 96px; }
.pct-input .input { padding-right: 26px; text-align: right; font-variant-numeric: tabular-nums; }
.pct-input span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 12px; pointer-events: none; }
.switch { position: relative; display: inline-block; vertical-align: middle; width: 34px; height: 20px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--ink-200); border: 1px solid var(--border); transition: background .18s var(--ease); pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); transition: transform .18s var(--ease); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 1px var(--accent), 0 0 0 3px var(--bg); }
:root[data-ds-theme="dark"] .switch span { background: var(--ink-200); }
.expand-row td { background: var(--surface-2); padding: 20px; }
.periods { width: 100%; border-collapse: collapse; }
.periods th { text-align: left; font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); font-weight: 500; padding: 6px 8px; }
.periods td { padding: 4px 8px; }
.periods .input { width: 100%; }
.src { font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.inline-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: grid; gap: 6px; }
.field label { font-size: 12px; color: var(--text-muted); }
.hint { font-size: 12px; color: var(--text-muted); }
.err-text { font-size: 12px; color: var(--text); display: flex; gap: 6px; align-items: flex-start; }
.err-text .ico { color: var(--bad); flex-shrink: 0; width: 14px; height: 14px; margin-top: 2px; }

.empty { padding: 48px 20px; text-align: center; color: var(--text-muted); }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--ink-100), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
:root[data-ds-theme="dark"] .skeleton { background: linear-gradient(90deg, var(--surface-2), var(--ink-200), var(--surface-2)); background-size: 200% 100%; }
@keyframes sk { to { background-position: -200% 0; } }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--accent); color: var(--bg); padding: 10px 16px; border-radius: var(--r-btn); box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 500; transition: opacity .2s var(--ease), transform .2s var(--ease); z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (max-width: 1080px) {
  .kpis, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .funnel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .funnel > div { border-bottom: 1px solid var(--border); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar-inner { padding: 0 16px; gap: 12px; height: auto; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .brand .eyebrow, .brand-sep, .sync-stamp { display: none; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .page { padding: 24px 16px 48px; }
  .kpis, .stats { grid-template-columns: 1fr; }
  .funnel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cfg-list { grid-template-columns: 1fr; gap: 2px 0; }
  .cfg-list dd { margin-bottom: 10px; }
  .inline-form { grid-template-columns: 1fr; }
  .hero-motif { display: none; }
  h1 { font-size: 22px; }
}
@media print {
  :root, :root[data-ds-theme="dark"] { --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #0A0A0A; --text-muted: #525252; --accent: #0A0A0A; --border: rgba(10,10,10,.12); color-scheme: light; }
  [data-ds-theme="dark"] .logo { filter: none; }
  .topbar, .toolbar, .foot, .toast { display: none; }
}
.periods-wrap { overflow-x: auto; }
.periods { min-width: 620px; }
.periods input[type="date"] { min-width: 136px; }
.periods .input.num { min-width: 84px; text-align: right; }
.expand-row .two-col { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 1080px) { .expand-row .two-col { grid-template-columns: 1fr; } }

/* Puntaje y cumplimiento al frente; real y objetivo de apoyo. */
.seg-sub { font-family: var(--mono); font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted); margin-left: 6px; }
.kcell-top small { font-size: 12px; font-weight: 500; margin-left: -4px; }
.kcell-pts { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; line-height: 1; }
.kpi-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.kpi-value small { font-size: 14px; font-weight: 500; color: var(--text-muted); margin-left: 4px; letter-spacing: 0; }
.kpi-pct { display: grid; justify-items: end; gap: 2px; }
.kpi-pct b { font-size: 22px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi-rows { font-size: 12px; }
.obj-input { width: 96px; text-align: right; }
.periods { min-width: 860px; }
.cfg-table td:nth-child(2) { min-width: 220px; }
.cfg-table .obj-input { width: 104px; min-width: 104px; }
.user-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-muted); }
.user-chip[hidden] { display: none; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
@media (max-width: 720px) { .user-chip #userEmail { display: none; } }
