/* ============================================================================
 * app.css — DEMO COMERCIAL · Agente Comercial WhatsApp · DIMEXA × Cofoundy
 * ----------------------------------------------------------------------------
 * Shared design tokens + shell components for the 5-view demo platform.
 * This file is the ONLY shared stylesheet — all views include ONLY this file.
 * Per-view styles go in a <style> block in that .html file.
 *
 * Design language: sibling of demo-fase1-gestor-light (light mode, same
 * palette, same shell geometry, same typography stack). DO NOT change tokens.
 *
 * Authors: Foundation agent — 2026-06-23
 * ============================================================================ */

/* ============================================================================
 * GOOGLE FONTS — loaded here so views only need this one CSS import
 * ============================================================================ */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ============================================================================
 * DESIGN TOKENS — COLOR (light mode)
 * ============================================================================ */
:root {
  /* ---------- Surfaces (warm-cool gray, never pure white at canvas) ---------- */
  --bg-primary:    #F7F8FB;   /* page canvas */
  --bg-secondary:  #FFFFFF;   /* card / panel surface */
  --bg-tertiary:   #F9FAFB;   /* elevated panels, table headers */
  --bg-elevated:   #F3F4F6;   /* hover, inputs */
  --bg-overlay:    rgba(15, 22, 32, 0.45);

  /* ---------- Glass (in light mode = solid white + shadow) ------------------- */
  --glass-card:        #FFFFFF;
  --glass-card-hover:  #F9FAFB;
  --glass-border:      rgba(15, 22, 32, 0.08);
  --glass-border-soft: rgba(15, 22, 32, 0.04);

  /* ---------- Text ----------------------------------------------------------- */
  --text-primary:   #0F1620;
  --text-secondary: #374151;
  --text-muted:     #6B7280;
  --text-faint:     #9CA3AF;
  --text-inverse:   #FFFFFF;

  /* ---------- Borders -------------------------------------------------------- */
  --border-subtle: rgba(15, 22, 32, 0.06);
  --border-strong: rgba(15, 22, 32, 0.10);
  --border-accent: rgba(15, 22, 32, 0.14);

  /* ---------- Brand — DIMEXA cyan (primary) ---------------------------------- */
  /* Exact match with Fase 1 gestor: #2D8DC4 (passes AAA on white) */
  --cofoundy-primary:    #2D8DC4;   /* DIMEXA cyan — primary interactive */
  --cofoundy-primary-hi: #46A0D0;   /* hover / highlight */
  --cofoundy-primary-lo: #1F627F;   /* DIMEXA dark teal */
  --cofoundy-deep:       #0F3957;
  --cofoundy-midnight:   #020b1b;

  /* ---------- DIMEXA brand -------------------------------------------------- */
  --dimexa-blue:        #2D8DC4;   /* isotipo arc superior */
  --dimexa-blue-light:  #68C8EA;   /* cyan claro */
  --dimexa-blue-deep:   #1F627F;   /* heading color del sitio */
  --dimexa-green:       #6CB33F;   /* isotipo arc inferior — GREEN accent */
  --dimexa-green-light: #A8D878;   /* verde claro */
  --dimexa-green-deep:  #4A7B2A;   /* verde oscuro */

  /* ---------- Semantic accents ----------------------------------------------- */
  --cofoundy-accent:    var(--cofoundy-primary);
  --cofoundy-accent-hi: var(--cofoundy-primary-hi);
  --cofoundy-purple:    #7C3AED;

  /* ---------- Segmento colors (pharma segmentation A–D) --------------------- */
  /* Segment A: strategic key accounts — violet (premium) */
  /* Segment B: high potential — teal (brand) */
  /* Segment C: standard — slate */
  /* Segment D: small / intensive agent — amber */
  --seg-a: #7C3AED;   /* violet */
  --seg-b: #2D8DC4;   /* brand cyan */
  --seg-c: #475569;   /* slate */
  --seg-d: #D97706;   /* amber */

  /* ---------- Status --------------------------------------------------------- */
  --status-success:  #059669;
  --status-warning:  #D97706;
  --status-danger:   #DC2626;
  --status-info:     var(--cofoundy-primary);

  /* ---------- Campaign type colors ------------------------------------------ */
  --tipo-bonificacion:     #059669;   /* green — free units = generosity */
  --tipo-bonificacion-bg:  #ECFDF5;
  --tipo-descuento:        #2D8DC4;   /* cyan — % off = brand precision */
  --tipo-descuento-bg:     #EFF9FF;

  /* ---------- WhatsApp channel ---------------------------------------------- */
  --wa-green: #128C3D;
  --wa-green-bg: #F0FDF4;

  /* ---------- Ranking gradient (margin bars) --------------------------------- */
  --margin-high: #059669;    /* top margin — green */
  --margin-mid:  #D97706;    /* mid margin — amber */
  --margin-low:  #DC2626;    /* low margin — red */

  /* ============================================================================
   * TYPOGRAPHY
   * ============================================================================ */
  --font-display: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  --font-sans:    'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:    'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  --fs-2xs: 11px;
  --fs-xs:  12px;
  --fs-sm:  13px;
  --fs-md:  14px;
  --fs-lg:  16px;
  --fs-xl:  20px;
  --fs-2xl: 26px;
  --fs-3xl: 36px;

  --fw-normal:   400;
  --fw-medium:   500;
  --fw-semibold: 600;
  --fw-bold:     700;

  --lh-tight:  1.15;
  --lh-snug:   1.3;
  --lh-normal: 1.5;
  --lh-loose:  1.65;

  --tracking-tight:   -0.02em;
  --tracking-tighter: -0.03em;
  --tracking-wide:    0.06em;
  --tracking-wider:   0.12em;

  /* ============================================================================
   * SPACING
   * ============================================================================ */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  24px;
  --space-6:  32px;
  --space-7:  40px;
  --space-8:  48px;
  --space-9:  64px;
  --space-10: 80px;

  /* ============================================================================
   * RADII
   * ============================================================================ */
  --radius-xs:   6px;
  --radius-sm:   8px;
  --radius-md:   12px;
  --radius-lg:   16px;
  --radius-xl:   20px;
  --radius-2xl:  24px;
  --radius-pill: 999px;

  /* ============================================================================
   * SHADOWS — light-mode, layered
   * ============================================================================ */
  --shadow-sm:       0 1px 2px rgba(15, 22, 32, 0.06);
  --shadow-card:     0 1px 3px rgba(15, 22, 32, 0.06), 0 1px 2px rgba(15, 22, 32, 0.04);
  --shadow-elevated: 0 8px 24px rgba(15, 22, 32, 0.08), 0 2px 6px rgba(15, 22, 32, 0.04);
  --shadow-modal:    0 20px 60px rgba(15, 22, 32, 0.18), 0 4px 12px rgba(15, 22, 32, 0.08);
  --shadow-glow:     0 0 0 1px rgba(70, 160, 208, 0.32), 0 8px 20px rgba(70, 160, 208, 0.18);
  --shadow-glow-green: 0 0 0 1px rgba(108, 179, 63, 0.32), 0 8px 20px rgba(108, 179, 63, 0.14);

  /* ============================================================================
   * MOTION
   * ============================================================================ */
  --ease-default: cubic-bezier(0.19, 1, 0.22, 1);
  --ease-out:     cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring:  cubic-bezier(0.34, 1.3, 0.64, 1);

  --t-fast: 140ms var(--ease-default);
  --t-base: 200ms var(--ease-default);
  --t-slow: 320ms var(--ease-default);

  /* ============================================================================
   * LAYOUT
   * ============================================================================ */
  --topbar-h:    64px;
  --sidebar-w:   232px;
  --content-max: 1440px;
  --z-topbar:    50;
  --z-sidebar:   40;
  --z-modal:     200;
  --z-toast:     300;
}

/* ============================================================================
 * RESET
 * ============================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 0% 0%, rgba(70, 160, 208, 0.05), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(108, 179, 63, 0.04), transparent 55%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
  overflow-x: hidden;
}

a { color: var(--cofoundy-primary); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--cofoundy-primary-lo); }
button { font: inherit; cursor: pointer; }
img, svg { display: block; max-width: 100%; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(15, 22, 32, 0.14);
  border-radius: var(--radius-pill);
  border: 2px solid var(--bg-primary);
}
::-webkit-scrollbar-thumb:hover { background: rgba(15, 22, 32, 0.24); }
::selection { background: rgba(70, 160, 208, 0.22); color: var(--text-primary); }

/* ============================================================================
 * DEMO BANNER — fixed at top, above everything
 * Not sticky — scrolls away so topbar sits cleanly at top:0
 * Cyan tone: informational, not alarming
 * ============================================================================ */
.demo-banner {
  position: relative;
  z-index: calc(var(--z-topbar) + 1);
  background: linear-gradient(90deg, rgba(70, 160, 208, 0.14), rgba(108, 179, 63, 0.08), rgba(70, 160, 208, 0.14));
  border-bottom: 1px solid rgba(70, 160, 208, 0.28);
  color: var(--cofoundy-primary-lo);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-align: center;
  padding: 6px var(--space-4);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.demo-banner::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dimexa-green);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50%       { opacity: 1;   transform: scale(1.25); }
}

/* ============================================================================
 * APP SHELL — topbar + sidebar + main (CSS Grid)
 * ============================================================================ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar  topbar"
    "sidebar main";
  min-height: 100vh;
}

/* ============================================================================
 * TOPBAR
 * ============================================================================ */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  padding: 0 var(--space-6);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid var(--border-strong);
  z-index: var(--z-topbar);
  position: sticky;
  top: 0;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-width: 0;
}

.topbar__logo-cluster {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* Cofoundy isologo — small helper mark */
.topbar__logo-cofoundy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  opacity: 0.90;
}
.topbar__logo-cofoundy img,
.topbar__logo-cofoundy svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.topbar__logo-divider {
  color: var(--text-faint);
  font-size: 18px;
  font-weight: 300;
  line-height: 1;
  user-select: none;
  margin: 0 -2px;
}

/* DIMEXA isotipo — dominant (bicolor arcs) */
.topbar__logo-dimexa {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}
.topbar__logo-dimexa svg { width: 100%; height: 100%; display: block; }

.topbar__title {
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__title-brand {
  color: var(--dimexa-blue-deep);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.topbar__title-suffix {
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

.topbar__breadcrumb {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  padding-left: var(--space-4);
  margin-left: var(--space-2);
  border-left: 1px solid var(--border-strong);
  white-space: nowrap;
}

.topbar__meta {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-size: var(--fs-sm);
  flex-shrink: 0;
}

.topbar__date {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.topbar__date::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--status-success);
  box-shadow: 0 0 6px rgba(5, 150, 105, 0.45);
}

.topbar__user {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  padding-left: var(--space-5);
  border-left: 1px solid var(--border-strong);
}

.topbar__user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cofoundy-primary-hi), var(--cofoundy-primary-lo));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(70, 160, 208, 0.28);
}

.topbar__user-info { display: flex; flex-direction: column; line-height: 1.2; }
.topbar__user-name { color: var(--text-primary); font-size: var(--fs-sm); font-weight: 600; }
.topbar__user-role { color: var(--text-faint); font-size: var(--fs-2xs); font-weight: 500; }

/* ============================================================================
 * SIDEBAR NAV
 * ============================================================================ */
.sidebar-nav {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  background: #F9FAFB;
  border-right: 1px solid var(--border-strong);
  padding: var(--space-5) var(--space-3);
  gap: 2px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  z-index: var(--z-sidebar);
}

.sidebar-nav__section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  padding: var(--space-2) var(--space-3) var(--space-2);
  margin-top: var(--space-2);
}
.sidebar-nav__section-label:first-child { margin-top: 0; }

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--fs-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}

.sidebar-nav .nav-link__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: currentColor;
  opacity: 0.7;
}

.sidebar-nav .nav-link:hover {
  background: rgba(15, 22, 32, 0.04);
  color: var(--text-primary);
}
.sidebar-nav .nav-link:hover .nav-link__icon { opacity: 1; }

.sidebar-nav .nav-link--active {
  background: #EFF6FF;
  color: var(--cofoundy-primary);
  font-weight: 600;
}
.sidebar-nav .nav-link--active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--cofoundy-primary);
}
.sidebar-nav .nav-link--active .nav-link__icon { opacity: 1; color: var(--cofoundy-primary); }

.sidebar-nav .nav-link__badge {
  margin-left: auto;
  background: var(--status-danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  min-width: 18px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 3px rgba(220, 38, 38, 0.32);
}

.sidebar-nav__footer {
  margin-top: auto;
  padding: var(--space-4) var(--space-3) var(--space-2);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-nav__footer small {
  color: var(--text-faint);
  font-size: var(--fs-2xs);
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.sidebar-nav__footer small.tag-demo {
  color: var(--cofoundy-primary);
  font-weight: 600;
}

/* ============================================================================
 * MAIN CONTENT
 * ============================================================================ */
.main-content {
  grid-area: main;
  padding: var(--space-6) var(--space-7) var(--space-8);
  min-width: 0;
  max-width: var(--content-max);
}
.main-content > * + * { margin-top: var(--space-6); }

/* ============================================================================
 * PAGE HEADER
 * ============================================================================ */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.page-header__title {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  margin-bottom: var(--space-2);
}

.page-header__subtitle {
  color: var(--text-muted);
  font-size: var(--fs-md);
  font-weight: 400;
  max-width: 680px;
  line-height: var(--lh-loose);
}

.page-header__actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
  align-items: flex-start;
  padding-top: var(--space-1);
}

/* ============================================================================
 * SECTION
 * ============================================================================ */
.section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.section__title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
}

.section__subtitle {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============================================================================
 * LAYOUT UTILITIES
 * ============================================================================ */
.stack   { display: flex; flex-direction: column; gap: var(--space-3); }
.stack--sm { gap: var(--space-2); }
.stack--lg { gap: var(--space-5); }

.row         { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.row--end     { justify-content: flex-end; }

.grid     { display: grid; gap: var(--space-4); }
.grid--2  { grid-template-columns: repeat(2, 1fr); }
.grid--3  { grid-template-columns: repeat(3, 1fr); }
.grid--4  { grid-template-columns: repeat(4, 1fr); }

.muted  { color: var(--text-muted); }
.faint  { color: var(--text-faint); }
.mono   { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.display { font-family: var(--font-display); letter-spacing: var(--tracking-tight); }

.text-2xs { font-size: var(--fs-2xs); }
.text-xs  { font-size: var(--fs-xs); }
.text-sm  { font-size: var(--fs-sm); }
.text-lg  { font-size: var(--fs-lg); }
.text-xl  { font-size: var(--fs-xl); }

.weight-medium   { font-weight: 500; }
.weight-semibold { font-weight: 600; }
.weight-bold     { font-weight: 700; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

/* ============================================================================
 * CARD
 * ============================================================================ */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-card);
  transition: border-color var(--t-base), transform var(--t-base), box-shadow var(--t-base);
  position: relative;
}

.card--elevated { box-shadow: var(--shadow-elevated); }
.card--clickable { cursor: pointer; }
.card--clickable:hover {
  border-color: rgba(70, 160, 208, 0.32);
  transform: translateY(-2px);
  box-shadow: var(--shadow-elevated);
}

/* Left accent strip variants */
.card--accent        { position: relative; overflow: hidden; }
.card--accent::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--cofoundy-primary), var(--cofoundy-primary-lo));
}
.card--success { position: relative; overflow: hidden; }
.card--success::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--status-success); }
.card--warning { position: relative; overflow: hidden; }
.card--warning::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--status-warning); }
.card--danger  { position: relative; overflow: hidden; }
.card--danger::before  { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--status-danger); }

/* Top bar variants (for KPI cards) */
.card--top-cyan    { border-top: 3px solid var(--cofoundy-primary); }
.card--top-green   { border-top: 3px solid var(--dimexa-green); }
.card--top-success { border-top: 3px solid var(--status-success); }
.card--top-warning { border-top: 3px solid var(--status-warning); }
.card--top-danger  { border-top: 3px solid var(--status-danger); }

/* Gold / top-ranked highlight */
.card--gold {
  border-color: rgba(217, 119, 6, 0.32);
  background: linear-gradient(135deg, #FFFBEB 0%, #FFFFFF 40%);
  box-shadow: var(--shadow-elevated), 0 0 0 1px rgba(217, 119, 6, 0.16);
}
.card--gold::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, #F59E0B, #D97706);
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card__title {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
}
.card__subtitle { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }
.card__body { color: var(--text-secondary); font-size: var(--fs-sm); line-height: var(--lh-loose); }
.card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

/* ============================================================================
 * BUTTON
 * ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.005em;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-appearance: none;
}
.btn:active   { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(180deg, var(--cofoundy-primary-hi), var(--cofoundy-primary));
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 4px 12px rgba(70,160,208,0.28);
}
.btn--primary:hover {
  background: linear-gradient(180deg, var(--cofoundy-primary), var(--cofoundy-primary-lo));
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 6px 20px rgba(70,160,208,0.4);
  color: #fff;
}

.btn--secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-accent);
}
.btn--secondary:hover { background: var(--bg-tertiary); border-color: var(--text-muted); }

.btn--success {
  background: linear-gradient(180deg, #34D399, var(--status-success));
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 4px 12px rgba(16,185,129,0.28);
}
.btn--success:hover { filter: brightness(1.06); color: #fff; }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn--ghost:hover { background: rgba(15,22,32,0.05); color: var(--text-primary); }

.btn--sm  { padding: 6px var(--space-3); font-size: var(--fs-xs); }
.btn--lg  { padding: 12px var(--space-5); font-size: var(--fs-md); }
.btn--icon { width: 32px; height: 32px; padding: 0; }

/* ============================================================================
 * BADGE — tipo campaña, segmento, estado
 * ============================================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* --- Campaign tipo badges -------------------------------------------------- */
.badge--bonificacion {
  background: var(--tipo-bonificacion-bg);
  color: #047857;
  border-color: rgba(5, 150, 105, 0.32);
}
.badge--bonificacion::before {
  content: "🎁";
  font-size: 10px;
}

.badge--descuento {
  background: var(--tipo-descuento-bg);
  color: var(--cofoundy-primary-lo);
  border-color: rgba(45, 141, 196, 0.32);
}
.badge--descuento::before {
  content: "%";
  font-size: 9px;
  font-weight: 700;
  background: var(--cofoundy-primary);
  color: #fff;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* --- Segmento badges ------------------------------------------------------- */
.badge--seg-a {
  background: #F5F3FF;
  color: #6D28D9;
  border-color: rgba(124, 58, 237, 0.28);
}
.badge--seg-b {
  background: #EFF9FF;
  color: var(--cofoundy-primary);
  border-color: rgba(70, 160, 208, 0.32);
}
.badge--seg-c {
  background: #F1F5F9;
  color: #475569;
  border-color: rgba(71, 85, 105, 0.24);
}
.badge--seg-d {
  background: #FFFBEB;
  color: #B45309;
  border-color: rgba(217, 119, 6, 0.32);
}

/* --- Ranking badge (top pick) ---------------------------------------------- */
.badge--top1 {
  background: linear-gradient(135deg, #FEF3C7, #FDE68A);
  color: #92400E;
  border-color: rgba(217, 119, 6, 0.4);
  font-weight: 700;
}

/* --- Status variants ------------------------------------------------------- */
.badge--success {
  background: #ECFDF5; color: #047857; border-color: rgba(5,150,105,0.32);
}
.badge--warning {
  background: #FFFBEB; color: #B45309; border-color: rgba(217,119,6,0.32);
}
.badge--danger {
  background: #FEF2F2; color: #B91C1C; border-color: rgba(220,38,38,0.32);
}
.badge--soft {
  background: transparent; color: var(--text-muted); border-color: var(--border-accent);
  text-transform: none; letter-spacing: 0; font-family: var(--font-mono); font-weight: 500;
}
.badge--lg { padding: var(--space-2) var(--space-3); font-size: var(--fs-sm); }

/* ============================================================================
 * TABLE
 * ============================================================================ */
.table-wrap {
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table thead th {
  background: #F9FAFB;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-weight: 600;
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: 10px;
  letter-spacing: var(--tracking-wider);
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-strong);
}

.table tbody td {
  padding: var(--space-4);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: #F3F4F6; }
.table .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.table tr.is-top { background: #FFFBEB; }
.table tr.is-top:hover { background: #FEF3C7; }

/* ============================================================================
 * MARGIN / RANKING BAR — horizontal progress bar for margenPct
 * ============================================================================ */
.margin-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 120px;
}

.margin-bar__track {
  flex: 1;
  height: 8px;
  background: #E5E7EB;
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.margin-bar__fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width 0.6s var(--ease-out);
  /* Color injected via JS / inline style; defaults below via modifier classes */
}

.margin-bar__fill--high {
  background: linear-gradient(90deg, var(--status-success), #10B981);
}
.margin-bar__fill--mid {
  background: linear-gradient(90deg, #F59E0B, var(--status-warning));
}
.margin-bar__fill--low {
  background: linear-gradient(90deg, #EF4444, var(--status-danger));
}

.margin-bar__label {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
}

/* ============================================================================
 * KPI CARD
 * ============================================================================ */
.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.kpi-card__label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
}

.kpi-card__value {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tighter);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.kpi-card__unit {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: 500;
  color: var(--text-muted);
}

.kpi-card__delta {
  font-size: var(--fs-xs);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
.kpi-card__delta--up   { color: var(--status-success); }
.kpi-card__delta--down { color: var(--status-danger); }
.kpi-card__meta { font-size: var(--fs-xs); color: var(--text-faint); margin-top: var(--space-1); }

.kpi-card--success { border-top: 3px solid var(--status-success); }
.kpi-card--warning { border-top: 3px solid var(--status-warning); }
.kpi-card--danger  { border-top: 3px solid var(--status-danger); }
.kpi-card--info    { border-top: 3px solid var(--cofoundy-primary); }
.kpi-card--green   { border-top: 3px solid var(--dimexa-green); }

/* ============================================================================
 * PROGRESS BAR (generic)
 * ============================================================================ */
.progress-bar {
  width: 100%;
  height: 6px;
  background: #E5E7EB;
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cofoundy-primary), var(--cofoundy-primary-hi));
  border-radius: var(--radius-pill);
  transition: width var(--t-slow);
}
.progress-bar__fill--success { background: linear-gradient(90deg, var(--status-success), #10B981); }
.progress-bar__fill--warning { background: linear-gradient(90deg, var(--status-warning), #F59E0B); }
.progress-bar__fill--danger  { background: linear-gradient(90deg, var(--status-danger), #EF4444); }
.progress-bar__fill--green   { background: linear-gradient(90deg, var(--dimexa-green), var(--dimexa-green-light)); }

/* ============================================================================
 * WHATSAPP BUBBLE — for conversation preview
 * ============================================================================ */
.wa-thread {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: #E5DDD5;
  border-radius: var(--radius-md);
  background-image:
    url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='60' height='60' fill='%23e5ddd5'/%3E%3C/svg%3E");
}

.wa-bubble {
  max-width: 78%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  line-height: var(--lh-loose);
  position: relative;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.wa-bubble--agent {
  align-self: flex-start;
  background: #FFFFFF;
  border-radius: 0 var(--radius-md) var(--radius-md) var(--radius-md);
  color: #111827;
}

.wa-bubble--pharmacy {
  align-self: flex-end;
  background: #D9FDD3;
  border-radius: var(--radius-md) 0 var(--radius-md) var(--radius-md);
  color: #111827;
}

.wa-bubble__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-1);
  margin-top: 4px;
}

.wa-bubble__time {
  font-size: 10px;
  color: #8696A0;
  font-variant-numeric: tabular-nums;
}

.wa-bubble__ticks {
  color: #53BDEB;
  font-size: 12px;
  line-height: 1;
}

.wa-sender-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--wa-green);
  margin-bottom: 2px;
}

/* ============================================================================
 * RANKING NUMBER — big ordinal indicator
 * ============================================================================ */
.rank-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 700;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.rank-num--1 {
  background: linear-gradient(135deg, #FCD34D, #F59E0B);
  color: #78350F;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.35);
}
.rank-num--2 {
  background: #E5E7EB;
  color: #374151;
  box-shadow: 0 2px 6px rgba(15,22,32,0.12);
}
.rank-num--3 {
  background: linear-gradient(135deg, #FED7AA, #F97316);
  color: #7C2D12;
  box-shadow: 0 2px 6px rgba(249, 115, 22, 0.28);
}
.rank-num--other {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

/* ============================================================================
 * INSIGHT BOX — RAG intelligence callout
 * ============================================================================ */
.insight-box {
  background: linear-gradient(135deg, rgba(108, 179, 63, 0.08), rgba(45, 141, 196, 0.06));
  border: 1px solid rgba(108, 179, 63, 0.28);
  border-left: 4px solid var(--dimexa-green);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
}

.insight-box__icon {
  width: 20px;
  height: 20px;
  color: var(--dimexa-green);
  flex-shrink: 0;
  margin-top: 1px;
}

.insight-box__title {
  font-family: var(--font-display);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--dimexa-green-deep);
  letter-spacing: var(--tracking-tight);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: var(--tracking-wider);
  margin-bottom: 2px;
}

.insight-box__body {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  line-height: var(--lh-loose);
}

/* ============================================================================
 * INPUT / SELECT
 * ============================================================================ */
.input, .select {
  display: block;
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px var(--space-3);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--fs-sm);
  line-height: 1.5;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.input:focus, .select:focus {
  border-color: var(--cofoundy-primary);
  box-shadow: 0 0 0 3px rgba(70,160,208,0.18);
}
.input::placeholder { color: var(--text-faint); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='%2394a3b8'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-7);
}

/* ============================================================================
 * TOAST
 * ============================================================================ */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + var(--space-4));
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--cofoundy-primary);
  color: var(--text-primary);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-elevated);
  font-size: var(--fs-sm);
  font-weight: 500;
  min-width: 260px;
  max-width: 380px;
  pointer-events: auto;
}

/* ============================================================================
 * AVATAR
 * ============================================================================ */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cofoundy-primary), var(--cofoundy-deep));
  color: #fff;
  font-family: var(--font-display); font-size: var(--fs-xs); font-weight: 700;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(70,160,208,0.25);
}
.avatar--sm { width: 28px; height: 28px; font-size: 10px; }

/* ============================================================================
 * DIVIDER
 * ============================================================================ */
.divider { height: 1px; background: var(--border-subtle); border: none; margin: var(--space-4) 0; }
