/* Base styles (tema claro) */
:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #000000;
  --muted: #667085;
  --primary: #000468;    /* azul profundo */
  --accent: #00e7e4;     /* cian */
  --ok: var(--accent);
  --info: var(--primary);
  --warn: var(--primary);
  --error: #000000;      /* marcamos error en negro */
  --border: #e5e7eb;
  --chip-bg: #ffffff;    /* KPIs fondo blanco por defecto */
  --chip-selected-bg: #e6fefe;
  --chip-selected-border: #00e7e4;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
code { background: #f3f4f6; padding: .15rem .35rem; border-radius: 4px; }
.container { max-width: 980px; padding: 0 16px; margin: 0 auto; }

/* Header / Footer */
.site-header { border-bottom: 1px solid var(--border); background: var(--panel); }
.site-header .container { padding: 24px 16px; }
.brand-row { display: flex; gap: 12px; align-items: center; }
.brand-logo { height: 32px; width: auto; }
.site-header h1 { margin: 0; font-size: 22px; color: var(--primary); }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0 4px; font-size: 13px; }
.btn-link:hover { text-decoration: underline; }
.site-footer { border-top: 1px solid var(--border); margin-top: 48px; }
.site-footer .container { padding: 20px 16px; color: var(--muted); }

/* Landing */
.landing { text-align: center; padding: 48px 12px; }
.landing .logo { width: 220px; height: auto; margin: 16px auto 12px; display: block; }
.landing-text { color: var(--muted); }

/* Summary (KPIs) */
.summary-section { margin: 16px 0 24px; }
.summary-header { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px 6px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  user-select: none;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; display: inline-block; }
.chip:hover { background: #f7f7f8; border-color: #dfe3e8; }
.chip:focus-visible { outline: 2px solid color-mix(in lab, var(--primary), #fff 40%); outline-offset: 2px; }
.chip .count { font-weight: 600; }
.chip.ok { border-color: color-mix(in lab, var(--ok), #fff 30%); }
.chip.warn { border-color: color-mix(in lab, var(--warn), #fff 30%); }
.chip.error { border-color: color-mix(in lab, var(--error), #fff 30%); }
.chip.info { border-color: color-mix(in lab, var(--info), #fff 30%); }
.chip.neutral { border-color: #e3e3e3; }
.chip.selected { background: #f3f4f6; border-color: #d0d5dd; box-shadow: 0 0 0 2px #eef0f3 inset; }

/* KPI-specific color coding only when selected */
.chip.kpi-sent::before { background: #d0d5dd; }
.chip.kpi-sent.selected { color: var(--info); background: color-mix(in lab, var(--info), #fff 88%); border-color: var(--info); box-shadow: 0 0 0 2px color-mix(in lab, var(--info), #fff 65%) inset; }
.chip.kpi-sent.selected::before { background: var(--info); }

.chip.kpi-delivered::before { background: #d0d5dd; }
.chip.kpi-delivered.selected { color: var(--accent); background: color-mix(in lab, var(--accent), #fff 85%); border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in lab, var(--accent), #fff 60%) inset; }
.chip.kpi-delivered.selected::before { background: var(--accent); }

.chip.kpi-read::before { background: #d0d5dd; }
.chip.kpi-read.selected { color: var(--primary); background: color-mix(in lab, var(--primary), #fff 88%); border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in lab, var(--primary), #fff 60%) inset; }
.chip.kpi-read.selected::before { background: var(--primary); }

.chip.kpi-failed::before { background: #d0d5dd; }
.chip.kpi-failed.selected { color: #000; background: #ededed; border-color: #000; box-shadow: 0 0 0 2px #d6d6d6 inset; }
.chip.kpi-failed.selected::before { background: #000; }

.chip.kpi-unknown::before { background: #d0d5dd; }
.chip.kpi-unknown.selected { color: #4b5563; background: #f2f4f7; border-color: #cbd5e1; box-shadow: 0 0 0 2px #e5e7eb inset; }
.chip.kpi-unknown.selected::before { background: #98a2b3; }

.chip.kpi-all.selected { color: var(--primary); background: #eef6ff; border-color: color-mix(in lab, var(--primary), #fff 10%); box-shadow: 0 0 0 2px color-mix(in lab, var(--primary), #fff 70%) inset; }

/* Funnel */
.funnel { margin-top: 12px; }
.funnel-embudo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 8px; }
.funnel-layer { height: 36px; border-radius: 10px; color: #000; display: flex; align-items: center; justify-content: space-between; padding: 0 10px; box-shadow: 0 1px 2px rgba(0,0,0,.06); border: 1px solid var(--border); }
.layer-total { background: #f3f4f6; border-color: #d0d5dd; }
.layer-sent { background: color-mix(in lab, var(--info), #fff 85%); border-color: var(--info); }
.layer-delivered { background: color-mix(in lab, var(--accent), #fff 85%); border-color: var(--accent); }
.layer-read { background: color-mix(in lab, var(--primary), #fff 85%); border-color: var(--primary); }
.funnel-layer .name { font-weight: 600; }
.funnel-layer .value { font-size: 12px; color: var(--muted); }
.funnel-aside { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.funnel-aside .chip { cursor: default; }

/* Results (lista agrupada) */
.results-section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.results-header { padding: 12px 12px 0; display: flex; justify-content: space-between; align-items: baseline; }
.results-header .actions { display: flex; align-items: center; gap: 10px; }
.btn { background: var(--primary); color: #fff; border: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.input-search { min-width: 220px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
.input-search::placeholder { color: var(--muted); }
.input-search:focus { outline: none; border-color: color-mix(in lab, var(--primary), #fff 30%); box-shadow: 0 0 0 3px color-mix(in lab, var(--primary), #fff 85%); }
.select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
.note { display: block; max-width: 780px; }
.muted { color: var(--muted); }
.results-list { display: block; padding: 12px; }
.group { margin: 10px 0 18px; }
.group-title { font-size: 13px; color: var(--muted); margin: 14px 2px 8px; font-weight: 600; }
.group-title .select-all { margin-left: 8px; font-weight: normal; font-size: 12px; }
.group-items { display: block; }
.card { border: 1px solid var(--border); background: #fff; border-radius: 12px; padding: 12px; margin-bottom: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card .left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.select-box { width: 18px; height: 18px; }

/* Bulk card */
.bulk-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--border); padding: 12px; margin: 8px 12px 0; }
.bulk-text { font-size: 14px; }
.bulk-controls { display: flex; align-items: center; gap: 12px; }
.title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.identity { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.user-name { font-weight: 600; color: var(--text); line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.phone { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.org-name { font-weight: 600; }
.status-badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); background: #f7f7f8; }
.status-ok { color: var(--accent); border-color: var(--accent); background: color-mix(in lab, var(--accent), #fff 90%); }
.status-warn { color: var(--primary); border-color: var(--primary); background: color-mix(in lab, var(--primary), #fff 90%); }
.status-error { color: #000; border-color: #000; background: #f2f2f2; }
.status-info { color: var(--info); border-color: var(--info); background: color-mix(in lab, var(--info), #fff 92%); }
.status-neutral { color: var(--muted); border-color: #e8e8e8; background: #f6f6f6; }
.meta { color: var(--muted); font-size: 12px; }
.error-box { background: #fafafa; border: 1px dashed #000; border-radius: 6px; padding: 8px; margin-top: 8px; }
.error-title { font-weight: 600; margin-bottom: 4px; color: #000; }
.error-message { color: #333; }

/* Modal (admin org picker) */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border: 1px solid var(--border); border-radius: 10px; width: min(680px, calc(100% - 24px)); max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.modal-header { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { margin: 0; font-size: 16px; }
.modal-body { padding: 10px 14px; overflow: auto; }
.modal-actions { padding: 10px 14px; border-top: 1px solid var(--border); text-align: right; }
.input-text { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.list { list-style: none; padding: 0; margin: 10px 0 0; }
.list-item { padding: 8px 10px; border: 1px solid #f0f0f0; border-radius: 8px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.list-item:hover { background: #f8fafc; }
.pill { font-size: 12px; padding: 2px 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }

/* Loading state */
.summary-section, .results-section { position: relative; }
.loading { opacity: .6; }
.loading::before { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.6); border-radius: 8px; }
.loading::after {
  content: "";
  position: absolute;
  width: 28px; height: 28px;
  top: 16px; right: 16px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--primary);
  border-right-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 12px 0; }
.banner-warn { background: #fff8e1; border-color: #fde68a; }
.banner-text { font-size: 14px; color: #7a6a00; }
