/* ============================================================
   DharmaApp — Refresh layer ("Caribbean Bento 2.0")
   Carga DESPUÉS de app.css. Añade tokens nuevos y componentes
   premium sin romper los antiguos.
   ============================================================ */

/* ── Geist (banear Inter, regla anti-slop) ── */
@import url('https://fonts.bunny.net/css?family=geist:400,500,600,700|geist-mono:400,500&display=swap');

:root {
  /* === Tipografía nueva === */
  --font-display: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-body:    'Geist', 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-mono:    'Geist Mono', ui-monospace, 'SF Mono', monospace;

  /* === Color refinado === */
  --ink:           #0B1F2E;
  --ink-soft:      #3B5566;
  --ink-muted:     #6B8B9A;

  --paper:         #FAFBFC;
  --surface-warm:  #FAF6EE;
  --surface-tint:  rgba(10,191,188,0.04);

  --brand:         #0E6A8A;
  --brand-deep:    #0C3B5E;
  --brand-soft:    rgba(14,106,138,0.08);
  --accent:        #0ABFBC;
  --accent-soft:   rgba(10,191,188,0.10);

  --success:       #0D7960;
  --warning:       #A05E00;
  --danger:        #B91C1C;

  --border-neutral:        #E3E8EC;
  --border-neutral-strong: #C8D1D7;
  --border-brand:          rgba(14,106,138,0.20);

  /* === Sombras "diffusion" === */
  --shadow-card:        0 1px 2px rgba(11,31,46,0.04), 0 4px 12px rgba(11,31,46,0.04);
  --shadow-card-hover:  0 4px 8px rgba(11,31,46,0.05), 0 12px 32px rgba(11,31,46,0.08);
  --shadow-floating:    0 20px 40px -15px rgba(11,31,46,0.08);
  --shadow-inset-glass: inset 0 1px 0 rgba(255,255,255,0.6);

  /* === Radius cálidos === */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-pill: 9999px;

  /* === Motion === */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast:    140ms;
  --dur-base:    220ms;
  --dur-slow:    360ms;
}

/* ── prefers-reduced-motion ── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ── Tabular numerals universal ── */
.num, .price, .kpi-value, .stat-number, table, .table, .tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ============================================================
   BUTTONS — sistema nuevo, jerarquía estricta
   ============================================================ */
.btn {
  --btn-h: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 16px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--sm { --btn-h: 32px; font-size: 13px; padding: 0 12px; gap: 6px; }
.btn--lg { --btn-h: 48px; font-size: 15px; padding: 0 20px; }

.btn--primary {
  background: var(--brand);
  color: #fff;
  box-shadow: var(--shadow-inset-glass), 0 1px 2px rgba(12,59,94,0.15);
}
.btn--primary:hover { background: var(--brand-deep); transform: translateY(-1px); color: #fff; }

.btn--secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--border-neutral-strong);
}
.btn--secondary:hover { border-color: var(--brand); color: var(--brand); }

.btn--ghost {
  color: var(--brand);
  padding: 0 10px;
}
.btn--ghost:hover { background: var(--brand-soft); color: var(--brand-deep); }

.btn--danger {
  background: #fff;
  color: var(--danger);
  border-color: var(--border-neutral-strong);
}
.btn--danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn--success {
  background: var(--success);
  color: #fff;
}
.btn--success:hover { background: #0a604c; color: #fff; }

.btn--whatsapp {
  background: #25D366;
  color: #fff;
}
.btn--whatsapp:hover { background: #1eaa50; color: #fff; }

.btn--icon {
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--ink-soft);
  border-radius: var(--r-sm);
}
.btn--icon:hover { background: var(--brand-soft); color: var(--brand); }
.btn--icon.btn--sm { width: 28px; height: 28px; }

/* Block button */
.btn--block { width: 100%; }

/* ============================================================
   CARDS — sistema unificado
   ============================================================ */
.card-x {
  background: #fff;
  border: 1px solid var(--border-neutral);
  border-radius: var(--r-md);
  padding: 24px;
  transition: border-color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              transform var(--dur-base) var(--ease-out);
}
.card-x--interactive { cursor: pointer; }
.card-x--interactive:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-card-hover);
  transform: translateY(-2px);
}
.card-x--premium {
  background: var(--surface-warm);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-floating);
}
.card-x--bento {
  border-radius: var(--r-xl);
  padding: 32px;
  box-shadow: var(--shadow-card);
}
.card-x--ghost {
  background: transparent;
  border: 1px solid var(--border-neutral);
  border-radius: var(--r-md);
  padding: 20px;
}

.card-x__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.card-x__title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.card-x__title svg { flex-shrink: 0; }
.card-x__count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 2px 8px;
  background: var(--paper);
  border-radius: var(--r-pill);
  border: 1px solid var(--border-neutral);
}

/* ============================================================
   FIELDS — formularios premium
   ============================================================ */
.field-x {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field-x__label {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.field-x__label[data-required]::after { content: '*'; color: var(--danger); }
.field-x__input,
.field-x__select,
.field-x__textarea {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border-neutral-strong);
  border-radius: var(--r-sm);
  padding: 0 12px;
  height: 40px;
  width: 100%;
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.field-x__textarea {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.5;
  min-height: 80px;
}
.field-x__input:focus,
.field-x__select:focus,
.field-x__textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field-x__input[aria-invalid="true"],
.field-x__select[aria-invalid="true"],
.field-x__textarea[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(185,28,28,0.10);
}
.field-x__help { font-size: 12px; color: var(--ink-muted); }
.field-x__error { font-size: 12px; color: var(--danger); }

/* ============================================================
   STATUS DOTS, PILLS, CHIPS
   ============================================================ */
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot--success { background: var(--success); }
.dot--warning { background: var(--warning); }
.dot--danger { background: var(--danger); }
.dot--brand { background: var(--brand); }
.dot--muted { background: var(--ink-muted); }
.dot--pulse {
  animation: pulse-urgent 2.4s ease-in-out infinite;
}
@keyframes pulse-urgent {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.4); opacity: 0.6; }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: var(--r-pill);
}
.chip--neutral { background: var(--paper); color: var(--ink-soft); border: 1px solid var(--border-neutral); }
.chip--success { background: rgba(13,121,96,0.10); color: var(--success); }
.chip--warning { background: rgba(160,94,0,0.10); color: var(--warning); }
.chip--danger  { background: rgba(185,28,28,0.08); color: var(--danger); }

/* Relative time pill — colored by recency */
.timeago { font-family: var(--font-mono); font-size: 12px; }
.timeago--fresh   { color: var(--success); }
.timeago--ok      { color: var(--ink-muted); }
.timeago--stale   { color: var(--warning); }
.timeago--rotten  { color: var(--danger); }

/* ============================================================
   LAYOUT — bento grid asimétrico
   ============================================================ */
.bento-x {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}
@media (min-width: 900px) {
  .bento-x--today {
    grid-template-columns: 2fr 1fr;
  }
}

.stack { display: flex; flex-direction: column; gap: var(--gap, 16px); }
.row   { display: flex; align-items: center; gap: var(--gap, 12px); flex-wrap: wrap; }
.spacer { flex: 1; }

/* ============================================================
   STAGGER REVEAL — listas que entran en cascada
   ============================================================ */
.rise {
  opacity: 0;
  transform: translateY(8px);
  animation: rise 420ms var(--ease-out) forwards;
  animation-delay: calc(var(--i, 0) * 60ms);
}
@keyframes rise { to { opacity: 1; transform: translateY(0); } }

/* ============================================================
   SKELETON LOADERS
   ============================================================ */
.skeleton {
  background: linear-gradient(90deg, #E8EDF0 0%, #F4F7F9 50%, #E8EDF0 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--r-xs);
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skeleton--line { height: 12px; }
.skeleton--line-lg { height: 18px; }
.skeleton--avatar { width: 32px; height: 32px; border-radius: 50%; }
.skeleton--w-30 { width: 30%; } .skeleton--w-50 { width: 50%; }
.skeleton--w-70 { width: 70%; } .skeleton--w-100 { width: 100%; }

/* ============================================================
   EMPTY STATE — con CTA
   ============================================================ */
.empty-x {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 12px;
}
.empty-x__icon {
  width: 56px;
  height: 56px;
  background: var(--brand-soft);
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand);
}
.empty-x__title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
.empty-x__msg { font-size: 14px; color: var(--ink-muted); max-width: 380px; line-height: 1.5; }
.empty-x__actions { display: flex; gap: 8px; margin-top: 8px; }
.empty-x--positive .empty-x__icon { background: rgba(13,121,96,0.10); color: var(--success); }

/* ============================================================
   TIMELINE (Cliente 360 — Fase 3)
   ============================================================ */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--border-neutral);
  border-radius: 1px;
}
.timeline__item {
  position: relative;
  padding: 8px 0 16px 16px;
}
.timeline__item::before {
  content: '';
  position: absolute;
  left: -19px;
  top: 14px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--brand);
}
.timeline__item--inbound::before  { border-color: var(--success); }
.timeline__item--system::before   { border-color: var(--ink-muted); background: var(--ink-muted); }
.timeline__when { font-family: var(--font-mono); font-size: 11px; color: var(--ink-muted); }
.timeline__title { font-size: 14px; font-weight: 500; color: var(--ink); margin-top: 2px; }
.timeline__body { font-size: 13px; color: var(--ink-soft); margin-top: 4px; line-height: 1.5; }

/* ============================================================
   FAB — acciones rápidas en cliente detail
   ============================================================ */
.fab-x {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.fab-x__main {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-floating);
  transition: transform var(--dur-fast) var(--ease-out);
}
.fab-x__main:hover { transform: scale(1.05); }
.fab-x__main:active { transform: scale(0.96); }
.fab-x__menu {
  display: none;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.fab-x[aria-expanded="true"] .fab-x__menu { display: flex; }
.fab-x__action {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border-neutral);
  border-radius: var(--r-pill);
  padding: 8px 16px 8px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
  text-decoration: none;
  animation: fab-rise 280ms var(--ease-spring) backwards;
  animation-delay: calc(var(--i, 0) * 50ms);
}
.fab-x__action:hover { transform: translateX(-2px); box-shadow: var(--shadow-card-hover); }
@keyframes fab-rise {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   SECTION (mejora de <details>)
   ============================================================ */
.section-x {
  border: 1px solid var(--border-neutral);
  border-radius: var(--r-md);
  background: #fff;
  margin-bottom: 12px;
  overflow: hidden;
}
.section-x__head {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.section-x__head::-webkit-details-marker { display: none; }
.section-x__head:hover { background: var(--paper); }
.section-x__icon { color: var(--brand); flex-shrink: 0; }
.section-x__title { flex: 1; }
.section-x__counter {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-muted);
  padding: 2px 8px;
  background: var(--paper);
  border: 1px solid var(--border-neutral);
  border-radius: var(--r-pill);
}
.section-x__chevron {
  color: var(--ink-muted);
  transition: transform var(--dur-base) var(--ease-out);
  flex-shrink: 0;
}
.section-x[open] .section-x__chevron { transform: rotate(180deg); }
.section-x__body {
  padding: 18px;
  border-top: 1px solid var(--border-neutral);
  background: var(--paper);
}

/* ============================================================
   TABS (Cliente 360)
   ============================================================ */
.tabs-x {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-neutral);
  margin-bottom: 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs-x::-webkit-scrollbar { display: none; }
.tabs-x__tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-fast), border-color var(--dur-fast);
  text-decoration: none;
}
.tabs-x__tab:hover { color: var(--ink); }
.tabs-x__tab[aria-selected="true"] {
  color: var(--brand);
  border-bottom-color: var(--brand);
  font-weight: 600;
}
.tabs-x__count {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: var(--r-pill);
}

/* ============================================================
   PROGRESS BAR (visit results, scoring)
   ============================================================ */
.bar-x {
  height: 6px;
  background: var(--paper);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.bar-x__fill {
  height: 100%;
  border-radius: inherit;
  transition: width var(--dur-slow) var(--ease-out);
}
.bar-x__fill--success { background: linear-gradient(90deg, var(--accent), var(--success)); }
.bar-x__fill--warning { background: linear-gradient(90deg, #F5A623, var(--warning)); }
.bar-x__fill--brand   { background: var(--brand); }

/* ============================================================
   TOOLTIPS (Manual Vivo — Fase 4-bis)
   ============================================================ */
.tip-x {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 4px;
  cursor: help;
}
.tip-x__trigger {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-muted);
  border: 1px solid var(--border-neutral);
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}
.tip-x:hover .tip-x__trigger { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.tip-x__panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  background: var(--ink);
  color: #fff;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 400;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-fast);
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
}
.tip-x:hover .tip-x__panel,
.tip-x:focus-within .tip-x__panel { opacity: 1; }
.tip-x__panel::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink);
}

/* ============================================================
   PAGE HEADER (refresh)
   ============================================================ */
.page-x__title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}
.page-x__subtitle {
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink-muted);
  margin-top: 4px;
}
.page-x__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

/* ============================================================
   KPI BLOCK
   ============================================================ */
.kpi-x {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-x__value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi-x__label {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kpi-x__delta { font-family: var(--font-mono); font-size: 12px; }
.kpi-x__delta--up   { color: var(--success); }
.kpi-x__delta--down { color: var(--danger); }

/* ============================================================
   MOBILE RESPONSIVE OVERRIDES
   ============================================================ */
@media (max-width: 720px) {
  .page-x__title { font-size: 22px; }
  .card-x--bento { padding: 20px; border-radius: var(--r-lg); }
  .fab-x { bottom: 16px; right: 16px; }
  .fab-x__main { width: 48px; height: 48px; }
  .bento-x { gap: 14px; }
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
*:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
