/**
 * KPIs de estados — Gestión de tickets
 * Profundidad sutil, tipografía clara, movimiento contenido.
 */

.tk-kpi-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0 0 0.75rem;
}

.tk-kpi {
  --kpi-c1: #D7E2EA;
  --kpi-c2: #F2F6F9;
  --kpi-c3: #C8D7E4;
  --kpi-c4: #F8FBFD;
  --kpi-accent: rgba(100, 116, 139, 0.28);
  --kpi-accent-soft: rgba(148, 163, 184, 0.18);
  --kpi-ink: #0F172A;
  --kpi-muted: #475569;
  --kpi-icon-bg: rgba(71, 85, 105, 0.12);
  --kpi-icon-fg: #334155;
  --kpi-border: rgba(148, 163, 184, 0.4);
  --kpi-shadow: 0 6px 16px rgba(15, 23, 42, 0.08);
  --kpi-glow: rgba(148, 163, 184, 0.22);

  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 74px;
  padding: 0.55rem 0.65rem 0.5rem;
  border: 1px solid var(--kpi-border);
  border-radius: 14px;
  background:
    linear-gradient(160deg, var(--kpi-c4) 0%, transparent 42%),
    linear-gradient(125deg, var(--kpi-c1), var(--kpi-c2) 48%, var(--kpi-c3));
  background-size: 180% 180%, 200% 200%;
  box-shadow:
    var(--kpi-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.72);
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
  user-select: none;
  animation: tk-kpi-gradient-flow 22s ease-in-out infinite;
}

/* Capas de fondo — suaves, sin blur agresivo */
.tk-kpi__glow,
.tk-kpi__orb,
.tk-kpi__mesh,
.tk-kpi__sheen {
  position: absolute;
  pointer-events: none;
  z-index: 0;
}

.tk-kpi__glow {
  inset: -30%;
  background: radial-gradient(circle at 40% 35%, var(--kpi-glow), transparent 65%);
  opacity: 0.55;
  animation: tk-kpi-glow-pulse 14s ease-in-out infinite;
}

.tk-kpi__orb {
  width: 58%;
  height: 58%;
  border-radius: 50%;
  opacity: 0.55;
}

.tk-kpi__orb--a {
  top: -22%;
  left: -14%;
  background: radial-gradient(circle, var(--kpi-accent) 0%, transparent 70%);
  animation: tk-kpi-orb-a 18s ease-in-out infinite;
}

.tk-kpi__orb--b {
  right: -18%;
  bottom: -28%;
  width: 66%;
  height: 66%;
  background: radial-gradient(circle, var(--kpi-accent-soft) 0%, transparent 72%);
  animation: tk-kpi-orb-b 22s ease-in-out infinite;
}

.tk-kpi__mesh {
  inset: -20%;
  background:
    radial-gradient(circle at 16% 20%, rgba(255, 255, 255, 0.5), transparent 40%),
    radial-gradient(circle at 78% 82%, rgba(255, 255, 255, 0.22), transparent 44%);
  animation: tk-kpi-mesh-drift 20s ease-in-out infinite alternate;
  opacity: 0.7;
}

.tk-kpi__sheen {
  inset: 0;
  background: linear-gradient(
    115deg,
    transparent 0%,
    transparent 42%,
    rgba(255, 255, 255, 0.28) 50%,
    transparent 58%,
    transparent 100%
  );
  background-size: 260% 100%;
  animation: tk-kpi-sheen 16s ease-in-out infinite;
  opacity: 0.28;
}

/* Contenido — jerarquía tipográfica */
.tk-kpi__body {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.tk-kpi__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  min-width: 0;
}

.tk-kpi__value {
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  color: var(--kpi-ink);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.4);
  min-width: 0;
}

.tk-kpi__icon {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  flex: 0 0 auto;
  background: var(--kpi-icon-bg);
  color: var(--kpi-icon-fg);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 1px 3px rgba(15, 23, 42, 0.06);
}

.tk-kpi__icon i {
  line-height: 1;
  display: block;
}

.tk-kpi__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  min-width: 0;
  padding-top: 0.15rem;
  border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.tk-kpi__label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--kpi-muted);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.tk-kpi__detail {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 7px;
  flex: 0 0 auto;
  font-size: 0.62rem;
  color: var(--kpi-icon-fg);
  background: rgba(255, 255, 255, 0.55);
  text-decoration: none !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5);
  opacity: 0.72;
  transition: background-color 0.15s ease, color 0.15s ease, opacity 0.15s ease;
}

.tk-kpi__detail:hover {
  background: rgba(255, 255, 255, 0.95);
  color: #0F172A;
  opacity: 1;
  transform: none;
}

/* Hover contenido — sin acelerar animaciones de fondo */
.tk-kpi.card_focus:hover,
.tk-kpi:hover {
  color: inherit;
  background-color: transparent;
  transform: translateY(-2px);
  box-shadow:
    0 10px 22px rgba(15, 23, 42, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tk-kpi:hover .tk-kpi__detail {
  opacity: 1;
}

.tk-kpi:hover .tk-kpi__icon {
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.65),
    0 2px 6px rgba(15, 23, 42, 0.1);
}

/* Desfase leve entre tarjetas */
.tk-kpi-board .tk-kpi:nth-child(2) { animation-delay: -3s; }
.tk-kpi-board .tk-kpi:nth-child(3) { animation-delay: -6s; }
.tk-kpi-board .tk-kpi:nth-child(4) { animation-delay: -9s; }
.tk-kpi-board .tk-kpi:nth-child(5) { animation-delay: -12s; }
.tk-kpi-board .tk-kpi:nth-child(6) { animation-delay: -15s; }
.tk-kpi-board .tk-kpi:nth-child(7) { animation-delay: -18s; }

.tk-kpi-board .tk-kpi:nth-child(odd) .tk-kpi__orb--a { animation-delay: -4s; }
.tk-kpi-board .tk-kpi:nth-child(even) .tk-kpi__orb--b { animation-delay: -7s; }

/* Tonos semánticos */
.tk-kpi--info {
  --kpi-c1: #A8D9E8;
  --kpi-c2: #EAF7FB;
  --kpi-c3: #7FC4D8;
  --kpi-c4: #F4FBFE;
  --kpi-accent: rgba(8, 145, 178, 0.28);
  --kpi-accent-soft: rgba(34, 211, 238, 0.16);
  --kpi-glow: rgba(14, 165, 233, 0.22);
  --kpi-icon-bg: rgba(14, 116, 144, 0.14);
  --kpi-icon-fg: #0E7490;
  --kpi-border: rgba(14, 116, 144, 0.32);
  --kpi-shadow: 0 6px 16px rgba(14, 116, 144, 0.1);
}

.tk-kpi--warning {
  --kpi-c1: #F3D19A;
  --kpi-c2: #FFF6E9;
  --kpi-c3: #E8B05C;
  --kpi-c4: #FFFBF4;
  --kpi-accent: rgba(217, 119, 6, 0.26);
  --kpi-accent-soft: rgba(251, 191, 36, 0.18);
  --kpi-glow: rgba(245, 158, 11, 0.2);
  --kpi-icon-bg: rgba(180, 83, 9, 0.14);
  --kpi-icon-fg: #B45309;
  --kpi-border: rgba(217, 119, 6, 0.32);
  --kpi-shadow: 0 6px 16px rgba(180, 83, 9, 0.1);
}

.tk-kpi--muted {
  --kpi-c1: #CDD1D2;
  --kpi-c2: #F2F3F3;
  --kpi-c3: #B2B7B8;
  --kpi-c4: #F8F8F8;
  --kpi-accent: rgba(100, 116, 139, 0.22);
  --kpi-accent-soft: rgba(148, 163, 184, 0.14);
  --kpi-glow: rgba(100, 116, 139, 0.16);
  --kpi-icon-bg: rgba(71, 85, 105, 0.12);
  --kpi-icon-fg: #4B5563;
  --kpi-border: rgba(100, 116, 139, 0.3);
  --kpi-shadow: 0 6px 14px rgba(71, 85, 105, 0.08);
}

.tk-kpi--primary {
  --kpi-c1: #9BCBB9;
  --kpi-c2: #EAF5F1;
  --kpi-c3: #6FB29A;
  --kpi-c4: #F3FAF7;
  --kpi-accent: rgba(35, 91, 78, 0.28);
  --kpi-accent-soft: rgba(52, 168, 133, 0.16);
  --kpi-glow: rgba(35, 91, 78, 0.2);
  --kpi-icon-bg: rgba(35, 91, 78, 0.14);
  --kpi-icon-fg: #1A443A;
  --kpi-border: rgba(35, 91, 78, 0.34);
  --kpi-shadow: 0 6px 16px rgba(35, 91, 78, 0.11);
}

.tk-kpi--danger {
  --kpi-c1: #E8B0BD;
  --kpi-c2: #FCF0F3;
  --kpi-c3: #D07A8E;
  --kpi-c4: #FFF7F9;
  --kpi-accent: rgba(159, 34, 65, 0.26);
  --kpi-accent-soft: rgba(244, 114, 182, 0.14);
  --kpi-glow: rgba(190, 24, 93, 0.18);
  --kpi-icon-bg: rgba(159, 34, 65, 0.12);
  --kpi-icon-fg: #9F2241;
  --kpi-border: rgba(159, 34, 65, 0.32);
  --kpi-shadow: 0 6px 16px rgba(159, 34, 65, 0.1);
}

.tk-kpi--success {
  --kpi-c1: #9FD8B2;
  --kpi-c2: #ECF9F0;
  --kpi-c3: #68C088;
  --kpi-c4: #F4FBF6;
  --kpi-accent: rgba(21, 128, 61, 0.26);
  --kpi-accent-soft: rgba(74, 222, 128, 0.16);
  --kpi-glow: rgba(34, 197, 94, 0.18);
  --kpi-icon-bg: rgba(21, 128, 61, 0.12);
  --kpi-icon-fg: #166534;
  --kpi-border: rgba(21, 128, 61, 0.32);
  --kpi-shadow: 0 6px 16px rgba(21, 128, 61, 0.1);
}

.tk-kpi--pending {
  --kpi-c1: #BCC8D8;
  --kpi-c2: #F0F4F8;
  --kpi-c3: #97A8BD;
  --kpi-c4: #F7FAFC;
  --kpi-accent: rgba(71, 85, 105, 0.24);
  --kpi-accent-soft: rgba(148, 163, 184, 0.16);
  --kpi-glow: rgba(100, 116, 139, 0.18);
  --kpi-icon-bg: rgba(71, 85, 105, 0.12);
  --kpi-icon-fg: #334155;
  --kpi-border: rgba(100, 116, 139, 0.32);
  --kpi-shadow: 0 6px 14px rgba(71, 85, 105, 0.08);
}

.tk-kpi--neutral {
  --kpi-c1: #D7E2EA;
  --kpi-c2: #F2F6F9;
  --kpi-c3: #C8D7E4;
  --kpi-c4: #F8FBFD;
}

/* Selección activa */
.tk-kpi.seleccion,
.tk-kpi.is-selected,
.tk-kpi.seleccion:hover,
.tk-kpi.is-selected:hover {
  transform: none !important;
  border-color: #235B4E;
  -webkit-box-shadow:
    0 0 0 2px rgba(35, 91, 78, 0.2),
    0 10px 22px rgba(35, 91, 78, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  -moz-box-shadow:
    0 0 0 2px rgba(35, 91, 78, 0.2),
    0 10px 22px rgba(35, 91, 78, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  box-shadow:
    0 0 0 2px rgba(35, 91, 78, 0.2),
    0 10px 22px rgba(35, 91, 78, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tk-kpi.seleccion .tk-kpi__value,
.tk-kpi.is-selected .tk-kpi__value {
  color: #14352E;
}

.tk-kpi.seleccion .tk-kpi__label,
.tk-kpi.is-selected .tk-kpi__label {
  color: #1F2937;
}

.tk-kpi.seleccion .tk-kpi__icon,
.tk-kpi.is-selected .tk-kpi__icon {
  background: rgba(35, 91, 78, 0.16);
  color: #235B4E;
}

/* Animaciones — lentas y de baja amplitud */
@keyframes tk-kpi-gradient-flow {
  0%,
  100% {
    background-position: 0% 45%, 0% 50%;
  }
  50% {
    background-position: 55% 55%, 40% 45%;
  }
}

@keyframes tk-kpi-mesh-drift {
  0% {
    transform: translate3d(-1.5%, -1%, 0);
  }
  100% {
    transform: translate3d(1.5%, 1.5%, 0);
  }
}

@keyframes tk-kpi-orb-a {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(10%, 8%, 0);
  }
}

@keyframes tk-kpi-orb-b {
  0%,
  100% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(-8%, -6%, 0);
  }
}

@keyframes tk-kpi-glow-pulse {
  0%,
  100% {
    opacity: 0.4;
  }
  50% {
    opacity: 0.65;
  }
}

@keyframes tk-kpi-sheen {
  0% {
    background-position: 140% 0;
  }
  35% {
    background-position: -20% 0;
  }
  100% {
    background-position: -20% 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tk-kpi,
  .tk-kpi__glow,
  .tk-kpi__orb,
  .tk-kpi__mesh,
  .tk-kpi__sheen {
    animation: none !important;
  }

  .tk-kpi:hover {
    transform: none;
  }
}

@media (max-width: 1199.98px) {
  .tk-kpi-board {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 767.98px) {
  .tk-kpi-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
  }

  .tk-kpi {
    min-height: 70px;
  }

  .tk-kpi__value {
    font-size: 1.35rem;
  }

  .tk-kpi__sheen {
    display: none;
  }
}
